mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
fix: testnet electrum methods
This commit is contained in:
parent
028dcb3b98
commit
4b3b3f6d2c
4 changed files with 22 additions and 17 deletions
|
@ -256,19 +256,23 @@ class ElectrumClient {
|
|||
return '';
|
||||
});
|
||||
|
||||
Future<String> broadcastTransaction({required String transactionRaw}) async {
|
||||
return http
|
||||
.post(Uri(scheme: 'https', host: 'blockstream.info', path: '/testnet/api/tx'),
|
||||
headers: <String, String>{'Content-Type': 'application/json; charset=utf-8'},
|
||||
body: transactionRaw)
|
||||
.then((http.Response response) {
|
||||
print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
return response.body;
|
||||
}
|
||||
Future<String> 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: <String, String>{'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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 = <void Function(ElectrumTransactionInfo transaction)>[];
|
||||
|
||||
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<void> 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();
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue