Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Aug 28, 2024
1 parent 70fd024 commit 9d4ece4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (k Keeper) registerInterchainAccount(ctx context.Context, connectionID, por
}
}

sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52
msg := channeltypes.NewMsgChannelOpenInit(portID, version, ordering, []string{connectionID}, icatypes.HostPortID, authtypes.NewModuleAddress(icatypes.ModuleName).String())
handler := k.msgRouter.Handler(msg)
res, err := handler(sdkCtx, msg)
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/29-fee/keeper/escrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (k Keeper) distributePacketFeeOnTimeout(ctx context.Context, refundAddr, ti
// the state changes will be discarded.
func (k Keeper) distributeFee(ctx context.Context, receiver, refundAccAddress sdk.AccAddress, fee sdk.Coins) {
// cache context before trying to distribute fees
sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52
cacheCtx, writeFn := sdkCtx.CacheContext()

err := k.bankKeeper.SendCoinsFromModuleToAccount(cacheCtx, types.ModuleName, receiver, fee)
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/29-fee/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func emitIncentivizedPacketEvent(ctx context.Context, packetID channeltypes.Pack
totalTimeoutFees = totalTimeoutFees.Add(fee.Fee.TimeoutFee...)
}
}
sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeIncentivizedPacket,
Expand All @@ -47,7 +47,7 @@ func emitIncentivizedPacketEvent(ctx context.Context, packetID channeltypes.Pack

// emitRegisterPayeeEvent emits an event containing information of a registered payee for a relayer on a particular channel
func emitRegisterPayeeEvent(ctx context.Context, relayer, payee, channelID string) {
sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeRegisterPayee,
Expand All @@ -64,7 +64,7 @@ func emitRegisterPayeeEvent(ctx context.Context, relayer, payee, channelID strin

// emitRegisterCounterpartyPayeeEvent emits an event containing information of a registered counterparty payee for a relayer on a particular channel
func emitRegisterCounterpartyPayeeEvent(ctx context.Context, relayer, counterpartyPayee, channelID string) {
sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeRegisterCounterpartyPayee,
Expand All @@ -81,7 +81,7 @@ func emitRegisterCounterpartyPayeeEvent(ctx context.Context, relayer, counterpar

// emitDistributeFeeEvent emits an event containing a distribution fee and receiver address
func emitDistributeFeeEvent(ctx context.Context, receiver string, fee sdk.Coins) {
sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeDistributeFee,
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func NewSimApp(
bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore)

// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[capabilitytypes.StoreKey]), runtime.NewMemStoreService(memKeys[capabilitytypes.MemStoreKey]))

scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
Expand Down
50 changes: 36 additions & 14 deletions modules/capability/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (k *Keeper) IsSealed() bool {
// can't initialize it in a constructor.
func (k *Keeper) InitMemStore(ctx context.Context) {
// create context with no block gas meter to ensure we do not consume gas during local initialization logic.
sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after 52 upgrade
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove after 52 upgrade
noGasCtx := sdkCtx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()).WithGasMeter(storetypes.NewInfiniteGasMeter())

// check if memory store has not been initialized yet by checking if initialized flag is nil.
Expand All @@ -146,7 +146,9 @@ func (k *Keeper) InitMemStore(ctx context.Context) {

// set the initialized flag so we don't rerun initialization logic
memStore := k.memService.OpenMemoryStore(noGasCtx)
memStore.Set(types.KeyMemInitialized, []byte{1})
if err := memStore.Set(types.KeyMemInitialized, []byte{1}); err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}
}
}

Expand Down Expand Up @@ -174,7 +176,9 @@ func (k Keeper) InitializeIndex(ctx context.Context, index uint64) error {

// set the global index to the passed index
store := k.storeService.OpenKVStore(ctx)
store.Set(types.KeyIndex, types.IndexToKey(index))
if err := store.Set(types.KeyIndex, types.IndexToKey(index)); err != nil {
panic(err)
}
return nil
}

Expand Down Expand Up @@ -224,13 +228,17 @@ func (k Keeper) InitializeCapability(ctx context.Context, index uint64, owners t
for _, owner := range owners.Owners {
// Set the forward mapping between the module and capability tuple and the
// capability name in the memKVStore
memStore.Set(types.FwdCapabilityKey(owner.Module, capability), []byte(owner.Name))
if err := memStore.Set(types.FwdCapabilityKey(owner.Module, capability), []byte(owner.Name)); err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

// Set the reverse mapping between the module and capability name and the
// index in the in-memory store. Since marshalling and unmarshalling into a store
// will change memory address of capability, we simply store index as value here
// and retrieve the in-memory pointer to the capability from our map
memStore.Set(types.RevCapabilityKey(owner.Module, owner.Name), sdk.Uint64ToBigEndian(index))
if err := memStore.Set(types.RevCapabilityKey(owner.Module, owner.Name), sdk.Uint64ToBigEndian(index)); err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

// Set the mapping from index to in-memory capability in the go map
k.capMap[index] = capability
Expand All @@ -253,7 +261,7 @@ func (sk ScopedKeeper) NewCapability(ctx context.Context, name string) (*types.C
store := sk.storeService.OpenKVStore(ctx)

if _, ok := sk.GetCapability(ctx, name); ok {
return nil, errorsmod.Wrapf(types.ErrCapabilityTaken, fmt.Sprintf("module: %s, name: %s", sk.module, name))
return nil, errorsmod.Wrapf(types.ErrCapabilityTaken, "module: %s, name: %s", sk.module, name)
}

// create new capability with the current global index
Expand All @@ -270,19 +278,25 @@ func (sk ScopedKeeper) NewCapability(ctx context.Context, name string) (*types.C
}

// increment global index
store.Set(types.KeyIndex, types.IndexToKey(index+1))
if err := store.Set(types.KeyIndex, types.IndexToKey(index+1)); err != nil {
panic(err)
}

memStore := sk.memService.OpenMemoryStore(ctx)

// Set the forward mapping between the module and capability tuple and the
// capability name in the memKVStore
memStore.Set(types.FwdCapabilityKey(sk.module, capability), []byte(name))
if err := memStore.Set(types.FwdCapabilityKey(sk.module, capability), []byte(name)); err != nil {
panic(err)
}

// Set the reverse mapping between the module and capability name and the
// index in the in-memory store. Since marshalling and unmarshalling into a store
// will change memory address of capability, we simply store index as value here
// and retrieve the in-memory pointer to the capability from our map
memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(index))
if err := memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(index)); err != nil {
panic(err)
}

// Set the mapping from index to in-memory capability in the go map
sk.capMap[index] = capability
Expand Down Expand Up @@ -328,13 +342,17 @@ func (sk ScopedKeeper) ClaimCapability(ctx context.Context, cap *types.Capabilit

// Set the forward mapping between the module and capability tuple and the
// capability name in the memKVStore
memStore.Set(types.FwdCapabilityKey(sk.module, cap), []byte(name))
if err := memStore.Set(types.FwdCapabilityKey(sk.module, cap), []byte(name)); err != nil {
panic(err)
}

// Set the reverse mapping between the module and capability name and the
// index in the in-memory store. Since marshalling and unmarshalling into a store
// will change memory address of capability, we simply store index as value here
// and retrieve the in-memory pointer to the capability from our map
memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(cap.GetIndex()))
if err := memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(cap.GetIndex())); err != nil {
panic(err)
}

logger(ctx).Info("claimed capability", "module", sk.module, "name", name, "capability", cap.GetIndex())

Expand All @@ -357,11 +375,15 @@ func (sk ScopedKeeper) ReleaseCapability(ctx context.Context, cap *types.Capabil

// Delete the forward mapping between the module and capability tuple and the
// capability name in the memKVStore
memStore.Delete(types.FwdCapabilityKey(sk.module, cap))
if err := memStore.Delete(types.FwdCapabilityKey(sk.module, cap)); err != nil {
panic(err)
}

// Delete the reverse mapping between the module and capability name and the
// index in the in-memory store.
memStore.Delete(types.RevCapabilityKey(sk.module, name))
if err := memStore.Delete(types.RevCapabilityKey(sk.module, name)); err != nil {
panic(err)
}

// remove owner
capOwners := sk.getOwners(ctx, cap)
Expand Down Expand Up @@ -522,6 +544,6 @@ func (sk ScopedKeeper) getOwners(ctx context.Context, cap *types.Capability) *ty
}

func logger(ctx context.Context) log.Logger {
sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after 52 upgrade
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove after 52 upgrade
return sdkCtx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
2 changes: 1 addition & 1 deletion modules/light-clients/08-wasm/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func NewSimApp(
bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore)

// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[capabilitytypes.StoreKey]), runtime.NewMemStoreService(memKeys[capabilitytypes.MemStoreKey]))

scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
Expand Down
2 changes: 1 addition & 1 deletion testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func NewSimApp(
bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore)

// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[capabilitytypes.StoreKey]), memKeys[capabilitytypes.MemStoreKey])
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[capabilitytypes.StoreKey]), runtime.NewMemStoreService(memKeys[capabilitytypes.MemStoreKey]))

scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
Expand Down

0 comments on commit 9d4ece4

Please sign in to comment.