-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.go
66 lines (53 loc) · 1.35 KB
/
upgrade.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
package upgrade
import (
"errors"
store "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/store/types"
sdk "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/x/params"
)
type UpgradeModule interface {
RegisterTask() HeightTask
UpgradeHeight() int64
RegisterParam() params.ParamSet
ModuleName() string
CommitFilter() *store.StoreFilter
PruneFilter() *store.StoreFilter
VersionFilter() *store.VersionFilter
}
type HeightTasks []HeightTask
func (h HeightTasks) Len() int {
return len(h)
}
func (h HeightTasks) Less(i, j int) bool {
return h[i].GetOrderer() < h[j].GetOrderer()
}
func (h HeightTasks) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
}
type HeightTask interface {
GetOrderer() int16
Execute(c sdk.Context) error
ValidateBasic() error
}
type heightTask struct {
orderer int16
taskExecutor func(ctx sdk.Context) error
}
var (
_ HeightTask = (*heightTask)(nil)
)
func NewHeightTask(orderer int16, taskExecutor func(ctx sdk.Context) error) HeightTask {
return &heightTask{orderer: orderer, taskExecutor: taskExecutor}
}
func (t *heightTask) GetOrderer() int16 {
return t.orderer
}
func (t *heightTask) ValidateBasic() error {
if t.taskExecutor == nil {
return errors.New("executor cant be nil")
}
return nil
}
func (t *heightTask) Execute(ctx sdk.Context) error {
return t.taskExecutor(ctx)
}