Skip to content

Commit

Permalink
modify cleos : add "homepage" for "get account", and add "set persona…
Browse files Browse the repository at this point in the history
……" (EOSIO#70)

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
  • Loading branch information
maodaishan authored and Thaipanda committed Mar 27, 2019
1 parent 8653573 commit 56f84e5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
22 changes: 22 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,28 @@ read_only::get_account_results read_only::get_account( const get_account_params&
}
}
}

//get homepage
if(nullptr != db.db().find<account_object,by_name>(N(personal.bos))){
const auto& personal_account = db.db().get<account_object,by_name>( 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<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( N(personal.bos), params.account_name, N(personaldata) ));
if (t_id != nullptr) {
const auto &idx = d.get_index<key_value_index, by_scope_primary>();

name key_name{"homepage"};
auto it = idx.find(boost::make_tuple( t_id->id, key_name.value ));
if ( it != idx.end() ) {
vector<char> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class read_only {
fc::variant self_delegated_bandwidth;
fc::variant refund_request;
fc::variant voter_info;
string homepage;
};

struct get_account_params {
Expand Down Expand Up @@ -734,7 +735,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) )
Expand Down
39 changes: 39 additions & 0 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,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;
Expand Down Expand Up @@ -1845,6 +1875,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;
Expand Down Expand Up @@ -2603,6 +2639,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;
Expand Down

0 comments on commit 56f84e5

Please sign in to comment.