Example #1
0
   void wallet_db::store_account( const account_data& account )
   { try {
       FC_ASSERT( is_open() );
       FC_ASSERT( account.name != string() );
       FC_ASSERT( account.owner_key != public_key_type() );

       owallet_account_record account_record = lookup_account( account.owner_address() );
       if( !account_record.valid() )
           account_record = wallet_account_record();

       account_data& temp = *account_record;
       temp = account;

       store_and_reload_record( *account_record );

       set<public_key_type> account_public_keys;
       account_public_keys.insert( account_record->owner_key );
       for( const auto& active_key_item : account_record->active_key_history )
       {
           const public_key_type& active_key = active_key_item.second;
           if( active_key == public_key_type() ) continue;
           account_public_keys.insert( active_key );
       }
       if( account.is_delegate() )
       {
           for( const auto& item : account.delegate_info->signing_key_history )
           {
               const public_key_type& signing_key = item.second;
               if( signing_key == public_key_type() ) continue;
               account_public_keys.insert( signing_key );
           }
       }

       for( const public_key_type& account_public_key : account_public_keys )
       {
           const address account_address = address( account_public_key );
           owallet_key_record key_record = lookup_key( account_address );
           if( !key_record.valid() )
           {
               key_data key;
               key.account_address = account_address;
               key.public_key = account_public_key;
               store_key( key );
           }
           else if( key_record->has_private_key() )
           {
               if( !account_record->is_my_account )
               {
                   account_record->is_my_account = true;
                   store_and_reload_record( *account_record );
               }

               if( key_record->account_address != account_record->owner_address() )
               {
                   key_record->account_address = account_record->owner_address();
                   store_key( *key_record );
               }
           }
       }
   } FC_CAPTURE_AND_RETHROW( (account) ) }
Example #2
0
   void wallet_db::store_account( const blockchain::account_record& blockchain_account_record )
   { try {
       FC_ASSERT( is_open() );

       owallet_account_record account_record = lookup_account( blockchain_account_record.owner_address() );
       if( !account_record.valid() )
           account_record = wallet_account_record();

       blockchain::account_record& temp = *account_record;
       temp = blockchain_account_record;

       store_account( *account_record );
   } FC_CAPTURE_AND_RETHROW( (blockchain_account_record) ) }
Example #3
0
   void wallet_db::add_contact_account( const account_record& blockchain_account_record, const variant& private_data )
   { try {
       FC_ASSERT( is_open() );

       owallet_account_record record = lookup_account( blockchain_account_record.name );
       FC_ASSERT( !record.valid(), "Wallet already contains an account with that name!" );

       const public_key_type account_address = blockchain_account_record.owner_key;
       owallet_key_record key_record = lookup_key( account_address );
       FC_ASSERT( !key_record.valid(), "Wallet already contains that key" );

       record = wallet_account_record();
       account_record& temp_record = *record;
       temp_record = blockchain_account_record;
       record->private_data = private_data;

       store_account( *record );
   } FC_CAPTURE_AND_RETHROW( (blockchain_account_record) ) }
Example #4
0
   wallet_account_record wallet_db::store_account( const account_data& account )
   { try {
       FC_ASSERT( is_open() );
       FC_ASSERT( account.name != string() );
       FC_ASSERT( account.owner_key != public_key_type() );

       owallet_account_record account_record = lookup_account( account.owner_address() );
       if( !account_record.valid() )
           account_record = wallet_account_record();

       account_data& temp = *account_record;
       temp = account;

       store_and_reload_record( *account_record );

       const auto index_key = [ & ]( const public_key_type& account_public_key )
       {
           const address account_address = address( account_public_key );
           owallet_key_record key_record = lookup_key( account_address );
           if( !key_record.valid() )
           {
               key_data key;
               key.account_address = account_address;
               key.public_key = account_public_key;
               store_key( key );
           }
           else if( key_record->has_private_key() )
           {
               if( key_record->account_address != account_record->owner_address() )
               {
                   key_record->account_address = account_record->owner_address();
                   store_key( *key_record );
               }
           }
       };
       account_record->scan_public_keys( index_key );

       return *account_record;
   } FC_CAPTURE_AND_RETHROW( (account) ) }