forked from ethereum/evmone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereum#116 from ethereum/host-example
Host example
- Loading branch information
Showing
13 changed files
with
159 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
# EVMC: Ethereum Client-VM Connector API. | ||
# Copyright 2018 The EVMC Authors. | ||
# Licensed under the Apache License, Version 2.0. See the LICENSE file. | ||
|
||
add_subdirectory(examplevm) | ||
include(GNUInstallDirs) | ||
|
||
add_executable(example-capi capi.c) | ||
target_link_libraries(example-capi PRIVATE evmc evmc-examplevm) | ||
if(NOT MSVC) | ||
target_compile_options(example-capi PRIVATE -Wno-extra) | ||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
endif() | ||
set(CMAKE_DEBUG_POSTFIX "") | ||
|
||
|
||
add_library(evmc-example-host STATIC example_host.cpp) | ||
target_link_libraries(evmc-example-host PRIVATE evmc) | ||
|
||
|
||
add_library(evmc-example-vm example_vm.c) | ||
target_link_libraries(evmc-example-vm PRIVATE evmc) | ||
set_source_files_properties(example_vm.c PROPERTIES COMPILE_DEFINITIONS PROJECT_VERSION=${PROJECT_VERSION}) | ||
|
||
|
||
add_executable(evmc-example example.c) | ||
target_link_libraries(evmc-example PRIVATE evmc-example-host evmc-example-vm evmc) | ||
|
||
|
||
install(TARGETS evmc-example-vm | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* EVMC: Ethereum Client-VM Connector API. | ||
* Copyright 2018 The EVMC Authors. | ||
* Licensed under the Apache License, Version 2.0. See the LICENSE file. | ||
*/ | ||
|
||
#include "example_host.h" | ||
#include "example_vm.h" | ||
|
||
#include <evmc/helpers.h> | ||
|
||
#include <inttypes.h> | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
struct evmc_instance* vm = evmc_create_example_vm(); | ||
if (!evmc_is_abi_compatible(vm)) | ||
return 1; | ||
// EVM bytecode goes here. This is one of the examples. | ||
const uint8_t code[] = "\x30\x60\x00\x52\x59\x60\x00\xf3"; | ||
const size_t code_size = sizeof(code); | ||
const struct evmc_uint256be code_hash = {.bytes = {1, 2, 3}}; | ||
const uint8_t input[] = "Hello World!"; | ||
const struct evmc_uint256be value = {{1, 0}}; | ||
const struct evmc_address addr = {{0, 1, 2}}; | ||
const int64_t gas = 200000; | ||
struct evmc_context* ctx = example_host_create_context(); | ||
struct evmc_message msg; | ||
msg.sender = addr; | ||
msg.destination = addr; | ||
msg.value = value; | ||
msg.input_data = input; | ||
msg.input_size = sizeof(input); | ||
msg.code_hash = code_hash; | ||
msg.gas = gas; | ||
msg.depth = 0; | ||
struct evmc_result result = evmc_execute(vm, ctx, EVMC_HOMESTEAD, &msg, code, code_size); | ||
printf("Execution result:\n"); | ||
if (result.status_code != EVMC_SUCCESS) | ||
{ | ||
printf(" EVM execution failure: %d\n", result.status_code); | ||
} | ||
else | ||
{ | ||
printf(" Gas used: %" PRId64 "\n", gas - result.gas_left); | ||
printf(" Gas left: %" PRId64 "\n", result.gas_left); | ||
printf(" Output size: %zd\n", result.output_size); | ||
printf(" Output: "); | ||
size_t i = 0; | ||
for (i = 0; i < result.output_size; i++) | ||
printf("%02x ", result.output_data[i]); | ||
printf("\n"); | ||
} | ||
evmc_release_result(&result); | ||
example_host_destroy_context(ctx); | ||
evmc_destroy(vm); | ||
return 0; | ||
} |
Oops, something went wrong.