Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alepacheco committed Jul 13, 2018
1 parent da8232f commit 1c08e42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void resource_exchange::withdraw(account_name to, asset quantity) {

if (quantity > state.liquid_funds) {
if (quantity > state.get_unstaked()) {
// force overdraft
// TODO: force overdraft
eosio_assert(false, "cannot withdraw");
} else {
// retry next cycle
Expand All @@ -60,10 +60,14 @@ void resource_exchange::withdraw(account_name to, asset quantity) {
});

state_on_withdraw(quantity);
// schedule wiithdraw after cycle to prevent abuse
eosio::transaction out;
out.actions.emplace_back(
permission_level(_contract, N(active)), N(eosio.token), N(transfer),
std::make_tuple(_contract, to, quantity, std::string("")));

action(permission_level(_contract, N(active)), N(eosio.token), N(transfer),
std::make_tuple(_contract, to, quantity, std::string("")))
.send();
out.delay_sec = CYCLE_TIME + 100;
out.send(to, _contract, true);

if (itr->is_empty()) {
accounts.erase(itr);
Expand Down
3 changes: 1 addition & 2 deletions src/resource_exchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ void resource_exchange::cycle() {
}

void resource_exchange::docycle() {
// TODO proccess withdraws first
double cost_per_token = calcosttoken();
asset fees_collected = asset(0);
for (auto acnt = accounts.begin(); acnt != accounts.end(); ++acnt) {
fees_collected += billaccount(acnt->owner, cost_per_token);
matchbandwidth(acnt->owner);
}
asset fees_devs = asset(fees_collected.amount * 0.1);
asset fees_devs = asset(fees_collected.amount * 0.0);
for (auto acnt = accounts.begin(); acnt != accounts.end(); ++acnt) {
payreward(acnt->owner, fees_collected - fees_devs);
}
Expand Down

0 comments on commit 1c08e42

Please sign in to comment.