Skip to content

Commit

Permalink
fix for raw trx abi bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
nsjames committed Sep 14, 2018
1 parent 1b94809 commit c6864fe
Show file tree
Hide file tree
Showing 3 changed files with 7,103 additions and 7,523 deletions.
76 changes: 40 additions & 36 deletions scatterfunds/scatterfunds.cpp
Expand Up @@ -77,41 +77,6 @@ class scatterfunds : contract {
Settings(_self, N("started")).set(settings{now()}, _self);
}

void buy( const currency::transfer& t ){

eosio_assert(t.quantity.symbol == string_to_symbol(4, "EOS"), "Token must be EOS");
eosio_assert(t.quantity.is_valid(), "Token asset is not valid");
eosio_assert(t.quantity.amount >= 1'0000, "Not enough tokens");

int64_t cycle(getCurrentCycle());
eosio_assert(cycle <= lastCycle, "2 years have passed, this development fundraiser is over.");

CycleData cycleData = getCycleData(cycle);
asset total = cycleData.tokens;
eosio_assert(total < maxEosPerCycle(), "Too much has been spent today");

asset quantity = t.quantity;

// Too much was spent, sending the overage back
if(quantity + total > maxEosPerCycle()){
asset refunded = quantity + total - maxEosPerCycle();
quantity = quantity - refunded;
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {{_self,N(active)}}, {_self, t.from, refunded, "RIDL Over-Spend Refund"} );
}

setCycleData(cycle, total + quantity);

Claimables claimables(_self, t.from);
auto iter = claimables.find(cycle);
if(iter == claimables.end()) claimables.emplace(t.from, [&](auto& row){
row.cycle = cycle;
row.tokens = quantity;
});
else claimables.modify(iter, 0, [&](auto& row){
row.tokens += quantity;
});
}

// @abi actions
void claim( account_name owner ){
Claimables claimables(_self, owner);
Expand Down Expand Up @@ -148,6 +113,41 @@ class scatterfunds : contract {
/*** ***/
/**********************************************/

void buy( const currency::transfer& t ){

eosio_assert(t.quantity.symbol == string_to_symbol(4, "EOS"), "Token must be EOS");
eosio_assert(t.quantity.is_valid(), "Token asset is not valid");
eosio_assert(t.quantity.amount >= 1'0000, "Not enough tokens");

int64_t cycle(getCurrentCycle());
eosio_assert(cycle <= lastCycle, "2 years have passed, this development fundraiser is over.");

CycleData cycleData = getCycleData(cycle);
asset total = cycleData.tokens;
eosio_assert(total < maxEosPerCycle(), "Too much has been spent today");

asset quantity = t.quantity;

// Too much was spent, sending the overage back
if(quantity + total > maxEosPerCycle()){
asset refunded = quantity + total - maxEosPerCycle();
quantity = quantity - refunded;
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {{_self,N(active)}}, {_self, t.from, refunded, "RIDL Over-Spend Refund"} );
}

setCycleData(cycle, total + quantity);

Claimables claimables(_self, t.from);
auto iter = claimables.find(cycle);
if(iter == claimables.end()) claimables.emplace(_self, [&](auto& row){
row.cycle = cycle;
row.tokens = quantity;
});
else claimables.modify(iter, 0, [&](auto& row){
row.tokens += quantity;
});
}

void receivedTokens( const currency::transfer& t, account_name code ) {
if( code == _self ){
print("Contract sent money to itself?");
Expand All @@ -170,10 +170,14 @@ class scatterfunds : contract {
return;
}

if( action == N(buy) ){
eosio_assert(false, "Can't call buy directly");
}

if( contract != _self ) return;
auto& thiscontract = *this;
switch( action ) {
EOSIO_API( scatterfunds, (start)(buy)(claim) )
EOSIO_API( scatterfunds, (start)(claim) )
};
}

Expand Down
Binary file modified scatterfunds/scatterfunds.wasm
Binary file not shown.

0 comments on commit c6864fe

Please sign in to comment.