X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=api%2Fnodeinfo.go;h=6557e3366494cfa28e5fb0e7d6adc5e1f7dde713;hb=cc3526dc33e7b56e49934d6daed814027968b43f;hp=c0b55c1edad5a14965b8a9ab2c2a7aeb10dcc2bb;hpb=08281341c2cb02ba11d4218576256688854790fc;p=bytom%2Fvapor.git diff --git a/api/nodeinfo.go b/api/nodeinfo.go index c0b55c1e..6557e336 100644 --- a/api/nodeinfo.go +++ b/api/nodeinfo.go @@ -4,10 +4,16 @@ import ( "context" "net" - "github.com/vapor/errors" - "github.com/vapor/netsync" - "github.com/vapor/p2p" - "github.com/vapor/version" + log "github.com/sirupsen/logrus" + + "github.com/bytom/vapor/common" + cfg "github.com/bytom/vapor/config" + "github.com/bytom/vapor/consensus" + "github.com/bytom/vapor/crypto" + "github.com/bytom/vapor/errors" + "github.com/bytom/vapor/netsync/peers" + "github.com/bytom/vapor/p2p" + "github.com/bytom/vapor/version" ) type VersionInfo struct { @@ -21,6 +27,8 @@ type NetInfo struct { Listening bool `json:"listening"` Syncing bool `json:"syncing"` Mining bool `json:"mining"` + NodeXPub string `json:"node_xpub"` + FedAddress string `json:"federation_address"` PeerCount int `json:"peer_count"` CurrentBlock uint64 `json:"current_block"` HighestBlock uint64 `json:"highest_block"` @@ -30,13 +38,24 @@ type NetInfo struct { // GetNodeInfo return net information func (a *API) GetNodeInfo() *NetInfo { + nodeXPub := cfg.CommonConfig.PrivateKey().XPub() + + signScript := cfg.FederationPMultiSigScript(cfg.CommonConfig) + scriptHash := crypto.Sha256(signScript) + address, err := common.NewAddressWitnessScriptHash(scriptHash, consensus.BytomMainNetParams(&consensus.ActiveNetParams)) + if err != nil { + log.WithFields(log.Fields{"module": logModule, "err": err}).Fatal("Failed to get federation address.") + } + info := &NetInfo{ - Listening: a.sync.Switch().IsListening(), + Listening: a.sync.IsListening(), Syncing: !a.sync.IsCaughtUp(), - Mining: a.cpuMiner.IsMining(), - PeerCount: len(a.sync.Switch().Peers().List()), + Mining: a.blockProposer.IsProposing(), + NodeXPub: nodeXPub.String(), + FedAddress: address.EncodeAddress(), + PeerCount: a.sync.PeerCount(), CurrentBlock: a.chain.BestBlockHeight(), - NetWorkID: a.sync.NodeInfo().Network, + NetWorkID: a.sync.GetNetwork(), Version: &VersionInfo{ Version: version.Version, Update: version.Status.VersionStatus(), @@ -53,7 +72,7 @@ func (a *API) GetNodeInfo() *NetInfo { } // return the currently connected peers with net address -func (a *API) getPeerInfoByAddr(addr string) *netsync.PeerInfo { +func (a *API) getPeerInfoByAddr(addr string) *peers.PeerInfo { peerInfos := a.sync.GetPeerInfos() for _, peerInfo := range peerInfos { if peerInfo.RemoteAddr == addr { @@ -69,16 +88,15 @@ func (a *API) disconnectPeerById(peerID string) error { } // connect peer b y net address -func (a *API) connectPeerByIpAndPort(ip string, port uint16) (*netsync.PeerInfo, error) { +func (a *API) connectPeerByIpAndPort(ip string, port uint16) (*peers.PeerInfo, error) { netIp := net.ParseIP(ip) if netIp == nil { return nil, errors.New("invalid ip address") } addr := p2p.NewNetAddressIPPort(netIp, port) - sw := a.sync.Switch() - if err := sw.DialPeerWithAddress(addr); err != nil { + if err := a.sync.DialPeerWithAddress(addr); err != nil { return nil, errors.Wrap(err, "can not connect to the address") } peer := a.getPeerInfoByAddr(addr.String()) @@ -99,9 +117,9 @@ func (a *API) isMining() Response { return NewSuccessResponse(IsMining) } -// IsMining return mining status +// IsProposing return mining status func (a *API) IsMining() bool { - return a.cpuMiner.IsMining() + return a.blockProposer.IsProposing() } // return the peers of current node