1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package main
import (
"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() {
genesis := core.DefaultGenesisBlock()
// 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)
}
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(2e6)),
Staked: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e6)),
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())
}
data, err := json.MarshalIndent(genesis, "", " ")
if err != nil {
panic(err)
}
if err := ioutil.WriteFile(genesisFile, data, 0644); err != nil {
panic(err)
}
fmt.Println("Done.")
}
|