From b27137aacd121de45ef81e61f1b52983315bee69 Mon Sep 17 00:00:00 2001 From: maodaishan Date: Mon, 25 Mar 2019 11:47:07 +0800 Subject: [PATCH] modify cleos : add "homepage" for "get account", and add "set personal ..." in "bos.contracts",new contract "personal.bos" was added to let user save personal data,ex. homepage. To let user use it easier, modify "cleos" adding below functions: 1. in "cleos get account xxx",if this account has table "personaldata" and has key "homepage",display its value in result. 2. add new sub command: "cleos set personal xx1 xx2 xx3" for easy set personal data,where xx1 is account to operate xx2 is key xx3 is value it's implimented by calling "personal.bos"->setpersonal --- plugins/chain_plugin/chain_plugin.cpp | 21 ++++++++++ .../eosio/chain_plugin/chain_plugin.hpp | 3 +- programs/cleos/main.cpp | 39 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 2603a87178b..672ede68b22 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -1755,6 +1755,27 @@ read_only::get_account_results read_only::get_account( const get_account_params& } } } + + //get homepage + const auto& personal_account = db.db().get( N(personal.bos) ); + abi_def abi_personal; + if( abi_serializer::to_abi(personal_account.abi, abi_personal) ) { + abi_serializer abis_personal( abi_personal, abi_serializer_max_time ); + const auto* t_id = d.find(boost::make_tuple( N(personal.bos), params.account_name, N(personaldata) )); + if (t_id != nullptr) { + const auto &idx = d.get_index(); + + name key_name{"homepage"}; + auto it = idx.find(boost::make_tuple( t_id->id, key_name.value )); + if ( it != idx.end() ) { + vector data; + copy_inline_row(*it, data); + variant raw_data= abis_personal.binary_to_variant( "personal", data, abi_serializer_max_time, shorten_abi_errors ); + result.homepage=raw_data["value"].as_string(); + } + } + } + return result; } diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index 0b69a6af89a..d7b8bb7ee69 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -135,6 +135,7 @@ class read_only { fc::variant self_delegated_bandwidth; fc::variant refund_request; fc::variant voter_info; + string homepage; }; struct get_account_params { @@ -695,7 +696,7 @@ FC_REFLECT( eosio::chain_apis::read_only::get_scheduled_transactions_result, (tr FC_REFLECT( eosio::chain_apis::read_only::get_account_results, (account_name)(head_block_num)(head_block_time)(privileged)(last_code_update)(created) (core_liquid_balance)(ram_quota)(net_weight)(cpu_weight)(net_limit)(cpu_limit)(ram_usage)(permissions) - (total_resources)(self_delegated_bandwidth)(refund_request)(voter_info) ) + (total_resources)(self_delegated_bandwidth)(refund_request)(voter_info)(homepage) ) FC_REFLECT( eosio::chain_apis::read_only::get_code_results, (account_name)(code_hash)(wast)(wasm)(abi) ) FC_REFLECT( eosio::chain_apis::read_only::get_code_hash_results, (account_name)(code_hash) ) FC_REFLECT( eosio::chain_apis::read_only::get_abi_results, (account_name)(abi) ) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index af70e0683b8..517ba7c0517 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -771,6 +771,36 @@ struct set_action_permission_subcommand { } }; +struct set_personal_subcommand { + string accountStr; + string keyStr; + string valueStr; + + set_personal_subcommand(CLI::App* actionRoot) { + auto personal = actionRoot->add_subcommand("personal", localized("set personal data for account")); + personal->add_option("account", accountStr, localized("the account to set personal data for"))->required(); + personal->add_option("key", keyStr, localized("the key of personal data"))->required(); + personal->add_option("value", valueStr, localized("the value of personal data"))->required(); + + add_standard_transaction_options(personal, "account@active"); + + personal->set_callback([this] { + name account = name(accountStr); + auto action_var = fc::mutable_variant_object() + ("account", account) + ("key", keyStr) + ("value", valueStr); + + send_actions( + {create_action( + {permission_level{account,config::active_name}}, + N(personal.bos), + N(setpersonal), + action_var) + }); + }); + } +}; bool local_port_used() { using namespace boost::asio; @@ -1735,6 +1765,12 @@ void get_account( const string& accountName, const string& coresym, bool json_fo std::cout << "proxy:" << indent << proxy << std::endl; } } + + if( res.homepage.size() > 0 ){ + std::cout <<"homepage:"; + std::cout << indent << res.homepage << std::endl; + } + std::cout << std::endl; } else { std::cout << fc::json::to_pretty_string(json) << std::endl; @@ -2488,6 +2524,9 @@ int main( int argc, char** argv ) { // set action permission auto setActionPermission = set_action_permission_subcommand(setAction); + //set personal + auto setPersonal = set_personal_subcommand(setSubcommand); + // Transfer subcommand string con = "eosio.token"; string sender;