Skip to content

Commit a0fb76c

Browse files
nickjjzhaosoftprofe
authored andcommitted
Add a transaction in cleos for contract query
1 parent 2080979 commit a0fb76c

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

programs/cleos/main.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,23 +3063,6 @@ int main( int argc, char** argv ) {
30633063
std::cout << fc::json::to_pretty_string(call(get_key_accounts_func, arg)) << std::endl;
30643064
});
30653065

3066-
// get contract_query
3067-
string acct_name;
3068-
string query;
3069-
string other_args;
3070-
auto getContractQuery =get->add_subcommand("contract_query", localized("Read-only query a contract"));
3071-
getContractQuery->add_option( "contract", code, localized("The contract that operates the query") )->required();
3072-
getContractQuery->add_option( "account", acct_name, localized("The account to query contract for") )->required();
3073-
getContractQuery->add_option( "query", query, localized("The query to retrieve an action of the contract") )->required();
3074-
getContractQuery->add_option("args", other_args, localized("Optional arguments") );
3075-
getContractQuery->callback([&]{
3076-
fc::mutable_variant_object arg;
3077-
arg( "code", code );
3078-
arg( "query", query );
3079-
arg( "args", other_args);
3080-
std::cout<< fc::json::to_pretty_string(call(get_contract_query_func, arg))<<std::endl;
3081-
});
3082-
30833066
// get servants
30843067
string controllingAccount;
30853068
auto getServants = get->add_subcommand("servants", localized("Retrieve accounts which are servants of a given account "));
@@ -3629,6 +3612,27 @@ int main( int argc, char** argv ) {
36293612
}
36303613
});
36313614

3615+
// contract_query subcommand
3616+
string con_account;
3617+
string query;
3618+
string args;
3619+
auto getContractQuery =app.add_subcommand("contract_query", localized("Read-only query a contract"));
3620+
getContractQuery->add_option( "account", con_account, localized("The account to query contract for") )->required();
3621+
getContractQuery->add_option( "query", query, localized("The query to retrieve an action of the contract") )->required();
3622+
getContractQuery->add_option("args", args, localized("Optional arguments") );
3623+
3624+
add_standard_transaction_options_plus_signing(getContractQuery);
3625+
3626+
getContractQuery->callback([&]{
3627+
fc::variant action_args_var;
3628+
if( !args.empty() ) {
3629+
action_args_var = json_from_file_or_string(args, fc::json::parse_type::relaxed_parser);
3630+
}
3631+
auto accountPermissions = get_account_permissions(tx_permission);
3632+
send_actions({chain::action{accountPermissions, name(con_account), name(query),
3633+
variant_to_bin( name(con_account), name(query), action_args_var ) }}, signing_keys_opt.get_keys());
3634+
});
3635+
36323636
// Net subcommand
36333637
string new_host;
36343638
auto net = app.add_subcommand( "net", localized("Interact with local p2p network connections"));

0 commit comments

Comments
 (0)