From 7724d5e24885962a5dc2bcac8ee58626c6162813 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Thu, 24 Jun 2021 18:59:19 +0300 Subject: [PATCH] CAKE-333 | fixed commit() method in the pending_bitcoin_transaction.dart; added bitcoin_commit_transaction_exception.dart to the app --- lib/bitcoin/bitcoin_commit_transaction_exception.dart | 4 ++++ lib/bitcoin/pending_bitcoin_transaction.dart | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 lib/bitcoin/bitcoin_commit_transaction_exception.dart diff --git a/lib/bitcoin/bitcoin_commit_transaction_exception.dart b/lib/bitcoin/bitcoin_commit_transaction_exception.dart new file mode 100644 index 000000000..3e21bae81 --- /dev/null +++ b/lib/bitcoin/bitcoin_commit_transaction_exception.dart @@ -0,0 +1,4 @@ +class BitcoinCommitTransactionException implements Exception { + @override + String toString() => 'Transaction commit is failed.'; +} \ No newline at end of file diff --git a/lib/bitcoin/pending_bitcoin_transaction.dart b/lib/bitcoin/pending_bitcoin_transaction.dart index ec3e3a985..b26814339 100644 --- a/lib/bitcoin/pending_bitcoin_transaction.dart +++ b/lib/bitcoin/pending_bitcoin_transaction.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/bitcoin/bitcoin_commit_transaction_exception.dart'; import 'package:flutter/foundation.dart'; import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; import 'package:cake_wallet/core/pending_transaction.dart'; @@ -33,7 +34,13 @@ class PendingBitcoinTransaction with PendingTransaction { @override Future commit() async { - await electrumClient.broadcastTransaction(transactionRaw: _tx.toHex()); + final result = + await electrumClient.broadcastTransaction(transactionRaw: _tx.toHex()); + + if (result.isEmpty) { + throw BitcoinCommitTransactionException(); + } + _listeners?.forEach((listener) => listener(transactionInfo())); }