fix merge issue

This commit is contained in:
julian 2023-09-22 13:33:36 -06:00
parent 722a72cff6
commit 7d2aaa28aa

View file

@ -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<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}");
@ -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());