"strings"
"time"
- "github.com/bytom/p2p"
- "github.com/bytom/protocol/bc"
- "github.com/bytom/types"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire/data"
+
+ "github.com/bytom/p2p"
+ "github.com/bytom/protocol/bc"
)
type BlockNonce [8]byte
LastHeight uint64 `json:"last_height"`
}
-type ResultGenesis struct {
- Genesis *types.GenesisDoc `json:"genesis"`
-}
-
type ResultBlock struct {
}
package commands
import (
- "encoding/hex"
- "os"
-
- log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
- cmn "github.com/tendermint/tmlibs/common"
cfg "github.com/bytom/config"
- "github.com/bytom/crypto/ed25519/chainkd"
- "github.com/bytom/types"
)
var initFilesCmd = &cobra.Command{
} else {
cfg.EnsureRoot(config.RootDir, "testnet")
}
-
- genFile := config.GenesisFile()
- if _, err := os.Stat(genFile); !os.IsNotExist(err) {
- log.WithField("genesis", config.GenesisFile()).Info("Already exists config file.")
- return
- }
- xprv, err := chainkd.NewXPrv(nil)
- if err != nil {
- log.WithField("error", err).Error("Spawn node's key failed.")
- return
- }
- genDoc := types.GenesisDoc{
- ChainID: cmn.Fmt(config.ChainID),
- PrivateKey: hex.EncodeToString(xprv.Bytes()),
- }
- genDoc.SaveAs(genFile)
- log.WithField("genesis", config.GenesisFile()).Info("Initialized bytom")
}
import (
"fmt"
- "io/ioutil"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
- cmn "github.com/tendermint/tmlibs/common"
"github.com/bytom/node"
- "github.com/bytom/types"
)
var runNodeCmd = &cobra.Command{
runNodeCmd.Flags().Bool("wallet.disable", config.Wallet.Disable, "Disable wallet")
runNodeCmd.Flags().Bool("web.closed", config.Web.Closed, "Lanch web browser or not")
+ runNodeCmd.Flags().String("chain_id", config.ChainID, "Select network type")
// p2p flags
runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
}
func runNode(cmd *cobra.Command, args []string) error {
- genDocFile := config.GenesisFile()
- if cmn.FileExists(genDocFile) {
- jsonBlob, err := ioutil.ReadFile(genDocFile)
- if err != nil {
- return fmt.Errorf("Couldn't read GenesisDoc file: %v ", err)
- }
- genDoc, err := types.GenesisDocFromJSON(jsonBlob)
- if err != nil {
- return fmt.Errorf("Error reading GenesisDoc: %v ", err)
- }
- if genDoc.ChainID == "" {
- return fmt.Errorf("Genesis doc %v must include non-empty chain_id ", genDocFile)
- }
-
- config.ChainID = genDoc.ChainID
- config.PrivateKey = genDoc.PrivateKey
- config.Time = genDoc.GenesisTime
- } else {
- return fmt.Errorf("not find genesis.json")
- }
-
// Create & start node
n := node.NewNode(config)
if _, err := n.Start(); err != nil {
// This should be set in viper so it can unmarshal into this struct
RootDir string `mapstructure:"home"`
- // A JSON file containing the initial validator set and other meta data
- Genesis string `mapstructure:"genesis_file"`
-
//The ID of the network to json
ChainID string `mapstructure:"chain_id"`
// Default configurable base parameters.
func DefaultBaseConfig() BaseConfig {
return BaseConfig{
- Genesis: "genesis.json",
Moniker: "anonymous",
ProfListenAddress: "",
FastSync: true,
}
}
-func (b BaseConfig) GenesisFile() string {
- return rootify(b.Genesis, b.RootDir)
-}
-
func (b BaseConfig) DBDir() string {
return rootify(b.DBPath, b.RootDir)
}
// check the root dir stuff...
cfg.SetRoot("/foo")
- cfg.Genesis = "bar"
cfg.DBPath = "/opt/data"
- assert.Equal("/foo/bar", cfg.GenesisFile())
assert.Equal("/opt/data", cfg.DBDir())
}
fast_sync = true
db_backend = "leveldb"
api_addr = "0.0.0.0:9888"
+`
+var mainNetConfigTmpl = `chain_id = "mainnet"
[p2p]
laddr = "tcp://0.0.0.0:46656"
+seeds = ""
`
-var testnetSeeds = `
+var testNetConfigTmpl = `chain_id = "testnet"
+[p2p]
+laddr = "tcp://0.0.0.0:46656"
seeds = "139.162.105.40:46656,139.162.88.74:46656,47.96.42.1:46656,45.79.213.28:46656,212.111.41.245:46656"
`
-var mainnetSeeds = `seeds = ""`
// Select network seeds to merge a new string.
func selectNetwork(network string) string {
if network == "testnet" {
- return defaultConfigTmpl + testnetSeeds
+ return defaultConfigTmpl + testNetConfigTmpl
} else {
- return defaultConfigTmpl + mainnetSeeds
+ return defaultConfigTmpl + mainNetConfigTmpl
}
}
nodeInfo := &p2p.NodeInfo{
PubKey: sm.privKey.PubKey().Unwrap().(crypto.PubKeyEd25519),
Moniker: sm.config.Moniker,
- Network: "bytom",
+ Network: sm.config.ChainID,
Version: version.Version,
Other: []string{
cmn.Fmt("wire_version=%v", wire.Version),
+++ /dev/null
-package types
-
-import (
- "encoding/json"
- "time"
-
- cmn "github.com/tendermint/tmlibs/common"
-)
-
-//------------------------------------------------------------
-// core types for a genesis definition
-type GenesisDoc struct {
- GenesisTime time.Time `json:"genesis_time"`
- ChainID string `json:"chain_id"`
- PrivateKey string `json:"private_key"`
-}
-
-// Utility method for saving GenensisDoc as JSON file.
-func (genDoc *GenesisDoc) SaveAs(file string) error {
- genDocBytes, err := json.Marshal(genDoc)
- if err != nil {
- return err
- }
- return cmn.WriteFile(file, genDocBytes, 0644)
-}
-
-//------------------------------------------------------------
-// Make genesis state from file
-
-func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
- genDoc := GenesisDoc{}
- err := json.Unmarshal(jsonBlob, &genDoc)
- return &genDoc, err
-}