core: move genesis.go into core/genesis package

This commit is contained in:
Edwin 2017-08-14 14:05:36 +08:00
parent 19b2eb266d
commit 149d8b4700
4 changed files with 18 additions and 12 deletions

View File

@ -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, "")

View File

@ -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)
}

View File

@ -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
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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 {