Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Quick fixes for abidiff, rename proj to init and spruce up examples t…
Browse files Browse the repository at this point in the history
…o use new project pattern
  • Loading branch information
larryk85 committed Dec 12, 2018
1 parent 8c6d89b commit 0d12e39
Show file tree
Hide file tree
Showing 24 changed files with 178 additions and 128 deletions.
2 changes: 0 additions & 2 deletions examples/CMakeLists.txt

This file was deleted.

21 changes: 16 additions & 5 deletions examples/multi_index_example/CMakeLists.txt
@@ -1,6 +1,17 @@
cmake_minimum_required(VERSION 3.5)
project(hello_example VERSION 1.0.0)
include(ExternalProject)
# if no cdt root is given use default path
if(EOSIO_CDT_ROOT STREQUAL "" OR NOT EOSIO_CDT_ROOT)
find_package(eosio.cdt)
endif()

find_package(eosio.cdt)

add_contract( multi_index_example mie multi_index_example.cpp )
ExternalProject_Add(
multi_index_example_project
SOURCE_DIR ${CMAKE_SOURCE_DIR}/src
BINARY_DIR ${CMAKE_BINARY_DIR}/multi_index_example
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${EOSIO_CDT_ROOT}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake
UPDATE_COMMAND ""
PATCH_COMMAND ""
TEST_COMMAND ""
INSTALL_COMMAND ""
BUILD_ALWAYS 1
)
12 changes: 12 additions & 0 deletions examples/multi_index_example/README.txt
@@ -0,0 +1,12 @@
--- multi_index_example Project ---

- How to Build -
- cd to 'build' directory
- run the command 'cmake ..'
- run the command 'make'

- After build -
- The built smart contract is under the 'multi_index_example' directory in the 'build' directory
- You can then do a 'set contract' action with 'cleos' and point in to the './build/multi_index_example' directory

- Additions to CMake should be done to the CMakeLists.txt in the './src' directory and not in the top level CMakeLists.txt
30 changes: 30 additions & 0 deletions examples/multi_index_example/include/multi_index_example.hpp
@@ -0,0 +1,30 @@
#include <eosiolib/eosio.hpp>
using namespace eosio;

CONTRACT multi_index_example : public contract {
public:
using contract::contract;
multi_index_example( name receiver, name code, datastream<const char*> ds )
: contract(receiver, code, ds), testtab(receiver, receiver.value) {}

ACTION set(name user);
ACTION print( name user );
ACTION bysec( name secid );
ACTION mod( name user, uint32_t n );

TABLE test_table {
name test_primary;
name secondary;
uint64_t datum;
uint64_t primary_key()const { return test_primary.value; }
uint64_t by_secondary()const { return secondary.value; }
};

typedef eosio::multi_index<"testtaba"_n, test_table, eosio::indexed_by<"secid"_n, eosio::const_mem_fun<test_table, uint64_t, &test_table::by_secondary>>> test_tables;

using set_action = action_wrapper<"set"_n, &multi_index_example::set>;
using print_action = action_wrapper<"print"_n, &multi_index_example::print>;
using bysec_action = action_wrapper<"bysec"_n, &multi_index_example::bysec>;
using mod_action = action_wrapper<"mod"_n, &multi_index_example::mod>;
test_tables testtab;
};
75 changes: 0 additions & 75 deletions examples/multi_index_example/multi_index_example.cpp

This file was deleted.

@@ -0,0 +1,3 @@
<h1 class="contract"> hi </h1>

Stub for hi action's ricardian contract
8 changes: 8 additions & 0 deletions examples/multi_index_example/src/CMakeLists.txt
@@ -0,0 +1,8 @@
project(multi_index_example)

set(EOSIO_WASM_OLD_BEHAVIOR "Off")
find_package(eosio.cdt)

add_contract( multi_index_example multi_index_example multi_index_example.cpp )
target_include_directories( multi_index_example PUBLIC ${CMAKE_SOURCE_DIR}/../include )
target_ricardian_directory( multi_index_example ${CMAKE_SOURCE_DIR}/../ricardian )
37 changes: 37 additions & 0 deletions examples/multi_index_example/src/multi_index_example.cpp
@@ -0,0 +1,37 @@
#include <multi_index_example.hpp>
ACTION multi_index_example::set( name user ) {
auto itr = testtab.find(user.value);
if ( itr == testtab.end() ) {
testtab.emplace( _self, [&]( auto& u ) {
u.test_primary = user;
u.secondary = "second"_n;
u.datum = 0;
});
}
}

ACTION multi_index_example::print( name user ) {
auto itr = testtab.find(user.value);
eosio_assert( itr != testtab.end(), "test table not set" );
eosio::print_f("Test Table : {%, %, %}\n", itr->test_primary, itr->secondary, itr->datum);
}

ACTION multi_index_example::bysec( name secid ) {
auto idx = testtab.get_index<"secid"_n>();
for ( auto itr = idx.begin(); itr != idx.end(); itr++ ) {
print( itr->test_primary );
}
}


ACTION multi_index_example::mod( name user, uint32_t n ) {
auto itr = testtab.find(user.value);
eosio_assert( itr != testtab.end(), "test table not set" );
testtab.modify( itr, _self, [&]( auto& row ) {
row.secondary = user;
row.datum = n;
});
}


EOSIO_DISPATCH( multi_index_example, (set)(print)(mod)(bysec) )
24 changes: 16 additions & 8 deletions examples/send_inline/CMakeLists.txt
@@ -1,9 +1,17 @@
cmake_minimum_required(VERSION 3.5)
project(hello_example VERSION 1.0.0)
include(ExternalProject)
# if no cdt root is given use default path
if(EOSIO_CDT_ROOT STREQUAL "" OR NOT EOSIO_CDT_ROOT)
find_package(eosio.cdt)
endif()

find_package(eosio.cdt)

### Generate the wasm and abi
add_contract( send_inline send_inline send_inline.cpp )

target_include_directories( send_inline.wasm PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../hello )
ExternalProject_Add(
send_inline_project
SOURCE_DIR ${CMAKE_SOURCE_DIR}/src
BINARY_DIR ${CMAKE_BINARY_DIR}/send_inline
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${EOSIO_CDT_ROOT}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake
UPDATE_COMMAND ""
PATCH_COMMAND ""
TEST_COMMAND ""
INSTALL_COMMAND ""
BUILD_ALWAYS 1
)
12 changes: 12 additions & 0 deletions examples/send_inline/README.txt
@@ -0,0 +1,12 @@
--- send_inline Project ---

- How to Build -
- cd to 'build' directory
- run the command 'cmake ..'
- run the command 'make'

- After build -
- The built smart contract is under the 'send_inline' directory in the 'build' directory
- You can then do a 'set contract' action with 'cleos' and point in to the './build/send_inline' directory

- Additions to CMake should be done to the CMakeLists.txt in the './src' directory and not in the top level CMakeLists.txt
11 changes: 11 additions & 0 deletions examples/send_inline/include/send_inline.hpp
@@ -0,0 +1,11 @@
#include <eosiolib/eosio.hpp>
using namespace eosio;

CONTRACT send_inline : public contract {
public:
using contract::contract;

ACTION test( name user, name inline_code );

using test_action = action_wrapper<"test"_n, &send_inline::test>;
};
3 changes: 3 additions & 0 deletions examples/send_inline/ricardian/send_inline.contracts.md
@@ -0,0 +1,3 @@
<h1 class="contract"> hi </h1>

Stub for hi action's ricardian contract
21 changes: 0 additions & 21 deletions examples/send_inline/send_inline.cpp

This file was deleted.

9 changes: 9 additions & 0 deletions examples/send_inline/src/CMakeLists.txt
@@ -0,0 +1,9 @@
project(send_inline)

set(EOSIO_WASM_OLD_BEHAVIOR "Off")
find_package(eosio.cdt)

add_contract( send_inline send_inline send_inline.cpp )
target_include_directories( send_inline PUBLIC ${CMAKE_SOURCE_DIR}/../include )
target_include_directories( send_inline PUBLIC ${CMAKE_SOURCE_DIR}/../../hello/include )
target_ricardian_directory( send_inline ${CMAKE_SOURCE_DIR}/../ricardian )
10 changes: 10 additions & 0 deletions examples/send_inline/src/send_inline.cpp
@@ -0,0 +1,10 @@
#include <send_inline.hpp>
#include <hello.hpp>
ACTION send_inline::test( name user, name inline_code ) {
print_f( "Hello % from send_inline", user );
// constructor takes two arguments (the code the contract is deployed on and the set of permissions)
hello::hi_action hi(inline_code, {_self, "active"_n});
hi.send(user);
}

EOSIO_DISPATCH( send_inline, (test) )
7 changes: 0 additions & 7 deletions examples/template/CMakeLists.txt

This file was deleted.

3 changes: 2 additions & 1 deletion install.sh
Expand Up @@ -63,8 +63,9 @@
create_symlink "eosio-cpp eosio-cpp"
create_symlink "eosio-ld eosio-ld"
create_symlink "eosio-pp eosio-pp"
create_symlink "eosio-proj eosio-proj"
create_symlink "eosio-init eosio-init"
create_symlink "eosio-abigen eosio-abigen"
create_symlink "eosio-abidiff eosio-abidiff"
create_symlink "eosio-wasm2wast eosio-wasm2wast"
create_symlink "eosio-wast2wasm eosio-wast2wasm"
}
Expand Down
2 changes: 1 addition & 1 deletion modules/InstallCDT.cmake
Expand Up @@ -64,7 +64,7 @@ eosio_tool_install(eosio-cpp)
eosio_tool_install(eosio-ld)
eosio_tool_install(eosio-abigen)
eosio_tool_install(eosio-abidiff)
eosio_tool_install(eosio-proj)
eosio_tool_install(eosio-init)
eosio_clang_install(../lib/LLVMEosioApply${CMAKE_SHARED_LIBRARY_SUFFIX})
eosio_clang_install(../lib/LLVMEosioSoftfloat${CMAKE_SHARED_LIBRARY_SUFFIX})
eosio_clang_install(../lib/eosio_plugin${CMAKE_SHARED_LIBRARY_SUFFIX})
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_tarball.sh
Expand Up @@ -51,7 +51,7 @@ create_symlink "eosio-cc eosio-cc"
create_symlink "eosio-cpp eosio-cpp"
create_symlink "eosio-ld eosio-ld"
create_symlink "eosio-pp eosio-pp"
create_symlink "eosio-proj eosio-proj"
create_symlink "eosio-init eosio-init"
create_symlink "eosio-abigen eosio-abigen"
create_symlink "eosio-wasm2wast eosio-wasm2wast"
create_symlink "eosio-wast2wasm eosio-wast2wasm"
Expand Down
2 changes: 1 addition & 1 deletion tools/CMakeLists.txt
Expand Up @@ -70,7 +70,7 @@ add_subdirectory(abigen)
add_subdirectory(abidiff)
add_subdirectory(cc)
add_subdirectory(ld)
add_subdirectory(proj)
add_subdirectory(init)
add_subdirectory(external)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/compiler_options.hpp.in ${CMAKE_BINARY_DIR}/compiler_options.hpp)
2 changes: 1 addition & 1 deletion tools/abidiff/eosio-abidiff.cpp.in
Expand Up @@ -75,7 +75,7 @@ class abidiff {
}

void diff_version() {
if (abi_1["version"] == abi_2["version"]) {
if (get_version(abi_1) != get_version(abi_2)) {
std::cout << "< version\n\t";
std::cout << abi_1["version"] << "\n";
std::cout << "> version\n\t";
Expand Down
3 changes: 3 additions & 0 deletions tools/init/CMakeLists.txt
@@ -0,0 +1,3 @@
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/eosio-init.cpp ${CMAKE_BINARY_DIR}/eosio-init.cpp @ONLY)

add_tool(eosio-init)
4 changes: 2 additions & 2 deletions tools/proj/eosio-proj.cpp → tools/init/eosio-init.cpp
Expand Up @@ -186,9 +186,9 @@ struct project {
int main(int argc, const char **argv) {

cl::SetVersionPrinter([](llvm::raw_ostream& os) {
os << "eosio-proj version " << @VERSION_MAJOR@ << "." << @VERSION_MINOR@ << "." << @VERSION_PATCH@ << "\n";
os << "eosio-init version " << @VERSION_MAJOR@ << "." << @VERSION_MINOR@ << "." << @VERSION_PATCH@ << "\n";
});
cl::OptionCategory cat("eosio-proj", "generates an eosio smart contract project");
cl::OptionCategory cat("eosio-init", "generates an eosio smart contract project");

cl::opt<bool> bare_opt(
"bare",
Expand Down
3 changes: 0 additions & 3 deletions tools/proj/CMakeLists.txt

This file was deleted.

0 comments on commit 0d12e39

Please sign in to comment.