aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIlya Kitaev <mbg033@gmail.com>2016-03-11 17:05:36 +0300
committerIlya Kitaev <mbg033@gmail.com>2016-03-16 14:29:06 +0300
commit5a4f099540750c5bf9c610b4550bc4e8cf25f176 (patch)
tree9e8f586eaa91849adbeccb27c37d8283490a4fde /src
parentchanges in wallet2_api + implemented WalletManager::openWallet (diff)
downloadmonero-5a4f099540750c5bf9c610b4550bc4e8cf25f176.tar.xz
Wallet::setPassword() method for wallet2_api
Diffstat (limited to 'src')
-rw-r--r--src/wallet/wallet2.cpp10
-rw-r--r--src/wallet/wallet2.h3
-rw-r--r--src/wallet/wallet2_api.cpp23
-rw-r--r--src/wallet/wallet2_api.h31
4 files changed, 58 insertions, 9 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 389286ceb..c4f60306b 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -2695,6 +2695,16 @@ bool wallet2::get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) c
return true;
}
+std::string wallet2::get_wallet_file() const
+{
+ return m_wallet_file;
+}
+
+std::string wallet2::get_keys_file() const
+{
+ return m_keys_file;
+}
+
//----------------------------------------------------------------------------------------------------
void wallet2::generate_genesis(cryptonote::block& b) {
if (m_testnet)
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 6c689d4ba..2835815b7 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -348,8 +348,11 @@ namespace tools
bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) const;
+
bool use_fork_rules(uint8_t version);
+ std::string get_wallet_file() const;
+ std::string get_keys_file() const;
private:
/*!
* \brief Stores wallet information to wallet file.
diff --git a/src/wallet/wallet2_api.cpp b/src/wallet/wallet2_api.cpp
index 3a80b4221..2dfc7b292 100644
--- a/src/wallet/wallet2_api.cpp
+++ b/src/wallet/wallet2_api.cpp
@@ -65,6 +65,7 @@ public:
void setListener(Listener *) {}
int status() const;
std::string errorString() const;
+ bool setPassword(const std::string &password);
private:
void clearStatus();
@@ -110,9 +111,6 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co
return false;
}
// TODO: validate language
- // TODO: create wallet
- // m_wallet.reset(new tools::wallet2());
-
m_wallet->set_seed_language(language);
crypto::secret_key recovery_val, secret_key;
try {
@@ -134,7 +132,7 @@ bool WalletImpl::open(const std::string &path, const std::string &password)
// TODO: handle "deprecated"
m_wallet->load(path, password);
result = true;
- } catch (const tools::error::file_not_found &e) {
+ } catch (const std::exception &e) {
LOG_ERROR("Error opening wallet: " << e.what());
m_status = Status_Error;
m_errorString = e.what();
@@ -185,6 +183,20 @@ std::string WalletImpl::errorString() const
return m_errorString;
}
+bool WalletImpl::setPassword(const std::string &password)
+{
+ bool result = false;
+ try {
+ m_wallet->rewrite(m_wallet->get_wallet_file(), password);
+ result = true;
+ } catch (const std::exception &e) {
+ result = false;
+ m_status = Status_Error;
+ m_errorString = e.what();
+ }
+ return result;
+}
+
void WalletImpl::clearStatus()
{
m_status = Status_Ok;
@@ -228,9 +240,10 @@ Wallet *WalletManagerImpl::openWallet(const std::string &path, const std::string
return wallet;
}
-Wallet * WalletManagerImpl::recoveryWallet(const std::string &path, const std::string &memo, const std::string &language)
+Wallet *WalletManagerImpl::recoveryWallet(const std::string &path, const std::string &memo, const std::string &language)
{
return nullptr;
+
}
bool WalletManagerImpl::closeWallet(Wallet *wallet)
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index b89c74e28..c985581df 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -64,6 +64,7 @@ struct Wallet
virtual int status() const = 0;
//! in case error status, returns error string
virtual std::string errorString() const = 0;
+ virtual bool setPassword(const std::string &password) = 0;
};
/**
@@ -71,15 +72,37 @@ struct Wallet
*/
struct WalletManager
{
- //! creates new wallet
+
+ /*!
+ * \brief Creates new wallet
+ * \param path Name of wallet file
+ * \param password Password of wallet file
+ * \param language Language to be used to generate electrum seed memo
+ * \return Wallet instance (Wallet::status() needs to be called to check if created successfully)
+ */
virtual Wallet * createWallet(const std::string &path, const std::string &password, const std::string &language) = 0;
- //! opens existing wallet
+ /*!
+ * \brief Opens existing wallet
+ * \param path Name of wallet file
+ * \param password Password of wallet file
+ * \return Wallet instance (Wallet::status() needs to be called to check if opened successfully)
+ */
virtual Wallet * openWallet(const std::string &path, const std::string &password) = 0;
- //! recovers existing wallet using memo (electrum words)
+ /*!
+ * \brief recovers existing wallet using memo (electrum seed)
+ * \param path Name of wallet file to be created
+ * \param memo memo (25 words electrum seed)
+ * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
+ */
virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, const std::string &language) = 0;
- //! closes wallet. in case operation succeded, wallet object deleted. in case operation failed, wallet object not deleted
+
+ /*!
+ * \brief Closes wallet. In case operation succeded, wallet object deleted. in case operation failed, wallet object not deleted
+ * \param wallet previously opened / created wallet instance
+ * \return None
+ */
virtual bool closeWallet(Wallet *wallet) = 0;
//! checks if wallet with the given name already exists