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 {
|
if err == nil {
|
||||||
result.Result = res
|
result.Result = res
|
||||||
}
|
}
|
||||||
case "getaddressesbyaccount", "getrawmempool":
|
case "getaddressesbyaccount":
|
||||||
var res []string
|
var res []string
|
||||||
err = json.Unmarshal(objmap["result"], &res)
|
err = json.Unmarshal(objmap["result"], &res)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -346,8 +346,6 @@ var resulttests = []struct {
|
||||||
{"getaddressesbyaccount", []byte(`{"error":null,"id":1,"result":["test"]}`), false, true},
|
{"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":[{"a":"b"}]}`), false, false},
|
||||||
{"getmininginfo", []byte(`{"error":null,"id":1,"result":{"generate":true}}`), false, true},
|
{"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":{"isvalid":false}}`), false, true},
|
||||||
{"validateaddress", []byte(`{"error":null,"id":1,"result":{false}}`), false, false},
|
{"validateaddress", []byte(`{"error":null,"id":1,"result":{false}}`), false, false},
|
||||||
{"signrawtransaction", []byte(`{"error":null,"id":1,"result":{"hex":"something","complete":false}}`), false, true},
|
{"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.
|
// unmarshaling of getrawmempool JSON RPC commands.
|
||||||
type GetRawMempoolCmd struct {
|
type GetRawMempoolCmd struct {
|
||||||
id interface{}
|
id interface{}
|
||||||
|
Verbose bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enforce that GetRawMempoolCmd satisifies the Cmd interface.
|
// Enforce that GetRawMempoolCmd satisifies the Cmd interface.
|
||||||
var _ Cmd = &GetRawMempoolCmd{}
|
var _ Cmd = &GetRawMempoolCmd{}
|
||||||
|
|
||||||
// NewGetRawMempoolCmd creates a new 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{
|
return &GetRawMempoolCmd{
|
||||||
id: id,
|
id: id,
|
||||||
|
Verbose: verbose,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2855,14 +2864,18 @@ func (cmd *GetRawMempoolCmd) Method() string {
|
||||||
|
|
||||||
// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface.
|
// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface.
|
||||||
func (cmd *GetRawMempoolCmd) MarshalJSON() ([]byte, error) {
|
func (cmd *GetRawMempoolCmd) MarshalJSON() ([]byte, error) {
|
||||||
|
raw := RawCmd{
|
||||||
// Fill and marshal a RawCmd.
|
|
||||||
return json.Marshal(RawCmd{
|
|
||||||
Jsonrpc: "1.0",
|
Jsonrpc: "1.0",
|
||||||
Method: "getrawmempool",
|
Method: "getrawmempool",
|
||||||
Id: cmd.id,
|
Id: cmd.id,
|
||||||
Params: []interface{}{},
|
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
|
// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of
|
||||||
|
@ -2874,11 +2887,21 @@ func (cmd *GetRawMempoolCmd) UnmarshalJSON(b []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(r.Params) != 0 {
|
if len(r.Params) > 1 {
|
||||||
return ErrWrongNumberOfParams
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -535,6 +535,25 @@ var jsoncmdtests = []struct {
|
||||||
id: float64(1),
|
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",
|
name: "basic getrawtransaction",
|
||||||
f: func() (Cmd, error) {
|
f: func() (Cmd, error) {
|
||||||
|
|
Loading…
Reference in a new issue