void wallet_db::add_account( const account_record& blockchain_account, const variant& private_data ) { try { wallet_account_record war; account_record& tmp = war; tmp = blockchain_account; war.private_data = private_data; war.account_address = address(blockchain_account.owner_key); war.wallet_record_index = new_wallet_record_index(); if (has_private_key(war.account_address)) war.is_my_account = true; store_record( war ); auto current_key = lookup_key( blockchain_account.owner_key ); if( current_key.valid() ) { current_key->account_address = address(blockchain_account.owner_key); store_record( *current_key ); } else { wallet_key_record new_key; new_key.wallet_record_index = new_wallet_record_index(); new_key.account_address = address(blockchain_account.owner_key); new_key.public_key = blockchain_account.active_key(); my->load_key_record( new_key, false ); store_key( new_key ); } } FC_CAPTURE_AND_RETHROW( (blockchain_account) ) }
void wallet_db::store_transaction( wallet_transaction_record& trx_to_store ) { try { if( trx_to_store.wallet_record_index == 0 ) trx_to_store.wallet_record_index = new_wallet_record_index(); store_record( trx_to_store ); transactions[ trx_to_store.record_id ] = trx_to_store; } FC_RETHROW_EXCEPTIONS( warn, "", ("trx_to_store",trx_to_store) ) }
void wallet_db::add_account( const string& new_account_name, const public_key_type& new_account_key, const variant& private_data ) { auto current_account_itr = name_to_account_wallet_record_index.find( new_account_name ); FC_ASSERT( current_account_itr == name_to_account_wallet_record_index.end(), "Account with name ${name} already exists", ("name",new_account_name) ); auto current_address_itr = address_to_account_wallet_record_index.find( new_account_key ); FC_ASSERT( current_address_itr == address_to_account_wallet_record_index.end(), "Account with address ${address} already exists", ("name",new_account_key) ); wallet_account_record war; war.name = new_account_name; war.id = 0; war.account_address = address( new_account_key ); war.owner_key = new_account_key; war.set_active_key( blockchain::now(), new_account_key ); war.private_data = private_data; war.wallet_record_index = new_wallet_record_index(); if (has_private_key(war.account_address)) war.is_my_account = true; store_record( war ); auto current_key = lookup_key( new_account_key ); if( current_key ) { current_key->account_address = address(new_account_key); store_record( *current_key, true ); } else { wallet_key_record new_key; new_key.wallet_record_index = new_wallet_record_index(); new_key.account_address = address(new_account_key); new_key.public_key = new_account_key; my->load_key_record( new_key, false ); store_key( new_key ); } }
void wallet_db::store_key( const key_data& key_to_store ) { auto key_itr = keys.find( key_to_store.get_address() ); if( key_itr != keys.end() ) { key_data& old_data = key_itr->second; old_data = key_to_store; if( key_to_store.has_private_key()) { auto oacct = lookup_account( key_to_store.account_address ); FC_ASSERT(oacct.valid(), "expecting an account to existing at this point"); oacct->is_my_account = true; store_record( *oacct ); cache_account( *oacct ); ilog( "WALLET: storing private key for ${key} under account '${account_name}' address: (${account})", ("key",key_to_store.public_key) ("account",key_to_store.account_address) ("account_name",get_account_name(key_to_store.account_address)) ); } else { /* ilog( "WALLET: storing public key ${key} under account named '${account_name}' address: (${account})", ("key",key_to_store.public_key) ("account",key_to_store.account_address) ("account_name",get_account_name(key_to_store.account_address)) ); */ } ilog( "storing key" ); store_record( key_itr->second, true ); } else { auto r = wallet_key_record( key_to_store, new_wallet_record_index() ); store_record( keys[key_to_store.get_address()] = r, true ); auto key = key_to_store.public_key; auto bts_addr = key_to_store.get_address(); btc_to_bts_address[ address(key) ] = bts_addr; btc_to_bts_address[ address(pts_address(key,false,56) )] = bts_addr; btc_to_bts_address[ address(pts_address(key,true,56) ) ] = bts_addr; btc_to_bts_address[ address(pts_address(key,false,0) ) ] = bts_addr; btc_to_bts_address[ address(pts_address(key,true,0) ) ] = bts_addr; ilog( "indexing key ${k}", ("k",address(pts_address(key,false,56) ) ) ); ilog( "indexing key ${k}", ("k",address(pts_address(key,true,56) ) ) ); } }
void wallet_db::store_setting(const string& name, const variant& value) { auto orec = lookup_setting(name); if (orec.valid()) { orec->value = value; settings[name] = *orec; store_record( *orec ); } else { auto rec = wallet_setting_record( setting(name, value), new_wallet_record_index() ); settings[name] = rec; store_record( rec ); } }
void wallet_db::cache_balance( const bts::blockchain::balance_record& balance_to_cache ) { auto balance_id = balance_to_cache.id(); owallet_balance_record current_bal = lookup_balance(balance_id); wallet_balance_record balance_record; if( !current_bal.valid() ) { balance_record = wallet_balance_record( balance_to_cache, new_wallet_record_index() ); } else { *current_bal = balance_to_cache; balance_record = *current_bal; } store_record( balance_record ); }
wallet_transaction_record wallet_db::cache_transaction( const signed_transaction& trx, const asset& amount, share_type fees, const string& memo_message, const public_key_type& to, time_point_sec created, time_point_sec received, public_key_type from, const vector<address>& extra_addresses ) { try { auto trx_id = trx.id(); auto itr = transactions.find( trx_id ); wallet_transaction_record data; if( itr != transactions.end() ) data = itr->second; if( data.wallet_record_index == 0 ) data.wallet_record_index = new_wallet_record_index(); data.trx = trx; data.transaction_id = trx.id(); data.amount = amount; data.fees = fees; data.to_account = to; data.from_account = from; data.created_time = created; data.received_time = received; data.memo_message = memo_message; data.extra_addresses = extra_addresses; store_record( data ); transactions[trx_id] = data; return data; //transaction_data data } FC_RETHROW_EXCEPTIONS( warn, "", ("trx",trx) ("memo_message",memo_message) ("to",to) ) }
void store_record( T record_to_store, bool sync = true ) { if( record_to_store.wallet_record_index == 0 ) record_to_store.wallet_record_index = new_wallet_record_index(); store_generic_record( generic_wallet_record( record_to_store ), sync ); }
void wallet_db::set_property( property_enum property_id, const variant& v ) { wallet_property_record property_record; auto property_itr = properties.find( property_id ); if( property_itr != properties.end() ) { property_record = property_itr->second; property_record.value = v; } else { if( property_id == property_enum::next_record_number ) property_record = wallet_property_record( wallet_property(property_id, v), 1 ); else property_record = wallet_property_record( wallet_property(property_id, v), new_wallet_record_index() ); } store_record( property_record ); }
void store_and_reload_record( T& record_to_store, const bool sync = false ) { if( record_to_store.wallet_record_index == 0 ) record_to_store.wallet_record_index = new_wallet_record_index(); store_and_reload_generic_record( generic_wallet_record( record_to_store ), sync ); }