From f5a1fb9965e4415c619c032e04ac21731f92167a Mon Sep 17 00:00:00 2001 From: eugene Date: Mon, 2 Aug 2021 11:14:52 -0400 Subject: [PATCH] mempool: export isDust for use in other projects This changes isDust to IsDust so other golang projects (btcwallet or lnd) can use the precise dust calculation used by btcd. --- mempool/policy.go | 6 +++--- mempool/policy_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mempool/policy.go b/mempool/policy.go index 7e973293..74142bf6 100644 --- a/mempool/policy.go +++ b/mempool/policy.go @@ -172,12 +172,12 @@ func checkPkScriptStandard(pkScript []byte, scriptClass txscript.ScriptClass) er return nil } -// isDust returns whether or not the passed transaction output amount is +// IsDust returns whether or not the passed transaction output amount is // considered dust or not based on the passed minimum transaction relay fee. // Dust is defined in terms of the minimum transaction relay fee. In // particular, if the cost to the network to spend coins is more than 1/3 of the // minimum transaction relay fee, it is considered dust. -func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool { +func IsDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool { // Unspendable outputs are considered dust. if txscript.IsUnspendable(txOut.PkScript) { return true @@ -351,7 +351,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int32, // "dust". if scriptClass == txscript.NullDataTy { numNullDataOutputs++ - } else if isDust(txOut, minRelayTxFee) { + } else if IsDust(txOut, minRelayTxFee) { str := fmt.Sprintf("transaction output %d: payment "+ "of %d is dust", i, txOut.Value) return txRuleError(wire.RejectDust, str) diff --git a/mempool/policy_test.go b/mempool/policy_test.go index 9dd618ad..b9cdbac4 100644 --- a/mempool/policy_test.go +++ b/mempool/policy_test.go @@ -204,7 +204,7 @@ func TestCheckPkScriptStandard(t *testing.T) { } } -// TestDust tests the isDust API. +// TestDust tests the IsDust API. func TestDust(t *testing.T) { pkScript := []byte{0x76, 0xa9, 0x21, 0x03, 0x2f, 0x7e, 0x43, 0x0a, 0xa4, 0xc9, 0xd1, 0x59, 0x43, 0x7e, 0x84, 0xb9, @@ -268,7 +268,7 @@ func TestDust(t *testing.T) { }, } for _, test := range tests { - res := isDust(&test.txOut, test.relayFee) + res := IsDust(&test.txOut, test.relayFee) if res != test.isDust { t.Fatalf("Dust test '%s' failed: want %v got %v", test.name, test.isDust, res)