mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 18:16:45 +00:00
handle user set fee
This commit is contained in:
parent
ccf7de9f62
commit
2ff9c94c62
2 changed files with 15 additions and 3 deletions
|
@ -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;
|
long valueRequiredAmt = recipientAmount;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
@ -279,7 +279,7 @@ public class Wallet {
|
||||||
//Add recipient output
|
//Add recipient output
|
||||||
transaction.addOutput(recipientAmount, recipientAddress);
|
transaction.addOutput(recipientAmount, recipientAddress);
|
||||||
int noChangeVSize = transaction.getVirtualSize();
|
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
|
//Calculate what is left over from selected utxos after paying recipient
|
||||||
long differenceAmt = totalSelectedAmt - recipientAmount;
|
long differenceAmt = totalSelectedAmt - recipientAmount;
|
||||||
|
@ -298,7 +298,7 @@ public class Wallet {
|
||||||
if(changeAmt > dustThreshold) {
|
if(changeAmt > dustThreshold) {
|
||||||
//Change output is required, determine new fee once change output has been added
|
//Change output is required, determine new fee once change output has been added
|
||||||
int changeVSize = noChangeVSize + changeOutput.getLength();
|
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
|
//Recalculate the change amount with the new fee
|
||||||
changeAmt = differenceAmt - changeFeeRequiredAmt;
|
changeAmt = differenceAmt - changeFeeRequiredAmt;
|
||||||
|
|
|
@ -64,6 +64,10 @@ public class WalletTransaction {
|
||||||
return changeNode;
|
return changeNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Address getChangeAddress() {
|
||||||
|
return getWallet().getAddress(getChangeNode());
|
||||||
|
}
|
||||||
|
|
||||||
public long getChangeAmount() {
|
public long getChangeAmount() {
|
||||||
return changeAmount;
|
return changeAmount;
|
||||||
}
|
}
|
||||||
|
@ -71,4 +75,12 @@ public class WalletTransaction {
|
||||||
public long getFee() {
|
public long getFee() {
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getTotal() {
|
||||||
|
return selectedUtxos.keySet().stream().mapToLong(BlockTransactionHashIndex::getValue).sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getFeePercentage() {
|
||||||
|
return (double)getFee() / getTotal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue