Skip to content

Commit

Permalink
Merge pull request #676 from gofractally/main
Browse files Browse the repository at this point in the history
EdenOS Release 0.3
  • Loading branch information
brandonfancher authored Mar 21, 2022
2 parents 7167acc + d5fbc7e commit ea8f445
Show file tree
Hide file tree
Showing 181 changed files with 4,306 additions and 15,268 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
build-cpp:
name: Build C++
runs-on: ubuntu-latest
container: ghcr.io/eoscommunity/eden-builder:sub-chain
container: ghcr.io/gofractally/eden-builder:latest

steps:
- name: ✅ Checkout code
Expand Down Expand Up @@ -115,19 +115,20 @@ jobs:
tar czf clsdk-ubuntu-20-04.tar.gz clsdk
rm -rf ../product_cache
mkdir -p ../product_cache
mkdir -p ../product_cache/clsdk/contracts
cp clsdk-ubuntu-20-04.tar.gz ../product_cache
cp atomicassets.abi ../product_cache
cp atomicassets.wasm ../product_cache
cp atomicmarket.abi ../product_cache
cp atomicmarket.wasm ../product_cache
cp bios.wasm ../product_cache
cp clsdk/contracts/bios.wasm ../product_cache/clsdk/contracts/bios.wasm
cp boot.wasm ../product_cache
cp eden-micro-chain.wasm ../product_cache
cp eden.abi ../product_cache
cp eden.wasm ../product_cache
cp run-elections.wasm ../product_cache
cp run-genesis.wasm ../product_cache
cp run-complete-elections.wasm ../product_cache
cp token.abi ../product_cache
cp token.wasm ../product_cache
Expand Down Expand Up @@ -174,19 +175,20 @@ jobs:
product_cache/atomicassets.wasm
product_cache/atomicmarket.abi
product_cache/atomicmarket.wasm
product_cache/bios.wasm
product_cache/clsdk/contracts/bios.wasm
product_cache/boot.wasm
product_cache/eden.abi
product_cache/eden.wasm
product_cache/token.abi
product_cache/token.wasm
product_cache/run-genesis.wasm
product_cache/run-elections.wasm
product_cache/run-complete-elections.wasm
build-micro-chain:
name: Build Micro Chain
runs-on: ubuntu-latest
container: ghcr.io/eoscommunity/eden-builder:sub-chain
container: ghcr.io/gofractally/eden-builder:latest

steps:
- name: ✅ Checkout code
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/eden-builder.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: eden-builder container

on:
workflow_dispatch:
push:
branches:
- main
Expand All @@ -27,7 +28,7 @@ jobs:
REGISTRY="ghcr.io"
IMAGE="${REGISTRY}/${{ github.repository_owner }}/eden-builder"
TAGS="${IMAGE}:${{ github.sha }}"
if [[ $GITHUB_REF == ref/head/master ]]; then
if [[ $GITHUB_REF == ref/head/main ]]; then
TAGS="${TAGS},${IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS,,}
Expand Down
5 changes: 1 addition & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
url = https://github.com/Tencent/rapidjson.git
[submodule "external/eos"]
path = external/eos
url = https://github.com/eoscommunity/eos.git
url = https://github.com/eosnetworkfoundation/mandel.git
[submodule "external/fmt"]
path = external/fmt
url = https://github.com/fmtlib/fmt.git
[submodule "external/Catch2"]
path = external/Catch2
url = https://github.com/catchorg/Catch2.git
[submodule "external/rocksdb"]
path = external/rocksdb
url = https://github.com/facebook/rocksdb.git
[submodule "external/atomicassets-contract"]
path = external/atomicassets-contract
url = https://github.com/pinknetworkx/atomicassets-contract.git
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ 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.
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.

#### Get the executables

Expand Down Expand Up @@ -121,4 +121,4 @@ open http://localhost:3000

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.
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.
2 changes: 2 additions & 0 deletions contracts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ add_subdirectory(eden)
add_subdirectory(token)
add_subdirectory(boot)
add_subdirectory(bios)
add_subdirectory(bios2)
add_subdirectory(bios3)
13 changes: 12 additions & 1 deletion contracts/bios/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
add_executable(bios src/bios.cpp)
target_include_directories(bios PUBLIC include)
target_link_libraries(bios eosio-contract-simple-malloc)
set_target_properties(bios PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ROOT_BINARY_DIR})
set_target_properties(bios PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ROOT_BINARY_DIR}/clsdk/contracts)

add_executable(bios-abigen src/bios.cpp)
target_include_directories(bios-abigen PUBLIC include)
target_link_libraries(bios-abigen eosio-contract-abigen)
add_custom_command(TARGET bios-abigen POST_BUILD
COMMAND mkdir -p ${ROOT_BINARY_DIR}/clsdk/contracts
COMMAND ${ROOT_BINARY_DIR}/cltester bios-abigen.wasm >${ROOT_BINARY_DIR}/clsdk/contracts/bios.abi
)

configure_file(include/bios/bios.hpp ${ROOT_BINARY_DIR}/clsdk/contracts/bios/include/bios/bios.hpp COPYONLY)
configure_file(src/bios.cpp ${ROOT_BINARY_DIR}/clsdk/contracts/bios/src/bios.cpp COPYONLY)
149 changes: 133 additions & 16 deletions contracts/bios/include/bios/bios.hpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,149 @@
#pragma once

#include <eosio/bytes.hpp>
#include <eosio/contract.hpp>
#include <eosio/dispatcher.hpp>
#include <eosio/multi_index.hpp>
#include <eosio/privileged.hpp>

#if defined(COMPILING_TESTS)
#include <eosio/tester.hpp>
#endif

namespace bios
{
struct abi_hash
{
eosio::name owner;
eosio::checksum256 hash;

uint64_t primary_key() const { return owner.value; }
};
EOSIO_REFLECT(abi_hash, owner, hash)

typedef eosio::multi_index<"abihash"_n, abi_hash> abi_hash_table;

class bios_contract : public eosio::contract
{
public:
using eosio::contract::contract;
void newaccount() {}
void updateauth() {}
void deleteauth() {}
void linkauth() {}
void setcode() {}
void setabi() {}
void canceldelay() {}
void setpriv(eosio::name account, bool is_priv) { eosio::set_privileged(account, is_priv); }

void onblock() {}

void newaccount(eosio::ignore<eosio::name> creator,
eosio::ignore<eosio::name> name,
eosio::ignore<eosio::authority> owner,
eosio::ignore<eosio::authority> active)
{
}

void updateauth(eosio::ignore<eosio::name> account,
eosio::ignore<eosio::name> permission,
eosio::ignore<eosio::name> parent,
eosio::ignore<eosio::authority> auth)
{
}

void deleteauth(eosio::ignore<eosio::name> account, eosio::ignore<eosio::name> permission) {}

void linkauth(eosio::ignore<eosio::name> account,
eosio::ignore<eosio::name> code,
eosio::ignore<eosio::name> type,
eosio::ignore<eosio::name> requirement)
{
}

void unlinkauth(eosio::ignore<eosio::name> account,
eosio::ignore<eosio::name> code,
eosio::ignore<eosio::name> type)
{
}

void canceldelay(eosio::ignore<eosio::permission_level> canceling_auth,
eosio::ignore<eosio::checksum256> trx_id)
{
}

void setcode(eosio::ignore<eosio::name> account,
eosio::ignore<uint8_t> vmtype,
eosio::ignore<uint8_t> vmversion,
eosio::ignore<eosio::bytes> code)
{
}

void setabi(eosio::name account, const eosio::bytes& abi);

/**
* Set privilege status for an account
*/
void setpriv(eosio::name account, bool is_priv);

/**
* Set the resource limits of an account
*
* @param account - eosio::name of the account whose resource limit to be set
* @param ram_bytes - ram limit in absolute bytes
* @param net_weight - fractionally proportionate net limit of available resources based on (weight / total_weight_of_all_accounts)
* @param cpu_weight - fractionally proportionate cpu limit of available resources based on (weight / total_weight_of_all_accounts)
*/
void setalimits(eosio::name account,
int64_t ram_bytes,
int64_t net_weight,
int64_t cpu_weight);

/**
* Set the blockchain parameters.
*/
void setparams(const eosio::blockchain_parameters& params);

/**
* Check if the account eosio::name `from` passed in as param has authorization to access
* current action, that is, if it is listed in the action’s allowed permissions vector.
*
* @param from - the account eosio::name to authorize
*/
void reqauth(eosio::name from);

/**
* Activate a protocol feature
*
* @param feature_digest - hash of the protocol feature to activate.
*/
void activate(const eosio::checksum256& feature_digest);

/**
* Assert that a protocol feature has been activated
*
* @param feature_digest - hash of the protocol feature to check for activation.
*/
void reqactivated(const eosio::checksum256& feature_digest);
};
EOSIO_ACTIONS(bios_contract,
"eosio"_n,
newaccount,
updateauth,
deleteauth,
linkauth,
setcode,
setabi,
canceldelay,
setpriv)
action(onblock),
action(newaccount, creator, name, owner, active),
action(updateauth, account, permission, parent, auth),
action(deleteauth, account, permission),
action(linkauth, account, code, type, requirement),
action(unlinkauth, account, code, type),
action(canceldelay, canceling_auth, trx_id),
action(setcode, account, vmtype, vmversion, code),
action(setabi, account, abi),
action(setpriv, account, is_priv),
action(setalimits, account, ram_bytes, net_weight, cpu_weight),
action(setparams, params),
action(reqauth, from),
action(activate, feature_digest),
action(reqactivated, feature_digest))

#if defined(COMPILING_TESTS)
void activate(eosio::test_chain& chain, const std::vector<eosio::checksum256>& features)
{
for (auto& feature : features)
chain.as("eosio"_n).act<actions::activate>(feature);
chain.finish_block();
chain.finish_block();
}
#endif

} // namespace bios
59 changes: 59 additions & 0 deletions contracts/bios/src/bios.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
#include <bios/bios.hpp>
#include <eosio/abi_generator.hpp>

namespace bios
{
void bios_contract::setabi(eosio::name account, const eosio::bytes& abi)
{
abi_hash_table table(get_self(), get_self().value);
auto itr = table.find(account.value);
if (itr == table.end())
{
table.emplace(account, [&](auto& row) {
row.owner = account;
row.hash = eosio::sha256(const_cast<char*>(abi.data.data()), abi.data.size());
});
}
else
{
table.modify(itr, eosio::same_payer, [&](auto& row) {
row.hash = eosio::sha256(const_cast<char*>(abi.data.data()), abi.data.size());
});
}
}

void bios_contract::setpriv(eosio::name account, bool is_priv)
{
require_auth(get_self());
set_privileged(account, is_priv);
}

void bios_contract::setalimits(eosio::name account,
int64_t ram_bytes,
int64_t net_weight,
int64_t cpu_weight)
{
require_auth(get_self());
set_resource_limits(account, ram_bytes, net_weight, cpu_weight);
}

void bios_contract::setparams(const eosio::blockchain_parameters& params)
{
require_auth(get_self());
set_blockchain_parameters(params);
}

void bios_contract::reqauth(eosio::name from) { require_auth(from); }

void bios_contract::activate(const eosio::checksum256& feature_digest)
{
require_auth(get_self());
preactivate_feature(feature_digest);
}

void bios_contract::reqactivated(const eosio::checksum256& feature_digest)
{
eosio::check(eosio::is_feature_activated(feature_digest),
"protocol feature is not activated");
}
} // namespace bios

EOSIO_ACTION_DISPATCHER(bios::actions)
EOSIO_ABIGEN(actions(bios::actions), table("abihash"_n, bios::abi_hash))
15 changes: 15 additions & 0 deletions contracts/bios2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
add_executable(bios2 src/bios2.cpp)
target_include_directories(bios2 PUBLIC include)
target_link_libraries(bios2 eosio-contract-simple-malloc)
set_target_properties(bios2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ROOT_BINARY_DIR}/clsdk/contracts)

add_executable(bios2-abigen src/bios2.cpp)
target_include_directories(bios2-abigen PUBLIC include)
target_link_libraries(bios2-abigen eosio-contract-abigen)
add_custom_command(TARGET bios2-abigen POST_BUILD
COMMAND mkdir -p ${ROOT_BINARY_DIR}/clsdk/contracts
COMMAND ${ROOT_BINARY_DIR}/cltester bios2-abigen.wasm >${ROOT_BINARY_DIR}/clsdk/contracts/bios2.abi
)

configure_file(include/bios2/bios2.hpp ${ROOT_BINARY_DIR}/clsdk/contracts/bios2/include/bios2/bios2.hpp COPYONLY)
configure_file(src/bios2.cpp ${ROOT_BINARY_DIR}/clsdk/contracts/bios2/src/bios2.cpp COPYONLY)
Loading

0 comments on commit ea8f445

Please sign in to comment.