### Define Installation Component Arguments (CMake) Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Sets up arguments for CMake's install command, specifically defining a component for installation. This allows users to selectively install parts of the project, controlled by the 'ABIEOS_INSTALL_COMPONENT' variable. ```cmake if(ABIEOS_INSTALL_COMPONENT) set(INSTALL_COMPONENT_ARGS COMPONENT ${ABIEOS_INSTALL_COMPONENT} EXCLUDE_FROM_ALL) endif() ``` -------------------------------- ### Install Abieos Library Targets (CMake) Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Installs the compiled Abieos library artifacts (e.g., static or shared libraries) to the system's library directory. It also installs the CMake export files necessary for other projects to find and link against the Abieos library. Installation can be filtered by component. ```cmake install(TARGETS abieos EXPORT abieos INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${INSTALL_COMPONENT_ARGS} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ${INSTALL_COMPONENT_ARGS} ) ``` -------------------------------- ### Install Abieos Config File (CMake) Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Installs the generated Abieos CMake configuration file to the system's share directory. This makes the Abieos library available for use in other CMake projects through the `find_package` command. Installation can be filtered by component. ```cmake install(FILES ${CMAKE_CURRENT_BINARY_DIR}/share/abieos/abieos-config.cmake DESTINATION "share/abieos" ${INSTALL_COMPONENT_ARGS}) ``` -------------------------------- ### Install Abieos Headers (CMake) Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Installs the header files for the Abieos library into the system's include directory. It ensures that external projects can easily link against the Abieos library by providing access to its public API. Installation can be filtered by component. ```cmake install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio DESTINATION include ${INSTALL_COMPONENT_ARGS}) ``` -------------------------------- ### Install Abieos CMake Export File (CMake) Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Installs the CMake target export file for the Abieos library. This file enables CMake's find_package mechanism, allowing other CMake projects to easily discover and use the Abieos library. Installation can be filtered by component. ```cmake install(EXPORT abieos DESTINATION "share/abieos" FILE abieos-targets.cmake ${INSTALL_COMPONENT_ARGS} ) ``` -------------------------------- ### Create Static Library with Include Directories (CMake) Source: https://github.com/antelopeio/abieos/blob/main/tools/CMakeLists.txt This code defines a static library 'abieos_util' from multiple source files. It also configures public include directories, specifying paths relative to the build and install configurations. This is crucial for managing header files and dependencies. ```cmake add_library(abieos_util STATIC ../src/abieos.cpp ../src/abi.cpp ../src/crypto.cpp) target_include_directories(abieos_util PUBLIC "$/../src" "$/../include" "$/../external/rapidjson/include" "$") ``` -------------------------------- ### Find Packages and Include Directories - CMake Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Finds the 'Threads' package and includes GNUInstallDirs. It also sets up public include directories for the 'abieos' static library, including build-time and installation paths. ```cmake find_package(Threads) include(GNUInstallDirs) add_library(abieos STATIC src/abi.cpp src/crypto.cpp) target_include_directories(abieos PUBLIC "$/include" "$/external/rapidjson/include" "$") if(ABIEOS_NO_INT128) target_compile_definitions(abieos PUBLIC ABIEOS_NO_INT128) endif() ``` -------------------------------- ### Get Table Type Name from ABI (C) Source: https://context7.com/antelopeio/abieos/llms.txt Retrieves the Antelope type name associated with a specific table for a given contract. Requires the contract's ABI to be loaded. ```c abieos_context* ctx = abieos_create(); uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); abieos_set_abi(ctx, contract, token_abi_json); uint64_t table = abieos_string_to_name(ctx, "accounts"); const char* table_type = abieos_get_type_for_table(ctx, contract, table); if (table_type) { printf("Table type: %s\n", table_type); // "account" } else { fprintf(stderr, "Error: %s\n", abieos_get_error(ctx)); } abieos_destroy(ctx); ``` -------------------------------- ### Get Action Type Name from ABI (C) Source: https://context7.com/antelopeio/abieos/llms.txt Retrieves the Antelope type name associated with a specific action for a given contract. Requires the contract's ABI to be loaded. ```c abieos_context* ctx = abieos_create(); uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); abieos_set_abi(ctx, contract, token_abi_json); uint64_t action = abieos_string_to_name(ctx, "transfer"); const char* action_type = abieos_get_type_for_action(ctx, contract, action); if (action_type) { printf("Action type: %s\n", action_type); // "transfer" } else { fprintf(stderr, "Error: %s\n", abieos_get_error(ctx)); } abieos_destroy(ctx); ``` -------------------------------- ### Build and Test Abieos using CMake Source: https://github.com/antelopeio/abieos/blob/main/README.md This shell script outlines the process for building and testing the abieos library. It involves creating a build directory, navigating into it, configuring the build with CMake, compiling the project, and running tests. ```shell mkdir build cd build cmake .. make ctest ``` -------------------------------- ### Create, Set ABI, and Convert Transaction Data to Binary Hex using Abieos Source: https://github.com/antelopeio/abieos/blob/main/README.md This C code demonstrates how to pack transactions using the abieos library. It involves creating a context, loading ABIs for contracts, converting JSON action and transaction data into binary hex format, and finally destroying the context. Ensure the ABI files are correctly specified and accessible. ```c void* context = abieos_create(); // Load eosjs2/src/transaction.abi into contract 0 abieos_set_abi(context, 0, "eosjs2/src/transaction.abi"); // Load the contract's ABI (replace with actual contract ABI path) abieos_set_abi(context, contract_id, "path/to/contract.abi"); // Convert action data to hex char* action_type = abieos_get_type_for_action(context, contract_id, "action_name"); char* action_hex = abieos_json_to_bin(context, contract_id, action_type, "{\"from\": \"useraaaaaaaa\", \"to\": \"useraaaaaaab\", \"quantity\": \"0.0001 SYS\", \"memo\": \"\"}"); char* action_hex_string = abieos_get_bin_hex(context, action_hex); // Convert transaction to hex char* transaction_type = abieos_string_to_name(context, "transaction"); char* transaction_hex = abieos_json_to_bin(context, 0, transaction_type, "{\"expiration\": \"2018-06-27T20:33:54.000\", \"ref_block_num\": 45323, \"ref_block_prefix\": 2628749070, \"max_net_usage_words\": 0, \"max_cpu_usage_ms\": 0, \"delay_sec\": 0, \"context_free_actions\": [], \"actions\": [{\"account\": \"eosio.token\", \"name\": \"transfer\", \"authorization\":[{\"actor\": \"useraaaaaaaa\", \"permission\": \"active\"}], \"data\": \"608C31C6187315D6708C31C6187315D60100000000000000045359530000000000\"}], \"transaction_extensions\":[]}"); char* transaction_hex_string = abieos_get_bin_hex(context, transaction_hex); abieos_destroy(context); ``` -------------------------------- ### Configure Testing - CMake Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Enables testing and defines multiple test executables ('test_abieos', 'test_abieos_template', 'test_abieos_key', 'test_abieos_reflect'). Each executable is linked against the 'abieos' library and Pthreads where applicable. ```cmake enable_testing() add_executable(test_abieos src/test.cpp src/abieos.cpp src/ship.abi.cpp) target_link_libraries(test_abieos abieos ${CMAKE_THREAD_LIBS_INIT}) add_test(NAME test_abieos COMMAND test_abieos) if(NOT ABIEOS_NO_INT128) add_executable(test_abieos_template src/template_test.cpp src/abieos.cpp) target_link_libraries(test_abieos_template abieos ${CMAKE_THREAD_LIBS_INIT}) add_test(NAME test_abieos_template COMMAND test_abieos_template) endif() add_executable(test_abieos_key src/key_test.cpp src/abieos.cpp) target_link_libraries(test_abieos_key abieos ${CMAKE_THREAD_LIBS_INIT}) add_test(NAME test_abieos_key COMMAND test_abieos_key) add_executable(test_abieos_reflect src/reflect_test.cpp) target_include_directories(test_abieos_reflect PRIVATE include) add_test(NAME test_abieos_reflect COMMAND test_abieos_reflect) ``` -------------------------------- ### Build JSON Utility Executables (CMake) Source: https://github.com/antelopeio/abieos/blob/main/tools/CMakeLists.txt These snippets show how to create two executable targets, 'generate_hex_from_json' and 'generate_json_from_hex', each linked against the 'abieos_util' library and the thread library. This pattern is typical for building utility tools that leverage a common library. ```cmake add_executable(generate_hex_from_json util_generate_hex_from_json.cpp) target_link_libraries(generate_hex_from_json abieos_util ${CMAKE_THREAD_LIBS_INIT}) add_executable(generate_json_from_hex util_generate_json_from_hex.cpp) target_link_libraries(generate_json_from_hex abieos_util ${CMAKE_THREAD_LIBS_INIT}) ``` -------------------------------- ### Define Executable and Link Libraries (CMake) Source: https://github.com/antelopeio/abieos/blob/main/tools/CMakeLists.txt This snippet demonstrates how to define an executable target and link it against the 'abieos' library and the initialized thread library. It's a common pattern for building applications that depend on specific libraries. ```cmake find_package(Threads) add_executable(name name.cpp) target_link_libraries(name abieos ${CMAKE_THREAD_LIBS_INIT}) ``` -------------------------------- ### Add Custom Post-Build Commands (CMake) Source: https://github.com/antelopeio/abieos/blob/main/tools/CMakeLists.txt This CMake code defines custom commands to be executed after the 'name' target is built. It uses `create_symlink` to create symbolic links named 'name2num' and 'num2name' pointing to the built executable. This is useful for creating aliases or alternative entry points. ```cmake add_custom_command( TARGET name POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink $ ${CMAKE_CURRENT_BINARY_DIR}/name2num ) add_custom_command( TARGET name POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink $ ${CMAKE_CURRENT_BINARY_DIR}/num2name ) ``` -------------------------------- ### Create and Destroy abieos Context (C) Source: https://context7.com/antelopeio/abieos/llms.txt Initializes and cleans up the abieos context, which is required for all library operations. Handles potential context creation failures and retrieves error messages. ```c #include "abieos.h" // Create context for all operations abieos_context* ctx = abieos_create(); if (!ctx) { fprintf(stderr, "Failed to create context\n"); return 1; } // Perform operations... const char* error = abieos_get_error(ctx); if (error && strlen(error) > 0) { fprintf(stderr, "Error: %s\n", error); } // Clean up abieos_destroy(ctx); ``` -------------------------------- ### Create Module Library and Link Dependencies - CMake Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Defines a 'abieos_module' library and sets its include directories. It also links the Pthreads library and sets the output name to 'abieos'. ```cmake add_library(abieos_module MODULE src/abieos.cpp src/abi.cpp src/crypto.cpp) target_include_directories(abieos_module PUBLIC "$/include;" "$/external/rapidjson/include" "$") target_link_libraries(abieos_module ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(abieos_module PROPERTIES OUTPUT_NAME "abieos") ``` -------------------------------- ### Configure Project and Build Type - CMake Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Sets the minimum CMake version, project name and version, and configures the default build type if none is specified. It also enforces C++17 standard compliance. ```cmake cmake_minimum_required (VERSION 3.16...4.0) project(abieos VERSION 0.1 LANGUAGES CXX C) set(default_build_type "Release") if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to '${default_build_type}' as none was specified.") set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) ``` -------------------------------- ### Define Custom Struct and Use with ABI (C++) Source: https://context7.com/antelopeio/abieos/llms.txt Demonstrates how to define a custom data structure using C++ with EOSIO reflection and then serialize/deserialize it using the Abieos C++ API. It includes defining a struct, reflecting its members, creating an ABI, and performing binary conversions. ```cpp #include "eosio/abi.hpp" #include "eosio/reflection.hpp" namespace my_contract { struct transfer { eosio::name from; eosio::name to; eosio::asset quantity; std::string memo; }; EOSIO_REFLECT(transfer, from, to, quantity, memo) } // Create ABI and add custom type eosio::abi abi; abi.add_type(); // Serialize to binary my_contract::transfer t{ eosio::name{"useraaaaaaaa"}, eosio::name{"useraaaaaaab"}, eosio::asset{1, eosio::symbol{"SYS", 4}}, "" }; std::vector bin; eosio::vector_stream stream{bin}; eosio::to_bin(t, stream); // Deserialize from binary eosio::input_stream input{bin.data(), bin.size()}; my_contract::transfer t2; eosio::from_bin(t2, input); ``` -------------------------------- ### Load ABI from Binary Format (C) Source: https://context7.com/antelopeio/abieos/llms.txt Loads an Antelope contract's ABI definition from raw binary data into the abieos context. This is efficient for loading ABIs directly from files or network streams. ```c abieos_context* ctx = abieos_create(); // Binary ABI data (from file or network) const char* abi_bin_data = /* binary data */; size_t abi_bin_size = /* size of binary data */; uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); if (!abieos_set_abi_bin(ctx, contract, abi_bin_data, abi_bin_size)) { fprintf(stderr, "Failed to load binary ABI: %s\n", abieos_get_error(ctx)); abieos_destroy(ctx); return 1; } abieos_destroy(ctx); ``` -------------------------------- ### Configure Abieos Config File (CMake) Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Copies the Abieos CMake configuration file template to the build directory. This file is later used to provide package information to consumers of the Abieos library via `find_package`. ```cmake configure_file(abieos-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/share/abieos/abieos-config.cmake COPYONLY) ``` -------------------------------- ### Context Management API Source: https://context7.com/antelopeio/abieos/llms.txt Manage the abieos context, which is required for all operations. This includes creating a new context and destroying it after use. ```APIDOC ## Context Management API ### Description Manages the abieos context, which is necessary for all library operations. This includes creating a new context and cleaning it up when done. ### Create Context ```c abieos_context* ctx = abieos_create(); if (!ctx) { fprintf(stderr, "Failed to create context\n"); return 1; } ``` ### Get Error Message ```c const char* error = abieos_get_error(ctx); if (error && strlen(error) > 0) { fprintf(stderr, "Error: %s\n", error); } ``` ### Destroy Context ```c abieos_destroy(ctx); ``` ``` -------------------------------- ### Convert Between JSON and Binary using C++ API Source: https://context7.com/antelopeio/abieos/llms.txt Illustrates converting data between JSON and binary formats using the Abieos C++ API. This involves creating an ABI object, obtaining a specific type, and then using its methods to perform JSON-to-binary and binary-to-JSON conversions. ```cpp #include "abieos.hpp" // Create ABI from definition eosio::abi_def def; // ... populate def ... abieos::abi abi; abieos::convert(def, abi); // Get type for conversion const eosio::abi_type* type = abi.get_type("transfer"); // JSON to binary std::string json = R"({\"from\":\"useraaaaaaaa\",\"to\":\"useraaaaaaab\",\"quantity\":\"0.0001 SYS\",\"memo\":\"\"})"; std::vector bin = type->json_to_bin(json); // Binary to JSON eosio::input_stream bin_stream{bin.data(), bin.size()}; std::string result_json = type->bin_to_json(bin_stream); ``` -------------------------------- ### Define Build Options - CMake Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Defines CMake options to control build features, specifically disabling 128-bit integer support and opting to build only the library. ```cmake option(ABIEOS_NO_INT128 "disable use of __int128" OFF) option(ABIEOS_ONLY_LIBRARY "define and build the ABIEOS library" OFF) ``` -------------------------------- ### Convert Between String and uint64 Name (C) Source: https://context7.com/antelopeio/abieos/llms.txt Converts Antelope account names between their string representation and uint64 integer format. Requires an initialized abieos context. ```c abieos_context* ctx = abieos_create(); // String to name const char* account_str = "eosio.token"; uint64_t account_name = abieos_string_to_name(ctx, account_str); // account_name = 6138663577826885632 // Name to string const char* decoded = abieos_name_to_string(ctx, account_name); // decoded = "eosio.token" abieos_destroy(ctx); ``` -------------------------------- ### ABI Management API Source: https://context7.com/antelopeio/abieos/llms.txt Load Application Binary Interface (ABI) definitions for contracts into the abieos context. ABIs can be loaded from JSON, hex-encoded binary, or raw binary data. ```APIDOC ## ABI Management API ### Description Allows loading Application Binary Interface (ABI) definitions for Antelope contracts. ABIs are crucial for correctly serializing and deserializing action data and table rows. ABIs can be provided in JSON, hex-encoded binary, or raw binary formats. ### Load ABI from JSON ```c abieos_context* ctx = abieos_create(); const char* token_abi_json = "{\"version\":\"eosio::abi/1.0\",\"structs\":[{\"name\":\"transfer\",\"fields\":[{\"name\":\"from\",\"type\":\"name\"},{\"name\":\"to\",\"type\":\"name\"},{\"name\":\"quantity\",\"type\":\"asset\"},{\"name\":\"memo\",\"type\":\"string\"}]}],\"actions\":[{\"name\":\"transfer\",\"type\":\"transfer\"}]}"; uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); if (!abieos_set_abi(ctx, contract, token_abi_json)) { fprintf(stderr, "Failed to load ABI: %s\n", abieos_get_error(ctx)); abieos_destroy(ctx); return 1; } abieos_destroy(ctx); ``` ### Load ABI from Hex ```c abieos_context* ctx = abieos_create(); const char* abi_hex = "0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d65..."; uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); if (!abieos_set_abi_hex(ctx, contract, abi_hex)) { fprintf(stderr, "Failed to load ABI from hex: %s\n", abieos_get_error(ctx)); abieos_destroy(ctx); return 1; } abieos_destroy(ctx); ``` ### Load ABI from Binary ```c abieos_context* ctx = abieos_create(); // Binary ABI data (from file or network) const char* abi_bin_data = /* binary data */; size_t abi_bin_size = /* size of binary data */; uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); if (!abieos_set_abi_bin(ctx, contract, abi_bin_data, abi_bin_size)) { fprintf(stderr, "Failed to load binary ABI: %s\n", abieos_get_error(ctx)); abieos_destroy(ctx); return 1; } abieos_destroy(ctx); ``` ``` -------------------------------- ### Conditionally Add Tools Subdirectory (CMake) Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Includes the 'tools' subdirectory only if the 'ABIEOS_ONLY_LIBRARY' build option is not defined. This allows for building additional command-line tools alongside the main library, controlled by a CMake variable. ```cmake if (NOT ABIEOS_ONLY_LIBRARY) add_subdirectory(tools) endif() ``` -------------------------------- ### Load ABI from JSON Format (C) Source: https://context7.com/antelopeio/abieos/llms.txt Loads an Antelope contract's ABI definition from a JSON string into the abieos context. Associates the ABI with a specific contract name. ```c abieos_context* ctx = abieos_create(); const char* token_abi_json = "{\"version\":\"eosio::abi/1.0\",\"structs\":[{\"name\":\"transfer\",\"fields\":[{\"name\":\"from\",\"type\":\"name\"},{\"name\":\"to\",\"type\":\"name\"},{\"name\":\"quantity\",\"type\":\"asset\"},{\"name\":\"memo\",\"type\":\"string\"}]}],\"actions\":[{\"name\":\"transfer\",\"type\":\"transfer\"}]}"; uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); if (!abieos_set_abi(ctx, contract, token_abi_json)) { fprintf(stderr, "Failed to load ABI: %s\n", abieos_get_error(ctx)); abieos_destroy(ctx); return 1; } abieos_destroy(ctx); ``` -------------------------------- ### Convert ABI JSON to Binary (C) Source: https://context7.com/antelopeio/abieos/llms.txt Converts an ABI definition from JSON format to its binary representation using the Abieos C API. It initializes a context, performs the conversion, and retrieves the resulting binary data size and hex-encoded string. Error handling is included to report conversion failures. ```c abieos_context* ctx = abieos_create(); const char* abi_json = "{\"version\":\"eosio::abi/1.0\",\"structs\":[...]}"; if (!abieos_abi_json_to_bin(ctx, abi_json)) { fprintf(stderr, "ABI JSON to binary failed: %s\n", abieos_get_error(ctx)); abieos_destroy(ctx); return 1; } int bin_size = abieos_get_bin_size(ctx); const char* bin_data = abieos_get_bin_data(ctx); const char* hex = abieos_get_bin_hex(ctx); printf("ABI binary size: %d\n", bin_size); printf("ABI hex: %s\n", hex); abieos_destroy(ctx); ``` -------------------------------- ### Type Lookup API Source: https://context7.com/antelopeio/abieos/llms.txt Retrieve the type names associated with actions and tables defined in a loaded contract ABI. ```APIDOC ## Type Lookup API ### Description Enables querying the type names for specific actions and tables within a loaded contract ABI. This is useful for understanding the data structures associated with blockchain operations. ### Get Action Type Name ```c abieos_context* ctx = abieos_create(); uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); abieos_set_abi(ctx, contract, token_abi_json); // Assuming token_abi_json is loaded uint64_t action = abieos_string_to_name(ctx, "transfer"); const char* action_type = abieos_get_type_for_action(ctx, contract, action); if (action_type) { printf("Action type: %s\n", action_type); // "transfer" } else { fprintf(stderr, "Error: %s\n", abieos_get_error(ctx)); } abieos_destroy(ctx); ``` ### Get Table Type Name ```c abieos_context* ctx = abieos_create(); uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); abieos_set_abi(ctx, contract, token_abi_json); // Assuming token_abi_json is loaded uint64_t table = abieos_string_to_name(ctx, "accounts"); const char* table_type = abieos_get_type_for_table(ctx, contract, table); if (table_type) { printf("Table type: %s\n", table_type); // "account" } else { fprintf(stderr, "Error: %s\n", abieos_get_error(ctx)); } abieos_destroy(ctx); ``` ``` -------------------------------- ### Load ABI from Hex Format (C) Source: https://context7.com/antelopeio/abieos/llms.txt Loads an Antelope contract's ABI definition from a hexadecimal string into the abieos context. Useful when the ABI is available as a hex-encoded string. ```c abieos_context* ctx = abieos_create(); const char* abi_hex = "0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d65..."; uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); if (!abieos_set_abi_hex(ctx, contract, abi_hex)) { fprintf(stderr, "Failed to load ABI from hex: %s\n", abieos_get_error(ctx)); abieos_destroy(ctx); return 1; } abieos_destroy(ctx); ``` -------------------------------- ### Convert Action JSON to Binary using Abieos C API Source: https://context7.com/antelopeio/abieos/llms.txt Converts a JSON string representing an action into its binary format using the Abieos C API. This function requires an initialized context, contract ABI, and the action's JSON payload. It outputs the binary data as a hex string or raw bytes. ```c abieos_context* ctx = abieos_create(); uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); abieos_set_abi(ctx, contract, token_abi_json); const char* action_json = "{\"from\":\"useraaaaaaaa\",\"to\":\"useraaaaaaab\",\"quantity\":\"0.0001 SYS\",\"memo\":\"\"}"; uint64_t action = abieos_string_to_name(ctx, "transfer"); const char* action_type = abieos_get_type_for_action(ctx, contract, action); if (!abieos_json_to_bin(ctx, contract, action_type, action_json)) { fprintf(stderr, "JSON to binary failed: %s\n", abieos_get_error(ctx)); abieos_destroy(ctx); return 1; } const char* hex_data = abieos_get_bin_hex(ctx); printf("Hex: %s\n", hex_data); int bin_size = abieos_get_bin_size(ctx); const char* bin_data = abieos_get_bin_data(ctx); abieos_destroy(ctx); ``` -------------------------------- ### Convert Binary Data to JSON using Abieos C API Source: https://context7.com/antelopeio/abieos/llms.txt Converts raw binary data, typically obtained from a blockchain, back into a human-readable JSON format using the Abieos C API. This function requires an initialized context, the contract ABI, the action's type string, and the binary data itself. ```c abieos_context* ctx = abieos_create(); uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); abieos_set_abi(ctx, contract, token_abi_json); const char* bin_data = "\x60\x8C\x31\xC6\x18\x73\x15\xD6\x70\x8C\x31\xC6\x18\x73\x15\xD6\x01\x00\x00\x00\x00\x00\x00\x00\x04\x53\x59\x53\x00\x00\x00\x00\x00"; size_t bin_size = 33; const char* action_type = abieos_get_type_for_action(ctx, contract, abieos_string_to_name(ctx, "transfer")); const char* json = abieos_bin_to_json(ctx, contract, action_type, bin_data, bin_size); if (json) { printf("JSON: %s\n", json); } else { fprintf(stderr, "Binary to JSON failed: %s\n", abieos_get_error(ctx)); } abieos_destroy(ctx); ``` -------------------------------- ### Set Fuzzer Compile Options (CMake) Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Configures compile-time options for the fuzzer target using CMake. It enables sanitizers for detecting memory, undefined behavior, and integer overflows during fuzzing. This is crucial for robust security and stability testing. ```cmake target_compile_options(fuzzer PRIVATE -fsanitize=fuzzer,address,undefined,signed-integer-overflow -fstandalone-debug) ``` -------------------------------- ### Export Abieos Targets (CMake) Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Generates the CMake export file that lists the targets provided by the Abieos library. This file is essential for making the library discoverable by other CMake projects using `find_package`. ```cmake export(TARGETS abieos FILE ${CMAKE_CURRENT_BINARY_DIR}/share/abieos/abieos-targets.cmake) ``` -------------------------------- ### Submodule Check - CMake Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Checks if Git submodules are up-to-date, failing the build if they are not. This ensures all necessary external dependencies are correctly initialized. ```cmake if(NOT DEFINED SKIP_SUBMODULE_CHECK) execute_process(COMMAND git submodule status --recursive COMMAND grep -c "^[+\- ]" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE submodule_status OUTPUT_STRIP_TRAILING_WHITESPACE) if(submodule_status GREATER 0) message(FATAL_ERROR "git submodules are not up to date. Please run the command 'git submodule update --init --recursive'.") endif() endif() ``` -------------------------------- ### Name Conversion API Source: https://context7.com/antelopeio/abieos/llms.txt Convert Antelope account names between their string representation and uint64_t representation. ```APIDOC ## Name Conversion API ### Description Provides functions to convert between the string representation of Antelope account names and their uint64_t numerical representation. ### String to Name ```c abieos_context* ctx = abieos_create(); const char* account_str = "eosio.token"; uint64_t account_name = abieos_string_to_name(ctx, account_str); // account_name = 6138663577826885632 abieos_destroy(ctx); ``` ### Name to String ```c abieos_context* ctx = abieos_create(); uint64_t account_name = 6138663577826885632; const char* decoded = abieos_name_to_string(ctx, account_name); // decoded = "eosio.token" abieos_destroy(ctx); ``` ``` -------------------------------- ### Set Compiler Warnings for Clang/AppleClang (CMake) Source: https://github.com/antelopeio/abieos/blob/main/CMakeLists.txt Applies specific compiler warning flags when using Clang or AppleClang compilers. These flags enforce strict coding standards by enabling all common warnings and disabling specific ones that might be too noisy. This improves code quality and helps catch potential issues early. ```cmake if (CMAKE_CXX_COMPILER_ID MATCHES Clang|AppleClang) target_compile_options(abieos PRIVATE -Wall -Wextra -Wno-unused-parameter -fcolor-diagnostics) target_compile_options(test_abieos PRIVATE -Wall -Wextra -Wno-unused-parameter -fcolor-diagnostics) endif() ``` -------------------------------- ### Convert Transaction JSON to Binary using Abieos C API Source: https://context7.com/antelopeio/abieos/llms.txt Converts a JSON string representing a full transaction into its binary format using the Abieos C API. This is useful for constructing transactions before signing and broadcasting. It requires the transaction ABI to be set and the JSON payload for the transaction. ```c abieos_context* ctx = abieos_create(); abieos_set_abi(ctx, 0, transaction_abi_json); const char* tx_json = "{\"expiration\":\"2018-06-27T20:33:54.000\",\"ref_block_num\":45323,\"ref_block_prefix\":2628749070,\"max_net_usage_words\":0,\"max_cpu_usage_ms\":0,\"delay_sec\":0,\"context_free_actions\":[],\"actions\":[{\"account\":\"eosio.token\",\"name\":\"transfer\",\"authorization\":[{\"actor\":\"useraaaaaaaa\",\"permission\":\"active\"}],\"data\":\"608C31C6187315D6708C31C6187315D60100000000000000045359530000000000\"}],\"transaction_extensions\":[]}"; uint64_t type_name = abieos_string_to_name(ctx, "transaction"); const char* type_str = abieos_name_to_string(ctx, type_name); if (!abieos_json_to_bin(ctx, 0, type_str, tx_json)) { fprintf(stderr, "Transaction conversion failed: %s\n", abieos_get_error(ctx)); abieos_destroy(ctx); return 1; } const char* tx_hex = abieos_get_bin_hex(ctx); printf("Transaction hex: %s\n", tx_hex); abieos_destroy(ctx); ``` -------------------------------- ### Convert JSON with Reorderable Fields to Binary using Abieos C API Source: https://context7.com/antelopeio/abieos/llms.txt Converts a JSON string with fields in a different order than the ABI definition to binary format. The `abieos_json_to_bin_reorderable` function handles this by correctly mapping JSON fields to their corresponding ABI types, ensuring accurate serialization regardless of field order. ```c abieos_context* ctx = abieos_create(); uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); abieos_set_abi(ctx, contract, token_abi_json); const char* json_out_of_order = "{\"memo\":\"\",\"quantity\":\"0.0001 SYS\",\"from\":\"useraaaaaaaa\",\"to\":\"useraaaaaaab\"}"; const char* action_type = abieos_get_type_for_action(ctx, contract, abieos_string_to_name(ctx, "transfer")); if (!abieos_json_to_bin_reorderable(ctx, contract, action_type, json_out_of_order)) { fprintf(stderr, "Conversion failed: %s\n", abieos_get_error(ctx)); abieos_destroy(ctx); return 1; } const char* hex = abieos_get_bin_hex(ctx); printf("Result: %s\n", hex); abieos_destroy(ctx); ``` -------------------------------- ### Convert ABI Binary to JSON (C) Source: https://context7.com/antelopeio/abieos/llms.txt Converts ABI binary data into a human-readable JSON format using the Abieos C API. This function takes raw binary ABI data and its size as input and returns a JSON string representing the ABI definition. It includes error handling for the conversion process. ```c abieos_context* ctx = abieos_create(); // ABI binary data (from blockchain or file) const char* abi_bin = /* binary ABI data */; size_t abi_size = /* size */; const char* abi_json = abieos_abi_bin_to_json(ctx, abi_bin, abi_size); if (abi_json) { printf("ABI JSON:\n%s\n", abi_json); // Parse and use the JSON ABI definition } else { fprintf(stderr, "ABI binary to JSON failed: %s\n", abieos_get_error(ctx)); } abieos_destroy(ctx); ``` -------------------------------- ### Delete Loaded Contract from Context (C) Source: https://context7.com/antelopeio/abieos/llms.txt Removes a previously loaded contract from the Abieos context to free up memory. This operation requires the contract's name (represented as a uint64_t) and returns a boolean indicating success or failure. ```c abieos_context* ctx = abieos_create(); uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); abieos_set_abi(ctx, contract, token_abi_json); // Later, remove the contract to free memory if (abieos_delete_contract(ctx, contract)) { printf("Contract deleted successfully\n"); } else { printf("Contract not found\n"); } abieos_destroy(ctx); ``` -------------------------------- ### Convert Hex Data to JSON using Abieos C API Source: https://context7.com/antelopeio/abieos/llms.txt Converts a hexadecimal string representation of binary data into a JSON format using the Abieos C API. This is useful when dealing with data that is already in hex format, such as from API responses or logs. It requires the contract ABI and the action's type string. ```c abieos_context* ctx = abieos_create(); uint64_t contract = abieos_string_to_name(ctx, "eosio.token"); abieos_set_abi(ctx, contract, token_abi_json); const char* hex_data = "608C31C6187315D6708C31C6187315D60100000000000000045359530000000000"; const char* action_type = abieos_get_type_for_action(ctx, contract, abieos_string_to_name(ctx, "transfer")); const char* json = abieos_hex_to_json(ctx, contract, action_type, hex_data); if (json) { printf("JSON: %s\n", json); } else { fprintf(stderr, "Hex to JSON failed: %s\n", abieos_get_error(ctx)); } abieos_destroy(ctx); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.