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

View file

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