Skip to content

Commit

Permalink
add timestamp to raw block results
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Neznaykin committed Apr 12, 2024
1 parent 918a5f6 commit 0a2caa2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions modules/raw/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"encoding/json"
"fmt"
"time"

coretypes "github.com/cometbft/cometbft/rpc/core/types"
jsoniter "github.com/json-iterator/go"

"github.com/bro-n-bro/spacebox-crawler/types"
Expand Down Expand Up @@ -34,14 +36,22 @@ func (m *Module) HandleBlock(ctx context.Context, block *types.Block) error {
return fmt.Errorf("failed to publish raw block: %w", err)
}

return m.publishBlockResults(ctx, block.Height)
return m.publishBlockResults(ctx, block.Height, block.Timestamp)
}

func (m *Module) publishBlockResults(ctx context.Context, height int64) error {
rawBR, err := m.rpcClient.GetBlockResults(ctx, height)
func (m *Module) publishBlockResults(ctx context.Context, height int64, timestamp time.Time) error {
brResp, err := m.rpcClient.GetBlockResults(ctx, height)
if err != nil {
return fmt.Errorf("failed to get block results: %w", err)
}

rawBR := struct {
*coretypes.ResultBlockResults
Timestamp time.Time `json:"timestamp"`
}{
ResultBlockResults: brResp,
Timestamp: timestamp,
}

return m.broker.PublishRawBlockResults(ctx, rawBR)
}

0 comments on commit 0a2caa2

Please sign in to comment.