Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcclient: Add addressType to GenNewAddress #1567

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions btcjson/walletsvrcmds.go
Expand Up @@ -166,17 +166,19 @@ func NewGetBalanceCmd(account *string, minConf *int) *GetBalanceCmd {

// GetNewAddressCmd defines the getnewaddress JSON-RPC command.
type GetNewAddressCmd struct {
Account *string
Account *string
AddressType *string
}

// NewGetNewAddressCmd returns a new instance which can be used to issue a
// getnewaddress JSON-RPC command.
//
// The parameters which are pointers indicate they are optional. Passing nil
// for optional parameters will use the default value.
func NewGetNewAddressCmd(account *string) *GetNewAddressCmd {
func NewGetNewAddressCmd(account, addressType *string) *GetNewAddressCmd {
return &GetNewAddressCmd{
Account: account,
Account: account,
AddressType: addressType,
}
}

Expand Down
18 changes: 16 additions & 2 deletions btcjson/walletsvrcmds_test.go
Expand Up @@ -228,7 +228,7 @@ func TestWalletSvrCmds(t *testing.T) {
return btcjson.NewCmd("getnewaddress")
},
staticCmd: func() interface{} {
return btcjson.NewGetNewAddressCmd(nil)
return btcjson.NewGetNewAddressCmd(nil, nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getnewaddress","params":[],"id":1}`,
unmarshalled: &btcjson.GetNewAddressCmd{
Expand All @@ -241,13 +241,27 @@ func TestWalletSvrCmds(t *testing.T) {
return btcjson.NewCmd("getnewaddress", "acct")
},
staticCmd: func() interface{} {
return btcjson.NewGetNewAddressCmd(btcjson.String("acct"))
return btcjson.NewGetNewAddressCmd(btcjson.String("acct"), nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getnewaddress","params":["acct"],"id":1}`,
unmarshalled: &btcjson.GetNewAddressCmd{
Account: btcjson.String("acct"),
},
},
{
name: "getnewaddress optional addressType",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getnewaddress", "acct", "bech32")
},
staticCmd: func() interface{} {
return btcjson.NewGetNewAddressCmd(btcjson.String("acct"), btcjson.String("bech32"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add another test for the case when the label is nil and the address type is specified?

btcjson.NewGetNewAddressCmd(nil, btcjson.String("bech32"))

},
marshalled: `{"jsonrpc":"1.0","method":"getnewaddress","params":["acct","bech32"],"id":1}`,
unmarshalled: &btcjson.GetNewAddressCmd{
Account: btcjson.String("acct"),
AddressType: btcjson.String("bech32"),
},
},
{
name: "getrawchangeaddress",
newCmd: func() (interface{}, error) {
Expand Down
17 changes: 16 additions & 1 deletion rpcclient/wallet.go
Expand Up @@ -894,7 +894,7 @@ func (r FutureGetNewAddressResult) Receive() (btcutil.Address, error) {
//
// See GetNewAddress for the blocking version and more details.
func (c *Client) GetNewAddressAsync(account string) FutureGetNewAddressResult {
cmd := btcjson.NewGetNewAddressCmd(&account)
cmd := btcjson.NewGetNewAddressCmd(&account, nil)
return c.sendCmd(cmd)
}

Expand All @@ -903,6 +903,21 @@ func (c *Client) GetNewAddress(account string) (btcutil.Address, error) {
return c.GetNewAddressAsync(account).Receive()
}

// GetNewAddressWithTypeAsync returns an instance of a type that can be used to get the
// result of the RPC at some future time by invoking the Receive function on the
// returned instance.
//
// See GetNewAddressWithType for the blocking version and more details.
func (c *Client) GetNewAddressWithTypeAsync(account, addressType string) FutureGetNewAddressResult {
cmd := btcjson.NewGetNewAddressCmd(&account, &addressType)
return c.sendCmd(cmd)
}

// GetNewAddressWithType returns a new address with specified type.
func (c *Client) GetNewAddressWithType(account, addressType string) (btcutil.Address, error) {
return c.GetNewAddressWithTypeAsync(account, addressType).Receive()
}

// FutureGetRawChangeAddressResult is a future promise to deliver the result of
// a GetRawChangeAddressAsync RPC invocation (or an applicable error).
type FutureGetRawChangeAddressResult chan *response
Expand Down