Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into develop
  • Loading branch information
vogel76 committed Aug 19, 2014
2 parents 83cce20 + 2027212 commit 1a197ef
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 50 deletions.
8 changes: 4 additions & 4 deletions libraries/api/wallet_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
{
"method_name": "wallet_import_bitcoin",
"description": "Imports a Bitcoin Core or BitShares PTS wallet",
"return_type": "void",
"return_type": "uint32_t",
"parameters" : [
{
"name" : "wallet_filename",
Expand All @@ -118,7 +118,7 @@
{
"method_name": "wallet_import_armory",
"description": "Imports an Armory wallet",
"return_type": "void",
"return_type": "uint32_t",
"parameters" : [
{
"name" : "wallet_filename",
Expand All @@ -141,7 +141,7 @@
{
"method_name": "wallet_import_electrum",
"description": "Imports an Electrum wallet",
"return_type": "void",
"return_type": "uint32_t",
"parameters" : [
{
"name" : "wallet_filename",
Expand All @@ -164,7 +164,7 @@
{
"method_name": "wallet_import_multibit",
"description": "Imports a Multibit wallet",
"return_type": "void",
"return_type": "uint32_t",
"parameters" : [
{
"name" : "wallet_filename",
Expand Down
50 changes: 32 additions & 18 deletions libraries/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1964,45 +1964,59 @@ config load_config( const fc::path& datadir )
return optional<digest_block>();
}

void detail::client_impl::wallet_import_bitcoin(const fc::path& filename,
const string& passphrase,
const string& account_name )
uint32_t detail::client_impl::wallet_import_bitcoin(
const fc::path& filename,
const string& passphrase,
const string& account_name
)
{
try
{
_wallet->import_bitcoin_wallet(filename, "", account_name);
const auto count = _wallet->import_bitcoin_wallet(filename, "", account_name);
_wallet->auto_backup( "bitcoin_import" );
return;
return count;
}
catch( const fc::exception& e )
{
ilog( "import_bitcoin_wallet failed with empty password: ${e}", ("e",e.to_detail_string() ) );
}

_wallet->import_bitcoin_wallet(filename, passphrase, account_name);
const auto count = _wallet->import_bitcoin_wallet(filename, passphrase, account_name);
_wallet->auto_backup( "bitcoin_import" );
return count;
}
void detail::client_impl::wallet_import_multibit(const fc::path& filename,
const string& passphrase,
const string& account_name )

uint32_t detail::client_impl::wallet_import_multibit(
const fc::path& filename,
const string& passphrase,
const string& account_name
)
{
_wallet->import_multibit_wallet(filename, passphrase, account_name);
const auto count = _wallet->import_multibit_wallet(filename, passphrase, account_name);
_wallet->auto_backup( "multibit_import" );
return count;
}
void detail::client_impl::wallet_import_electrum(const fc::path& filename,
const string& passphrase,
const string& account_name )

uint32_t detail::client_impl::wallet_import_electrum(
const fc::path& filename,
const string& passphrase,
const string& account_name
)
{
_wallet->import_electrum_wallet(filename, passphrase, account_name);
const auto count = _wallet->import_electrum_wallet(filename, passphrase, account_name);
_wallet->auto_backup( "electrum_import" );
return count;
}

void detail::client_impl::wallet_import_armory(const fc::path& filename,
const string& passphrase,
const string& account_name )
uint32_t detail::client_impl::wallet_import_armory(
const fc::path& filename,
const string& passphrase,
const string& account_name
)
{
_wallet->import_armory_wallet(filename, passphrase, account_name);
const auto count = _wallet->import_armory_wallet(filename, passphrase, account_name);
_wallet->auto_backup( "armory_import" );
return count;
}

void detail::client_impl::wallet_import_keyhotee(const string& firstname,
Expand Down
32 changes: 20 additions & 12 deletions libraries/wallet/include/bts/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,26 @@ namespace bts { namespace wallet {
vector<wallet_account_record> list_unregistered_accounts()const;
vector<wallet_account_record> list_my_accounts()const;

void import_bitcoin_wallet( const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name );
void import_multibit_wallet( const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name );
void import_electrum_wallet( const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name );
void import_armory_wallet( const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name );
uint32_t import_bitcoin_wallet(
const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name
);
uint32_t import_multibit_wallet(
const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name
);
uint32_t import_electrum_wallet(
const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name
);
uint32_t import_armory_wallet(
const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name
);

void import_keyhotee( const string& firstname,
const string& middlename,
Expand Down
38 changes: 25 additions & 13 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ namespace bts { namespace wallet {
try
{
_scan_progress = 0;
auto account_priv_keys = _wallet_db.get_account_private_keys( _wallet_password );
const auto account_priv_keys = _wallet_db.get_account_private_keys( _wallet_password );

for( auto block_num = start; !_scan_in_progress.canceled() && block_num <= min_end; ++block_num )
{
Expand Down Expand Up @@ -4684,9 +4684,11 @@ namespace bts { namespace wallet {
return pretty_trx;
}

void wallet::import_bitcoin_wallet( const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name )
uint32_t wallet::import_bitcoin_wallet(
const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name
)
{ try {
if( !is_valid_account_name( account_name ) )
FC_THROW_EXCEPTION( invalid_name, "Invalid account name!", ("account_name",account_name) );
Expand All @@ -4700,12 +4702,15 @@ namespace bts { namespace wallet {

scan_chain( 0, 1 );
ulog( "Successfully imported ${x} keys from ${file}", ("x",keys.size())("file",wallet_dat.filename()) );
return keys.size();
} FC_RETHROW_EXCEPTIONS( warn, "error importing bitcoin wallet ${wallet_dat}",
("wallet_dat",wallet_dat)("account_name",account_name) ) }

void wallet::import_multibit_wallet( const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name )
uint32_t wallet::import_multibit_wallet(
const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name
)
{ try {
if( !is_valid_account_name( account_name ) )
FC_THROW_EXCEPTION( invalid_name, "Invalid account name!", ("account_name",account_name) );
Expand All @@ -4720,12 +4725,15 @@ namespace bts { namespace wallet {

scan_chain( 0, 1 );
ulog( "Successfully imported ${x} keys from ${file}", ("x",keys.size())("file",wallet_dat.filename()) );
return keys.size();
} FC_RETHROW_EXCEPTIONS( warn, "error importing bitcoin wallet ${wallet_dat}",
("wallet_dat",wallet_dat)("account_name",account_name) ) }

void wallet::import_electrum_wallet( const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name )
uint32_t wallet::import_electrum_wallet(
const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name
)
{ try {
if( !is_valid_account_name( account_name ) )
FC_THROW_EXCEPTION( invalid_name, "Invalid account name!", ("account_name",account_name) );
Expand All @@ -4740,12 +4748,15 @@ namespace bts { namespace wallet {

scan_chain( 0, 1 );
ulog( "Successfully imported ${x} keys from ${file}", ("x",keys.size())("file",wallet_dat.filename()) );
return keys.size();
} FC_RETHROW_EXCEPTIONS( warn, "error importing bitcoin wallet ${wallet_dat}",
("wallet_dat",wallet_dat)("account_name",account_name) ) }

void wallet::import_armory_wallet( const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name )
uint32_t wallet::import_armory_wallet(
const path& wallet_dat,
const string& wallet_dat_passphrase,
const string& account_name
)
{ try {
if( !is_valid_account_name( account_name ) )
FC_THROW_EXCEPTION( invalid_name, "Invalid account name!", ("account_name",account_name) );
Expand All @@ -4760,6 +4771,7 @@ namespace bts { namespace wallet {

scan_chain( 0, 1 );
ulog( "Successfully imported ${x} keys from ${file}", ("x",keys.size())("file",wallet_dat.filename()) );
return keys.size();
} FC_RETHROW_EXCEPTIONS( warn, "error importing bitcoin wallet ${wallet_dat}",
("wallet_dat",wallet_dat)("account_name",account_name) ) }

Expand Down
4 changes: 2 additions & 2 deletions libraries/wallet/wallet_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ namespace bts { namespace wallet {
keys.push_back( key_rec->decrypt_private_key( password ) );
} catch ( const fc::exception& e )
{
wlog( "error decrypting private key: ${e}", ("e", e.to_detail_string() ) );
throw; // TODO... don't thtrow here, just log
elog( "error decrypting private key: ${e}", ("e", e.to_detail_string() ) );
}
}
};
Expand Down Expand Up @@ -721,6 +720,7 @@ namespace bts { namespace wallet {
}
catch( const fc::key_not_found_exception& )
{
wlog("wallet_db tried to remove nonexistent index: ${i}", ("i",index) );
}
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/wallet/wallet_records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace bts { namespace wallet {
fc::ecc::private_key key_data::decrypt_private_key( const fc::sha512& password )const
{ try {
FC_ASSERT( password != fc::sha512() );
auto plain_text = fc::aes_decrypt( password, encrypted_private_key );
const auto plain_text = fc::aes_decrypt( password, encrypted_private_key );
return fc::raw::unpack<fc::ecc::private_key>( plain_text );
} FC_CAPTURE_AND_RETHROW() }

Expand Down

0 comments on commit 1a197ef

Please sign in to comment.