btcjson: add TestMempoolAcceptCmd

This commit is contained in:
yyforyongyu 2023-11-04 02:08:38 +08:00
parent 2ad8026a38
commit ca4261f028
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
2 changed files with 50 additions and 0 deletions

View File

@ -1042,6 +1042,27 @@ func NewVerifyTxOutProofCmd(proof string) *VerifyTxOutProofCmd {
}
}
// TestMempoolAcceptCmd defines the testmempoolaccept JSON-RPC command.
type TestMempoolAcceptCmd struct {
// An array of hex strings of raw transactions.
RawTxns []string
// Reject transactions whose fee rate is higher than the specified
// value, expressed in BTC/kvB, optional, default="0.10".
MaxFeeRate float64 `json:"omitempty"`
}
// NewTestMempoolAcceptCmd returns a new instance which can be used to issue a
// testmempoolaccept JSON-RPC command.
func NewTestMempoolAcceptCmd(rawTxns []string,
maxFeeRate float64) *TestMempoolAcceptCmd {
return &TestMempoolAcceptCmd{
RawTxns: rawTxns,
MaxFeeRate: maxFeeRate,
}
}
func init() {
// No special flags for commands in this file.
flags := UsageFlag(0)
@ -1102,4 +1123,5 @@ func init() {
MustRegisterCmd("verifychain", (*VerifyChainCmd)(nil), flags)
MustRegisterCmd("verifymessage", (*VerifyMessageCmd)(nil), flags)
MustRegisterCmd("verifytxoutproof", (*VerifyTxOutProofCmd)(nil), flags)
MustRegisterCmd("testmempoolaccept", (*TestMempoolAcceptCmd)(nil), flags)
}

View File

@ -1472,6 +1472,34 @@ func TestChainSvrCmds(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"getzmqnotifications","params":[],"id":1}`,
unmarshalled: &btcjson.GetZmqNotificationsCmd{},
},
{
name: "testmempoolaccept",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("testmempoolaccept", []string{"rawhex"}, 0.1)
},
staticCmd: func() interface{} {
return btcjson.NewTestMempoolAcceptCmd([]string{"rawhex"}, 0.1)
},
marshalled: `{"jsonrpc":"1.0","method":"testmempoolaccept","params":[["rawhex"],0.1],"id":1}`,
unmarshalled: &btcjson.TestMempoolAcceptCmd{
RawTxns: []string{"rawhex"},
MaxFeeRate: 0.1,
},
},
{
name: "testmempoolaccept with maxfeerate",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("testmempoolaccept", []string{"rawhex"}, 0.01)
},
staticCmd: func() interface{} {
return btcjson.NewTestMempoolAcceptCmd([]string{"rawhex"}, 0.01)
},
marshalled: `{"jsonrpc":"1.0","method":"testmempoolaccept","params":[["rawhex"],0.01],"id":1}`,
unmarshalled: &btcjson.TestMempoolAcceptCmd{
RawTxns: []string{"rawhex"},
MaxFeeRate: 0.01,
},
},
}
t.Logf("Running %d tests", len(tests))