-
Notifications
You must be signed in to change notification settings - Fork 267
/
genesis.go
84 lines (72 loc) · 2.45 KB
/
genesis.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
package types
import (
"fmt"
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
"cosmossdk.io/errors"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
// DefaultParamspace defines the default blobstream module parameter subspace
const (
DefaultParamspace = ModuleName
// MinimumDataCommitmentWindow is a constant that defines the minimum
// allowable window for the Blobstream data commitments.
MinimumDataCommitmentWindow = 100
)
// ParamsStoreKeyDataCommitmentWindow is the key used for the
// DataCommitmentWindow param.
var ParamsStoreKeyDataCommitmentWindow = []byte("DataCommitmentWindow")
// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
Params: &Params{
DataCommitmentWindow: 400,
},
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
// this line is used by starport scaffolding # genesis/types/validate
if err := gs.Params.ValidateBasic(); err != nil {
return errors.Wrap(err, "params")
}
return nil
}
// ParamKeyTable for blobstream module
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}
// ParamSetPairs implements the ParamSet interface and returns all the key/value
// pairs of auth module's parameters.
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamsStoreKeyDataCommitmentWindow, &p.DataCommitmentWindow, validateDataCommitmentWindow),
}
}
func validateDataCommitmentWindow(i interface{}) error {
val, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
} else if val < MinimumDataCommitmentWindow {
return errors.Wrap(ErrInvalidDataCommitmentWindow, fmt.Sprintf(
"data commitment window %v must be >= minimum data commitment window %v",
val,
MinimumDataCommitmentWindow,
))
}
if val > uint64(appconsts.DataCommitmentBlocksLimit) {
return errors.Wrap(ErrInvalidDataCommitmentWindow, fmt.Sprintf(
"data commitment window %v must be <= data commitment blocks limit %v",
val,
appconsts.DataCommitmentBlocksLimit,
))
}
return nil
}
// ValidateBasic checks that the parameters have valid values.
func (p Params) ValidateBasic() error {
if err := validateDataCommitmentWindow(p.DataCommitmentWindow); err != nil {
return errors.Wrap(err, "data commitment window")
}
return nil
}