/
constants.go
72 lines (60 loc) · 2.32 KB
/
constants.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
/*
Copyright [2019] - [2021], GRIDIRON TECHNOLOGIES PTE. LTD. and the gridironCore contributors
SPDX-License-Identifier: Apache-2.0
*/
package app
import (
errorsmod "cosmossdk.io/errors"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const (
Bech32MainPrefix = "gridiron"
CoinType = 118
Purpose = 44
HumanCoinUnit = "xprt"
BaseCoinUnit = "uxprt"
XPRTExponent = 6
Bech32PrefixAccAddr = Bech32MainPrefix
Bech32PrefixAccPub = Bech32MainPrefix + sdkTypes.PrefixPublic
Bech32PrefixValAddr = Bech32MainPrefix + sdkTypes.PrefixValidator + sdkTypes.PrefixOperator
Bech32PrefixValPub = Bech32MainPrefix + sdkTypes.PrefixValidator + sdkTypes.PrefixOperator + sdkTypes.PrefixPublic
Bech32PrefixConsAddr = Bech32MainPrefix + sdkTypes.PrefixValidator + sdkTypes.PrefixConsensus
Bech32PrefixConsPub = Bech32MainPrefix + sdkTypes.PrefixValidator + sdkTypes.PrefixConsensus + sdkTypes.PrefixPublic
)
func init() {
SetAddressPrefixes()
RegisterDenoms()
}
func RegisterDenoms() {
err := sdkTypes.RegisterDenom(HumanCoinUnit, sdkTypes.OneDec())
if err != nil {
panic(err)
}
err = sdkTypes.RegisterDenom(BaseCoinUnit, sdkTypes.NewDecWithPrec(1, XPRTExponent))
if err != nil {
panic(err)
}
}
func SetAddressPrefixes() {
config := sdkTypes.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
// This is copied from the cosmos sdk v0.43.0-beta1
// source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141
config.SetAddressVerifier(func(bytes []byte) error {
if len(bytes) == 0 {
return errorsmod.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
}
if len(bytes) > address.MaxAddrLen {
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
}
// TODO: Do we want to allow addresses of lengths other than 20 and 32 bytes?
if len(bytes) != 20 && len(bytes) != 32 {
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
}
return nil
})
}