3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 18:25:51 +00:00

Make TransactionOutput.getMinNonDustOutput exact.

This commit is contained in:
Matt Corallo 2013-06-16 20:48:06 +02:00 committed by Mike Hearn
parent d6fec93be3
commit be88a05c93
2 changed files with 4 additions and 4 deletions

View File

@ -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;

View File

@ -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);
} }
/** /**