Fix getreceivedby[account|address] api. The first parameter is not

optional.
This commit is contained in:
David Hill 2014-01-30 11:48:27 -05:00
parent cbe4b140b9
commit ced679c4e5

View File

@ -3210,27 +3210,13 @@ type GetReceivedByAccountCmd struct {
var _ Cmd = &GetReceivedByAccountCmd{} var _ Cmd = &GetReceivedByAccountCmd{}
// NewGetReceivedByAccountCmd creates a new GetReceivedByAccountCmd. // NewGetReceivedByAccountCmd creates a new GetReceivedByAccountCmd.
func NewGetReceivedByAccountCmd(id interface{}, optArgs ...interface{}) (*GetReceivedByAccountCmd, error) { func NewGetReceivedByAccountCmd(id interface{}, account string, optArgs ...int) (*GetReceivedByAccountCmd, error) {
if len(optArgs) > 2 { if len(optArgs) > 1 {
return nil, ErrTooManyOptArgs return nil, ErrTooManyOptArgs
} }
var account string
if len(optArgs) > 0 {
a, ok := optArgs[0].(string)
if !ok {
return nil, errors.New("first optional argument account is not a string")
}
account = a
}
var minconf int = 1 var minconf int = 1
if len(optArgs) > 1 { if len(optArgs) > 0 {
m, ok := optArgs[1].(int) minconf = optArgs[0]
if !ok {
return nil, errors.New("second optional argument minconf is not a int")
}
minconf = m
} }
return &GetReceivedByAccountCmd{ return &GetReceivedByAccountCmd{
id: id, id: id,
@ -3261,11 +3247,9 @@ func (cmd *GetReceivedByAccountCmd) MarshalJSON() ([]byte, error) {
Jsonrpc: "1.0", Jsonrpc: "1.0",
Method: "getreceivedbyaccount", Method: "getreceivedbyaccount",
Id: cmd.id, Id: cmd.id,
Params: []interface{}{}, Params: []interface{}{
} cmd.Account,
},
if cmd.Account != "" || cmd.MinConf != 1 {
raw.Params = append(raw.Params, cmd.Account)
} }
if cmd.MinConf != 1 { if cmd.MinConf != 1 {
@ -3287,16 +3271,12 @@ func (cmd *GetReceivedByAccountCmd) UnmarshalJSON(b []byte) error {
return ErrWrongNumberOfParams return ErrWrongNumberOfParams
} }
optArgs := make([]interface{}, 0, 2) account, ok := r.Params[0].(string)
if len(r.Params) > 0 { if !ok {
account, ok := r.Params[0].(string) return errors.New("first parameter account must be a string")
if !ok {
return errors.New("first optional parameter account must be a string")
}
optArgs = append(optArgs, account)
} }
optArgs := make([]int, 0, 1)
if len(r.Params) > 1 { if len(r.Params) > 1 {
minconf, ok := r.Params[1].(float64) minconf, ok := r.Params[1].(float64)
if !ok { if !ok {
@ -3306,7 +3286,7 @@ func (cmd *GetReceivedByAccountCmd) UnmarshalJSON(b []byte) error {
optArgs = append(optArgs, int(minconf)) optArgs = append(optArgs, int(minconf))
} }
newCmd, err := NewGetReceivedByAccountCmd(r.Id, optArgs...) newCmd, err := NewGetReceivedByAccountCmd(r.Id, account, optArgs...)
if err != nil { if err != nil {
return err return err
} }
@ -3327,27 +3307,13 @@ type GetReceivedByAddressCmd struct {
var _ Cmd = &GetReceivedByAddressCmd{} var _ Cmd = &GetReceivedByAddressCmd{}
// NewGetReceivedByAddressCmd creates a new GetReceivedByAddressCmd. // NewGetReceivedByAddressCmd creates a new GetReceivedByAddressCmd.
func NewGetReceivedByAddressCmd(id interface{}, optArgs ...interface{}) (*GetReceivedByAddressCmd, error) { func NewGetReceivedByAddressCmd(id interface{}, address string, optArgs ...int) (*GetReceivedByAddressCmd, error) {
if len(optArgs) > 2 { if len(optArgs) > 1 {
return nil, ErrTooManyOptArgs return nil, ErrTooManyOptArgs
} }
var address string
if len(optArgs) > 0 {
a, ok := optArgs[0].(string)
if !ok {
return nil, errors.New("first optional argument address is not a string")
}
address = a
}
var minconf int = 1 var minconf int = 1
if len(optArgs) > 1 { if len(optArgs) > 0 {
m, ok := optArgs[1].(int) minconf = optArgs[0]
if !ok {
return nil, errors.New("second optional argument minconf is not a int")
}
minconf = m
} }
return &GetReceivedByAddressCmd{ return &GetReceivedByAddressCmd{
id: id, id: id,
@ -3378,11 +3344,9 @@ func (cmd *GetReceivedByAddressCmd) MarshalJSON() ([]byte, error) {
Jsonrpc: "1.0", Jsonrpc: "1.0",
Method: "getreceivedbyaddress", Method: "getreceivedbyaddress",
Id: cmd.id, Id: cmd.id,
Params: []interface{}{}, Params: []interface{}{
} cmd.Address,
},
if cmd.Address != "" || cmd.MinConf != 1 {
raw.Params = append(raw.Params, cmd.Address)
} }
if cmd.MinConf != 1 { if cmd.MinConf != 1 {
@ -3404,16 +3368,12 @@ func (cmd *GetReceivedByAddressCmd) UnmarshalJSON(b []byte) error {
return ErrWrongNumberOfParams return ErrWrongNumberOfParams
} }
optArgs := make([]interface{}, 0, 2) address, ok := r.Params[0].(string)
if len(r.Params) > 0 { if !ok {
address, ok := r.Params[0].(string) return errors.New("first parameter address must be a string")
if !ok {
return errors.New("first optional parameter address must be a string")
}
optArgs = append(optArgs, address)
} }
optArgs := make([]int, 0, 1)
if len(r.Params) > 1 { if len(r.Params) > 1 {
minconf, ok := r.Params[1].(float64) minconf, ok := r.Params[1].(float64)
if !ok { if !ok {
@ -3423,7 +3383,7 @@ func (cmd *GetReceivedByAddressCmd) UnmarshalJSON(b []byte) error {
optArgs = append(optArgs, int(minconf)) optArgs = append(optArgs, int(minconf))
} }
newCmd, err := NewGetReceivedByAddressCmd(r.Id, optArgs...) newCmd, err := NewGetReceivedByAddressCmd(r.Id, address, optArgs...)
if err != nil { if err != nil {
return err return err
} }