From dc1689d8ff260a3638ebeeb2b1df9042a4de9319 Mon Sep 17 00:00:00 2001 From: woodser Date: Sun, 18 Aug 2019 11:58:43 -0400 Subject: [PATCH] is_daemon_trusted(), rescan_spent(), get_multisig_hex(), import_multisig_hex() impls compiling --- src/wallet/monero_wallet.cpp | 45 +++++++++++++++++++++++++++++++++--- src/wallet/monero_wallet.h | 22 ++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/wallet/monero_wallet.cpp b/src/wallet/monero_wallet.cpp index 36c7c00..c30c45a 100644 --- a/src/wallet/monero_wallet.cpp +++ b/src/wallet/monero_wallet.cpp @@ -1001,6 +1001,11 @@ namespace monero { return daemonHeight >= get_daemon_max_peer_height() && daemonHeight > 1; } + bool monero_wallet::is_daemon_trusted() const { + if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + return m_w2->is_trusted_daemon(); + } + bool monero_wallet::is_synced() const { return m_is_synced; } @@ -1212,6 +1217,13 @@ namespace monero { } } + void monero_wallet::rescan_spent() { + MTRACE("rescan_spent()"); + if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!is_daemon_trusted()) throw runtime_error("Rescan spent can only be used with a trusted daemon"); + m_w2->rescan_spent(); + } + // TODO: support arguments bool hard, bool refresh = true, bool keep_key_images = false void monero_wallet::rescan_blockchain() { MTRACE("rescan_blockchain()"); @@ -2580,7 +2592,7 @@ namespace monero { monero_multisig_init_result monero_wallet::exchange_multisig_keys(const vector& multisig_hexes, const string& password) { - // validate state and request + // validate state and args bool ready; uint32_t threshold, total; if (!m_w2->multisig(&ready, &threshold, &total)) throw new runtime_error("This wallet is not multisig"); @@ -2598,11 +2610,38 @@ namespace monero { } string monero_wallet::get_multisig_hex() { - throw runtime_error("get_multisig_hex not implemented"); + bool ready; + if (!m_w2->multisig(&ready)) throw runtime_error("This wallet is not multisig"); + if (!ready) throw runtime_error("This wallet is multisig, but not yet finalized"); + return epee::string_tools::buff_to_hex_nodelimer(m_w2->export_multisig()); } int monero_wallet::import_multisig_hex(const vector& multisig_hexes) { - throw runtime_error("import_multisig_hex not implemented"); + + // validate state and args + bool ready; + uint32_t threshold, total; + if (!m_w2->multisig(&ready, &threshold, &total)) throw runtime_error("This wallet is not multisig"); + if (!ready) throw runtime_error("This wallet is multisig, but not yet finalized"); + if (multisig_hexes.size() < threshold - 1) throw runtime_error("Needs multisig export info from more participants"); + + // validate and parse each peer multisig hex + std::vector multisig_hex_blobs; + multisig_hex_blobs.resize(multisig_hexes.size()); + for (size_t n = 0; n < multisig_hexes.size(); ++n) { + if (!epee::string_tools::parse_hexstr_to_binbuff(multisig_hexes[n], multisig_hex_blobs[n])) { + throw runtime_error("Failed to parse hex."); + } + } + + // import peer multisig hex + int num_outputs = m_w2->import_multisig(multisig_hex_blobs); + + // if daemon is trusted, rescan spent + if (is_daemon_trusted()) rescan_spent(); + + // return the number of outputs signed by the given multisig hex + return num_outputs; } monero_multisig_sign_result monero_wallet::sign_multisig_tx_hex(const string& multisig_tx_hex) { diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index 93415e7..684a351 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -266,6 +266,13 @@ namespace monero { */ bool is_daemon_synced() const; + /** + * Indicates if the daemon is trusted or untrusted. + * + * @return true if the daemon is trusted, false otherwise + */ + bool is_daemon_trusted() const; + /** * Indicates if the wallet is synced with the daemon. * @@ -446,6 +453,17 @@ namespace monero { */ void stop_syncing(); + /** + * Rescan the blockchain for spent outputs. + * + * Note: this can only be called with a trusted daemon. + * + * Example use case: peer multisig hex is import when connected to an untrusted daemon, + * so the wallet will not rescan spent outputs. Then the wallet connects to a trusted + * daemon. This method should be manually invoked to rescan outputs. + */ + void rescan_spent(); + /** * Rescan the blockchain from scratch, losing any information which cannot be recovered from * the blockchain itself. @@ -1360,6 +1378,10 @@ namespace monero { /** * Import multisig info as hex from other participants. * + * Note: If the daemon is not trusted, this method will not automatically + * update the spent status after importing peer multisig hex. In that case, + * the + * * @param multisig_hexes are multisig hex from each participant * @return the number of outputs signed with the given multisig hex */