diff --git a/container/ethereum.go b/container/ethereum.go index 03479a6f..8eba7575 100644 --- a/container/ethereum.go +++ b/container/ethereum.go @@ -32,7 +32,7 @@ import ( "github.com/docker/go-connections/nat" "github.com/getamis/go-ethereum/cmd/utils" "github.com/getamis/go-ethereum/ethclient" - "github.com/getamis/istanbul-tools/core" + "github.com/getamis/istanbul-tools/core/genesis" ) const ( @@ -101,12 +101,12 @@ func (eth *ethereum) Init(genesisFile string) error { "init", "--" + utils.DataDirFlag.Name, eth.dataDir, - filepath.Join("/", core.GenesisJson), + filepath.Join("/", genesis.FileName), }, }, &container.HostConfig{ Binds: []string{ - genesisFile + ":" + filepath.Join("/", core.GenesisJson), + genesisFile + ":" + filepath.Join("/", genesis.FileName), eth.hostDataDir + ":" + eth.dataDir, }, }, nil, "") diff --git a/container/ethereum_test.go b/container/ethereum_test.go index 045ce519..103a6a11 100644 --- a/container/ethereum_test.go +++ b/container/ethereum_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/getamis/istanbul-tools/core" + "github.com/getamis/istanbul-tools/core/genesis" ) func TestEthereumContainer(t *testing.T) { @@ -46,7 +47,7 @@ func TestEthereumContainer(t *testing.T) { Logging(true), ) - err := geth.Init(filepath.Join(env.DataDir, core.GenesisJson)) + err := geth.Init(filepath.Join(env.DataDir, genesis.FileName)) if err != nil { t.Error(err) } diff --git a/core/cluster.go b/core/cluster.go index 8b95aebe..7d5eb7b1 100644 --- a/core/cluster.go +++ b/core/cluster.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/p2p/discover" + "github.com/getamis/istanbul-tools/core/genesis" "github.com/satori/go.uuid" ) @@ -43,7 +44,6 @@ const ( clientIdentifier = "geth" staticNodeJson = "static-nodes.json" - GenesisJson = "genesis.json" ) type Env struct { @@ -106,9 +106,9 @@ func SetupNodes(envs []*Env) error { } addrs := toAddress(envs) - genesis := GenerateGenesis(addrs) + g := genesis.New(addrs) for _, env := range envs { - if err := saveGenesis(env.DataDir, genesis); err != nil { + if err := genesis.Save(env.DataDir, g); err != nil { return err } } diff --git a/core/genesis.go b/core/genesis/genesis.go similarity index 87% rename from core/genesis.go rename to core/genesis/genesis.go index 4c932d10..d3cb63e1 100644 --- a/core/genesis.go +++ b/core/genesis/genesis.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -package core +package genesis import ( "encoding/json" @@ -23,6 +23,7 @@ import ( "math/big" "path/filepath" "time" + "log" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -33,10 +34,14 @@ import ( "github.com/getamis/istanbul-tools/cmd/istanbul/extradata" ) -func GenerateGenesis(addrs []common.Address) *core.Genesis { +const ( + FileName = "genesis.json" +) + +func New(addrs []common.Address) *core.Genesis { extraData, err := extradata.Encode("0x00", addrs) if err != nil { - panic(fmt.Sprintf("%s%s", "Failed to generate genesis", err)) + log.Fatalf("Failed to generate genesis, err:%s", err) } return &core.Genesis{ @@ -59,8 +64,8 @@ func GenerateGenesis(addrs []common.Address) *core.Genesis { } } -func saveGenesis(dataDir string, genesis *core.Genesis) error { - filePath := filepath.Join(dataDir, GenesisJson) +func Save(dataDir string, genesis *core.Genesis) error { + filePath := filepath.Join(dataDir, FileName) raw, err := json.Marshal(genesis) if err != nil {