diff options
Diffstat (limited to 'src/wallet/api/wallet.cpp')
-rw-r--r-- | src/wallet/api/wallet.cpp | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index c0974f880..9cd72b543 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -303,7 +303,7 @@ WalletImpl::~WalletImpl() // Pause refresh thread - prevents refresh from starting again pauseRefresh(); // Close wallet - stores cache and stops ongoing refresh operation - close(); + close(false); // do not store wallet as part of the closing activities // Stop refresh thread stopRefresh(); delete m_wallet2Callback; @@ -379,7 +379,32 @@ bool WalletImpl::createWatchOnly(const std::string &path, const std::string &pas const cryptonote::account_public_address address = m_wallet->get_account().get_keys().m_account_address; try { + // Generate view only wallet view_wallet->generate(path, password, address, viewkey); + + // Export/Import outputs + auto outputs = m_wallet->export_outputs(); + view_wallet->import_outputs(outputs); + + // Copy scanned blockchain + auto bc = m_wallet->export_blockchain(); + view_wallet->import_blockchain(bc); + + // copy payments + auto payments = m_wallet->export_payments(); + view_wallet->import_payments(payments); + + // copy confirmed outgoing payments + std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>> out_payments; + m_wallet->get_payments_out(out_payments, 0); + view_wallet->import_payments_out(out_payments); + + // Export/Import key images + // We already know the spent status from the outputs we exported, thus no need to check them again + auto key_images = m_wallet->export_key_images(); + uint64_t spent = 0; + uint64_t unspent = 0; + view_wallet->import_key_images(key_images,spent,unspent,false); m_status = Status_Ok; } catch (const std::exception &e) { LOG_ERROR("Error creating view only wallet: " << e.what()); @@ -387,6 +412,8 @@ bool WalletImpl::createWatchOnly(const std::string &path, const std::string &pas m_errorString = e.what(); return false; } + // Store wallet + view_wallet->store(); return true; } @@ -539,19 +566,21 @@ bool WalletImpl::recover(const std::string &path, const std::string &seed) return m_status == Status_Ok; } -bool WalletImpl::close() +bool WalletImpl::close(bool store) { bool result = false; LOG_PRINT_L1("closing wallet..."); try { - // Do not store wallet with invalid status - // Status Critical refers to errors on opening or creating wallets. - if (status() != Status_Critical) - m_wallet->store(); - else - LOG_ERROR("Status_Critical - not storing wallet"); - LOG_PRINT_L1("wallet::store done"); + if (store) { + // Do not store wallet with invalid status + // Status Critical refers to errors on opening or creating wallets. + if (status() != Status_Critical) + m_wallet->store(); + else + LOG_ERROR("Status_Critical - not storing wallet"); + LOG_PRINT_L1("wallet::store done"); + } LOG_PRINT_L1("Calling wallet::stop..."); m_wallet->stop(); LOG_PRINT_L1("wallet::stop done"); @@ -862,6 +891,11 @@ bool WalletImpl::exportKeyImages(const string &filename) bool WalletImpl::importKeyImages(const string &filename) { + if (!trustedDaemon()) { + m_status = Status_Error; + m_errorString = tr("Key images can only be imported with a trusted daemon"); + return false; + } try { uint64_t spent = 0, unspent = 0; |