diff --git a/libraries/chain/block_database.cpp b/libraries/chain/block_database.cpp index 95c37790..cd1f1e29 100644 --- a/libraries/chain/block_database.cpp +++ b/libraries/chain/block_database.cpp @@ -68,8 +68,14 @@ void block_database::flush() _block_num_to_pos.flush(); } -void block_database::store( const block_id_type& id, const signed_block& b ) +void block_database::store( const block_id_type& _id, const signed_block& b ) { + block_id_type id = _id; + if( id == block_id_type() ) + { + id = b.id(); + elog( "id argument of block_database::store() was not initialized for block ${id}", ("id", id) ); + } auto num = block_header::num_from_id(id); _block_num_to_pos.seekp( sizeof( index_entry ) * num ); index_entry e; @@ -103,6 +109,9 @@ void block_database::remove( const block_id_type& id ) bool block_database::contains( const block_id_type& id )const { + if( id == block_id_type() ) + return false; + index_entry e; auto index_pos = sizeof(e)*block_header::num_from_id(id); _block_num_to_pos.seekg( 0, _block_num_to_pos.end ); @@ -116,6 +125,7 @@ bool block_database::contains( const block_id_type& id )const block_id_type block_database::fetch_block_id( uint32_t block_num )const { + assert( block_num != 0 ); index_entry e; auto index_pos = sizeof(e)*block_num; _block_num_to_pos.seekg( 0, _block_num_to_pos.end ); @@ -125,6 +135,7 @@ block_id_type block_database::fetch_block_id( uint32_t block_num )const _block_num_to_pos.seekg( index_pos ); _block_num_to_pos.read( (char*)&e, sizeof(e) ); + FC_ASSERT( e.block_id != block_id_type(), "Empty block_id in block_database (maybe corrupt on disk?)" ); return e.block_id; } diff --git a/libraries/chain/fork_database.cpp b/libraries/chain/fork_database.cpp index 0fab49a3..7910b417 100644 --- a/libraries/chain/fork_database.cpp +++ b/libraries/chain/fork_database.cpp @@ -143,22 +143,30 @@ void fork_database::set_max_size( uint32_t s ) } } - - - bool fork_database::is_known_block(const block_id_type& id)const { auto& index = _index.get(); auto itr = index.find(id); - return itr != index.end(); + if( itr != index.end() ) + return true; + auto& unlinked_index = _unlinked_index.get(); + auto unlinked_itr = unlinked_index.find(id); + return unlinked_itr != unlinked_index.end(); } + item_ptr fork_database::fetch_block(const block_id_type& id)const { - auto itr = _index.get().find(id); - if( itr != _index.get().end() ) + auto& index = _index.get(); + auto itr = index.find(id); + if( itr != index.end() ) return *itr; + auto& unlinked_index = _unlinked_index.get(); + auto unlinked_itr = unlinked_index.find(id); + if( unlinked_itr != unlinked_index.end() ) + return *unlinked_itr; return item_ptr(); } + vector fork_database::fetch_block_by_number(uint32_t num)const { vector result; diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index ac1c334b..68b191e9 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -356,6 +356,12 @@ class wallet_api */ string get_wallet_filename() const; + /** + * Get the WIF private key corresponding to a public key. The + * private key must already be in the wallet. + */ + string get_private_key( public_key_type pubkey )const; + /** * @ingroup Transaction Builder API */ @@ -1301,6 +1307,7 @@ FC_API( graphene::wallet::wallet_api, (get_global_properties) (get_dynamic_global_properties) (get_object) + (get_private_key) (load_wallet_file) (normalize_brain_key) (get_limit_orders) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 0eefe792..1c211d32 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2800,6 +2800,11 @@ string wallet_api::get_key_label( public_key_type key )const return string(); } +string wallet_api::get_private_key( public_key_type pubkey )const +{ + return key_to_wif( my->get_private_key( pubkey ) ); +} + public_key_type wallet_api::get_public_key( string label )const { try { return fc::variant(label).as(); } catch ( ... ){}