2015-03-26 21:30:42 -07:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2015-03-30 22:50:27 -07:00
|
|
|
"github.com/tendermint/tendermint2/config"
|
|
|
|
dbm "github.com/tendermint/tendermint2/db"
|
|
|
|
sm "github.com/tendermint/tendermint2/state"
|
|
|
|
"github.com/tendermint/tendermint2/types"
|
2015-03-26 21:30:42 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-03-28 23:10:05 -07:00
|
|
|
func Status() (*ResponseStatus, error) {
|
2015-03-26 21:30:42 -07:00
|
|
|
db := dbm.NewMemDB()
|
|
|
|
genesisState := sm.MakeGenesisStateFromFile(db, config.App().GetString("GenesisFile"))
|
|
|
|
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-03-28 23:10:05 -07:00
|
|
|
return &ResponseStatus{genesisHash, config.App().GetString("Network"), latestBlockHash, latestHeight, latestBlockTime}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-03-28 23:10:05 -07:00
|
|
|
func NetInfo() (*ResponseNetInfo, error) {
|
2015-03-26 21:30:42 -07:00
|
|
|
o, i, _ := p2pSwitch.NumPeers()
|
|
|
|
numPeers := o + i
|
|
|
|
listening := p2pSwitch.IsListening()
|
|
|
|
network := config.App().GetString("Network")
|
2015-03-28 23:10:05 -07:00
|
|
|
return &ResponseNetInfo{numPeers, listening, network}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|