Some checks are pending
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
90 lines
2.9 KiB
Go
90 lines
2.9 KiB
Go
package keeper
|
|
|
|
import (
|
|
"github.com/cosmos/gogoproto/grpc"
|
|
|
|
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/auth/exported"
|
|
v2 "git.cw.tr/mukan-network/mukan-sdk/x/auth/migrations/v2"
|
|
v3 "git.cw.tr/mukan-network/mukan-sdk/x/auth/migrations/v3"
|
|
v4 "git.cw.tr/mukan-network/mukan-sdk/x/auth/migrations/v4"
|
|
v5 "git.cw.tr/mukan-network/mukan-sdk/x/auth/migrations/v5"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/auth/types"
|
|
)
|
|
|
|
// Migrator is a struct for handling in-place store migrations.
|
|
type Migrator struct {
|
|
keeper AccountKeeper
|
|
queryServer grpc.Server
|
|
legacySubspace exported.Subspace
|
|
}
|
|
|
|
// NewMigrator returns a new Migrator.
|
|
func NewMigrator(keeper AccountKeeper, queryServer grpc.Server, ss exported.Subspace) Migrator {
|
|
return Migrator{keeper: keeper, queryServer: queryServer, legacySubspace: ss}
|
|
}
|
|
|
|
// Migrate1to2 migrates from version 1 to 2.
|
|
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
|
var iterErr error
|
|
|
|
m.keeper.IterateAccounts(ctx, func(account sdk.AccountI) (stop bool) {
|
|
wb, err := v2.MigrateAccount(ctx, account, m.queryServer)
|
|
if err != nil {
|
|
iterErr = err
|
|
return true
|
|
}
|
|
|
|
if wb == nil {
|
|
return false
|
|
}
|
|
|
|
m.keeper.SetAccount(ctx, wb)
|
|
return false
|
|
})
|
|
|
|
return iterErr
|
|
}
|
|
|
|
// Migrate2to3 migrates from consensus version 2 to version 3. Specifically, for each account
|
|
// we index the account's ID to their address.
|
|
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
|
|
return v3.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc)
|
|
}
|
|
|
|
// Migrate3to4 migrates the x/auth module state from the consensus version 3 to
|
|
// version 4. Specifically, it takes the parameters that are currently stored
|
|
// and managed by the x/params modules and stores them directly into the x/auth
|
|
// module state.
|
|
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
|
|
return v4.Migrate(ctx, m.keeper.storeService, m.legacySubspace, m.keeper.cdc)
|
|
}
|
|
|
|
// Migrate4To5 migrates the x/auth module state from the consensus version 4 to 5.
|
|
// It migrates the GlobalAccountNumber from being a protobuf defined value to a
|
|
// big-endian encoded uint64, it also migrates it to use a more canonical prefix.
|
|
func (m Migrator) Migrate4To5(ctx sdk.Context) error {
|
|
return v5.Migrate(ctx, m.keeper.storeService, m.keeper.AccountNumber)
|
|
}
|
|
|
|
// V45_SetAccount implements V45_SetAccount
|
|
// set the account without map to accAddr to accNumber.
|
|
//
|
|
// NOTE: This is used for testing purposes only.
|
|
func (m Migrator) V45SetAccount(ctx sdk.Context, acc sdk.AccountI) error {
|
|
addr := acc.GetAddress()
|
|
store := m.keeper.storeService.OpenKVStore(ctx)
|
|
|
|
bz, err := m.keeper.Accounts.ValueCodec().Encode(acc)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return store.Set(addressStoreKey(addr), bz)
|
|
}
|
|
|
|
// addressStoreKey turn an address to key used to get it from the account store
|
|
// NOTE(tip): exists for legacy compatibility
|
|
func addressStoreKey(addr sdk.AccAddress) []byte {
|
|
return append(types.AddressStoreKeyPrefix, addr.Bytes()...)
|
|
}
|