ListAllTransactions - allow nil for account name
This commit is contained in:
parent
47d862e482
commit
32205c5552
2 changed files with 17 additions and 13 deletions
10
cmds.go
10
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)
|
||||
}
|
||||
|
||||
|
|
20
cmds_test.go
20
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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue