-
Notifications
You must be signed in to change notification settings - Fork 341
/
config.go
60 lines (46 loc) · 1.1 KB
/
config.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
package config
import (
"flag"
"log"
"sync"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func SetConfig() {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix)
config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix)
config.SetCoinType(CoinType)
croUnit := sdk.OneDec()
err := sdk.RegisterDenom(HumanCoinUnit, croUnit)
if err != nil {
log.Fatal(err)
}
carsonUnit := sdk.NewDecWithPrec(1, int64(CroExponent)) // 10^-8 (carson)
err = sdk.RegisterDenom(BaseCoinUnit, carsonUnit)
if err != nil {
log.Fatal(err)
}
config.Seal()
}
var testingConfigState = struct {
mtx sync.Mutex
isSet bool
}{
isSet: false,
}
func SetTestingConfig() {
if !isGoTest() {
panic("SetTestingConfig called but not running go test")
}
testingConfigState.mtx.Lock()
defer testingConfigState.mtx.Unlock()
if testingConfigState.isSet {
return
}
SetConfig()
testingConfigState.isSet = true
}
func isGoTest() bool {
return flag.Lookup("test.v") != nil
}