bitcoinjs-lib
bitcoinjs-lib copied to clipboard
Feature request: Dust threshold value based on output script
Sometimes when parsing transactions I need to check whether an output value is too low for a given output type. Would you consider adding some sort of utility, maybe to bitcoin.address, that would allow me to look up the dust threshold based on the output script? Perhaps bitcoin.address.dustThresholdFromOutputScript() or something similar?
Ooh, that sounds like a good idea.
I'll see if I can whip something up later.
If anyone wants to work on it let me know.
Basically:
- If it's provably unspendable (OP_RETURN et al) then 0 sats is ok
- If it's segwit then use 67 bytes if not, use 148 bytes
- Add the size of the output, which is script size + size of varint for scriptSize + 8 (for i64 amount)
- Multiply bytes by 3 to get sats (round up). (MIN_RELAY_TX_FEE = 1000 assumed)
https://github.com/bitcoin/bitcoin/blob/160d23677ad799cf9b493eaa923b2ac080c3fb8e/src/policy/policy.cpp#L26-L63
Questions:
- Add a parameter to represent MIN_RELAY? (I checked and it's not based off of the eject level, it's based off of the min_relay parameter (which defaults to 1000)
- If we do add a parameter... should we do sat/kvB? (1000) or sat/vB (1)? (defaults in parens)
Check out the PR.
Wow, that was fast! Do answer your second question: I think sat/vByte is probably the most convenient.
I guess it really doesn't matter. We can change it later.
Just check it out and make sure it jives with the Core code.
By the way, thank you so much for implementing this! Shall I close this issue?
No it'll be closed when we merge it.