buildInputs method

BigIntX buildInputs({
  1. BigIntX? outAmountBn,
  2. int extraInputsNum = 0,
})

Implementation

BigIntX buildInputs({BigIntX? outAmountBn, int extraInputsNum = 0}) {
  var inAmountBn = BigIntX.zero;

  for (var txIn in this.txIns) {
    var txOut = this.uTxOutMap.get(txIn.txHashBuf!, txIn.txOutNum);
    inAmountBn = inAmountBn.add(txOut.valueBn);
    this.tx.addTxIn(data: txIn);
    if (inAmountBn.geq(outAmountBn)) {
      if (extraInputsNum <= 0) {
        break;
      }
      extraInputsNum--;
    }
  }
  if (inAmountBn.lt(outAmountBn)) {
    throw ('not enough funds for outputs: inAmountBn ${inAmountBn.toNumber()} outAmountBn ${outAmountBn!.toNumber()}');
  }
  return inAmountBn;
}