mukan-sdk/x/authz/migrations/v2/store.go
Mukan Erkin Törük 20afb5db80
Some checks failed
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
Build & Push SDK Proto Builder / build (push) Has been cancelled
initial: sovereign Mukan Network fork
2026-05-11 03:18:24 +03:00

78 lines
2.1 KiB
Go

package v2
import (
"context"
corestoretypes "cosmossdk.io/core/store"
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/internal/conv"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
)
// MigrateStore performs in-place store migrations from v0.45 to v0.46. The
// migration includes:
//
// - pruning expired authorizations
// - create secondary index for pruning expired authorizations
func MigrateStore(ctx context.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec) error {
store := storeService.OpenKVStore(ctx)
sdkCtx := sdk.UnwrapSDKContext(ctx)
err := addExpiredGrantsIndex(sdkCtx, runtime.KVStoreAdapter(store), cdc)
if err != nil {
return err
}
return nil
}
func addExpiredGrantsIndex(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
grantsStore := prefix.NewStore(store, GrantPrefix)
grantsIter := grantsStore.Iterator(nil, nil)
defer grantsIter.Close()
queueItems := make(map[string][]string)
now := ctx.BlockTime()
for ; grantsIter.Valid(); grantsIter.Next() {
var grant authz.Grant
bz := grantsIter.Value()
if err := cdc.Unmarshal(bz, &grant); err != nil {
return err
}
// delete expired authorization
// before 0.46 Expiration was required so it's safe to dereference
if grant.Expiration.Before(now) {
grantsStore.Delete(grantsIter.Key())
} else {
granter, grantee, msgType := ParseGrantKey(grantsIter.Key())
// before 0.46 expiration was not a pointer, so now it's safe to dereference
key := GrantQueueKey(*grant.Expiration, granter, grantee)
queueItem, ok := queueItems[conv.UnsafeBytesToStr(key)]
if !ok {
queueItems[string(key)] = []string{msgType}
} else {
queueItem = append(queueItem, msgType)
queueItems[string(key)] = queueItem
}
}
}
for key, v := range queueItems {
bz, err := cdc.Marshal(&authz.GrantQueueItem{
MsgTypeUrls: v,
})
if err != nil {
return err
}
store.Set(conv.UnsafeStrToBytes(key), bz)
}
return nil
}