From 28b413686fc8d20f918387559e73cf7a068beaa3 Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 6 Jul 2019 15:00:30 -0400 Subject: [PATCH] support wallet.setDaemonConnection(rpcConnection) --- src/wallet/MoneroWallet.cpp | 26 +++++++++++++------------ src/wallet/MoneroWallet.h | 39 +++++++++++++++++++++---------------- todo.txt | 1 - 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 96c0d28..17c7b3b 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -737,6 +737,13 @@ namespace monero { return walletFileExists; } + MoneroWallet::MoneroWallet(const string& path, const string& password, const MoneroNetworkType networkType) { + cout << "MoneroWallet(3b)" << endl; + wallet2 = unique_ptr(new tools::wallet2(static_cast(networkType), 1, true)); + wallet2->load(path, password); + wallet2Listener = unique_ptr(new Wallet2Listener(*this, *wallet2)); + } + MoneroWallet::MoneroWallet(const string& path, const string& password) { cout << "MoneroWallet()" << endl; throw runtime_error("Not implemented"); @@ -745,7 +752,7 @@ namespace monero { MoneroWallet::MoneroWallet(const string& path, const string&password, const MoneroNetworkType networkType, const MoneroRpcConnection& daemonConnection, const string& language) { cout << "MoneroWallet(3)" << endl; wallet2 = unique_ptr(new tools::wallet2(static_cast(networkType), 1, true)); - setDaemonConnection(daemonConnection.uri, daemonConnection.username, daemonConnection.password); + setDaemonConnection(daemonConnection); wallet2->set_seed_language(language); crypto::secret_key secret_key; wallet2->generate(path, password, secret_key, false, false); @@ -763,7 +770,7 @@ namespace monero { // initialize wallet wallet2 = unique_ptr(new tools::wallet2(static_cast(networkType), 1, true)); - setDaemonConnection(daemonConnection.uri, daemonConnection.username, daemonConnection.password); + setDaemonConnection(daemonConnection); wallet2->set_seed_language(language); wallet2->generate(path, password, recoveryKey, true, false); wallet2->set_refresh_from_block_height(restoreHeight); @@ -825,7 +832,7 @@ namespace monero { if (hasSpendKey && hasViewKey) wallet2->generate(path, password, info.address, spendKeySK, viewKeySK); if (!hasSpendKey && hasViewKey) wallet2->generate(path, password, info.address, viewKeySK); if (hasSpendKey && !hasViewKey) wallet2->generate(path, password, spendKeySK, true, false); - setDaemonConnection(daemonConnection.uri, daemonConnection.username, daemonConnection.password); + setDaemonConnection(daemonConnection); wallet2->set_refresh_from_block_height(restoreHeight); wallet2->set_seed_language(language); wallet2Listener = unique_ptr(new Wallet2Listener(*this, *wallet2)); @@ -836,20 +843,11 @@ namespace monero { cout << "Mnemonic: " << string(fetchedMnemonic.data(), fetchedMnemonic.size()) << endl; } - MoneroWallet::MoneroWallet(const string& path, const string& password, const MoneroNetworkType networkType) { - cout << "MoneroWallet(3b)" << endl; - wallet2 = unique_ptr(new tools::wallet2(static_cast(networkType), 1, true)); - wallet2->load(path, password); - wallet2Listener = unique_ptr(new Wallet2Listener(*this, *wallet2)); - } - MoneroWallet::~MoneroWallet() { cout << "~MoneroWallet()" << endl; close(); } - // TODO: switch this to setDaemonConnection(MoneroDaemonRpc& daemonConnection) - // TODO: actually setDaemonConnection(boost::optional& connection) void MoneroWallet::setDaemonConnection(const string& uri, const string& username, const string& password) { cout << "setDaemonConnection(" << uri << ", " << username << ", " << password << ")" << endl; @@ -864,6 +862,10 @@ namespace monero { if (!wallet2->init(uri, login)) throw runtime_error("Failed to initialize wallet with daemon connection"); } + void MoneroWallet::setDaemonConnection(const MoneroRpcConnection& connection) { + setDaemonConnection(connection.uri, connection.username, connection.password); + } + shared_ptr MoneroWallet::getDaemonConnection() const { if (wallet2->get_daemon_address().empty()) return nullptr; shared_ptr connection = shared_ptr(new MoneroRpcConnection()); diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 7223406..5fe2c05 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -147,7 +147,16 @@ namespace monero { static bool walletExists(const string& path); /** - * Construct an unconnected English wallet with a randomly generated seed on mainnet. + * Open an existing wallet. + * + * @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 string& password, const MoneroNetworkType networkType); + + /** + * Create a new wallet with a randomly generated seed on mainnet in English. * * @param path is the path to create the wallet * @param password is the password encrypt the wallet @@ -155,7 +164,7 @@ namespace monero { MoneroWallet(const string& path, const string& password); /** - * Construct a wallet with a randomly generated seed. + * Create a new wallet with a randomly generated seed. * * @param path is the path to create the wallet * @param password is the password encrypt the wallet @@ -166,7 +175,7 @@ namespace monero { MoneroWallet(const string& path, const string& password, const MoneroNetworkType networkType, const MoneroRpcConnection& daemonConnection, const string& language); /** - * Construct a wallet from a mnemonic phrase. + * Create a wallet from an existing mnemonic phrase. * * @param path is the path to create the wallet * @param password is the password encrypt the wallet @@ -178,7 +187,7 @@ namespace monero { MoneroWallet(const string& path, const string& password, const string& mnemonic, const MoneroNetworkType networkType, const MoneroRpcConnection& daemonConnection, uint64_t restoreHeight); /** - * Construct a wallet from an address, view key, and spend key. + * Create a wallet from an address, view key, and spend key. * * @param path is the path to create the wallet * @param password is the password encrypt the wallet @@ -193,29 +202,25 @@ namespace monero { MoneroWallet(const string& path, const string& password, const string& address, const string& viewKey, const string& spendKey, const MoneroNetworkType networkType, const MoneroRpcConnection& daemonConnection, uint64_t restoreHeight, const string& language); /** - * 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 string& password, const MoneroNetworkType networkType); - - /** - * Deconstructs the wallet. + * Deconstruct the wallet. */ ~MoneroWallet(); /** * Set the wallet's daemon connection. * - * TODO: support MoneroRpcConnection - * * @param uri is the daemon's URI * @param username is the daemon's username * @param password is the daemon's password */ - void setDaemonConnection(const string& uri, const string& username, const string& password); + void setDaemonConnection(const string& uri, const string& username = "", const string& password = ""); + + /** + * Set the wallet's daemon connection. + * + * @param connection is the connection to set + */ + void setDaemonConnection(const MoneroRpcConnection& connection); /** * TODO diff --git a/todo.txt b/todo.txt index cab91cd..c233f13 100644 --- a/todo.txt +++ b/todo.txt @@ -6,7 +6,6 @@ tx 121158a7e51044e27de6958a9501cc9eba811b2e37bc651ab9a04e749d11cc38 should have comb code todos MEDIUM PRIORITY -DaemonConnection is its own object onSyncProgress(startHeight, currentHeight, endHeight, percentDone, message)? remove warning jstring2string rename external-libs/monero to monero-core for clarity