Skip to content

Commit

Permalink
api: /chain/blockToDate now fallbacks to fetching timestamp from indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui authored and p4u committed Jun 17, 2024
1 parent 95fa13c commit 77480ae
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,14 @@ func (a *API) chainEstimateDateHandler(_ *apirest.APIdata, ctx *httprouter.HTTPC
return err
}
timestamp := a.vocinfo.HeightTime(height)
if timestamp.IsZero() {
// if block was not found in store, the indexer might have it anyway
timestamp, err = a.indexer.BlockTimestamp(int64(height))
if err != nil {
return err
}
}

data, err := json.Marshal(struct {
Date time.Time `json:"date"`
}{Date: timestamp},
Expand Down

0 comments on commit 77480ae

Please sign in to comment.