replace bitcoindart with coinlib

This commit is contained in:
sneurlax 2023-09-22 14:20:19 -05:00
parent af40bf3667
commit 55e6e56a2d
4 changed files with 38 additions and 16 deletions

@ -1 +1 @@
Subproject commit 75aa93ba25e59f19c90825ac2e9114b20ac3e538
Subproject commit 2ad67494611097d2471ff1f3a1f57c88e8f38ce8

View file

@ -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<String, dynamic> _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,

View file

@ -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:

View file

@ -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: