diff --git a/cw_bitcoin/lib/electrum.dart b/cw_bitcoin/lib/electrum.dart index d7438061c..f5d546592 100644 --- a/cw_bitcoin/lib/electrum.dart +++ b/cw_bitcoin/lib/electrum.dart @@ -256,19 +256,23 @@ class ElectrumClient { return ''; }); - Future broadcastTransaction({required String transactionRaw}) async { - return http - .post(Uri(scheme: 'https', host: 'blockstream.info', path: '/testnet/api/tx'), - headers: {'Content-Type': 'application/json; charset=utf-8'}, - body: transactionRaw) - .then((http.Response response) { - print(response.body); - if (response.statusCode == 200) { - return response.body; - } + Future broadcastTransaction( + {required String transactionRaw, NetworkType? networkType}) async { + if (networkType != null && networkType.bech32 == testnet.bech32) { + return http + .post(Uri(scheme: 'https', host: 'blockstream.info', path: '/testnet/api/tx'), + headers: {'Content-Type': 'application/json; charset=utf-8'}, + body: transactionRaw) + .then((http.Response response) { + print(response.body); + if (response.statusCode == 200) { + return response.body; + } + + return ''; + }); + } - return ''; - }); return call(method: 'blockchain.transaction.broadcast', params: [transactionRaw]) .then((dynamic result) { if (result is String) { diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 89f19cc03..cdb2d03bd 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -512,7 +512,7 @@ abstract class ElectrumWalletBase } return PendingBitcoinTransaction(txb.build(), type, - electrumClient: electrumClient, amount: amount, fee: fee) + electrumClient: electrumClient, amount: amount, fee: fee, networkType: networkType) ..addListener((transaction) async { transactionHistory.addOne(transaction); await updateBalance(); diff --git a/cw_bitcoin/lib/pending_bitcoin_transaction.dart b/cw_bitcoin/lib/pending_bitcoin_transaction.dart index d539b2cdf..582282160 100644 --- a/cw_bitcoin/lib/pending_bitcoin_transaction.dart +++ b/cw_bitcoin/lib/pending_bitcoin_transaction.dart @@ -9,7 +9,7 @@ import 'package:cw_core/wallet_type.dart'; class PendingBitcoinTransaction with PendingTransaction { 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 = []; final WalletType type; @@ -17,6 +17,7 @@ class PendingBitcoinTransaction with PendingTransaction { final ElectrumClient electrumClient; final int amount; final int fee; + final bitcoin.NetworkType? networkType; @override String get id => _tx.getId(); @@ -34,8 +35,8 @@ class PendingBitcoinTransaction with PendingTransaction { @override Future commit() async { - final result = - await electrumClient.broadcastTransaction(transactionRaw: _tx.txHex ?? _tx.toHex()); + final result = await electrumClient.broadcastTransaction( + transactionRaw: _tx.txHex ?? _tx.toHex(), networkType: networkType); if (result.isEmpty) { throw BitcoinCommitTransactionException(); diff --git a/cw_bitcoin/pubspec.lock b/cw_bitcoin/pubspec.lock index e2174e332..2278dbbc1 100644 --- a/cw_bitcoin/pubspec.lock +++ b/cw_bitcoin/pubspec.lock @@ -88,7 +88,7 @@ packages: description: path: "." ref: silent-payments - resolved-ref: "28168b4e678b04bbbe70aa7fb5d2797b0a8e1b71" + resolved-ref: d4f4f9726499750da66a6057ce12dc70f60215c6 url: "https://github.com/cake-tech/bitcoin_flutter.git" source: git version: "2.0.2"