Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Remmeauth/remprotocol in…
Browse files Browse the repository at this point in the history
…to develop-v2.0.0-rc2
  • Loading branch information
Artem Saprykin committed Dec 4, 2019
2 parents 3d5f15b + c3815b7 commit 9061673
Show file tree
Hide file tree
Showing 9 changed files with 981 additions and 297 deletions.
5 changes: 5 additions & 0 deletions contracts/contracts/rem.auth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ target_include_directories(rem.auth
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../rem.token/include)

target_include_directories(rem.auth
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../rem.swap/src)

target_include_directories(rem.auth
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include)
Expand Down
12 changes: 7 additions & 5 deletions contracts/contracts/rem.auth/src/rem.auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
*/

#include <rem.auth/rem.auth.hpp>
#include <../../rem.swap/src/base58.cpp> // TODO: fix includes
#include <rem.system/rem.system.hpp>
#include <rem.token/rem.token.hpp>

#include <base58.cpp>

namespace eosio {
using eosiosystem::system_contract;

Expand Down Expand Up @@ -140,16 +141,17 @@ namespace eosio {
require_auth(account);
check(quantity.is_valid(), "invalid quantity");
check(quantity.amount > 0, "quantity should be a positive value");
check(max_price > 0, "maximum price should be a positive value");
check(quantity.symbol == auth_symbol, "symbol precision mismatch");

double remusd = get_market_price("rem.usd"_n);

check(max_price > remusd, "currently rem-usd price is above maximum price");
asset purchase_fee = get_authrem_price(quantity);

transfer_tokens(account, get_self(), purchase_fee, "purchase fee AUTH tokens");
transfer_tokens(account, get_self(), purchase_fee, "purchase fee AUTH credits");
issue_tokens(quantity);
transfer_tokens(get_self(), account, quantity, "buying an auth token");
transfer_tokens(get_self(), account, quantity, "buying an AUTH credits");
}

void auth::sub_storage_fee(const name &account, const asset &price_limit)
Expand All @@ -174,7 +176,7 @@ namespace eosio {
transfer_tokens(account, get_self(), authrem_price, "purchase fee REM tokens");
} else {
check(auth_credit_supply.amount > 0, "overdrawn balance");
transfer_tokens(account, get_self(), key_store_price, "purchase fee AUTH tokens");
transfer_tokens(account, get_self(), key_store_price, "purchase fee AUTH credits");
retire_tokens(key_store_price);
}

Expand Down Expand Up @@ -219,7 +221,7 @@ namespace eosio {
void auth::issue_tokens(const asset &quantity)
{
token::issue_action issue(system_contract::token_account, {get_self(), system_contract::active_permission});
issue.send(get_self(), quantity, string("buy auth tokens"));
issue.send(get_self(), quantity, string("buy AUTH credits"));
}

void auth::retire_tokens(const asset &quantity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,15 @@ namespace eosiosystem {
[[eosio::action]]
void setunloperiod( uint64_t period_in_days);

[[eosio::action]]
void setinacttime( uint64_t period_in_minutes );

[[eosio::action]]
void setpnshperiod( uint64_t period_in_days );

[[eosio::action]]
void punishprod( const name& producer );


// Actions:
/**
Expand Down
23 changes: 22 additions & 1 deletion contracts/contracts/rem.system/src/producer_pay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,17 @@ namespace eosiosystem {
}

if (schedule_version > _gstate.last_schedule_version) {
std::vector<name> active_producers = eosio::get_active_producers();
for (size_t producer_index = 0; producer_index < _gstate.last_schedule.size(); producer_index++) {
const auto producer_name = _gstate.last_schedule[producer_index].first;
const auto& prod = _producers.get(producer_name.value);

if( std::find(active_producers.begin(), active_producers.end(), producer_name) == active_producers.end() ) {
_producers.modify(prod, same_payer, [&](auto& p) {
p.top21_chosen_time = time_point(eosio::seconds(0));
});
}

//blocks from full rounds
const auto full_rounds_passed = (timestamp.slot - prod.last_expected_produced_blocks_update.slot) / blocks_per_round;
uint32_t expected_produced_blocks = full_rounds_passed * producer_repetitions;
Expand Down Expand Up @@ -181,7 +189,20 @@ namespace eosiosystem {

_gstate.current_round_start_time = timestamp;
_gstate.last_schedule_version = schedule_version;
std::vector<name> active_producers = eosio::get_active_producers();

for (size_t i = 0; i < active_producers.size(); i++) {
const auto& prod_name = active_producers[i];
const auto& prod = _producers.get(prod_name.value);
auto res = std::find_if(_gstate.last_schedule.begin(),
_gstate.last_schedule.end(),
[&prod_name](const std::pair<eosio::name, double>& element){ return element.first == prod_name;});
if( res == _gstate.last_schedule.end() ) {
_producers.modify(prod, same_payer, [&](auto& p) {
p.top21_chosen_time = current_time_point();
});
}
}

if (active_producers.size() != _gstate.last_schedule.size()) {
_gstate.last_schedule.resize(active_producers.size());
}
Expand Down
31 changes: 31 additions & 0 deletions contracts/contracts/rem.system/src/rem.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ namespace eosiosystem {
_gremstate.per_vote_share = vote_share;
}

void system_contract::setinacttime( uint64_t period_in_minutes ) {
require_auth(get_self());

check(period_in_minutes != 0, "block producer maximum inactivity time cannot be zero");
_gremstate.producer_max_inactivity_time = eosio::minutes(period_in_minutes);
}

void system_contract::setpnshperiod( uint64_t period_in_days ) {
require_auth(get_self());

check(period_in_days != 0, "punishment period cannot be zero");
_gremstate.producer_inactivity_punishment_period = eosio::days(period_in_days);
}

void system_contract::setlockperiod( uint64_t period_in_days ) {
require_auth(get_self());

Expand Down Expand Up @@ -216,6 +230,23 @@ namespace eosiosystem {
});
}

void system_contract::punishprod( const name& producer ) {
auto prod = _producers.find( producer.value );
check( prod != _producers.end(), "producer not found" );

const auto ct = current_time_point();
check( prod->active() && prod->top21_chosen_time != time_point(eosio::seconds(0)), "can only punish top21 active producers" );

check( ct - prod->last_block_time >= _gremstate.producer_max_inactivity_time, "not enough inactivity to punish producer" );
check( ct - prod->top21_chosen_time >= _gremstate.producer_max_inactivity_time, "not enough inactivity to punish producer" );

_producers.modify( prod, same_payer, [&](auto& p) {
p.punished_until = ct + _gremstate.producer_inactivity_punishment_period;
p.top21_chosen_time = time_point(eosio::seconds(0));
p.deactivate();
});
}

void system_contract::updtrevision( uint8_t revision ) {
require_auth( get_self() );
check( _gstate2.revision < 255, "can not increment revision" ); // prevent wrap around
Expand Down
1 change: 1 addition & 0 deletions contracts/contracts/rem.system/src/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace eosiosystem {
}, producer_authority );

if ( prod != _producers.end() ) {
check( ct > prod->punished_until, "can not register producer during punishment period" );
_producers.modify( prod, producer, [&]( producer_info& info ){
info.producer_key = producer_key;
info.is_active = true;
Expand Down
Loading

0 comments on commit 9061673

Please sign in to comment.