mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[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:
parent
f8e851a6ed
commit
3d04e6bded
@ -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.
|
||||
//
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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.",
|
||||
|
Loading…
x
Reference in New Issue
Block a user