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-7] Add functionality to burn addresses #188

Merged
merged 1 commit into from Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions libraries/chain/include/eosio/chain/contract_types.hpp
Expand Up @@ -124,6 +124,20 @@ namespace eosio {
}
};

struct burnaddress {
string fio_address;
int64_t max_fee;
name actor;
string tpid;

static account_name get_account() {
return N(fio.address);
}

static action_name get_name() {
return N(burnaddress);
}
};

struct xferdomain {
string fio_domain;
Expand Down Expand Up @@ -308,6 +322,7 @@ FC_REFLECT(eosio::chain::onerror, (sender_id)(sent_trx))
FC_REFLECT(eosio::chain::trnsfiopubky, (payee_public_key)(amount)(max_fee)(actor)(tpid))
FC_REFLECT(eosio::chain::regaddress, (fio_address)(owner_fio_public_key)(max_fee)(actor)(tpid))
FC_REFLECT(eosio::chain::regdomain, (fio_domain)(owner_fio_public_key)(max_fee)(actor)(tpid))
FC_REFLECT(eosio::chain::burnaddress, (fio_address)(max_fee)(actor)(tpid))
FC_REFLECT(eosio::chain::xferdomain, (fio_domain)(new_owner_fio_public_key)(max_fee)(actor)(tpid))
FC_REFLECT(eosio::chain::xferaddress, (fio_address)(new_owner_fio_public_key)(max_fee)(actor)(tpid))
FC_REFLECT(eosio::chain::lockperiods, (duration)(percent))
Expand Down
Expand Up @@ -25,7 +25,7 @@ namespace fioio {
action == "remaddress" || action == "remalladdr" ||
action == "renewdomain" || action == "renewaddress" ||
action == "setdomainpub" || action == "bind2eosio" ||
action == "burnexpired" || action == "decrcounter" || action == "xferdomain" || action == "xferaddress" )
action == "burnexpired" || action == "decrcounter" || action == "burnaddress" ||action == "xferdomain" || action == "xferaddress" )
return "fio.address";


Expand Down
2 changes: 2 additions & 0 deletions plugins/chain_api_plugin/chain_api_plugin.cpp
Expand Up @@ -157,6 +157,8 @@ namespace eosio {
chain_apis::read_write::unregister_proxy_results, 202),
CHAIN_RW_CALL_ASYNC(register_proxy,
chain_apis::read_write::register_proxy_results, 202),
CHAIN_RW_CALL_ASYNC(burn_fio_address,
chain_apis::read_write::burn_fio_address_results, 202),
CHAIN_RW_CALL_ASYNC(transfer_fio_domain,
chain_apis::read_write::transfer_fio_domain_results, 202),
CHAIN_RW_CALL_ASYNC(transfer_fio_address,
Expand Down
63 changes: 56 additions & 7 deletions plugins/chain_plugin/chain_plugin.cpp
Expand Up @@ -4543,12 +4543,12 @@ if( options.count(name) ) { \
}

/***
* compute fees - This enpoint will compute fees based on pending votes..
* @param p Accepts a variant object of from a pushed fio transaction that contains a public key in packed actions
* @return result, result.transaction_id (chain::transaction_id_type), result.processed (fc::variant)
*/
* compute fees - This enpoint will compute fees based on pending votes..
* @param p Accepts a variant object of from a pushed fio transaction that contains a public key in packed actions
* @return result, result.transaction_id (chain::transaction_id_type), result.processed (fc::variant)
*/
void read_write::compute_fees(const read_write::compute_fees_params &params,
next_function<read_write::compute_fees_results> next) {
next_function <read_write::compute_fees_results> next) {
try {
FIO_403_ASSERT(params.size() == 4,
fioio::ErrorTransaction); // variant object contains authorization, account, name, data
Expand All @@ -4563,7 +4563,7 @@ if( options.count(name) ) { \
EOS_RETHROW_EXCEPTIONS(chain::fio_invalid_trans_exception, "Invalid transaction")

transaction trx = pretty_input->get_transaction();
vector<action> &actions = trx.actions;
vector <action> &actions = trx.actions;
dlog("\n");
dlog(actions[0].name.to_string());
FIO_403_ASSERT(trx.total_actions() == 1, fioio::InvalidAccountOrAction);
Expand All @@ -4572,7 +4572,7 @@ if( options.count(name) ) { \
FIO_403_ASSERT(actions[0].name.to_string() == "computefees", 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 {
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 {
Expand All @@ -4595,6 +4595,55 @@ if( options.count(name) ) { \
} CATCH_AND_CALL(next);
}

void read_write::burn_fio_address(const read_write::burn_fio_address_params &params,
next_function <read_write::burn_fio_address_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("burn_fio_address 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() == "burnaddress", 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::burn_fio_address_results{id, output});
} CATCH_AND_CALL(next);
}
});

} catch (boost::interprocess::bad_alloc &) {
chain_plugin::handle_db_exhaustion();
} 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 {
Expand Down
11 changes: 11 additions & 0 deletions plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
Expand Up @@ -1064,6 +1064,16 @@ namespace eosio {

//end renew_address

//begin burn_fio_address
using burn_fio_address_params = fc::variant_object;
struct burn_fio_address_results {
chain::transaction_id_type transaction_id;
fc::variant processed;
};

void burn_fio_address(const burn_fio_address_params &params,
chain::plugin_interface::next_function<burn_fio_address_results> next);

//begin transfer_fio_domain
using transfer_fio_domain_params = fc::variant_object;
struct transfer_fio_domain_results {
Expand Down Expand Up @@ -1495,6 +1505,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::burn_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::transfer_fio_address_results, (transaction_id)(processed));
FC_REFLECT(eosio::chain_apis::read_write::set_fio_domain_public_results, (transaction_id)(processed));
Expand Down