-
Notifications
You must be signed in to change notification settings - Fork 16
/
types.go
133 lines (108 loc) · 3.6 KB
/
types.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package v4
import (
"errors"
"fmt"
"strings"
"github.com/cosmos/cosmos-sdk/x/params/types"
types2 "github.com/jackalLabs/canine-chain/v3/x/storage/types"
)
type LegacyParams struct {
DepositAccount string `protobuf:"bytes,1,opt,name=deposit_account,json=depositAccount,proto3" json:"deposit_account,omitempty"`
ProofWindow int64 `protobuf:"varint,2,opt,name=proof_window,json=proofWindow,proto3" json:"proof_window,omitempty"`
// Chunk size of a file is divided into
// The value cannot be smaller than 1 to avoid zero division
ChunkSize int64 `protobuf:"varint,3,opt,name=chunk_size,json=chunkSize,proto3" json:"chunk_size,omitempty"`
MissesToBurn int64 `protobuf:"varint,4,opt,name=misses_to_burn,json=missesToBurn,proto3" json:"misses_to_burn,omitempty"`
PriceFeed string `protobuf:"bytes,5,opt,name=price_feed,json=priceFeed,proto3" json:"price_feed,omitempty"`
// Life span of a contract in blocks
MaxContractAgeInBlocks int64 `protobuf:"varint,6,opt,name=max_contract_age_in_blocks,json=maxContractAgeInBlocks,proto3" json:"max_contract_age_in_blocks,omitempty"`
PricePerTbPerMonth int64 `protobuf:"varint,7,opt,name=price_per_tb_per_month,json=pricePerTbPerMonth,proto3" json:"price_per_tb_per_month,omitempty"`
}
// ParamSetPairs get the params.ParamSet
func (p *LegacyParams) ParamSetPairs() types.ParamSetPairs {
return types.ParamSetPairs{
types.NewParamSetPair(types2.KeyDepositAccount, &p.DepositAccount, validateDeposit),
types.NewParamSetPair(types2.KeyProofWindow, &p.ProofWindow, validateProofWindow),
types.NewParamSetPair(types2.KeyChunkSize, &p.ChunkSize, validateChunkSize),
types.NewParamSetPair(types2.KeyMissesToBurn, &p.MissesToBurn, validateMissesToBurn),
types.NewParamSetPair(types2.KeyPriceFeed, &p.PriceFeed, validatePriceFeed),
types.NewParamSetPair(
types2.KeyMaxContractAgeInBlocks,
&p.MaxContractAgeInBlocks,
validateMaxContractAgeInBlocks),
types.NewParamSetPair(
types2.KeyPricePerTbPerMonth,
&p.PricePerTbPerMonth,
validatePricePerTbPerMonth),
}
}
func validateProofWindow(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v <= 1 {
return errors.New("proof window must be greater than 1")
}
return nil
}
func validateDeposit(i interface{}) error {
v, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if strings.TrimSpace(v) == "" {
return errors.New("deposit cannot be blank")
}
return nil
}
func validateChunkSize(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v < 1 {
return errors.New("chunk size cannot be smaller than 1")
}
return nil
}
func validateMissesToBurn(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v < 1 {
return errors.New("misses to burn cannot be smaller than 1")
}
return nil
}
func validatePriceFeed(i interface{}) error {
v, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if strings.TrimSpace(v) == "" {
return errors.New("price feed cannot be blank")
}
return nil
}
func validateMaxContractAgeInBlocks(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v < 0 {
return errors.New("max contract age in blocks cannot be negative")
}
return nil
}
func validatePricePerTbPerMonth(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v < 0 {
return errors.New("price per tb per month cannot be negative")
}
return nil
}