mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-25 17:46:44 +00:00
support utxo sets in wallet tx
This commit is contained in:
parent
f46d627755
commit
ebf7128ae5
2 changed files with 22 additions and 15 deletions
|
@ -828,7 +828,7 @@ public class Wallet extends Persistable implements Comparable<Wallet> {
|
||||||
//The new fee has meant that one of the change outputs is now dust. We pay too high a fee without change, but change is dust when added.
|
//The new fee has meant that one of the change outputs is now dust. We pay too high a fee without change, but change is dust when added.
|
||||||
if(numSets > 1 && differenceAmt / transaction.getVirtualSize() < noChangeFeeRate * 2) {
|
if(numSets > 1 && differenceAmt / transaction.getVirtualSize() < noChangeFeeRate * 2) {
|
||||||
//Maximize privacy. Pay a higher fee to keep multiple output sets.
|
//Maximize privacy. Pay a higher fee to keep multiple output sets.
|
||||||
return new WalletTransaction(this, transaction, utxoSelectors, selectedUtxos, txPayments, differenceAmt);
|
return new WalletTransaction(this, transaction, utxoSelectors, selectedUtxoSets, txPayments, differenceAmt);
|
||||||
} else {
|
} else {
|
||||||
//Maxmize efficiency. Increase value required from inputs and try again.
|
//Maxmize efficiency. Increase value required from inputs and try again.
|
||||||
valueRequiredAmt = totalSelectedAmt + 1;
|
valueRequiredAmt = totalSelectedAmt + 1;
|
||||||
|
@ -836,10 +836,10 @@ public class Wallet extends Persistable implements Comparable<Wallet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WalletTransaction(this, transaction, utxoSelectors, selectedUtxos, txPayments, changeMap, changeFeeRequiredAmt);
|
return new WalletTransaction(this, transaction, utxoSelectors, selectedUtxoSets, txPayments, changeMap, changeFeeRequiredAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WalletTransaction(this, transaction, utxoSelectors, selectedUtxos, txPayments, differenceAmt);
|
return new WalletTransaction(this, transaction, utxoSelectors, selectedUtxoSets, txPayments, differenceAmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,7 @@ import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
||||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||||
import com.sparrowwallet.drongo.psbt.PSBT;
|
import com.sparrowwallet.drongo.psbt.PSBT;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WalletTransaction contains a draft transaction along with associated metadata. The draft transaction has empty signatures but is otherwise complete.
|
* WalletTransaction contains a draft transaction along with associated metadata. The draft transaction has empty signatures but is otherwise complete.
|
||||||
|
@ -18,25 +15,25 @@ public class WalletTransaction {
|
||||||
private final Wallet wallet;
|
private final Wallet wallet;
|
||||||
private final Transaction transaction;
|
private final Transaction transaction;
|
||||||
private final List<UtxoSelector> utxoSelectors;
|
private final List<UtxoSelector> utxoSelectors;
|
||||||
private final Map<BlockTransactionHashIndex, WalletNode> selectedUtxos;
|
private final List<Map<BlockTransactionHashIndex, WalletNode>> selectedUtxoSets;
|
||||||
private final List<Payment> payments;
|
private final List<Payment> payments;
|
||||||
private final Map<WalletNode, Long> changeMap;
|
private final Map<WalletNode, Long> changeMap;
|
||||||
private final long fee;
|
private final long fee;
|
||||||
private final Map<Sha256Hash, BlockTransaction> inputTransactions;
|
private final Map<Sha256Hash, BlockTransaction> inputTransactions;
|
||||||
|
|
||||||
public WalletTransaction(Wallet wallet, Transaction transaction, List<UtxoSelector> utxoSelectors, Map<BlockTransactionHashIndex, WalletNode> selectedUtxos, List<Payment> payments, long fee) {
|
public WalletTransaction(Wallet wallet, Transaction transaction, List<UtxoSelector> utxoSelectors, List<Map<BlockTransactionHashIndex, WalletNode>> selectedUtxoSets, List<Payment> payments, long fee) {
|
||||||
this(wallet, transaction, utxoSelectors, selectedUtxos, payments, Collections.emptyMap(), fee);
|
this(wallet, transaction, utxoSelectors, selectedUtxoSets, payments, Collections.emptyMap(), fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WalletTransaction(Wallet wallet, Transaction transaction, List<UtxoSelector> utxoSelectors, Map<BlockTransactionHashIndex, WalletNode> selectedUtxos, List<Payment> payments, Map<WalletNode, Long> changeMap, long fee) {
|
public WalletTransaction(Wallet wallet, Transaction transaction, List<UtxoSelector> utxoSelectors, List<Map<BlockTransactionHashIndex, WalletNode>> selectedUtxoSets, List<Payment> payments, Map<WalletNode, Long> changeMap, long fee) {
|
||||||
this(wallet, transaction, utxoSelectors, selectedUtxos, payments, changeMap, fee, Collections.emptyMap());
|
this(wallet, transaction, utxoSelectors, selectedUtxoSets, payments, changeMap, fee, Collections.emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
public WalletTransaction(Wallet wallet, Transaction transaction, List<UtxoSelector> utxoSelectors, Map<BlockTransactionHashIndex, WalletNode> selectedUtxos, List<Payment> payments, Map<WalletNode, Long> changeMap, long fee, Map<Sha256Hash, BlockTransaction> inputTransactions) {
|
public WalletTransaction(Wallet wallet, Transaction transaction, List<UtxoSelector> utxoSelectors, List<Map<BlockTransactionHashIndex, WalletNode>> selectedUtxoSets, List<Payment> payments, Map<WalletNode, Long> changeMap, long fee, Map<Sha256Hash, BlockTransaction> inputTransactions) {
|
||||||
this.wallet = wallet;
|
this.wallet = wallet;
|
||||||
this.transaction = transaction;
|
this.transaction = transaction;
|
||||||
this.utxoSelectors = utxoSelectors;
|
this.utxoSelectors = utxoSelectors;
|
||||||
this.selectedUtxos = selectedUtxos;
|
this.selectedUtxoSets = selectedUtxoSets;
|
||||||
this.payments = payments;
|
this.payments = payments;
|
||||||
this.changeMap = changeMap;
|
this.changeMap = changeMap;
|
||||||
this.fee = fee;
|
this.fee = fee;
|
||||||
|
@ -60,9 +57,19 @@ public class WalletTransaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<BlockTransactionHashIndex, WalletNode> getSelectedUtxos() {
|
public Map<BlockTransactionHashIndex, WalletNode> getSelectedUtxos() {
|
||||||
|
if(selectedUtxoSets.size() == 1) {
|
||||||
|
return selectedUtxoSets.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<BlockTransactionHashIndex, WalletNode> selectedUtxos = new LinkedHashMap<>();
|
||||||
|
selectedUtxoSets.forEach(selectedUtxos::putAll);
|
||||||
return selectedUtxos;
|
return selectedUtxos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Map<BlockTransactionHashIndex, WalletNode>> getSelectedUtxoSets() {
|
||||||
|
return selectedUtxoSets;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Payment> getPayments() {
|
public List<Payment> getPayments() {
|
||||||
return payments;
|
return payments;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +91,7 @@ public class WalletTransaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTotal() {
|
public long getTotal() {
|
||||||
return selectedUtxos.keySet().stream().mapToLong(BlockTransactionHashIndex::getValue).sum();
|
return getSelectedUtxos().keySet().stream().mapToLong(BlockTransactionHashIndex::getValue).sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Sha256Hash, BlockTransaction> getInputTransactions() {
|
public Map<Sha256Hash, BlockTransaction> getInputTransactions() {
|
||||||
|
|
Loading…
Reference in a new issue