diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-11-29 09:20:57 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:19 +0800 |
commit | 3bc8c1628257b2fab50f260e048118fc56b1ab02 (patch) | |
tree | 4dacbb2704ab4fd10676b87964ae03940d704db8 /test/keygen.go | |
parent | 4324cf089ad686b79d05444f03ed2468ab1ed644 (diff) | |
download | go-tangerine-3bc8c1628257b2fab50f260e048118fc56b1ab02.tar go-tangerine-3bc8c1628257b2fab50f260e048118fc56b1ab02.tar.gz go-tangerine-3bc8c1628257b2fab50f260e048118fc56b1ab02.tar.bz2 go-tangerine-3bc8c1628257b2fab50f260e048118fc56b1ab02.tar.lz go-tangerine-3bc8c1628257b2fab50f260e048118fc56b1ab02.tar.xz go-tangerine-3bc8c1628257b2fab50f260e048118fc56b1ab02.tar.zst go-tangerine-3bc8c1628257b2fab50f260e048118fc56b1ab02.zip |
test: improve keygen.go (#62)
Diffstat (limited to 'test/keygen.go')
-rw-r--r-- | test/keygen.go | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/test/keygen.go b/test/keygen.go index 5397bc269..b98d70751 100644 --- a/test/keygen.go +++ b/test/keygen.go @@ -1,34 +1,83 @@ package main import ( - "encoding/hex" + "encoding/json" "fmt" + "io/ioutil" + "math/big" "os" "strconv" + "github.com/dexon-foundation/dexon/common" + "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/crypto" ) +const genesisFile = "genesis.json" + +var preFundAmount *big.Int = new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e8)) + +var preFundAddresss = []string{ + "0x2a9D669e4791845EED01D4c0ffF3B927cC94A884", + "0x1245A8672FA881Cf858eF01D34c42B55D9b263fF", + "0xe0F859340353854693F537ea337106a33E9FeAB0", +} + func main() { + data, err := ioutil.ReadFile(genesisFile) + if err != nil { + panic(err) + } + + genesis := new(core.Genesis) + if err := json.Unmarshal(data, &genesis); err != nil { + panic(err) + } + + // Clear previous allocation. + genesis.Alloc = make(map[common.Address]core.GenesisAccount) + count, err := strconv.Atoi(os.Args[1]) if err != nil { panic(err) } + for _, addr := range preFundAddresss { + address := common.HexToAddress(addr) + genesis.Alloc[address] = core.GenesisAccount{ + Balance: preFundAmount, + Staked: big.NewInt(0), + } + fmt.Printf("Created account %s\n", address.String()) + } for i := 0; i < count; i++ { privKey, err := crypto.GenerateKey() if err != nil { panic(err) } - address := crypto.PubkeyToAddress(privKey.PublicKey).String() - pk := hex.EncodeToString(crypto.FromECDSAPub(&privKey.PublicKey)) + crypto.SaveECDSA(fmt.Sprintf("keystore/test%d.key", i), privKey) + + address := crypto.PubkeyToAddress(privKey.PublicKey) + genesis.Alloc[address] = core.GenesisAccount{ + Balance: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e6)), + Staked: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(5e5)), + PublicKey: crypto.FromECDSAPub(&privKey.PublicKey), + NodeInfo: core.NodeInfo{ + Name: fmt.Sprintf("DEXON Test Node %d", i), + Email: fmt.Sprintf("dexon%d@dexon.org", i), + Location: "Taipei, Taiwan", + Url: "https://dexon.org", + }, + } + fmt.Printf("Created account %s\n", address.String()) + } - fmt.Printf(` - "%s": { - "balance": "1000000000000000000000", - "staked": "500000000000000000000", - "publicKey": "0x%s" - },`, address, pk) + data, err = json.MarshalIndent(genesis, "", " ") + if err != nil { + panic(err) + } - crypto.SaveECDSA(fmt.Sprintf("test%d.nodekey", i), privKey) + if err := ioutil.WriteFile(genesisFile, data, 0644); err != nil { + panic(err) } + fmt.Println("Done.") } |