-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathstate.go
149 lines (135 loc) · 5.5 KB
/
state.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package v4
import (
sdk "github.com/cosmos/cosmos-sdk/types"
basketv1 "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/basket/v1"
ecocreditv1 "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/v1"
)
// MigrateState performs in-place store migrations from ConsensusVersion 3 to 4.
func MigrateState(sdkCtx sdk.Context, baseStore ecocreditv1.StateStore, basketStore basketv1.StateStore) error {
if sdkCtx.ChainID() == "regen-1" {
// mainnet batch metadata migration
batchUpdates := getBatchUpdates()
for _, batchUpdate := range batchUpdates {
if err := migrateBatchMetadata(sdkCtx, baseStore, batchUpdate); err != nil {
return err
}
}
// mainnet basket criteria migration
if err := migrateBasketCriteria(sdkCtx, basketStore); err != nil {
return err
}
}
return nil
}
type Batch struct {
Denom string
NewMetadata string
}
func getBatchUpdates() []Batch {
return []Batch{
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-001
{
Denom: "C01-001-20150101-20151231-001",
NewMetadata: "regen:13toVg38ZRvFxPA2TBNnxGhabgogpJnv4LDm7YPgSuzuETiXz8GbnTF.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-002
{
Denom: "C01-001-20150101-20151231-002",
NewMetadata: "regen:13toVhTFtGtXxoHw7yy3QQVDGEpSQoVy4VARhtTWeuNQa5V25WUhagq.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-003
{
Denom: "C01-001-20150101-20151231-003",
NewMetadata: "regen:13toVghYySmmX9gm76MuwiPCC9AJy6Psb7wj6uj9JiBk4NvACGkpJDw.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-004
{
Denom: "C01-001-20150101-20151231-004",
NewMetadata: "regen:13toVgGhCxGuNrqKKugLY9thKAdLTgXHGxhbVutz2QLgtFmdZzPAKUB.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-005
{
Denom: "C01-001-20150101-20151231-005",
NewMetadata: "regen:13toVhaDUK1CHmqdZfKr6ZdF1L1ekTvUgjbEiGxWYqDWVZ937GUviFr.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-001
{
Denom: "C01-002-20190101-20191231-001",
NewMetadata: "regen:13toVgu5VbjKdfDKuwPfUoMeo2isi1ApbsCsaTCoyNknKnN9FE6j1hW.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-002
{
Denom: "C01-002-20190101-20191231-002",
NewMetadata: "regen:13toVgxDAxBev51DadD1he6gdkF6UPAoe25Y2xsSn3uDpzmHG3qGqRh.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-003
{
Denom: "C01-002-20190101-20191231-003",
NewMetadata: "regen:13toVgsTujvEeCS4hG9MXZii8eF9LBkrgzaw8mh2q54KfFtGFtH5DLi.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-004
{
Denom: "C01-002-20190101-20191231-004",
NewMetadata: "regen:13toVhKuR8NndSGZdciYTtCJf11hjYGwNvsWdjSPBmXNAqk8oL7u7XW.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-003-20150701-20160630-001
{
Denom: "C01-003-20150701-20160630-001",
NewMetadata: "regen:13toVhMT8c7hFZePMqa8raLBgCuLFo4MWbJ7QJRheFRC5dfPcmFZ4hk.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-001-20180101-20181231-001
{
Denom: "C02-001-20180101-20181231-001",
NewMetadata: "regen:13toVgpAwAm6fzYUUkD8UmioCYCP3GMbA3pdNkTM4wKeWc5UxmmCZW8.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-003-20200630-20220629-001
{
Denom: "C02-003-20200630-20220629-001",
NewMetadata: "regen:13toVh5g1AhGAWcTQCBXra1YfD2XJUbH35dvSLuEPAR8mQHJDY5ovVe.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-002-20211012-20241013-001
{
Denom: "C02-002-20211012-20241013-001",
NewMetadata: "regen:13toVhAukPXsjX5gMTADfUQzJQBjehJJoPwSavuU6GjyH5DtxZ5oVYS.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-004-20210102-20211207-001
{
Denom: "C02-004-20210102-20211207-001",
NewMetadata: "regen:13toVh1EoPoJJs1VSvmeQB3HHpXDgFBA19KqiP1tg4NByjWsFLJdjuq.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-005
{
Denom: "C01-002-20190101-20191231-005",
NewMetadata: "regen:13toVgwjqzxx3b9cRiRXBxrsUQB6D1WC4Kk8zZuXUfwnZ8WYtxRy4r5.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-006
{
Denom: "C01-001-20150101-20151231-006",
NewMetadata: "regen:13toVhaPG4MzeWcmoriPhQ5jRGx6ohhdzBPREoarrdqTRVCP8Xj7scM.rdf",
},
// http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-006
{
Denom: "C01-002-20190101-20191231-006",
NewMetadata: "regen:13toVh3NyL4uDzLFcrf6rUFMQnV8af87tBdSzh1Dvsc8zgEx193Y7hr.rdf",
},
}
}
func migrateBatchMetadata(ctx sdk.Context, baseStore ecocreditv1.StateStore, batch Batch) error {
b, err := baseStore.BatchTable().GetByDenom(ctx, batch.Denom)
if err != nil {
return err
}
b.Metadata = batch.NewMetadata
return baseStore.BatchTable().Update(ctx, b)
}
func migrateBasketCriteria(ctx sdk.Context, basketStore basketv1.StateStore) error {
b, err := basketStore.BasketTable().GetByBasketDenom(ctx, "eco.uC.NCT")
if err != nil {
return err
}
b.DisableAutoRetire = true
b.DateCriteria = &basketv1.DateCriteria{
YearsInThePast: 10,
}
return basketStore.BasketTable().Update(ctx, b)
}