-
Notifications
You must be signed in to change notification settings - Fork 203
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
Showing
6 changed files
with
1,392 additions
and
131 deletions.
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
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
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,24 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
v2 "github.com/initia-labs/initia/x/gov/migrations/v2" | ||
) | ||
|
||
// Migrator is a struct for handling in-place store migrations. | ||
type Migrator struct { | ||
keeper *Keeper | ||
} | ||
|
||
// NewMigrator returns a new Migrator. | ||
func NewMigrator(keeper *Keeper) Migrator { | ||
return Migrator{ | ||
keeper: keeper, | ||
} | ||
} | ||
|
||
// Migrate1to2 migrates from version 1 to 2. | ||
func (m Migrator) Migrate1to2(ctx sdk.Context) error { | ||
return v2.MigrateStore(ctx, m.keeper.Proposals, m.keeper.storeService, m.keeper.cdc) | ||
} |
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,66 @@ | ||
package v1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"cosmossdk.io/collections" | ||
corestoretypes "cosmossdk.io/core/store" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
customtypes "github.com/initia-labs/initia/x/gov/types" | ||
) | ||
|
||
const ( | ||
ModuleName = "gov" | ||
) | ||
|
||
func ConvertLegacyProposalToProposal(proposal customtypes.LegacyProposal) customtypes.Proposal { | ||
return customtypes.Proposal{ | ||
Id: proposal.Id, | ||
Messages: proposal.Messages, | ||
EmergencyStartTime: proposal.EmergencyStartTime, | ||
EmergencyNextTallyTime: proposal.EmergencyNextTallyTime, | ||
Metadata: proposal.Metadata, | ||
Title: proposal.Title, | ||
Summary: proposal.Summary, | ||
Proposer: proposal.Proposer, | ||
Expedited: proposal.Expedited, | ||
Emergency: proposal.Emergency, | ||
FailedReason: proposal.FailedReason, | ||
Status: proposal.Status, | ||
SubmitTime: proposal.SubmitTime, | ||
DepositEndTime: proposal.DepositEndTime, | ||
TotalDeposit: proposal.TotalDeposit, | ||
VotingStartTime: proposal.VotingStartTime, | ||
VotingEndTime: proposal.VotingEndTime, | ||
|
||
// Convert the final tally result | ||
FinalTallyResult: customtypes.TallyResult{ | ||
TallyHeight: 0, | ||
TotalStakingPower: "0", | ||
TotalVestingPower: "0", | ||
V1TallyResult: proposal.FinalTallyResult, | ||
}, | ||
} | ||
} | ||
|
||
func MigrateStore( | ||
ctx context.Context, | ||
proposals collections.Map[uint64, customtypes.Proposal], | ||
storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec, | ||
) error { | ||
sb := collections.NewSchemaBuilder(storeService) | ||
legacyProposals := collections.NewMap(sb, types.ProposalsKeyPrefix, "proposals", collections.Uint64Key, codec.CollValue[customtypes.LegacyProposal](cdc)) | ||
_, err := sb.Build() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("SIBONG") | ||
return legacyProposals.Walk(ctx, nil, func(pid uint64, lp customtypes.LegacyProposal) (bool, error) { | ||
p := ConvertLegacyProposalToProposal(lp) | ||
return false, proposals.Set(ctx, pid, p) | ||
}) | ||
} |
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.