Skip to content

Commit

Permalink
chore: add also commit and validato set to block by height
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id committed Oct 23, 2024
1 parent 72dd961 commit 7754fd7
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions rpc/grpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ func (blockAPI *BlockAPI) BlockByHash(req *BlockByHashRequest, stream BlockAPI_B
func (blockAPI *BlockAPI) BlockByHeight(req *BlockByHeightRequest, stream BlockAPI_BlockByHeightServer) error {
blockStore := core.GetEnvironment().BlockStore
blockMeta := blockStore.LoadBlockMeta(req.Height)

commit := blockStore.LoadBlockCommit(blockMeta.Header.Height).ToProto()

validatorSet, err := core.GetEnvironment().StateStore.LoadValidators(blockMeta.Header.Height)
if err != nil {
return err
}
protoValidatorSet, err := validatorSet.ToProto()
if err != nil {
return err
}

for i := 0; i < int(blockMeta.BlockID.PartSetHeader.Total); i++ {
part, err := blockStore.LoadBlockPart(req.Height, i).ToProto()
if err != nil {
Expand All @@ -234,10 +246,16 @@ func (blockAPI *BlockAPI) BlockByHeight(req *BlockByHeightRequest, stream BlockA
part.Proof = crypto.Proof{}
}
isLastPart := i == int(blockMeta.BlockID.PartSetHeader.Total)-1
err = stream.Send(&BlockByHeightResponse{
resp := BlockByHeightResponse{
BlockPart: part,
IsLast: isLastPart,
})
}
if i == 0 {
resp.BlockMeta = blockMeta.ToProto()
resp.ValidatorSet = protoValidatorSet
resp.Commit = commit
}
err = stream.Send(&resp)
if err != nil {
return err
}
Expand Down

0 comments on commit 7754fd7

Please sign in to comment.