mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
refactor to use transaction parameters record object when creating a wallet transaction
This commit is contained in:
parent
31909b7a15
commit
6c9b580d4f
3 changed files with 16 additions and 42 deletions
2
drongo
2
drongo
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4e68815fa977a45a7caddead35e5d0f90f5e8fd6
|
Subproject commit e975cbe6f8d8574785124e6db5780d0541e20024
|
||||||
|
|
@ -624,8 +624,9 @@ public class PayNymController {
|
||||||
List<UtxoSelector> utxoSelectors = List.of(utxos == null ? new KnapsackUtxoSelector(noInputsFee) : new PresetUtxoSelector(utxos, true, false));
|
List<UtxoSelector> utxoSelectors = List.of(utxos == null ? new KnapsackUtxoSelector(noInputsFee) : new PresetUtxoSelector(utxos, true, false));
|
||||||
List<TxoFilter> txoFilters = List.of(new SpentTxoFilter(), new FrozenTxoFilter(), new CoinbaseTxoFilter(wallet));
|
List<TxoFilter> txoFilters = List.of(new SpentTxoFilter(), new FrozenTxoFilter(), new CoinbaseTxoFilter(wallet));
|
||||||
|
|
||||||
return wallet.createWalletTransaction(utxoSelectors, txoFilters, payments, opReturns, Collections.emptySet(), feeRate, minimumFeeRate, minRelayFeeRate, null,
|
TransactionParameters params = new TransactionParameters(utxoSelectors, txoFilters, payments, opReturns, Collections.emptySet(),
|
||||||
AppServices.getCurrentBlockHeight(), groupByAddress, includeMempoolOutputs, true);
|
feeRate, minimumFeeRate, minRelayFeeRate, null, AppServices.getCurrentBlockHeight(), groupByAddress, includeMempoolOutputs, true);
|
||||||
|
return wallet.createWalletTransaction(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<BlockTransaction, WalletNode> getNotificationTransaction(PaymentCode externalPaymentCode) {
|
private Map<BlockTransaction, WalletNode> getNotificationTransaction(PaymentCode externalPaymentCode) {
|
||||||
|
|
|
||||||
|
|
@ -619,10 +619,11 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
boolean allowRbf = (replacedTransaction == null || replacedTransaction.getTransaction().isReplaceByFee())
|
boolean allowRbf = (replacedTransaction == null || replacedTransaction.getTransaction().isReplaceByFee())
|
||||||
&& payments.stream().noneMatch(payment -> payment instanceof SilentPayment);
|
&& payments.stream().noneMatch(payment -> payment instanceof SilentPayment);
|
||||||
|
|
||||||
walletTransactionService = new WalletTransactionService(wallet, getUtxoSelectors(payments), getTxoFilters(),
|
TransactionParameters params = new TransactionParameters(getUtxoSelectors(payments), getTxoFilters(),
|
||||||
payments, opReturnsList, excludedChangeNodes,
|
payments, opReturnsList, excludedChangeNodes,
|
||||||
feeRate, getMinimumFeeRate(), minRelayFeeRate, userFee,
|
feeRate, getMinimumFeeRate(), minRelayFeeRate, userFee,
|
||||||
currentBlockHeight, groupByAddress, includeMempoolOutputs, replacedTransaction, allowRbf);
|
currentBlockHeight, groupByAddress, includeMempoolOutputs, allowRbf);
|
||||||
|
walletTransactionService = new WalletTransactionService(wallet, params, replacedTransaction);
|
||||||
walletTransactionService.setOnSucceeded(event -> {
|
walletTransactionService.setOnSucceeded(event -> {
|
||||||
if(!walletTransactionService.isIgnoreResult()) {
|
if(!walletTransactionService.isIgnoreResult()) {
|
||||||
walletTransactionProperty.setValue(walletTransactionService.getValue());
|
walletTransactionProperty.setValue(walletTransactionService.getValue());
|
||||||
|
|
@ -685,42 +686,14 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
|
|
||||||
private static class WalletTransactionService extends Service<WalletTransaction> {
|
private static class WalletTransactionService extends Service<WalletTransaction> {
|
||||||
private final Wallet wallet;
|
private final Wallet wallet;
|
||||||
private final List<UtxoSelector> utxoSelectors;
|
private final TransactionParameters params;
|
||||||
private final List<TxoFilter> txoFilters;
|
|
||||||
private final List<Payment> payments;
|
|
||||||
private final List<byte[]> opReturns;
|
|
||||||
private final Set<WalletNode> 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 BlockTransaction replacedTransaction;
|
private final BlockTransaction replacedTransaction;
|
||||||
private final boolean allowRbf;
|
|
||||||
private boolean ignoreResult;
|
private boolean ignoreResult;
|
||||||
|
|
||||||
public WalletTransactionService(Wallet wallet, List<UtxoSelector> utxoSelectors, List<TxoFilter> txoFilters,
|
public WalletTransactionService(Wallet wallet, TransactionParameters params, BlockTransaction replacedTransaction) {
|
||||||
List<Payment> payments, List<byte[]> opReturns, Set<WalletNode> excludedChangeNodes,
|
|
||||||
double feeRate, double longTermFeeRate, double minRelayFeeRate, Long fee,
|
|
||||||
Integer currentBlockHeight, boolean groupByAddress, boolean includeMempoolOutputs,
|
|
||||||
BlockTransaction replacedTransaction, boolean allowRbf) {
|
|
||||||
this.wallet = wallet;
|
this.wallet = wallet;
|
||||||
this.utxoSelectors = utxoSelectors;
|
this.params = params;
|
||||||
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.replacedTransaction = replacedTransaction;
|
this.replacedTransaction = replacedTransaction;
|
||||||
this.allowRbf = allowRbf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -731,11 +704,11 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
return getWalletTransaction();
|
return getWalletTransaction();
|
||||||
} catch(InsufficientFundsException e) {
|
} catch(InsufficientFundsException e) {
|
||||||
if(e.getTargetValue() != null && replacedTransaction != null && wallet.isSafeToAddInputsOrOutputs(replacedTransaction)
|
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
|
//Creating RBF transaction - include additional UTXOs if available to pay desired fee
|
||||||
List<TxoFilter> filters = new ArrayList<>(txoFilters);
|
List<TxoFilter> filters = new ArrayList<>(params.txoFilters());
|
||||||
filters.add(presetUtxoSelector.asExcludeTxoFilter());
|
filters.add(presetUtxoSelector.asExcludeTxoFilter());
|
||||||
List<OutputGroup> outputGroups = wallet.getGroupedUtxos(filters, feeRate, AppServices.getMinimumRelayFeeRate(), Config.get().isGroupByAddress())
|
List<OutputGroup> outputGroups = wallet.getGroupedUtxos(filters, params.feeRate(), AppServices.getMinimumRelayFeeRate(), Config.get().isGroupByAddress())
|
||||||
.stream().filter(outputGroup -> outputGroup.getEffectiveValue() >= 0).collect(Collectors.toList());
|
.stream().filter(outputGroup -> outputGroup.getEffectiveValue() >= 0).collect(Collectors.toList());
|
||||||
Collections.shuffle(outputGroups);
|
Collections.shuffle(outputGroups);
|
||||||
|
|
||||||
|
|
@ -756,8 +729,7 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
private WalletTransaction getWalletTransaction() throws InsufficientFundsException {
|
private WalletTransaction getWalletTransaction() throws InsufficientFundsException {
|
||||||
try {
|
try {
|
||||||
updateMessage("Selecting UTXOs...");
|
updateMessage("Selecting UTXOs...");
|
||||||
return wallet.createWalletTransaction(utxoSelectors, txoFilters, payments, opReturns, excludedChangeNodes,
|
return wallet.createWalletTransaction(params);
|
||||||
feeRate, longTermFeeRate, minRelayFeeRate, fee, currentBlockHeight, groupByAddress, includeMempoolOutputs, allowRbf);
|
|
||||||
} finally {
|
} finally {
|
||||||
updateMessage("");
|
updateMessage("");
|
||||||
}
|
}
|
||||||
|
|
@ -1265,8 +1237,9 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
boolean groupByAddress = Config.get().isGroupByAddress();
|
boolean groupByAddress = Config.get().isGroupByAddress();
|
||||||
boolean includeMempoolOutputs = Config.get().isIncludeMempoolOutputs();
|
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);
|
excludedChangeNodes, feeRate, getMinimumFeeRate(), minRelayFeeRate, userFee, currentBlockHeight, groupByAddress, includeMempoolOutputs, true);
|
||||||
|
WalletTransaction finalWalletTx = decryptedWallet.createWalletTransaction(params);
|
||||||
PSBT psbt = finalWalletTx.createPSBT();
|
PSBT psbt = finalWalletTx.createPSBT();
|
||||||
decryptedWallet.sign(psbt);
|
decryptedWallet.sign(psbt);
|
||||||
decryptedWallet.finalise(psbt);
|
decryptedWallet.finalise(psbt);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue