diff --git a/cmds.go b/cmds.go index fd10d736..cc3f33a1 100644 --- a/cmds.go +++ b/cmds.go @@ -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) } diff --git a/cmds_test.go b/cmds_test.go index 29c9b72a..91950f61 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -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, }, }, }