Skip to content
Snippets Groups Projects
Unverified Commit a5eefbf6 authored by Benjamin Bollen's avatar Benjamin Bollen
Browse files

move /rpc/tendermint/NetInfo

parent 63d4e754
No related branches found
No related tags found
No related merge requests found
......@@ -33,9 +33,10 @@ import (
log "github.com/eris-ltd/eris-logger"
config "github.com/eris-ltd/eris-db/config"
definitions "github.com/eris-ltd/eris-db/definitions"
manager_types "github.com/eris-ltd/eris-db/manager/types"
config "github.com/eris-ltd/eris-db/config"
definitions "github.com/eris-ltd/eris-db/definitions"
manager_types "github.com/eris-ltd/eris-db/manager/types"
rpc_tendermint_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types"
// files "github.com/eris-ltd/eris-db/files"
)
......@@ -147,6 +148,28 @@ func (this *TendermintNode) LoadBlockMeta(height int) *tendermint_types.BlockMet
return this.tmintNode.BlockStore().LoadBlockMeta(height)
}
func (this *TendermintNode) IsListening() bool {
return this.tmintNode.Switch().IsListening()
}
func (this *TendermintNode) Listeners() []p2p.Listener {
var copyListeners []p2p.Listener
// copy slice of Listeners
copy(copyListeners[:], this.tmintNode.Switch().Listeners())
return copyListeners
}
func (this *TendermintNode) Peers() []rpc_tendermint_types.Peer {
peers := []rpc_tendermint_types.Peer{}
for _, peer := range this.tmintNode.Switch().Peers().List() {
peers = append(peers, rpc_tendermint_types.Peer {
NodeInfo: *peer.NodeInfo,
IsOutbound: peer.IsOutbound(),
})
}
return peers
}
func (this *TendermintNode) NodeInfo() *p2p.NodeInfo {
var copyNodeInfo = new(p2p.NodeInfo)
// call Switch().NodeInfo is not go-routine safe, so copy
......
......@@ -63,14 +63,14 @@ func NewCore(chainId string, consensusConfig *config.ModuleConfig,
if err != nil {
log.Warn(fmt.Sprintf("Tendermint gateway not supported by %s",
managerConfig.Version))
return &Core{
return &Core {
chainId: chainId,
evsw: evsw,
pipe: pipe,
tendermintPipe: nil,
}, nil
}
return &Core{
return &Core {
chainId: chainId,
evsw: evsw,
pipe: pipe,
......
......@@ -20,6 +20,8 @@ import (
crypto "github.com/tendermint/go-crypto"
p2p "github.com/tendermint/go-p2p"
tendermint_types "github.com/tendermint/tendermint/types"
rpc_tendermint_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types"
)
// TODO: [ben] explore the value of abstracting the consensus into an interface
......@@ -32,10 +34,14 @@ type ConsensusEngine interface {
LoadBlockMeta(height int) *tendermint_types.BlockMeta
// Peer-2-Peer
IsListening() bool
Listeners() []p2p.Listener
NodeInfo() *p2p.NodeInfo
Peers() []rpc_tendermint_types.Peer
// Private Validator
PublicValidatorKey() crypto.PubKey
}
// type Communicator interface {
......
......@@ -246,7 +246,17 @@ func (pipe *ErisMintPipe) Status() (*rpc_tendermint_types.ResultStatus, error) {
}
func (pipe *ErisMintPipe) NetInfo() (*rpc_tendermint_types.ResultNetInfo, error) {
return nil, fmt.Errorf("Unimplemented.")
listening := pipe.consensusEngine.IsListening()
listeners := []string{}
for _, listener := range pipe.consensusEngine.Listeners() {
listeners = append(listeners, listener.String())
}
peers := pipe.consensusEngine.Peers()
return &rpc_tendermint_types.ResultNetInfo{
Listening: listening,
Listeners: listeners,
Peers: peers,
}, nil
}
func (pipe *ErisMintPipe) Genesis() (*rpc_tendermint_types.ResultGenesis, error) {
......
......@@ -3,64 +3,64 @@ package core
import (
ctypes "github.com/eris-ltd/eris-db/rpc/tendermint/core/types"
sm "github.com/eris-ltd/eris-db/manager/eris-mint/state"
"github.com/tendermint/tendermint/types"
// "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/go-db"
// dbm "github.com/tendermint/go-db"
)
// TODO:[ben] remove commented code
//-----------------------------------------------------------------------------
// cache the genesis state
var genesisState *sm.State
func Status() (*ctypes.ResultStatus, error) {
db := dbm.NewMemDB()
if genesisState == nil {
genesisState = sm.MakeGenesisState(db, genDoc)
}
genesisHash := genesisState.Hash()
latestHeight := blockStore.Height()
var (
latestBlockMeta *types.BlockMeta
latestBlockHash []byte
latestBlockTime int64
)
if latestHeight != 0 {
latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
latestBlockHash = latestBlockMeta.Hash
latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
}
return &ctypes.ResultStatus{
NodeInfo: p2pSwitch.NodeInfo(),
GenesisHash: genesisHash,
PubKey: privValidator.PubKey,
LatestBlockHash: latestBlockHash,
LatestBlockHeight: latestHeight,
LatestBlockTime: latestBlockTime}, nil
}
// func Status() (*ctypes.ResultStatus, error) {
// db := dbm.NewMemDB()
// if genesisState == nil {
// genesisState = sm.MakeGenesisState(db, genDoc)
// }
// genesisHash := genesisState.Hash()
// latestHeight := blockStore.Height()
// var (
// latestBlockMeta *types.BlockMeta
// latestBlockHash []byte
// latestBlockTime int64
// )
// if latestHeight != 0 {
// latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
// latestBlockHash = latestBlockMeta.Hash
// latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
// }
//
// return &ctypes.ResultStatus{
// NodeInfo: p2pSwitch.NodeInfo(),
// GenesisHash: genesisHash,
// PubKey: privValidator.PubKey,
// LatestBlockHash: latestBlockHash,
// LatestBlockHeight: latestHeight,
// LatestBlockTime: latestBlockTime}, nil
// }
//-----------------------------------------------------------------------------
func NetInfo() (*ctypes.ResultNetInfo, error) {
listening := p2pSwitch.IsListening()
listeners := []string{}
for _, listener := range p2pSwitch.Listeners() {
listeners = append(listeners, listener.String())
}
peers := []ctypes.Peer{}
for _, peer := range p2pSwitch.Peers().List() {
peers = append(peers, ctypes.Peer{
NodeInfo: *peer.NodeInfo,
IsOutbound: peer.IsOutbound(),
})
}
return &ctypes.ResultNetInfo{
Listening: listening,
Listeners: listeners,
Peers: peers,
}, nil
}
// func NetInfo() (*ctypes.ResultNetInfo, error) {
// listening := p2pSwitch.IsListening()
// listeners := []string{}
// for _, listener := range p2pSwitch.Listeners() {
// listeners = append(listeners, listener.String())
// }
// peers := []ctypes.Peer{}
// for _, peer := range p2pSwitch.Peers().List() {
// peers = append(peers, ctypes.Peer{
// NodeInfo: *peer.NodeInfo,
// IsOutbound: peer.IsOutbound(),
// })
// }
// return &ctypes.ResultNetInfo{
// Listening: listening,
// Listeners: listeners,
// Peers: peers,
// }, nil
// }
//-----------------------------------------------------------------------------
......
......@@ -28,7 +28,7 @@ func SetConfig(c server.ServerConfig) {
config = c
}
func SetErisMint(em *erismint.ErisMint) {
func SetApplication(em *erismint.ErisMint) {
erisMint = em
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment