createPayloadForNearMPC method

Future<MpcTransactionInfo> createPayloadForNearMPC({
  1. required String senderAddress,
  2. required String receiverAddress,
  3. required String amountOfBTC,
  4. bool testNetwork = true,
})

Implementation

Future<MpcTransactionInfo> createPayloadForNearMPC({
  required String senderAddress,
  required String receiverAddress,
  required String amountOfBTC,
  bool testNetwork = true,
}) async {
  final utxos = await bitcoinRpcClient.getUTXOs(address: senderAddress);
  final feeRate = await bitcoinRpcClient.getFeeRate();

  final Map<String, dynamic> txInfos = {};

  for (var utxo in utxos) {
    final res =
        await bitcoinRpcClient.getExecutedTxData(txHash: utxo['txid']);
    txInfos[utxo['txid']] = res;
  }

  final amountOfSatoshi =
      int.parse(BitcoinFormatter.bitcoinToSatoshi(amountOfBTC));

  final network = testNetwork ? 'testnet' : 'mainnet';

  final psbtEncoded = await jsVMService.callJS(
      "window.BitcoinUtils.createPayload('$senderAddress', '$receiverAddress', $amountOfSatoshi, '${jsonEncode(utxos)}', '${jsonEncode(txInfos)}', $feeRate, '$network')");
  final psbtInHex = jsonDecode(psbtEncoded);

  return MpcTransactionInfo(transactionInfo: {
    'psbt': psbtInHex,
    'utxos': utxos,
  });
}