Skip to content

Commit

Permalink
Add method for fetching emulator version info (ton-blockchain#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
dungeon-master-666 authored Jul 27, 2024
1 parent b3828f8 commit 25386f5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions emulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ else()
add_library(emulator STATIC ${EMULATOR_SOURCE} ${EMULATOR_HEADERS})
endif()

target_link_libraries(emulator PUBLIC emulator_static)
target_link_libraries(emulator PUBLIC emulator_static git)
generate_export_header(emulator EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/emulator_export.h)
target_include_directories(emulator PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
Expand All @@ -48,7 +48,7 @@ if (USE_EMSCRIPTEN)
add_executable(emulator-emscripten ${EMULATOR_EMSCRIPTEN_SOURCE})
target_link_libraries(emulator-emscripten PUBLIC emulator)
target_link_options(emulator-emscripten PRIVATE -sEXPORTED_RUNTIME_METHODS=_malloc,free,UTF8ToString,stringToUTF8,allocate,ALLOC_NORMAL,lengthBytesUTF8)
target_link_options(emulator-emscripten PRIVATE -sEXPORTED_FUNCTIONS=_emulate,_free,_run_get_method,_create_emulator,_destroy_emulator,_emulate_with_emulator)
target_link_options(emulator-emscripten PRIVATE -sEXPORTED_FUNCTIONS=_emulate,_free,_run_get_method,_create_emulator,_destroy_emulator,_emulate_with_emulator,_version)
target_link_options(emulator-emscripten PRIVATE -sEXPORT_NAME=EmulatorModule)
target_link_options(emulator-emscripten PRIVATE -sERROR_ON_UNDEFINED_SYMBOLS=0)
target_link_options(emulator-emscripten PRIVATE -Oz)
Expand Down
4 changes: 4 additions & 0 deletions emulator/emulator-emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,8 @@ const char *run_get_method(const char *params, const char* stack, const char* co
return output;
}

const char *version() {
return emulator_version();
}

}
10 changes: 10 additions & 0 deletions emulator/emulator-extern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "tvm-emulator.hpp"
#include "crypto/vm/stack.hpp"
#include "crypto/vm/memo.h"
#include "git.h"

td::Result<td::Ref<vm::Cell>> boc_b64_to_cell(const char *boc) {
TRY_RESULT_PREFIX(boc_decoded, td::base64_decode(td::Slice(boc)), "Can't decode base64 boc: ");
Expand Down Expand Up @@ -717,3 +718,12 @@ void tvm_emulator_destroy(void *tvm_emulator) {
void emulator_config_destroy(void *config) {
delete static_cast<block::Config *>(config);
}

const char* emulator_version() {
auto version_json = td::JsonBuilder();
auto obj = version_json.enter_object();
obj("emulatorLibCommitHash", GitMetadata::CommitSHA1());
obj("emulatorLibCommitDate", GitMetadata::CommitDate());
obj.leave();
return strdup(version_json.string_builder().as_cslice().c_str());
}
4 changes: 4 additions & 0 deletions emulator/emulator-extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ EMULATOR_EXPORT void tvm_emulator_destroy(void *tvm_emulator);
*/
EMULATOR_EXPORT void emulator_config_destroy(void *config);

/**
* @brief Get git commit hash and date of the library
*/
EMULATOR_EXPORT const char* emulator_version();

#ifdef __cplusplus
} // extern "C"
Expand Down
1 change: 1 addition & 0 deletions emulator/emulator_export_list
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ _tvm_emulator_send_external_message
_tvm_emulator_send_internal_message
_tvm_emulator_destroy
_tvm_emulator_emulate_run_method
_emulator_version

0 comments on commit 25386f5

Please sign in to comment.