diff --git a/core/src/main/java/org/bitcoinj/core/TransactionOutput.java b/core/src/main/java/org/bitcoinj/core/TransactionOutput.java index 3c21d315..45131e76 100644 --- a/core/src/main/java/org/bitcoinj/core/TransactionOutput.java +++ b/core/src/main/java/org/bitcoinj/core/TransactionOutput.java @@ -225,23 +225,21 @@ public class TransactionOutput extends ChildMessage { *

You probably should use {@link org.bitcoinj.core.TransactionOutput#getMinNonDustValue()} which uses * a safe fee-per-kb by default.

* - * @param feePerKbRequired The fee required per kilobyte. Note that this is the same as Bitcoin Core's -minrelaytxfee * 3 - * If you want a safe default, use {@link Transaction#REFERENCE_DEFAULT_MIN_TX_FEE}*3 + * @param feePerKb The fee required per kilobyte. Note that this is the same as Bitcoin Core's -minrelaytxfee * 3 */ - public Coin getMinNonDustValue(Coin feePerKbRequired) { + public Coin getMinNonDustValue(Coin feePerKb) { // A typical output is 33 bytes (pubkey hash + opcodes) and requires an input of 148 bytes to spend so we add // that together to find out the total amount of data used to transfer this amount of value. Note that this // formula is wrong for anything that's not a pay-to-address output, unfortunately, we must follow Bitcoin Core's // wrongness in order to ensure we're considered standard. A better formula would either estimate the // size of data needed to satisfy all different script types, or just hard code 33 below. final long size = this.unsafeBitcoinSerialize().length + 148; - Coin[] nonDustAndRemainder = feePerKbRequired.multiply(size).divideAndRemainder(1000); - return nonDustAndRemainder[1].equals(Coin.ZERO) ? nonDustAndRemainder[0] : nonDustAndRemainder[0].add(Coin.SATOSHI); + return feePerKb.multiply(size).divide(1000); } /** * Returns the minimum value for this output to be considered "not dust", i.e. the transaction will be relayable - * and mined by default miners. For normal pay to address outputs, this is 546 satoshis, the same as + * and mined by default miners. For normal pay to address outputs, this is 2730 satoshis, the same as * {@link Transaction#MIN_NONDUST_OUTPUT}. */ public Coin getMinNonDustValue() { diff --git a/core/src/test/java/org/bitcoinj/core/TransactionOutputTest.java b/core/src/test/java/org/bitcoinj/core/TransactionOutputTest.java index 321fb61d..58ad752f 100644 --- a/core/src/test/java/org/bitcoinj/core/TransactionOutputTest.java +++ b/core/src/test/java/org/bitcoinj/core/TransactionOutputTest.java @@ -64,4 +64,10 @@ public class TransactionOutputTest extends TestWithWallet { assertNull(tx.getOutput(0).getAddressFromP2SH(PARAMS)); assertNull(tx.getOutput(0).getAddressFromP2PKHScript(PARAMS)); } + + @Test + public void getMinNonDustValue() throws Exception { + TransactionOutput payToAddressOutput = new TransactionOutput(PARAMS, null, Coin.COIN, myAddress); + assertEquals(Transaction.MIN_NONDUST_OUTPUT, payToAddressOutput.getMinNonDustValue()); + } }