mirror of
https://github.com/monero-project/monero.git
synced 2026-01-26 22:34:39 +01:00
Wallet API: add support for wallet creation from hardware device
This commit is contained in:
committed by
moneromooo-monero
parent
9e9cd108a3
commit
8fb50b738f
@@ -338,6 +338,7 @@ WalletImpl::WalletImpl(NetworkType nettype)
|
||||
, m_trustedDaemon(false)
|
||||
, m_wallet2Callback(nullptr)
|
||||
, m_recoveringFromSeed(false)
|
||||
, m_recoveringFromDevice(false)
|
||||
, m_synchronized(false)
|
||||
, m_rebuildWalletCache(false)
|
||||
, m_is_connected(false)
|
||||
@@ -385,6 +386,7 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co
|
||||
|
||||
clearStatus();
|
||||
m_recoveringFromSeed = false;
|
||||
m_recoveringFromDevice = false;
|
||||
bool keys_file_exists;
|
||||
bool wallet_file_exists;
|
||||
tools::wallet2::wallet_exists(path, keys_file_exists, wallet_file_exists);
|
||||
@@ -584,11 +586,28 @@ bool WalletImpl::recoverFromKeysWithPassword(const std::string &path,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WalletImpl::recoverFromDevice(const std::string &path, const std::string &password, const std::string &device_name)
|
||||
{
|
||||
clearStatus();
|
||||
m_recoveringFromSeed = false;
|
||||
m_recoveringFromDevice = true;
|
||||
try
|
||||
{
|
||||
m_wallet->restore(path, password, device_name);
|
||||
LOG_PRINT_L1("Generated new wallet from device: " + device_name);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
setStatusError(string(tr("failed to generate new wallet: ")) + e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WalletImpl::open(const std::string &path, const std::string &password)
|
||||
{
|
||||
clearStatus();
|
||||
m_recoveringFromSeed = false;
|
||||
m_recoveringFromDevice = false;
|
||||
try {
|
||||
// TODO: handle "deprecated"
|
||||
// Check if wallet cache exists
|
||||
@@ -628,6 +647,7 @@ bool WalletImpl::recover(const std::string &path, const std::string &password, c
|
||||
}
|
||||
|
||||
m_recoveringFromSeed = true;
|
||||
m_recoveringFromDevice = false;
|
||||
crypto::secret_key recovery_key;
|
||||
std::string old_language;
|
||||
if (!crypto::ElectrumWords::words_to_bytes(seed, recovery_key, old_language)) {
|
||||
@@ -837,6 +857,16 @@ void WalletImpl::setRecoveringFromSeed(bool recoveringFromSeed)
|
||||
m_recoveringFromSeed = recoveringFromSeed;
|
||||
}
|
||||
|
||||
void WalletImpl::setRecoveringFromDevice(bool recoveringFromDevice)
|
||||
{
|
||||
m_recoveringFromDevice = recoveringFromDevice;
|
||||
}
|
||||
|
||||
void WalletImpl::setSubaddressLookahead(uint32_t major, uint32_t minor)
|
||||
{
|
||||
m_wallet->set_subaddress_lookahead(major, minor);
|
||||
}
|
||||
|
||||
uint64_t WalletImpl::balance(uint32_t accountIndex) const
|
||||
{
|
||||
return m_wallet->balance(accountIndex);
|
||||
@@ -1839,7 +1869,7 @@ bool WalletImpl::isNewWallet() const
|
||||
// with the daemon (pull hashes instead of pull blocks).
|
||||
// If wallet cache is rebuilt, creation height stored in .keys is used.
|
||||
// Watch only wallet is a copy of an existing wallet.
|
||||
return !(blockChainHeight() > 1 || m_recoveringFromSeed || m_rebuildWalletCache) && !watchOnly();
|
||||
return !(blockChainHeight() > 1 || m_recoveringFromSeed || m_recoveringFromDevice || m_rebuildWalletCache) && !watchOnly();
|
||||
}
|
||||
|
||||
bool WalletImpl::doInit(const string &daemon_address, uint64_t upper_transaction_size_limit, bool ssl)
|
||||
|
||||
Reference in New Issue
Block a user