handle user set fee

This commit is contained in:
Craig Raw 2020-07-05 15:01:12 +02:00
parent ccf7de9f62
commit 2ff9c94c62
2 changed files with 15 additions and 3 deletions

View file

@ -248,7 +248,7 @@ public class Wallet {
}
}
public WalletTransaction createWalletTransaction(List<UtxoSelector> utxoSelectors, Address recipientAddress, long recipientAmount, double feeRate) throws InsufficientFundsException {
public WalletTransaction createWalletTransaction(List<UtxoSelector> utxoSelectors, Address recipientAddress, long recipientAmount, double feeRate, Long fee) throws InsufficientFundsException {
long valueRequiredAmt = recipientAmount;
while(true) {
@ -279,7 +279,7 @@ public class Wallet {
//Add recipient output
transaction.addOutput(recipientAmount, recipientAddress);
int noChangeVSize = transaction.getVirtualSize();
long noChangeFeeRequiredAmt = (long)(feeRate * noChangeVSize);
long noChangeFeeRequiredAmt = (fee == null ? (long)(feeRate * noChangeVSize) : fee);
//Calculate what is left over from selected utxos after paying recipient
long differenceAmt = totalSelectedAmt - recipientAmount;
@ -298,7 +298,7 @@ public class Wallet {
if(changeAmt > dustThreshold) {
//Change output is required, determine new fee once change output has been added
int changeVSize = noChangeVSize + changeOutput.getLength();
long changeFeeRequiredAmt = (long)(feeRate * changeVSize);
long changeFeeRequiredAmt = (fee == null ? (long)(feeRate * changeVSize) : fee);
//Recalculate the change amount with the new fee
changeAmt = differenceAmt - changeFeeRequiredAmt;

View file

@ -64,6 +64,10 @@ public class WalletTransaction {
return changeNode;
}
public Address getChangeAddress() {
return getWallet().getAddress(getChangeNode());
}
public long getChangeAmount() {
return changeAmount;
}
@ -71,4 +75,12 @@ public class WalletTransaction {
public long getFee() {
return fee;
}
public long getTotal() {
return selectedUtxos.keySet().stream().mapToLong(BlockTransactionHashIndex::getValue).sum();
}
public double getFeePercentage() {
return (double)getFee() / getTotal();
}
}