Skip to content

Commit

Permalink
Merge pull request #656 from eoscommunity/main
Browse files Browse the repository at this point in the history
EdenOS Release 0.2.24
  • Loading branch information
brandonfancher committed Jan 6, 2022
2 parents a2f0c3a + 5fedc5b commit 7167acc
Show file tree
Hide file tree
Showing 110 changed files with 3,735 additions and 898 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
cp eden-micro-chain.wasm ../product_cache
cp eden.abi ../product_cache
cp eden.wasm ../product_cache
cp run-full-election.wasm ../product_cache
cp run-elections.wasm ../product_cache
cp run-genesis.wasm ../product_cache
cp token.abi ../product_cache
cp token.wasm ../product_cache
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
product_cache/token.abi
product_cache/token.wasm
product_cache/run-genesis.wasm
product_cache/run-full-election.wasm
product_cache/run-elections.wasm
build-micro-chain:
name: Build Micro Chain
Expand Down Expand Up @@ -353,6 +353,7 @@ jobs:
- "tsconfig.build.json"
- "tsconfig.json"
- "yarn.lock"
- "scripts/eden_chain_runner.sh"
- "packages/**"
- "contracts/**"
Expand All @@ -364,7 +365,7 @@ jobs:
name: Eden Microchain
path: build

- name: Download Ephemeral Chain Runners
- name: Download Ephemeral Eden Chain Runners
if: steps.filter.outputs.src == 'true'
uses: actions/download-artifact@v2
with:
Expand Down
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,64 @@ wget https://nodejs.org/dist/v14.16.0/node-v14.16.0-linux-x64.tar.xz
tar xf node-v14.16.0-linux-x64.tar.xz
npm i -g yarn
```

### Running Eden with Ephemeral Chains Locally

Ephemeral chains are instances of the EOS blockchain spawned by `nodeos` locally, with manipulated data from our chain runners, eg: [Basic Genesis Runner](contracts/eden/tests/run-genesis.cpp) or [Full Election Runner](contracts/eden/tests/run-full-election.cpp). By running a ephemeral chain you are in full control of the blockchain, giving you more flexibility to test the Eden contracts.

#### Get the executables

You will need to build the repo locally by following the below **build** steps. If you don't have a proper C++ environment setup you can download it from our current [main branch artifacts](https://github.com/eoscommunity/Eden/actions/workflows/build.yml?query=branch%3Amain).

If you built locally, you can skip these steps.

**Downloading the executables**

- Open our [main branch builds](https://github.com/eoscommunity/Eden/actions/workflows/build.yml?query=branch%3Amain).
- Click in the most recent successful one
- Scroll down to the artifacts section
- Download the following files:
- Eden Microchain
- Ephemeral Eden Chains Runners
- clsdk
- From the root of this repo, run the following commands:

```sh
mkdir build
# unzip all of the above artifact files in this build folder
cd build
tar -xvf clsdk-ubuntu-20-04.tar.gz clsdk/bin
cp ../scripts/eden_chain_runner.sh ./
```

Now you have all the files needed for running the ephemeral chain inside the `build` folder.

If you are on a Linux machine compatible with Ubuntu arch you can spin it up by just running: `./eden_chain_runner.sh run-genesis.wasm 1`

Otherwise you can spin it up with the following docker command:

```sh
docker run --name eden-genesis \
-v "$(pwd)":/app \
-w /app \
-p 8080:8080 -p 8888:8888 \
-d -it ghcr.io/eoscommunity/eden-builder:sub-chain \
bash ./eden_chain_runner.sh run-genesis.wasm 1
```

To see if the chain is running successfully you can execute `cleos get info` or watch the nodeos logs: `tail -fn +1 eden-runner.log`

With the ephemeral chain running you can just spin up our local environment with:

```sh
yarn
NODE_ENV=test yarn build --stream
NODE_ENV=test yarn start --stream
open http://localhost:3000
```

**Re-running ephemeral chains**

Running the above commands again will just setup a brand new chain! Just watch out to kill nodeos and unlock your keos wallet if built locally or remove your docker container. Also don't forget to restart the `yarn` environment because the blocks state needs to be refreshed.

In the above instructions we ran a simple genesis case with 3 inducted members, but you can also try `run-full-election.wasm` to see a community with more than 100 members with chief delegates already elected.
4 changes: 3 additions & 1 deletion contracts/eden/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_executable(eden
src/actions/migrate.cpp
src/actions/encrypt.cpp
src/actions/tables.cpp
src/actions/sessions.cpp
src/eden.cpp
src/events.cpp
src/accounts.cpp
Expand All @@ -32,6 +33,7 @@ add_executable(eden
src/encrypt.cpp
)
target_include_directories(eden PUBLIC include ../token/include PRIVATE ../../external/atomicassets-contract/include)
target_compile_options(eden PUBLIC -flto)
target_link_libraries(eden eosio-contract)
set_target_properties(eden PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ROOT_BINARY_DIR})

Expand Down Expand Up @@ -62,7 +64,7 @@ eden_tester_test(test-eden)

# Chain Runners
add_test_eden("run-genesis" "")
add_test_eden("run-full-election" "")
add_test_eden("run-elections" "")

file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/tests/data ${ROOT_BINARY_DIR}/eden-test-data SYMBOLIC)

Expand Down
106 changes: 76 additions & 30 deletions contracts/eden/include/eden.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

#include <constants.hpp>
#include <eden-atomicassets.hpp>
#include <eden_dispatcher.hpp>
#include <encrypt.hpp>
#include <eosio/asset.hpp>
#include <eosio/bytes.hpp>
#include <eosio/eosio.hpp>
#include <inductions.hpp>
#include <sessions.hpp>
#include <string>
#include <vector>

Expand Down Expand Up @@ -40,6 +42,9 @@ namespace eden
extern const char* peacetreaty_clause;
extern const char* bylaws_clause;

// Placeholder; the ABI generator redefines this
using verb = std::variant<int>;

#ifdef ENABLE_SET_TABLE_ROWS
using table_variant = boost::mp11::mp_append<account_variant,
auction_variant,
Expand Down Expand Up @@ -74,6 +79,17 @@ namespace eden
const eosio::asset& quantity,
std::string memo);

void newsession(eosio::name eden_account,
const eosio::public_key& key,
eosio::block_timestamp expiration,
const std::string& description);

void delsession(const eosio::not_in_abi<session_info>& current_session,
eosio::name eden_account,
const eosio::public_key& key);

void run(eosio::ignore<run_auth> auth, eosio::ignore<std::vector<verb>> verbs);

void withdraw(eosio::name owner, const eosio::asset& quantity);

void donate(eosio::name payer, const eosio::asset& quantity);
Expand All @@ -95,21 +111,33 @@ namespace eden

void clearall();

void inductinit(uint64_t id,
void inductinit(const eosio::not_in_abi<session_info>& current_session,
uint64_t id,
eosio::name inviter,
eosio::name invitee,
std::vector<eosio::name> witnesses);

void inductprofil(uint64_t id, new_member_profile new_member_profile);
void inductprofil(const eosio::not_in_abi<session_info>& current_session,
uint64_t id,
new_member_profile new_member_profile);

void inductvideo(eosio::name account, uint64_t id, std::string video);
void inductvideo(const eosio::not_in_abi<session_info>& current_session,
eosio::name account,
uint64_t id,
std::string video);

void inductendors(eosio::name account, uint64_t id, eosio::checksum256 induction_data_hash);
void inductendors(const eosio::not_in_abi<session_info>& current_session,
eosio::name account,
uint64_t id,
eosio::checksum256 induction_data_hash);

void inductdonate(eosio::name payer, uint64_t id, const eosio::asset& quantity);

void inductcancel(eosio::name account, uint64_t id);
void inductmeetin(eosio::name account,
void inductcancel(const eosio::not_in_abi<session_info>& current_session,
eosio::name account,
uint64_t id);
void inductmeetin(const eosio::not_in_abi<session_info>& current_session,
eosio::name account,
uint64_t id,
const std::vector<encrypted_key>& keys,
const eosio::bytes& data,
Expand All @@ -127,16 +155,25 @@ namespace eden
const std::string& election_time,
uint32_t round_duration_sec);

void electopt(eosio::name member, bool participating);
void electopt(const eosio::not_in_abi<session_info>& current_session,
eosio::name member,
bool participating);

void electseed(const eosio::bytes& btc_header);
void electmeeting(eosio::name account,
void electmeeting(const eosio::not_in_abi<session_info>& current_session,
eosio::name account,
uint8_t round,
const std::vector<encrypted_key>& keys,
const eosio::bytes& data,
const std::optional<eosio::bytes>& old_data);
void electvote(uint8_t round, eosio::name voter, eosio::name candidate);
void electvideo(uint8_t round, eosio::name voter, const std::string& video);
void electvote(const eosio::not_in_abi<session_info>& current_session,
uint8_t round,
eosio::name voter,
eosio::name candidate);
void electvideo(const eosio::not_in_abi<session_info>& current_session,
uint8_t round,
eosio::name voter,
const std::string& video);
void electprocess(uint32_t max_steps);

void distribute(uint32_t max_steps);
Expand Down Expand Up @@ -188,9 +225,12 @@ namespace eden
eosio::ignore<std::vector<eosio::asset>>);
};

EOSIO_ACTIONS(
EDEN_ACTIONS(
eden,
"eden.gm"_n,
action(newsession, eden_account, key, expiration, description),
eden_verb(delsession, 0, eden_account, key),
action(run, auth, verbs),
action(withdraw, owner, quantity, ricardian_contract(withdraw_ricardian)),
action(donate, owner, quantity),
action(fundtransfer, from, distribution_time, rank, to, amount, memo),
Expand All @@ -211,35 +251,41 @@ namespace eden
action(addtogenesis, account, expiration),
action(gensetexpire, id, new_expiration),
action(clearall, ricardian_contract(clearall_ricardian)),
action(inductinit,
id,
inviter,
invitee,
witnesses,
ricardian_contract(inductinit_ricardian)),
action(inductmeetin, account, id, keys, data, old_data),
action(inductprofil, id, new_member_profile, ricardian_contract(inductprofil_ricardian)),
action(inductvideo, account, id, video, ricardian_contract(inductvideo_ricardian)),
action(inductendors,
account,
id,
induction_data_hash,
ricardian_contract(inductendors_ricardian)),
eden_verb(inductinit,
10,
id,
inviter,
invitee,
witnesses,
ricardian_contract(inductinit_ricardian)),
eden_verb(inductmeetin, 1, account, id, keys, data, old_data),
eden_verb(inductprofil,
2,
id,
new_member_profile,
ricardian_contract(inductprofil_ricardian)),
eden_verb(inductvideo, 3, account, id, video, ricardian_contract(inductvideo_ricardian)),
eden_verb(inductendors,
4,
account,
id,
induction_data_hash,
ricardian_contract(inductendors_ricardian)),
action(setencpubkey, account, key),
action(electsettime, election_time),
action(electconfig, day, time, round_duration),
action(electopt, member, participating),
eden_verb(electopt, 5, member, participating),
action(electseed, btc_header),
action(electmeeting, account, round, keys, data, old_data),
action(electvote, round, voter, candidate),
action(electvideo, round, voter, video),
eden_verb(electmeeting, 6, account, round, keys, data, old_data),
eden_verb(electvote, 7, round, voter, candidate),
eden_verb(electvideo, 8, round, voter, video),
action(electprocess, max_steps),
action(bylawspropose, proposer, bylaws),
action(bylawsapprove, approver, bylaws_hash),
action(bylawsratify, approver, bylaws_hash),
action(distribute, max_steps),
action(inductdonate, payer, id, quantity, ricardian_contract(inductdonate_ricardian)),
action(inductcancel, account, id, ricardian_contract(inductcancel_ricardian)),
eden_verb(inductcancel, 9, account, id, ricardian_contract(inductcancel_ricardian)),
action(inducted, inductee, ricardian_contract(inducted_ricardian)),
action(resign, account),
action(gc, limit, ricardian_contract(gc_ricardian)),
Expand Down
20 changes: 20 additions & 0 deletions contracts/eden/include/eden_abi_generator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#define EOSIO_ABIGEN_ITEMeden_verbs(ns, variant_name, missing_struct_name) \
([&] { \
gen.def.structs.push_back(eosio::struct_def{missing_struct_name}); \
eosio::variant_def vdef{variant_name}; \
ns::for_each_verb([&](uint32_t index, const char* name, const auto&) { \
if (index >= vdef.types.size()) \
vdef.types.resize(index + 1, missing_struct_name); \
vdef.types[index] = name; \
}); \
auto& variants = gen.def.variants.value; \
auto it = std::find_if(variants.begin(), variants.end(), \
[&](auto& d) { return d.name == variant_name; }); \
if (it != variants.end()) \
*it = std::move(vdef); \
else \
variants.push_back(std::move(vdef)); \
})(); \
, 1
Loading

0 comments on commit 7167acc

Please sign in to comment.