Skip to content

Commit

Permalink
Merge pull request #11 from EOSLaoMao/feature/safe-transfer
Browse files Browse the repository at this point in the history
use proxy transfer account to avoid RAM abuse
  • Loading branch information
datudou authored Oct 17, 2018
2 parents 3c7f9be + 2bfc01a commit 8b01a78
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/bankofstaked/bankofstaked.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace bank
{
static const account_name code_account = N(bankofstaked);
static const account_name ram_payer = N(bankofstaked);
static const account_name safe_transfer_account = N(masktransfer);
static const uint64_t SECONDS_PER_MIN = 60;
static const uint64_t SECONDS_PER_DAY = 24 * 3600;
static const uint64_t MAX_PAID_ORDERS = 5;
Expand Down
14 changes: 10 additions & 4 deletions src/bankofstaked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,14 @@ class bankofstaked : contract
if (order.is_free == FALSE)
{
auto plan = p.get(order.plan_id);
std:string memo = "bankofstaked income";

auto username = name{order.creditor};
std::string recipient_name = username.to_string();
std::string memo = recipient_name + " bankofstaked income";
action act3 = action(
permission_level{ code_account, N(bankperm) },
N(eosio.token), N(transfer),
std::make_tuple(code_account, order.creditor, order.price, memo)
std::make_tuple(code_account, safe_transfer_account, order.price, memo)
);
out.actions.emplace_back(act3);
}
Expand Down Expand Up @@ -522,16 +525,19 @@ class bankofstaked : contract
order_id = i.id;
});

// if plan is free, add a Freelock entry
if(plan->is_free == TRUE)
{
// if plan is free, add a Freelock entry
add_freelock(beneficiary);
// auto refund immediately
//INLINE ACTION to auto refund
creditor_table c(code_account, SCOPE_CREDITOR>>1);
std::string free_memo = c.get(creditor).free_memo;
auto username = name{buyer};
std::string buyer_name = username.to_string();
std::string memo = buyer_name + " " + free_memo;
INLINE_ACTION_SENDER(eosio::token, transfer)
(N(eosio.token), {{code_account, N(bankperm)}}, {code_account, buyer, plan->price, free_memo});
(N(eosio.token), {{code_account, N(bankperm)}}, {code_account, safe_transfer_account, plan->price, memo});
}

//deferred transaction to auto undelegate after expired
Expand Down
1 change: 1 addition & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace utils
if (memo.length() > 0)
{
to = string_to_name(memo.c_str());
eosio_assert( is_account( to ), "to account does not exist");
}
return to;
}
Expand Down

0 comments on commit 8b01a78

Please sign in to comment.