-
Notifications
You must be signed in to change notification settings - Fork 670
/
flags.go
83 lines (67 loc) · 1.76 KB
/
flags.go
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
76
77
78
79
80
81
82
83
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package genesis
import (
"fmt"
"math"
"time"
"github.com/spf13/pflag"
"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"
xsgenesis "github.com/ava-labs/avalanchego/vms/example/xsvm/genesis"
)
const (
TimeKey = "time"
AddressKey = "address"
BalanceKey = "balance"
EncodingKey = "encoding"
binaryEncoding = "binary"
hexEncoding = "hex"
)
func AddFlags(flags *pflag.FlagSet) {
flags.Int64(TimeKey, time.Now().Unix(), "Unix timestamp to include in the genesis")
flags.String(AddressKey, genesis.EWOQKey.Address().String(), "Address to fund in the genesis")
flags.Uint64(BalanceKey, math.MaxUint64, "Amount to provide the funded address in the genesis")
flags.String(EncodingKey, hexEncoding, fmt.Sprintf("Encoding to use for the genesis. Available values: %s or %s", hexEncoding, binaryEncoding))
}
type Config struct {
Genesis *xsgenesis.Genesis
Encoding string
}
func ParseFlags(flags *pflag.FlagSet, args []string) (*Config, error) {
if err := flags.Parse(args); err != nil {
return nil, err
}
timestamp, err := flags.GetInt64(TimeKey)
if err != nil {
return nil, err
}
addrStr, err := flags.GetString(AddressKey)
if err != nil {
return nil, err
}
addr, err := ids.ShortFromString(addrStr)
if err != nil {
return nil, err
}
balance, err := flags.GetUint64(BalanceKey)
if err != nil {
return nil, err
}
encoding, err := flags.GetString(EncodingKey)
if err != nil {
return nil, err
}
return &Config{
Genesis: &xsgenesis.Genesis{
Timestamp: timestamp,
Allocations: []xsgenesis.Allocation{
{
Address: addr,
Balance: balance,
},
},
},
Encoding: encoding,
}, nil
}