# All files / src/tx/applyTx checkDeposit.js

93.75% Statements 15/16
93.75% Branches 15/16
100% Functions 1/1
93.75% Lines 15/16

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45

    1x
    1x
    1x

    1x
    15x
    1x

    14x
    3x

    11x
    1x

    10x

    10x
    10x

    4x

    6x

     /**
     * Copyright (c) 2018-present, Leap DAO (leapdao.org)
     *
     * This source code is licensed under the Mozilla Public License Version 2.0
     * found in the LICENSE file in the root directory of this source tree.
     */

    const { Type } = require('leap-core');
    const { BigInt, equal, lessThan } = require('jsbi-utils');
    const { isNFT, addrCmp } = require('../../utils');

    module.exports = (state, tx, bridgeState) => {
      if (tx.type !== Type.DEPOSIT) {
        throw new Error('Deposit tx expected');
      }

      if (tx.options.depositId <= state.processedDeposit) {
        throw new Error('Deposit ID already used.');
      }
      if (tx.options.depositId > state.processedDeposit + 1) {
        throw new Error(
          `Deposit ID skipping ahead. want ${state.processedDeposit + 1}, found ${
            tx.options.depositId
          }`
        );
      }

      Iif (
        !isNFT(tx.outputs[0].color) &&
        lessThan(BigInt(tx.outputs[0].value), BigInt(1))
      ) {
        throw new Error('Deposit out has value < 1');
      }
      const deposit = bridgeState.deposits[tx.options.depositId];
      if (
        !deposit ||
        !equal(BigInt(deposit.amount), BigInt(tx.outputs[0].value)) ||
        Number(deposit.color) !== tx.outputs[0].color ||
        !addrCmp(deposit.depositor, tx.outputs[0].address)
      ) {
        throw new Error('Trying to submit incorrect deposit');
      }
      state.processedDeposit += 1;
    };