diff --git a/api/client.go b/api/client.go index bb870fd2..09de6a25 100644 --- a/api/client.go +++ b/api/client.go @@ -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 } diff --git a/api/server.go b/api/server.go index 8681840f..305aee76 100644 --- a/api/server.go +++ b/api/server.go @@ -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 { @@ -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,