From 1dde238f2c21a0cc9bada10a2449cf9c6b2178ad Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Tue, 5 Dec 2017 15:57:12 -0500 Subject: [PATCH 1/2] Add ChainClient setMockTime, getWallets methods Needed to set mock times, and get wallet interface pointers correctly when wallet code is running in a different process from node code. --- src/interfaces/chain.h | 6 ++++++ src/interfaces/node.cpp | 5 +++-- src/interfaces/wallet.cpp | 9 +++++++++ src/rpc/misc.cpp | 9 ++++++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 7304f8274..846966705 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -280,6 +280,12 @@ public: //! Shut down client. virtual void stop() = 0; + + //! Set mock time. + virtual void setMockTime(int64_t time) = 0; + + //! Return interfaces for accessing wallets (if any). + virtual std::vector> getWallets() = 0; }; //! Return implementation of Chain interface. diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index 8a64a9d26..c3cfc7131 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -251,8 +251,9 @@ public: std::vector> getWallets() override { std::vector> wallets; - for (const std::shared_ptr& wallet : GetWallets()) { - wallets.emplace_back(MakeWallet(wallet)); + for (auto& client : m_context.chain_clients) { + auto client_wallets = client->getWallets(); + std::move(client_wallets.begin(), client_wallets.end(), std::back_inserter(wallets)); } return wallets; } diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index baea71d0b..bec203b63 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -529,6 +529,15 @@ public: void start(CScheduler& scheduler) override { return StartWallets(scheduler); } void flush() override { return FlushWallets(); } void stop() override { return StopWallets(); } + void setMockTime(int64_t time) override { return SetMockTime(time); } + std::vector> getWallets() override + { + std::vector> wallets; + for (const auto& wallet : GetWallets()) { + wallets.emplace_back(MakeWallet(wallet)); + } + return wallets; + } ~WalletClientImpl() override { UnloadWallets(); } Chain& m_chain; diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 4279756f4..778bd05da 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -4,6 +4,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include @@ -356,7 +357,13 @@ static UniValue setmocktime(const JSONRPCRequest& request) LOCK(cs_main); RPCTypeCheck(request.params, {UniValue::VNUM}); - SetMockTime(request.params[0].get_int64()); + int64_t time = request.params[0].get_int64(); + SetMockTime(time); + if (g_rpc_node) { + for (const auto& chain_client : g_rpc_node->chain_clients) { + chain_client->setMockTime(time); + } + } return NullUniValue; } From 3ce16ad2f91d1e2edc7e7bdc5a19f72aa8c3e739 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Fri, 24 Jan 2020 17:02:41 -0500 Subject: [PATCH 2/2] refactor: Use psbt forward declaration Also clean up forward other forward declarations in interfaces/wallet.h with !sort Original motivation for this change was to fix a circular dependencies lint error: "interfaces/chain.h -> interfaces/wallet.h -> psbt -> node/transaction -> node/context -> interfaces/chain.h" from an earlier commit in this PR adding a "interfaces/chain.h -> interfaces/wallet.h" include. Now, the wallet include is no longer added, but it is still good to clean up the psbt include for efficiency, and to sort the forward declarations. --- src/interfaces/wallet.h | 8 ++++---- src/qt/walletmodel.cpp | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index d4280e809..935fc6992 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -25,12 +24,13 @@ class CCoinControl; class CFeeRate; class CKey; class CWallet; -enum isminetype : unsigned int; enum class FeeReason; -typedef uint8_t isminefilter; - enum class OutputType; +enum class TransactionError; +enum isminetype : unsigned int; struct CRecipient; +struct PartiallySignedTransaction; +typedef uint8_t isminefilter; namespace interfaces { diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 8a84a8c16..83796c384 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include // for GetBoolArg #include