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.
This commit is contained in:
parent
d9cba7ca6a
commit
8412cde46f
3 changed files with 11 additions and 11 deletions
|
@ -87,12 +87,12 @@ type BlockDetails struct {
|
||||||
// RecvTxNtfn defines the recvtx JSON-RPC notification.
|
// RecvTxNtfn defines the recvtx JSON-RPC notification.
|
||||||
type RecvTxNtfn struct {
|
type RecvTxNtfn struct {
|
||||||
HexTx string
|
HexTx string
|
||||||
Block BlockDetails
|
Block *BlockDetails
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRecvTxNtfn returns a new instance which can be used to issue a recvtx
|
// NewRecvTxNtfn returns a new instance which can be used to issue a recvtx
|
||||||
// JSON-RPC notification.
|
// JSON-RPC notification.
|
||||||
func NewRecvTxNtfn(hexTx string, block BlockDetails) *RecvTxNtfn {
|
func NewRecvTxNtfn(hexTx string, block *BlockDetails) *RecvTxNtfn {
|
||||||
return &RecvTxNtfn{
|
return &RecvTxNtfn{
|
||||||
HexTx: hexTx,
|
HexTx: hexTx,
|
||||||
Block: block,
|
Block: block,
|
||||||
|
@ -102,12 +102,12 @@ func NewRecvTxNtfn(hexTx string, block BlockDetails) *RecvTxNtfn {
|
||||||
// RedeemingTxNtfn defines the redeemingtx JSON-RPC notification.
|
// RedeemingTxNtfn defines the redeemingtx JSON-RPC notification.
|
||||||
type RedeemingTxNtfn struct {
|
type RedeemingTxNtfn struct {
|
||||||
HexTx string
|
HexTx string
|
||||||
Block BlockDetails
|
Block *BlockDetails
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRedeemingTxNtfn returns a new instance which can be used to issue a
|
// NewRedeemingTxNtfn returns a new instance which can be used to issue a
|
||||||
// redeemingtx JSON-RPC notification.
|
// redeemingtx JSON-RPC notification.
|
||||||
func NewRedeemingTxNtfn(hexTx string, block BlockDetails) *RedeemingTxNtfn {
|
func NewRedeemingTxNtfn(hexTx string, block *BlockDetails) *RedeemingTxNtfn {
|
||||||
return &RedeemingTxNtfn{
|
return &RedeemingTxNtfn{
|
||||||
HexTx: hexTx,
|
HexTx: hexTx,
|
||||||
Block: block,
|
Block: block,
|
||||||
|
|
|
@ -68,12 +68,12 @@ func TestChainSvrWsNtfns(t *testing.T) {
|
||||||
Index: 0,
|
Index: 0,
|
||||||
Time: 12345678,
|
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}`,
|
marshalled: `{"jsonrpc":"1.0","method":"recvtx","params":["001122",{"height":100000,"hash":"123","index":0,"time":12345678}],"id":null}`,
|
||||||
unmarshalled: &btcjson.RecvTxNtfn{
|
unmarshalled: &btcjson.RecvTxNtfn{
|
||||||
HexTx: "001122",
|
HexTx: "001122",
|
||||||
Block: btcjson.BlockDetails{
|
Block: &btcjson.BlockDetails{
|
||||||
Height: 100000,
|
Height: 100000,
|
||||||
Hash: "123",
|
Hash: "123",
|
||||||
Index: 0,
|
Index: 0,
|
||||||
|
@ -93,12 +93,12 @@ func TestChainSvrWsNtfns(t *testing.T) {
|
||||||
Index: 0,
|
Index: 0,
|
||||||
Time: 12345678,
|
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}`,
|
marshalled: `{"jsonrpc":"1.0","method":"redeemingtx","params":["001122",{"height":100000,"hash":"123","index":0,"time":12345678}],"id":null}`,
|
||||||
unmarshalled: &btcjson.RedeemingTxNtfn{
|
unmarshalled: &btcjson.RedeemingTxNtfn{
|
||||||
HexTx: "001122",
|
HexTx: "001122",
|
||||||
Block: btcjson.BlockDetails{
|
Block: &btcjson.BlockDetails{
|
||||||
Height: 100000,
|
Height: 100000,
|
||||||
Hash: "123",
|
Hash: "123",
|
||||||
Index: 0,
|
Index: 0,
|
||||||
|
|
|
@ -614,7 +614,7 @@ func blockDetails(block *btcutil.Block, txIndex int) *btcjson.BlockDetails {
|
||||||
// with the passed parameters.
|
// with the passed parameters.
|
||||||
func newRedeemingTxNotification(txHex string, index int, block *btcutil.Block) ([]byte, error) {
|
func newRedeemingTxNotification(txHex string, index int, block *btcutil.Block) ([]byte, error) {
|
||||||
// Create and marshal the notification.
|
// Create and marshal the notification.
|
||||||
ntfn := btcjson.NewRedeemingTxNtfn(txHex, *blockDetails(block, index))
|
ntfn := btcjson.NewRedeemingTxNtfn(txHex, blockDetails(block, index))
|
||||||
return btcjson.MarshalCmd(nil, ntfn)
|
return btcjson.MarshalCmd(nil, ntfn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,7 +648,7 @@ func (m *wsNotificationManager) notifyForTxOuts(ops map[wire.OutPoint]map[chan s
|
||||||
if txHex == "" {
|
if txHex == "" {
|
||||||
txHex = txHexString(tx)
|
txHex = txHexString(tx)
|
||||||
}
|
}
|
||||||
ntfn := btcjson.NewRecvTxNtfn(txHex, *blockDetails(block,
|
ntfn := btcjson.NewRecvTxNtfn(txHex, blockDetails(block,
|
||||||
tx.Index()))
|
tx.Index()))
|
||||||
|
|
||||||
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
|
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
|
||||||
|
@ -1639,7 +1639,7 @@ func rescanBlock(wsc *wsClient, lookups *rescanKeys, blk *btcutil.Block) {
|
||||||
txHex = txHexString(tx)
|
txHex = txHexString(tx)
|
||||||
}
|
}
|
||||||
ntfn := btcjson.NewRecvTxNtfn(txHex,
|
ntfn := btcjson.NewRecvTxNtfn(txHex,
|
||||||
*blockDetails(blk, tx.Index()))
|
blockDetails(blk, tx.Index()))
|
||||||
|
|
||||||
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
|
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue