mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 13:26:44 +00:00
bnb and knapsack selectors
This commit is contained in:
parent
603f3036fa
commit
e7b511fc74
3 changed files with 18 additions and 33 deletions
2
drongo
2
drongo
|
@ -1 +1 @@
|
||||||
Subproject commit 0a6e247163f737926b582c12c8ceb1b8161e7a4a
|
Subproject commit 9d272c0eb2785f0d4f745f7d1ede115e91ab4e28
|
|
@ -1,14 +0,0 @@
|
||||||
package com.sparrowwallet.sparrow.wallet;
|
|
||||||
|
|
||||||
import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex;
|
|
||||||
import com.sparrowwallet.drongo.wallet.UtxoSelector;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
public class MaxUtxoSelector implements UtxoSelector {
|
|
||||||
@Override
|
|
||||||
public Collection<BlockTransactionHashIndex> select(long targetValue, Collection<BlockTransactionHashIndex> candidates) {
|
|
||||||
return Collections.unmodifiableCollection(candidates);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,7 +5,6 @@ import com.sparrowwallet.drongo.BitcoinUnit;
|
||||||
import com.sparrowwallet.drongo.address.Address;
|
import com.sparrowwallet.drongo.address.Address;
|
||||||
import com.sparrowwallet.drongo.address.InvalidAddressException;
|
import com.sparrowwallet.drongo.address.InvalidAddressException;
|
||||||
import com.sparrowwallet.drongo.address.P2PKHAddress;
|
import com.sparrowwallet.drongo.address.P2PKHAddress;
|
||||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
|
||||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||||
import com.sparrowwallet.drongo.protocol.TransactionOutput;
|
import com.sparrowwallet.drongo.protocol.TransactionOutput;
|
||||||
import com.sparrowwallet.drongo.wallet.*;
|
import com.sparrowwallet.drongo.wallet.*;
|
||||||
|
@ -207,7 +206,10 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
feeRate.setText("Unknown");
|
feeRate.setText("Unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
setTargetBlocks(5);
|
int defaultTarget = TARGET_BLOCKS_RANGE.get((TARGET_BLOCKS_RANGE.size() / 2) - 1);
|
||||||
|
int index = TARGET_BLOCKS_RANGE.indexOf(defaultTarget);
|
||||||
|
targetBlocks.setValue(index);
|
||||||
|
feeRatesChart.select(defaultTarget);
|
||||||
|
|
||||||
fee.setTextFormatter(new CoinTextFormatter());
|
fee.setTextFormatter(new CoinTextFormatter());
|
||||||
fee.textProperty().addListener(feeListener);
|
fee.textProperty().addListener(feeListener);
|
||||||
|
@ -293,8 +295,9 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
private void updateTransaction(boolean sendAll) {
|
private void updateTransaction(boolean sendAll) {
|
||||||
try {
|
try {
|
||||||
Address recipientAddress = getRecipientAddress();
|
Address recipientAddress = getRecipientAddress();
|
||||||
Long recipientAmount = sendAll ? Long.valueOf(1L) : getRecipientValueSats();
|
long recipientDustThreshold = getRecipientDustThreshold();
|
||||||
if(recipientAmount != null && recipientAmount > getRecipientDustThreshold() && (!userFeeSet.get() || (getFeeValueSats() != null && getFeeValueSats() > 0))) {
|
Long recipientAmount = sendAll ? Long.valueOf(recipientDustThreshold + 1) : getRecipientValueSats();
|
||||||
|
if(recipientAmount != null && recipientAmount > recipientDustThreshold && (!userFeeSet.get() || (getFeeValueSats() != null && getFeeValueSats() > 0))) {
|
||||||
Wallet wallet = getWalletForm().getWallet();
|
Wallet wallet = getWalletForm().getWallet();
|
||||||
Long userFee = userFeeSet.get() ? getFeeValueSats() : null;
|
Long userFee = userFeeSet.get() ? getFeeValueSats() : null;
|
||||||
WalletTransaction walletTransaction = wallet.createWalletTransaction(getUtxoSelectors(), recipientAddress, recipientAmount, getFeeRate(), getMinimumFeeRate(), userFee, sendAll);
|
WalletTransaction walletTransaction = wallet.createWalletTransaction(getUtxoSelectors(), recipientAddress, recipientAmount, getFeeRate(), getMinimumFeeRate(), userFee, sendAll);
|
||||||
|
@ -317,33 +320,29 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
return List.of(utxoSelectorProperty.get());
|
return List.of(utxoSelectorProperty.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
return getBnBSelector();
|
return List.of(getBnBSelector(), getKnapsackSelector());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<UtxoSelector> getBnBSelector() {
|
private UtxoSelector getBnBSelector() {
|
||||||
try {
|
try {
|
||||||
Transaction transaction = new Transaction();
|
int noInputsWeightUnits = getWalletForm().getWallet().getNoInputsWeightUnits(getRecipientAddress());
|
||||||
if(Arrays.asList(ScriptType.WITNESS_TYPES).contains(getWalletForm().getWallet().getScriptType())) {
|
return new BnBUtxoSelector(getWalletForm().getWallet(), noInputsWeightUnits, getFeeRate(), getMinimumFeeRate());
|
||||||
transaction.setSegwitVersion(0);
|
|
||||||
}
|
|
||||||
transaction.addOutput(getRecipientValueSats(), getRecipientAddress());
|
|
||||||
int noInputsWeightUnits = transaction.getWeightUnits();
|
|
||||||
|
|
||||||
UtxoSelector bnbSelector = new BnBUtxoSelector(getWalletForm().getWallet(), noInputsWeightUnits, getFeeRate(), getMinimumFeeRate());
|
|
||||||
return List.of(bnbSelector);
|
|
||||||
} catch(InvalidAddressException e) {
|
} catch(InvalidAddressException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<UtxoSelector> getPrioritySelector() {
|
private UtxoSelector getKnapsackSelector() {
|
||||||
|
return new KnapsackUtxoSelector();
|
||||||
|
}
|
||||||
|
|
||||||
|
private UtxoSelector getPrioritySelector() {
|
||||||
Integer blockHeight = AppController.getCurrentBlockHeight();
|
Integer blockHeight = AppController.getCurrentBlockHeight();
|
||||||
if(blockHeight == null) {
|
if(blockHeight == null) {
|
||||||
blockHeight = getWalletForm().getWallet().getStoredBlockHeight();
|
blockHeight = getWalletForm().getWallet().getStoredBlockHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
UtxoSelector priorityUtxoSelector = new PriorityUtxoSelector(blockHeight);
|
return new PriorityUtxoSelector(blockHeight);
|
||||||
return List.of(priorityUtxoSelector);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidRecipientAddress() {
|
private boolean isValidRecipientAddress() {
|
||||||
|
|
Loading…
Reference in a new issue