github.com/mavryk-network/mvgo@v1.19.9/cmd/tzgenesis/main.go (about)

     1  package main
     2  
     3  import (
     4  	"crypto/rand"
     5  	"encoding/json"
     6  	"flag"
     7  	"fmt"
     8  	"os"
     9  	"time"
    10  
    11  	"github.com/mavryk-network/mvgo/mavryk"
    12  )
    13  
    14  var (
    15  	proto = mavryk.MustParseProtocolHash("ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im")
    16  	key   = mavryk.MustParseKey("edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2")
    17  	block mavryk.BlockHash
    18  	name  = "TEZOS"
    19  	tm    string
    20  )
    21  
    22  func init() {
    23  	rand.Read(block[:])
    24  }
    25  
    26  func main() {
    27  	if err := run(); err != nil {
    28  		fmt.Println("Error:", err)
    29  	}
    30  }
    31  func run() error {
    32  	flag.Var(&proto, "proto", "Genesis protocol hash")
    33  	flag.Var(&key, "key", "Genesis pubkey")
    34  	flag.Var(&block, "block", "Genesis block")
    35  	flag.StringVar(&name, "name", "TEZOS", "Chain name")
    36  	flag.StringVar(&tm, "time", time.Now().UTC().Format(time.RFC3339), "Genesis timestamp")
    37  	flag.Parse()
    38  
    39  	ts, err := time.Parse(time.RFC3339, tm)
    40  	if err != nil {
    41  		return fmt.Errorf("Parsing timestamp %q: %v", tm, err)
    42  	}
    43  
    44  	genesis := Genesis{
    45  		Genesis: GenesisInfo{
    46  			Timestamp: ts.Format(time.RFC3339),
    47  			Block:     block,
    48  			Protocol:  proto,
    49  		},
    50  		Params: GenesisParams{
    51  			Values: GenesisValues{
    52  				Key: key,
    53  			},
    54  		},
    55  		ChainName:        name,
    56  		SandboxChainName: "SANDBOXED_" + name,
    57  	}
    58  	enc := json.NewEncoder(os.Stdout)
    59  	enc.SetIndent("", "  ")
    60  	return enc.Encode(genesis)
    61  }
    62  
    63  type Genesis struct {
    64  	Genesis          GenesisInfo   `json:"genesis"`
    65  	Params           GenesisParams `json:"genesis_parameters"`
    66  	ChainName        string        `json:"chain_name"`
    67  	SandboxChainName string        `json:"sandboxed_chain_name"`
    68  }
    69  
    70  type GenesisInfo struct {
    71  	Timestamp string              `json:"timestamp"`
    72  	Block     mavryk.BlockHash    `json:"block"`
    73  	Protocol  mavryk.ProtocolHash `json:"protocol"`
    74  }
    75  
    76  type GenesisParams struct {
    77  	Values GenesisValues `json:"values"`
    78  }
    79  
    80  type GenesisValues struct {
    81  	Key mavryk.Key `json:"genesis_pubkey"`
    82  }