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

modify cleos : add "homepage" for "get account", and add "set persona…" #64

Closed
Closed
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
21 changes: 21 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,27 @@ read_only::get_account_results read_only::get_account( const get_account_params&
}
}
}

//get homepage
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