From 7d2aaa28aa02f94ac1855bc632279c5586ed4aae Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 22 Sep 2023 13:33:36 -0600 Subject: [PATCH] fix merge issue --- .../mixins/fusion_wallet_interface.dart | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/services/mixins/fusion_wallet_interface.dart b/lib/services/mixins/fusion_wallet_interface.dart index ad2a13094..83e273f1b 100644 --- a/lib/services/mixins/fusion_wallet_interface.dart +++ b/lib/services/mixins/fusion_wallet_interface.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:convert/convert.dart'; import 'package:decimal/decimal.dart'; import 'package:fusiondart/fusiondart.dart'; import 'package:fusiondart/src/models/address.dart' as fusion_address; @@ -528,7 +527,10 @@ extension FusionTransaction on Transaction { fusionTransaction.Inputs = await Future.wait(inputs.map((input) async { // Find input amount. Map _tx = await cachedElectrumX.getTransaction( - coin: Coin.bitcoincash, txHash: input.txid, verbose: true); + coin: Coin.bitcoincash, + txHash: input.txid, + verbose: true, + ); if (_tx.isEmpty) { throw Exception("Transaction not found for input: ${input.txid}"); @@ -543,20 +545,14 @@ extension FusionTransaction on Transaction { "Output value at index ${input.vout} in transaction ${input.txid} not found", ); } - if (_tx["vout"] == null) { - throw Exception("Vout in transaction ${input.txid} is null"); - } - if (_tx["vout"][input.vout] == null) { - throw Exception("Vout index ${input.vout} in transaction is null"); - } - if (_tx["vout"][input.vout]["scriptPubKey"] == null) { - throw Exception("scriptPubKey at vout index ${input.vout} is null"); - } - if (_tx["vout"][input.vout]["scriptPubKey"]["hex"] == null) { + + final scriptPubKeyHex = + _tx["vout"]?[input.vout]?["scriptPubKey"] as String?; + if (scriptPubKeyHex == null) { throw Exception( - "scriptPubKey hex of vout index ${input.vout} in transaction is null"); + "scriptPubKey of vout index ${input.vout} in transaction is null", + ); } - // TODO replace with conditional chaining? // Assign vout value to amount. final value = Amount.fromDecimal( @@ -567,7 +563,7 @@ extension FusionTransaction on Transaction { return fusion_input.Input( prevTxid: utf8.encode(input.txid), prevIndex: input.vout, - pubKey: hex.decode("${_tx["vout"][input.vout]["scriptPubKey"]["hex"]}"), + pubKey: scriptPubKeyHex.toUint8ListFromHex, amount: value.raw.toInt(), ); }).toList());