From f696d49c494caf99ba6280ab55f55d4711907408 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 15 Aug 2018 21:02:33 -0700 Subject: [PATCH 1/2] btcjson/chainsvrresults: use int64 for verbose getblock[header] confs This commit modifies the parsed fields in GetBlockVerbose and GetBlockHeaderVerbose from a uint64 to an int64. bitcoind will return -1 if the requested block is not in the main chain, which causes a panic when trying to serialize into a uint. --- btcjson/chainsvrresults.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/btcjson/chainsvrresults.go b/btcjson/chainsvrresults.go index 24d6cf7c..30c6369a 100644 --- a/btcjson/chainsvrresults.go +++ b/btcjson/chainsvrresults.go @@ -11,7 +11,7 @@ import "encoding/json" // returns a hex-encoded string. type GetBlockHeaderVerboseResult struct { Hash string `json:"hash"` - Confirmations uint64 `json:"confirmations"` + Confirmations int64 `json:"confirmations"` Height int32 `json:"height"` Version int32 `json:"version"` VersionHex string `json:"versionHex"` @@ -29,7 +29,7 @@ type GetBlockHeaderVerboseResult struct { // hex-encoded string. type GetBlockVerboseResult struct { Hash string `json:"hash"` - Confirmations uint64 `json:"confirmations"` + Confirmations int64 `json:"confirmations"` StrippedSize int32 `json:"strippedsize"` Size int32 `json:"size"` Weight int32 `json:"weight"` From 85cb8f50a0b52e18c51b1492c512d2d6043d18e2 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 15 Aug 2018 21:05:34 -0700 Subject: [PATCH 2/2] rpcserver: convert verbose confirmations fields to int64 --- rpcserver.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 8475ef57..6ade888d 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1126,7 +1126,7 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i PreviousHash: blockHeader.PrevBlock.String(), Nonce: blockHeader.Nonce, Time: blockHeader.Timestamp.Unix(), - Confirmations: uint64(1 + best.Height - blockHeight), + Confirmations: int64(1 + best.Height - blockHeight), Height: int64(blockHeight), Size: int32(len(blkBytes)), StrippedSize: int32(blk.MsgBlock().SerializeSizeStripped()), @@ -1364,7 +1364,7 @@ func handleGetBlockHeader(s *rpcServer, cmd interface{}, closeChan <-chan struct params := s.cfg.ChainParams blockHeaderReply := btcjson.GetBlockHeaderVerboseResult{ Hash: c.Hash, - Confirmations: uint64(1 + best.Height - blockHeight), + Confirmations: int64(1 + best.Height - blockHeight), Height: blockHeight, Version: blockHeader.Version, VersionHex: fmt.Sprintf("%08x", blockHeader.Version),