wallet: API changes to enable passphrase entry
This commit is contained in:
parent
fe3403c8f0
commit
827f52add0
@ -449,6 +449,11 @@ WalletImpl::~WalletImpl()
|
||||
close(false); // do not store wallet as part of the closing activities
|
||||
// Stop refresh thread
|
||||
stopRefresh();
|
||||
|
||||
if (m_wallet2Callback->getListener()) {
|
||||
m_wallet2Callback->getListener()->onSetWallet(nullptr);
|
||||
}
|
||||
|
||||
LOG_PRINT_L1(__FUNCTION__ << " finished");
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <set>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
// Public interface for libwallet library
|
||||
namespace Monero {
|
||||
@ -337,6 +338,7 @@ protected:
|
||||
bool m_indeterminate;
|
||||
};
|
||||
|
||||
struct Wallet;
|
||||
struct WalletListener
|
||||
{
|
||||
virtual ~WalletListener() = 0;
|
||||
@ -381,7 +383,7 @@ struct WalletListener
|
||||
/**
|
||||
* @brief called by device if the action is required
|
||||
*/
|
||||
virtual void onDeviceButtonRequest(uint64_t code) {}
|
||||
virtual void onDeviceButtonRequest(uint64_t code) { (void)code; }
|
||||
|
||||
/**
|
||||
* @brief called by device when PIN is needed
|
||||
@ -401,7 +403,12 @@ struct WalletListener
|
||||
/**
|
||||
* @brief Signalizes device operation progress
|
||||
*/
|
||||
virtual void onDeviceProgress(const DeviceProgress & event) {};
|
||||
virtual void onDeviceProgress(const DeviceProgress & event) { (void)event; };
|
||||
|
||||
/**
|
||||
* @brief If the listener is created before the wallet this enables to set created wallet object
|
||||
*/
|
||||
virtual void onSetWallet(Wallet * wallet) { (void)wallet; };
|
||||
};
|
||||
|
||||
|
||||
@ -440,8 +447,8 @@ struct Wallet
|
||||
//! returns both error and error string atomically. suggested to use in instead of status() and errorString()
|
||||
virtual void statusWithErrorString(int& status, std::string& errorString) const = 0;
|
||||
virtual bool setPassword(const std::string &password) = 0;
|
||||
virtual bool setDevicePin(const std::string &password) { return false; };
|
||||
virtual bool setDevicePassphrase(const std::string &password) { return false; };
|
||||
virtual bool setDevicePin(const std::string &pin) { (void)pin; return false; };
|
||||
virtual bool setDevicePassphrase(const std::string &passphrase) { (void)passphrase; return false; };
|
||||
virtual std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const = 0;
|
||||
std::string mainAddress() const { return address(0, 0); }
|
||||
virtual std::string path() const = 0;
|
||||
@ -1020,9 +1027,10 @@ struct WalletManager
|
||||
* \param password Password of wallet file
|
||||
* \param nettype Network type
|
||||
* \param kdf_rounds Number of rounds for key derivation function
|
||||
* \param listener Wallet listener to set to the wallet after creation
|
||||
* \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, NetworkType nettype, uint64_t kdf_rounds = 1) = 0;
|
||||
virtual Wallet * openWallet(const std::string &path, const std::string &password, NetworkType nettype, uint64_t kdf_rounds = 1, WalletListener * listener = nullptr) = 0;
|
||||
Wallet * openWallet(const std::string &path, const std::string &password, bool testnet = false) // deprecated
|
||||
{
|
||||
return openWallet(path, password, testnet ? TESTNET : MAINNET);
|
||||
@ -1134,6 +1142,7 @@ struct WalletManager
|
||||
* \param restoreHeight restore from start height (0 sets to current height)
|
||||
* \param subaddressLookahead Size of subaddress lookahead (empty sets to some default low value)
|
||||
* \param kdf_rounds Number of rounds for key derivation function
|
||||
* \param listener Wallet listener to set to the wallet after creation
|
||||
* \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
|
||||
*/
|
||||
virtual Wallet * createWalletFromDevice(const std::string &path,
|
||||
@ -1142,7 +1151,8 @@ struct WalletManager
|
||||
const std::string &deviceName,
|
||||
uint64_t restoreHeight = 0,
|
||||
const std::string &subaddressLookahead = "",
|
||||
uint64_t kdf_rounds = 1) = 0;
|
||||
uint64_t kdf_rounds = 1,
|
||||
WalletListener * listener = nullptr) = 0;
|
||||
|
||||
/*!
|
||||
* \brief Closes wallet. In case operation succeeded, wallet object deleted. in case operation failed, wallet object not deleted
|
||||
|
@ -57,9 +57,14 @@ Wallet *WalletManagerImpl::createWallet(const std::string &path, const std::stri
|
||||
return wallet;
|
||||
}
|
||||
|
||||
Wallet *WalletManagerImpl::openWallet(const std::string &path, const std::string &password, NetworkType nettype, uint64_t kdf_rounds)
|
||||
Wallet *WalletManagerImpl::openWallet(const std::string &path, const std::string &password, NetworkType nettype, uint64_t kdf_rounds, WalletListener * listener)
|
||||
{
|
||||
WalletImpl * wallet = new WalletImpl(nettype, kdf_rounds);
|
||||
wallet->setListener(listener);
|
||||
if (listener){
|
||||
listener->onSetWallet(wallet);
|
||||
}
|
||||
|
||||
wallet->open(path, password);
|
||||
//Refresh addressBook
|
||||
wallet->addressBook()->refresh();
|
||||
@ -122,9 +127,15 @@ Wallet *WalletManagerImpl::createWalletFromDevice(const std::string &path,
|
||||
const std::string &deviceName,
|
||||
uint64_t restoreHeight,
|
||||
const std::string &subaddressLookahead,
|
||||
uint64_t kdf_rounds)
|
||||
uint64_t kdf_rounds,
|
||||
WalletListener * listener)
|
||||
{
|
||||
WalletImpl * wallet = new WalletImpl(nettype, kdf_rounds);
|
||||
wallet->setListener(listener);
|
||||
if (listener){
|
||||
listener->onSetWallet(wallet);
|
||||
}
|
||||
|
||||
if(restoreHeight > 0){
|
||||
wallet->setRefreshFromBlockHeight(restoreHeight);
|
||||
} else {
|
||||
|
@ -40,7 +40,7 @@ class WalletManagerImpl : public WalletManager
|
||||
public:
|
||||
Wallet * createWallet(const std::string &path, const std::string &password,
|
||||
const std::string &language, NetworkType nettype, uint64_t kdf_rounds = 1) override;
|
||||
Wallet * openWallet(const std::string &path, const std::string &password, NetworkType nettype, uint64_t kdf_rounds = 1) override;
|
||||
Wallet * openWallet(const std::string &path, const std::string &password, NetworkType nettype, uint64_t kdf_rounds = 1, WalletListener * listener = nullptr) override;
|
||||
virtual Wallet * recoveryWallet(const std::string &path,
|
||||
const std::string &password,
|
||||
const std::string &mnemonic,
|
||||
@ -72,7 +72,8 @@ public:
|
||||
const std::string &deviceName,
|
||||
uint64_t restoreHeight = 0,
|
||||
const std::string &subaddressLookahead = "",
|
||||
uint64_t kdf_rounds = 1) override;
|
||||
uint64_t kdf_rounds = 1,
|
||||
WalletListener * listener = nullptr) override;
|
||||
virtual bool closeWallet(Wallet *wallet, bool store = true) override;
|
||||
bool walletExists(const std::string &path) override;
|
||||
bool verifyWalletPassword(const std::string &keys_file_name, const std::string &password, bool no_spend_key, uint64_t kdf_rounds = 1) const override;
|
||||
|
Loading…
Reference in New Issue
Block a user