diff --git a/contracts/fio.address/fio.address.abi b/contracts/fio.address/fio.address.abi index 0e4e790e..558730b1 100644 --- a/contracts/fio.address/fio.address.abi +++ b/contracts/fio.address/fio.address.abi @@ -132,6 +132,37 @@ } ] }, + { + "name": "regdomadd", + "base": "", + "fields": [ + { + "name": "fio_address", + "type": "string" + }, + { + "name": "is_public", + "type": "int8" + }, + { + "name": "owner_fio_public_key", + "type": "string" + }, + { + "name": "max_fee", + "type": "int64" + }, + { + "name": "tpid", + "type": "string" + }, + { + "name": "actor", + "type": "name" + }, + + ] + }, { "name": "tokenpubaddr", "base": "", @@ -710,6 +741,11 @@ "type": "regdomain", "ricardian_contract": "" }, + { + "name": "regdomadd", + "type": "regdomadd", + "ricardian_contract": "" + }, { "name": "renewdomain", "type": "renewdomain", diff --git a/contracts/fio.address/fio.address.cpp b/contracts/fio.address/fio.address.cpp index 6f366120..e2d5b3ac 100644 --- a/contracts/fio.address/fio.address.cpp +++ b/contracts/fio.address/fio.address.cpp @@ -809,6 +809,131 @@ namespace fioio { send_response(response_string.c_str()); } + + /*********** + * This action will register a fio domain and fio handle on the domain. T + * @param fio_address this is the fio address that will be registered to the domain. Domain must not already be registered. + * @param is_public 0 - the domain will be private; 1 - the new domain will be public + * @param owner_fio_public_key this is the public key that will own the registered fio address and fio domain + * @param max_fee this is the maximum fee that is willing to be paid for this transaction on the blockchain. + * @param tpid this is the fio address of the owner of the domain. + * @param actor this is the fio account that has sent this transaction. + */ + [[eosio::action]] + void + regdomadd(const string &fio_address, const uint8_t &is_public, const string &owner_fio_public_key, const int64_t &max_fee, const string &tpid, const name &actor) + { + + FioAddress fa; + fio_400_assert(validateTPIDFormat(tpid), "tpid", tpid, + "TPID must be empty or valid FIO address", + ErrorPubKeyValid); + fio_400_assert(max_fee >= 0, "max_fee", to_string(max_fee), "Invalid fee value", + ErrorMaxFeeInvalid); + + + fio_400_assert((is_public == 1 || is_public == 0), "is_public", to_string(is_public), "Only 0 or 1 allowed", + ErrorMaxFeeInvalid); + + if (owner_fio_public_key.length() > 0) { + fio_400_assert(isPubKeyValid(owner_fio_public_key), "owner_fio_public_key", owner_fio_public_key, + "Invalid FIO Public Key format", + ErrorPubKeyValid); + } + + name owner_account_name = accountmgnt(actor, owner_fio_public_key); + + getFioAddressStruct(fio_address, fa); + + fio_400_assert(validateFioNameFormat(fa), "fio_address", fa.fioaddress, "Invalid FIO Address format", ErrorInvalidFioNameFormat); + + uint128_t domainHash = string_to_uint128_hash(fa.fiodomain.c_str()); + + auto domainsbyname = domains.get_index<"byname"_n>(); + auto domains_iter = domainsbyname.find(domainHash); + + fio_400_assert(domains_iter == domainsbyname.end(), "fio_name", fa.fioaddress, + "Domain already registered, use regaddress instead.", ErrorDomainAlreadyRegistered); + + uint32_t domain_expiration = get_now_plus_one_year(); + domains.emplace(actor, [&](struct domain &d) { + d.id = domains.available_primary_key();; + d.name = fa.fiodomain; + d.domainhash = domainHash; + d.expiration = domain_expiration; + d.account = owner_account_name.value; + d.is_public = is_public; + }); + + auto key_iter = accountmap.find(owner_account_name.value); + + fio_400_assert(key_iter != accountmap.end(), "owner", to_string(owner_account_name.value), + "Owner is not bound in the account map.", ErrorActorNotInFioAccountMap); + + vector pubaddresses; + tokenpubaddr t1; + t1.public_address = key_iter->clientkey; + t1.token_code = "FIO"; + t1.chain_code = "FIO"; + pubaddresses.push_back(t1); + + fionames.emplace(actor, [&](struct fioname &a) { + a.id = fionames.available_primary_key();; + a.name = fa.fioaddress; + a.addresses = pubaddresses; + a.namehash = string_to_uint128_hash(fa.fioaddress.c_str());; + a.domain = fa.fiodomain; + a.domainhash = domainHash; + a.expiration = 4294967295; //Sunday, February 7, 2106 6:28:15 AM GMT+0000 (Max 32 bit expiration) + a.owner_account = owner_account_name.value; + a.bundleeligiblecountdown = getBundledAmount(); + }); + + const uint128_t endpoint_hash = string_to_uint128_hash(REGISTER_FIO_DOMAIN_ADDRESS_ENDPOINT); + + auto fees_by_endpoint = fiofees.get_index<"byendpoint"_n>(); + auto fee_iter = fees_by_endpoint.find(endpoint_hash); + fio_400_assert(fee_iter != fees_by_endpoint.end(), "endpoint_name", REGISTER_FIO_DOMAIN_ADDRESS_ENDPOINT, + "FIO fee not found for endpoint", ErrorNoEndpoint); + + const uint64_t reg_amount = fee_iter->suf_amount; + const uint64_t fee_type = fee_iter->type; + + fio_400_assert(fee_type == 0, "fee_type", to_string(fee_type), + "unexpected fee type for endpoint register_fio_address, expected 0", + ErrorNoEndpoint); + + fio_400_assert(max_fee >= (int64_t) reg_amount, "max_fee", to_string(max_fee), + "Fee exceeds supplied maximum.", + ErrorMaxFeeExceeded); + + fio_fees(actor, asset(reg_amount, FIOSYMBOL), REGISTER_FIO_DOMAIN_ADDRESS_ENDPOINT); + processbucketrewards(tpid, reg_amount, get_self(), actor); + + if (REGDOMADDRAM > 0) { + action( + permission_level{SYSTEMACCOUNT, "active"_n}, + "eosio"_n, + "incram"_n, + std::make_tuple(actor, REGDOMADDRAM) + ).send(); + } + + struct tm timeinfo; + fioio::convertfiotime(domain_expiration, &timeinfo); + std::string timebuffer = fioio::tmstringformat(timeinfo); + + const string response_string = string("{\"status\": \"OK\",\"expiration\":\"") + + timebuffer + string("\",\"fee_collected\":") + + to_string(reg_amount) + string("}"); + + 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 renew a fio domain, the domains expiration time will be extended by one year. * @param fio_domain this is the fio domain to be renewed. @@ -2233,8 +2358,7 @@ namespace fioio { }; - EOSIO_DISPATCH(FioNameLookup, (regaddress)(addaddress)(remaddress)(remalladdr)(regdomain)(renewdomain)(renewaddress)( - setdomainpub)(burnexpired)(decrcounter) - (bind2eosio)(burnaddress)(xferdomain)(xferaddress)(addbundles)(xferescrow)(addnft)(remnft)(remallnfts) - (burnnfts)) + EOSIO_DISPATCH(FioNameLookup, (regaddress)(addaddress)(remaddress)(remalladdr)(regdomain)(renewdomain)(renewaddress) + (setdomainpub)(burnexpired)(decrcounter)(bind2eosio)(burnaddress)(xferdomain)(xferaddress)(addbundles)(xferescrow) + (addnft)(remnft)(remallnfts)(burnnfts)(regdomadd)) } diff --git a/contracts/fio.common/fio.common.hpp b/contracts/fio.common/fio.common.hpp index 579dc321..461f94c3 100644 --- a/contracts/fio.common/fio.common.hpp +++ b/contracts/fio.common/fio.common.hpp @@ -83,6 +83,8 @@ #define BUY_DOMAIN_ENDPOINT "buy_domain" #define SET_MARKETPLACE_CONFIG_ENDPOINT "set_marketplace_config" +#define REGISTER_FIO_DOMAIN_ADDRESS_ENDPOINT "register_fio_domain_address" + namespace fioio { using namespace eosio; @@ -482,6 +484,7 @@ namespace fioio { static const uint64_t UNSTAKEFIOTOKENSRAM = 512; //integrated. static const uint64_t REGDOMAINRAM = 2560; //integrated. static const uint64_t REGADDRESSRAM = 2560; //integrated. + static const uint64_t REGDOMADDRAM = 5120; static const uint64_t ADDADDRESSRAM = 512; //integrated. static const uint64_t SETDOMAINPUBRAM = 256; //integrated. static const uint64_t NEWFUNDSREQUESTRAM = 3120; //integrated. diff --git a/contracts/fio.common/fiotime.hpp b/contracts/fio.common/fiotime.hpp index 359f8b12..c02e3c27 100644 --- a/contracts/fio.common/fiotime.hpp +++ b/contracts/fio.common/fiotime.hpp @@ -102,14 +102,14 @@ namespace fioio { for (months = 0; days_in_month[months] <= remdays; months++) remdays -= days_in_month[months]; - if (years + 100 > INT_MAX || years + 100 < INT_MIN) + if (years + 2000 > INT_MAX || years + 2000 < INT_MIN) return -1; tm->tm_year = years + 2000; tm->tm_mon = months + 3; if (tm->tm_mon >= 12) { tm->tm_mon -= 12; - tm->tm_year++; + //tm->tm_year++; if(tm->tm_mon == 00){ // some unknown but that makes the 12th month 00. tm->tm_mon = 12;