Skip to content

Commit

Permalink
Merge pull request #4 from EOSIO/master
Browse files Browse the repository at this point in the history
update from origin
  • Loading branch information
igorls authored Jun 1, 2018
2 parents ed56850 + cbf28a2 commit 6d66276
Show file tree
Hide file tree
Showing 30 changed files with 261 additions and 373 deletions.
2 changes: 1 addition & 1 deletion contracts/asserter/asserter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static int global_variable = 45;

extern "C" {
/// The apply method implements the dispatch of events to this contract
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
void apply( uint64_t /* receiver */, uint64_t code, uint64_t action ) {
require_auth(code);
if( code == N(asserter) ) {
if( action == N(procassert) ) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/eosio.bios/eosio.bios.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace eosio {
set_privileged( account, ispriv );
}

void setalimits( account_name account, uint64_t ram_bytes, uint64_t net_weight, uint64_t cpu_weight ) {
void setalimits( account_name account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight ) {
require_auth( _self );
set_resource_limits( account, ram_bytes, net_weight, cpu_weight );
}
Expand Down
3 changes: 1 addition & 2 deletions contracts/eosio.system/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace eosiosystem {
tokens_out = es.convert( asset(bytes,S(0,RAM)), CORE_SYMBOL);
});

_gstate.total_ram_bytes_reserved -= bytes;
_gstate.total_ram_bytes_reserved -= static_cast<decltype(_gstate.total_ram_bytes_reserved)>(bytes); // bytes > 0 is asserted above
_gstate.total_ram_stake -= tokens_out.amount;

//// this shouldn't happen, but just in case it does we should prevent it
Expand All @@ -190,7 +190,6 @@ namespace eosiosystem {
}

void validate_b1_vesting( int64_t stake ) {
const int64_t seconds_per_year = 60*60*24*365;
const int64_t base_time = 1527811200; /// 2018-06-01
const int64_t max_claimable = 100'000'000'0000ll;
const int64_t claimable = int64_t(max_claimable * double(now()-base_time) / (10*seconds_per_year) );
Expand Down
17 changes: 7 additions & 10 deletions contracts/eosio.system/eosio.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace eosiosystem {
} else {
eosio_assert( current->high_bid > 0, "this auction has already closed" );
eosio_assert( bid.amount - current->high_bid > (current->high_bid / 10), "must increase bid by 10%" );
eosio_assert( current->high_bidder != bidder, "account is already high bidder" );
eosio_assert( current->high_bidder != bidder, "account is already highest bidder" );

INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio.names),N(active)},
{ N(eosio.names), current->high_bidder, asset(current->high_bid),
Expand All @@ -135,13 +135,10 @@ namespace eosiosystem {
* Called after a new account is created. This code enforces resource-limits rules
* for new accounts as well as new account naming conventions.
*
* 1. accounts cannot contain '.' symbols which forces all acccounts to be 12
* characters long without '.' until a future account auction process is implemented
* which prevents name squatting.
* Account names containing '.' symbols must have a suffix equal to the name of the creator.
* This allows users who buy a premium name (shorter than 12 characters with no dots) to be the only ones
* who can create accounts with the creator's name as a suffix.
*
* 2. new accounts must stake a minimal number of tokens (as set in system parameters)
* therefore, this method will execute an inline buyram from receiver for newacnt in
* an amount equal to the current new account creation fee.
*/
void native::newaccount( account_name creator,
account_name newact
Expand All @@ -157,13 +154,13 @@ namespace eosiosystem {
has_dot |= !(tmp & 0x1f);
tmp >>= 5;
}
auto suffix = eosio::name_suffix(newact);
if( has_dot ) {
if( has_dot ) { // or is less than 12 characters
auto suffix = eosio::name_suffix(newact);
if( suffix == newact ) {
name_bid_table bids(_self,_self);
auto current = bids.find( newact );
eosio_assert( current != bids.end(), "no active bid for name" );
eosio_assert( current->high_bidder == creator, "only high bidder can claim" );
eosio_assert( current->high_bidder == creator, "only highest bidder can claim" );
eosio_assert( current->high_bid < 0, "auction for name is not closed yet" );
bids.erase( current );
} else {
Expand Down
4 changes: 2 additions & 2 deletions contracts/eosio.system/eosio.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace eosiosystem {
int64_t high_bid = 0; ///< negative high_bid == closed auction waiting to be claimed
uint64_t last_bid_time = 0;

auto primary_key()const { return newname; }
uint64_t by_high_bid()const { return -high_bid; }
auto primary_key()const { return newname; }
uint64_t by_high_bid()const { return static_cast<uint64_t>(-high_bid); }
};

typedef eosio::multi_index< N(namebids), name_bid,
Expand Down
2 changes: 1 addition & 1 deletion contracts/eosio.system/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace eosiosystem {
bytes packed_schedule = pack(producers);

if( set_proposed_producers( packed_schedule.data(), packed_schedule.size() ) >= 0 ) {
_gstate.last_producer_schedule_size = top_producers.size();
_gstate.last_producer_schedule_size = static_cast<decltype(_gstate.last_producer_schedule_size)>( top_producers.size() );
}
}

Expand Down
46 changes: 27 additions & 19 deletions contracts/eosiolib/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,36 @@ namespace eosio {
#define N(X) ::eosio::string_to_name(#X)


static constexpr uint64_t name_suffix( uint64_t tmp ) {
uint64_t suffix = 0;
bool endsuffix = false;
uint32_t offset = 0;
for( uint32_t i = 0; i <= 12; ++i, ++offset ) {
auto p = tmp >> 59;
if( !p ) {
endsuffix = true;
} else {
if( !endsuffix ) {
suffix |= uint64_t(p) << (59-(5*offset));
}
static constexpr uint64_t name_suffix( uint64_t n ) {
uint32_t remaining_bits_after_last_actual_dot = 0;
uint32_t tmp = 0;
for( int32_t remaining_bits = 59; remaining_bits >= 4; remaining_bits -= 5 ) { // Note: remaining_bits must remain signed integer
// Get characters one-by-one in name in order from left to right (not including the 13th character)
auto c = (n >> remaining_bits) & 0x1Full;
if( !c ) { // if this character is a dot
tmp = static_cast<uint32_t>(remaining_bits);
} else { // if this character is not a dot
remaining_bits_after_last_actual_dot = tmp;
}
if( endsuffix && p ) {
endsuffix = false;
offset = 0;
suffix = uint64_t(p) << (59-(5*offset));
}
tmp <<= 5;
}
return suffix;

uint64_t thirteenth_character = n & 0x0Full;
if( thirteenth_character ) { // if 13th character is not a dot
remaining_bits_after_last_actual_dot = tmp;
}

if( remaining_bits_after_last_actual_dot == 0 ) // there is no actual dot in the name other than potentially leading dots
return n;

// At this point remaining_bits_after_last_actual_dot has to be within the range of 4 to 59 (and restricted to increments of 5).

// Mask for remaining bits corresponding to characters after last actual dot, except for 4 least significant bits (corresponds to 13th character).
uint64_t mask = (1ull << remaining_bits_after_last_actual_dot) - 16;
uint32_t shift = 64 - remaining_bits_after_last_actual_dot;

return ( ((n & mask) << shift) + (thirteenth_character << (shift-1)) );
}

/**
* @brief wraps a uint64_t to ensure it is only passed to methods that expect a Name
* @details wraps a uint64_t to ensure it is only passed to methods that expect a Name and
Expand Down
2 changes: 1 addition & 1 deletion contracts/exchange/exchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace eosio {

void exchange::createx( account_name creator,
asset initial_supply,
uint32_t fee,
uint32_t /* fee */,
extended_asset base_deposit,
extended_asset quote_deposit
) {
Expand Down
8 changes: 5 additions & 3 deletions contracts/exchange/test_exchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ exchange_state borrow( const exchange_state& current, account_name user,
/// remove amount_to_borrow from exchange
/// lock collateral for user
/// simulate complete margin calls
return exchange_state();
}

exchange_state cover( const exchange_state& current, account_name user,
Expand All @@ -357,22 +358,23 @@ exchange_state cover( const exchange_state& current, account_name user,
// - if borrowed from user, reduce borrowed from user
/// calculate new call price and update least collateralized position
/// simulate complete margin calls

return exchange_state();
}

exchange_state lend( const exchange_state& current, account_name lender,
asset asset_to_lend ) {
/// add to pool of funds available for lending and buy SHARES in
/// interest pool at current rate.

return exchange_state();
}

exchange_state unlend( const exchange_state& current, account_name lender,
asset asset_to_lend ) {
/// sell shares in interest pool at current rate
/// this is permitable so long as total borrowed from users remains less than
/// total available to lend. Otherwise, margin is called on the least
/// collateralized position.
/// collateralized position.
return exchange_state();
}


Expand Down
2 changes: 1 addition & 1 deletion contracts/multi_index_test/multi_index_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct limit_order {
namespace multi_index_test {
extern "C" {
/// The apply method implements the dispatch of events to this contract
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
void apply( uint64_t /* receiver */, uint64_t code, uint64_t action ) {
require_auth(code);
eosio_assert(eosio::dispatch<multi_index_test, multi_index_test::trigger>(code, action),
"Could not dispatch");
Expand Down
2 changes: 1 addition & 1 deletion contracts/proxy/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace proxy {
};

template<typename T>
void apply_transfer(uint64_t receiver, account_name code, const T& transfer) {
void apply_transfer(uint64_t receiver, account_name /* code */, const T& transfer) {
config code_config;
const auto self = receiver;
auto get_res = configs::get(code_config, self);
Expand Down
2 changes: 1 addition & 1 deletion contracts/test_api/test_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void test_action::test_cf_action() {
publication_time();
eosio_assert( false, "system_api should not be allowed" );
} else if ( cfa.payload == 210 ) {
send_inline( "hello", 6 );
send_inline( (char*)"hello", 6 );
eosio_assert( false, "transaction_api should not be allowed" );
} else if ( cfa.payload == 211 ) {
send_deferred( N(testapi), N(testapi), "hello", 6 );
Expand Down
35 changes: 31 additions & 4 deletions contracts/test_api/test_datastream.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include <eosiolib/eosio.hpp>
#include <eosiolib/datastream.hpp>
#include <cmath>

#include "test_api.hpp"

Expand All @@ -17,6 +18,32 @@ struct testtype {
}
};

template <>
struct testtype<double> {
static void run(const double &v, const char *errmsg = "") {
char buf[128];
eosio::datastream<char *> ds(buf, sizeof(buf));
ds << v;
double v2;
ds.seekp(0);
ds >> v2;
eosio_assert(std::abs(v - v2) < 1e-20, errmsg);
}
};

template <>
struct testtype<float> {
static void run(const float &v, const char *errmsg = "") {
char buf[128];
eosio::datastream<char *> ds(buf, sizeof(buf));
ds << v;
float v2;
ds.seekp(0);
ds >> v2;
eosio_assert(std::abs(v - v2) < float(1e-10), errmsg);
}
};

void test_datastream::test_basic()
{

Expand All @@ -28,7 +55,7 @@ void test_datastream::test_basic()
testtype<unsigned short>::run(12345, "uint16");
testtype<int>::run(-1234567890, "int32");
testtype<unsigned int>::run(3234567890u, "uint32");
testtype<long long>::run(0x8000000000000000ull, "int64");
testtype<long long>::run((long long)0x8000000000000000ll, "int64");
testtype<unsigned long long>::run(0x7fffffffffffffffull, "uint64");
testtype<float>::run(1.234f, "float");
testtype<double>::run(0.333333333333333333, "double");
Expand All @@ -39,21 +66,21 @@ void test_datastream::test_basic()
struct Pair {
int a;
double d;
bool operator==(const Pair &p) const { return a == p.a && d == p.d;}
bool operator==(const Pair &p) const { return a == p.a && std::abs(d - p.d) < 1e-20;}
};
testtype<Pair>::run({1, 1.23456}, "struct");

struct StaticArray {
int a[2];
bool operator==(const StaticArray &o) const { return a[0] == o.a[0] && a[1] == o.a[1]; }
};
testtype<StaticArray>::run({10,20}, "staticArray");
testtype<StaticArray>::run({{10,20}}, "StaticArray");

testtype<std::string>::run("hello", "string");

testtype<std::vector<int> >::run({10,20,30}, "vector");
testtype<std::vector<int> >::run({}, "empty vector");
testtype<std::array<int, 3> >::run({10,20,30}, "std::array<T,N>");
testtype<std::array<int, 3> >::run({{10,20,30}}, "std::array<T,N>");
testtype<std::map<int, std::string> >::run({{1,"apple"}, {2,"cat"}, {3,"panda"}}, "map");
testtype<std::tuple<int, std::string, double> >::run({1, "abc", 3.3333}, "tuple");
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/test_api/test_permission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct test_permission_last_used_msg {
EOSLIB_SERIALIZE( test_permission_last_used_msg, (account)(permission)(last_used_time) )
};

void test_permission::test_permission_last_used(uint64_t receiver, uint64_t code, uint64_t action) {
void test_permission::test_permission_last_used(uint64_t /* receiver */, uint64_t code, uint64_t action) {
(void)code;
(void)action;
using namespace eosio;
Expand All @@ -68,7 +68,7 @@ void test_permission::test_permission_last_used(uint64_t receiver, uint64_t code
eosio_assert( get_permission_last_used(params.account, params.permission) == params.last_used_time, "unexpected last used permission time" );
}

void test_permission::test_account_creation_time(uint64_t receiver, uint64_t code, uint64_t action) {
void test_permission::test_account_creation_time(uint64_t /* receiver */, uint64_t code, uint64_t action) {
(void)code;
(void)action;
using namespace eosio;
Expand Down
6 changes: 3 additions & 3 deletions contracts/test_api/test_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void test_transaction::send_deferred_tx_with_dtt_action() {
void test_transaction::cancel_deferred_transaction_success() {
using namespace eosio;
auto r = cancel_deferred( 0xffffffffffffffff ); //use the same id (0) as in send_deferred_transaction
eosio_assert( r, "transaction was not found" );
eosio_assert( (bool)r, "transaction was not found" );
}

void test_transaction::cancel_deferred_transaction_not_found() {
Expand Down Expand Up @@ -310,9 +310,9 @@ void test_transaction::context_free_api() {

extern "C" { int is_feature_active(int64_t); }
void test_transaction::new_feature() {
eosio_assert(false == is_feature_active(N(newfeature)), "we should not have new features unless hardfork");
eosio_assert(false == is_feature_active((int64_t)N(newfeature)), "we should not have new features unless hardfork");
}

void test_transaction::active_new_feature() {
activate_feature(N(newfeature));
activate_feature((int64_t)N(newfeature));
}
11 changes: 8 additions & 3 deletions contracts/test_api_db/test_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void test_db::primary_i64_general(uint64_t receiver, uint64_t code, uint64_t act

buffer_len = 20;
len = db_get_i64(itr, value, 0);
len = db_get_i64(itr, value, len);
len = db_get_i64(itr, value, (uint32_t)len);
value[len] = '\0';
std::string sfull(value);
eosio_assert(sfull == "bob's info", "primary_i64_general - db_get_i64 - full");
Expand Down Expand Up @@ -448,7 +448,7 @@ void test_db::test_invalid_access(uint64_t receiver, uint64_t code, uint64_t act
uint64_t pk = scope;

int32_t itr = -1;
uint64_t value;
uint64_t value = 0;
switch( ia.index ) {
case 1:
itr = db_idx64_find_primary(ia.code, scope, table, &value, pk);
Expand Down Expand Up @@ -536,7 +536,10 @@ void test_db::idx_double_nan_lookup_fail(uint64_t receiver, uint64_t, uint64_t)
}
}

void test_db::misaligned_secondary_key256_tests(uint64_t receiver, uint64_t, uint64_t) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-align"

void test_db::misaligned_secondary_key256_tests(uint64_t /* receiver */, uint64_t, uint64_t) {
auto key = eosio::key256::make_from_word_sequence<uint64_t>(0ULL, 0ULL, 0ULL, 42ULL);
char* ptr = (char*)(&key);
ptr += 1;
Expand All @@ -545,3 +548,5 @@ void test_db::misaligned_secondary_key256_tests(uint64_t receiver, uint64_t, uin
// test that find_primary doesn't crash on unaligned data
db_idx256_find_primary( N(testapi), N(testtable), N(testapi), (eosio::key256*)(ptr), 2, 0);
}

#pragma clang diagnostic pop
2 changes: 1 addition & 1 deletion contracts/test_api_mem/test_extended_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void test_extended_memory::test_page_memory_exceeded() {
}

void test_extended_memory::test_page_memory_negative_bytes() {
eosio_assert(reinterpret_cast<int32_t>(sbrk(-1)) == -1, "Should have errored for trying to remove memory");
eosio_assert(reinterpret_cast<int32_t>(sbrk((uint32_t)-1)) == -1, "Should have errored for trying to remove memory");
}

void test_extended_memory::test_initial_buffer() {
Expand Down
Loading

0 comments on commit 6d66276

Please sign in to comment.