Skip to content

Commit

Permalink
Bitcoin wallet import API calls return # of keys imported
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramrajkumar committed Aug 19, 2014
1 parent 46f8680 commit bdf1171
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 46 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
36 changes: 24 additions & 12 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
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

0 comments on commit bdf1171

Please sign in to comment.