Skip to content

Commit

Permalink
Merge pull request #313 from fioprotocol/develop
Browse files Browse the repository at this point in the history
Release Candidate 2.9.x Update
  • Loading branch information
misterleet authored Jul 20, 2023
2 parents 9532d75 + 92cc1b8 commit f2827eb
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 39 deletions.
19 changes: 19 additions & 0 deletions contracts/fio.address/fio.address.abi
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,20 @@
}
]
},
{
"name": "burndomain",
"base": "",
"fields": [
{
"name": "domainname",
"type": "string"
},
{
"name": "domainidx",
"type": "uint64"
}
]
},
{
"name": "burnexpired",
"base": "",
Expand Down Expand Up @@ -808,6 +822,11 @@
"type": "renewaddress",
"ricardian_contract": ""
},
{
"name": "burndomain",
"type": "burndomain",
"ricardian_contract": ""
},
{
"name": "burnexpired",
"type": "burnexpired",
Expand Down
74 changes: 72 additions & 2 deletions contracts/fio.address/fio.address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ namespace fioio {

const uint64_t bundleeligiblecountdown = fioname_iter->bundleeligiblecountdown;

//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), actor);
}

if (bundleeligiblecountdown > 0) {
namesbyname.modify(fioname_iter, _self, [&](struct fioname &a) {
a.bundleeligiblecountdown = (bundleeligiblecountdown - 1);
Expand All @@ -515,6 +520,8 @@ namespace fioio {
);
}
}


return fee_amount;
}

Expand Down Expand Up @@ -617,6 +624,10 @@ namespace fioio {
);
}
}
//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), actor);
}
return fee_amount;
}

Expand Down Expand Up @@ -749,6 +760,12 @@ namespace fioio {
);
}
}

//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), actor);
}

return fee_amount;
}

Expand Down Expand Up @@ -1372,6 +1389,37 @@ namespace fioio {
send_response(response_string.c_str());
}

[[eosio::action]]
void burndomain(const string &domainname, const uint64_t &domainidx) {
//only fio.address able to call this.
eosio_assert(has_auth(AddressContract),
"missing required authority of fio.address");

auto domainiter = domains.find(domainidx);
fio_400_assert(domainiter->name.compare(domainname) == 0, "domainname", domainname,
"Domain name does not match name at index", ErrorDomainNotFound);

fio_400_assert(domainiter != domains.end(), "domainidx", std::to_string(domainidx),
"Domain index not found", ErrorDomainNotFound);

const auto domainhash = domainiter->domainhash;
auto nameexpidx = fionames.get_index<"bydomain"_n>();
auto nameiter = nameexpidx.find(domainhash);

fio_400_assert(nameiter == nameexpidx.end(), "domainidx", std::to_string(domainidx),
"Cannot burn domain when domain has fio handles", ErrorDomainNotFound);

domains.erase(domainiter);


const string response_string = string("{\"status\": \"OK\" },\"");

fio_400_assert(transaction_size() <= MAX_TRX_SIZE, "transaction_size", std::to_string(transaction_size()),
"Transaction is too large", ErrorTransactionTooLarge);

send_response(response_string.c_str());
}

/*
* This action will look for expired domains, then look for expired addresses, it will burn a total
* of 25 addresses each time called. please see the code for the logic of identifying expired domains
Expand Down Expand Up @@ -1457,7 +1505,12 @@ namespace fioio {
}

if (nameiter == nameexpidx.end()) {
domains.erase(domainiter);
action(
permission_level{get_self(), "active"_n},
"fio.address"_n,
"burndomain"_n,
std::make_tuple(domainiter->name,index)
).send();
recordProcessed++;

// Find any domains listed for sale on the fio.escrow contract table
Expand Down Expand Up @@ -1793,6 +1846,10 @@ namespace fioio {
);
}
}
//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), actor);
}

if (ADDNFTRAM > 0) {
action(
Expand Down Expand Up @@ -1955,6 +2012,10 @@ namespace fioio {
);
}
}
//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), actor);
}

const string response_string = string("{\"status\": \"OK\",\"fee_collected\":") +
to_string(fee_amount) + string("}");
Expand Down Expand Up @@ -2054,6 +2115,10 @@ namespace fioio {
);
}
}
//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), actor);
}

const string response_string = string("{\"status\": \"OK\",\"fee_collected\":") +
to_string(fee_amount) + string("}");
Expand Down Expand Up @@ -2407,6 +2472,7 @@ namespace fioio {
"burn_fio_address unexpected fee type for endpoint burn_fio_address, expected 1",
ErrorNoEndpoint);


if (bundleeligiblecountdown == 0) {
fee_amount = fee_iter->suf_amount;
fio_400_assert(max_fee >= (int64_t) fee_amount, "max_fee", to_string(max_fee),
Expand All @@ -2416,6 +2482,10 @@ namespace fioio {
fio_fees(actor, asset(fee_amount, FIOSYMBOL), BURN_FIO_ADDRESS_ENDPOINT);
process_rewards(tpid, fee_amount, get_self(), actor);
}
//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), actor);
}

const string response_string = string("{\"status\": \"OK\",\"fee_collected\":") +
to_string(fee_amount) + string("}");
Expand Down Expand Up @@ -2661,6 +2731,6 @@ namespace fioio {
};

EOSIO_DISPATCH(FioNameLookup,(regaddress)(addaddress)(remaddress)(remalladdr)(regdomain)(renewdomain)(renewaddress)
(setdomainpub)(burnexpired)(decrcounter)(bind2eosio)(burnaddress)(xferdomain)(xferaddress)(addbundles)(xferescrow)
(setdomainpub)(burnexpired)(burndomain)(decrcounter)(bind2eosio)(burnaddress)(xferdomain)(xferaddress)(addbundles)(xferescrow)
(addnft)(remnft)(remallnfts)(burnnfts)(regdomadd)(updcryptkey))
}
17 changes: 17 additions & 0 deletions contracts/fio.request.obt/fio.request.obt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ namespace fioio {
);
}
}
//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), aactor);
}
//end fees, bundle eligible fee logic
if (fio_request_id.length() > 0) {
uint64_t requestId;
Expand Down Expand Up @@ -449,6 +453,11 @@ namespace fioio {
);
}
}

//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), aActor);
}
//end fees, bundle eligible fee logic
const uint64_t id = fioTransactionsTable.available_primary_key();
const uint128_t toHash = string_to_uint128_hash(payee_fio_address.c_str());
Expand Down Expand Up @@ -603,6 +612,10 @@ namespace fioio {
);
}
}
//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), aactor);
}
//end fees, bundle eligible fee logic

trxtByRequestId.modify(fioreqctx_iter, _self, [&](struct fiotrxt_info &fr) {
Expand Down Expand Up @@ -741,6 +754,10 @@ namespace fioio {
);
}
}
//handle auto proxy
if (!tpid.empty()) {
set_auto_proxy(tpid, 0, get_self(), aactor);
}
//end fees, bundle eligible fee logic
trxtByRequestId.modify(fioreqctx_iter, _self, [&](struct fiotrxt_info &fr) {
fr.fio_data_type = static_cast<int64_t >(trxstatus::cancelled);
Expand Down
90 changes: 53 additions & 37 deletions contracts/fio.token/include/fio.token/fio.token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,74 +389,90 @@ namespace eosio {
}

//begin general locked tokens
//this will compute the present unlocked tokens for this user based on the
//unlocking schedule, it will update the locktokens table if the doupdate
//this will compute the present locked token amount for this user based on the
//unlocking schedule, it will update the locktokensv2 table if the doupdate
//is set to true.
static uint64_t computegenerallockedtokens(const name &actor, bool doupdate) {
uint32_t present_time = now();

//set up the query for lock periods this account.
eosiosystem::general_locks_table_v2 generalLockTokensTable(SYSTEMACCOUNT, SYSTEMACCOUNT.value);
auto locks_by_owner = generalLockTokensTable.get_index<"byowner"_n>();
auto lockiter = locks_by_owner.find(actor.value);
//if we get results from the query
if (lockiter != locks_by_owner.end()) {

//if the lock is not already completely paid out.
if (lockiter->payouts_performed < lockiter->periods.size()) {
uint32_t secondsSinceGrant = (present_time - lockiter->timestamp);
uint32_t number_unlocks = 0; //this is the number of unlock periods to perform at this time.
uint64_t computed_amount_unlock = 0; // this is the computed amount of fio to unlock at this time.

uint32_t payoutsDue = 0;

//loop over periods, total number of unlock periods to perform now, and compute present amount unlocked.
for (int i=0;i<lockiter->periods.size(); i++){
if (lockiter->periods[i].duration <= secondsSinceGrant){
payoutsDue++;
number_unlocks++;
if(i < lockiter->payouts_performed) {
computed_amount_unlock += lockiter->periods[i].amount;
}
}

}
uint64_t amountpay = 0;
uint64_t newlockedamount = lockiter->remaining_lock_amount;
bool didsomething = false;
//compute the remaining lock amount, for use in incoherency check.
uint64_t computed_remaining_lock_amount = lockiter->lock_amount - computed_amount_unlock;

if (payoutsDue > lockiter->payouts_performed) {
if((lockiter->payouts_performed + payoutsDue) >= lockiter->periods.size())
{
//payout the remaining lock amount.
amountpay = newlockedamount;
}
else {
uint64_t unlock_amount = 0; //the amount to unlock at this time
int unlock_periods = 0; //the number of periods to unlock at this time.

for (int i = lockiter->payouts_performed; i < payoutsDue; i++) {
amountpay += lockiter->periods[i].amount;
}
}
//if there are unlock periods needing processed now, record the number of periods to process.
if (lockiter->payouts_performed < number_unlocks){
unlock_periods = number_unlocks - lockiter->payouts_performed;
}

if (newlockedamount > amountpay) {
newlockedamount -= amountpay;
} else {
newlockedamount = 0;
//initialize the remaining lock amount to use from state.
uint64_t use_remaining_lock_amount = lockiter->remaining_lock_amount;

//compare the computed remaining lock amount
// and the state remaining lock amount, if they dont match then the lock
// is incoherent, if its incoherent use the computed remaining lock amount going forward.
if (use_remaining_lock_amount != computed_remaining_lock_amount){
use_remaining_lock_amount = computed_remaining_lock_amount;
print(" WARNING lock incoherency detected ", actor.to_string(), " using computed value for remaining_lock_amount ",
computed_remaining_lock_amount, " \n ");
}

//if the number of unlock periods is non zero, compute the amount to unlock at this time.
if (unlock_periods > 0) {
for (int i = lockiter->payouts_performed; i < number_unlocks; i++) {
unlock_amount += lockiter->periods[i].amount;
}
}

if ((amountpay > 0) && doupdate) {
//sanity check the amount to unlock and remaining lock amount, if they dont pass the sanity check
//do not proceed. prevent un-expected side effects of bad data.
check(use_remaining_lock_amount >= unlock_amount,
"computegenerallockedtokens, amount to unlock cannot be greater than remaining lock amount " + actor.to_string() );

//compute the present remaining lock amount, subtract the amount to unlock at this time.
use_remaining_lock_amount -= unlock_amount;

//if there is an amount to unlock, update state with the present lock info.
if (((unlock_amount > 0) && doupdate)) {
//get fio balance for this account,
uint32_t present_time = now();
const auto my_balance = eosio::token::get_balance("fio.token"_n, actor, FIOSYMBOL.code());
uint64_t amount = my_balance.amount;

if (newlockedamount > amount) {
print(" WARNING computed amount ", newlockedamount, " is more than amount in account ",
amount, " \n ",
" Transaction processing order can cause this, this amount is being re-aligned, resetting remaining locked amount to ",
amount, "\n");
newlockedamount = amount;
}

//final sanity check.
check(use_remaining_lock_amount <= amount,
"computegenerallockedtokens, remaining lock amount is larger than balance for " + actor.to_string() );

//update the locked table.
locks_by_owner.modify(lockiter, SYSTEMACCOUNT, [&](auto &av) {
av.remaining_lock_amount = newlockedamount;
av.payouts_performed = payoutsDue;
av.remaining_lock_amount = use_remaining_lock_amount;
av.payouts_performed = number_unlocks;
});
}

return newlockedamount;
return use_remaining_lock_amount;

} else {
return lockiter->remaining_lock_amount;
Expand Down

0 comments on commit f2827eb

Please sign in to comment.