WIP: very basic CPFP

This commit is contained in:
julian 2024-06-19 10:22:41 -06:00
parent e2c81a1af0
commit 318932022e
3 changed files with 24 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import '../../crypto_currency/crypto_currency.dart';
import '../../crypto_currency/interfaces/paynym_currency_interface.dart';
import '../intermediate/bip39_hd_wallet.dart';
import '../wallet_mixin_interfaces/coin_control_interface.dart';
import '../wallet_mixin_interfaces/cpfp_interface.dart';
import '../wallet_mixin_interfaces/electrumx_interface.dart';
import '../wallet_mixin_interfaces/paynym_interface.dart';
import '../wallet_mixin_interfaces/rbf_interface.dart';
@ -15,7 +16,8 @@ class BitcoinWallet<T extends PaynymCurrencyInterface> extends Bip39HDWallet<T>
ElectrumXInterface<T>,
CoinControlInterface,
PaynymInterface<T>,
RbfInterface<T> {
RbfInterface<T>,
CpfpInterface<T> {
@override
int get isarTransactionVersion => 2;

View file

@ -0,0 +1,7 @@
import '../../crypto_currency/interfaces/electrumx_currency_interface.dart';
import 'electrumx_interface.dart';
mixin CpfpInterface<T extends ElectrumXCurrencyInterface>
on ElectrumXInterface<T> {
//
}

View file

@ -26,6 +26,7 @@ import '../../models/tx_data.dart';
import '../impl/bitcoin_wallet.dart';
import '../impl/peercoin_wallet.dart';
import '../intermediate/bip39_hd_wallet.dart';
import 'cpfp_interface.dart';
import 'paynym_interface.dart';
mixin ElectrumXInterface<T extends ElectrumXCurrencyInterface>
@ -122,12 +123,16 @@ mixin ElectrumXInterface<T extends ElectrumXCurrencyInterface>
utxos ?? await mainDB.getUTXOs(walletId).findAll();
final currentChainHeight = await chainHeight;
final canCPFP = this is CpfpInterface && coinControl;
final spendableOutputs = availableOutputs
.where(
(e) =>
!e.isBlocked &&
(e.used != true) &&
e.isConfirmed(currentChainHeight, cryptoCurrency.minConfirms),
(canCPFP ||
e.isConfirmed(
currentChainHeight, cryptoCurrency.minConfirms)),
)
.toList();
final spendableSatoshiValue =
@ -1655,6 +1660,14 @@ mixin ElectrumXInterface<T extends ElectrumXCurrencyInterface>
final bool coinControl = utxos != null;
if (coinControl &&
this is CpfpInterface &&
txData.amount ==
(info.cachedBalance.spendable +
info.cachedBalance.pendingSpendable)) {
isSendAll = true;
}
final result = await coinSelection(
txData: txData.copyWith(feeRateAmount: -1),
isSendAll: isSendAll,