dev
dart 56 lines 1.7 KB
Raw
1 import 'package:cw_core/amount/money.dart';
2 import 'package:cw_wownero/api/structs/pending_transaction.dart';
3 import 'package:cw_wownero/api/transaction_history.dart' as wownero_transaction_history;
4 import 'package:cw_core/crypto_currency.dart';
5
6 import 'package:cw_core/pending_transaction.dart';
7
8 class DoubleSpendException implements Exception {
9 DoubleSpendException();
10
11 @override
12 String toString() =>
13 'This transaction cannot be committed. This can be due to many reasons including the wallet not being synced, there is not enough WOW in your available balance, or previous transactions are not yet fully processed.';
14 }
15
16 class PendingWowneroTransaction with PendingTransaction {
17 PendingWowneroTransaction(this.pendingTransactionDescription);
18
19 final PendingTransactionDescription pendingTransactionDescription;
20
21 Money get amount => Money.fromInt(pendingTransactionDescription.amount, CryptoCurrency.wow);
22
23 Money get fee => Money.fromInt(pendingTransactionDescription.fee, CryptoCurrency.wow);
24
25 @override
26 String get id => pendingTransactionDescription.hash;
27
28 @override
29 String get hex => pendingTransactionDescription.hex;
30
31 String get txKey => pendingTransactionDescription.txKey;
32
33 @override
34 String get amountFormatted => amount.toString();
35
36 @override
37 Future<void> commit() async {
38 try {
39 wownero_transaction_history.commitTransactionFromPointerAddress(
40 address: pendingTransactionDescription.pointerAddress);
41 } catch (e) {
42 final message = e.toString();
43
44 if (message.contains('Reason: double spend')) {
45 throw DoubleSpendException();
46 }
47
48 rethrow;
49 }
50 }
51
52 @override
53 Future<Map<String, String>> commitUR() {
54 throw UnimplementedError();
55 }
56 }