From fe786c93b6f4e0c96d6b19157b72963a9b50293d Mon Sep 17 00:00:00 2001
From: Jeremiah Goyette <jsgoyette@gmail.com>
Date: Tue, 12 Sep 2017 00:07:53 -0500
Subject: [PATCH] rpcclient: implement addwitnessaddress

---
 rpcclient/wallet.go | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/rpcclient/wallet.go b/rpcclient/wallet.go
index 889a28d5..10c12f1f 100644
--- a/rpcclient/wallet.go
+++ b/rpcclient/wallet.go
@@ -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