Skip to content

Commit

Permalink
Merge pull request EOSIO#145 from enumivo/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Enumivo authored May 24, 2018
2 parents 2a75e38 + 9cda8cf commit 2c55fbb
Show file tree
Hide file tree
Showing 52 changed files with 947 additions and 337 deletions.
10 changes: 5 additions & 5 deletions contracts/enumivo.coin/enumivo.coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void token::issue( account_name to, asset quantity, string memo )
s.supply += quantity;
});

add_balance( st.issuer, quantity, st, st.issuer );
add_balance( st.issuer, quantity, st.issuer );

if( to != st.issuer ) {
SEND_INLINE_ACTION( *this, transfer, {st.issuer,N(active)}, {st.issuer, to, quantity, memo} );
Expand Down Expand Up @@ -80,11 +80,11 @@ void token::transfer( account_name from,
enumivo_assert( memo.size() <= 256, "memo has more than 256 bytes" );


sub_balance( from, quantity, st );
add_balance( to, quantity, st, from );
sub_balance( from, quantity );
add_balance( to, quantity, from );
}

void token::sub_balance( account_name owner, asset value, const currency_stats& st ) {
void token::sub_balance( account_name owner, asset value ) {
accounts from_acnts( _self, owner );

const auto& from = from_acnts.get( value.symbol.name(), "no balance object found" );
Expand All @@ -100,7 +100,7 @@ void token::sub_balance( account_name owner, asset value, const currency_stats&
}
}

void token::add_balance( account_name owner, asset value, const currency_stats& st, account_name ram_payer )
void token::add_balance( account_name owner, asset value, account_name ram_payer )
{
accounts to_acnts( _self, owner );
auto to = to_acnts.find( value.symbol.name() );
Expand Down
5 changes: 2 additions & 3 deletions contracts/enumivo.coin/enumivo.coin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ namespace enumivo {
typedef enumivo::multi_index<N(accounts), account> accounts;
typedef enumivo::multi_index<N(stat), currency_stats> stats;

void sub_balance( account_name owner, asset value, const currency_stats& st );
void add_balance( account_name owner, asset value, const currency_stats& st,
account_name ram_payer );
void sub_balance( account_name owner, asset value );
void add_balance( account_name owner, asset value, account_name ram_payer );

public:
struct transfer_args {
Expand Down
33 changes: 23 additions & 10 deletions contracts/enumivo.system/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,32 @@ namespace enumivosystem {
require_auth( payer );
enumivo_assert( quant.amount > 0, "must purchase a positive amount" );

auto fee = quant;
fee.amount /= 200; /// .5% fee
auto quant_after_fee = quant;
quant_after_fee.amount -= fee.amount;

if( payer != N(enumivo) ) {
INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {payer,N(active)},
{ payer, N(enumivo), quant, std::string("buy ram") } );
{ payer, N(enumivo.ram), quant_after_fee, std::string("buy ram") } );
}

if( fee.amount > 0 ) {
INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {payer,N(active)},
{ payer, N(enumivo.rfee), fee, std::string("ram fee") } );
}

int64_t bytes_out;

auto itr = _rammarket.find(S(4,RAMCORE));
_rammarket.modify( itr, 0, [&]( auto& es ) {
bytes_out = es.convert( quant, S(0,RAM) ).amount;
bytes_out = es.convert( quant_after_fee, S(0,RAM) ).amount;
});


enumivo_assert( bytes_out > 0, "must reserve a positive amount" );

_gstate.total_ram_bytes_reserved += uint64_t(bytes_out);
_gstate.total_ram_stake += quant.amount;
_gstate.total_ram_stake += quant_after_fee.amount;

user_resources_table userres( _self, receiver );
auto res_itr = userres.find( receiver );
Expand Down Expand Up @@ -175,8 +183,13 @@ namespace enumivosystem {
set_resource_limits( res_itr->owner, res_itr->ram_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );

if( N(enumivo) != account ) {
INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo),N(active)},
{ N(enumivo), account, asset(tokens_out), std::string("sell ram") } );
INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo.ram),N(active)},
{ N(enumivo.ram), account, asset(tokens_out), std::string("sell ram") } );
auto fee = tokens_out.amount / 200;
if( fee > 0 ) {
INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {account,N(active)},
{ account, N(enumivo.rfee), asset(fee), std::string("sell ram fee") } );
}
}
}

Expand Down Expand Up @@ -252,7 +265,7 @@ namespace enumivosystem {
} // tot_itr can be invalid, should go out of scope

// create refund or update from existing refund
if ( N(enumivo) != source_stake_from ) { //for enumivo both transfer and refund make no sense
if ( N(enumivo.stk) != source_stake_from ) { //for enumivo both transfer and refund make no sense
refunds_table refunds_tbl( _self, from );
auto req = refunds_tbl.find( from );

Expand Down Expand Up @@ -317,7 +330,7 @@ namespace enumivosystem {
auto transfer_amount = net_balance + cpu_balance;
if ( asset(0) < transfer_amount ) {
INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {source_stake_from, N(active)},
{ source_stake_from, N(enumivo), asset(transfer_amount), std::string("stake bandwidth") } );
{ source_stake_from, N(enumivo.stk), asset(transfer_amount), std::string("stake bandwidth") } );
}
}

Expand Down Expand Up @@ -379,8 +392,8 @@ namespace enumivosystem {
// allow people to get their tokens earlier than the 3 day delay if the unstake happened immediately after many
// consecutive missed blocks.

INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo),N(active)},
{ N(enumivo), req->owner, req->net_amount + req->cpu_amount, std::string("unstake") } );
INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo.stk),N(active)},
{ N(enumivo.stk), req->owner, req->net_amount + req->cpu_amount, std::string("unstake") } );

refunds_tbl.erase( req );
}
Expand Down
10 changes: 6 additions & 4 deletions contracts/enumivo.system/enumivo.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace enumivosystem {
void system_contract::setram( uint64_t max_ram_size ) {
require_auth( _self );

enumivo_assert( _gstate.max_ram_size < max_ram_size, "ram may only be increased" ); /// decreasing ram might result market maker issues
enumivo_assert( max_ram_size < 1024ll*1024*1024*1024*1024, "ram size is unrealistic" );
enumivo_assert( max_ram_size > _gstate.total_ram_bytes_reserved, "attempt to set max below reserved" );

Expand Down Expand Up @@ -133,11 +134,12 @@ namespace enumivosystem {
const authority& active*/ ) {

if( creator != _self ) {
auto tmp = newact;
auto tmp = newact >> 4;
bool has_dot = false;
for( uint32_t i = 0; i < 13; ++i ) {
has_dot |= (tmp >> 59);
tmp <<= 5;

for( uint32_t i = 0; i < 12; ++i ) {
has_dot |= !(tmp & 0x1f);
tmp >>= 5;
}
auto suffix = enumivo::name_suffix(newact);
if( has_dot ) {
Expand Down
21 changes: 16 additions & 5 deletions contracts/enumivo.system/producer_pay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ namespace enumivosystem {
INLINE_ACTION_SENDER(enumivo::token, issue)( N(enumivo.coin), {{N(enumivo),N(active)}},
{N(enumivo), asset(new_tokens), std::string("issue tokens for producer pay and savings")} );

INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo),N(active)},
{ N(enumivo), N(enumivo.save), asset(to_savings), "unallocated inflation" } );

INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo),N(active)},
{ N(enumivo), N(enumivo.bpay), asset(to_per_block_pay), "fund per-block bucket" } );

INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo),N(active)},
{ N(enumivo), N(enumivo.vpay), asset(to_per_vote_pay), "fund per-vote bucket" } );

_gstate.pervote_bucket += to_per_vote_pay;
_gstate.perblock_bucket += to_per_block_pay;
_gstate.savings += to_savings;
Expand All @@ -113,8 +122,6 @@ namespace enumivosystem {
if( producer_per_vote_pay < min_pervote_daily_pay ) {
producer_per_vote_pay = 0;
}
int64_t total_pay = producer_per_block_pay + producer_per_vote_pay;

_gstate.pervote_bucket -= producer_per_vote_pay;
_gstate.perblock_bucket -= producer_per_block_pay;
_gstate.total_unpaid_blocks -= prod.unpaid_blocks;
Expand All @@ -124,9 +131,13 @@ namespace enumivosystem {
p.unpaid_blocks = 0;
});

if( total_pay > 0 ) {
INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo),N(active)},
{ N(enumivo), owner, asset(total_pay), std::string("producer pay") } );
if( producer_per_block_pay > 0 ) {
INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo.bpay),N(active)},
{ N(enumivo.bpay), owner, asset(producer_per_block_pay), std::string("producer block pay") } );
}
if( producer_per_vote_pay > 0 ) {
INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo.vpay),N(active)},
{ N(enumivo.vpay), owner, asset(producer_per_vote_pay), std::string("producer vote pay") } );
}
}

Expand Down
4 changes: 4 additions & 0 deletions contracts/enumivolib/print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ namespace enumivo {
prints_l( s.c_str(), s.size() );
}

inline void print( const char c ) {
prints_l( &c, 1 );
}

/**
* Prints signed integer
* @brief Prints signed integer as a 64 bit signed integer
Expand Down
1 change: 0 additions & 1 deletion contracts/test_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ add_wast_executable(TARGET test_api
INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}"
LIBRARIES libc++ libc enumivolib
DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
MAX_MEMORY 1048576
)
8 changes: 8 additions & 0 deletions contracts/test_api/test_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ extern "C" {
// test checktime
WASM_TEST_HANDLER(test_checktime, checktime_pass);
WASM_TEST_HANDLER(test_checktime, checktime_failure);
WASM_TEST_HANDLER(test_checktime, checktime_sha1_failure);
WASM_TEST_HANDLER(test_checktime, checktime_assert_sha1_failure);
WASM_TEST_HANDLER(test_checktime, checktime_sha256_failure);
WASM_TEST_HANDLER(test_checktime, checktime_assert_sha256_failure);
WASM_TEST_HANDLER(test_checktime, checktime_sha512_failure);
WASM_TEST_HANDLER(test_checktime, checktime_assert_sha512_failure);
WASM_TEST_HANDLER(test_checktime, checktime_ripemd160_failure);
WASM_TEST_HANDLER(test_checktime, checktime_assert_ripemd160_failure);

// test datastream
WASM_TEST_HANDLER(test_datastream, test_basic);
Expand Down
8 changes: 8 additions & 0 deletions contracts/test_api/test_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ struct test_memory {
struct test_checktime {
static void checktime_pass();
static void checktime_failure();
static void checktime_sha1_failure();
static void checktime_assert_sha1_failure();
static void checktime_sha256_failure();
static void checktime_assert_sha256_failure();
static void checktime_sha512_failure();
static void checktime_assert_sha512_failure();
static void checktime_ripemd160_failure();
static void checktime_assert_ripemd160_failure();
};
/*
struct test_softfloat {
Expand Down
54 changes: 54 additions & 0 deletions contracts/test_api/test_checktime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
*/

#include <enumivolib/enumivo.hpp>
#include <enumivolib/crypto.h>
#include <enumivolib/print.h>
#include "test_api.hpp"

#include <vector>

void test_checktime::checktime_pass() {
int p = 0;
for ( int i = 0; i < 10000; i++ )
Expand All @@ -23,3 +27,53 @@ void test_checktime::checktime_failure() {

enumivo::print(p);
}

constexpr size_t size = 20000000;

void test_checktime::checktime_sha1_failure() {
char* ptr = new char[size];
checksum160 res;
sha1( ptr, size, &res );
}

void test_checktime::checktime_assert_sha1_failure() {
char* ptr = new char[size];
checksum160 res;
assert_sha1( ptr, size, &res );
}

void test_checktime::checktime_sha256_failure() {
char* ptr = new char[size];
checksum256 res;
sha256( ptr, size, &res );
}

void test_checktime::checktime_assert_sha256_failure() {
char* ptr = new char[size];
checksum256 res;
assert_sha256( ptr, size, &res );
}

void test_checktime::checktime_sha512_failure() {
char* ptr = new char[size];
checksum512 res;
sha512( ptr, size, &res );
}

void test_checktime::checktime_assert_sha512_failure() {
char* ptr = new char[size];
checksum512 res;
assert_sha512( ptr, size, &res );
}

void test_checktime::checktime_ripemd160_failure() {
char* ptr = new char[size];
checksum160 res;
ripemd160( ptr, size, &res );
}

void test_checktime::checktime_assert_ripemd160_failure() {
char* ptr = new char[size];
checksum160 res;
assert_ripemd160( ptr, size, &res );
}
26 changes: 13 additions & 13 deletions libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ using boost::container::flat_set;
namespace enumivo { namespace chain {

static inline void print_debug(account_name receiver, const action_trace& ar) {
if(fc::logger::get(DEFAULT_LOGGER).is_enabled(fc::log_level::debug)) {
if (!ar.console.empty()) {
auto prefix = fc::format_string(
"\n[(${a},${n})->${r}]",
fc::mutable_variant_object()
("a", ar.act.account)
("n", ar.act.name)
("r", receiver));
dlog(prefix + ": CONSOLE OUTPUT BEGIN =====================\n"
+ ar.console
+ prefix + ": CONSOLE OUTPUT END =====================" );
}
if (!ar.console.empty()) {
auto prefix = fc::format_string(
"\n[(${a},${n})->${r}]",
fc::mutable_variant_object()
("a", ar.act.account)
("n", ar.act.name)
("r", receiver));
dlog(prefix + ": CONSOLE OUTPUT BEGIN =====================\n"
+ ar.console
+ prefix + ": CONSOLE OUTPUT END =====================" );
}
}

Expand Down Expand Up @@ -75,7 +73,9 @@ action_trace apply_context::exec_one()

trx_context.executed.emplace_back( move(r) );

print_debug(receiver, t);
if ( control.contracts_console() ) {
print_debug(receiver, t);
}

reset_console();

Expand Down
13 changes: 7 additions & 6 deletions libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,21 +262,20 @@ namespace enumivo { namespace chain {
}
} // construct_index

void block_log::repair_log( const fc::path& data_dir ) {
fc::path block_log::repair_log( const fc::path& data_dir ) {
ilog("Recovering Block Log...");
FC_ASSERT( fc::is_directory(data_dir) && fc::is_regular_file(data_dir / "blocks.log"),
"Block log not found in '${blocks_dir}'", ("blocks_dir", data_dir) );

auto now = fc::time_point::now();

auto blocks_dir = fc::canonical( data_dir );
if( blocks_dir.filename().generic_string() == "." ) {
blocks_dir = blocks_dir.parent_path();
}
auto backup_dir = blocks_dir.parent_path();
auto blocks_dir_name = blocks_dir.filename();
if( blocks_dir_name.generic_string() == "." ) {
blocks_dir_name = backup_dir.filename();
backup_dir = backup_dir.parent_path();
FC_ASSERT( blocks_dir_name.generic_string() != ".", "Invalid path to blocks directory" );
}
FC_ASSERT( blocks_dir_name.generic_string() != ".", "Invalid path to blocks directory" );
backup_dir = backup_dir / blocks_dir_name.generic_string().append("-").append( now );

FC_ASSERT( !fc::exists(backup_dir),
Expand Down Expand Up @@ -369,6 +368,8 @@ namespace enumivo { namespace chain {
} else {
ilog( "Existing block log was undamaged. Recovered all irreversible blocks up to block number ${num}.", ("num", block_num) );
}

return backup_dir;
}

} } /// enumivo::chain
Loading

0 comments on commit 2c55fbb

Please sign in to comment.