Skip to content

Commit

Permalink
Refactor BlockDigest: rename id to BlockID, remove ID() method, and u…
Browse files Browse the repository at this point in the history
…pdate tests
  • Loading branch information
UlyanaAndrukhiv committed Feb 4, 2025
1 parent b51c719 commit 4e8ab87
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion access/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ func (h *Handler) SubscribeBlockDigestsFromLatest(request *access.SubscribeBlock
func (h *Handler) handleBlockDigestsResponse(send sendSubscribeBlockDigestsResponseFunc) func(*flow.BlockDigest) error {
return func(blockDigest *flow.BlockDigest) error {
err := send(&access.SubscribeBlockDigestsResponse{
BlockId: convert.IdentifierToMessage(blockDigest.ID()),
BlockId: convert.IdentifierToMessage(blockDigest.BlockID),
BlockHeight: blockDigest.Height,
BlockTimestamp: timestamppb.New(blockDigest.Timestamp),
})
Expand Down
2 changes: 1 addition & 1 deletion engine/access/rest/websockets/models/block_digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// Build creates a BlockDigest instance with data from the provided flow.BlockDigest.
func (b *BlockDigest) Build(block *flow.BlockDigest) {
b.BlockId = block.ID().String()
b.BlockId = block.BlockID.String()
b.Height = util.FromUint(block.Height)
b.Timestamp = block.Timestamp
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *BackendBlockDigestSuite) requireBlockDigests(v interface{}, expectedBlo
actualBlock, ok := v.(*flow.BlockDigest)
require.True(s.T(), ok, "unexpected response type: %T", v)

s.Require().Equal(expectedBlock.Header.ID(), actualBlock.ID())
s.Require().Equal(expectedBlock.Header.ID(), actualBlock.BlockID)
s.Require().Equal(expectedBlock.Header.Height, actualBlock.Height)
s.Require().Equal(expectedBlock.Header.Timestamp, actualBlock.Timestamp)
}
Expand Down
11 changes: 3 additions & 8 deletions model/flow/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,20 @@ func (b *CertifiedBlock) Height() uint64 {

// BlockDigest holds lightweight block information which includes only block id, block height and block timestamp
type BlockDigest struct {
id Identifier
BlockID Identifier
Height uint64
Timestamp time.Time
}

// NewBlockDigest constructs a new block digest.
func NewBlockDigest(
id Identifier,
blockID Identifier,
height uint64,
timestamp time.Time,
) *BlockDigest {
return &BlockDigest{
id: id,
BlockID: blockID,
Height: height,
Timestamp: timestamp,
}
}

// ID returns the id of the BlockDigest.
func (b *BlockDigest) ID() Identifier {
return b.id
}

0 comments on commit 4e8ab87

Please sign in to comment.