diff --git a/blockdag/dag.go b/blockdag/dag.go index ad1bb4182..c30858152 100644 --- a/blockdag/dag.go +++ b/blockdag/dag.go @@ -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. // diff --git a/rpcmodel/rpc_results.go b/rpcmodel/rpc_results.go index a791d56b6..0517d525c 100644 --- a/rpcmodel/rpc_results.go +++ b/rpcmodel/rpc_results.go @@ -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 diff --git a/server/rpc/common.go b/server/rpc/common.go index 8005a7e8f..92f761f6a 100644 --- a/server/rpc/common.go +++ b/server/rpc/common.go @@ -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 { diff --git a/server/rpc/rpcserverhelp.go b/server/rpc/rpcserverhelp.go index 93d965598..00c61931c 100644 --- a/server/rpc/rpcserverhelp.go +++ b/server/rpc/rpcserverhelp.go @@ -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.",