[NOD-943] Add acceptedBlockHashes to GetBlockVerboseResult (#708)

* [NOD-943] Add acceptedBlockHashes to GetBlockVerboseResult

* [NOD-943] Remove intermediate variables

* [NOD-943] Add block hash to error message

* [NOD-943] Change comment
This commit is contained in:
Ori Newman 2020-05-05 17:26:54 +03:00 committed by GitHub
parent f8e851a6ed
commit 3d04e6bded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 4 deletions

View File

@ -1489,6 +1489,21 @@ func (dag *BlockDAG) BlueScoreByBlockHash(hash *daghash.Hash) (uint64, error) {
return node.blueScore, nil
}
// BluesByBlockHash returns the blues of the block for the given hash.
func (dag *BlockDAG) BluesByBlockHash(hash *daghash.Hash) ([]*daghash.Hash, error) {
node := dag.index.LookupNode(hash)
if node == nil {
return nil, errors.Errorf("block %s is unknown", hash)
}
hashes := make([]*daghash.Hash, len(node.blues))
for i, blue := range node.blues {
hashes[i] = blue.hash
}
return hashes, nil
}
// BlockConfirmationsByHash returns the confirmations number for a block with the
// given hash. See blockConfirmations for further details.
//

View File

@ -46,8 +46,9 @@ type GetBlockVerboseResult struct {
Bits string `json:"bits"`
Difficulty float64 `json:"difficulty"`
ParentHashes []string `json:"parentHashes"`
SelectedParentHash string `json:"selectedParentHash,omitempty"`
ChildHashes []string `json:"childHashes,omitempty"`
SelectedParentHash string `json:"selectedParentHash"`
ChildHashes []string `json:"childHashes"`
AcceptedBlockHashes []string `json:"acceptedBlockHashes"`
}
// CreateMultiSigResult models the data returned from the createmultisig

View File

@ -221,7 +221,6 @@ func buildGetBlockVerboseResult(s *Server, block *util.Block, isVerboseTx bool)
context := "No next block"
return nil, internalRPCError(err.Error(), context)
}
childHashStrings := daghash.Strings(childHashes)
blockConfirmations, err := s.cfg.DAG.BlockConfirmationsByHashNoLock(hash)
if err != nil {
@ -245,6 +244,12 @@ func buildGetBlockVerboseResult(s *Server, block *util.Block, isVerboseTx bool)
return nil, internalRPCError(err.Error(), context)
}
acceptedBlockHashes, err := s.cfg.DAG.BluesByBlockHash(hash)
if err != nil {
context := fmt.Sprintf("Could not get block accepted blocks for block %s", hash)
return nil, internalRPCError(err.Error(), context)
}
result := &rpcmodel.GetBlockVerboseResult{
Hash: hash.String(),
Version: blockHeader.Version,
@ -262,7 +267,8 @@ func buildGetBlockVerboseResult(s *Server, block *util.Block, isVerboseTx bool)
Size: int32(block.MsgBlock().SerializeSize()),
Bits: strconv.FormatInt(int64(blockHeader.Bits), 16),
Difficulty: getDifficultyRatio(blockHeader.Bits, params),
ChildHashes: childHashStrings,
ChildHashes: daghash.Strings(childHashes),
AcceptedBlockHashes: daghash.Strings(acceptedBlockHashes),
}
if isVerboseTx {

View File

@ -252,6 +252,7 @@ var helpDescsEnUS = map[string]string{
"getBlockVerboseResult-parentHashes": "The hashes of the parent blocks",
"getBlockVerboseResult-selectedParentHash": "The selected parent hash",
"getBlockVerboseResult-childHashes": "The hashes of the child blocks (only if there are any)",
"getBlockVerboseResult-acceptedBlockHashes": "The hashes of the blocks accepted by this block",
// GetBlockCountCmd help.
"getBlockCount--synopsis": "Returns the number of blocks in the block DAG.",