Merge branch 'master' of https://github.com/cryptonomex/graphene
This commit is contained in:
commit
487046e375
3 changed files with 24 additions and 43 deletions
|
|
@ -111,31 +111,6 @@ void database::open(
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto is_new = [&]() -> bool
|
|
||||||
{
|
|
||||||
// directory doesn't exist
|
|
||||||
if( !fc::exists( data_dir ) )
|
|
||||||
return true;
|
|
||||||
// if directory exists but is empty, return true; else false.
|
|
||||||
return ( fc::directory_iterator( data_dir ) == fc::directory_iterator() );
|
|
||||||
};
|
|
||||||
|
|
||||||
auto is_outdated = [&]() -> bool
|
|
||||||
{
|
|
||||||
if( !fc::exists( data_dir / "db_version" ) )
|
|
||||||
return true;
|
|
||||||
std::string version_str;
|
|
||||||
fc::read_file_contents( data_dir / "db_version", version_str );
|
|
||||||
return (version_str != GRAPHENE_CURRENT_DB_VERSION);
|
|
||||||
};
|
|
||||||
|
|
||||||
if( (!is_new()) && is_outdated() )
|
|
||||||
{
|
|
||||||
ilog( "Old database version detected, reindex is required" );
|
|
||||||
wipe( data_dir, false );
|
|
||||||
fc::remove_all( data_dir / "db_version" );
|
|
||||||
}
|
|
||||||
|
|
||||||
object_database::open(data_dir);
|
object_database::open(data_dir);
|
||||||
|
|
||||||
_block_id_to_block.open(data_dir / "database" / "block_num_to_block");
|
_block_id_to_block.open(data_dir / "database" / "block_num_to_block");
|
||||||
|
|
@ -153,19 +128,6 @@ void database::open(
|
||||||
FC_ASSERT( head_block_num() == 0, "last block ID does not match current chain state" );
|
FC_ASSERT( head_block_num() == 0, "last block ID does not match current chain state" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// doing this down here helps ensure that DB will be wiped
|
|
||||||
// if any of the above steps were interrupted on a previous run
|
|
||||||
if( !fc::exists( data_dir / "db_version" ) )
|
|
||||||
{
|
|
||||||
std::ofstream db_version(
|
|
||||||
(data_dir / "db_version").generic_string().c_str(),
|
|
||||||
std::ios::out | std::ios::binary | std::ios::trunc );
|
|
||||||
std::string version_string = GRAPHENE_CURRENT_DB_VERSION;
|
|
||||||
db_version.write( version_string.c_str(), version_string.size() );
|
|
||||||
db_version.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
//idump((head_block_id())(head_block_num()));
|
//idump((head_block_id())(head_block_num()));
|
||||||
}
|
}
|
||||||
FC_CAPTURE_LOG_AND_RETHROW( (data_dir) )
|
FC_CAPTURE_LOG_AND_RETHROW( (data_dir) )
|
||||||
|
|
|
||||||
|
|
@ -53,16 +53,34 @@ struct static_variant_map_visitor
|
||||||
int which;
|
int which;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template< typename StaticVariant >
|
||||||
|
struct from_which_visitor
|
||||||
|
{
|
||||||
|
typedef StaticVariant result_type;
|
||||||
|
|
||||||
|
template< typename Member > // Member is member of static_variant
|
||||||
|
result_type operator()( const Member& dummy )
|
||||||
|
{
|
||||||
|
Member result;
|
||||||
|
from_variant( v, result );
|
||||||
|
return result; // converted from StaticVariant to Result automatically due to return type
|
||||||
|
}
|
||||||
|
|
||||||
|
const variant& v;
|
||||||
|
|
||||||
|
from_which_visitor( const variant& _v ) : v(_v) {}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
T from_which_variant( int which, const variant& v )
|
T from_which_variant( int which, const variant& v )
|
||||||
{
|
{
|
||||||
// Parse a variant for a known which()
|
// Parse a variant for a known which()
|
||||||
T result;
|
T dummy;
|
||||||
result.set_which( which );
|
dummy.set_which( which );
|
||||||
from_variant( v, result );
|
impl::from_which_visitor< T > vtor(v);
|
||||||
return result;
|
return dummy.visit( vtor );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
||||||
|
|
@ -2694,11 +2694,12 @@ bool wallet_api::import_account_keys( string filename, string password, string s
|
||||||
const auto plain_text = fc::aes_decrypt( password_hash, encrypted_key );
|
const auto plain_text = fc::aes_decrypt( password_hash, encrypted_key );
|
||||||
const auto private_key = fc::raw::unpack<private_key_type>( plain_text );
|
const auto private_key = fc::raw::unpack<private_key_type>( plain_text );
|
||||||
|
|
||||||
import_key( dest_account_name, string( graphene::utilities::key_to_wif( private_key ) ) );
|
my->import_key( dest_account_name, string( graphene::utilities::key_to_wif( private_key ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
save_wallet_file();
|
||||||
|
|
||||||
FC_ASSERT( found_account );
|
FC_ASSERT( found_account );
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue