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

Add FIP11b (transfer_tokens_fio_add) to chain and api plugins #306

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions plugins/chain_api_plugin/chain_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ namespace eosio {
chain_apis::read_write::renew_fio_domain_results, 202),
CHAIN_RW_CALL_ASYNC(renew_fio_address,
chain_apis::read_write::renew_fio_address_results, 202),
CHAIN_RW_CALL_ASYNC(transfer_tokens_fio_add,
chain_apis::read_write::transfer_tokens_fio_add_results, 202),
CHAIN_RW_CALL_ASYNC(record_obt_data,
chain_apis::read_write::record_obt_data_results, 202),
CHAIN_RW_CALL_ASYNC(reject_funds_request,
Expand Down
51 changes: 51 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4003,6 +4003,57 @@ if( options.count(name) ) { \
} CATCH_AND_CALL(next);
}

void read_write::transfer_tokens_fio_add(const read_write::transfer_tokens_fio_add_params &params,
next_function<read_write::transfer_tokens_fio_add_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_tokens_fio_add 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.reqobt", fioio::InvalidAccountOrAction);
FIO_403_ASSERT(actions[0].name.to_string() == "trnsfiopubad", 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_tokens_fio_add_results{id, output});
} CATCH_AND_CALL(next);
}
});


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

/***
* record_obt_data - This api method will invoke the fio.request.obt smart contract for recordobt. this api method is
Expand Down
13 changes: 13 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 @@ -1241,6 +1241,18 @@ namespace eosio {
chain::plugin_interface::next_function<cancel_funds_request_results> next);
//end added for cancel request

//Begin Added for transfer_tokens_fio_add api method
using transfer_tokens_fio_add_params = fc::variant_object;

struct transfer_tokens_fio_add_results {
chain::transaction_id_type transaction_id;
fc::variant processed;
};

void transfer_tokens_fio_add(const transfer_tokens_fio_add_params &params,
chain::plugin_interface::next_function<transfer_tokens_fio_add_results> next);
//end

//Begin Added for record send api method
using record_obt_data_params = fc::variant_object;

Expand Down Expand Up @@ -1547,6 +1559,7 @@ FC_REFLECT(eosio::chain_apis::read_write::set_fio_domain_public_results, (transa
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));
FC_REFLECT(eosio::chain_apis::read_write::cancel_funds_request_results, (transaction_id)(processed));
FC_REFLECT(eosio::chain_apis::read_write::transfer_tokens_fio_add_results, (transaction_id)(processed));
FC_REFLECT(eosio::chain_apis::read_write::record_obt_data_results, (transaction_id)(processed));
FC_REFLECT(eosio::chain_apis::read_write::record_send_results, (transaction_id)(processed));
FC_REFLECT(eosio::chain_apis::read_write::submit_bundled_transaction_results, (transaction_id)(processed));
Expand Down