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

Transfer FIO Domain (MAS-1640 / FIP-1 Part 1) #70

Merged
merged 8 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
25 changes: 24 additions & 1 deletion fio.contracts/contracts/fio.address/fio.address.abi
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,26 @@
"name": "existing",
"type": "bool"
}]
}
},{
"name": "xferdomain",
"base": "",
"fields": [{
"name": "fio_domain",
"type": "string"
},{
"name": "new_owner_fio_public_key",
"type": "string"
},{
"name": "max_fee",
"type": "int64"
},{
"name": "tpid",
"type": "string"
},{
"name": "actor",
"type": "name"
}]
}
],
"actions": [{
"name": "regaddress",
Expand Down Expand Up @@ -260,6 +279,10 @@
"name": "bind2eosio",
"type": "bind2eosio",
"ricardian_contract": ""
},{
"name": "xferdomain",
"type": "xferdomain",
"ricardian_contract": ""
}
],
"tables": [{
Expand Down
78 changes: 73 additions & 5 deletions fio.contracts/contracts/fio.address/fio.address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ namespace fioio {
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);

Expand Down Expand Up @@ -923,9 +923,6 @@ namespace fioio {
send_response(response_string.c_str());
} //addaddress




[[eosio::action]]
void
setdomainpub(const string &fio_domain, const int8_t is_public, const int64_t &max_fee, const name &actor,
Expand Down Expand Up @@ -1048,6 +1045,77 @@ namespace fioio {
}
}

[[eosio::action]]
void xferdomain(const string &fio_domain, const string &new_owner_fio_public_key, const int64_t &max_fee,
const string &tpid, const name &actor) {
require_auth(actor);

fio_400_assert(isPubKeyValid(new_owner_fio_public_key), "new_owner_fio_public_key", new_owner_fio_public_key,
"Invalid FIO Public Key", ErrorChainAddressEmpty);
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);

auto domainsbyname = domains.get_index<"byname"_n>();
auto domains_iter = domainsbyname.find(string_to_uint128_hash(fio_domain));
fio_400_assert(domains_iter != domainsbyname.end(), "fio_domain", fio_domain,
"FIO Domain not registered", ErrorDomainNotRegistered);

const uint32_t domain_expiration = domains_iter->expiration;
const uint32_t present_time = now();
fio_400_assert(present_time <= domain_expiration, "fio_domain", fio_domain, "FIO Domain expired. Renew first.",
ErrorDomainExpired);

fio_403_assert(domains_iter->account == actor.value, ErrorSignature);
require_auth(domains_iter->account);
const uint128_t endpoint_hash = string_to_uint128_hash("transfer_fio_domain");

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", "transfer_fio_domain",
"FIO fee not found for endpoint", ErrorNoEndpoint);

//Transfer the domain
const name nm = name{new_owner_fio_public_key};
domainsbyname.modify(domains_iter, actor, [&](struct domain &a) {
a.account = nm.value;
});

//fees
const uint64_t fee_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),
"register_fio_address unexpected fee type for endpoint register_fio_domain, expected 0",
ErrorNoEndpoint);

fio_400_assert(max_fee >= (int64_t) fee_amount, "max_fee", to_string(max_fee),
"Fee exceeds supplied maximum.",
ErrorMaxFeeExceeded);

fio_fees(actor, asset(fee_amount, FIOSYMBOL));
processbucketrewards(tpid, fee_amount, get_self());

if (XFERDOMAINRAM > 0) {
action(
permission_level{SYSTEMACCOUNT, "active"_n},
"eosio"_n,
"incram"_n,
std::make_tuple(actor, XFERDOMAINRAM)
).send();
}

const string response_string = string("{\"status\": \"OK\",\"fee_collected\":") +
to_string(fee_amount) + string("}");

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

send_response(response_string.c_str());
}

void decrcounter(const string &fio_address, const int32_t step) {

check(step > 0, "step must be greater than 0");
Expand All @@ -1070,5 +1138,5 @@ namespace fioio {
};

EOSIO_DISPATCH(FioNameLookup, (regaddress)(addaddress)(regdomain)(renewdomain)(renewaddress)(setdomainpub)(burnexpired)(decrcounter)
(bind2eosio))
(bind2eosio) (xferdomain))
}
2 changes: 2 additions & 0 deletions fio.contracts/contracts/fio.common/fioerror.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ namespace fioio {
constexpr auto ErrorClientKeyNotFound = ident | httpDataError | 149; // Fioname not yet registered (No clientkey)
constexpr auto ErrorTimeViolation = ident | httpDataError | 150;
constexpr auto ErrorNoAuthWaits = ident | httpDataError | 151;
constexpr auto ErrorDomainOwner = ident | httpInvalidError | 153;
constexpr auto ErrorTransactionTooLarge = ident | httpDataError | 152; // Transaction too large

/**
* Helper funtions for detecting rich error messages and extracting bitfielded values
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace fioio {
if (action == "regaddress" || action == "regdomain" || action == "addaddress" ||
action == "renewdomain" || action == "renewaddress" ||
action == "setdomainpub" || action == "bind2eosio" ||
action == "burnexpired" || action == "decrcounter" )
action == "burnexpired" || action == "decrcounter" || action == "transferdom" )
return "fio.address";


Expand Down
48 changes: 48 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3643,6 +3643,54 @@ if( options.count(name) ) { \
} CATCH_AND_CALL(next);
}

void read_write::transfer_fio_domain(const read_write::transfer_fio_domain_params &params,
next_function<read_write::transfer_fio_domain_results> next) {
try {
FIO_403_ASSERT(params.size() == 4,
fioio::ErrorTransaction); // variant object contains authorization, account, name, data
auto pretty_input = std::make_shared<packed_transaction>();
auto resolver = make_resolver(this, abi_serializer_max_time);
transaction_metadata_ptr ptrx;
dlog("transfer_fio_domain called");
try {
abi_serializer::from_variant(params, *pretty_input, resolver, abi_serializer_max_time);
ptrx = std::make_shared<transaction_metadata>(pretty_input);
} EOS_RETHROW_EXCEPTIONS(chain::fio_invalid_trans_exception, "Invalid transaction")

transaction trx = pretty_input->get_transaction();
vector<action> &actions = trx.actions;
dlog("\n");
dlog(actions[0].name.to_string());
FIO_403_ASSERT(trx.total_actions() == 1, fioio::InvalidAccountOrAction);
FIO_403_ASSERT(actions[0].authorization.size() > 0, fioio::ErrorTransaction);
FIO_403_ASSERT(actions[0].account.to_string() == "fio.address", fioio::InvalidAccountOrAction);
FIO_403_ASSERT(actions[0].name.to_string() == "xferdomain", fioio::InvalidAccountOrAction);

app().get_method<incoming::methods::transaction_async>()(ptrx, true, [this, next](
const fc::static_variant<fc::exception_ptr, transaction_trace_ptr> &result) -> void {
if (result.contains<fc::exception_ptr>()) {
next(result.get<fc::exception_ptr>());
} else {
auto trx_trace_ptr = result.get<transaction_trace_ptr>();

try {
fc::variant output;
try {
output = db.to_variant_with_abi(*trx_trace_ptr, abi_serializer_max_time);
} catch (chain::abi_exception &) {
output = *trx_trace_ptr;
}
const chain::transaction_id_type &id = trx_trace_ptr->id;
next(read_write::transfer_fio_domain_results{id, output});
} CATCH_AND_CALL(next);
}
});

} catch (boost::interprocess::bad_alloc &) {
chain_plugin::handle_db_exhaustion();
} CATCH_AND_CALL(next);
}

/***
* unregister_proxy - This enpoint will set the specified fio address account to no longer be a proxy.
* @param p Accepts a variant object of from a pushed fio transaction that contains a public key in packed actions
Expand Down
10 changes: 10 additions & 0 deletions plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,15 @@ namespace eosio {

//end renew_address

//begin transfer_fio_domain
using transfer_fio_domain_params = fc::variant_object;
struct transfer_fio_domain_results {
chain::transaction_id_type transaction_id;
fc::variant processed;
};

void transfer_fio_domain(const transfer_fio_domain_params &params,
chain::plugin_interface::next_function<transfer_fio_domain_results> next);

//begin burn_expired
using burn_expired_params = fc::variant_object;
Expand Down Expand Up @@ -1306,6 +1315,7 @@ FC_REFLECT(eosio::chain_apis::read_only::avail_check_result, (is_registered));
FC_REFLECT(eosio::chain_apis::read_only::fio_key_lookup_params, (key)(chain))
FC_REFLECT(eosio::chain_apis::read_only::fio_key_lookup_result, (name)(expiration));
FC_REFLECT(eosio::chain_apis::read_write::register_fio_address_results, (transaction_id)(processed));
FC_REFLECT(eosio::chain_apis::read_write::transfer_fio_domain_results, (transaction_id)(processed));
FC_REFLECT(eosio::chain_apis::read_write::set_fio_domain_public_results, (transaction_id)(processed));
FC_REFLECT(eosio::chain_apis::read_write::register_fio_domain_results, (transaction_id)(processed));
FC_REFLECT(eosio::chain_apis::read_write::reject_funds_request_results, (transaction_id)(processed));
Expand Down