Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set precompiles after keeper creation #101

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,11 @@ func (k Keeper) AddTransientGasUsed(ctx sdk.Context, gasUsed uint64) (uint64, er
k.SetTransientGasUsed(ctx, result)
return result, nil
}

// ----------------------------------------------------------------------------
// Stateful Precompiled Contracts section
// ----------------------------------------------------------------------------

func (k *Keeper) WithStatefulPrecompiledContracts(contracts []CustomContractFn) {
k.customContractFns = contracts
}
Comment on lines +418 to +420
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor the method for better readability and safety.

Consider applying the following refactors:

  1. Rename the method to SetStatefulPrecompiledContracts to clearly indicate that it's a setter method.
  2. Return the Keeper instance to allow method chaining, which can lead to more concise and readable code.
  3. Add a nil check for the contracts argument to prevent setting a nil slice and to improve the method's defensive programming.

Here's the updated method with the suggested changes:

func (k *Keeper) SetStatefulPrecompiledContracts(contracts []CustomContractFn) *Keeper {
    if contracts == nil {
        panic("contracts cannot be nil")
    }
    k.customContractFns = contracts
    return k
}

Loading