diff --git a/btcjson/walletsvrcmds.go b/btcjson/walletsvrcmds.go index 6697555172..3f7f85fd9b 100644 --- a/btcjson/walletsvrcmds.go +++ b/btcjson/walletsvrcmds.go @@ -166,7 +166,8 @@ 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 @@ -174,9 +175,10 @@ type GetNewAddressCmd struct { // // 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, } } diff --git a/btcjson/walletsvrcmds_test.go b/btcjson/walletsvrcmds_test.go index efc08cc945..6d18903769 100644 --- a/btcjson/walletsvrcmds_test.go +++ b/btcjson/walletsvrcmds_test.go @@ -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{ @@ -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")) + }, + 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) { diff --git a/rpcclient/wallet.go b/rpcclient/wallet.go index 27546f5de0..8b539e5a91 100644 --- a/rpcclient/wallet.go +++ b/rpcclient/wallet.go @@ -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) } @@ -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