Change searchrawtransaction to be compatible with bitcoind
* Pluralise `searchrawtransaction` -> `searchrawtransactions` * Change the `verbose` parameter from a bool to an int.
This commit is contained in:
parent
dc4989461a
commit
1b57f5bf87
7 changed files with 44 additions and 44 deletions
|
@ -652,7 +652,7 @@ getpeerinfo.`,
|
||||||
"reconsiderblock": `reconsiderblock "hash"
|
"reconsiderblock": `reconsiderblock "hash"
|
||||||
Remove invalid mark from block specified by "hash" so it is considered again.`,
|
Remove invalid mark from block specified by "hash" so it is considered again.`,
|
||||||
|
|
||||||
"searchrawtransaction": `searchrawtransaction "address" (verbose=1 skip=0 count=100)
|
"searchrawtransactions": `searchrawtransactions "address" (verbose=1 skip=0 count=100)
|
||||||
Returns raw tx data related to credits or debits to "address". Skip indicates
|
Returns raw tx data related to credits or debits to "address". Skip indicates
|
||||||
the number of leading transactions to leave out of the final result. Count
|
the number of leading transactions to leave out of the final result. Count
|
||||||
represents the max number of transactions to return. If verbose is false, a
|
represents the max number of transactions to return. If verbose is false, a
|
||||||
|
|
|
@ -619,7 +619,7 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
|
||||||
*/
|
*/
|
||||||
finalMessage, err = jsonWithArgs(message, id, []interface{}{args[0].(string), txList})
|
finalMessage, err = jsonWithArgs(message, id, []interface{}{args[0].(string), txList})
|
||||||
// one required string (address), one optional bool, two optional ints.
|
// one required string (address), one optional bool, two optional ints.
|
||||||
case "searchrawtransaction":
|
case "searchrawtransactions":
|
||||||
if len(args) > 4 || len(args) == 0 {
|
if len(args) > 4 || len(args) == 0 {
|
||||||
err = fmt.Errorf("wrong number of arguments for %s", message)
|
err = fmt.Errorf("wrong number of arguments for %s", message)
|
||||||
return finalMessage, err
|
return finalMessage, err
|
||||||
|
@ -629,7 +629,7 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
|
||||||
ok3 := true
|
ok3 := true
|
||||||
ok4 := true
|
ok4 := true
|
||||||
if len(args) >= 2 {
|
if len(args) >= 2 {
|
||||||
_, ok2 = args[1].(bool)
|
_, ok2 = args[1].(int)
|
||||||
}
|
}
|
||||||
if len(args) >= 3 {
|
if len(args) >= 3 {
|
||||||
_, ok3 = args[2].(int)
|
_, ok3 = args[2].(int)
|
||||||
|
|
|
@ -181,12 +181,12 @@ var cmdtests = []struct {
|
||||||
{"signrawtransaction", []interface{}{1.2, "test", "test2", "test3", "test4"}, false},
|
{"signrawtransaction", []interface{}{1.2, "test", "test2", "test3", "test4"}, false},
|
||||||
{"signrawtransaction", []interface{}{"hexstring", 1, "test2", "test3", "test4"}, false},
|
{"signrawtransaction", []interface{}{"hexstring", 1, "test2", "test3", "test4"}, false},
|
||||||
{"signrawtransaction", []interface{}{"hexstring", "test", "test2", 3, "test4"}, false},
|
{"signrawtransaction", []interface{}{"hexstring", "test", "test2", 3, "test4"}, false},
|
||||||
{"searchrawtransaction", []interface{}{"someaddr"}, true},
|
{"searchrawtransactions", []interface{}{"someaddr"}, true},
|
||||||
{"searchrawtransaction", []interface{}{"someaddr", true}, true},
|
{"searchrawtransactions", []interface{}{"someaddr", 1}, true},
|
||||||
{"searchrawtransaction", []interface{}{"someaddr", false, 1}, true},
|
{"searchrawtransactions", []interface{}{"someaddr", 0, 1}, true},
|
||||||
{"searchrawtransaction", []interface{}{"someaddr", true, 5, 500}, true},
|
{"searchrawtransactions", []interface{}{"someaddr", 1, 5, 500}, true},
|
||||||
{"searchrawtransaction", []interface{}{"someaddr", true, 5, "test"}, false},
|
{"searchrawtransactions", []interface{}{"someaddr", 1, 5, "test"}, false},
|
||||||
{"searchrawtransaction", []interface{}{}, false},
|
{"searchrawtransactions", []interface{}{}, false},
|
||||||
{"listsinceblock", []interface{}{"test", "test"}, true},
|
{"listsinceblock", []interface{}{"test", "test"}, true},
|
||||||
{"listsinceblock", []interface{}{"test", "test", "test"}, false},
|
{"listsinceblock", []interface{}{"test", "test", "test"}, false},
|
||||||
{"listsinceblock", []interface{}{"test"}, true},
|
{"listsinceblock", []interface{}{"test"}, true},
|
||||||
|
|
48
jsoncmd.go
48
jsoncmd.go
|
@ -286,8 +286,8 @@ func ParseMarshaledCmd(b []byte) (Cmd, error) {
|
||||||
case "reconsiderblock":
|
case "reconsiderblock":
|
||||||
cmd = new(ReconsiderBlockCmd)
|
cmd = new(ReconsiderBlockCmd)
|
||||||
|
|
||||||
case "searchrawtransaction":
|
case "searchrawtransactions":
|
||||||
cmd = new(SearchRawTransactionCmd)
|
cmd = new(SearchRawTransactionsCmd)
|
||||||
|
|
||||||
case "sendfrom":
|
case "sendfrom":
|
||||||
cmd = new(SendFromCmd)
|
cmd = new(SendFromCmd)
|
||||||
|
@ -5322,21 +5322,21 @@ func (cmd *ReconsiderBlockCmd) UnmarshalJSON(b []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchRawTransactionCmd is a type handling custom marshaling and
|
// SearchRawTransactionsCmd is a type handling custom marshaling and
|
||||||
// unmarshaling of sendrawtransaction JSON RPC commands.
|
// unmarshaling of sendrawtransactions JSON RPC commands.
|
||||||
type SearchRawTransactionCmd struct {
|
type SearchRawTransactionsCmd struct {
|
||||||
id interface{}
|
id interface{}
|
||||||
Address string
|
Address string
|
||||||
Verbose bool
|
Verbose int
|
||||||
Skip int
|
Skip int
|
||||||
Count int
|
Count int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSearchRawTransactionCmd creates a new SearchRawTransactionCmd.
|
// NewSearchRawTransactionsCmd creates a new SearchRawTransactionsCmd.
|
||||||
func NewSearchRawTransactionCmd(id interface{}, address string,
|
func NewSearchRawTransactionsCmd(id interface{}, address string,
|
||||||
optArgs ...interface{}) (*SearchRawTransactionCmd, error) {
|
optArgs ...interface{}) (*SearchRawTransactionsCmd, error) {
|
||||||
verbose := true
|
|
||||||
var skip int
|
var skip int
|
||||||
|
verbose := 1
|
||||||
count := 100
|
count := 100
|
||||||
|
|
||||||
if len(optArgs) > 3 {
|
if len(optArgs) > 3 {
|
||||||
|
@ -5344,9 +5344,9 @@ func NewSearchRawTransactionCmd(id interface{}, address string,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(optArgs) > 0 {
|
if len(optArgs) > 0 {
|
||||||
v, ok := optArgs[0].(bool)
|
v, ok := optArgs[0].(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("first optional argument verbose is not a bool")
|
return nil, errors.New("first optional argument verbose is not a int")
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose = v
|
verbose = v
|
||||||
|
@ -5367,7 +5367,7 @@ func NewSearchRawTransactionCmd(id interface{}, address string,
|
||||||
count = c
|
count = c
|
||||||
}
|
}
|
||||||
|
|
||||||
return &SearchRawTransactionCmd{
|
return &SearchRawTransactionsCmd{
|
||||||
id: id,
|
id: id,
|
||||||
Address: address,
|
Address: address,
|
||||||
Verbose: verbose,
|
Verbose: verbose,
|
||||||
|
@ -5377,20 +5377,20 @@ func NewSearchRawTransactionCmd(id interface{}, address string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Id satisfies the Cmd interface by returning the id of the command.
|
// Id satisfies the Cmd interface by returning the id of the command.
|
||||||
func (cmd *SearchRawTransactionCmd) Id() interface{} {
|
func (cmd *SearchRawTransactionsCmd) Id() interface{} {
|
||||||
return cmd.id
|
return cmd.id
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method satisfies the Cmd interface by returning the json method.
|
// Method satisfies the Cmd interface by returning the json method.
|
||||||
func (cmd *SearchRawTransactionCmd) Method() string {
|
func (cmd *SearchRawTransactionsCmd) Method() string {
|
||||||
return "searchrawtransaction"
|
return "searchrawtransactions"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 *SearchRawTransactionCmd) MarshalJSON() ([]byte, error) {
|
func (cmd *SearchRawTransactionsCmd) MarshalJSON() ([]byte, error) {
|
||||||
params := make([]interface{}, 1, 4)
|
params := make([]interface{}, 1, 4)
|
||||||
params[0] = cmd.Address
|
params[0] = cmd.Address
|
||||||
if !cmd.Verbose || cmd.Skip != 0 || cmd.Count != 100 {
|
if cmd.Verbose != 1 || cmd.Skip != 0 || cmd.Count != 100 {
|
||||||
params = append(params, cmd.Verbose)
|
params = append(params, cmd.Verbose)
|
||||||
}
|
}
|
||||||
if cmd.Skip != 0 || cmd.Count != 100 {
|
if cmd.Skip != 0 || cmd.Count != 100 {
|
||||||
|
@ -5411,7 +5411,7 @@ func (cmd *SearchRawTransactionCmd) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of
|
// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of
|
||||||
// the Cmd interface.
|
// the Cmd interface.
|
||||||
func (cmd *SearchRawTransactionCmd) UnmarshalJSON(b []byte) error {
|
func (cmd *SearchRawTransactionsCmd) UnmarshalJSON(b []byte) error {
|
||||||
// Unmarshal into a RawCmd
|
// Unmarshal into a RawCmd
|
||||||
var r RawCmd
|
var r RawCmd
|
||||||
if err := json.Unmarshal(b, &r); err != nil {
|
if err := json.Unmarshal(b, &r); err != nil {
|
||||||
|
@ -5429,9 +5429,9 @@ func (cmd *SearchRawTransactionCmd) UnmarshalJSON(b []byte) error {
|
||||||
|
|
||||||
optArgs := make([]interface{}, 0, 3)
|
optArgs := make([]interface{}, 0, 3)
|
||||||
if len(r.Params) > 1 {
|
if len(r.Params) > 1 {
|
||||||
var verbose bool
|
var verbose int
|
||||||
if err := json.Unmarshal(r.Params[1], &verbose); err != nil {
|
if err := json.Unmarshal(r.Params[1], &verbose); err != nil {
|
||||||
return fmt.Errorf("second optional parameter 'verbose' must be an bool: %v", err)
|
return fmt.Errorf("second optional parameter 'verbose' must be an int: %v", err)
|
||||||
}
|
}
|
||||||
optArgs = append(optArgs, verbose)
|
optArgs = append(optArgs, verbose)
|
||||||
}
|
}
|
||||||
|
@ -5450,7 +5450,7 @@ func (cmd *SearchRawTransactionCmd) UnmarshalJSON(b []byte) error {
|
||||||
optArgs = append(optArgs, count)
|
optArgs = append(optArgs, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
newCmd, err := NewSearchRawTransactionCmd(r.Id, address, optArgs...)
|
newCmd, err := NewSearchRawTransactionsCmd(r.Id, address, optArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -5459,8 +5459,8 @@ func (cmd *SearchRawTransactionCmd) UnmarshalJSON(b []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enforce that SearchRawTransactionCmd satisifies the Cmd interface.
|
// Enforce that SearchRawTransactionsCmd satisifies the Cmd interface.
|
||||||
var _ Cmd = &SearchRawTransactionCmd{}
|
var _ Cmd = &SearchRawTransactionsCmd{}
|
||||||
|
|
||||||
// SendFromCmd is a type handling custom marshaling and
|
// SendFromCmd is a type handling custom marshaling and
|
||||||
// unmarshaling of sendfrom JSON RPC commands.
|
// unmarshaling of sendfrom JSON RPC commands.
|
||||||
|
|
|
@ -1210,15 +1210,15 @@ var jsoncmdtests = []struct {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "basic + optionals",
|
name: "basic + optionals",
|
||||||
cmd: "searchrawtransaction",
|
cmd: "searchrawtransactions",
|
||||||
f: func() (Cmd, error) {
|
f: func() (Cmd, error) {
|
||||||
return NewSearchRawTransactionCmd(testID,
|
return NewSearchRawTransactionsCmd(testID,
|
||||||
"someaddr", true, 5, 200)
|
"someaddr", 1, 5, 200)
|
||||||
},
|
},
|
||||||
result: &SearchRawTransactionCmd{
|
result: &SearchRawTransactionsCmd{
|
||||||
id: testID,
|
id: testID,
|
||||||
Address: "someaddr",
|
Address: "someaddr",
|
||||||
Verbose: true,
|
Verbose: 1,
|
||||||
Skip: 5,
|
Skip: 5,
|
||||||
Count: 200,
|
Count: 200,
|
||||||
},
|
},
|
||||||
|
@ -1725,7 +1725,7 @@ func TestHelps(t *testing.T) {
|
||||||
"move",
|
"move",
|
||||||
"ping",
|
"ping",
|
||||||
"reconsiderblock",
|
"reconsiderblock",
|
||||||
"searchrawtransaction",
|
"searchrawtransactions",
|
||||||
"sendfrom",
|
"sendfrom",
|
||||||
"sendmany",
|
"sendmany",
|
||||||
"sendrawtransaction",
|
"sendrawtransaction",
|
||||||
|
|
|
@ -690,8 +690,8 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
|
||||||
result.Result = res
|
result.Result = res
|
||||||
}
|
}
|
||||||
|
|
||||||
case "searchrawtransaction":
|
case "searchrawtransactions":
|
||||||
// searchrawtransaction can either return a list of JSON objects
|
// searchrawtransactions can either return a list of JSON objects
|
||||||
// or a list of hex-encoded strings depending on the verbose flag.
|
// or a list of hex-encoded strings depending on the verbose flag.
|
||||||
// Choose the right form accordingly.
|
// Choose the right form accordingly.
|
||||||
if bytes.IndexByte(objmap["result"], '{') > -1 {
|
if bytes.IndexByte(objmap["result"], '{') > -1 {
|
||||||
|
|
|
@ -61,9 +61,9 @@ var resulttests = []struct {
|
||||||
{"signrawtransaction", []byte(`{"error":null,"id":1,"result":{false}}`), false, false},
|
{"signrawtransaction", []byte(`{"error":null,"id":1,"result":{false}}`), false, false},
|
||||||
{"listunspent", []byte(`{"error":null,"id":1,"result":[{"txid":"something"}]}`), false, true},
|
{"listunspent", []byte(`{"error":null,"id":1,"result":[{"txid":"something"}]}`), false, true},
|
||||||
{"listunspent", []byte(`{"error":null,"id":1,"result":[{"txid"}]}`), false, false},
|
{"listunspent", []byte(`{"error":null,"id":1,"result":[{"txid"}]}`), false, false},
|
||||||
{"searchrawtransaction", []byte(`{"error":null,"id":1,"result":{"a":"b"}}`), false, false},
|
{"searchrawtransactions", []byte(`{"error":null,"id":1,"result":{"a":"b"}}`), false, false},
|
||||||
{"searchrawtransaction", []byte(`{"error":null,"id":1,"result":["sometxhex"]}`), false, true},
|
{"searchrawtransactions", []byte(`{"error":null,"id":1,"result":["sometxhex"]}`), false, true},
|
||||||
{"searchrawtransaction", []byte(`{"error":null,"id":1,"result":[{"hex":"somejunk","version":1}]}`), false, true},
|
{"searchrawtransactions", []byte(`{"error":null,"id":1,"result":[{"hex":"somejunk","version":1}]}`), false, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestReadResultCmd tests that readResultCmd can properly unmarshall the
|
// TestReadResultCmd tests that readResultCmd can properly unmarshall the
|
||||||
|
|
Loading…
Add table
Reference in a new issue