void pending_chain_state::get_undo_state( const chain_interface_ptr& undo_state_arg )const { auto undo_state = std::dynamic_pointer_cast<pending_chain_state>(undo_state_arg); chain_interface_ptr prev_state = _prev_state.lock(); FC_ASSERT( prev_state ); for( const auto& item : properties ) { auto prev_value = prev_state->get_property( (chain_property_enum)item.first ); undo_state->set_property( (chain_property_enum)item.first, prev_value ); } for( const auto& item : assets ) { auto prev_value = prev_state->get_asset_record( item.first ); if( !!prev_value ) undo_state->store_asset_record( *prev_value ); else undo_state->store_asset_record( item.second.make_null() ); } for( const auto& item : slates ) { auto prev_value = prev_state->get_delegate_slate( item.first ); if( prev_value ) undo_state->store_delegate_slate( item.first, *prev_value ); else undo_state->store_delegate_slate( item.first, delegate_slate() ); } for( const auto& item : accounts ) { auto prev_value = prev_state->get_account_record( item.first ); if( !!prev_value ) undo_state->store_account_record( *prev_value ); else undo_state->store_account_record( item.second.make_null() ); } for( const auto& item : proposals ) { auto prev_value = prev_state->get_proposal_record( item.first ); if( !!prev_value ) undo_state->store_proposal_record( *prev_value ); else undo_state->store_proposal_record( item.second.make_null() ); } for( const auto& item : proposal_votes ) { auto prev_value = prev_state->get_proposal_vote( item.first ); if( !!prev_value ) undo_state->store_proposal_vote( *prev_value ); else { undo_state->store_proposal_vote( item.second.make_null() ); } } for( const auto& item : balances ) { auto prev_value = prev_state->get_balance_record( item.first ); if( !!prev_value ) undo_state->store_balance_record( *prev_value ); else undo_state->store_balance_record( item.second.make_null() ); } for( const auto& item : transactions ) { auto prev_value = prev_state->get_transaction( item.first ); if( !!prev_value ) undo_state->store_transaction( item.first, *prev_value ); else undo_state->store_transaction( item.first, transaction_record() ); } for( const auto& item : bids ) { auto prev_value = prev_state->get_bid_record( item.first ); if( prev_value.valid() ) undo_state->store_bid_record( item.first, *prev_value ); else undo_state->store_bid_record( item.first, order_record() ); } for( const auto& item : asks ) { auto prev_value = prev_state->get_ask_record( item.first ); if( prev_value.valid() ) undo_state->store_ask_record( item.first, *prev_value ); else undo_state->store_ask_record( item.first, order_record() ); } for( const auto& item : shorts ) { auto prev_value = prev_state->get_short_record( item.first ); if( prev_value.valid() ) undo_state->store_short_record( item.first, *prev_value ); else undo_state->store_short_record( item.first, order_record() ); } for( const auto& item : collateral ) { auto prev_value = prev_state->get_collateral_record( item.first ); if( prev_value.valid() ) undo_state->store_collateral_record( item.first, *prev_value ); else undo_state->store_collateral_record( item.first, collateral_record() ); } for( const auto& item : slots ) { auto prev_value = prev_state->get_slot_record( item.first ); if( prev_value ) undo_state->store_slot_record( *prev_value ); else { slot_record invalid_slot_record; invalid_slot_record.start_time = item.first; invalid_slot_record.block_produced = true; invalid_slot_record.block_id = block_id_type(); undo_state->store_slot_record( invalid_slot_record ); } } }
void WalletDb::repair_entrys( const fc::sha512& password ) { try { FC_ASSERT( is_open() ,"Wallet not open!"); vector<GenericWalletEntry> entrys; for( auto iter = my->_entrys.begin(); iter.valid(); ++iter ) entrys.push_back( iter.value() ); // Repair account_data.is_my_account and key_data.account_address uint32_t count = 0; for( GenericWalletEntry& entry : entrys ) { try { if( WalletEntryTypeEnum( entry.type ) == account_entry_type ) { std::cout << "\rRepairing account entry " << std::to_string( ++count ) << std::flush; WalletAccountEntry account_entry = entry.as<WalletAccountEntry>(); store_account( account_entry ); } } catch( ... ) { } } // Repair key_data.public_key when I have the private key and // repair key_data.account_address and account_data.is_my_account count = 0; for( GenericWalletEntry& entry : entrys ) { try { if( WalletEntryTypeEnum( entry.type ) == key_entry_type ) { std::cout << "\rRepairing key entry " << std::to_string( ++count ) << std::flush; WalletKeyEntry key_entry = entry.as<WalletKeyEntry>(); if( key_entry.has_private_key() ) { const PrivateKeyType private_key = key_entry.decrypt_private_key( password ); const PublicKeyType public_key = private_key.get_public_key(); if( key_entry.public_key != public_key ) { const Address key_address = key_entry.get_address(); keys.erase( key_address ); btc_to_gop_address.erase( key_address ); btc_to_gop_address.erase( Address( PtsAddress( key_entry.public_key, false, 0 ) ) ); btc_to_gop_address.erase( Address( PtsAddress( key_entry.public_key, true, 0 ) ) ); btc_to_gop_address.erase( Address( PtsAddress( key_entry.public_key, false, 56 ) ) ); btc_to_gop_address.erase( Address( PtsAddress( key_entry.public_key, true, 56 ) ) ); key_entry.public_key = public_key; my->load_key_entry( key_entry ); } } store_key( key_entry ); } } catch( ... ) { } } // Repair transaction_data.entry_id count = 0; for( GenericWalletEntry& entry : entrys ) { try { if( WalletEntryTypeEnum( entry.type ) == transaction_entry_type ) { std::cout << "\rRepairing transaction entry " << std::to_string( ++count ) << std::flush; WalletTransactionEntry transaction_entry = entry.as<WalletTransactionEntry>(); if( transaction_entry.trx.id() != SignedTransaction().id() ) { const TransactionIdType entry_id = transaction_entry.trx.id(); if( transaction_entry.entry_id != entry_id ) { transactions.erase( transaction_entry.entry_id ); id_to_transaction_entry_index.erase( transaction_entry.entry_id ); transaction_entry.entry_id = entry_id; my->load_transaction_entry( transaction_entry ); } } store_transaction( transaction_entry ); } } catch( ... ) { } } std::cout << "\rWallet entrys repaired. " << std::flush << "\n"; } FC_CAPTURE_AND_RETHROW() }
void pending_chain_state::get_undo_state( const chain_interface_ptr& undo_state_arg )const { auto undo_state = std::dynamic_pointer_cast<pending_chain_state>( undo_state_arg ); chain_interface_ptr prev_state = _prev_state.lock(); FC_ASSERT( prev_state ); for( const auto& item : properties ) { auto prev_value = prev_state->get_property( (chain_property_enum)item.first ); undo_state->set_property( (chain_property_enum)item.first, prev_value ); } for( const auto& item : assets ) { auto prev_value = prev_state->get_asset_record( item.first ); if( !!prev_value ) undo_state->store_asset_record( *prev_value ); else undo_state->store_asset_record( item.second.make_null() ); } for( const auto& item : slates ) { auto prev_value = prev_state->get_delegate_slate( item.first ); if( prev_value ) undo_state->store_delegate_slate( item.first, *prev_value ); else undo_state->store_delegate_slate( item.first, delegate_slate() ); } for( const auto& item : accounts ) { auto prev_value = prev_state->get_account_record( item.first ); if( !!prev_value ) undo_state->store_account_record( *prev_value ); else undo_state->store_account_record( item.second.make_null() ); } #if 0 for( const auto& item : proposals ) { auto prev_value = prev_state->get_proposal_record( item.first ); if( !!prev_value ) undo_state->store_proposal_record( *prev_value ); else undo_state->store_proposal_record( item.second.make_null() ); } for( const auto& item : proposal_votes ) { auto prev_value = prev_state->get_proposal_vote( item.first ); if( !!prev_value ) undo_state->store_proposal_vote( *prev_value ); else { undo_state->store_proposal_vote( item.second.make_null() ); } } #endif for( const auto& item : balances ) { auto prev_value = prev_state->get_balance_record( item.first ); if( !!prev_value ) undo_state->store_balance_record( *prev_value ); else undo_state->store_balance_record( item.second.make_null() ); } for( const auto& item : transactions ) { auto prev_value = prev_state->get_transaction( item.first ); if( !!prev_value ) undo_state->store_transaction( item.first, *prev_value ); else undo_state->store_transaction( item.first, transaction_record() ); } for( const auto& item : bids ) { auto prev_value = prev_state->get_bid_record( item.first ); if( prev_value.valid() ) undo_state->store_bid_record( item.first, *prev_value ); else undo_state->store_bid_record( item.first, order_record() ); } for( const auto& item : asks ) { auto prev_value = prev_state->get_ask_record( item.first ); if( prev_value.valid() ) undo_state->store_ask_record( item.first, *prev_value ); else undo_state->store_ask_record( item.first, order_record() ); } for( const auto& item : shorts ) { auto prev_value = prev_state->get_short_record( item.first ); if( prev_value.valid() ) undo_state->store_short_record( item.first, *prev_value ); else undo_state->store_short_record( item.first, order_record() ); } for( const auto& item : collateral ) { auto prev_value = prev_state->get_collateral_record( item.first ); if( prev_value.valid() ) undo_state->store_collateral_record( item.first, *prev_value ); else undo_state->store_collateral_record( item.first, collateral_record() ); } for( const auto& item : slots ) { auto prev_value = prev_state->get_slot_record( item.first ); if( prev_value ) undo_state->store_slot_record( *prev_value ); else { slot_record invalid_slot_record; invalid_slot_record.start_time = item.first; invalid_slot_record.block_produced = true; invalid_slot_record.block_id = block_id_type(); undo_state->store_slot_record( invalid_slot_record ); } } for( const auto& item : market_statuses ) { auto prev_value = prev_state->get_market_status( item.first.first, item.first.second ); if( prev_value ) undo_state->store_market_status( *prev_value ); else { undo_state->store_market_status( market_status() ); } } for( const auto& item : feeds ) { auto prev_value = prev_state->get_feed( item.first ); if( prev_value ) undo_state->set_feed( *prev_value ); else undo_state->set_feed( feed_record{item.first} ); } for( const auto& item : burns ) { undo_state->store_burn_record( burn_record( item.first ) ); } const auto dirty_markets = prev_state->get_dirty_markets(); undo_state->set_dirty_markets(dirty_markets); /* NOTE: Recent operations are currently not rewound on undo */ }
void wallet_db::repair_records( const fc::sha512& password ) { try { FC_ASSERT( is_open() ); vector<generic_wallet_record> records; for( auto iter = my->_records.begin(); iter.valid(); ++iter ) records.push_back( iter.value() ); // Repair key_data.account_address when possible uint32_t count = 0; for( generic_wallet_record& record : records ) { try { if( wallet_record_type_enum( record.type ) == account_record_type ) { std::cout << "\rRepairing account record " << std::to_string( ++count ) << std::flush; wallet_account_record account_record = record.as<wallet_account_record>(); store_account( account_record ); } } catch( const fc::exception& ) { } } // Repair key_data.public_key when I have the private key and remove if I don't have the private key count = 0; for( generic_wallet_record& record : records ) { try { if( wallet_record_type_enum( record.type ) == key_record_type ) { std::cout << "\rRepairing key record " << std::to_string( ++count ) << std::flush; wallet_key_record key_record = record.as<wallet_key_record>(); const address key_address = key_record.get_address(); if( key_record.has_private_key() ) { const private_key_type private_key = key_record.decrypt_private_key( password ); const public_key_type public_key = private_key.get_public_key(); if( key_record.public_key != public_key ) { keys.erase( key_address ); btc_to_bts_address.erase( key_address ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 0 ) ) ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, true, 0 ) ) ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 56 ) ) ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, true, 56 ) ) ); key_record.public_key = public_key; my->load_key_record( key_record ); } } else { keys.erase( key_address ); btc_to_bts_address.erase( key_address ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 0 ) ) ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, true, 0 ) ) ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 56 ) ) ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, true, 56 ) ) ); remove_item( key_record.wallet_record_index ); continue; } store_key( key_record ); } } catch( const fc::exception& ) { } } // Repair transaction_data.record_id count = 0; for( generic_wallet_record& record : records ) { try { if( wallet_record_type_enum( record.type ) == transaction_record_type ) { std::cout << "\rRepairing transaction record " << std::to_string( ++count ) << std::flush; wallet_transaction_record transaction_record = record.as<wallet_transaction_record>(); if( transaction_record.trx.id() != signed_transaction().id() ) { const transaction_id_type record_id = transaction_record.trx.id(); if( transaction_record.record_id != record_id ) { transactions.erase( transaction_record.record_id ); id_to_transaction_record_index.erase( transaction_record.record_id ); transaction_record.record_id = record_id; my->load_transaction_record( transaction_record ); } } store_transaction( transaction_record ); } } catch( const fc::exception& ) { } } std::cout << "\rWallet records repaired. " << std::flush << "\n"; } FC_CAPTURE_AND_RETHROW() }
void wallet_db::repair_records( const fc::sha512& password ) { try { FC_ASSERT( is_open() ); vector<generic_wallet_record> records; for( auto iter = my->_records.begin(); iter.valid(); ++iter ) records.push_back( iter.value() ); // Repair account_data.is_my_account and key_data.account_address for( generic_wallet_record& record : records ) { try { if( wallet_record_type_enum( record.type ) == account_record_type ) { wallet_account_record account_record = record.as<wallet_account_record>(); store_account( account_record ); } } catch( ... ) { } } // Repair key_data.public_key when I have the private key and // repair key_data.account_address and account_data.is_my_account for( generic_wallet_record& record : records ) { try { if( wallet_record_type_enum( record.type ) == key_record_type ) { wallet_key_record key_record = record.as<wallet_key_record>(); if( key_record.has_private_key() ) { const private_key_type private_key = key_record.decrypt_private_key( password ); const public_key_type public_key = private_key.get_public_key(); if( key_record.public_key != public_key ) { const address key_address = key_record.get_address(); keys.erase( key_address ); btc_to_bts_address.erase( key_address ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 0 ) ) ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, true, 0 ) ) ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 56 ) ) ); btc_to_bts_address.erase( address( pts_address( key_record.public_key, true, 56 ) ) ); key_record.public_key = public_key; my->load_key_record( key_record ); } } store_key( key_record ); } } catch( ... ) { } } // Repair transaction_data.record_id for( generic_wallet_record& record : records ) { try { if( wallet_record_type_enum( record.type ) == transaction_record_type ) { wallet_transaction_record transaction_record = record.as<wallet_transaction_record>(); if( transaction_record.trx.id() != signed_transaction().id() ) { const transaction_id_type record_id = transaction_record.trx.permanent_id(); if( transaction_record.record_id != record_id ) { transactions.erase( transaction_record.record_id ); id_to_transaction_record_index.erase( transaction_record.record_id ); transaction_record.record_id = record_id; my->load_transaction_record( transaction_record ); } } store_transaction( transaction_record ); } } catch( ... ) { } } } FC_CAPTURE_AND_RETHROW() }