Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIP-42] Add regdomadd action #278

Merged
merged 9 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions contracts/fio.address/fio.address.abi
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -710,6 +741,11 @@
"type": "regdomain",
"ricardian_contract": ""
},
{
"name": "regdomadd",
"type": "regdomadd",
"ricardian_contract": ""
},
{
"name": "renewdomain",
"type": "renewdomain",
Expand Down
131 changes: 127 additions & 4 deletions contracts/fio.address/fio.address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,130 @@ 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;
});

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 <tokenpubaddr> 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)
ericbutz marked this conversation as resolved.
Show resolved Hide resolved
).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.
Expand Down Expand Up @@ -2233,8 +2357,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))
}
3 changes: 3 additions & 0 deletions contracts/fio.common/fio.common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down