Skip to content

Commit

Permalink
chore(lint): placate the linting overlords
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Apr 1, 2024
1 parent 63d7f73 commit b39b788
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
24 changes: 17 additions & 7 deletions x/assets/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,34 @@ import (

// InitGenesis initializes the module's state from a provided genesis state.
func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
k.SetParams(ctx, &data.Params)
if err := k.SetParams(ctx, &data.Params); err != nil {
panic(err)
}
// client_chain.go
for _, info := range data.ClientChains {
k.SetClientChainInfo(ctx, &info)
for _, infoCopy := range data.ClientChains {
info := infoCopy // prevent implicit memory aliasing
if err := k.SetClientChainInfo(ctx, &info); err != nil {
panic(err)
}
}
// client_chain_asset.go
for _, info := range data.Tokens {
k.SetStakingAssetInfo(ctx, &info)
for _, infoCopy := range data.Tokens {
info := infoCopy // prevent implicit memory aliasing
if err := k.SetStakingAssetInfo(ctx, &info); err != nil {
panic(err)
}
}
// operator_asset.go
for _, level1 := range data.OperatorAssetInfos {
// we have validated previously that the address is
// the bech32 encoded address of sdk.AccAddress
addr := level1.OperatorAddress
for _, info := range level1.AssetIdAndInfos {
k.SetOperatorAssetInfo(
if err := k.SetOperatorAssetInfo(
ctx, addr, info.AssetID, info.Info,
)
); err != nil {
panic(err)
}
}
}
// staker_asset.go
Expand Down
3 changes: 3 additions & 0 deletions x/assets/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ func areMapsIdentical(m1, m2 map[string]math.Int) bool {
return false
}

// this code is not consensus critical, so we can loop.
// the codeQL warning can be ignored.
// nolint:gosec

Check failure on line 285 in x/assets/types/genesis.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

directive `// nolint:gosec` is unused for linter "gosec" (nolintlint)
for k1, v1 := range m1 {
v2, ok := m2[k1]
if !ok || !v1.Equal(v2) {
Expand Down
2 changes: 1 addition & 1 deletion x/delegation/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (k Keeper) InitGenesis(
assetID := b.AssetID
for _, c := range b.DelegationsByOperator {
operatorAddress := c.OperatorAddress
// already validated in genState.Validate()
// #nosec G703 // already validated
accAddress, _ := sdk.AccAddressFromBech32(operatorAddress)
amount := c.Amount
if !k.operatorKeeper.IsOperator(ctx, accAddress) {
Expand Down
2 changes: 1 addition & 1 deletion x/dogfood/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (k Keeper) InitGenesis(
}
out := make([]abci.ValidatorUpdate, len(genState.InitialValSet))
for _, val := range genState.InitialValSet {
// already validated
// #nosec G703 // already validated
consKey, _ := operatortypes.HexStringToPubKey(val.PublicKey)
out = append(out, abci.ValidatorUpdate{
PubKey: *consKey,
Expand Down
9 changes: 5 additions & 4 deletions x/operator/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (

func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) []abci.ValidatorUpdate {
// operators.go
for _, info := range state.Operators {
for _, infoCopy := range state.Operators {
info := infoCopy // prevent implicit memory aliasing
if err := k.SetOperatorInfo(ctx, info.EarningsAddr, &info); err != nil {
panic(err)
}
operatorAddress := info.EarningsAddr
// already validated during state.Validate()
// #nosec G703 // already validated
operatorAccAddress, _ := sdk.AccAddressFromBech32(operatorAddress)
if err := k.OptIn(ctx, operatorAccAddress, ctx.ChainID()); err != nil {
panic(err)
Expand All @@ -22,11 +23,11 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) []abci.Va
// consensus_keys.go
for _, record := range state.OperatorRecords {
operatorAddress := record.OperatorAddress
// already validated during state.Validate()
// #nosec G703 // already validated
operatorAccAddress, _ := sdk.AccAddressFromBech32(operatorAddress)
for _, subRecord := range record.Chains {
consKeyBytes32 := subRecord.ConsensusKey
// already validated
// #nosec G703 // already validated
consKey, _ := types.HexStringToPubKey(consKeyBytes32)
if err := k.SetOperatorConsKeyForChainID(
ctx, operatorAccAddress, subRecord.ChainID, consKey,
Expand Down

0 comments on commit b39b788

Please sign in to comment.