github.com/elastos/Elastos.ELA.SideChain.ETH@v0.2.2/consensus/pbft/api.go (about) 1 // Copyright (c) 2017-2019 The Elastos Foundation 2 // Use of this source code is governed by an MIT 3 // license that can be found in the LICENSE file. 4 // 5 6 package pbft 7 8 import ( 9 "github.com/elastos/Elastos.ELA.SideChain.ESC/common" 10 "github.com/elastos/Elastos.ELA.SideChain.ESC/consensus" 11 "github.com/elastos/Elastos.ELA.SideChain.ESC/dpos" 12 ) 13 14 // API is a user facing RPC API to allow controlling the signer and voting 15 // mechanisms of the delegate-proof-of-stake scheme. 16 type API struct { 17 chain consensus.ChainReader 18 pbft *Pbft 19 } 20 21 func (a *API) AnnounceDAddr() uint64 { 22 if a.pbft.AnnounceDAddr() { 23 return 1 24 } 25 return 0 26 } 27 28 func (a *API) GetAtbiterPeersInfo() []peerInfo { 29 return a.pbft.GetAtbiterPeersInfo() 30 } 31 32 func (a *API) GetAllPeersInfo() []peerInfo { 33 peers := a.pbft.GetAllArbiterPeersInfo() 34 result := make([]peerInfo, 0) 35 for _, peer := range peers { 36 pid := peer.PID[:] 37 result = append(result, peerInfo{ 38 NodePublicKey: common.Bytes2Hex(pid), 39 IP: peer.Addr, 40 ConnState: peer.State.String(), 41 }) 42 } 43 return result 44 } 45 46 47 func (a *API) Dispatcher() *dpos.Dispatcher { 48 return a.pbft.dispatcher 49 } 50 51 //func (a *API) Account() daccount.Account { 52 // return a.pbft.account 53 //} 54 55 func (a *API) Network() *dpos.Network { 56 return a.pbft.network 57 }