ListAllTransactions - allow nil for account name

This commit is contained in:
Javed Khan 2014-11-20 11:03:56 +05:30
parent 47d862e482
commit 32205c5552
2 changed files with 17 additions and 13 deletions

10
cmds.go
View file

@ -1568,7 +1568,7 @@ func (cmd *ListAddressTransactionsCmd) UnmarshalJSON(b []byte) error {
// unmarshaling of listalltransactions JSON websocket extension commands. // unmarshaling of listalltransactions JSON websocket extension commands.
type ListAllTransactionsCmd struct { type ListAllTransactionsCmd struct {
id interface{} id interface{}
Account string Account *string
} }
// Enforce that ListAllTransactionsCmd satisifies the btcjson.Cmd // Enforce that ListAllTransactionsCmd satisifies the btcjson.Cmd
@ -1580,14 +1580,16 @@ func NewListAllTransactionsCmd(id interface{},
optArgs ...string) (*ListAllTransactionsCmd, error) { optArgs ...string) (*ListAllTransactionsCmd, error) {
// Optional arguments set to their default values. // Optional arguments set to their default values.
account := "" var account *string
if len(optArgs) > 1 { if len(optArgs) > 1 {
return nil, btcjson.ErrInvalidParams return nil, btcjson.ErrInvalidParams
} else {
account = nil
} }
if len(optArgs) == 1 { if len(optArgs) == 1 {
account = optArgs[0] account = &optArgs[0]
} }
return &ListAllTransactionsCmd{ return &ListAllTransactionsCmd{
@ -1630,7 +1632,7 @@ func (cmd *ListAllTransactionsCmd) 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 *ListAllTransactionsCmd) MarshalJSON() ([]byte, error) { func (cmd *ListAllTransactionsCmd) MarshalJSON() ([]byte, error) {
params := make([]interface{}, 0, 1) params := make([]interface{}, 0, 1)
if cmd.Account != "" { if cmd.Account != nil {
params = append(params, cmd.Account) params = append(params, cmd.Account)
} }

View file

@ -13,6 +13,8 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
) )
var testAccount = "account"
var cmdtests = []struct { var cmdtests = []struct {
name string name string
f func() (btcjson.Cmd, error) f func() (btcjson.Cmd, error)
@ -74,11 +76,11 @@ var cmdtests = []struct {
name: "getunconfirmedbalance one optarg", name: "getunconfirmedbalance one optarg",
f: func() (btcjson.Cmd, error) { f: func() (btcjson.Cmd, error) {
return NewGetUnconfirmedBalanceCmd(float64(1), return NewGetUnconfirmedBalanceCmd(float64(1),
"abcde") testAccount)
}, },
result: &GetUnconfirmedBalanceCmd{ result: &GetUnconfirmedBalanceCmd{
id: float64(1), id: float64(1),
Account: "abcde", Account: testAccount,
}, },
}, },
{ {
@ -108,11 +110,11 @@ var cmdtests = []struct {
return NewListAddressTransactionsCmd( return NewListAddressTransactionsCmd(
float64(1), float64(1),
addrs, addrs,
"abcde") testAccount)
}, },
result: &ListAddressTransactionsCmd{ result: &ListAddressTransactionsCmd{
id: float64(1), id: float64(1),
Account: "abcde", Account: testAccount,
Addresses: []string{ Addresses: []string{
"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH",
}, },
@ -125,7 +127,7 @@ var cmdtests = []struct {
}, },
result: &ListAllTransactionsCmd{ result: &ListAllTransactionsCmd{
id: float64(1), id: float64(1),
Account: "", Account: nil,
}, },
}, },
{ {
@ -133,11 +135,11 @@ var cmdtests = []struct {
f: func() (btcjson.Cmd, error) { f: func() (btcjson.Cmd, error) {
return NewListAllTransactionsCmd( return NewListAllTransactionsCmd(
float64(1), float64(1),
"abcde") testAccount)
}, },
result: &ListAllTransactionsCmd{ result: &ListAllTransactionsCmd{
id: float64(1), id: float64(1),
Account: "abcde", Account: &testAccount,
}, },
}, },
{ {
@ -290,11 +292,11 @@ var cmdtests = []struct {
f: func() (btcjson.Cmd, error) { f: func() (btcjson.Cmd, error) {
return NewWalletIsLockedCmd( return NewWalletIsLockedCmd(
float64(1), float64(1),
"abcde") testAccount)
}, },
result: &WalletIsLockedCmd{ result: &WalletIsLockedCmd{
id: float64(1), id: float64(1),
Account: "abcde", Account: testAccount,
}, },
}, },
} }