-
Notifications
You must be signed in to change notification settings - Fork 117
/
asset.go
62 lines (49 loc) · 1.05 KB
/
asset.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
package types
import (
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
type Assets []Asset
// NewAsset returns a new Asset
func NewAsset(symbol string) Asset {
return Asset{
Symbol: symbol,
}
}
func (a Asset) Validate() bool {
if !VerifyRange(len(strings.TrimSpace(a.Symbol)), 0, MaxSymbolLength) {
return false
}
coin := sdk.NewCoin(a.Symbol, sdk.OneInt())
return coin.IsValid()
}
func VerifyRange(num, low, high int) bool {
if num >= high {
return false
}
if num <= low {
return false
}
return true
}
func (a Asset) Equals(a2 Asset) bool {
return a.Symbol == (a2.Symbol)
}
func (a Asset) IsEmpty() bool {
return a.Symbol == ""
}
func (a *Asset) IsSettlementAsset() bool {
return *a == GetSettlementAsset()
}
func GetSettlementAsset() Asset {
return Asset{
Symbol: NativeSymbol,
}
}
func GetCLPModuleAddress() sdk.AccAddress {
return authtypes.NewModuleAddress(ModuleName)
}
func GetDefaultCLPAdmin() sdk.AccAddress {
return authtypes.NewModuleAddress("ClpAdmin")
}