mirror of https://github.com/status-im/evmc.git
EVM-C: get rid of evm_bytes_view type
This commit is contained in:
parent
8684f22c43
commit
d26635abc2
|
@ -23,14 +23,14 @@ void example() {
|
||||||
struct evm_instance* jit = evm_create(query, 0, 0);
|
struct evm_instance* jit = evm_create(query, 0, 0);
|
||||||
|
|
||||||
char const code[] = "exec()";
|
char const code[] = "exec()";
|
||||||
struct evm_bytes_view code_view = {code, sizeof(code)};
|
|
||||||
struct evm_hash256 code_hash = {.words = {1, 2, 3}};
|
struct evm_hash256 code_hash = {.words = {1, 2, 3}};
|
||||||
struct evm_bytes_view input = {"Hello World!", 12};
|
char const input[] = "Hello World!";
|
||||||
struct evm_uint256 value = {{1, 0, 0, 0}};
|
struct evm_uint256 value = {{1, 0, 0, 0}};
|
||||||
|
|
||||||
int64_t gas = 200000;
|
int64_t gas = 200000;
|
||||||
struct evm_result result =
|
struct evm_result result =
|
||||||
evm_execute(jit, NULL, code_hash, code_view, gas, input, value);
|
evm_execute(jit, NULL, code_hash, code, sizeof(code), gas, input,
|
||||||
|
sizeof(input), value);
|
||||||
|
|
||||||
evm_destroy_result(result);
|
evm_destroy_result(result);
|
||||||
evm_destroy(jit);
|
evm_destroy(jit);
|
||||||
|
|
|
@ -53,12 +53,6 @@ struct evm_hash256 {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Reference to non-mutable memory.
|
|
||||||
struct evm_bytes_view {
|
|
||||||
char const* bytes; ///< Pointer the begining of the memory.
|
|
||||||
size_t size; ///< The memory size.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#define EVM_EXCEPTION INT64_MIN ///< The execution ended with an exception.
|
#define EVM_EXCEPTION INT64_MIN ///< The execution ended with an exception.
|
||||||
|
|
||||||
|
@ -69,7 +63,10 @@ struct evm_result {
|
||||||
|
|
||||||
/// Rerefence to output data. The memory containing the output data
|
/// Rerefence to output data. The memory containing the output data
|
||||||
/// is owned by EVM and is freed with evm_destroy_result().
|
/// is owned by EVM and is freed with evm_destroy_result().
|
||||||
struct evm_bytes_view output_data;
|
char const* output_data;
|
||||||
|
|
||||||
|
/// Size of the output data.
|
||||||
|
size_t output_size;
|
||||||
|
|
||||||
/// Pointer to EVM-owned memory.
|
/// Pointer to EVM-owned memory.
|
||||||
/// @see output_data.
|
/// @see output_data.
|
||||||
|
@ -125,7 +122,13 @@ union evm_variant {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A memory reference.
|
/// A memory reference.
|
||||||
struct evm_bytes_view bytes;
|
struct {
|
||||||
|
/// Pointer to the data.
|
||||||
|
char const* data;
|
||||||
|
|
||||||
|
/// Size of the referenced memory/data.
|
||||||
|
size_t data_size;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Query callback function.
|
/// Query callback function.
|
||||||
|
@ -190,11 +193,14 @@ enum evm_call_kind {
|
||||||
/// of CREATE.
|
/// of CREATE.
|
||||||
/// @param value The value sent to the callee. The endowment in case of
|
/// @param value The value sent to the callee. The endowment in case of
|
||||||
/// CREATE.
|
/// CREATE.
|
||||||
/// @param input_data The call input data or the create init code.
|
/// @param input The call input data or the create init code.
|
||||||
/// @param output_data The reference to the memory where the call output is to
|
/// @param input_size The size of the input data.
|
||||||
|
/// @param output The reference to the memory where the call output is to
|
||||||
/// be copied. In case of create, the memory is guaranteed
|
/// be copied. In case of create, the memory is guaranteed
|
||||||
/// to be at least 160 bytes to hold the address of the
|
/// to be at least 160 bytes to hold the address of the
|
||||||
/// created contract.
|
/// created contract.
|
||||||
|
/// @param output_data The size of the output data. In case of create, expected
|
||||||
|
/// value is 160.
|
||||||
/// @return If non-negative - the amount of gas left,
|
/// @return If non-negative - the amount of gas left,
|
||||||
/// If negative - an exception occurred during the call/create.
|
/// If negative - an exception occurred during the call/create.
|
||||||
/// There is no need to set 0 address in the output in this case.
|
/// There is no need to set 0 address in the output in this case.
|
||||||
|
@ -204,10 +210,10 @@ typedef int64_t (*evm_call_fn)(
|
||||||
int64_t gas,
|
int64_t gas,
|
||||||
struct evm_hash160 address,
|
struct evm_hash160 address,
|
||||||
struct evm_uint256 value,
|
struct evm_uint256 value,
|
||||||
char const* input_data,
|
char const* input,
|
||||||
size_t input_size,
|
size_t input_size,
|
||||||
char* output_data,
|
char* output,
|
||||||
size_t output_size);
|
size_t output_size);
|
||||||
|
|
||||||
|
|
||||||
/// A piece of information about the EVM implementation.
|
/// A piece of information about the EVM implementation.
|
||||||
|
@ -275,16 +281,20 @@ bool evm_set_option(struct evm_instance* evm,
|
||||||
/// hash the code itself if it requires it, but the host
|
/// hash the code itself if it requires it, but the host
|
||||||
/// application usually has the hash already.
|
/// application usually has the hash already.
|
||||||
/// @param code Reference to the bytecode to be executed.
|
/// @param code Reference to the bytecode to be executed.
|
||||||
|
/// @param code_size The length of the bytecode.
|
||||||
/// @param gas Gas for execution. Min 0, max 2^63-1.
|
/// @param gas Gas for execution. Min 0, max 2^63-1.
|
||||||
/// @param input_data Reference to the call input data.
|
/// @param input Reference to the input data.
|
||||||
|
/// @param input_size The size of the input data.
|
||||||
/// @param value Call value.
|
/// @param value Call value.
|
||||||
/// @return All execution results.
|
/// @return All execution results.
|
||||||
struct evm_result evm_execute(struct evm_instance* instance,
|
struct evm_result evm_execute(struct evm_instance* instance,
|
||||||
struct evm_env* env,
|
struct evm_env* env,
|
||||||
struct evm_hash256 code_hash,
|
struct evm_hash256 code_hash,
|
||||||
struct evm_bytes_view code,
|
char const* code,
|
||||||
|
size_t code_size,
|
||||||
int64_t gas,
|
int64_t gas,
|
||||||
struct evm_bytes_view input_data,
|
char const* input,
|
||||||
|
size_t input_size,
|
||||||
struct evm_uint256 value);
|
struct evm_uint256 value);
|
||||||
|
|
||||||
/// Destroys execution result.
|
/// Destroys execution result.
|
||||||
|
|
Loading…
Reference in New Issue