mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-29 15:09:23 +00:00
291aa710c6
* Add initial checkbox for RBF * minor progress * minor progress * Minor progress * Debugging RBF * Minor fix * Fix RBF transaction inputs (now it's working) * New versions Fix issues with Monero.com * Add sending for Solana tokens exchanges * Add default keyword for P2WPKH [skip ci] * chore: Switch solana commitment to confirmed to reduced blockhash expiration (#1313) * Modify test workflow to send arm64-v8a build only * Fix workflow build path * Remove unnecessary reverse of txId * Update Replace by fee with the new bitcoin base implementation * btc custom fee priority * add feeRate to btc credential * UI fixes * add check if the change covers the fee * Update settings_store.dart * add check confirmation for rbf * add a check to see if the change is sufficient for the new fee * addressing PR comments * update localization files * addressing PR comments * minor fixes * Update transaction_details_view_model.dart * Minor Fix for building Monero.com [skip ci] * update localization files * add bump fee page * update localisation files * Update cw_bitcoin.dart * fix merge conflict * fix UI issues * Fix Conflicts, Fix RBF flow, some enhancements * prevent default custom fee rate * hide outputs and inputs items * minor fix [skip ci] * addressing PR comments * remove rbf checkbox * default picker value * minor ui change [skip ci] * min fee rate [skip ci] * Minor fix and some minor enhancements --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com> Co-authored-by: Adegoke David <64401859+Blazebrain@users.noreply.github.com>
95 lines
2.7 KiB
Dart
95 lines
2.7 KiB
Dart
import 'package:cw_bitcoin/exceptions.dart';
|
|
import 'package:bitcoin_base/bitcoin_base.dart';
|
|
import 'package:cw_core/pending_transaction.dart';
|
|
import 'package:cw_bitcoin/electrum.dart';
|
|
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
|
|
import 'package:cw_bitcoin/electrum_transaction_info.dart';
|
|
import 'package:cw_core/transaction_direction.dart';
|
|
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.feeRate,
|
|
this.network,
|
|
required this.hasChange,
|
|
this.isSendAll = false,
|
|
this.hasTaprootInputs = false,
|
|
}) : _listeners = <void Function(ElectrumTransactionInfo transaction)>[];
|
|
|
|
final WalletType type;
|
|
final BtcTransaction _tx;
|
|
final ElectrumClient electrumClient;
|
|
final int amount;
|
|
final int fee;
|
|
final String feeRate;
|
|
final BasedUtxoNetwork? network;
|
|
final bool hasChange;
|
|
final bool isSendAll;
|
|
final bool hasTaprootInputs;
|
|
|
|
@override
|
|
String get id => _tx.txId();
|
|
|
|
@override
|
|
String get hex => _tx.serialize();
|
|
|
|
@override
|
|
String get amountFormatted => bitcoinAmountToString(amount: amount);
|
|
|
|
@override
|
|
String get feeFormatted => bitcoinAmountToString(amount: fee);
|
|
|
|
@override
|
|
int? get outputCount => _tx.outputs.length;
|
|
|
|
final List<void Function(ElectrumTransactionInfo transaction)> _listeners;
|
|
|
|
@override
|
|
Future<void> commit() async {
|
|
int? callId;
|
|
|
|
final result = await electrumClient.broadcastTransaction(
|
|
transactionRaw: hex, network: network, idCallback: (id) => callId = id);
|
|
|
|
if (result.isEmpty) {
|
|
if (callId != null) {
|
|
final error = electrumClient.getErrorMessage(callId!);
|
|
|
|
if (error.contains("dust")) {
|
|
if (hasChange) {
|
|
throw BitcoinTransactionCommitFailedDustChange();
|
|
} else if (!isSendAll) {
|
|
throw BitcoinTransactionCommitFailedDustOutput();
|
|
} else {
|
|
throw BitcoinTransactionCommitFailedDustOutputSendAll();
|
|
}
|
|
}
|
|
|
|
if (error.contains("bad-txns-vout-negative")) {
|
|
throw BitcoinTransactionCommitFailedVoutNegative();
|
|
}
|
|
}
|
|
throw BitcoinTransactionCommitFailed();
|
|
}
|
|
|
|
_listeners.forEach((listener) => listener(transactionInfo()));
|
|
}
|
|
|
|
void addListener(void Function(ElectrumTransactionInfo transaction) listener) =>
|
|
_listeners.add(listener);
|
|
|
|
ElectrumTransactionInfo transactionInfo() => ElectrumTransactionInfo(type,
|
|
id: id,
|
|
height: 0,
|
|
amount: amount,
|
|
direction: TransactionDirection.outgoing,
|
|
date: DateTime.now(),
|
|
isPending: true,
|
|
confirmations: 0,
|
|
fee: fee);
|
|
}
|