24 #include <boost/algorithm/string/replace.hpp> 25 #include <boost/range/adaptors.hpp> 38 # include <sys/types.h> 39 # include <sys/stat.h> 44 template class api<graphene::wallet::wallet_api, identity_member_with_optionals>;
51 namespace graphene {
namespace wallet {
namespace detail {
55 _chain_id(initial_data.chain_id),
58 _remote_net_broadcast(rapi->network_broadcast()),
59 _remote_hist(rapi->history())
66 wlog(
"Custom operations API is not active on server.");
71 FC_THROW(
"Remote server gave us an unexpected chain_id",
72 (
"remote_chain_id", remote_chain_id)
110 result[
"head_block_num"] = dynamic_props.head_block_number;
111 result[
"head_block_id"] =
fc::variant(dynamic_props.head_block_id, 1);
115 result[
"next_maintenance_time"] =
117 result[
"chain_id"] = chain_props.chain_id;
118 stringstream participation;
119 participation << fixed << std::setprecision(2) << (100.0*
fc::popcount(dynamic_props.recent_slots_filled)) / 128.0;
120 result[
"participation"] = participation.str();
122 result[
"active_committee_members"] =
133 const size_t pos = client_version.find(
'/' );
134 if( pos != string::npos && client_version.size() > pos )
135 client_version = client_version.substr( pos + 1 );
140 result[
"client_version"] = client_version;
147 result[
"compile_date"] =
"compiled on " __DATE__
" at " __TIME__;
148 result[
"boost_version"] = boost::replace_all_copy(std::string(BOOST_LIB_VERSION),
"_",
".");
149 result[
"openssl_version"] = OPENSSL_VERSION_TEXT;
151 std::string bitness = boost::lexical_cast<std::string>(8 *
sizeof(
int*)) +
"-bit";
152 #if defined(__APPLE__) 153 std::string os =
"osx";
154 #elif defined(__linux__) 155 std::string os =
"linux";
156 #elif defined(_MSC_VER) 157 std::string os =
"win32";
159 std::string os =
"other";
161 result[
"build"] = os +
" " + bitness;
168 ilog(
"Quitting Cli Wallet ..." );
170 throw fc::canceled_exception();
183 return _remote_db->get_dynamic_global_properties();
188 fc::async([
this]{resync();},
"Resync after block");
201 FC_THROW(
"Unsupported operation: \"${operation_name}\"", (
"operation_name", operation_name));
205 void wallet_api_impl::init_prototype_ops()
208 int64_t op_count = op.
count();
209 for( int64_t t=0; t<op_count; t++ )
217 int wallet_api_impl::find_first_unused_derived_key_index(
const fc::ecc::private_key& parent_key)
219 int first_unused_index = 0;
220 int number_of_consecutive_unused_keys = 0;
221 for (
int key_index = 0; ; ++key_index)
225 if(
_keys.find(derived_public_key) ==
_keys.end() )
227 if (number_of_consecutive_unused_keys)
229 ++number_of_consecutive_unused_keys;
230 if (number_of_consecutive_unused_keys > 5)
231 return first_unused_index;
235 first_unused_index = key_index;
236 number_of_consecutive_unused_keys = 1;
242 first_unused_index = 0;
243 number_of_consecutive_unused_keys = 0;
248 void wallet_api_impl::enable_umask_protection()
251 _old_umask = umask( S_IRWXG | S_IRWXO );
255 void wallet_api_impl::disable_umask_protection()
267 fc::path dest_path = destination_filename + _wallet_filename_extension;
272 dest_path = destination_filename +
"-" +
to_string( suffix ) + _wallet_filename_extension;
274 wlog(
"backing up wallet ${src} to ${dest}",
276 (
"dest", dest_path) );
281 enable_umask_protection();
285 disable_umask_protection();
289 disable_umask_protection();
303 void wallet_api_impl::resync()
317 std::vector<string> pending_account_names =
321 std::vector<fc::optional<graphene::chain::account_object >>
322 pending_account_objects =
_remote_db->lookup_account_names( pending_account_names );
326 if( optional_account )
327 claim_registered_account(*optional_account);
333 std::vector<string> pending_witness_names =
337 std::vector<fc::optional<graphene::chain::account_object>> owner_account_objects =
338 _remote_db->lookup_account_names(pending_witness_names);
342 if (optional_account)
344 auto account_id = std::string(optional_account->id);
347 claim_registered_witness(optional_account->name);
361 if( wallet_filename ==
"" )
369 FC_THROW(
"Wallet chain ID does not match",
373 size_t account_pagination = 100;
374 vector< std::string > account_ids_to_send;
376 account_ids_to_send.reserve( std::min( account_pagination, n ) );
379 for(
size_t start=0; start<n; start+=account_pagination )
381 size_t end = std::min( start+account_pagination, n );
382 assert( end > start );
383 account_ids_to_send.clear();
384 std::vector< account_object > old_accounts;
385 for(
size_t i=start; i<end; i++ )
388 old_accounts.push_back( *it );
389 auto account_id = std::string(old_accounts.back().id);
390 account_ids_to_send.push_back( account_id );
393 std::vector< optional< account_object > > accounts =
_remote_db->get_accounts(account_ids_to_send, {});
395 FC_ASSERT( accounts.size() == account_ids_to_send.size() );
402 elog(
"Could not find account ${id} : \"${name}\" does not exist on the chain!",
403 (
"id", old_acct.
id)(
"name", old_acct.
name) );
412 wlog(
"Account ${id} : \"${name}\" updated on chain", (
"id", acct->id)(
"name", acct->name) );
433 if( wallet_filename ==
"" )
436 wlog(
"saving wallet to file ${fn}", (
"fn", wallet_filename) );
442 enable_umask_protection();
449 std::string tmp_wallet_filename = wallet_filename +
".tmp";
451 outfile.write( data.c_str(), data.length() );
455 wlog(
"saved successfully wallet to tmp file ${fn}", (
"fn", tmp_wallet_filename) );
457 std::string wallet_file_content;
460 if (wallet_file_content == data) {
461 wlog(
"validated successfully tmp wallet file ${fn}", (
"fn", tmp_wallet_filename) );
463 fc::rename( tmp_wallet_filename, wallet_filename );
465 wlog(
"renamed successfully tmp wallet file ${fn}", (
"fn", tmp_wallet_filename) );
469 FC_THROW(
"tmp wallet file cannot be validated ${fn}", (
"fn", tmp_wallet_filename) );
472 wlog(
"successfully saved wallet to file ${fn}", (
"fn", wallet_filename) );
474 disable_umask_protection();
483 disable_umask_protection();
static string to_string(const variant &v, output_formatting format=stringify_large_ints_and_doubles, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
map< string, vector< string > > pending_account_registrations
fc::path parent_path() const
bool exists(const path &p)
std::string get_approximate_relative_time_string(const time_point_sec &event_time, const time_point_sec &relative_to_time=fc::time_point::now(), const std::string &ago=" ago")
auto async(Functor &&f, const char *desc FC_TASK_NAME_DEFAULT_ARG, priority prio=priority()) -> fc::future< decltype(f())>
dynamic_global_property_object get_dynamic_global_properties() const
const char *const git_revision_sha
void set_operation_fees(signed_transaction &tx, const fee_schedule &s) const
fc::api< custom_operations_api > _custom_operations
vector< operation > operations
public_key get_public_key() const
#define GRAPHENE_MAX_NESTED_OBJECTS
contains all of the parameters necessary to calculate the fee for any operation
This class represents an account on the object graphAccounts are the primary unit of authority on the...
Maintains global state information (committee_member list, current fees)This is an implementation det...
tracks the blockchain state in an extensible manner
An order-perserving dictionary of variant's.
bool copy_wallet_file(string destination_filename)
make a copy of the wallet file Note: this will not overwrite. It simply adds a version suffix...
Used to generate a useful error report when an exception is thrown.At each level in the stack where t...
flat_map< string, operation > _prototype_ops
void rename(const path &from, const path &to)
fc::static_variant< transfer_operation, limit_order_create_operation, limit_order_cancel_operation, call_order_update_operation, fill_order_operation, account_create_operation, account_update_operation, account_whitelist_operation, account_upgrade_operation, account_transfer_operation, asset_create_operation, asset_update_operation, asset_update_bitasset_operation, asset_update_feed_producers_operation, asset_issue_operation, asset_reserve_operation, asset_fund_fee_pool_operation, asset_settle_operation, asset_global_settle_operation, asset_publish_feed_operation, witness_create_operation, witness_update_operation, proposal_create_operation, proposal_update_operation, proposal_delete_operation, withdraw_permission_create_operation, withdraw_permission_update_operation, withdraw_permission_claim_operation, withdraw_permission_delete_operation, committee_member_create_operation, committee_member_update_operation, committee_member_update_global_parameters_operation, vesting_balance_create_operation, vesting_balance_withdraw_operation, worker_create_operation, custom_operation, assert_operation, balance_claim_operation, override_transfer_operation, transfer_to_blind_operation, blind_transfer_operation, transfer_from_blind_operation, asset_settle_cancel_operation, asset_claim_fees_operation, fba_distribute_operation, bid_collateral_operation, execute_bid_operation, asset_claim_pool_operation, asset_update_issuer_operation, htlc_create_operation, htlc_redeem_operation, htlc_redeemed_operation, htlc_extend_operation, htlc_refund_operation, custom_authority_create_operation, custom_authority_update_operation, custom_authority_delete_operation, ticket_create_operation, ticket_update_operation, liquidity_pool_create_operation, liquidity_pool_delete_operation, liquidity_pool_deposit_operation, liquidity_pool_withdraw_operation, liquidity_pool_exchange_operation, samet_fund_create_operation, samet_fund_delete_operation, samet_fund_update_operation, samet_fund_borrow_operation, samet_fund_repay_operation, credit_offer_create_operation, credit_offer_delete_operation, credit_offer_update_operation, credit_offer_accept_operation, credit_deal_repay_operation, credit_deal_expired_operation >
void create_directories(const path &p)
void read_file_contents(const fc::path &filename, std::string &result)
visitor::result_type visit(visitor &v)
map< string, string > pending_witness_registrations
variant_object about() const
static variant from_file(const fc::path &p, parse_type ptype=legacy_parser, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
static constexpr size_t count()
provides stack-based nullable value similar to boost::optional
std::string key_to_wif(const fc::sha256 &private_secret)
const uint32_t git_revision_unix_timestamp
fc::ecc::private_key derive_private_key(const std::string &prefix_string, int sequence_number)
fc::api< database_api > _remote_db
bool update_account(const account_object &acct)
virtual ~wallet_api_impl()
global_property_object get_global_properties() const
operation get_prototype_operation(string operation_name)
account_multi_index_type my_accounts
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
string name
The account's name. This name must be unique among all account names on the graph. May not be empty.
T as(uint32_t max_depth) const
const char *const git_revision_sha
adds a signature to a transaction
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
void save_wallet_file(string wallet_filename="")
static string to_pretty_string(const variant &v, output_formatting format=stringify_large_ints_and_doubles, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
const uint32_t git_revision_unix_timestamp
string get_wallet_filename() const
std::string to_string(double)
bool load_wallet_file(string wallet_filename="")
map< public_key_type, string > _keys
void set_which(tag_type tag)
Maintains global state information (committee_member list, current fees)This is an implementation det...
asset set_fee(operation &op, const price &core_exchange_rate=price::unit_price()) const
uint8_t popcount(uint64_t v)
const char *const git_revision_description
void copy(const path &from, const path &to)
an elliptic curve private key.
void on_block_applied(const variant &block_id)
wraps boost::filesystem::path to provide platform independent path manipulation.
path absolute(const path &p)
An order-perserving dictionary of variant's.
chain_property_object get_chain_properties() const