createCompoundTx method

SendTx createCompoundTx({
  1. required Address compoundAddress,
  2. required List<Utxo> spendableUtxos,
  3. required BigInt feePerInput,
})

Implementation

SendTx createCompoundTx({
  required Address compoundAddress,
  required List<Utxo> spendableUtxos,
  required BigInt feePerInput,
}) {
  final selectedUtxos =
      spendableUtxos.take(kMaxInputsPerTransaction).toList();
  final fee = BigInt.from(selectedUtxos.length) * feePerInput;
  final selectedTotal = selectedUtxos.fold<BigInt>(
    BigInt.zero,
    (sum, utxo) => sum + utxo.utxoEntry.amount,
  );
  final amountRaw = selectedTotal - fee;

  return SendTx(
    uri: KaspaUri(
      address: compoundAddress,
      amount: Amount.raw(amountRaw),
    ),
    amountRaw: amountRaw,
    utxos: selectedUtxos,
    fee: fee,
  );
}