-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f36991
commit 9242669
Showing
8 changed files
with
426 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/sentinel-official/hub/v12/x/deposit/types/v1" | ||
) | ||
|
||
type Migrator struct { | ||
Keeper | ||
} | ||
|
||
func NewMigrator(k Keeper) Migrator { | ||
return Migrator{k} | ||
} | ||
|
||
func (k Migrator) Migrate(ctx sdk.Context) error { | ||
if err := k.refund(ctx); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (k Migrator) refund(ctx sdk.Context) error { | ||
k.IterateDeposits(ctx, func(_ int, item v1.Deposit) (stop bool) { | ||
addr, err := sdk.AccAddressFromBech32(item.Address) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := k.SubtractDeposit(ctx, addr, item.Coins); err != nil { | ||
panic(err) | ||
} | ||
|
||
return false | ||
}) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package keeper | ||
|
||
import ( | ||
"time" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
base "github.com/sentinel-official/hub/v12/types" | ||
v1base "github.com/sentinel-official/hub/v12/types/v1" | ||
"github.com/sentinel-official/hub/v12/x/node/types/v2" | ||
"github.com/sentinel-official/hub/v12/x/node/types/v3" | ||
) | ||
|
||
type Migrator struct { | ||
Keeper | ||
} | ||
|
||
func NewMigrator(k Keeper) Migrator { | ||
return Migrator{k} | ||
} | ||
|
||
func (k *Migrator) Migrate(ctx sdk.Context) error { | ||
prefixList := [][]byte{ | ||
{0x11}, // NodeForInactiveAtKeyPrefix | ||
{0x12}, // NodeForPlanKeyPrefix | ||
} | ||
|
||
for _, buf := range prefixList { | ||
k.deleteKeys(ctx, buf) | ||
} | ||
|
||
k.setParams(ctx) | ||
k.migrateNodes(ctx) | ||
|
||
return nil | ||
} | ||
|
||
func (k *Migrator) deleteKeys(ctx sdk.Context, keyPrefix []byte) { | ||
store := prefix.NewStore(k.Store(ctx), keyPrefix) | ||
|
||
it := store.Iterator(nil, nil) | ||
defer it.Close() | ||
|
||
for ; it.Valid(); it.Next() { | ||
store.Delete(it.Key()) | ||
} | ||
} | ||
|
||
func (k *Migrator) setParams(ctx sdk.Context) { | ||
params := v3.Params{ | ||
Deposit: sdk.NewInt64Coin("udvpn", 0), | ||
ActiveDuration: 1 * time.Hour, | ||
MinGigabytePrices: []v1base.Price{}, | ||
MinHourlyPrices: []v1base.Price{}, | ||
MaxSessionGigabytes: 1_000_000, | ||
MinSessionGigabytes: 1, | ||
MaxSessionHours: 720, | ||
MinSessionHours: 1, | ||
StakingShare: sdkmath.LegacyMustNewDecFromStr("0.2"), | ||
} | ||
|
||
k.SetParams(ctx, params) | ||
} | ||
|
||
func (k *Migrator) migrateNodes(ctx sdk.Context) { | ||
store := prefix.NewStore(k.Store(ctx), []byte{0x10}) | ||
|
||
it := store.Iterator(nil, nil) | ||
defer it.Close() | ||
|
||
for ; it.Valid(); it.Next() { | ||
var item v2.Node | ||
k.cdc.MustUnmarshal(it.Value(), &item) | ||
store.Delete(it.Key()) | ||
|
||
node := v3.Node{ | ||
Address: item.Address, | ||
GigabytePrices: nil, | ||
HourlyPrices: nil, | ||
RemoteURL: item.RemoteURL, | ||
InactiveAt: item.InactiveAt, | ||
Status: item.Status, | ||
StatusAt: item.StatusAt, | ||
} | ||
|
||
addr, err := base.NodeAddressFromBech32(node.Address) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
k.SetNode(ctx, node) | ||
k.SetNodeForInactiveAt(ctx, node.InactiveAt, addr) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package keeper | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
base "github.com/sentinel-official/hub/v12/types" | ||
v1base "github.com/sentinel-official/hub/v12/types/v1" | ||
"github.com/sentinel-official/hub/v12/x/plan/types/v2" | ||
"github.com/sentinel-official/hub/v12/x/plan/types/v3" | ||
) | ||
|
||
type Migrator struct { | ||
Keeper | ||
} | ||
|
||
func NewMigrator(k Keeper) Migrator { | ||
return Migrator{k} | ||
} | ||
|
||
func (k *Migrator) Migrate(ctx sdk.Context) error { | ||
prefixList := [][]byte{ | ||
{0x11}, // PlanForProviderKeyPrefix | ||
} | ||
|
||
for _, buf := range prefixList { | ||
k.deleteKeys(ctx, buf) | ||
} | ||
|
||
k.migratePlans(ctx) | ||
|
||
return nil | ||
} | ||
|
||
func (k *Migrator) deleteKeys(ctx sdk.Context, keyPrefix []byte) { | ||
store := prefix.NewStore(k.Store(ctx), keyPrefix) | ||
|
||
it := store.Iterator(nil, nil) | ||
defer it.Close() | ||
|
||
for ; it.Valid(); it.Next() { | ||
store.Delete(it.Key()) | ||
} | ||
} | ||
|
||
func (k *Migrator) migratePlans(ctx sdk.Context) { | ||
store := prefix.NewStore(k.Store(ctx), []byte{0x10}) | ||
|
||
it := store.Iterator(nil, nil) | ||
defer it.Close() | ||
|
||
for ; it.Valid(); it.Next() { | ||
var item v2.Plan | ||
k.cdc.MustUnmarshal(it.Value(), &item) | ||
store.Delete(it.Key()) | ||
|
||
plan := v3.Plan{ | ||
ID: item.ID, | ||
ProvAddress: item.ProviderAddress, | ||
Gigabytes: item.Gigabytes, | ||
Hours: int64(item.Duration / time.Hour), | ||
Prices: []v1base.Price{}, | ||
Status: item.Status, | ||
StatusAt: item.StatusAt, | ||
} | ||
|
||
addr, err := base.ProvAddressFromBech32(plan.ProvAddress) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
k.SetPlan(ctx, plan) | ||
k.SetPlanForProvider(ctx, addr, plan.ID) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package keeper | ||
|
||
import ( | ||
sdkmath "cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/sentinel-official/hub/v12/x/provider/types/v2" | ||
) | ||
|
||
type Migrator struct { | ||
Keeper | ||
} | ||
|
||
func NewMigrator(k Keeper) Migrator { | ||
return Migrator{k} | ||
} | ||
|
||
func (k *Migrator) Migrate(ctx sdk.Context) error { | ||
k.setParams(ctx) | ||
|
||
return nil | ||
} | ||
|
||
func (k *Migrator) setParams(ctx sdk.Context) { | ||
params := v2.Params{ | ||
Deposit: sdk.NewInt64Coin("udvpn", 0), | ||
StakingShare: sdkmath.LegacyMustNewDecFromStr("0.2"), | ||
} | ||
|
||
k.SetParams(ctx, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package keeper | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/sentinel-official/hub/v12/x/session/types/v2" | ||
) | ||
|
||
type Migrator struct { | ||
Keeper | ||
} | ||
|
||
func NewMigrator(k Keeper) Migrator { | ||
return Migrator{k} | ||
} | ||
|
||
func (k *Migrator) Migrate(ctx sdk.Context) error { | ||
prefixList := [][]byte{ | ||
{0x10}, // SessionKeyPrefix | ||
|
||
{0x11}, // SessionForInactiveAtKeyPrefix | ||
{0x12}, // SessionForAccountKeyPrefix | ||
{0x13}, // SessionForNodeKeyPrefix | ||
{0x14}, // SessionForSubscriptionKeyPrefix | ||
{0x15}, // SessionForAllocationKeyPrefix | ||
} | ||
|
||
for _, buf := range prefixList { | ||
k.deleteKeys(ctx, buf) | ||
} | ||
|
||
k.setParams(ctx) | ||
|
||
return nil | ||
} | ||
|
||
func (k *Migrator) deleteKeys(ctx sdk.Context, keyPrefix []byte) { | ||
store := prefix.NewStore(k.Store(ctx), keyPrefix) | ||
|
||
it := store.Iterator(nil, nil) | ||
defer it.Close() | ||
|
||
for ; it.Valid(); it.Next() { | ||
store.Delete(it.Key()) | ||
} | ||
} | ||
|
||
func (k *Migrator) setParams(ctx sdk.Context) { | ||
params := v2.Params{ | ||
StatusChangeDelay: 2 * time.Hour, | ||
ProofVerificationEnabled: false, | ||
} | ||
|
||
k.SetParams(ctx, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package keeper | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/sentinel-official/hub/v12/x/subscription/types/v2" | ||
) | ||
|
||
type Migrator struct { | ||
Keeper | ||
} | ||
|
||
func NewMigrator(k Keeper) Migrator { | ||
return Migrator{k} | ||
} | ||
|
||
func (k *Migrator) Migrate(ctx sdk.Context) error { | ||
prefixList := [][]byte{ | ||
{0x10}, // SubscriptionKeyPrefix | ||
{0x20}, // AllocationKeyPrefix | ||
{0x30}, // PayoutKeyPrefix | ||
|
||
{0x11}, // SubscriptionForInactiveAtKeyPrefix | ||
{0x12}, // SubscriptionForAccountKeyPrefix | ||
{0x13}, // SubscriptionForNodeKeyPrefix | ||
{0x14}, // SubscriptionForPlanKeyPrefix | ||
|
||
{0x31}, // PayoutForNextAtKeyPrefix | ||
{0x32}, // PayoutForAccountKeyPrefix | ||
{0x33}, // PayoutForNodeKeyPrefix | ||
{0x34}, // PayoutForAccountByNodeKeyPrefix | ||
} | ||
|
||
for _, buf := range prefixList { | ||
k.deleteKeys(ctx, buf) | ||
} | ||
|
||
k.setParams(ctx) | ||
|
||
return nil | ||
} | ||
|
||
func (k *Migrator) deleteKeys(ctx sdk.Context, keyPrefix []byte) { | ||
store := prefix.NewStore(k.Store(ctx), keyPrefix) | ||
|
||
it := store.Iterator(nil, nil) | ||
defer it.Close() | ||
|
||
for ; it.Valid(); it.Next() { | ||
store.Delete(it.Key()) | ||
} | ||
} | ||
|
||
func (k *Migrator) setParams(ctx sdk.Context) { | ||
params := v2.Params{ | ||
StatusChangeDelay: 4 * time.Hour, | ||
} | ||
|
||
k.SetParams(ctx, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.