[explorer] Instruct explorer.InSync RPC uses NodeAPI as backend.

pull/3654/head
Jacky Wang 4 years ago
parent ee1644ce06
commit 1ea2725457
No known key found for this signature in database
GPG Key ID: 1085CE5F4FF5842C
  1. 15
      api/service/explorer/service.go
  2. 2
      node/service_setup.go

@ -14,8 +14,8 @@ import (
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/gorilla/mux" "github.com/gorilla/mux"
msg_pb "github.com/harmony-one/harmony/api/proto/message" msg_pb "github.com/harmony-one/harmony/api/proto/message"
"github.com/harmony-one/harmony/api/service/legacysync"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/hmy"
"github.com/harmony-one/harmony/internal/chain" "github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/internal/common" "github.com/harmony-one/harmony/internal/common"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
@ -45,13 +45,18 @@ type Service struct {
Storage *Storage Storage *Storage
server *http.Server server *http.Server
messageChan chan *msg_pb.Message messageChan chan *msg_pb.Message
stateSync *legacysync.StateSync
blockchain *core.BlockChain blockchain *core.BlockChain
backend hmy.NodeAPI
} }
// New returns explorer service. // New returns explorer service.
func New(selfPeer *p2p.Peer, ss *legacysync.StateSync, bc *core.BlockChain) *Service { func New(selfPeer *p2p.Peer, bc *core.BlockChain, backend hmy.NodeAPI) *Service {
return &Service{IP: selfPeer.IP, Port: selfPeer.Port, stateSync: ss, blockchain: bc} return &Service{
IP: selfPeer.IP,
Port: selfPeer.Port,
blockchain: bc,
backend: backend,
}
} }
// Start starts explorer service. // Start starts explorer service.
@ -267,7 +272,7 @@ func (s *Service) GetTotalSupply(w http.ResponseWriter, r *http.Request) {
// GetNodeSync returns status code 500 if node is not in sync // GetNodeSync returns status code 500 if node is not in sync
func (s *Service) GetNodeSync(w http.ResponseWriter, r *http.Request) { func (s *Service) GetNodeSync(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
sync, _ := s.stateSync.SyncStatus(s.blockchain) sync, _ := s.backend.SyncStatus(s.blockchain.ShardID())
if !sync { if !sync {
w.WriteHeader(http.StatusTeapot) w.WriteHeader(http.StatusTeapot)
} }

@ -27,7 +27,7 @@ func (node *Node) RegisterValidatorServices() {
func (node *Node) RegisterExplorerServices() { func (node *Node) RegisterExplorerServices() {
// Register explorer service. // Register explorer service.
node.serviceManager.Register( node.serviceManager.Register(
service.SupportExplorer, explorer.New(&node.SelfPeer, node.stateSync, node.Blockchain()), service.SupportExplorer, explorer.New(&node.SelfPeer, node.Blockchain(), node),
) )
} }

Loading…
Cancel
Save