mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 18:16:45 +00:00
calculate dust threshold for multiple outputs
This commit is contained in:
parent
8b07336d71
commit
c4f5218f29
1 changed files with 8 additions and 6 deletions
|
@ -361,25 +361,27 @@ public class Wallet {
|
||||||
/**
|
/**
|
||||||
* Determines the fee for a transaction from this wallet that has one output and no inputs
|
* Determines the fee for a transaction from this wallet that has one output and no inputs
|
||||||
*
|
*
|
||||||
* @param recipientAddress The address to create the output to send to
|
* @param payments The payment details to create the output to send to
|
||||||
* @return The determined fee
|
* @return The determined fee
|
||||||
*/
|
*/
|
||||||
public long getNoInputsFee(Address recipientAddress, Double feeRate) {
|
public long getNoInputsFee(List<Payment> payments, Double feeRate) {
|
||||||
return (long)Math.ceil((double)getNoInputsWeightUnits(recipientAddress) * feeRate / (double)WITNESS_SCALE_FACTOR);
|
return (long)Math.ceil((double)getNoInputsWeightUnits(payments) * feeRate / (double)WITNESS_SCALE_FACTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the weight units for a transaction from this wallet that has one output and no inputs
|
* Determines the weight units for a transaction from this wallet that has one output and no inputs
|
||||||
*
|
*
|
||||||
* @param recipientAddress The address to create the output to send to
|
* @param payments The payment details to create the output to send to
|
||||||
* @return The determined weight units
|
* @return The determined weight units
|
||||||
*/
|
*/
|
||||||
public int getNoInputsWeightUnits(Address recipientAddress) {
|
public int getNoInputsWeightUnits(List<Payment> payments) {
|
||||||
Transaction transaction = new Transaction();
|
Transaction transaction = new Transaction();
|
||||||
if(Arrays.asList(ScriptType.WITNESS_TYPES).contains(getScriptType())) {
|
if(Arrays.asList(ScriptType.WITNESS_TYPES).contains(getScriptType())) {
|
||||||
transaction.setSegwitVersion(0);
|
transaction.setSegwitVersion(0);
|
||||||
}
|
}
|
||||||
transaction.addOutput(1L, recipientAddress);
|
for(Payment payment : payments) {
|
||||||
|
transaction.addOutput(payment.getAmount(), payment.getAddress());
|
||||||
|
}
|
||||||
return transaction.getWeightUnits();
|
return transaction.getWeightUnits();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue