From 696cb268d92898b59d18150b3317ff35201a0962 Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 27 May 2019 10:40:37 -0400 Subject: [PATCH] implemented MoneroWallet::walletExists(const string& path) --- src/wallet/MoneroWallet.cpp | 8 +++ src/wallet/MoneroWallet.h | 134 +++++++++++++++++++----------------- todo.txt | 3 +- 3 files changed, 79 insertions(+), 66 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index c817e40..77515df 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -5,6 +5,14 @@ using namespace std; using namespace epee; +bool MoneroWallet::walletExists(const string& path) { + cout << "walletExists(" << path << ")" << endl; + bool keyFileExists; + bool walletFileExists; + tools::wallet2::wallet_exists(path, keyFileExists, walletFileExists); + return walletFileExists; +} + MoneroWallet::MoneroWallet() { cout << "MoneroWallet()" << endl; } diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index b273e3c..da61695 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -4,10 +4,6 @@ using namespace std; using namespace crypto; using namespace cryptonote; -//int main(int argc, const char* argv[]) { -// cout << "===== MAIN =====" << endl; -//} - /** * Monero wallet interface. * @@ -15,69 +11,77 @@ using namespace cryptonote; */ class MoneroWallet { - // --------------------------------- PUBLIC -------------------------------- + // --------------------------------- PUBLIC -------------------------------- public: - /** - * Construct a wallet with a randomly generated seed. - */ - MoneroWallet(); + /** + * Indicates if a wallet exists at the given path. + * + * @param path is the path to check for a wallet + * @return true if a wallet exists at the given path, false otherwise + */ + static bool walletExists(const string& path); - /** - * Construct a wallet with a randomly generated seed. - * - * @param networkType is the wallet's network type (default = MoneroNetworkType.MAINNET) - * @param daemonConnection is connection information to a daemon (default = an unconnected wallet) - * @param language is the wallet and mnemonic's language (default = "English") - */ - MoneroWallet(network_type networkType, const string& daemonConnection, const string& language); + /** + * Construct a wallet with a randomly generated seed. + */ + MoneroWallet(); - /** - * Construct a wallet from a mnemonic phrase. - * - * @param mnemonic is the mnemonic of the wallet to construct - * @param networkType is the wallet's network type - * @param daemonConnection is connection information to a daemon (default = an unconnected wallet) - * @param restoreHeight is the block height to restore (i.e. scan the chain) from (default = 0) - */ - MoneroWallet(const string& mnemonic, network_type networkType, const string& daemonConnection, uint64_t restoreHeight); + /** + * Construct a wallet with a randomly generated seed. + * + * @param networkType is the wallet's network type (default = MoneroNetworkType.MAINNET) + * @param daemonConnection is connection information to a daemon (default = an unconnected wallet) + * @param language is the wallet and mnemonic's language (default = "English") + */ + MoneroWallet(network_type networkType, const string& daemonConnection, const string& language); - /** - * Construct a wallet from an address, view key, and spend key. - * - * @param address is the address of the wallet to construct - * @param viewKey is the view key of the wallet to construct - * @param spendKey is the spend key of the wallet to construct - * @param networkType is the wallet's network type - * @param daemonConnection is connection information to a daemon (default = an unconnected wallet) - * @param restoreHeight is the block height to restore (i.e. scan the chain) from (default = 0) - * @param language is the wallet and mnemonic's language (default = "English") - */ - MoneroWallet(const string& address, const string& viewKey, const string& spendKey, network_type networkType, const string& daemonConnection, uint64_t restoreHeight, const string& language); + /** + * Construct a wallet from a mnemonic phrase. + * + * @param mnemonic is the mnemonic of the wallet to construct + * @param networkType is the wallet's network type + * @param daemonConnection is connection information to a daemon (default = an unconnected wallet) + * @param restoreHeight is the block height to restore (i.e. scan the chain) from (default = 0) + */ + MoneroWallet(const string& mnemonic, network_type networkType, const string& daemonConnection, uint64_t restoreHeight); - /** - * Construct a wallet by opening a wallet file on disk. - * - * @param path is the path to the wallet file to open - * @param password is the password of the wallet file to open - * @param networkType is the wallet's network type - */ - MoneroWallet(const string& path, const epee::wipeable_string& password, network_type networkType); + /** + * Construct a wallet from an address, view key, and spend key. + * + * @param address is the address of the wallet to construct + * @param viewKey is the view key of the wallet to construct + * @param spendKey is the spend key of the wallet to construct + * @param networkType is the wallet's network type + * @param daemonConnection is connection information to a daemon (default = an unconnected wallet) + * @param restoreHeight is the block height to restore (i.e. scan the chain) from (default = 0) + * @param language is the wallet and mnemonic's language (default = "English") + */ + MoneroWallet(const string& address, const string& viewKey, const string& spendKey, network_type networkType, const string& daemonConnection, uint64_t restoreHeight, const string& language); - /** - * Deconstructs the wallet. - */ - ~MoneroWallet(); + /** + * Construct a wallet by opening a wallet file on disk. + * + * @param path is the path to the wallet file to open + * @param password is the password of the wallet file to open + * @param networkType is the wallet's network type + */ + MoneroWallet(const string& path, const epee::wipeable_string& password, network_type networkType); - /** - * Set the wallet's daemon connection. - * - * @param daemonUri is the daemon's URI - * @param daemonUsername is the daemon's username - * @param daemonPassword is the daemon's password - */ - void setDaemonConnection(const string& daemonUri, const string& daemonUsername, const epee::wipeable_string& daemonPassword); + /** + * Deconstructs the wallet. + */ + ~MoneroWallet(); + + /** + * Set the wallet's daemon connection. + * + * @param daemonUri is the daemon's URI + * @param daemonUsername is the daemon's username + * @param daemonPassword is the daemon's password + */ + void setDaemonConnection(const string& daemonUri, const string& daemonUsername, const epee::wipeable_string& daemonPassword); // /** // * Get the wallet's seed. @@ -86,14 +90,14 @@ using namespace cryptonote; // */ // const string getSeed(); - /** - * Get the wallet's mnemonic phrase derived from the seed. - * - * @param mnemonic is assigned the wallet's mnemonic phrase - */ - void getMnemonic(epee::wipeable_string& mnemonic) const; + /** + * Get the wallet's mnemonic phrase derived from the seed. + * + * @param mnemonic is assigned the wallet's mnemonic phrase + */ + void getMnemonic(epee::wipeable_string& mnemonic) const; - // --------------------------------- PRIVATE -------------------------------- + // --------------------------------- PRIVATE -------------------------------- private: tools::wallet2* wallet2; // internal wallet implementation diff --git a/todo.txt b/todo.txt index 7124565..f75cf5a 100644 --- a/todo.txt +++ b/todo.txt @@ -1 +1,2 @@ -DaemonConnection is its own object \ No newline at end of file +DaemonConnection is its own object +rename external-libs/monero to monero-core for clarity \ No newline at end of file