Skip to content

Commit

Permalink
rpc: update getblock response
Browse files Browse the repository at this point in the history
  • Loading branch information
roylee17 committed Sep 28, 2021
1 parent f53d9c8 commit 54348e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions btcjson/chainsvrresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type GetBlockHeaderVerboseResult struct {
Version int32 `json:"version"`
VersionHex string `json:"versionHex"`
MerkleRoot string `json:"merkleroot"`
ClaimTrie string `json:"claimtrie"`
ClaimTrie string `json:"claimtrie,omitempty"`
Time int64 `json:"time"`
Nonce uint64 `json:"nonce"`
Bits string `json:"bits"`
Expand Down Expand Up @@ -82,14 +82,14 @@ type GetBlockVerboseResult struct {
Version int32 `json:"version"`
VersionHex string `json:"versionHex"`
MerkleRoot string `json:"merkleroot"`
ClaimTrie string `json:"claimTrie"`
ClaimTrie string `json:"claimTrie,omitempty"`
Tx []string `json:"tx,omitempty"`
RawTx []TxRawResult `json:"rawtx,omitempty"` // Note: this field is always empty when verbose != 2.
Time int64 `json:"time"`
Nonce uint32 `json:"nonce"`
Bits string `json:"bits"`
Difficulty float64 `json:"difficulty"`
PreviousHash string `json:"previousblockhash"`
PreviousHash string `json:"previousblockhash,omitempty"`
NextHash string `json:"nextblockhash,omitempty"`
}

Expand Down
7 changes: 6 additions & 1 deletion rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,16 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i

params := s.cfg.ChainParams
blockHeader := &blk.MsgBlock().Header
var prevHashString string
if blockHeight > 0 {
prevHashString = blockHeader.PrevBlock.String()
}
blockReply := btcjson.GetBlockVerboseResult{
Hash: c.Hash,
Version: blockHeader.Version,
VersionHex: fmt.Sprintf("%08x", blockHeader.Version),
MerkleRoot: blockHeader.MerkleRoot.String(),
PreviousHash: blockHeader.PrevBlock.String(),
PreviousHash: prevHashString,
Nonce: blockHeader.Nonce,
Time: blockHeader.Timestamp.Unix(),
Confirmations: int64(1 + best.Height - blockHeight),
Expand All @@ -1204,6 +1208,7 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
Bits: strconv.FormatInt(int64(blockHeader.Bits), 16),
Difficulty: getDifficultyRatio(blockHeader.Bits, params),
NextHash: nextHashString,
ClaimTrie: blockHeader.ClaimTrie.String(),
}

if *c.Verbosity == 1 {
Expand Down

0 comments on commit 54348e8

Please sign in to comment.