cake_wallet/lib/monero/pending_monero_transaction.dart
2020-11-16 20:17:03 +02:00

47 lines
1.5 KiB
Dart

import 'package:cw_monero/structs/pending_transaction.dart';
import 'package:cw_monero/transaction_history.dart'
as monero_transaction_history;
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/core/amount_converter.dart';
import 'package:cake_wallet/core/pending_transaction.dart';
class DoubleSpendException implements Exception {
DoubleSpendException();
@override
String toString() =>
'This transaction cannot be committed. This can be due to many reasons including the wallet not being synced, there is not enough XMR in your available balance, or previous transactions are not yet fully processed.';
}
class PendingMoneroTransaction with PendingTransaction {
PendingMoneroTransaction(this.pendingTransactionDescription);
final PendingTransactionDescription pendingTransactionDescription;
@override
String get id => pendingTransactionDescription.hash;
@override
String get amountFormatted => AmountConverter.amountIntToString(
CryptoCurrency.xmr, pendingTransactionDescription.amount);
@override
String get feeFormatted => AmountConverter.amountIntToString(
CryptoCurrency.xmr, pendingTransactionDescription.fee);
@override
Future<void> commit() async {
try {
monero_transaction_history.commitTransactionFromPointerAddress(
address: pendingTransactionDescription.pointerAddress);
} catch (e) {
final message = e.toString();
if (message.contains('Reason: double spend')) {
throw DoubleSpendException();
}
rethrow;
}
}
}