Skip to content

Commit

Permalink
add call from precompile (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
minghinmatthewlam authored Dec 1, 2022
1 parent 5faabfe commit 2a9569a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/stateful_precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (m *mockAccessibleState) GetBlockContext() precompile.BlockContext { return

func (m *mockAccessibleState) GetSnowContext() *snow.Context { return m.snowContext }

func (m *mockAccessibleState) CallFromPrecompile(caller common.Address, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error) {
return nil, 0, nil
}

// This test is added within the core package so that it can import all of the required code
// without creating any import cycles
func TestContractDeployerAllowListRun(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
return ret, gas, err
}

// CallFromPrecompile invokes Call to execute the contract with the given input parameters.
func (evm *EVM) CallFromPrecompile(caller common.Address, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error) {
return evm.Call(AccountRef(caller), addr, input, gas, value)
}

// CallCode executes the contract associated with the addr with the given input
// as parameters. It also handles any necessary value transfer required and takes
// the necessary steps to create accounts and reverses the state in case of an
Expand Down
1 change: 1 addition & 0 deletions precompile/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type PrecompileAccessibleState interface {
GetStateDB() StateDB
GetBlockContext() BlockContext
GetSnowContext() *snow.Context
CallFromPrecompile(caller common.Address, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error)
}

// BlockContext defines an interface that provides information to a stateful precompile
Expand Down

0 comments on commit 2a9569a

Please sign in to comment.