提交 2c08d520 编写于 作者: D Daniel Larimer

Improving get account

- make signing transactions default (redefining -s to mean skip
                                     signatures)
- adding permission status to ./eosc get account
上级 a198cf3f
......@@ -28,6 +28,16 @@ struct shared_authority {
UInt32 threshold = 0;
shared_vector<types::AccountPermissionWeight> accounts;
shared_vector<types::KeyPermissionWeight> keys;
Authority to_authority()const {
Authority auth;
auth.threshold = threshold;
auth.keys.reserve(keys.size());
auth.accounts.reserve(accounts.size());
for( const auto& k : keys ) { auth.keys.emplace_back( k ); }
for( const auto& a : accounts ) { auth.accounts.emplace_back( a ); }
return auth;
}
};
inline bool operator< (const types::AccountPermission& a, const types::AccountPermission& b) {
......
......@@ -298,6 +298,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
const auto& balance = d.get<BalanceObject,byOwnerName>( params.name );
const auto& staked_balance = d.get<StakedBalanceObject,byOwnerName>( params.name );
if( accnt.abi.size() > 4 ) {
eos::types::Abi abi;
fc::datastream<const char*> ds( accnt.abi.data(), accnt.abi.size() );
......@@ -310,6 +311,14 @@ read_only::get_account_results read_only::get_account( const get_account_params&
result.unstaking_balance = staked_balance.unstakingBalance;
result.last_unstaking_time = staked_balance.lastUnstakingTime;
const auto& permissions = d.get_index<permission_index,by_owner>();
auto perm = permissions.lower_bound( boost::make_tuple( params.name ) );
while( perm != permissions.end() && perm->owner == params.name ) {
/// TODO: lookup perm->parent name
result.permissions.push_back( permission{ perm->name, perm->name, perm->auth.to_authority() } );
++perm;
}
return result;
}
......
......@@ -24,6 +24,12 @@ namespace eos {
namespace chain_apis {
struct empty{};
struct permission {
Name name;
Name parent;
types::Authority required_auth;
};
class read_only {
const chain_controller& db;
......@@ -55,12 +61,14 @@ public:
Name name;
};
struct get_account_results {
Name name;
uint64_t eos_balance = 0;
uint64_t staked_balance = 0;
uint64_t unstaking_balance = 0;
fc::time_point_sec last_unstaking_time;
vector<permission> permissions;
optional<producer_info> producer;
optional<types::Abi> abi;
};
......@@ -271,6 +279,7 @@ private:
}
FC_REFLECT( eos::chain_apis::permission, (name)(parent)(required_auth) )
FC_REFLECT(eos::chain_apis::empty, )
FC_REFLECT(eos::chain_apis::read_only::get_info_results,
(head_block_num)(last_irreversible_block_num)(head_block_id)(head_block_time)(head_block_producer)
......@@ -283,7 +292,7 @@ FC_REFLECT( eos::chain_apis::read_write::push_transaction_results, (transaction_
FC_REFLECT( eos::chain_apis::read_only::get_table_rows_params, (json)(table_type)(table_key)(scope)(code)(table)(lower_bound)(upper_bound)(limit) )
FC_REFLECT( eos::chain_apis::read_only::get_table_rows_result, (rows)(more) );
FC_REFLECT( eos::chain_apis::read_only::get_account_results, (name)(eos_balance)(staked_balance)(unstaking_balance)(last_unstaking_time)(producer)(abi) )
FC_REFLECT( eos::chain_apis::read_only::get_account_results, (name)(eos_balance)(staked_balance)(unstaking_balance)(last_unstaking_time)(permissions)(producer)(abi) )
FC_REFLECT( eos::chain_apis::read_only::get_account_params, (name) )
FC_REFLECT( eos::chain_apis::read_only::producer_info, (name) )
FC_REFLECT( eos::chain_apis::read_only::abi_json_to_bin_params, (code)(action)(args) )
......
......@@ -64,7 +64,7 @@ public:
std::vector<std::string> list_wallets();
/// @return A list of private keys from all unlocked wallets in wif format.
std::vector<std::string> list_keys();
map<public_key_type,std::string> list_keys();
/// @return A set of public keys from all unlocked wallets, use with chain_controller::get_required_keys.
flat_set<public_key_type> get_public_keys();
......
......@@ -73,14 +73,14 @@ std::vector<std::string> wallet_manager::list_wallets() {
return result;
}
std::vector<std::string> wallet_manager::list_keys() {
map<public_key_type,string> wallet_manager::list_keys() {
check_timeout();
std::vector<std::string> result;
map<public_key_type,string> result;
for (const auto& i : wallets) {
if (!i.second->is_locked()) {
const auto& keys = i.second->list_keys();
for (const auto& i : keys) {
result.emplace_back(i.second);
result[i.first] = i.second;
}
}
}
......@@ -126,7 +126,7 @@ void wallet_manager::lock(const std::string& name) {
void wallet_manager::unlock(const std::string& name, const std::string& password) {
check_timeout();
if (wallets.count(name) == 0) {
FC_THROW("Wallet not found: ${w}", ("w", name));
open( name );
}
auto& w = wallets.at(name);
if (!w->is_locked()) {
......
......@@ -188,15 +188,15 @@ int main( int argc, char** argv ) {
string name;
string ownerKey;
string activeKey;
bool sign = false;
bool skip_sign = false;
auto createAccount = create->add_subcommand("account", "Create a new account on the blockchain", false);
createAccount->add_option("creator", creator, "The name of the account creating the new account")->required();
createAccount->add_option("name", name, "The name of the new account")->required();
createAccount->add_option("OwnerKey", ownerKey, "The owner public key for the account")->required();
createAccount->add_option("ActiveKey", activeKey, "The active public key for the account")->required();
createAccount->add_flag("-s,--sign", sign, "Specify if unlocked wallet keys should be used to sign transaction");
createAccount->add_flag("-s,--skip-signature", skip_sign, "Specify that unlocked wallet keys should not be used to sign transaction");
createAccount->set_callback([&] {
create_account(creator, name, public_key_type(ownerKey), public_key_type(activeKey), sign);
create_account(creator, name, public_key_type(ownerKey), public_key_type(activeKey), !skip_sign);
});
// Get subcommand
......@@ -281,7 +281,7 @@ int main( int argc, char** argv ) {
->check(CLI::ExistingFile);
auto abi = contractSubcommand->add_option("abi-file,-a,--abi", abiPath, "The ABI for the contract")
->check(CLI::ExistingFile);
contractSubcommand->add_flag("-s,--sign", sign, "Specify if unlocked wallet keys should be used to sign transaction");
contractSubcommand->add_flag("-s,--skip-sign", skip_sign, "Specify if unlocked wallet keys should be used to sign transaction");
contractSubcommand->set_callback([&] {
std::string wast;
std::cout << "Reading WAST..." << std::endl;
......@@ -301,7 +301,7 @@ int main( int argc, char** argv ) {
"setcode", handler);
std::cout << "Publishing contract..." << std::endl;
std::cout << fc::json::to_pretty_string(push_transaction(trx, sign)) << std::endl;
std::cout << fc::json::to_pretty_string(push_transaction(trx, !skip_sign)) << std::endl;
});
// Transfer subcommand
......@@ -314,7 +314,7 @@ int main( int argc, char** argv ) {
transfer->add_option("recipient", recipient, "The account receiving EOS")->required();
transfer->add_option("amount", amount, "The amount of EOS to send")->required();
transfer->add_option("memo", memo, "The memo for the transfer");
transfer->add_flag("-s,--sign", sign, "Specify if unlocked wallet keys should be used to sign transaction");
transfer->add_flag("-s,--skip-sign", skip_sign, "Specify that unlocked wallet keys should not be used to sign transaction");
transfer->set_callback([&] {
SignedTransaction trx;
trx.scope = sort_names({sender,recipient});
......@@ -324,7 +324,7 @@ int main( int argc, char** argv ) {
auto info = get_info();
trx.expiration = info.head_block_time + 100; //chain.head_block_time() + 100;
transaction_set_reference_block(trx, info.head_block_id);
if (sign) {
if (!skip_sign) {
sign_transaction(trx);
}
......@@ -394,6 +394,7 @@ int main( int argc, char** argv ) {
// list wallets
auto listWallet = wallet->add_subcommand("list", "List opened wallets, * = unlocked", false);
listWallet->set_callback([] {
std::cout << "Wallets: \n";
const auto& v = call(wallet_host, wallet_port, wallet_list);
std::cout << fc::json::to_pretty_string(v) << std::endl;
});
......@@ -539,7 +540,7 @@ int main( int argc, char** argv ) {
messageSubcommand->add_option("-p,--permission", permissions,
"An account and permission level to authorize, as in 'account@permission'");
messageSubcommand->add_option("-s,--scope", scopes, "An account in scope for this operation", true);
messageSubcommand->add_flag("--sign", sign, "Specify if unlocked wallet keys should be used to sign transaction");
messageSubcommand->add_flag("--skip-sign", skip_sign, "Specify that unlocked wallet keys should not be used to sign transaction");
messageSubcommand->set_callback([&] {
ilog("Converting argument to binary...");
auto arg= fc::mutable_variant_object
......@@ -561,7 +562,7 @@ int main( int argc, char** argv ) {
fixedPermissions.back()},
result.get_object()["binargs"].as<Bytes>());
trx.scope.assign(scopes.begin(), scopes.end());
ilog("Transaction result:\n${r}", ("r", fc::json::to_pretty_string(push_transaction(trx, sign))));
ilog("Transaction result:\n${r}", ("r", fc::json::to_pretty_string(push_transaction(trx, !skip_sign ))));
});
// push transaction
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册