@@ -15,14 +15,12 @@ import (
1515 sdk "github.com/cosmos/cosmos-sdk/types"
1616)
1717
18- // NativeExecutor abstract the native execution logic of the stateful precompile, it's passed to the base `Precompile`
18+ // NativeAction abstract the native execution logic of the stateful precompile, it's passed to the base `Precompile`
1919// struct, base `Precompile` struct will handle things the native context setup, gas management, panic recovery etc,
2020// before and after the execution.
2121//
2222// It's usually implemented by the precompile itself.
23- type NativeExecutor interface {
24- Execute (ctx sdk.Context , stateDB vm.StateDB , contract * vm.Contract , readOnly bool ) ([]byte , error )
25- }
23+ type NativeAction func (ctx sdk.Context ) ([]byte , error )
2624
2725// Precompile is the base struct for precompiles that requires to access cosmos native storage.
2826type Precompile struct {
@@ -32,8 +30,6 @@ type Precompile struct {
3230
3331 // BalanceHandler is optional
3432 BalanceHandler * BalanceHandler
35-
36- Executor NativeExecutor
3733}
3834
3935// RequiredGas calculates the base minimum required gas for a transaction or a query.
@@ -49,16 +45,16 @@ func (p Precompile) RequiredGas(input []byte, isTransaction bool) uint64 {
4945
5046// Run prepare the native context to execute native action for stateful precompile,
5147// it manages the snapshot and revert of the multi-store.
52- func (p Precompile ) Run (evm * vm.EVM , contract * vm.Contract , readOnly bool ) ([]byte , error ) {
53- bz , err := p .run (evm , contract , readOnly )
48+ func (p Precompile ) RunNativeAction (evm * vm.EVM , contract * vm.Contract , action NativeAction ) ([]byte , error ) {
49+ bz , err := p .runNativeAction (evm , contract , action )
5450 if err != nil {
5551 return ReturnRevertError (evm , err )
5652 }
5753
5854 return bz , nil
5955}
6056
61- func (p Precompile ) run (evm * vm.EVM , contract * vm.Contract , readOnly bool ) (bz []byte , err error ) {
57+ func (p Precompile ) runNativeAction (evm * vm.EVM , contract * vm.Contract , action NativeAction ) (bz []byte , err error ) {
6258 stateDB , ok := evm .StateDB .(* statedb.StateDB )
6359 if ! ok {
6460 return nil , errors .New (ErrNotRunInEvm )
@@ -104,7 +100,7 @@ func (p Precompile) run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [
104100 p .BalanceHandler .BeforeBalanceChange (ctx )
105101 }
106102
107- bz , err = p . Executor . Execute (ctx , stateDB , contract , readOnly )
103+ bz , err = action (ctx )
108104 if err != nil {
109105 return bz , err
110106 }
0 commit comments