Skip to content

Commit

Permalink
Merge pull request EOSIO#132 from EOSIO/symbol-changes-2
Browse files Browse the repository at this point in the history
Major refactor of eosiolib (upgrade to C++17, no more core symbol dependence, and more)
  • Loading branch information
larryk85 authored Oct 5, 2018
2 parents ffbc804 + e9213f2 commit c7b7777
Show file tree
Hide file tree
Showing 30 changed files with 831 additions and 868 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $ cd eosio.cdt
Now run `build.sh` and give the core symbol for the EOSIO blockchain that intend to deploy to.
*`build.sh` will install any dependencies that are needed.
```sh
$ ./build.sh <CORE_SYMBOL>
$ ./build.sh
```

Finally, install the build
Expand All @@ -51,7 +51,7 @@ $ eosio-cpp hello.cpp -o hello.wasm

### How to use eosio-abigen
#### using with eosio-cpp
To generate an abi with ```eosio-cpp```, the only flag you need to pass to ```eosio-cpp``` is `-abigen`, this will tell the compiler to run `eosio-abigen` after compilation and linking stages. If the output filename is specified as a '.wasm' file with the `-o` option (e.g. \<filename\>.wasm) then eosio-cpp will tell the abi generator to create the abi with the name \<filename\>.abi, if no '.wasm' suffix is used then the resulting output filename is still \<filename\>.abi
To generate an abi with ```eosio-cpp```, the only flag you need to pass to ```eosio-cpp``` is `-abigen`, this will tell the compiler to run `eosio-abigen` after compilation and linking stages. If the output filename is specified as a '.wasm' file with the `-o` option (e.g. \<filename\>.wasm) then eosio-cpp will tell the abi generator to create the abi with the name \<filename\>.abi, if no '.wasm' suffix is used then the resulting output filename is still \<filename\>.abi

Example:
```bash
Expand Down Expand Up @@ -84,7 +84,7 @@ void testa( account_name n ) {
}

// this is the GNU style attribute, this can be used in C code and prior to C++ 11
__attribute__((eosio_action))
__attribute__((eosio_action))
void testa( account_name n ){
// do something
}
Expand Down
8 changes: 2 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [[ "${unamestr}" == 'Darwin' ]]; then
bash ./scripts/eosio_build_darwin.sh
else
OS_NAME=$( cat /etc/os-release | grep ^NAME | cut -d'=' -f2 | sed 's/\"//gI' )

case "$OS_NAME" in
"Amazon Linux AMI")
export ARCH="Amazon Linux AMI"
Expand Down Expand Up @@ -58,10 +58,6 @@ else
esac
fi

if [ $# -ge 1 ]; then
CORE_SYMBOL=$1
fi

if [[ `uname` == 'Darwin' ]]; then
FREE_MEM=`vm_stat | grep "Pages free:"`
read -ra FREE_MEM <<< "$FREE_MEM"
Expand Down Expand Up @@ -89,7 +85,7 @@ if [ -z "$CMAKE" ]; then
CMAKE=$( command -v cmake )
fi

"$CMAKE" -DCMAKE_INSTALL_PREFIX=/usr/local/eosio.cdt -DCORE_SYMBOL_NAME="${CORE_SYMBOL}" ../
"$CMAKE" -DCMAKE_INSTALL_PREFIX=/usr/local/eosio.cdt ../
if [ $? -ne 0 ]; then
exit -1;
fi
Expand Down
2 changes: 1 addition & 1 deletion eosio_llvm
Submodule eosio_llvm updated 1 files
+1 −1 tools/clang
8 changes: 6 additions & 2 deletions examples/abigen_test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <eosiolib/eosio.hpp>
#include <eosiolib/optional.hpp>

using namespace eosio;

typedef int type_def;

namespace test {
// mark this struct as an action
struct [[ eosio::action ]] testa {
Expand All @@ -26,13 +30,13 @@ class test_contract : public eosio::contract {

// mark this method as an action and specify the name explicity
[[ eosio::action("testacta") ]]
void testact_a( account_name user ) {
void testact_a( account_name user, const std::string& s, std::vector<int>& c, std::vector<std::string> sv ) {
print( "Hello, ", name{user} );
}

// mark this method as an action
[[ eosio::action ]]
void testactb( test::test_c input ) {
void testactb( test::test_c input, type_def td, optional<int> cc, bool d ) {
print(input.num);
}

Expand Down
9 changes: 3 additions & 6 deletions libraries/eosiolib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
file(GLOB HEADERS "*.hpp"
"*.h")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/core_symbol.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/core_symbol.hpp)

add_library(eosio
eosiolib.cpp
add_library(eosio
eosiolib.cpp
${HEADERS})

target_include_directories(eosio PUBLIC
target_include_directories(eosio PUBLIC
"$<BUILD_INTERFACE:${STANDARD_INCLUDES}>"
$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}>)

Expand All @@ -19,6 +17,5 @@ install(TARGETS eosio EXPORT EosioLib

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../eosiolib DESTINATION ${CMAKE_BINARY_DIR}/include FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
add_custom_command( TARGET eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eosio> ${CMAKE_BINARY_DIR}/lib )
add_custom_command( TARGET eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/core_symbol.hpp ${CMAKE_BINARY_DIR}/include/eosiolib )
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../eosiolib DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/core_symbol.hpp DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosiolib)
46 changes: 16 additions & 30 deletions libraries/eosiolib/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ extern "C" {
*
* ```
* struct action {
* scope_name scope; // the contract defining the primary code to execute for code/type
* action_name name; // the action to be taken
* capi_name account_name; // the contract defining the primary code to execute for code/type
* capi_name action_name; // the action to be taken
* permission_level[] authorization; // the accounts and permission levels provided
* bytes data; // opaque data processed by code
* };
Expand Down Expand Up @@ -68,7 +68,7 @@ extern "C" {

/**
* Copy up to @ref len bytes of current action data to the specified location
*
*
* @brief Copy current action data to the specified location
* @param msg - a pointer where up to @ref len bytes of the current action data will be copied
* @param len - len of the current action data to be copied, 0 to report required size
Expand All @@ -80,50 +80,50 @@ extern "C" {

/**
* Get the length of the current action's data field. This method is useful for dynamically sized actions
*
*
* @brief Get the length of current action's data field
* @return the length of the current action's data field
*/
uint32_t action_data_size();

/**
* Add the specified account to set of accounts to be notified
*
*
* @brief Add the specified account to set of accounts to be notified
* @param name - name of the account to be verified
*/
void require_recipient( account_name name );
void require_recipient( capi_name name );

/**
* Verifies that @ref name exists in the set of provided auths on a action. Throws if not found.
*
*
* @brief Verify specified account exists in the set of provided auths
* @param name - name of the account to be verified
*/
void require_auth( account_name name );
void require_auth( capi_name name );

/**
* Verifies that @ref name has auth.
*
*
* @brief Verifies that @ref name has auth.
* @param name - name of the account to be verified
*/
bool has_auth( account_name name );
bool has_auth( capi_name name );

/**
* Verifies that @ref name exists in the set of provided auths on a action. Throws if not found.
*
*
* @brief Verify specified account exists in the set of provided auths
* @param name - name of the account to be verified
* @param permission - permission level to be verified
*/
void require_auth2( account_name name, permission_name permission );
void require_auth2( capi_name name, capi_name permission );

bool is_account( account_name name );
bool is_account( capi_name name );

/**
* Send an inline action in the context of this action's parent transaction
*
*
* @param serialized_action - serialized action
* @param size - size of serialized action in bytes
* @pre `serialized_action` is a valid pointer to an array at least `size` bytes long
Expand All @@ -132,27 +132,13 @@ extern "C" {

/**
* Send an inline context free action in the context of this action's parent transaction
*
*
* @param serialized_action - serialized action
* @param size - size of serialized action in bytes
* @pre `serialized_action` is a valid pointer to an array at least `size` bytes long
*/
void send_context_free_inline(char *serialized_action, size_t size);

/**
* Verifies that @ref name exists in the set of write locks held on a action. Throws if not found
* @brief Verifies that @ref name exists in the set of write locks held
* @param name - name of the account to be verified
*/
void require_write_lock( account_name name );

/**
* Verifies that @ref name exists in the set of read locks held on a action. Throws if not found
* @brief Verifies that @ref name exists in the set of read locks held
* @param name - name of the account to be verified
*/
void require_read_lock( account_name name );

/**
* Returns the time in microseconds from 1970 of the publication_time
* @brief Get the publication time
Expand All @@ -165,6 +151,6 @@ extern "C" {
* @brief Get the current receiver of the action
* @return the account which specifies the current receiver of the action
*/
account_name current_receiver();
capi_name current_receiver();
///@ } actioncapi
}
Loading

0 comments on commit c7b7777

Please sign in to comment.