Skip to content

Commit

Permalink
Issue bitshares#1223: Major refactor
Browse files Browse the repository at this point in the history
Huge refactor of all of the light wallet code to facilitate multiple
accounts. The GUI does not yet support multiple accounts, but the light
wallet internals should support them now. For now the GUI assumes there
will only be one account.
  • Loading branch information
nathanielhourt committed Jan 28, 2015
1 parent 7b294e5 commit 5fda006
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 186 deletions.
55 changes: 33 additions & 22 deletions libraries/light_wallet/include/bts/light_wallet/light_wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
namespace bts { namespace light_wallet {
using namespace bts::blockchain;

struct account_data
{
vector<char> encrypted_private_key;
account_record user_account;
map<transaction_id_type, fc::variant_object> transaction_record_cache;
std::multimap<asset_id_type,transaction_id_type> transaction_index;
map<balance_id_type,memo_status> memos;
};
struct light_wallet_data
{
vector<char> encrypted_private_key;
account_record user_account;
fc::time_point last_balance_sync_time;
uint32_t last_transaction_sync_block;
map<transaction_id_type, fc::variant_object> transaction_record_cache;
map<string,pair<price,fc::time_point> > price_cache;
map<balance_id_type,memo_status> memos;

std::map<pair<account_id_type,asset_id_type>,std::set<transaction_id_type>> transaction_index;
fc::time_point_sec last_balance_sync_time;
uint32_t last_transaction_sync_block;
unordered_map<string,pair<price,fc::time_point>> price_cache;
unordered_map<string,account_data> accounts;
};

class light_wallet
Expand Down Expand Up @@ -53,25 +56,29 @@ namespace bts { namespace light_wallet {
const string& password,
const string& brain_seed, const string& salt = string() );

bool request_register_account();
account_record& account();
account_record& fetch_account();
bool request_register_account(const std::string& account_name);
account_record& account(const string& account_name);
account_record& fetch_account(const string& account_name);
vector<account_record*> account_records();

fc::variant_object prepare_transfer( const string& amount,
const string& symbol,
const string& from_account_name,
const string& to_account_name,
const string& memo );
bool complete_transfer(const string& password , const fc::variant_object& transaction_bundle);
bool complete_transfer(const std::string& account_name,
const string& password,
const fc::variant_object& transaction_bundle);

void sync_balance( bool resync_all = false);
void sync_transactions();

oprice get_median_feed_price( const string& symbol );
asset get_fee( const string& symbol );

map<string,double> balance()const;
bts::wallet::transaction_ledger_entry summarize(const fc::variant_object& transaction_bundle);
vector<wallet::transaction_ledger_entry> transactions( const string& symbol );
map<string,double> balance(const std::string& account_name)const;
bts::wallet::transaction_ledger_entry summarize(const std::string& account_name, const fc::variant_object& transaction_bundle);
vector<wallet::transaction_ledger_entry> transactions(const std::string& account_name, const string& symbol );

optional<asset_record> get_asset_record( const string& symbol ) const;
optional<asset_record> get_asset_record( const asset_id_type& id ) const;
Expand All @@ -81,7 +88,7 @@ namespace bts { namespace light_wallet {
bts::rpc::rpc_client _rpc;
fc::path _data_dir;
fc::path _wallet_file;
optional<fc::ecc::private_key> _private_key;
optional<fc::sha512> _wallet_key;
optional<light_wallet_data> _data;
mutable pending_chain_state_ptr _chain_cache;
oaccount_record _relay_fee_collector;
Expand All @@ -90,19 +97,23 @@ namespace bts { namespace light_wallet {

void fetch_welcome_package();
private:
fc::ecc::private_key create_one_time_key(uint64_t sequence_number);
fc::ecc::private_key create_one_time_key(const std::string& account_name, uint64_t sequence_number);
asset get_network_fee( const string& symbol );
fc::variants batch_active_addresses(const char* call_name, fc::variant last_sync, vector<std::string>& account_records);
fc::ecc::private_key private_key(const string& account_name);

map<string, account_record> _account_cache;
};

} }
FC_REFLECT( bts::light_wallet::light_wallet_data,
FC_REFLECT( bts::light_wallet::account_data,
(encrypted_private_key)
(user_account)
(transaction_record_cache)
(transaction_index)
(memos) );
FC_REFLECT( bts::light_wallet::light_wallet_data,
(last_balance_sync_time)
(last_transaction_sync_block)
(transaction_record_cache)
(price_cache)
(memos)
(transaction_index) );
(accounts) );
Loading

0 comments on commit 5fda006

Please sign in to comment.