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 getnewaddresstype and revert breaking change #1844

Merged
merged 1 commit into from Jun 6, 2022
Merged
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
32 changes: 30 additions & 2 deletions btcjson/walletsvrcmds_test.go
Expand Up @@ -388,7 +388,21 @@ func TestWalletSvrCmds(t *testing.T) {
},
},
{
name: "getnewaddress optional",
name: "getnewaddress optional acct",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getnewaddress", "acct")
},
staticCmd: func() interface{} {
return btcjson.NewGetNewAddressCmd(btcjson.String("acct"), nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getnewaddress","params":["acct"],"id":1}`,
unmarshalled: &btcjson.GetNewAddressCmd{
Account: btcjson.String("acct"),
AddressType: nil,
},
},
{
name: "getnewaddress optional acct and type",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getnewaddress", "acct", "legacy")
},
Expand Down Expand Up @@ -416,7 +430,21 @@ func TestWalletSvrCmds(t *testing.T) {
},
},
{
name: "getrawchangeaddress optional",
name: "getrawchangeaddress optional acct",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getrawchangeaddress", "acct")
},
staticCmd: func() interface{} {
return btcjson.NewGetRawChangeAddressCmd(btcjson.String("acct"), nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getrawchangeaddress","params":["acct"],"id":1}`,
unmarshalled: &btcjson.GetRawChangeAddressCmd{
Account: btcjson.String("acct"),
AddressType: nil,
},
},
{
name: "getrawchangeaddress optional acct and type",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getrawchangeaddress", "acct", "legacy")
},
Expand Down
59 changes: 50 additions & 9 deletions rpcclient/wallet.go
Expand Up @@ -9,10 +9,10 @@ import (
"strconv"

"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcd/btcutil"
)

// *****************************
Expand Down Expand Up @@ -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, addrType string) FutureGetNewAddressResult {
cmd := btcjson.NewGetNewAddressCmd(&account, &addrType)
func (c *Client) GetNewAddressAsync(account string) FutureGetNewAddressResult {
cmd := btcjson.NewGetNewAddressCmd(&account, nil)
result := FutureGetNewAddressResult{
network: c.chainParams,
responseChannel: c.SendCmd(cmd),
Expand All @@ -1100,8 +1100,28 @@ func (c *Client) GetNewAddressAsync(account, addrType string) FutureGetNewAddres

// GetNewAddress returns a new address, and decodes based on the client's
// chain params.
func (c *Client) GetNewAddress(account, addrType string) (btcutil.Address, error) {
return c.GetNewAddressAsync(account, addrType).Receive()
func (c *Client) GetNewAddress(account string) (btcutil.Address, error) {
return c.GetNewAddressAsync(account).Receive()
}

// GetNewAddressTypeAsync 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 GetNewAddressType for the blocking version and more details.
func (c *Client) GetNewAddressTypeAsync(account, addrType string) FutureGetNewAddressResult {
cmd := btcjson.NewGetNewAddressCmd(&account, &addrType)
result := FutureGetNewAddressResult{
network: c.chainParams,
responseChannel: c.SendCmd(cmd),
}
return result
}

// GetNewAddressType returns a new address, and decodes based on the client's
// chain params.
func (c *Client) GetNewAddressType(account, addrType string) (btcutil.Address, error) {
return c.GetNewAddressTypeAsync(account, addrType).Receive()
}

// FutureGetRawChangeAddressResult is a future promise to deliver the result of
Expand Down Expand Up @@ -1135,8 +1155,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, addrType string) FutureGetRawChangeAddressResult {
cmd := btcjson.NewGetRawChangeAddressCmd(&account, &addrType)
func (c *Client) GetRawChangeAddressAsync(account string) FutureGetRawChangeAddressResult {
cmd := btcjson.NewGetRawChangeAddressCmd(&account, nil)
result := FutureGetRawChangeAddressResult{
network: c.chainParams,
responseChannel: c.SendCmd(cmd),
Expand All @@ -1147,8 +1167,29 @@ func (c *Client) GetRawChangeAddressAsync(account, addrType string) FutureGetRaw
// 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, addrType string) (btcutil.Address, error) {
return c.GetRawChangeAddressAsync(account, addrType).Receive()
func (c *Client) GetRawChangeAddress(account string) (btcutil.Address, error) {
return c.GetRawChangeAddressAsync(account).Receive()
}

// GetRawChangeAddressTypeAsync 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 GetRawChangeAddressType for the blocking version and more details.
func (c *Client) GetRawChangeAddressTypeAsync(account, addrType string) FutureGetRawChangeAddressResult {
cmd := btcjson.NewGetRawChangeAddressCmd(&account, &addrType)
result := FutureGetRawChangeAddressResult{
network: c.chainParams,
responseChannel: c.SendCmd(cmd),
}
return result
}

// GetRawChangeAddressType 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) GetRawChangeAddressType(account, addrType string) (btcutil.Address, error) {
return c.GetRawChangeAddressTypeAsync(account, addrType).Receive()
}

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