From 8412cde46fb36282e79dcbaa4fd2f15712b87533 Mon Sep 17 00:00:00 2001
From: David Hill <dhill@mindcry.org>
Date: Thu, 26 Feb 2015 19:35:46 -0500
Subject: [PATCH] btcjson: Fix a bug in btcjson v2

btcjson v2 switched an optional field to mandatory which resulted
in a nil deference.  This switches it back to optional.
---
 btcjson/v2/btcjson/chainsvrwsntfns.go      | 8 ++++----
 btcjson/v2/btcjson/chainsvrwsntfns_test.go | 8 ++++----
 rpcwebsocket.go                            | 6 +++---
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/btcjson/v2/btcjson/chainsvrwsntfns.go b/btcjson/v2/btcjson/chainsvrwsntfns.go
index 8a8ef4b3..f567817c 100644
--- a/btcjson/v2/btcjson/chainsvrwsntfns.go
+++ b/btcjson/v2/btcjson/chainsvrwsntfns.go
@@ -87,12 +87,12 @@ type BlockDetails struct {
 // RecvTxNtfn defines the recvtx JSON-RPC notification.
 type RecvTxNtfn struct {
 	HexTx string
-	Block BlockDetails
+	Block *BlockDetails
 }
 
 // NewRecvTxNtfn returns a new instance which can be used to issue a recvtx
 // JSON-RPC notification.
-func NewRecvTxNtfn(hexTx string, block BlockDetails) *RecvTxNtfn {
+func NewRecvTxNtfn(hexTx string, block *BlockDetails) *RecvTxNtfn {
 	return &RecvTxNtfn{
 		HexTx: hexTx,
 		Block: block,
@@ -102,12 +102,12 @@ func NewRecvTxNtfn(hexTx string, block BlockDetails) *RecvTxNtfn {
 // RedeemingTxNtfn defines the redeemingtx JSON-RPC notification.
 type RedeemingTxNtfn struct {
 	HexTx string
-	Block BlockDetails
+	Block *BlockDetails
 }
 
 // NewRedeemingTxNtfn returns a new instance which can be used to issue a
 // redeemingtx JSON-RPC notification.
-func NewRedeemingTxNtfn(hexTx string, block BlockDetails) *RedeemingTxNtfn {
+func NewRedeemingTxNtfn(hexTx string, block *BlockDetails) *RedeemingTxNtfn {
 	return &RedeemingTxNtfn{
 		HexTx: hexTx,
 		Block: block,
diff --git a/btcjson/v2/btcjson/chainsvrwsntfns_test.go b/btcjson/v2/btcjson/chainsvrwsntfns_test.go
index 37b03871..bc5e3464 100644
--- a/btcjson/v2/btcjson/chainsvrwsntfns_test.go
+++ b/btcjson/v2/btcjson/chainsvrwsntfns_test.go
@@ -68,12 +68,12 @@ func TestChainSvrWsNtfns(t *testing.T) {
 					Index:  0,
 					Time:   12345678,
 				}
-				return btcjson.NewRecvTxNtfn("001122", blockDetails)
+				return btcjson.NewRecvTxNtfn("001122", &blockDetails)
 			},
 			marshalled: `{"jsonrpc":"1.0","method":"recvtx","params":["001122",{"height":100000,"hash":"123","index":0,"time":12345678}],"id":null}`,
 			unmarshalled: &btcjson.RecvTxNtfn{
 				HexTx: "001122",
-				Block: btcjson.BlockDetails{
+				Block: &btcjson.BlockDetails{
 					Height: 100000,
 					Hash:   "123",
 					Index:  0,
@@ -93,12 +93,12 @@ func TestChainSvrWsNtfns(t *testing.T) {
 					Index:  0,
 					Time:   12345678,
 				}
-				return btcjson.NewRedeemingTxNtfn("001122", blockDetails)
+				return btcjson.NewRedeemingTxNtfn("001122", &blockDetails)
 			},
 			marshalled: `{"jsonrpc":"1.0","method":"redeemingtx","params":["001122",{"height":100000,"hash":"123","index":0,"time":12345678}],"id":null}`,
 			unmarshalled: &btcjson.RedeemingTxNtfn{
 				HexTx: "001122",
-				Block: btcjson.BlockDetails{
+				Block: &btcjson.BlockDetails{
 					Height: 100000,
 					Hash:   "123",
 					Index:  0,
diff --git a/rpcwebsocket.go b/rpcwebsocket.go
index 008995bc..8dfee73c 100644
--- a/rpcwebsocket.go
+++ b/rpcwebsocket.go
@@ -614,7 +614,7 @@ func blockDetails(block *btcutil.Block, txIndex int) *btcjson.BlockDetails {
 // with the passed parameters.
 func newRedeemingTxNotification(txHex string, index int, block *btcutil.Block) ([]byte, error) {
 	// Create and marshal the notification.
-	ntfn := btcjson.NewRedeemingTxNtfn(txHex, *blockDetails(block, index))
+	ntfn := btcjson.NewRedeemingTxNtfn(txHex, blockDetails(block, index))
 	return btcjson.MarshalCmd(nil, ntfn)
 }
 
@@ -648,7 +648,7 @@ func (m *wsNotificationManager) notifyForTxOuts(ops map[wire.OutPoint]map[chan s
 			if txHex == "" {
 				txHex = txHexString(tx)
 			}
-			ntfn := btcjson.NewRecvTxNtfn(txHex, *blockDetails(block,
+			ntfn := btcjson.NewRecvTxNtfn(txHex, blockDetails(block,
 				tx.Index()))
 
 			marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
@@ -1639,7 +1639,7 @@ func rescanBlock(wsc *wsClient, lookups *rescanKeys, blk *btcutil.Block) {
 					txHex = txHexString(tx)
 				}
 				ntfn := btcjson.NewRecvTxNtfn(txHex,
-					*blockDetails(blk, tx.Index()))
+					blockDetails(blk, tx.Index()))
 
 				marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
 				if err != nil {