From 55e6e56a2dc6a723010f97f738ea1a846c73dbde Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 22 Sep 2023 14:20:19 -0500 Subject: [PATCH] replace bitcoindart with coinlib --- fusiondart | 2 +- .../mixins/fusion_wallet_interface.dart | 32 +++++++++++-------- pubspec.lock | 18 ++++++++++- pubspec.yaml | 2 ++ 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/fusiondart b/fusiondart index 75aa93ba2..2ad674946 160000 --- a/fusiondart +++ b/fusiondart @@ -1 +1 @@ -Subproject commit 75aa93ba25e59f19c90825ac2e9114b20ac3e538 +Subproject commit 2ad67494611097d2471ff1f3a1f57c88e8f38ce8 diff --git a/lib/services/mixins/fusion_wallet_interface.dart b/lib/services/mixins/fusion_wallet_interface.dart index 190bcd4c9..1a2301b3f 100644 --- a/lib/services/mixins/fusion_wallet_interface.dart +++ b/lib/services/mixins/fusion_wallet_interface.dart @@ -2,6 +2,7 @@ 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; @@ -527,10 +528,7 @@ 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}"); @@ -545,14 +543,20 @@ extension FusionTransaction on Transaction { "Output value at index ${input.vout} in transaction ${input.txid} not found", ); } - - final scriptPubKeyHex = - _tx["vout"]?[input.vout]?["scriptPubKey"] as String?; - if (scriptPubKeyHex == null) { - throw Exception( - "scriptPubKey of vout index ${input.vout} in transaction is null", - ); + 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) { + throw Exception( + "scriptPubKey hex of vout index ${input.vout} in transaction is null"); + } + // TODO replace with conditional chaining? // Assign vout value to amount. final value = Amount.fromDecimal( @@ -563,7 +567,7 @@ extension FusionTransaction on Transaction { return fusion_input.Input( prevTxid: utf8.encode(input.txid), prevIndex: input.vout, - pubKey: scriptPubKeyHex.toUint8ListFromHex, + pubKey: hex.decode("${_tx["vout"][input.vout]["scriptPubKey"]["hex"]}"), amount: value.raw.toInt(), ); }).toList()); @@ -585,7 +589,7 @@ extension FusionTransaction on Transaction { address: outputAddress, dbInstance: dbInstance, ); - fusion_address.DerivationPath derivationPath; + fusion_address.DerivationPath? derivationPath; if (derivationPathString == null) { // TODO: check on this: // Either the address is not an address of this wallet @@ -593,7 +597,7 @@ extension FusionTransaction on Transaction { // If the former, then the issue cannot be easily solved as we will // have no way of finding out what the derivation path is. // Throw exception for now. - throw Exception("derivationPathString is null"); + // throw Exception("derivationPathString is null"); } else { derivationPath = fusion_address.DerivationPath( derivationPathString, diff --git a/pubspec.lock b/pubspec.lock index 9a487f834..e7599a701 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -262,6 +262,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.6.0" + coinlib: + dependency: "direct main" + description: + name: coinlib + sha256: "410993f49aef30e48b76bbad8a33fef33f6b90e103b15b6be0277683ffe15399" + url: "https://pub.dev" + source: hosted + version: "1.0.0" collection: dependency: transitive description: @@ -287,7 +295,7 @@ packages: source: hosted version: "1.2.4" convert: - dependency: transitive + dependency: "direct main" description: name: convert sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" @@ -1861,6 +1869,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.0.12+1" + wasm_interop: + dependency: transitive + description: + name: wasm_interop + sha256: b1b378f07a4cf0103c25faf34d9a64d2c3312135b9efb47e0ec116ec3b14e48f + url: "https://pub.dev" + source: hosted + version: "2.0.1" watcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c8c975885..00890539c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -149,6 +149,8 @@ dependencies: bip340: ^0.2.0 tezart: ^2.0.5 socks5_proxy: ^1.0.3+dev.3 + coinlib: ^1.0.0 + convert: ^3.1.1 dev_dependencies: flutter_test: