mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-04 11:06:44 +00:00
send all utxos support
This commit is contained in:
parent
2ff9c94c62
commit
5d14be5c9c
2 changed files with 33 additions and 1 deletions
|
@ -0,0 +1,25 @@
|
||||||
|
package com.sparrowwallet.drongo.wallet;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PresetUtxoSelector implements UtxoSelector {
|
||||||
|
private final Collection<BlockTransactionHashIndex> presetUtxos;
|
||||||
|
|
||||||
|
public PresetUtxoSelector(Collection<BlockTransactionHashIndex> presetUtxos) {
|
||||||
|
this.presetUtxos = presetUtxos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<BlockTransactionHashIndex> select(long targetValue, Collection<BlockTransactionHashIndex> candidates) {
|
||||||
|
List<BlockTransactionHashIndex> utxos = new ArrayList<>(presetUtxos);
|
||||||
|
utxos.retainAll(candidates);
|
||||||
|
|
||||||
|
return utxos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<BlockTransactionHashIndex> getPresetUtxos() {
|
||||||
|
return presetUtxos;
|
||||||
|
}
|
||||||
|
}
|
|
@ -248,7 +248,7 @@ public class Wallet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WalletTransaction createWalletTransaction(List<UtxoSelector> utxoSelectors, Address recipientAddress, long recipientAmount, double feeRate, Long fee) throws InsufficientFundsException {
|
public WalletTransaction createWalletTransaction(List<UtxoSelector> utxoSelectors, Address recipientAddress, long recipientAmount, double feeRate, Long fee, boolean sendAll) throws InsufficientFundsException {
|
||||||
long valueRequiredAmt = recipientAmount;
|
long valueRequiredAmt = recipientAmount;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
@ -281,6 +281,13 @@ public class Wallet {
|
||||||
int noChangeVSize = transaction.getVirtualSize();
|
int noChangeVSize = transaction.getVirtualSize();
|
||||||
long noChangeFeeRequiredAmt = (fee == null ? (long)(feeRate * noChangeVSize) : fee);
|
long noChangeFeeRequiredAmt = (fee == null ? (long)(feeRate * noChangeVSize) : fee);
|
||||||
|
|
||||||
|
//If sending all selected utxos, set the recipient amount to equal to total of those utxos less the no change fee
|
||||||
|
long maxSendAmt = totalSelectedAmt - noChangeFeeRequiredAmt;
|
||||||
|
if(sendAll && recipientAmount != maxSendAmt) {
|
||||||
|
recipientAmount = maxSendAmt;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//Calculate what is left over from selected utxos after paying recipient
|
//Calculate what is left over from selected utxos after paying recipient
|
||||||
long differenceAmt = totalSelectedAmt - recipientAmount;
|
long differenceAmt = totalSelectedAmt - recipientAmount;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue