btcjson: add addresstype arg to getrawchangeaddress

This commit is contained in:
Jonathan Chappelow 2021-12-22 10:55:09 -06:00 committed by John C. Vernaleo
parent 061aef98af
commit 7eaf360063
3 changed files with 17 additions and 13 deletions

View File

@ -260,7 +260,8 @@ 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
@ -268,9 +269,10 @@ type GetRawChangeAddressCmd struct {
//
// 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,
}
}

View File

@ -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"),
},
},
{

View File

@ -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),
@ -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