forked from irisnet/irishub-sdk-go
/
env.go
82 lines (69 loc) · 2.22 KB
/
env.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
package types
const (
Testnet Network = "testnet"
Mainnet Network = "mainnet"
)
type Network string
// Can be configured through environment variables
var (
defaultNetwork = Testnet
)
var (
//testnetEnv = &AddrPrefixCfg{
// bech32AddressPrefix: map[string]string{
// "account_addr": "faa",
// "validator_addr": "fva",
// "consensus_addr": "fca",
// "account_pub": "fap",
// "validator_pub": "fvp",
// "consensus_pub": "fcp",
// },
//}
mainnetEnv = &AddrPrefixCfg{
bech32AddressPrefix: map[string]string{
"account_addr": "iaa",
"validator_addr": "iva",
"consensus_addr": "ica",
"account_pub": "iap",
"validator_pub": "ivp",
"consensus_pub": "icp",
},
}
)
type AddrPrefixCfg struct {
bech32AddressPrefix map[string]string
}
func SetNetwork(network Network) {
defaultNetwork = network
}
// GetAddrPrefixCfg returns the config instance for the corresponding Network type
func GetAddrPrefixCfg() *AddrPrefixCfg {
if defaultNetwork == Mainnet {
return mainnetEnv
}
return mainnetEnv
}
// GetBech32AccountAddrPrefix returns the Bech32 prefix for account address
func (config *AddrPrefixCfg) GetBech32AccountAddrPrefix() string {
return config.bech32AddressPrefix["account_addr"]
}
// GetBech32ValidatorAddrPrefix returns the Bech32 prefix for validator address
func (config *AddrPrefixCfg) GetBech32ValidatorAddrPrefix() string {
return config.bech32AddressPrefix["validator_addr"]
}
// GetBech32ConsensusAddrPrefix returns the Bech32 prefix for consensus node address
func (config *AddrPrefixCfg) GetBech32ConsensusAddrPrefix() string {
return config.bech32AddressPrefix["consensus_addr"]
}
// GetBech32AccountPubPrefix returns the Bech32 prefix for account public key
func (config *AddrPrefixCfg) GetBech32AccountPubPrefix() string {
return config.bech32AddressPrefix["account_pub"]
}
// GetBech32ValidatorPubPrefix returns the Bech32 prefix for validator public key
func (config *AddrPrefixCfg) GetBech32ValidatorPubPrefix() string {
return config.bech32AddressPrefix["validator_pub"]
}
// GetBech32ConsensusPubPrefix returns the Bech32 prefix for consensus node public key
func (config *AddrPrefixCfg) GetBech32ConsensusPubPrefix() string {
return config.bech32AddressPrefix["consensus_pub"]
}