2015-03-26 21:30:42 -07:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2015-05-29 11:13:45 -07:00
|
|
|
"io/ioutil"
|
|
|
|
|
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-04-07 11:44:25 -07:00
|
|
|
func Status() (*ctypes.ResponseStatus, error) {
|
2015-03-26 21:30:42 -07:00
|
|
|
db := dbm.NewMemDB()
|
2015-05-15 18:05:09 -07:00
|
|
|
genesisState := sm.MakeGenesisStateFromFile(db, config.GetString("genesis_file"))
|
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-05-15 18:05:09 -07:00
|
|
|
Moniker: config.GetString("moniker"),
|
2015-05-29 11:13:45 -07:00
|
|
|
ChainID: config.GetString("chain_id"),
|
2015-05-15 18:05:09 -07:00
|
|
|
Version: config.GetString("version"),
|
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 11:13:45 -07:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// returns pointer because the rpc-gen code returns nil (TODO!)
|
|
|
|
func Genesis() (*string, error) {
|
|
|
|
b, err := ioutil.ReadFile(config.GetString("genesis_file"))
|
|
|
|
if err != nil {
|
2015-05-29 14:53:57 -07:00
|
|
|
return nil, err
|
2015-05-29 11:13:45 -07:00
|
|
|
}
|
2015-05-29 14:53:57 -07:00
|
|
|
ret := string(b)
|
|
|
|
return &ret, nil
|
2015-05-29 11:13:45 -07:00
|
|
|
}
|