Skip to content

Commit

Permalink
Merge pull request EOSIO#124 from enumivo/staging
Browse files Browse the repository at this point in the history
rename eosio_assert
  • Loading branch information
Enumivo authored May 17, 2018
2 parents 06b2480 + 103346a commit 1da0efb
Show file tree
Hide file tree
Showing 60 changed files with 785 additions and 785 deletions.
4 changes: 2 additions & 2 deletions contracts/asserter/asserter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ extern "C" {
assertdef def = enumivo::unpack_action_data<assertdef>();

// maybe assert?
eosio_assert((uint32_t)def.condition, def.message.c_str());
enumivo_assert((uint32_t)def.condition, def.message.c_str());
} else if( action == N(provereset) ) {
eosio_assert(global_variable == 45, "Global Variable Initialized poorly");
enumivo_assert(global_variable == 45, "Global Variable Initialized poorly");
global_variable = 100;
}
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/bancor/converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace bancor {
save_and_send( trans.from, state, output, args.min_return );
}
else {
eosio_assert( false, "invalid to currency" );
enumivo_assert( false, "invalid to currency" );
}
}

Expand Down Expand Up @@ -118,7 +118,7 @@ namespace bancor {
template<typename CurrencyType>
static void start_convert( const typename CurrencyType::transfer_memo& trans ) {
auto args = unpack<converter_args>( trans.memo );
eosio_assert( args.to_currency_type != trans.quantity.token_type(), "cannot convert to self" );
enumivo_assert( args.to_currency_type != trans.quantity.token_type(), "cannot convert to self" );

auto state = read_converter_state();
on_convert( trans, args, state );
Expand Down Expand Up @@ -148,7 +148,7 @@ namespace bancor {
if( trans.to == converter_account ) {
start_convert( trans );
} else {
eosio_assert( trans.from == converter_account,
enumivo_assert( trans.from == converter_account,
"received unexpected notification of transfer" );
}
}
Expand All @@ -159,7 +159,7 @@ namespace bancor {
converter_currency::issue,
first_currency::transfer,
second_currency::transfer ) {
eosio_assert( false, "received unexpected action" );
enumivo_assert( false, "received unexpected action" );
}
}
}; /// converter_contract
Expand Down
44 changes: 22 additions & 22 deletions contracts/dice/dice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class dice : public enumivo::contract {
//@abi action
void offerbet(const asset& bet, const account_name player, const checksum256& commitment) {

eosio_assert( bet.symbol == S(4,EOS) , "only EOS token allowed" );
eosio_assert( bet.is_valid(), "invalid bet" );
eosio_assert( bet.amount > 0, "must bet positive quantity" );
enumivo_assert( bet.symbol == S(4,EOS) , "only EOS token allowed" );
enumivo_assert( bet.is_valid(), "invalid bet" );
enumivo_assert( bet.amount > 0, "must bet positive quantity" );

eosio_assert( !has_offer( commitment ), "offer with this commitment already exist" );
enumivo_assert( !has_offer( commitment ), "offer with this commitment already exist" );
require_auth( player );

auto cur_player_itr = accounts.find( player );
eosio_assert(cur_player_itr != accounts.end(), "unknown account");
enumivo_assert(cur_player_itr != accounts.end(), "unknown account");

// Store new offer
auto new_offer_itr = offers.emplace(_self, [&](auto& offer){
Expand All @@ -64,7 +64,7 @@ class dice : public enumivo::contract {

// No matching bet found, update player's account
accounts.modify( cur_player_itr, 0, [&](auto& acnt) {
eosio_assert( acnt.eos_balance >= bet, "insufficient balance" );
enumivo_assert( acnt.eos_balance >= bet, "insufficient balance" );
acnt.eos_balance -= bet;
acnt.open_offers++;
});
Expand Down Expand Up @@ -114,7 +114,7 @@ class dice : public enumivo::contract {
});

accounts.modify( cur_player_itr, 0, [&](auto& acnt) {
eosio_assert( acnt.eos_balance >= bet, "insufficient balance" );
enumivo_assert( acnt.eos_balance >= bet, "insufficient balance" );
acnt.eos_balance -= bet;
acnt.open_games++;
});
Expand All @@ -127,8 +127,8 @@ class dice : public enumivo::contract {
auto idx = offers.template get_index<N(commitment)>();
auto offer_itr = idx.find( offer::get_commitment(commitment) );

eosio_assert( offer_itr != idx.end(), "offer does not exists" );
eosio_assert( offer_itr->gameid == 0, "unable to cancel offer" );
enumivo_assert( offer_itr != idx.end(), "offer does not exists" );
enumivo_assert( offer_itr->gameid == 0, "unable to cancel offer" );
require_auth( offer_itr->owner );

auto acnt_itr = accounts.find(offer_itr->owner);
Expand All @@ -148,8 +148,8 @@ class dice : public enumivo::contract {
auto idx = offers.template get_index<N(commitment)>();
auto curr_revealer_offer = idx.find( offer::get_commitment(commitment) );

eosio_assert(curr_revealer_offer != idx.end(), "offer not found");
eosio_assert(curr_revealer_offer->gameid > 0, "unable to reveal");
enumivo_assert(curr_revealer_offer != idx.end(), "offer not found");
enumivo_assert(curr_revealer_offer->gameid > 0, "unable to reveal");

auto game_itr = games.find( curr_revealer_offer->gameid );

Expand All @@ -160,7 +160,7 @@ class dice : public enumivo::contract {
std::swap(curr_reveal, prev_reveal);
}

eosio_assert( is_zero(curr_reveal.reveal) == true, "player already revealed");
enumivo_assert( is_zero(curr_reveal.reveal) == true, "player already revealed");

if( !is_zero(prev_reveal.reveal) ) {

Expand Down Expand Up @@ -195,18 +195,18 @@ class dice : public enumivo::contract {

auto game_itr = games.find(gameid);

eosio_assert(game_itr != games.end(), "game not found");
eosio_assert(game_itr->deadline != enumivo::time_point_sec(0) && enumivo::time_point_sec(now()) > game_itr->deadline, "game not expired");
enumivo_assert(game_itr != games.end(), "game not found");
enumivo_assert(game_itr->deadline != enumivo::time_point_sec(0) && enumivo::time_point_sec(now()) > game_itr->deadline, "game not expired");

auto idx = offers.template get_index<N(commitment)>();
auto player1_offer = idx.find( offer::get_commitment(game_itr->player1.commitment) );
auto player2_offer = idx.find( offer::get_commitment(game_itr->player2.commitment) );

if( !is_zero(game_itr->player1.reveal) ) {
eosio_assert( is_zero(game_itr->player2.reveal), "game error");
enumivo_assert( is_zero(game_itr->player2.reveal), "game error");
pay_and_clean(*game_itr, *player1_offer, *player2_offer);
} else {
eosio_assert( is_zero(game_itr->player1.reveal), "game error");
enumivo_assert( is_zero(game_itr->player1.reveal), "game error");
pay_and_clean(*game_itr, *player2_offer, *player1_offer);
}

Expand All @@ -215,8 +215,8 @@ class dice : public enumivo::contract {
//@abi action
void deposit( const account_name from, const asset& quantity ) {

eosio_assert( quantity.is_valid(), "invalid quantity" );
eosio_assert( quantity.amount > 0, "must deposit positive quantity" );
enumivo_assert( quantity.is_valid(), "invalid quantity" );
enumivo_assert( quantity.amount > 0, "must deposit positive quantity" );

auto itr = accounts.find(from);
if( itr == accounts.end() ) {
Expand All @@ -240,14 +240,14 @@ class dice : public enumivo::contract {
void withdraw( const account_name to, const asset& quantity ) {
require_auth( to );

eosio_assert( quantity.is_valid(), "invalid quantity" );
eosio_assert( quantity.amount > 0, "must withdraw positive quantity" );
enumivo_assert( quantity.is_valid(), "invalid quantity" );
enumivo_assert( quantity.amount > 0, "must withdraw positive quantity" );

auto itr = accounts.find( to );
eosio_assert(itr != accounts.end(), "unknown account");
enumivo_assert(itr != accounts.end(), "unknown account");

accounts.modify( itr, 0, [&]( auto& acnt ) {
eosio_assert( acnt.eos_balance >= quantity, "insufficient balance" );
enumivo_assert( acnt.eos_balance >= quantity, "insufficient balance" );
acnt.eos_balance -= quantity;
});

Expand Down
32 changes: 16 additions & 16 deletions contracts/enumivo.coin/enumivo.coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ void token::create( account_name issuer,
require_auth( _self );

auto sym = maximum_supply.symbol;
eosio_assert( sym.is_valid(), "invalid symbol name" );
eosio_assert( maximum_supply.is_valid(), "invalid supply");
eosio_assert( maximum_supply.amount > 0, "max-supply must be positive");
enumivo_assert( sym.is_valid(), "invalid symbol name" );
enumivo_assert( maximum_supply.is_valid(), "invalid supply");
enumivo_assert( maximum_supply.amount > 0, "max-supply must be positive");

stats statstable( _self, sym.name() );
auto existing = statstable.find( sym.name() );
eosio_assert( existing == statstable.end(), "token with symbol already exists" );
enumivo_assert( existing == statstable.end(), "token with symbol already exists" );

statstable.emplace( _self, [&]( auto& s ) {
s.supply.symbol = maximum_supply.symbol;
Expand All @@ -32,20 +32,20 @@ void token::create( account_name issuer,
void token::issue( account_name to, asset quantity, string memo )
{
auto sym = quantity.symbol;
eosio_assert( sym.is_valid(), "invalid symbol name" );
enumivo_assert( sym.is_valid(), "invalid symbol name" );

auto sym_name = sym.name();
stats statstable( _self, sym_name );
auto existing = statstable.find( sym_name );
eosio_assert( existing != statstable.end(), "token with symbol does not exist, create token before issue" );
enumivo_assert( existing != statstable.end(), "token with symbol does not exist, create token before issue" );
const auto& st = *existing;

require_auth( st.issuer );
eosio_assert( quantity.is_valid(), "invalid quantity" );
eosio_assert( quantity.amount > 0, "must issue positive quantity" );
enumivo_assert( quantity.is_valid(), "invalid quantity" );
enumivo_assert( quantity.amount > 0, "must issue positive quantity" );

eosio_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
eosio_assert( quantity.amount <= st.max_supply.amount - st.supply.amount, "quantity exceeds available supply");
enumivo_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
enumivo_assert( quantity.amount <= st.max_supply.amount - st.supply.amount, "quantity exceeds available supply");

statstable.modify( st, 0, [&]( auto& s ) {
s.supply += quantity;
Expand All @@ -63,19 +63,19 @@ void token::transfer( account_name from,
asset quantity,
string /*memo*/ )
{
eosio_assert( from != to, "cannot transfer to self" );
enumivo_assert( from != to, "cannot transfer to self" );
require_auth( from );
eosio_assert( is_account( to ), "to account does not exist");
enumivo_assert( is_account( to ), "to account does not exist");
auto sym = quantity.symbol.name();
stats statstable( _self, sym );
const auto& st = statstable.get( sym );

require_recipient( from );
require_recipient( to );

eosio_assert( quantity.is_valid(), "invalid quantity" );
eosio_assert( quantity.amount > 0, "must transfer positive quantity" );
eosio_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
enumivo_assert( quantity.is_valid(), "invalid quantity" );
enumivo_assert( quantity.amount > 0, "must transfer positive quantity" );
enumivo_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );


sub_balance( from, quantity, st );
Expand All @@ -86,7 +86,7 @@ void token::sub_balance( account_name owner, asset value, const currency_stats&
accounts from_acnts( _self, owner );

const auto& from = from_acnts.get( value.symbol.name() );
eosio_assert( from.balance.amount >= value.amount, "overdrawn balance" );
enumivo_assert( from.balance.amount >= value.amount, "overdrawn balance" );


if( from.balance.amount == value.amount ) {
Expand Down
18 changes: 9 additions & 9 deletions contracts/enumivo.msig/enumivo.msig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ void multisig::propose() {
ds >> trx_header;

require_auth( proposer );
eosio_assert( trx_header.expiration >= enumivo::time_point_sec(now()), "transaction expired" );
//eosio_assert( trx_header.actions.size() > 0, "transaction must have at least one action" );
enumivo_assert( trx_header.expiration >= enumivo::time_point_sec(now()), "transaction expired" );
//enumivo_assert( trx_header.actions.size() > 0, "transaction must have at least one action" );

proposals proptable( _self, proposer );
eosio_assert( proptable.find( proposal_name ) == proptable.end(), "proposal with the same name exists" );
enumivo_assert( proptable.find( proposal_name ) == proptable.end(), "proposal with the same name exists" );

bytes packed_requested = pack(requested);
auto res = ::check_transaction_authorization( buffer+trx_pos, size-trx_pos,
(const char*)0, 0,
packed_requested.data(), packed_requested.size()
);
eosio_assert( res > 0, "transaction authorization failed" );
enumivo_assert( res > 0, "transaction authorization failed" );

proptable.emplace( proposer, [&]( auto& prop ) {
prop.proposal_name = proposal_name;
Expand All @@ -66,7 +66,7 @@ void multisig::approve( account_name proposer, name proposal_name, permission_le
auto& apps = apptable.get( proposal_name, "proposal not found" );

auto itr = std::find( apps.requested_approvals.begin(), apps.requested_approvals.end(), level );
eosio_assert( itr != apps.requested_approvals.end(), "approval is not on the list of requested approvals" );
enumivo_assert( itr != apps.requested_approvals.end(), "approval is not on the list of requested approvals" );

apptable.modify( apps, proposer, [&]( auto& a ) {
a.provided_approvals.push_back( level );
Expand All @@ -80,7 +80,7 @@ void multisig::unapprove( account_name proposer, name proposal_name, permission_
approvals apptable( _self, proposer );
auto& apps = apptable.get( proposal_name, "proposal not found" );
auto itr = std::find( apps.provided_approvals.begin(), apps.provided_approvals.end(), level );
eosio_assert( itr != apps.provided_approvals.end(), "no approval previously granted" );
enumivo_assert( itr != apps.provided_approvals.end(), "no approval previously granted" );

apptable.modify( apps, proposer, [&]( auto& a ) {
a.requested_approvals.push_back(level);
Expand All @@ -95,7 +95,7 @@ void multisig::cancel( account_name proposer, name proposal_name, account_name c
auto& prop = proptable.get( proposal_name, "proposal not found" );

if( canceler != proposer ) {
eosio_assert( unpack<transaction_header>( prop.packed_transaction ).expiration < enumivo::time_point_sec(now()), "cannot cancel until expiration" );
enumivo_assert( unpack<transaction_header>( prop.packed_transaction ).expiration < enumivo::time_point_sec(now()), "cannot cancel until expiration" );
}

approvals apptable( _self, proposer );
Expand All @@ -117,14 +117,14 @@ void multisig::exec( account_name proposer, name proposal_name, account_name exe
transaction_header trx_header;
datastream<const char*> ds( prop.packed_transaction.data(), prop.packed_transaction.size() );
ds >> trx_header;
eosio_assert( trx_header.expiration >= enumivo::time_point_sec(now()), "transaction expired" );
enumivo_assert( trx_header.expiration >= enumivo::time_point_sec(now()), "transaction expired" );

bytes packed_provided_approvals = pack(apps.provided_approvals);
auto res = ::check_transaction_authorization( prop.packed_transaction.data(), prop.packed_transaction.size(),
(const char*)0, 0,
packed_provided_approvals.data(), packed_provided_approvals.size()
);
eosio_assert( res > 0, "transaction authorization failed" );
enumivo_assert( res > 0, "transaction authorization failed" );

send_deferred( (uint128_t(proposer) << 64) | proposal_name, executer, prop.packed_transaction.data(), prop.packed_transaction.size() );

Expand Down
Loading

0 comments on commit 1da0efb

Please sign in to comment.