mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-05-10 14:42:26 +00:00
fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
This commit is contained in:
parent
315b6717e2
commit
caab5325ec
2 changed files with 35 additions and 11 deletions
cw_bitcoin
|
@ -39,6 +39,7 @@ import 'package:hex/hex.dart';
|
|||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:rxdart/subjects.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
part 'electrum_wallet.g.dart';
|
||||
|
||||
|
@ -645,18 +646,41 @@ abstract class ElectrumWalletBase
|
|||
|
||||
Future<ElectrumTransactionBundle> getTransactionExpanded(
|
||||
{required String hash, required int height}) async {
|
||||
final verboseTransaction = await electrumClient.getTransactionRaw(hash: hash);
|
||||
final transactionHex = verboseTransaction['hex'] as String;
|
||||
String transactionHex;
|
||||
int? time;
|
||||
int confirmations = 0;
|
||||
if (network == BitcoinNetwork.mainnet) {
|
||||
final verboseTransaction = await electrumClient.getTransactionRaw(hash: hash);
|
||||
|
||||
transactionHex = verboseTransaction as String;
|
||||
time = verboseTransaction['time'] as int?;
|
||||
confirmations = verboseTransaction['confirmations'] as int? ?? 0;
|
||||
} else {
|
||||
// Testnet public electrum server does not support verbose transaction fetching
|
||||
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_base.BtcTransaction.fromRaw(transactionHex);
|
||||
final ins = <bitcoin_base.BtcTransaction>[];
|
||||
final time = verboseTransaction['time'] as int?;
|
||||
final confirmations = verboseTransaction['confirmations'] as int? ?? 0;
|
||||
|
||||
for (final vin in original.inputs) {
|
||||
final id = HEX.encode(HEX.decode(vin.txId).reversed.toList());
|
||||
final txHex = await electrumClient.getTransactionHex(hash: id);
|
||||
final tx = bitcoin_base.BtcTransaction.fromRaw(txHex);
|
||||
ins.add(tx);
|
||||
try {
|
||||
final id = HEX.encode(HEX.decode(vin.txId).reversed.toList());
|
||||
final txHex = await electrumClient.getTransactionHex(hash: id);
|
||||
final tx = bitcoin_base.BtcTransaction.fromRaw(txHex);
|
||||
ins.add(tx);
|
||||
} catch (_) {
|
||||
ins.add(bitcoin_base.BtcTransaction.fromRaw(
|
||||
await electrumClient.getTransactionHex(hash: vin.txId),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return ElectrumTransactionBundle(original, ins: ins, time: time, confirmations: confirmations);
|
||||
|
|
|
@ -80,7 +80,7 @@ packages:
|
|||
description:
|
||||
path: "."
|
||||
ref: cake-update-v1
|
||||
resolved-ref: "59d6167a28d2eb2065ec5e90c23825fdfcfff505"
|
||||
resolved-ref: "72a098119a55e5ac708358797bc052abe35e80ef"
|
||||
url: "https://github.com/cake-tech/bitcoin_base.git"
|
||||
source: git
|
||||
version: "3.0.1"
|
||||
|
@ -177,10 +177,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: built_value
|
||||
sha256: c9aabae0718ec394e5bc3c7272e6bb0dc0b32201a08fe185ec1d8401d3e39309
|
||||
sha256: a3ec2e0f967bc47f69f95009bb93db936288d61d5343b9436e378b28a2f830c6
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "8.8.1"
|
||||
version: "8.9.0"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
Loading…
Reference in a new issue