mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-02-02 19:26:27 +00:00
fix: how testnet node gets tx expanded details
This commit is contained in:
parent
2c608d78ec
commit
c472ef0e07
2 changed files with 16 additions and 20 deletions
|
@ -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>{};
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue