mirror of
https://github.com/btcsuite/btcd.git
synced 2025-01-19 05:33:36 +01:00
rpcclient: implement addwitnessaddress
This commit is contained in:
parent
e4a6228752
commit
fe786c93b6
@ -943,6 +943,44 @@ func (c *Client) GetRawChangeAddress(account string) (btcutil.Address, error) {
|
||||
return c.GetRawChangeAddressAsync(account).Receive()
|
||||
}
|
||||
|
||||
// FutureAddWitnessAddressResult is a future promise to deliver the result of
|
||||
// a AddWitnessAddressAsync RPC invocation (or an applicable error).
|
||||
type FutureAddWitnessAddressResult chan *response
|
||||
|
||||
// Receive waits for the response promised by the future and returns the new
|
||||
// address.
|
||||
func (r FutureAddWitnessAddressResult) Receive() (btcutil.Address, error) {
|
||||
res, err := receiveFuture(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Unmarshal result as a string.
|
||||
var addr string
|
||||
err = json.Unmarshal(res, &addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return btcutil.DecodeAddress(addr, &chaincfg.MainNetParams)
|
||||
}
|
||||
|
||||
// AddWitnessAddressAsync 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 AddWitnessAddress for the blocking version and more details.
|
||||
func (c *Client) AddWitnessAddressAsync(address string) FutureAddWitnessAddressResult {
|
||||
cmd := btcjson.NewAddWitnessAddressCmd(address)
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// AddWitnessAddress adds a witness address for a script and returns the new
|
||||
// address (P2SH of the witness script).
|
||||
func (c *Client) AddWitnessAddress(address string) (btcutil.Address, error) {
|
||||
return c.AddWitnessAddressAsync(address).Receive()
|
||||
}
|
||||
|
||||
// FutureGetAccountAddressResult is a future promise to deliver the result of a
|
||||
// GetAccountAddressAsync RPC invocation (or an applicable error).
|
||||
type FutureGetAccountAddressResult chan *response
|
||||
|
Loading…
Reference in New Issue
Block a user