Skip to content

Commit

Permalink
Merge pull request #274 from fioprotocol/feature/BD-4082-fiocontracts…
Browse files Browse the repository at this point in the history
…-release28x-09262022

BD-4082 Enhance locks to enforce no duplicate accounts, and handle all lock adaptation cases for unsticking
  • Loading branch information
ericbutz authored Sep 26, 2022
2 parents 681e31b + d507290 commit 7453493
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
32 changes: 17 additions & 15 deletions contracts/fio.staking/fio.staking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,27 +497,29 @@ class [[eosio::contract("Staking")]] Staking: public eosio::contract {
}

//BD-3941 begin, be sure to handle edge case where we have locks and all are in the past.
if (foundinsix) {
if (foundinsix || newperiods.size() > 1) {
action(
permission_level{get_self(), "active"_n},
SYSTEMACCOUNT,
"modgenlocked"_n,
std::make_tuple(actor, newperiods, newlockamount, newremaininglockamount, payouts)
).send();
}else {
//else make the lock as if it was new, ALL perdiods in current locks are in the past!
bool canvote = true;
int64_t lockamount = (int64_t)(stakingrewardamount + amount);

vector <eosiosystem::lockperiodv2> periods;
eosiosystem::lockperiodv2 period;
period.duration = UNSTAKELOCKDURATIONSECONDS;
period.amount = lockamount;
periods.push_back(period);
INLINE_ACTION_SENDER(eosiosystem::system_contract, addgenlocked)
("eosio"_n, {{_self, "active"_n}},
{actor, periods, canvote, lockamount}
);
}
else {

bool canvote = true;
int64_t lockamount = (int64_t)(stakingrewardamount + amount);

vector <eosiosystem::lockperiodv2> periods;
eosiosystem::lockperiodv2 period;
period.duration = UNSTAKELOCKDURATIONSECONDS;
period.amount = lockamount;
periods.push_back(period);
INLINE_ACTION_SENDER(eosiosystem::system_contract, addgenlocked)
("eosio"_n, {{_self, "active"_n}},
{actor, periods, canvote, lockamount}
);

}
//BD-3941 end
}else {
Expand Down
10 changes: 10 additions & 0 deletions contracts/fio.system/src/fio.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ namespace eosiosystem {
check(is_account(owner),"account must pre exist");
check(amount > 0,"cannot add locked token amount less or equal 0.");

//BD-4082 begin

auto locks_by_owner = _generallockedtokens.get_index<"byowner"_n>();
auto lockiter = locks_by_owner.find(owner.value);
check(lockiter == locks_by_owner.end(),"cannot emplace locks when locks pre-exist.");


//BD-4082 end


_generallockedtokens.emplace(owner, [&](struct locked_tokens_info_v2 &a) {
a.id = _generallockedtokens.available_primary_key();
a.owner_account = owner;
Expand Down

0 comments on commit 7453493

Please sign in to comment.