Untitled


SUBMITTED BY: Guest

DATE: Nov. 3, 2013, 1:37 p.m.

FORMAT: Java

SIZE: 2.5 kB

HITS: 1426

  1. /**
  2. * <p>Gets the minimum value for a txout of this size to be considered non-dust by a reference client
  3. * (and thus relayed). See: CTxOut::IsDust() in the reference client. The assumption is that any output that would
  4. * consume more than a third of its value in fees is not something the Bitcoin system wants to deal with right now,
  5. * so we call them "dust outputs" and they're made non standard. The choice of one third is somewhat arbitrary and
  6. * may change in future.</p>
  7. *
  8. * <p>You probably should use {@link com.google.bitcoin.core.TransactionOutput#getMinNonDustValue()} which uses
  9. * a safe fee-per-kb by default.</p>
  10. *
  11. * @param feePerKbRequired The fee required per kilobyte. Note that this is the same as the reference client's -minrelaytxfee * 3
  12. * If you want a safe default, use {@link Transaction#REFERENCE_DEFAULT_MIN_TX_FEE}*3
  13. */
  14. public BigInteger getMinNonDustValue(BigInteger feePerKbRequired) {
  15. // A typical output is 33 bytes (pubkey hash + opcodes) and requires an input of 148 bytes to spend so we add
  16. // that together to find out the total amount of data used to transfer this amount of value. Note that this
  17. // formula is wrong for anything that's not a pay-to-address output, unfortunately, we must follow the reference
  18. // clients wrongness in order to ensure we're considered standard. A better formula would either estimate the
  19. // size of data needed to satisfy all different script types, or just hard code 33 below.
  20. final BigInteger size = BigInteger.valueOf(this.bitcoinSerialize().length + 148);
  21. BigInteger[] nonDustAndRemainder = feePerKbRequired.multiply(size).divideAndRemainder(BigInteger.valueOf(1000));
  22. return nonDustAndRemainder[1].equals(BigInteger.ZERO) ? nonDustAndRemainder[0] : nonDustAndRemainder[0].add(BigInteger.ONE);
  23. }
  24. /**
  25. * Returns the minimum value for this output to be considered "not dust", i.e. the transaction will be relayable
  26. * and mined by default miners. For normal pay to address outputs, this is 5460 satoshis, the same as
  27. * {@link Transaction#MIN_NONDUST_OUTPUT}.
  28. */
  29. public BigInteger getMinNonDustValue() {
  30. return getMinNonDustValue(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.multiply(BigInteger.valueOf(3)));
  31. }

comments powered by Disqus