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:convert';
import 'dart:io'; import 'dart:io';
import 'package:convert/convert.dart';
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:fusiondart/fusiondart.dart'; import 'package:fusiondart/fusiondart.dart';
import 'package:fusiondart/src/models/address.dart' as fusion_address; 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 { fusionTransaction.Inputs = await Future.wait(inputs.map((input) async {
// Find input amount. // Find input amount.
Map<String, dynamic> _tx = await cachedElectrumX.getTransaction( 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) { if (_tx.isEmpty) {
throw Exception("Transaction not found for input: ${input.txid}"); 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", "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"); final scriptPubKeyHex =
} _tx["vout"]?[input.vout]?["scriptPubKey"] as String?;
if (_tx["vout"][input.vout] == null) { if (scriptPubKeyHex == 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( 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. // Assign vout value to amount.
final value = Amount.fromDecimal( final value = Amount.fromDecimal(
@ -567,7 +563,7 @@ extension FusionTransaction on Transaction {
return fusion_input.Input( return fusion_input.Input(
prevTxid: utf8.encode(input.txid), prevTxid: utf8.encode(input.txid),
prevIndex: input.vout, prevIndex: input.vout,
pubKey: hex.decode("${_tx["vout"][input.vout]["scriptPubKey"]["hex"]}"), pubKey: scriptPubKeyHex.toUint8ListFromHex,
amount: value.raw.toInt(), amount: value.raw.toInt(),
); );
}).toList()); }).toList());