2015-03-26 21:30:42 -07:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2015-04-01 17:30:16 -07:00
|
|
|
dbm "github.com/tendermint/tendermint/db"
|
2015-04-07 11:44:25 -07:00
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2015-04-01 17:30:16 -07:00
|
|
|
sm "github.com/tendermint/tendermint/state"
|
|
|
|
"github.com/tendermint/tendermint/types"
|
2015-03-26 21:30:42 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-06-14 18:18:17 -04:00
|
|
|
// cache the genesis state
|
|
|
|
var genesisState *sm.State
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func Status() (*ctypes.ResponseStatus, error) {
|
2015-03-26 21:30:42 -07:00
|
|
|
db := dbm.NewMemDB()
|
2015-06-14 18:18:17 -04:00
|
|
|
if genesisState == nil {
|
|
|
|
genesisState = sm.MakeGenesisState(db, genDoc)
|
|
|
|
}
|
2015-03-26 21:30:42 -07:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2015-05-12 19:03:05 -07:00
|
|
|
return &ctypes.ResponseStatus{
|
2015-07-10 15:50:58 +00:00
|
|
|
NodeInfo: p2pSwitch.NodeInfo(),
|
2015-05-12 19:03:05 -07:00
|
|
|
GenesisHash: genesisHash,
|
|
|
|
PubKey: privValidator.PubKey,
|
|
|
|
LatestBlockHash: latestBlockHash,
|
|
|
|
LatestBlockHeight: latestHeight,
|
|
|
|
LatestBlockTime: latestBlockTime}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func NetInfo() (*ctypes.ResponseNetInfo, error) {
|
2015-03-26 21:30:42 -07:00
|
|
|
listening := p2pSwitch.IsListening()
|
2015-04-03 16:15:52 -07:00
|
|
|
listeners := []string{}
|
|
|
|
for _, listener := range p2pSwitch.Listeners() {
|
|
|
|
listeners = append(listeners, listener.String())
|
|
|
|
}
|
2015-04-17 18:22:44 -07:00
|
|
|
peers := []ctypes.Peer{}
|
2015-04-03 16:15:52 -07:00
|
|
|
for _, peer := range p2pSwitch.Peers().List() {
|
2015-04-17 18:22:44 -07:00
|
|
|
peers = append(peers, ctypes.Peer{
|
2015-04-20 15:29:01 -07:00
|
|
|
NodeInfo: *peer.NodeInfo,
|
2015-04-17 18:22:44 -07:00
|
|
|
IsOutbound: peer.IsOutbound(),
|
|
|
|
})
|
2015-04-03 16:15:52 -07:00
|
|
|
}
|
2015-04-07 11:44:25 -07:00
|
|
|
return &ctypes.ResponseNetInfo{
|
2015-04-03 16:15:52 -07:00
|
|
|
Listening: listening,
|
|
|
|
Listeners: listeners,
|
|
|
|
Peers: peers,
|
|
|
|
}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
2015-05-29 14:13:45 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-06-03 19:26:31 -04:00
|
|
|
func Genesis() (*sm.GenesisDoc, error) {
|
|
|
|
return genDoc, nil
|
2015-05-29 14:13:45 -04:00
|
|
|
}
|