Skip to content

Commit

Permalink
Merge pull request #85 from SiaFoundation/add-explorer-tip
Browse files Browse the repository at this point in the history
Add explorer tip endpoint
  • Loading branch information
n8maninger authored Sep 4, 2024
2 parents d7d947b + 29539cc commit 1a6471e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ func (c *Client) SyncerBroadcastBlock(b types.Block) (err error) {
return
}

// ConsensusTip returns the current tip of the chain manager.
func (c *Client) ConsensusTip() (resp types.ChainIndex, err error) {
err = c.c.GET("/consensus/tip", &resp)
return
}

// Tip returns the current tip of the explorer.
func (c *Client) Tip() (resp types.ChainIndex, err error) {
err = c.c.GET("/consensus/tip", &resp)
err = c.c.GET("/explorer/tip", &resp)
return
}

Expand Down
10 changes: 10 additions & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ func (s *server) consensusStateHandler(jc jape.Context) {
jc.Encode(s.cm.TipState())
}

func (s *server) explorerTipHandler(jc jape.Context) {
tip, err := s.e.Tip()
if jc.Check("failed to get tip", err) != nil {
return
}
jc.Encode(tip)
}

func (s *server) blocksMetricsHandler(jc jape.Context) {
tip, err := s.e.Tip()
if jc.Check("failed to get tip", err) != nil {
Expand Down Expand Up @@ -467,6 +475,8 @@ func NewServer(e Explorer, cm ChainManager, s Syncer) http.Handler {
"GET /consensus/tip": srv.consensusTipHandler,
"GET /consensus/tip/:height": srv.consensusTipHeightHandler,

"GET /explorer/tip": srv.explorerTipHandler,

"GET /blocks/:id": srv.blocksIDHandler,

"GET /transactions/:id": srv.transactionsIDHandler,
Expand Down

0 comments on commit 1a6471e

Please sign in to comment.