-
Notifications
You must be signed in to change notification settings - Fork 55
/
marketmaker.go
89 lines (73 loc) 路 1.87 KB
/
marketmaker.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
83
84
85
86
87
88
89
package types
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func GetAccAddress(address string) sdk.AccAddress {
if address == "" {
return nil
}
addr, err := sdk.AccAddressFromBech32(address)
if err != nil {
panic(err)
}
return addr
}
func (mm MarketMaker) GetAccAddress() sdk.AccAddress {
return GetAccAddress(mm.Address)
}
func (mm MarketMaker) Validate() error {
return ValidateMarketMaker(mm.Address, mm.PairId)
}
func (i Incentive) GetAccAddress() sdk.AccAddress {
return GetAccAddress(i.Address)
}
func (i Incentive) Validate() error {
_, err := sdk.AccAddressFromBech32(i.Address)
if err != nil {
return err
}
return i.Claimable.Validate()
}
func ValidateMarketMaker(address string, pairId uint64) error {
_, err := sdk.AccAddressFromBech32(address)
if err != nil {
return err
}
if pairId == uint64(0) {
return ErrInvalidPairId
}
return nil
}
func (mm MarketMakerHandle) Validate() error {
return ValidateMarketMaker(mm.Address, mm.PairId)
}
func (mm MarketMakerHandle) GetAccAddress() sdk.AccAddress {
return GetAccAddress(mm.Address)
}
func (id IncentiveDistribution) Validate() error {
if err := ValidateMarketMaker(id.Address, id.PairId); err != nil {
return err
}
if len(id.Amount) == 0 {
return fmt.Errorf("incentive distribution amount should be not empty")
}
return id.Amount.Validate()
}
func (id IncentiveDistribution) GetAccAddress() sdk.AccAddress {
return GetAccAddress(id.Address)
}
func UnmarshalMarketMaker(cdc codec.BinaryCodec, value []byte) (mm MarketMaker, err error) {
err = cdc.Unmarshal(value, &mm)
return mm, err
}
func (idr DepositRecord) Validate() error {
if err := ValidateMarketMaker(idr.Address, idr.PairId); err != nil {
return err
}
return idr.Amount.Validate()
}
func (idr DepositRecord) GetAccAddress() sdk.AccAddress {
return GetAccAddress(idr.Address)
}