Handle optional verbose parameter to getrawmempool.
This does remove the `nicer' type handle for getrawmempool for now since it is no longer so simple. ok jcv.
This commit is contained in:
parent
1f52db626d
commit
4cb318ac02
4 changed files with 50 additions and 10 deletions
|
@ -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 {
|
||||
|
|
|
@ -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},
|
||||
|
|
37
jsoncmd.go
37
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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue