From 6c9b580d4ff618eedca195cdd3ca90a33a1cb2d5 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 21 Oct 2025 12:06:00 +0200 Subject: [PATCH] refactor to use transaction parameters record object when creating a wallet transaction --- drongo | 2 +- .../sparrow/paynym/PayNymController.java | 5 +- .../sparrow/wallet/SendController.java | 51 +++++-------------- 3 files changed, 16 insertions(+), 42 deletions(-) diff --git a/drongo b/drongo index 4e68815f..e975cbe6 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 4e68815fa977a45a7caddead35e5d0f90f5e8fd6 +Subproject commit e975cbe6f8d8574785124e6db5780d0541e20024 diff --git a/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java b/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java index 76f58b15..c21bf467 100644 --- a/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java +++ b/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java @@ -624,8 +624,9 @@ public class PayNymController { List utxoSelectors = List.of(utxos == null ? new KnapsackUtxoSelector(noInputsFee) : new PresetUtxoSelector(utxos, true, false)); List txoFilters = List.of(new SpentTxoFilter(), new FrozenTxoFilter(), new CoinbaseTxoFilter(wallet)); - return wallet.createWalletTransaction(utxoSelectors, txoFilters, payments, opReturns, Collections.emptySet(), feeRate, minimumFeeRate, minRelayFeeRate, null, - AppServices.getCurrentBlockHeight(), groupByAddress, includeMempoolOutputs, true); + TransactionParameters params = new TransactionParameters(utxoSelectors, txoFilters, payments, opReturns, Collections.emptySet(), + feeRate, minimumFeeRate, minRelayFeeRate, null, AppServices.getCurrentBlockHeight(), groupByAddress, includeMempoolOutputs, true); + return wallet.createWalletTransaction(params); } private Map getNotificationTransaction(PaymentCode externalPaymentCode) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index 435b5018..63907943 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -619,10 +619,11 @@ public class SendController extends WalletFormController implements Initializabl boolean allowRbf = (replacedTransaction == null || replacedTransaction.getTransaction().isReplaceByFee()) && payments.stream().noneMatch(payment -> payment instanceof SilentPayment); - walletTransactionService = new WalletTransactionService(wallet, getUtxoSelectors(payments), getTxoFilters(), + TransactionParameters params = new TransactionParameters(getUtxoSelectors(payments), getTxoFilters(), payments, opReturnsList, excludedChangeNodes, feeRate, getMinimumFeeRate(), minRelayFeeRate, userFee, - currentBlockHeight, groupByAddress, includeMempoolOutputs, replacedTransaction, allowRbf); + currentBlockHeight, groupByAddress, includeMempoolOutputs, allowRbf); + walletTransactionService = new WalletTransactionService(wallet, params, replacedTransaction); walletTransactionService.setOnSucceeded(event -> { if(!walletTransactionService.isIgnoreResult()) { walletTransactionProperty.setValue(walletTransactionService.getValue()); @@ -685,42 +686,14 @@ public class SendController extends WalletFormController implements Initializabl private static class WalletTransactionService extends Service { private final Wallet wallet; - private final List utxoSelectors; - private final List txoFilters; - private final List payments; - private final List opReturns; - private final Set excludedChangeNodes; - private final double feeRate; - private final double longTermFeeRate; - private final double minRelayFeeRate; - private final Long fee; - private final Integer currentBlockHeight; - private final boolean groupByAddress; - private final boolean includeMempoolOutputs; + private final TransactionParameters params; private final BlockTransaction replacedTransaction; - private final boolean allowRbf; private boolean ignoreResult; - public WalletTransactionService(Wallet wallet, List utxoSelectors, List txoFilters, - List payments, List opReturns, Set excludedChangeNodes, - double feeRate, double longTermFeeRate, double minRelayFeeRate, Long fee, - Integer currentBlockHeight, boolean groupByAddress, boolean includeMempoolOutputs, - BlockTransaction replacedTransaction, boolean allowRbf) { + public WalletTransactionService(Wallet wallet, TransactionParameters params, BlockTransaction replacedTransaction) { this.wallet = wallet; - this.utxoSelectors = utxoSelectors; - this.txoFilters = txoFilters; - this.payments = payments; - this.opReturns = opReturns; - this.excludedChangeNodes = excludedChangeNodes; - this.feeRate = feeRate; - this.longTermFeeRate = longTermFeeRate; - this.minRelayFeeRate = minRelayFeeRate; - this.fee = fee; - this.currentBlockHeight = currentBlockHeight; - this.groupByAddress = groupByAddress; - this.includeMempoolOutputs = includeMempoolOutputs; + this.params = params; this.replacedTransaction = replacedTransaction; - this.allowRbf = allowRbf; } @Override @@ -731,11 +704,11 @@ public class SendController extends WalletFormController implements Initializabl return getWalletTransaction(); } catch(InsufficientFundsException e) { if(e.getTargetValue() != null && replacedTransaction != null && wallet.isSafeToAddInputsOrOutputs(replacedTransaction) - && utxoSelectors.size() == 1 && utxoSelectors.getFirst() instanceof PresetUtxoSelector presetUtxoSelector) { + && params.utxoSelectors().size() == 1 && params.utxoSelectors().getFirst() instanceof PresetUtxoSelector presetUtxoSelector) { //Creating RBF transaction - include additional UTXOs if available to pay desired fee - List filters = new ArrayList<>(txoFilters); + List filters = new ArrayList<>(params.txoFilters()); filters.add(presetUtxoSelector.asExcludeTxoFilter()); - List outputGroups = wallet.getGroupedUtxos(filters, feeRate, AppServices.getMinimumRelayFeeRate(), Config.get().isGroupByAddress()) + List outputGroups = wallet.getGroupedUtxos(filters, params.feeRate(), AppServices.getMinimumRelayFeeRate(), Config.get().isGroupByAddress()) .stream().filter(outputGroup -> outputGroup.getEffectiveValue() >= 0).collect(Collectors.toList()); Collections.shuffle(outputGroups); @@ -756,8 +729,7 @@ public class SendController extends WalletFormController implements Initializabl private WalletTransaction getWalletTransaction() throws InsufficientFundsException { try { updateMessage("Selecting UTXOs..."); - return wallet.createWalletTransaction(utxoSelectors, txoFilters, payments, opReturns, excludedChangeNodes, - feeRate, longTermFeeRate, minRelayFeeRate, fee, currentBlockHeight, groupByAddress, includeMempoolOutputs, allowRbf); + return wallet.createWalletTransaction(params); } finally { updateMessage(""); } @@ -1265,8 +1237,9 @@ public class SendController extends WalletFormController implements Initializabl boolean groupByAddress = Config.get().isGroupByAddress(); boolean includeMempoolOutputs = Config.get().isIncludeMempoolOutputs(); - WalletTransaction finalWalletTx = decryptedWallet.createWalletTransaction(utxoSelectors, getTxoFilters(), walletTransaction.getPayments(), List.of(blindedPaymentCode), + TransactionParameters params = new TransactionParameters(utxoSelectors, getTxoFilters(), walletTransaction.getPayments(), List.of(blindedPaymentCode), excludedChangeNodes, feeRate, getMinimumFeeRate(), minRelayFeeRate, userFee, currentBlockHeight, groupByAddress, includeMempoolOutputs, true); + WalletTransaction finalWalletTx = decryptedWallet.createWalletTransaction(params); PSBT psbt = finalWalletTx.createPSBT(); decryptedWallet.sign(psbt); decryptedWallet.finalise(psbt);