mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 10:15:52 +00:00
Make TransactionOutput.getMinNonDustOutput exact.
This commit is contained in:
parent
d6fec93be3
commit
be88a05c93
@ -65,7 +65,7 @@ public class Transaction extends ChildMessage implements Serializable {
|
|||||||
* This is calculated by assuming a standard output will be 34 bytes, and then using the formula used in
|
* This is calculated by assuming a standard output will be 34 bytes, and then using the formula used in
|
||||||
* {@link TransactionOutput#getMinNonDustValue(BigInteger)}.
|
* {@link TransactionOutput#getMinNonDustValue(BigInteger)}.
|
||||||
*/
|
*/
|
||||||
public static final BigInteger MIN_NONDUST_OUTPUT = BigInteger.valueOf(5461);
|
public static final BigInteger MIN_NONDUST_OUTPUT = BigInteger.valueOf(5460);
|
||||||
|
|
||||||
// These are serialized in both bitcoin and java serialization.
|
// These are serialized in both bitcoin and java serialization.
|
||||||
private long version;
|
private long version;
|
||||||
|
@ -180,9 +180,9 @@ public class TransactionOutput extends ChildMessage implements Serializable {
|
|||||||
* If you want a safe default, use {@link Transaction#REFERENCE_DEFAULT_MIN_TX_FEE}*3
|
* If you want a safe default, use {@link Transaction#REFERENCE_DEFAULT_MIN_TX_FEE}*3
|
||||||
*/
|
*/
|
||||||
public BigInteger getMinNonDustValue(BigInteger feePerKbRequired) {
|
public BigInteger getMinNonDustValue(BigInteger feePerKbRequired) {
|
||||||
// Note we skip the *3 as that should be considered in the parameter and we add one to account for loss of precision
|
// Note we skip the *3 as that should be considered in the parameter
|
||||||
// (1/1000 chance we require too much fee, 999/1000 chance we get the exact right value...)
|
BigInteger[] nonDustAndRemainder = feePerKbRequired.multiply(BigInteger.valueOf(this.bitcoinSerialize().length + 148)).divideAndRemainder(BigInteger.valueOf(1000));
|
||||||
return feePerKbRequired.multiply(BigInteger.valueOf(this.bitcoinSerialize().length + 148)).divide(BigInteger.valueOf(1000)).add(BigInteger.ONE);
|
return nonDustAndRemainder[1].equals(BigInteger.ZERO) ? nonDustAndRemainder[0] : nonDustAndRemainder[0].add(BigInteger.ONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user