Skip to content

Commit 11d828c

Browse files
Merge pull request #677 from gofractally/main
Updating production contract branch
2 parents 912f098 + d5fbc7e commit 11d828c

File tree

295 files changed

+8762
-16370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

295 files changed

+8762
-16370
lines changed

.github/workflows/build.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
build-cpp:
4242
name: Build C++
4343
runs-on: ubuntu-latest
44-
container: ghcr.io/eoscommunity/eden-builder:sub-chain
44+
container: ghcr.io/gofractally/eden-builder:latest
4545

4646
steps:
4747
- name: ✅ Checkout code
@@ -115,19 +115,20 @@ jobs:
115115
116116
tar czf clsdk-ubuntu-20-04.tar.gz clsdk
117117
rm -rf ../product_cache
118-
mkdir -p ../product_cache
118+
mkdir -p ../product_cache/clsdk/contracts
119119
cp clsdk-ubuntu-20-04.tar.gz ../product_cache
120120
cp atomicassets.abi ../product_cache
121121
cp atomicassets.wasm ../product_cache
122122
cp atomicmarket.abi ../product_cache
123123
cp atomicmarket.wasm ../product_cache
124-
cp bios.wasm ../product_cache
124+
cp clsdk/contracts/bios.wasm ../product_cache/clsdk/contracts/bios.wasm
125125
cp boot.wasm ../product_cache
126126
cp eden-micro-chain.wasm ../product_cache
127127
cp eden.abi ../product_cache
128128
cp eden.wasm ../product_cache
129-
cp run-full-election.wasm ../product_cache
129+
cp run-elections.wasm ../product_cache
130130
cp run-genesis.wasm ../product_cache
131+
cp run-complete-elections.wasm ../product_cache
131132
cp token.abi ../product_cache
132133
cp token.wasm ../product_cache
133134
@@ -174,19 +175,20 @@ jobs:
174175
product_cache/atomicassets.wasm
175176
product_cache/atomicmarket.abi
176177
product_cache/atomicmarket.wasm
177-
product_cache/bios.wasm
178+
product_cache/clsdk/contracts/bios.wasm
178179
product_cache/boot.wasm
179180
product_cache/eden.abi
180181
product_cache/eden.wasm
181182
product_cache/token.abi
182183
product_cache/token.wasm
183184
product_cache/run-genesis.wasm
184-
product_cache/run-full-election.wasm
185+
product_cache/run-elections.wasm
186+
product_cache/run-complete-elections.wasm
185187
186188
build-micro-chain:
187189
name: Build Micro Chain
188190
runs-on: ubuntu-latest
189-
container: ghcr.io/eoscommunity/eden-builder:sub-chain
191+
container: ghcr.io/gofractally/eden-builder:latest
190192

191193
steps:
192194
- name: ✅ Checkout code
@@ -353,6 +355,7 @@ jobs:
353355
- "tsconfig.build.json"
354356
- "tsconfig.json"
355357
- "yarn.lock"
358+
- "scripts/eden_chain_runner.sh"
356359
357360
- "packages/**"
358361
- "contracts/**"
@@ -364,7 +367,7 @@ jobs:
364367
name: Eden Microchain
365368
path: build
366369

367-
- name: Download Ephemeral Chain Runners
370+
- name: Download Ephemeral Eden Chain Runners
368371
if: steps.filter.outputs.src == 'true'
369372
uses: actions/download-artifact@v2
370373
with:

.github/workflows/eden-builder.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: eden-builder container
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- main
@@ -27,7 +28,7 @@ jobs:
2728
REGISTRY="ghcr.io"
2829
IMAGE="${REGISTRY}/${{ github.repository_owner }}/eden-builder"
2930
TAGS="${IMAGE}:${{ github.sha }}"
30-
if [[ $GITHUB_REF == ref/head/master ]]; then
31+
if [[ $GITHUB_REF == ref/head/main ]]; then
3132
TAGS="${TAGS},${IMAGE}:latest"
3233
fi
3334
echo ::set-output name=tags::${TAGS,,}

.gitmodules

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
url = https://github.com/Tencent/rapidjson.git
44
[submodule "external/eos"]
55
path = external/eos
6-
url = https://github.com/eoscommunity/eos.git
6+
url = https://github.com/eosnetworkfoundation/mandel.git
77
[submodule "external/fmt"]
88
path = external/fmt
99
url = https://github.com/fmtlib/fmt.git
1010
[submodule "external/Catch2"]
1111
path = external/Catch2
1212
url = https://github.com/catchorg/Catch2.git
13-
[submodule "external/rocksdb"]
14-
path = external/rocksdb
15-
url = https://github.com/facebook/rocksdb.git
1613
[submodule "external/atomicassets-contract"]
1714
path = external/atomicassets-contract
1815
url = https://github.com/pinknetworkx/atomicassets-contract.git

README.md

+61
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,64 @@ wget https://nodejs.org/dist/v14.16.0/node-v14.16.0-linux-x64.tar.xz
6161
tar xf node-v14.16.0-linux-x64.tar.xz
6262
npm i -g yarn
6363
```
64+
65+
### Running Eden with Ephemeral Chains Locally
66+
67+
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), [Elections Runner](contracts/eden/tests/run-elections.cpp) (which finishes with an open, running election), and [Completed Elections Runner](contracts/eden/tests/run-complete-elections.cpp). By running a ephemeral chain you are in full control of the blockchain, giving you more flexibility to test the Eden contracts.
68+
69+
#### Get the executables
70+
71+
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).
72+
73+
If you built locally, you can skip these steps.
74+
75+
**Downloading the executables**
76+
77+
- Open our [main branch builds](https://github.com/eoscommunity/Eden/actions/workflows/build.yml?query=branch%3Amain).
78+
- Click in the most recent successful one
79+
- Scroll down to the artifacts section
80+
- Download the following files:
81+
- Eden Microchain
82+
- Ephemeral Eden Chains Runners
83+
- clsdk
84+
- From the root of this repo, run the following commands:
85+
86+
```sh
87+
mkdir build
88+
# unzip all of the above artifact files in this build folder
89+
cd build
90+
tar -xvf clsdk-ubuntu-20-04.tar.gz clsdk/bin
91+
cp ../scripts/eden_chain_runner.sh ./
92+
```
93+
94+
Now you have all the files needed for running the ephemeral chain inside the `build` folder.
95+
96+
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`
97+
98+
Otherwise you can spin it up with the following docker command:
99+
100+
```sh
101+
docker run --name eden-genesis \
102+
-v "$(pwd)":/app \
103+
-w /app \
104+
-p 8080:8080 -p 8888:8888 \
105+
-d -it ghcr.io/eoscommunity/eden-builder:sub-chain \
106+
bash ./eden_chain_runner.sh run-genesis.wasm 1
107+
```
108+
109+
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`
110+
111+
With the ephemeral chain running you can just spin up our local environment with:
112+
113+
```sh
114+
yarn
115+
NODE_ENV=test yarn build --stream
116+
NODE_ENV=test yarn start --stream
117+
open http://localhost:3000
118+
```
119+
120+
**Re-running ephemeral chains**
121+
122+
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.
123+
124+
In the above instructions we ran a simple genesis case with 3 inducted members, but you can also try `run-complete-elections.wasm` to see a community with more than 100 members with chief delegates already elected.

contracts/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ add_subdirectory(eden)
22
add_subdirectory(token)
33
add_subdirectory(boot)
44
add_subdirectory(bios)
5+
add_subdirectory(bios2)
6+
add_subdirectory(bios3)

contracts/bios/CMakeLists.txt

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
add_executable(bios src/bios.cpp)
22
target_include_directories(bios PUBLIC include)
33
target_link_libraries(bios eosio-contract-simple-malloc)
4-
set_target_properties(bios PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ROOT_BINARY_DIR})
4+
set_target_properties(bios PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ROOT_BINARY_DIR}/clsdk/contracts)
5+
6+
add_executable(bios-abigen src/bios.cpp)
7+
target_include_directories(bios-abigen PUBLIC include)
8+
target_link_libraries(bios-abigen eosio-contract-abigen)
9+
add_custom_command(TARGET bios-abigen POST_BUILD
10+
COMMAND mkdir -p ${ROOT_BINARY_DIR}/clsdk/contracts
11+
COMMAND ${ROOT_BINARY_DIR}/cltester bios-abigen.wasm >${ROOT_BINARY_DIR}/clsdk/contracts/bios.abi
12+
)
13+
14+
configure_file(include/bios/bios.hpp ${ROOT_BINARY_DIR}/clsdk/contracts/bios/include/bios/bios.hpp COPYONLY)
15+
configure_file(src/bios.cpp ${ROOT_BINARY_DIR}/clsdk/contracts/bios/src/bios.cpp COPYONLY)

contracts/bios/include/bios/bios.hpp

+133-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,149 @@
11
#pragma once
22

3+
#include <eosio/bytes.hpp>
34
#include <eosio/contract.hpp>
45
#include <eosio/dispatcher.hpp>
6+
#include <eosio/multi_index.hpp>
57
#include <eosio/privileged.hpp>
68

9+
#if defined(COMPILING_TESTS)
10+
#include <eosio/tester.hpp>
11+
#endif
12+
713
namespace bios
814
{
15+
struct abi_hash
16+
{
17+
eosio::name owner;
18+
eosio::checksum256 hash;
19+
20+
uint64_t primary_key() const { return owner.value; }
21+
};
22+
EOSIO_REFLECT(abi_hash, owner, hash)
23+
24+
typedef eosio::multi_index<"abihash"_n, abi_hash> abi_hash_table;
25+
926
class bios_contract : public eosio::contract
1027
{
1128
public:
1229
using eosio::contract::contract;
13-
void newaccount() {}
14-
void updateauth() {}
15-
void deleteauth() {}
16-
void linkauth() {}
17-
void setcode() {}
18-
void setabi() {}
19-
void canceldelay() {}
20-
void setpriv(eosio::name account, bool is_priv) { eosio::set_privileged(account, is_priv); }
30+
31+
void onblock() {}
32+
33+
void newaccount(eosio::ignore<eosio::name> creator,
34+
eosio::ignore<eosio::name> name,
35+
eosio::ignore<eosio::authority> owner,
36+
eosio::ignore<eosio::authority> active)
37+
{
38+
}
39+
40+
void updateauth(eosio::ignore<eosio::name> account,
41+
eosio::ignore<eosio::name> permission,
42+
eosio::ignore<eosio::name> parent,
43+
eosio::ignore<eosio::authority> auth)
44+
{
45+
}
46+
47+
void deleteauth(eosio::ignore<eosio::name> account, eosio::ignore<eosio::name> permission) {}
48+
49+
void linkauth(eosio::ignore<eosio::name> account,
50+
eosio::ignore<eosio::name> code,
51+
eosio::ignore<eosio::name> type,
52+
eosio::ignore<eosio::name> requirement)
53+
{
54+
}
55+
56+
void unlinkauth(eosio::ignore<eosio::name> account,
57+
eosio::ignore<eosio::name> code,
58+
eosio::ignore<eosio::name> type)
59+
{
60+
}
61+
62+
void canceldelay(eosio::ignore<eosio::permission_level> canceling_auth,
63+
eosio::ignore<eosio::checksum256> trx_id)
64+
{
65+
}
66+
67+
void setcode(eosio::ignore<eosio::name> account,
68+
eosio::ignore<uint8_t> vmtype,
69+
eosio::ignore<uint8_t> vmversion,
70+
eosio::ignore<eosio::bytes> code)
71+
{
72+
}
73+
74+
void setabi(eosio::name account, const eosio::bytes& abi);
75+
76+
/**
77+
* Set privilege status for an account
78+
*/
79+
void setpriv(eosio::name account, bool is_priv);
80+
81+
/**
82+
* Set the resource limits of an account
83+
*
84+
* @param account - eosio::name of the account whose resource limit to be set
85+
* @param ram_bytes - ram limit in absolute bytes
86+
* @param net_weight - fractionally proportionate net limit of available resources based on (weight / total_weight_of_all_accounts)
87+
* @param cpu_weight - fractionally proportionate cpu limit of available resources based on (weight / total_weight_of_all_accounts)
88+
*/
89+
void setalimits(eosio::name account,
90+
int64_t ram_bytes,
91+
int64_t net_weight,
92+
int64_t cpu_weight);
93+
94+
/**
95+
* Set the blockchain parameters.
96+
*/
97+
void setparams(const eosio::blockchain_parameters& params);
98+
99+
/**
100+
* Check if the account eosio::name `from` passed in as param has authorization to access
101+
* current action, that is, if it is listed in the action’s allowed permissions vector.
102+
*
103+
* @param from - the account eosio::name to authorize
104+
*/
105+
void reqauth(eosio::name from);
106+
107+
/**
108+
* Activate a protocol feature
109+
*
110+
* @param feature_digest - hash of the protocol feature to activate.
111+
*/
112+
void activate(const eosio::checksum256& feature_digest);
113+
114+
/**
115+
* Assert that a protocol feature has been activated
116+
*
117+
* @param feature_digest - hash of the protocol feature to check for activation.
118+
*/
119+
void reqactivated(const eosio::checksum256& feature_digest);
21120
};
22121
EOSIO_ACTIONS(bios_contract,
23122
"eosio"_n,
24-
newaccount,
25-
updateauth,
26-
deleteauth,
27-
linkauth,
28-
setcode,
29-
setabi,
30-
canceldelay,
31-
setpriv)
123+
action(onblock),
124+
action(newaccount, creator, name, owner, active),
125+
action(updateauth, account, permission, parent, auth),
126+
action(deleteauth, account, permission),
127+
action(linkauth, account, code, type, requirement),
128+
action(unlinkauth, account, code, type),
129+
action(canceldelay, canceling_auth, trx_id),
130+
action(setcode, account, vmtype, vmversion, code),
131+
action(setabi, account, abi),
132+
action(setpriv, account, is_priv),
133+
action(setalimits, account, ram_bytes, net_weight, cpu_weight),
134+
action(setparams, params),
135+
action(reqauth, from),
136+
action(activate, feature_digest),
137+
action(reqactivated, feature_digest))
138+
139+
#if defined(COMPILING_TESTS)
140+
void activate(eosio::test_chain& chain, const std::vector<eosio::checksum256>& features)
141+
{
142+
for (auto& feature : features)
143+
chain.as("eosio"_n).act<actions::activate>(feature);
144+
chain.finish_block();
145+
chain.finish_block();
146+
}
147+
#endif
148+
32149
} // namespace bios

0 commit comments

Comments
 (0)