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

[4.0] if actions.data & actions.hex_data provided, use the hex_data in api call get_transaction_id #1280

Merged
merged 7 commits into from
Jun 15, 2023
39 changes: 39 additions & 0 deletions plugins/chain_api_plugin/chain_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,45 @@ parse_params<chain_apis::read_only::get_transaction_status_params, http_params_t
}
}

// if actions.data & actions.hex_data provided, use the hex_data since only currently support unexploded data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • As part of this effort, I think we should support exploded data.
  • As part of this effort, I think we should provide optional support for exploded data in cleos. For cleos, this should be optional as a user may want to prevent cleos from communicating with nodeos. Could support the option of providing abi. See --unpack-action-data option --abi-file.
  • To increase security, if both "data" and "hex_data" are provide then we should verify they are equivalent.
  • Please add some tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a separate issue to include exploded data handling improvements:
#1282

template<>
chain_apis::read_only::get_transaction_id_params
parse_params<chain_apis::read_only::get_transaction_id_params, http_params_types::params_required>(const std::string& body) {
if (body.empty()) {
EOS_THROW(chain::invalid_http_request, "A Request body is required");
}
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved

try {
fc::variant trx_var = fc::json::from_string( body );
Copy link
Contributor

@greg7mdp greg7mdp Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it an issue that we don't use a yield function to limit the time spent in the deserialization? never mind!

if( trx_var.is_object() ) {
fc::variant_object& vo = trx_var.get_object();
if( vo.contains("actions") && vo["actions"].is_array() ) {
fc::mutable_variant_object mvo = vo;
fc::variants& action_variants = mvo["actions"].get_array();
for( auto& action_v : action_variants ) {
if( action_v.is_object() ) {
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
fc::variant_object& action_vo = action_v.get_object();
if( action_vo.contains( "data" ) && action_vo.contains( "hex_data" ) ) {
fc::mutable_variant_object maction_vo = action_vo;
maction_vo["data"] = maction_vo["hex_data"];
action_vo = maction_vo;
vo = mvo;
}
}
}
}
else {
throw false;
heifner marked this conversation as resolved.
Show resolved Hide resolved
}
}
auto trx = trx_var.as<chain_apis::read_only::get_transaction_id_params>();
if( trx.id() == transaction().id() ) throw false;
return trx;
} catch( ... ) {
EOS_THROW(chain::invalid_http_request, "Invalid transaction");
}
}

#define CALL_WITH_400(api_name, api_handle, api_namespace, call_name, http_response_code, params_type) \
{std::string("/v1/" #api_name "/" #call_name), \
[api_handle](string&&, string&& body, url_response_callback&& cb) mutable { \
Expand Down