From 4d51bb40c2eeea6fde1789c81fc633fb890d9137 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 14 Jul 2020 13:36:43 +0200 Subject: [PATCH] refactor utxo selector creation --- drongo | 2 +- .../sparrow/wallet/SendController.java | 28 ++++--------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/drongo b/drongo index 9d272c0e..832ca8f2 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 9d272c0eb2785f0d4f745f7d1ede115e91ab4e28 +Subproject commit 832ca8f257559864823c83d8d29dc2276f44fa51 diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index deb83016..c46e4d0b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -315,34 +315,16 @@ public class SendController extends WalletFormController implements Initializabl walletTransactionProperty.setValue(null); } - private List getUtxoSelectors() { + private List getUtxoSelectors() throws InvalidAddressException { if(utxoSelectorProperty.get() != null) { return List.of(utxoSelectorProperty.get()); } - return List.of(getBnBSelector(), getKnapsackSelector()); - } + Wallet wallet = getWalletForm().getWallet(); + long noInputsFee = wallet.getNoInputsFee(getRecipientAddress(), getFeeRate()); + long costOfChange = wallet.getCostOfChange(getFeeRate(), getMinimumFeeRate()); - private UtxoSelector getBnBSelector() { - try { - int noInputsWeightUnits = getWalletForm().getWallet().getNoInputsWeightUnits(getRecipientAddress()); - return new BnBUtxoSelector(getWalletForm().getWallet(), noInputsWeightUnits, getFeeRate(), getMinimumFeeRate()); - } catch(InvalidAddressException e) { - throw new RuntimeException(e); - } - } - - private UtxoSelector getKnapsackSelector() { - return new KnapsackUtxoSelector(); - } - - private UtxoSelector getPrioritySelector() { - Integer blockHeight = AppController.getCurrentBlockHeight(); - if(blockHeight == null) { - blockHeight = getWalletForm().getWallet().getStoredBlockHeight(); - } - - return new PriorityUtxoSelector(blockHeight); + return List.of(new BnBUtxoSelector(noInputsFee, costOfChange), new KnapsackUtxoSelector(noInputsFee)); } private boolean isValidRecipientAddress() {