fix: testnet electrum methods

This commit is contained in:
Rafael Saes 2023-11-30 16:17:16 -03:00
parent 028dcb3b98
commit 4b3b3f6d2c
4 changed files with 22 additions and 17 deletions

View file

@ -256,19 +256,23 @@ class ElectrumClient {
return ''; return '';
}); });
Future<String> broadcastTransaction({required String transactionRaw}) async { Future<String> broadcastTransaction(
return http {required String transactionRaw, NetworkType? networkType}) async {
.post(Uri(scheme: 'https', host: 'blockstream.info', path: '/testnet/api/tx'), if (networkType != null && networkType.bech32 == testnet.bech32) {
headers: <String, String>{'Content-Type': 'application/json; charset=utf-8'}, return http
body: transactionRaw) .post(Uri(scheme: 'https', host: 'blockstream.info', path: '/testnet/api/tx'),
.then((http.Response response) { headers: <String, String>{'Content-Type': 'application/json; charset=utf-8'},
print(response.body); body: transactionRaw)
if (response.statusCode == 200) { .then((http.Response response) {
return response.body; print(response.body);
} if (response.statusCode == 200) {
return response.body;
}
return '';
});
}
return '';
});
return call(method: 'blockchain.transaction.broadcast', params: [transactionRaw]) return call(method: 'blockchain.transaction.broadcast', params: [transactionRaw])
.then((dynamic result) { .then((dynamic result) {
if (result is String) { if (result is String) {

View file

@ -512,7 +512,7 @@ abstract class ElectrumWalletBase
} }
return PendingBitcoinTransaction(txb.build(), type, return PendingBitcoinTransaction(txb.build(), type,
electrumClient: electrumClient, amount: amount, fee: fee) electrumClient: electrumClient, amount: amount, fee: fee, networkType: networkType)
..addListener((transaction) async { ..addListener((transaction) async {
transactionHistory.addOne(transaction); transactionHistory.addOne(transaction);
await updateBalance(); await updateBalance();

View file

@ -9,7 +9,7 @@ import 'package:cw_core/wallet_type.dart';
class PendingBitcoinTransaction with PendingTransaction { class PendingBitcoinTransaction with PendingTransaction {
PendingBitcoinTransaction(this._tx, this.type, PendingBitcoinTransaction(this._tx, this.type,
{required this.electrumClient, required this.amount, required this.fee}) {required this.electrumClient, required this.amount, required this.fee, this.networkType})
: _listeners = <void Function(ElectrumTransactionInfo transaction)>[]; : _listeners = <void Function(ElectrumTransactionInfo transaction)>[];
final WalletType type; final WalletType type;
@ -17,6 +17,7 @@ class PendingBitcoinTransaction with PendingTransaction {
final ElectrumClient electrumClient; final ElectrumClient electrumClient;
final int amount; final int amount;
final int fee; final int fee;
final bitcoin.NetworkType? networkType;
@override @override
String get id => _tx.getId(); String get id => _tx.getId();
@ -34,8 +35,8 @@ class PendingBitcoinTransaction with PendingTransaction {
@override @override
Future<void> commit() async { Future<void> commit() async {
final result = final result = await electrumClient.broadcastTransaction(
await electrumClient.broadcastTransaction(transactionRaw: _tx.txHex ?? _tx.toHex()); transactionRaw: _tx.txHex ?? _tx.toHex(), networkType: networkType);
if (result.isEmpty) { if (result.isEmpty) {
throw BitcoinCommitTransactionException(); throw BitcoinCommitTransactionException();

View file

@ -88,7 +88,7 @@ packages:
description: description:
path: "." path: "."
ref: silent-payments ref: silent-payments
resolved-ref: "28168b4e678b04bbbe70aa7fb5d2797b0a8e1b71" resolved-ref: d4f4f9726499750da66a6057ce12dc70f60215c6
url: "https://github.com/cake-tech/bitcoin_flutter.git" url: "https://github.com/cake-tech/bitcoin_flutter.git"
source: git source: git
version: "2.0.2" version: "2.0.2"