Skip to content

Commit

Permalink
btcjson: add addresstype arg to getrawchangeaddress
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Mar 8, 2022
1 parent b5bce57 commit d18d177
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
8 changes: 5 additions & 3 deletions btcjson/walletsvrcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,19 @@ func NewGetNewAddressCmd(account, addrType *string) *GetNewAddressCmd {

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

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

Expand Down
14 changes: 8 additions & 6 deletions btcjson/walletsvrcmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,24 +407,26 @@ func TestWalletSvrCmds(t *testing.T) {
return btcjson.NewCmd("getrawchangeaddress")
},
staticCmd: func() interface{} {
return btcjson.NewGetRawChangeAddressCmd(nil)
return btcjson.NewGetRawChangeAddressCmd(nil, nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getrawchangeaddress","params":[],"id":1}`,
unmarshalled: &btcjson.GetRawChangeAddressCmd{
Account: nil,
Account: nil,
AddressType: nil,
},
},
{
name: "getrawchangeaddress optional",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getrawchangeaddress", "acct")
return btcjson.NewCmd("getrawchangeaddress", "acct", "legacy")
},
staticCmd: func() interface{} {
return btcjson.NewGetRawChangeAddressCmd(btcjson.String("acct"))
return btcjson.NewGetRawChangeAddressCmd(btcjson.String("acct"), btcjson.String("legacy"))
},
marshalled: `{"jsonrpc":"1.0","method":"getrawchangeaddress","params":["acct"],"id":1}`,
marshalled: `{"jsonrpc":"1.0","method":"getrawchangeaddress","params":["acct","legacy"],"id":1}`,
unmarshalled: &btcjson.GetRawChangeAddressCmd{
Account: btcjson.String("acct"),
Account: btcjson.String("acct"),
AddressType: btcjson.String("legacy"),
},
},
{
Expand Down
8 changes: 4 additions & 4 deletions rpcclient/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,8 @@ func (r FutureGetRawChangeAddressResult) Receive() (btcutil.Address, error) {
// function on the returned instance.
//
// See GetRawChangeAddress for the blocking version and more details.
func (c *Client) GetRawChangeAddressAsync(account string) FutureGetRawChangeAddressResult {
cmd := btcjson.NewGetRawChangeAddressCmd(&account)
func (c *Client) GetRawChangeAddressAsync(account, addrType string) FutureGetRawChangeAddressResult {
cmd := btcjson.NewGetRawChangeAddressCmd(&account, &addrType)
result := FutureGetRawChangeAddressResult{
network: c.chainParams,
responseChannel: c.SendCmd(cmd),
Expand All @@ -1147,8 +1147,8 @@ func (c *Client) GetRawChangeAddressAsync(account string) FutureGetRawChangeAddr
// GetRawChangeAddress returns a new address for receiving change that will be
// associated with the provided account. Note that this is only for raw
// transactions and NOT for normal use.
func (c *Client) GetRawChangeAddress(account string) (btcutil.Address, error) {
return c.GetRawChangeAddressAsync(account).Receive()
func (c *Client) GetRawChangeAddress(account, addrType string) (btcutil.Address, error) {
return c.GetRawChangeAddressAsync(account, addrType).Receive()
}

// FutureAddWitnessAddressResult is a future promise to deliver the result of
Expand Down

0 comments on commit d18d177

Please sign in to comment.