github.com/aergoio/aergo@v1.3.1/tools/genesisdump/main.go (about) 1 package main 2 3 import ( 4 "encoding/hex" 5 "encoding/json" 6 "fmt" 7 "os" 8 9 "github.com/aergoio/aergo/types" 10 ) 11 12 func getGenesis(path string) *types.Genesis { 13 file, err := os.Open(path) 14 if err != nil { 15 fmt.Printf("fail to open %s \n", path) 16 return nil 17 } 18 defer file.Close() 19 genesis := new(types.Genesis) 20 if err := json.NewDecoder(file).Decode(genesis); err != nil { 21 fmt.Printf("fail to deserialize %s (error:%s)\n", path, err) 22 return nil 23 } 24 return genesis 25 } 26 27 func main() { 28 29 argsWithoutProg := os.Args[1:] 30 if 0 == len(argsWithoutProg) { 31 panic("Usage: dumpblk <genesis file path>") 32 } 33 34 g := getGenesis(argsWithoutProg[0]) 35 if g == nil || g.Validate() != nil { 36 panic("fail to read or validate") 37 } 38 39 bs, err := json.Marshal(g) 40 if err != nil { 41 panic(err) 42 } 43 44 str := "\"" + hex.EncodeToString(bs) + "\"" 45 fmt.Println(str) 46 }