wallettx understand if coin control present

This commit is contained in:
Craig Raw 2020-07-07 13:58:29 +02:00
parent 5d14be5c9c
commit 6135338df2
2 changed files with 16 additions and 5 deletions

View file

@ -318,10 +318,10 @@ public class Wallet {
//Add change output
transaction.addOutput(changeAmt, getOutputScript(changeNode));
return new WalletTransaction(this, transaction, selectedUtxos, recipientAddress, recipientAmount, changeNode, changeAmt, changeFeeRequiredAmt);
return new WalletTransaction(this, transaction, utxoSelectors, selectedUtxos, recipientAddress, recipientAmount, changeNode, changeAmt, changeFeeRequiredAmt);
}
return new WalletTransaction(this, transaction, selectedUtxos, recipientAddress, recipientAmount, differenceAmt);
return new WalletTransaction(this, transaction, utxoSelectors, selectedUtxos, recipientAddress, recipientAmount, differenceAmt);
}
}

View file

@ -4,6 +4,7 @@ import com.sparrowwallet.drongo.address.Address;
import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.psbt.PSBT;
import java.util.List;
import java.util.Map;
/**
@ -13,6 +14,7 @@ import java.util.Map;
public class WalletTransaction {
private final Wallet wallet;
private final Transaction transaction;
private final List<UtxoSelector> utxoSelectors;
private final Map<BlockTransactionHashIndex, WalletNode> selectedUtxos;
private final Address recipientAddress;
private final long recipientAmount;
@ -20,13 +22,14 @@ public class WalletTransaction {
private final long changeAmount;
private final long fee;
public WalletTransaction(Wallet wallet, Transaction transaction, Map<BlockTransactionHashIndex, WalletNode> selectedUtxos, Address recipientAddress, long recipientAmount, long fee) {
this(wallet, transaction, selectedUtxos, recipientAddress, recipientAmount, null, 0L, fee);
public WalletTransaction(Wallet wallet, Transaction transaction, List<UtxoSelector> utxoSelectors, Map<BlockTransactionHashIndex, WalletNode> selectedUtxos, Address recipientAddress, long recipientAmount, long fee) {
this(wallet, transaction, utxoSelectors, selectedUtxos, recipientAddress, recipientAmount, null, 0L, fee);
}
public WalletTransaction(Wallet wallet, Transaction transaction, Map<BlockTransactionHashIndex, WalletNode> selectedUtxos, Address recipientAddress, long recipientAmount, WalletNode changeNode, long changeAmount, long fee) {
public WalletTransaction(Wallet wallet, Transaction transaction, List<UtxoSelector> utxoSelectors, Map<BlockTransactionHashIndex, WalletNode> selectedUtxos, Address recipientAddress, long recipientAmount, WalletNode changeNode, long changeAmount, long fee) {
this.wallet = wallet;
this.transaction = transaction;
this.utxoSelectors = utxoSelectors;
this.selectedUtxos = selectedUtxos;
this.recipientAddress = recipientAddress;
this.recipientAmount = recipientAmount;
@ -48,6 +51,10 @@ public class WalletTransaction {
return transaction;
}
public List<UtxoSelector> getUtxoSelectors() {
return utxoSelectors;
}
public Map<BlockTransactionHashIndex, WalletNode> getSelectedUtxos() {
return selectedUtxos;
}
@ -83,4 +90,8 @@ public class WalletTransaction {
public double getFeePercentage() {
return (double)getFee() / getTotal();
}
public boolean isCoinControlUsed() {
return !utxoSelectors.isEmpty() && utxoSelectors.get(0) instanceof PresetUtxoSelector;
}
}