Browse Source

Merge pull request #171 from tendermint/init

Init
pull/176/head
Jae Kwon 9 years ago
parent
commit
a204f59ecb
6 changed files with 58 additions and 27 deletions
  1. +23
    -0
      cmd/tendermint/init.go
  2. +2
    -0
      cmd/tendermint/main.go
  3. +2
    -2
      config/tendermint/config.go
  4. +0
    -25
      rpc/core/net.go
  5. +30
    -0
      rpc/core/status.go
  6. +1
    -0
      rpc/core/types/responses.go

+ 23
- 0
cmd/tendermint/init.go View File

@ -0,0 +1,23 @@
package main
import (
"github.com/tendermint/tendermint/types"
)
func init_files() {
privValidator := types.GenPrivValidator()
privValidator.SetFile(config.GetString("priv_validator_file"))
privValidator.Save()
//TODO: chainID
genDoc := types.GenesisDoc{
ChainID: "hi",
}
genDoc.Validators = []types.GenesisValidator{types.GenesisValidator{
PubKey: privValidator.PubKey,
Amount: 10000,
}}
genDoc.SaveAs(config.GetString("genesis_file"))
}

+ 2
- 0
cmd/tendermint/main.go View File

@ -34,6 +34,8 @@ Commands:
switch args[0] { switch args[0] {
case "node": case "node":
node.RunNode() node.RunNode()
case "init":
init_files()
case "show_validator": case "show_validator":
show_validator() show_validator()
case "gen_validator": case "gen_validator":


+ 2
- 2
config/tendermint/config.go View File

@ -56,7 +56,7 @@ func GetConfig(rootDir string) cfg.Config {
mapConfig.SetDefault("moniker", "anonymous") mapConfig.SetDefault("moniker", "anonymous")
mapConfig.SetDefault("node_laddr", "0.0.0.0:46656") mapConfig.SetDefault("node_laddr", "0.0.0.0:46656")
// mapConfig.SetDefault("seeds", "goldenalchemist.chaintest.net:46656") // mapConfig.SetDefault("seeds", "goldenalchemist.chaintest.net:46656")
mapConfig.SetDefault("fast_sync", true)
mapConfig.SetDefault("fast_sync", false)
mapConfig.SetDefault("skip_upnp", false) mapConfig.SetDefault("skip_upnp", false)
mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json") mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json")
mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json") mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json")
@ -77,7 +77,7 @@ proxy_app = "tcp://127.0.0.1:46658"
moniker = "__MONIKER__" moniker = "__MONIKER__"
node_laddr = "0.0.0.0:46656" node_laddr = "0.0.0.0:46656"
seeds = "" seeds = ""
fast_sync = true
fast_sync = false
db_backend = "leveldb" db_backend = "leveldb"
log_level = "notice" log_level = "notice"
rpc_laddr = "0.0.0.0:46657" rpc_laddr = "0.0.0.0:46657"


+ 0
- 25
rpc/core/net.go View File

@ -2,35 +2,10 @@ package core
import ( import (
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
) )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// TODO Move to status.go or node.go
func Status() (*ctypes.ResultStatus, error) {
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(),
PubKey: privValidator.PubKey,
LatestBlockHash: latestBlockHash,
LatestBlockHeight: latestHeight,
LatestBlockTime: latestBlockTime}, nil
}
//-----------------------------------------------------------------------------
func NetInfo() (*ctypes.ResultNetInfo, error) { func NetInfo() (*ctypes.ResultNetInfo, error) {
listening := p2pSwitch.IsListening() listening := p2pSwitch.IsListening()
listeners := []string{} listeners := []string{}


+ 30
- 0
rpc/core/status.go View File

@ -0,0 +1,30 @@
package core
import (
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
)
func Status() (*ctypes.ResultStatus, error) {
latestHeight := blockStore.Height()
var (
latestBlockMeta *types.BlockMeta
latestBlockHash []byte
latestAppHash []byte
latestBlockTime int64
)
if latestHeight != 0 {
latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
latestBlockHash = latestBlockMeta.Hash
latestAppHash = latestBlockMeta.Header.AppHash
latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
}
return &ctypes.ResultStatus{
NodeInfo: p2pSwitch.NodeInfo(),
PubKey: privValidator.PubKey,
LatestBlockHash: latestBlockHash,
LatestAppHash: latestAppHash,
LatestBlockHeight: latestHeight,
LatestBlockTime: latestBlockTime}, nil
}

+ 1
- 0
rpc/core/types/responses.go View File

@ -21,6 +21,7 @@ type ResultStatus struct {
NodeInfo *p2p.NodeInfo `json:"node_info"` NodeInfo *p2p.NodeInfo `json:"node_info"`
PubKey crypto.PubKey `json:"pub_key"` PubKey crypto.PubKey `json:"pub_key"`
LatestBlockHash []byte `json:"latest_block_hash"` LatestBlockHash []byte `json:"latest_block_hash"`
LatestAppHash []byte `json:"latest_app_hash"`
LatestBlockHeight int `json:"latest_block_height"` LatestBlockHeight int `json:"latest_block_height"`
LatestBlockTime int64 `json:"latest_block_time"` // nano LatestBlockTime int64 `json:"latest_block_time"` // nano
} }


Loading…
Cancel
Save