This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quick fixes for abidiff, rename proj to init and spruce up examples t…
…o use new project pattern
- Loading branch information
Showing
24 changed files
with
178 additions
and
128 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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 | ||
) |
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,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
30
examples/multi_index_example/include/multi_index_example.hpp
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,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; | ||
}; |
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
examples/multi_index_example/ricardian/multi_index_example.contracts.md
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,3 @@ | ||
<h1 class="contract"> hi </h1> | ||
|
||
Stub for hi action's ricardian contract |
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,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 ) |
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,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) ) |
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,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 | ||
) |
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,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 |
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,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>; | ||
}; |
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,3 @@ | ||
<h1 class="contract"> hi </h1> | ||
|
||
Stub for hi action's ricardian contract |
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,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 ) |
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,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) ) |
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
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
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,3 @@ | ||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/eosio-init.cpp ${CMAKE_BINARY_DIR}/eosio-init.cpp @ONLY) | ||
|
||
add_tool(eosio-init) |
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 was deleted.
Oops, something went wrong.