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

Commit

Permalink
Merge pull request #36 from EOSIO/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
arhag authored Aug 1, 2018
2 parents 23659e4 + 44eb790 commit 7f1aae0
Show file tree
Hide file tree
Showing 30 changed files with 233 additions and 441 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
*.exe
*.out
*.app

build/*
27 changes: 17 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
cmake_minimum_required(VERSION 3.5)
project(eosio_contracts VERSION 1.1.1)
project(eosio_contracts VERSION 1.2.0)

set(EOSIO_DEPENDENCY "1.1")
set(EOSIO_WASMSDK_DEPENDENCY "1.1")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(TEST_BUILD_TYPE "Debug")
set(CMAKE_BUILD_TYPE "Release")
else()
set(TEST_BUILD_TYPE ${CMAKE_BUILD_TYPE})
endif()
if(CXX_COMPILER STREQUAL "" OR NOT CXX_COMPILER)
set(CXX_COMPILER ${CMAKE_CXX_COMPILER})
endif()

if(EOSIO_INSTALL_PREFIX STREQUAL "" OR NOT EOSIO_INSTALL_PREFIX)
set(EOSIO_INSTALL_PREFIX "/usr/local")
if(EOSIO_ROOT STREQUAL "" OR NOT EOSIO_ROOT)
set(EOSIO_ROOT "/usr/local/eosio")
endif()

# if no wasm root is given use default path
if(WASM_ROOT STREQUAL "" OR NOT WASM_ROOT)
set(WASM_ROOT ${CMAKE_INSTALL_PREFIX})
if(EOSIO_WASMSDK_ROOT STREQUAL "" OR NOT EOSIO_WASMSDK_ROOT)
set(EOSIO_WASMSDK_ROOT "/usr/local/eosio.wasmsdk")
endif()

list(APPEND CMAKE_MODULE_PATH ${WASM_ROOT}/lib/cmake)
list(APPEND CMAKE_MODULE_PATH ${EOSIO_WASMSDK_ROOT}/lib/cmake)
include(EosioWasmToolchain)

### Check the version of wasmsdk
string(FIND "${EOSIO_WASMSDK_VERSION}" "${EOSIO_WASMSDK_DEPENDENCY}" output)

if (NOT "${output}" EQUAL 0)
message(FATAL_ERROR "Incorrect EOSIO.WasmSDK version, please use version ${EOSIO_WASMSDK_DEPENDENCY}.x")
endif()

include_directories(AFTER ${BOOST_ROOT}/include)
add_subdirectory(eosio.msig)
add_subdirectory(eosio.sudo)
add_subdirectory(eosio.system)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# eosio.contracts

## Version : 1.1.1
## Version : 1.2.0

The design of the EOSIO blockchain calls for a number of smart contracts that are run at a privileged permission level in order to support functions such as block producer registration and voting, token staking for CPU and network bandwidth, RAM purchasing, multi-sig, etc. These smart contracts are referred to as the system, token, msig and sudo contracts.

Expand All @@ -14,8 +14,8 @@ The following unprivileged contract(s) are also part of the system.
* [eosio.token](https://github.com/eosio/eosio.contracts/tree/master/eosio.token)

Dependencies:
* [eosio v1.0.8](https://github.com/eosio/eos/tree/v1.0.8)
* [eosio.wasmsdk v1.0.0](https://github.com/eosio/eosio.wasmsdk/tree/v1.0.0)
* [eosio v1.1.2](https://github.com/eosio/eos/tree/v1.1.2)
* [eosio.wasmsdk v1.1.0](https://github.com/eosio/eosio.wasmsdk/tree/v1.1.0)

To build the contracts and the unit tests:
* First, ensure that your __eosio__ is compiled to the core symbol for the EOSIO blockchain that intend to deploy to.
Expand Down
4 changes: 2 additions & 2 deletions UnitTestsExternalProject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ include(GNUInstallDirs)

ExternalProject_Add(
contracts_unit_tests
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DROOT_DIR=${CMAKE_SOURCE_DIR} -DEOSIO_INSTALL_PREFIX=${EOSIO_INSTALL_PREFIX} -DOPENSSL_INSTALL_PREFIX=${OPENSSL_ROOT} -DSECP256K1_INSTALL_LIB=${SECP256K1_ROOT} -DBOOST_ROOT=${BOOST_ROOT}/include -DCMAKE_CXX_COMPILER=${CXX_COMPILER}
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DEOSIO_ROOT=${EOSIO_ROOT} -DEOSIO_DEPENDENCY=${EOSIO_DEPENDENCY}

SOURCE_DIR ${CMAKE_SOURCE_DIR}/tests
BINARY_DIR ${CMAKE_SOURCE_DIR}/build/tests
BINARY_DIR ${CMAKE_BINARY_DIR}/tests
BUILD_ALWAYS 1
TEST_COMMAND ""
INSTALL_COMMAND ""
Expand Down
51 changes: 1 addition & 50 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,9 @@ printf "\t=========== Building eosio.contracts ===========\n\n"
RED='\033[0;31m'
NC='\033[0m'

#if [ ! -d "/usr/local/eosio" ]; then
# printf "${RED}Error, please ensure that eosio is installed correctly!\n\n${NC}"
# exit -1
#fi

if [ ! -d "/usr/local/eosio.wasmsdk" ]; then
printf "${RED}Error, please ensure that eosio.wasmsdk is installed correctly!\n\n${NC}"
exit -1
fi

unamestr=`uname`
if [[ "${unamestr}" == 'Darwin' ]]; then
BOOST=/usr/local
CXX_COMPILER=g++
else
BOOST=~/opt/boost
OS_NAME=$( cat /etc/os-release | grep ^NAME | cut -d'=' -f2 | sed 's/\"//gI' )

case "$OS_NAME" in
"Amazon Linux AMI")
CXX_COMPILER=g++
C_COMPILER=gcc
;;
"CentOS Linux")
CXX_COMPILER=g++
C_COMPILER=gcc
;;
"elementary OS")
CXX_COMPILER=clang++-4.0
C_COMPILER=clang-4.0
;;
"Fedora")
CXX_COMPILER=g++
C_COMPILER=gcc
;;
"Linux Mint")
CXX_COMPILER=clang++-4.0
C_COMPILER=clang-4.0
;;
"Ubuntu")
CXX_COMPILER=clang++-4.0
C_COMPILER=clang-4.0
;;
*)
printf "\\n\\tUnsupported Linux Distribution. Exiting now.\\n\\n"
exit 1
esac
fi

CORES=`getconf _NPROCESSORS_ONLN`
mkdir -p build
pushd build &> /dev/null
cmake -DCXX_COMPILER="${CXX_COMPILER}" -DBOOST_ROOT="${BOOST}" -DEOSIO_INSTALL_PREFIX=/usr/local ../
cmake ../
make -j${CORES}
popd &> /dev/null
4 changes: 2 additions & 2 deletions eosio.msig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.msig.abi" "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.msig" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.msig.abi" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)

add_executable(eosio.msig.wasm ${CMAKE_CURRENT_SOURCE_DIR}/src/eosio.msig.cpp)
target_include_directories(eosio.msig.wasm
Expand All @@ -7,6 +7,6 @@ target_include_directories(eosio.msig.wasm

set_target_properties(eosio.msig.wasm
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.msig")
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${WASM_ROOT}/eosio.wasmsdk/include)
2 changes: 0 additions & 2 deletions eosio.msig/bin/eosio.msig/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions eosio.msig/build.sh

This file was deleted.

4 changes: 2 additions & 2 deletions eosio.sudo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ target_include_directories(eosio.sudo.wasm

set_target_properties(eosio.sudo.wasm
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.sudo")
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.sudo.abi" "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.sudo" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.sudo.abi" "${CMAKE__CURRENT_BINARY_DIR}" COPYONLY)
#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${WASM_ROOT}/eosio.wasmsdk/include)
2 changes: 0 additions & 2 deletions eosio.sudo/bin/eosio.sudo/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions eosio.sudo/build.sh

This file was deleted.

4 changes: 2 additions & 2 deletions eosio.system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ target_include_directories(eosio.system.wasm

set_target_properties(eosio.system.wasm
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.system")
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.system.abi" "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.system" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.system.abi" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)

#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${WASM_ROOT}/eosio.wasmsdk/include)
2 changes: 0 additions & 2 deletions eosio.system/bin/eosio.system/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions eosio.system/build.sh

This file was deleted.

17 changes: 9 additions & 8 deletions eosio.system/include/eosio.system/eosio.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ namespace eosiosystem {
struct eosio_global_state2 {
eosio_global_state2(){}

uint16_t new_ram_per_block = 0;
uint16_t new_ram_per_block = 0;
block_timestamp last_ram_increase;
block_timestamp last_block_num;
block_timestamp last_block_num; /* deprecated */
double reserved = 0;
uint8_t revision = 0; ///< used to track version updates in the future.

Expand Down Expand Up @@ -236,18 +236,19 @@ namespace eosiosystem {

void bidname( account_name bidder, account_name newname, asset bid );
private:
void update_elected_producers( block_timestamp timestamp );
void update_ram_supply();

// Implementation details:

//defind in delegate_bandwidth.cpp
//defined in eosio.system.cpp
static eosio_global_state get_default_parameters();
static block_timestamp current_block_time();
void update_ram_supply();

//defined in delegate_bandwidth.cpp
void changebw( account_name from, account_name receiver,
asset stake_net_quantity, asset stake_cpu_quantity, bool transfer );

//defined in voting.hpp
static eosio_global_state get_default_parameters();

void update_elected_producers( block_timestamp timestamp );
void update_votes( const account_name voter, const account_name proxy, const std::vector<account_name>& producers, bool voting );

// defined in voting.cpp
Expand Down
18 changes: 11 additions & 7 deletions eosio.system/src/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace eosiosystem {

static constexpr time refund_delay = 3*24*3600;
static constexpr time refund_expiration_time = 3600;
static constexpr int64_t ram_gift_bytes = 1400;

struct user_resources {
account_name owner;
Expand Down Expand Up @@ -86,7 +87,7 @@ namespace eosiosystem {
* This action will buy an exact amount of ram and bill the payer the current market price.
*/
void system_contract::buyrambytes( account_name payer, account_name receiver, uint32_t bytes ) {

auto itr = _rammarket.find(S(4,RAMCORE));
auto tmp = *itr;
auto eosout = tmp.convert( asset(bytes,S(0,RAM)), CORE_SYMBOL );
Expand Down Expand Up @@ -152,7 +153,7 @@ namespace eosiosystem {
res.ram_bytes += bytes_out;
});
}
set_resource_limits( res_itr->owner, res_itr->ram_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );
set_resource_limits( res_itr->owner, res_itr->ram_bytes + ram_gift_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );
}


Expand All @@ -179,7 +180,7 @@ namespace eosiosystem {
/// the cast to int64_t of bytes is safe because we certify bytes is <= quota which is limited by prior purchases
tokens_out = es.convert( asset(bytes,S(0,RAM)), CORE_SYMBOL);
});

eosio_assert( tokens_out.amount > 1, "token amount received from selling ram is too low" );

_gstate.total_ram_bytes_reserved -= static_cast<decltype(_gstate.total_ram_bytes_reserved)>(bytes); // bytes > 0 is asserted above
Expand All @@ -191,7 +192,7 @@ namespace eosiosystem {
userres.modify( res_itr, account, [&]( auto& res ) {
res.ram_bytes -= bytes;
});
set_resource_limits( res_itr->owner, res_itr->ram_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );
set_resource_limits( res_itr->owner, res_itr->ram_bytes + ram_gift_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );

INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {{N(eosio.ram),N(active)},{account,N(active)}},
{ N(eosio.ram), account, asset(tokens_out), std::string("sell ram") } );
Expand Down Expand Up @@ -270,7 +271,10 @@ namespace eosiosystem {
eosio_assert( asset(0) <= tot_itr->net_weight, "insufficient staked total net bandwidth" );
eosio_assert( asset(0) <= tot_itr->cpu_weight, "insufficient staked total cpu bandwidth" );

set_resource_limits( receiver, tot_itr->ram_bytes, tot_itr->net_weight.amount, tot_itr->cpu_weight.amount );
int64_t ram_bytes, net, cpu;
get_resource_limits( receiver, &ram_bytes, &net, &cpu );

set_resource_limits( receiver, std::max( tot_itr->ram_bytes + ram_gift_bytes, ram_bytes ), tot_itr->net_weight.amount, tot_itr->cpu_weight.amount );

if ( tot_itr->net_weight == asset(0) && tot_itr->cpu_weight == asset(0) && tot_itr->ram_bytes == 0 ) {
totals_tbl.erase( tot_itr );
Expand All @@ -286,8 +290,8 @@ namespace eosiosystem {
auto net_balance = stake_net_delta;
auto cpu_balance = stake_cpu_delta;
bool need_deferred_trx = false;


// net and cpu are same sign by assertions in delegatebw and undelegatebw
// redundant assertion also at start of changebw to protect against misuse of changebw
bool is_undelegating = (net_balance.amount + cpu_balance.amount ) < 0;
Expand Down
Loading

0 comments on commit 7f1aae0

Please sign in to comment.