@@ -2,7 +2,10 @@ package config
2
2
3
3
import (
4
4
"errors"
5
+ "fmt"
5
6
"regexp"
7
+
8
+ "github.com/gnolang/gno/tm2/pkg/crypto/bip39"
6
9
)
7
10
8
11
const (
@@ -12,6 +15,8 @@ const (
12
15
DefaultSendAmount = "1000000ugnot"
13
16
DefaultGasFee = "1000000ugnot"
14
17
DefaultGasWanted = "100000"
18
+ DefaultMnemonic = "source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast"
19
+ DefaultNumAccounts = uint64 (1 )
15
20
)
16
21
17
22
var (
@@ -33,6 +38,13 @@ type Config struct {
33
38
// The chain ID associated with the remote Gno chain
34
39
ChainID string `toml:"chain_id"`
35
40
41
+ // The mnemonic for the faucet
42
+ Mnemonic string `toml:"mnemonic"`
43
+
44
+ // The number of faucet accounts,
45
+ // based on the mnemonic (account 0, index x)
46
+ NumAccounts uint64 `toml:"num_accounts"`
47
+
36
48
// The static send amount (native currency).
37
49
// Format should be: <AMOUNT>ugnot
38
50
SendAmount string `toml:"send_amount"`
@@ -58,6 +70,8 @@ func DefaultConfig() *Config {
58
70
SendAmount : DefaultSendAmount ,
59
71
GasFee : DefaultGasFee ,
60
72
GasWanted : DefaultGasWanted ,
73
+ Mnemonic : DefaultMnemonic ,
74
+ NumAccounts : DefaultNumAccounts ,
61
75
CORSConfig : DefaultCORSConfig (),
62
76
}
63
77
}
@@ -94,5 +108,15 @@ func ValidateConfig(config *Config) error {
94
108
return errors .New ("invalid gas wanted" )
95
109
}
96
110
111
+ // validate the mnemonic is bip39-compliant
112
+ if ! bip39 .IsMnemonicValid (config .Mnemonic ) {
113
+ return fmt .Errorf ("invalid mnemonic, %s" , config .Mnemonic )
114
+ }
115
+
116
+ // validate at least one faucet account is set
117
+ if config .NumAccounts < 1 {
118
+ return errors .New ("invalid number of faucet accounts" )
119
+ }
120
+
97
121
return nil
98
122
}
0 commit comments