mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 01:40:07 +01:00
btcjson: add addresstype arg to getnewaddress
This commit is contained in:
parent
e0149d63a1
commit
061aef98af
@ -117,6 +117,9 @@ const (
|
||||
// example, key not found, etc.
|
||||
ErrRPCWallet RPCErrorCode = -4
|
||||
|
||||
// ErrRPCWalletInvalidAddressType indicates an invalid address type.
|
||||
ErrRPCWalletInvalidAddressType RPCErrorCode = -5
|
||||
|
||||
// ErrRPCWalletInsufficientFunds indicates that there are not enough
|
||||
// funds in wallet or account.
|
||||
ErrRPCWalletInsufficientFunds RPCErrorCode = -6
|
||||
|
@ -242,7 +242,8 @@ func NewGetBalancesCmd() *GetBalancesCmd {
|
||||
|
||||
// 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
|
||||
@ -250,9 +251,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, addrType *string) *GetNewAddressCmd {
|
||||
return &GetNewAddressCmd{
|
||||
Account: account,
|
||||
Account: account,
|
||||
AddressType: addrType,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,24 +379,26 @@ 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{
|
||||
Account: nil,
|
||||
Account: nil,
|
||||
AddressType: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getnewaddress optional",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("getnewaddress", "acct")
|
||||
return btcjson.NewCmd("getnewaddress", "acct", "legacy")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewGetNewAddressCmd(btcjson.String("acct"))
|
||||
return btcjson.NewGetNewAddressCmd(btcjson.String("acct"), btcjson.String("legacy"))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"getnewaddress","params":["acct"],"id":1}`,
|
||||
marshalled: `{"jsonrpc":"1.0","method":"getnewaddress","params":["acct","legacy"],"id":1}`,
|
||||
unmarshalled: &btcjson.GetNewAddressCmd{
|
||||
Account: btcjson.String("acct"),
|
||||
Account: btcjson.String("acct"),
|
||||
AddressType: btcjson.String("legacy"),
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -1089,8 +1089,8 @@ func (r FutureGetNewAddressResult) Receive() (btcutil.Address, error) {
|
||||
// returned instance.
|
||||
//
|
||||
// See GetNewAddress for the blocking version and more details.
|
||||
func (c *Client) GetNewAddressAsync(account string) FutureGetNewAddressResult {
|
||||
cmd := btcjson.NewGetNewAddressCmd(&account)
|
||||
func (c *Client) GetNewAddressAsync(account, addrType string) FutureGetNewAddressResult {
|
||||
cmd := btcjson.NewGetNewAddressCmd(&account, &addrType)
|
||||
result := FutureGetNewAddressResult{
|
||||
network: c.chainParams,
|
||||
responseChannel: c.SendCmd(cmd),
|
||||
@ -1100,8 +1100,8 @@ func (c *Client) GetNewAddressAsync(account string) FutureGetNewAddressResult {
|
||||
|
||||
// GetNewAddress returns a new address, and decodes based on the client's
|
||||
// chain params.
|
||||
func (c *Client) GetNewAddress(account string) (btcutil.Address, error) {
|
||||
return c.GetNewAddressAsync(account).Receive()
|
||||
func (c *Client) GetNewAddress(account, addrType string) (btcutil.Address, error) {
|
||||
return c.GetNewAddressAsync(account, addrType).Receive()
|
||||
}
|
||||
|
||||
// FutureGetRawChangeAddressResult is a future promise to deliver the result of
|
||||
|
Loading…
Reference in New Issue
Block a user