@@ -172,17 +172,10 @@ func checkPkScriptStandard(pkScript []byte, scriptClass txscript.ScriptClass) er
172172 return nil
173173}
174174
175- // isDust returns whether or not the passed transaction output amount is
176- // considered dust or not based on the passed minimum transaction relay fee.
177- // Dust is defined in terms of the minimum transaction relay fee. In
178- // particular, if the cost to the network to spend coins is more than 1/3 of the
179- // minimum transaction relay fee, it is considered dust.
180- func isDust (txOut * wire.TxOut , minRelayTxFee btcutil.Amount ) bool {
181- // Unspendable outputs are considered dust.
182- if txscript .IsUnspendable (txOut .PkScript ) {
183- return true
184- }
185-
175+ // GetDustThreshold calculates the dust limit for a *wire.TxOut by taking the
176+ // size of a typical spending transaction and multiplying it by 3 to account
177+ // for the minimum dust relay fee of 3000sat/kvb.
178+ func GetDustThreshold (txOut * wire.TxOut ) int64 {
186179 // The total serialized size consists of the output and the associated
187180 // input script to redeem it. Since there is no input script
188181 // to redeem it yet, use the minimum size of a typical input script.
@@ -253,6 +246,20 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
253246 totalSize += 107
254247 }
255248
249+ return 3 * int64 (totalSize )
250+ }
251+
252+ // IsDust returns whether or not the passed transaction output amount is
253+ // considered dust or not based on the passed minimum transaction relay fee.
254+ // Dust is defined in terms of the minimum transaction relay fee. In
255+ // particular, if the cost to the network to spend coins is more than 1/3 of the
256+ // minimum transaction relay fee, it is considered dust.
257+ func IsDust (txOut * wire.TxOut , minRelayTxFee btcutil.Amount ) bool {
258+ // Unspendable outputs are considered dust.
259+ if txscript .IsUnspendable (txOut .PkScript ) {
260+ return true
261+ }
262+
256263 // The output is considered dust if the cost to the network to spend the
257264 // coins is more than 1/3 of the minimum free transaction relay fee.
258265 // minFreeTxRelayFee is in Satoshi/KB, so multiply by 1000 to
@@ -265,7 +272,7 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
265272 //
266273 // The following is equivalent to (value/totalSize) * (1/3) * 1000
267274 // without needing to do floating point math.
268- return txOut .Value * 1000 / ( 3 * int64 ( totalSize ) ) < int64 (minRelayTxFee )
275+ return txOut .Value * 1000 / GetDustThreshold ( txOut ) < int64 (minRelayTxFee )
269276}
270277
271278// checkTransactionStandard performs a series of checks on a transaction to
@@ -351,7 +358,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int32,
351358 // "dust".
352359 if scriptClass == txscript .NullDataTy {
353360 numNullDataOutputs ++
354- } else if isDust (txOut , minRelayTxFee ) {
361+ } else if IsDust (txOut , minRelayTxFee ) {
355362 str := fmt .Sprintf ("transaction output %d: payment " +
356363 "of %d is dust" , i , txOut .Value )
357364 return txRuleError (wire .RejectDust , str )
0 commit comments