fix: how testnet node gets tx expanded details

This commit is contained in:
Rafael Saes 2023-12-11 10:54:07 -03:00
parent 2c608d78ec
commit c472ef0e07
2 changed files with 16 additions and 20 deletions

View file

@ -228,21 +228,13 @@ class ElectrumClient {
return [];
});
Future<dynamic> getTransactionRaw(
{required String hash, required NetworkType networkType}) async =>
callWithTimeout(
method: 'blockchain.transaction.get',
params: networkType.bech32 == bitcoin.bech32 ? [hash, true] : [hash],
timeout: 10000)
Future<Map<String, dynamic>> getTransactionRaw({required String hash}) async =>
callWithTimeout(method: 'blockchain.transaction.get', params: [hash, true], timeout: 10000)
.then((dynamic result) {
if (result is Map<String, dynamic>) {
return result;
}
if (networkType.bech32 == testnet.bech32 && result is String) {
return result;
}
return <String, dynamic>{};
});

View file

@ -671,9 +671,8 @@ abstract class ElectrumWalletBase
// Update unspents stored from scanned silent payment transactions
transactionHistory.transactions.values.forEach((tx) {
if (tx.unspent != null) {
if (!unspentCoins.any((utx) =>
utx.hash.contains(tx.unspent!.hash) &&
utx.vout == tx.unspent!.vout)) {
if (!unspentCoins
.any((utx) => utx.hash.contains(tx.unspent!.hash) && utx.vout == tx.unspent!.vout)) {
unspentCoins.add(tx.unspent!);
}
}
@ -992,19 +991,24 @@ Future<ElectrumTransactionBundle> getTransactionExpanded(
required int height,
required ElectrumClient electrumClient,
required bitcoin.NetworkType networkType}) async {
final verboseTransaction =
await electrumClient.getTransactionRaw(hash: hash, networkType: networkType);
String transactionHex;
int? time;
int confirmations = 0;
if (networkType.bech32 == bitcoin.testnet.bech32) {
if (networkType.bech32 == bitcoin.bitcoin.bech32) {
final verboseTransaction = await electrumClient.getTransactionRaw(hash: hash);
transactionHex = verboseTransaction as String;
confirmations = 1;
} else {
transactionHex = verboseTransaction['hex'] as String;
time = verboseTransaction['time'] as int?;
confirmations = verboseTransaction['confirmations'] as int? ?? 0;
} else {
transactionHex = await electrumClient.getTransactionHex(hash: hash);
final status = json.decode(
(await http.get(Uri.parse("https://blockstream.info/testnet/api/tx/$hash/status"))).body);
time = status["block_time"] as int?;
final tip = await electrumClient.getCurrentBlockChainTip() ?? 0;
confirmations = tip - (status["block_height"] as int? ?? 0);
}
final original = bitcoin.Transaction.fromHex(transactionHex);