diff --git a/contract/contract.go b/contract/contract.go index 73bd3e0b..3dcc562f 100644 --- a/contract/contract.go +++ b/contract/contract.go @@ -87,7 +87,7 @@ var ( type Caller interface { QueryContract(ctx context.Context, from, contract common.Address, abi abi.ABI, method string, res interface{}, args ...interface{}) error - ApplyContract(ctx context.Context, from, contract common.Address, value *big.Int, abi abi.ABI, method string, constructorData ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) + ApplyContract(ctx context.Context, from, contract common.Address, value *big.Int, abi abi.ABI, method string, args ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) ExecuteEVM(ctx sdk.Context, from common.Address, contract *common.Address, value *big.Int, gasLimit uint64, data []byte) (*evmtypes.MsgEthereumTxResponse, error) } diff --git a/precompiles/vm_caller.go b/precompiles/vm_caller.go index 3fa0fcef..a5ec0151 100644 --- a/precompiles/vm_caller.go +++ b/precompiles/vm_caller.go @@ -38,31 +38,28 @@ func (v *VMCall) QueryContract(_ context.Context, from, contract common.Address, return nil } -func (v *VMCall) ApplyContract(_ context.Context, from, contract common.Address, value *big.Int, abi abi.ABI, method string, constructorData ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) { - data, err := abi.Pack(method, constructorData...) +func (v *VMCall) ApplyContract(_ context.Context, from, contract common.Address, value *big.Int, abi abi.ABI, method string, args ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) { + data, err := abi.Pack(method, args...) if err != nil { return nil, types.ErrABIPack.Wrap(err.Error()) } - ret, leftoverGas, vmErr := v.evm.Call(vm.AccountRef(from), contract, data, v.maxGas, value) - var vmError string - if vmErr != nil { - vmError = vmErr.Error() - } - return &evmtypes.MsgEthereumTxResponse{ - GasUsed: v.maxGas - leftoverGas, - VmError: vmError, - Ret: ret, - }, nil + return v.ExecuteEVM(sdk.Context{}, from, &contract, value, v.maxGas, data) } func (v *VMCall) ExecuteEVM(_ sdk.Context, from common.Address, contract *common.Address, value *big.Int, gasLimit uint64, data []byte) (*evmtypes.MsgEthereumTxResponse, error) { + if value == nil { + value = big.NewInt(0) + } + if contract == nil { + contract = &common.Address{} + } ret, leftoverGas, vmErr := v.evm.Call(vm.AccountRef(from), *contract, data, gasLimit, value) var vmError string if vmErr != nil { vmError = vmErr.Error() } return &evmtypes.MsgEthereumTxResponse{ - GasUsed: v.maxGas - leftoverGas, + GasUsed: gasLimit - leftoverGas, VmError: vmError, Ret: ret, }, nil diff --git a/x/evm/keeper/contract_code.go b/x/evm/keeper/contract_code.go index cc8472f8..8529e6a3 100644 --- a/x/evm/keeper/contract_code.go +++ b/x/evm/keeper/contract_code.go @@ -127,8 +127,8 @@ func (k *Keeper) QueryContract(ctx context.Context, from, contract common.Addres } // ApplyContract apply contract with args -func (k *Keeper) ApplyContract(ctx context.Context, from, contract common.Address, value *big.Int, abi abi.ABI, method string, constructorData ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) { - args, err := abi.Pack(method, constructorData...) +func (k *Keeper) ApplyContract(ctx context.Context, from, contract common.Address, value *big.Int, abi abi.ABI, method string, args ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) { + data, err := abi.Pack(method, args...) if err != nil { return nil, types.ErrABIPack.Wrap(err.Error()) } @@ -136,7 +136,7 @@ func (k *Keeper) ApplyContract(ctx context.Context, from, contract common.Addres if err != nil { return nil, err } - resp, err := k.callEvm(sdk.UnwrapSDKContext(ctx), from, &contract, value, nonce, args, true) + resp, err := k.callEvm(sdk.UnwrapSDKContext(ctx), from, &contract, value, nonce, data, true) if err != nil { return nil, err }