rpc: separate out golang API into rpc/core

This commit is contained in:
Ethan Buchman
2015-03-26 21:30:42 -07:00
parent d2724c9731
commit 1fb1163721
8 changed files with 264 additions and 0 deletions

39
rpc/core/net.go Normal file
View File

@ -0,0 +1,39 @@
package core
import (
"github.com/tendermint/tendermint/config"
dbm "github.com/tendermint/tendermint/db"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
)
//-----------------------------------------------------------------------------
func Status() ([]byte, string, []byte, uint, int64) {
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()
}
return genesisHash, config.App().GetString("Network"), latestBlockHash, latestHeight, latestBlockTime
}
//-----------------------------------------------------------------------------
func NetInfo() (int, bool, string) {
o, i, _ := p2pSwitch.NumPeers()
numPeers := o + i
listening := p2pSwitch.IsListening()
network := config.App().GetString("Network")
return numPeers, listening, network
}