diff --git a/jsonapi.go b/jsonapi.go index d56c531c..e64bd7f6 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -793,7 +793,7 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) { if err == nil { result.Result = res } - case "getaddressesbyaccount", "getrawmempool": + case "getaddressesbyaccount": var res []string err = json.Unmarshal(objmap["result"], &res) if err == nil { diff --git a/jsonapi_test.go b/jsonapi_test.go index dc35de58..319b78e2 100644 --- a/jsonapi_test.go +++ b/jsonapi_test.go @@ -346,8 +346,6 @@ var resulttests = []struct { {"getaddressesbyaccount", []byte(`{"error":null,"id":1,"result":["test"]}`), false, true}, {"getmininginfo", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false}, {"getmininginfo", []byte(`{"error":null,"id":1,"result":{"generate":true}}`), false, true}, - {"getrawmempool", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false}, - {"getrawmempool", []byte(`{"error":null,"id":1,"result":["test"]}`), false, true}, {"validateaddress", []byte(`{"error":null,"id":1,"result":{"isvalid":false}}`), false, true}, {"validateaddress", []byte(`{"error":null,"id":1,"result":{false}}`), false, false}, {"signrawtransaction", []byte(`{"error":null,"id":1,"result":{"hex":"something","complete":false}}`), false, true}, diff --git a/jsoncmd.go b/jsoncmd.go index b0968f28..2dd3cf0f 100644 --- a/jsoncmd.go +++ b/jsoncmd.go @@ -2831,15 +2831,24 @@ func (cmd *GetRawChangeAddressCmd) UnmarshalJSON(b []byte) error { // unmarshaling of getrawmempool JSON RPC commands. type GetRawMempoolCmd struct { id interface{} + Verbose bool } // Enforce that GetRawMempoolCmd satisifies the Cmd interface. var _ Cmd = &GetRawMempoolCmd{} // NewGetRawMempoolCmd creates a new GetRawMempoolCmd. -func NewGetRawMempoolCmd(id interface{}) (*GetRawMempoolCmd, error) { +func NewGetRawMempoolCmd(id interface{}, optArgs ...bool) (*GetRawMempoolCmd, error) { + verbose := false + if len(optArgs) > 0 { + if len(optArgs) > 1 { + return nil, ErrTooManyOptArgs + } + verbose = optArgs[0] + } return &GetRawMempoolCmd{ id: id, + Verbose: verbose, }, nil } @@ -2855,14 +2864,18 @@ func (cmd *GetRawMempoolCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *GetRawMempoolCmd) MarshalJSON() ([]byte, error) { - - // Fill and marshal a RawCmd. - return json.Marshal(RawCmd{ + raw := RawCmd{ Jsonrpc: "1.0", Method: "getrawmempool", Id: cmd.id, Params: []interface{}{}, - }) + } + + if cmd.Verbose { + raw.Params = append(raw.Params, cmd.Verbose) + } + + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of @@ -2874,11 +2887,21 @@ func (cmd *GetRawMempoolCmd) UnmarshalJSON(b []byte) error { return err } - if len(r.Params) != 0 { + if len(r.Params) > 1 { return ErrWrongNumberOfParams } - newCmd, err := NewGetRawMempoolCmd(r.Id) + optArgs := make([]bool, 0, 1) + if len(r.Params) == 1 { + verbose, ok := r.Params[0].(bool) + if !ok { + return errors.New("first optional parameter verbose must be a bool") + } + + optArgs = append(optArgs, verbose) + } + + newCmd, err := NewGetRawMempoolCmd(r.Id, optArgs...) if err != nil { return err } diff --git a/jsoncmd_test.go b/jsoncmd_test.go index a3410714..2c20e4b7 100644 --- a/jsoncmd_test.go +++ b/jsoncmd_test.go @@ -535,6 +535,25 @@ var jsoncmdtests = []struct { id: float64(1), }, }, + { + name: "basic getrawmempool noverbose", + f: func() (Cmd, error) { + return NewGetRawMempoolCmd(float64(1), false) + }, + result: &GetRawMempoolCmd{ + id: float64(1), + }, + }, + { + name: "basic getrawmempool verbose", + f: func() (Cmd, error) { + return NewGetRawMempoolCmd(float64(1), true) + }, + result: &GetRawMempoolCmd{ + id: float64(1), + Verbose: true, + }, + }, { name: "basic getrawtransaction", f: func() (Cmd, error) {