// pack action data
string unpacked_action_data_account_string;
string unpacked_action_data_name_string;
string unpacked_action_data_string;
auto pack_action_data = convert->add_subcommand("pack_action_data", localized("From json action data to packed form"));
pack_action_data->add_option("account", unpacked_action_data_account_string, localized("The name of the account that hosts the contract"))->required();
pack_action_data->add_option("name", unpacked_action_data_name_string, localized("The name of the function that's called by this action"))->required();
pack_action_data->add_option("unpacked_action_data", unpacked_action_data_string, localized("The action data expressed as json"))->required();
pack_action_data->set_callback([&] {
fc::variant unpacked_action_data_json;
try {
unpacked_action_data_json = json_from_file_or_string(unpacked_action_data_string);
} EOS_RETHROW_EXCEPTIONS(transaction_type_exception, "Fail to parse unpacked action data JSON")
bytes packed_action_data_string = variant_to_bin(unpacked_action_data_account_string, unpacked_action_data_name_string, unpacked_action_data_json);
std::cout << fc::to_hex(packed_action_data_string.data(), packed_action_data_string.size()) << std::endl;
});
// unpack action data
string packed_action_data_account_string;
string packed_action_data_name_string;
string packed_action_data_string;
auto unpack_action_data = convert->add_subcommand("unpack_action_data", localized("From packed to json action data form"));
unpack_action_data->add_option("account", packed_action_data_account_string, localized("The name of the account that hosts the contract"))->required();
unpack_action_data->add_option("name", packed_action_data_name_string, localized("The name of the function that's called by this action"))->required();
unpack_action_data->add_option("packed_action_data", packed_action_data_string, localized("The action data expressed as packed hex string"))->required();
unpack_action_data->set_callback([&] {
EOS_ASSERT( packed_action_data_string.size() >= 2, transaction_type_exception, "No packed_action_data found" );
vector<char> packed_action_data_blob(packed_action_data_string.size()/2);
fc::from_hex(packed_action_data_string, packed_action_data_blob.data(), packed_action_data_blob.size());
fc::variant unpacked_action_data_json = bin_to_variant(packed_action_data_account_string, packed_action_data_name_string, packed_action_data_blob);
std::cout << fc::json::to_pretty_string(unpacked_action_data_json) << std::endl;
});
版权属于:区块链中文技术社区 / 转载原创者
本文链接:https://bcskill.com/index.php/archives/680.html
相关技术文章仅限于相关区块链底层技术研究,禁止用于非法用途,后果自负!本站严格遵守一切相关法律政策!