buildDummyTxFromScratch function

DummyTxInfo buildDummyTxFromScratch({
  1. required TransferIntent<FeeInformation> intent,
  2. required UTXONetworkType networkType,
  3. required HDWalletPath walletPath,
  4. required Iterable<UTXOTransaction> txList,
  5. required List<String> changeAddresses,
})

Creates a dummy transaction to estimate the size of the transaction and hence the fee Also returns the chosen UTXOs so that they can be used to create the real transaction with the same UTXOs Includes a safety margin so that changes in the Amount dont lead to a different fee

Implementation

DummyTxInfo buildDummyTxFromScratch({
  required TransferIntent intent,
  required UTXONetworkType networkType,
  required HDWalletPath walletPath,
  required Iterable<UTXOTransaction> txList,
  required List<String> changeAddresses,
}) {
  final allUTXOs = extractUTXOs(txList: txList);

  final chosenUTXOs = singleRandomDrawUTXOSelection(
    allUTXOs.keys.toList(),
    intent.amount.value,
  );

  final chosenUTXOsMap = {
    for (final utxo in chosenUTXOs) utxo: allUTXOs[utxo]!,
  };

  final (_, inputMap) = buildInputs(chosenUTXOsMap, networkType);

  final changeAddress = findUnusedAddress(
    addresses: changeAddresses,
    txs: txList,
  );

  final dummyOutputs = buildOutputs(
    recipient: intent.recipient,
    value: intent.amount.value,
    changeAddress: changeAddress,
    changeValue: BigInt.one,
    networkType: networkType,
  );

  final dummyTx = buildDummyTx(
    networkType: networkType,
    walletPath: walletPath,
    inputMap: inputMap,
    dummyOutputs: dummyOutputs,
  );

  return (dummyRawTx: dummyTx, chosenUTXOs: chosenUTXOs);
}