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

Commit

Permalink
added new examples
Browse files Browse the repository at this point in the history
  • Loading branch information
larryk85 committed Nov 8, 2018
1 parent 32c9ae7 commit 4f9479e
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 57 deletions.
6 changes: 3 additions & 3 deletions examples/hello/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ project(hello_example VERSION 1.0.0)

find_package(eosio.cdt)

### Only generate the wasm
#add_executable( hello.wasm hello.cpp )

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

### add the path to where the ricardian contracts/clauses are found
target_compile_options( hello.wasm PUBLIC -R${CMAKE_CURRENT_SOURCE_DIR} )
40 changes: 40 additions & 0 deletions examples/hello/hello.clauses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<h1 class="clause">Warranty</h1>
The invoker of the contract action shall uphold its Obligations under this Contract in a timely and workmanlike manner, using knowledge and recommendations for performing the services which meet generally acceptable standards set forth by EOS.IO Blockchain Block Producers.

<h1 class="clause">Default</h1>
The occurrence of any of the following shall constitute a material default under this Contract:

<h1 class="clause">Remedies</h1>
In addition to any and all other rights a party may have available according to law, if a party defaults by failing to substantially perform any provision, term or condition of this Contract, the other party may terminate the Contract by providing written notice to the defaulting party. This notice shall describe with sufficient detail the nature of the default. The party receiving such notice shall promptly be removed from being a Block Producer and this Contract shall be automatically terminated.

<h1 class="clause">ForceMajeure</h1>
If performance of this Contract or any obligation under this Contract is prevented, restricted, or interfered with by causes beyond either party's reasonable control ("Force Majeure"), and if the party unable to carry out its obligations gives the other party prompt written notice of such event, then the obligations of the party invoking this provision shall be suspended to the extent necessary by such event. The term Force Majeure shall include, without limitation, acts of God, fire, explosion, vandalism, storm or other similar occurrence, orders or acts of military or civil authority, or by national emergencies, insurrections, riots, or wars, or strikes, lock-outs, work stoppages, or supplier failures. The excused party shall use reasonable efforts under the circumstances to avoid or remove such causes of non-performance and shall proceed to perform with reasonable dispatch whenever such causes are removed or ceased. An act or omission shall be deemed within the reasonable control of a party if committed, omitted, or caused by such party, or its employees, officers, agents, or affiliates.

<h1 class="clause">DisputeResolution</h1>
Any controversies or disputes arising out of or relating to this Contract will be resolved by binding arbitration under the default rules set forth by the EOS.IO Blockchain. The arbitrator's award will be final, and judgment may be entered upon it by any court having proper jurisdiction.

<h1 class="clause">Agreement</h1>
This Contract contains the entire agreement of the parties, and there are no other promises or conditions in any other agreement whether oral or written concerning the subject matter of this Contract. This Contract supersedes any prior written or oral agreements between the parties.

<h1 class="clause">Severability</h1>
If any provision of this Contract will be held to be invalid or unenforceable for any reason, the remaining provisions will continue to be valid and enforceable. If a court finds that any provision of this Contract is invalid or unenforceable, but that by limiting such provision it would become valid and enforceable, then such provision will be deemed to be written, construed, and enforced as so limited.

<h1 class="clause">Amendment</h1>
This Contract may be modified or amended in writing by mutual agreement between the parties, if the writing is signed by the party obligated under the amendment.

<h1 class="clause">GoverningLaw</h1>
This Contract shall be construed in accordance with the Maxims of Equity.

<h1 class="clause">Notice</h1>
Any notice or communication required or permitted under this Contract shall be sufficiently given if delivered to a verifiable email address or to such other email address as one party may have publicly furnished in writing, or published on a broadcast contract provided by this blockchain for purposes of providing notices of this type.
<h1 class="clause">WaiverOfContractualRight</h1>
The failure of either party to enforce any provision of this Contract shall not be construed as a waiver or limitation of that party's right to subsequently enforce and compel strict compliance with every provision of this Contract.

<h1 class="clause">ArbitratorsFeesToPrevailingParty</h1>
In any action arising hereunder or any separate action pertaining to the validity of this Agreement, both sides shall pay half the initial cost of arbitration, and the prevailing party shall be awarded reasonable arbitrator's fees and costs.

<h1 class="clause">ConstructionAndInterpretation</h1>
The rule requiring construction or interpretation against the drafter is waived. The document shall be deemed as if it were drafted by both parties in a mutual effort.

<h1 class="clause">InWitnessWhereof</h1>
In witness whereof, the parties hereto have caused this Agreement to be executed by themselves or their duly authorized representatives as of the date of execution, and authorized as proven by the cryptographic signature on the transaction that invokes this contract.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# CONTRACT FOR hello::hi

## ACTION NAME: hi

<h1 class="contract">
hi
</h1>
### Parameters
Input parameters:

Expand Down
14 changes: 4 additions & 10 deletions examples/hello/hello.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#include <eosiolib/eosio.hpp>

#include "hello.hpp"
using namespace eosio;

CONTRACT hello : public eosio::contract {
public:
using contract::contract;

ACTION hi( name user ) {
print( "Hello, ", name{user} );
}
};
ACTION hello::hi( name user ) {
print_f( "Hello % from hello", user );
}

EOSIO_DISPATCH( hello, (hi) )
13 changes: 13 additions & 0 deletions examples/hello/hello.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <eosiolib/eosio.hpp>

using namespace eosio;

CONTRACT hello : public eosio::contract {
public:
using contract::contract;

ACTION hi( name user );

// accessor for external contracts to easily send inline actions to your contract
using hi_action = action_wrapper<"hi"_n, &hello::hi>;
};
40 changes: 0 additions & 40 deletions examples/hello/hello_rc.md

This file was deleted.

6 changes: 6 additions & 0 deletions examples/multi_index_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.5)
project(hello_example VERSION 1.0.0)

find_package(eosio.cdt)

add_contract( multi_index_example mie multi_index_example.cpp )
75 changes: 75 additions & 0 deletions examples/multi_index_example/multi_index_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <eosiolib/eosio.hpp>

using namespace eosio;

/* you can use this method of declaration */
//class [[eosio::contract]] multi_index_example : public contract {
/* or this method of declaration if you don't want to use the c++ class name */
//class [[eosio::contract("<some contract name>")]] multi_index_example : public contract {
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) {}

// [[eosio::action]]
// void set( name user ) {
ACTION 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;
});
}
}

// [[eosio::action]]
// void print( name user ) {
ACTION 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);
}

// [[eosio::action]]
// void bysec( name user ) {
ACTION bysec( name secid ) {
auto idx = testtab.get_index<"secid"_n>();
for ( auto itr = idx.begin(); itr != idx.end(); itr++ ) {
print( itr->test_primary );
}
}

// [[eosio::action]]
// void mod( name user, uint32_t n ) {
ACTION 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;
});
}

// struct [[eosio::table]] test_table {
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>;
private:
test_tables testtab;
};

EOSIO_DISPATCH( multi_index_example, (set)(print)(mod)(bysec) )
9 changes: 9 additions & 0 deletions examples/send_inline/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.5)
project(hello_example VERSION 1.0.0)

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 )
21 changes: 21 additions & 0 deletions examples/send_inline/send_inline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <eosiolib/eosio.hpp>
#include <hello.hpp>

using namespace eosio;

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

ACTION 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);
}

// accessor for external contracts to easily send inline actions to your contract
using test_action = action_wrapper<"test"_n, &send_inline::test>;
};

EOSIO_DISPATCH( send_inline, (test) )

0 comments on commit 4f9479e

Please sign in to comment.