Merge #17999: refactor: Add ChainClient setMockTime, getWallets methods

3ce16ad2f9 refactor: Use psbt forward declaration (Russell Yanofsky)
1dde238f2c Add ChainClient setMockTime, getWallets methods (Russell Yanofsky)

Pull request description:

  This PR is part of the [process separation project](https://github.com/bitcoin/bitcoin/projects/10).

  These changes are needed to set mock times, and get wallet interface pointers correctly when
  wallet code is running in a different process from node code in #10102

ACKs for top commit:
  MarcoFalke:
    re-ACK 3ce16ad2f9 🔙
  promag:
    Code review ACK 3ce16ad2f9.

Tree-SHA512: 6c093bfcd68adf5858a1aade4361cdb7fb015496673504ac7a93d0bd2595215047184551d6fd526baa27782331cd2819ce45c4cf923b205ce93ac29e485b5dd8
This commit is contained in:
MarcoFalke 2020-04-10 12:57:28 -04:00
commit 99d6a5be8b
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
6 changed files with 31 additions and 7 deletions

View file

@ -283,6 +283,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<std::unique_ptr<Wallet>> getWallets() = 0;
};
//! Return implementation of Chain interface.

View file

@ -253,8 +253,9 @@ public:
std::vector<std::unique_ptr<Wallet>> getWallets() override
{
std::vector<std::unique_ptr<Wallet>> wallets;
for (const std::shared_ptr<CWallet>& 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;
}

View file

@ -519,6 +519,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<std::unique_ptr<Wallet>> getWallets() override
{
std::vector<std::unique_ptr<Wallet>> wallets;
for (const auto& wallet : GetWallets()) {
wallets.emplace_back(MakeWallet(wallet));
}
return wallets;
}
~WalletClientImpl() override { UnloadWallets(); }
Chain& m_chain;

View file

@ -15,7 +15,6 @@
#include <functional>
#include <map>
#include <memory>
#include <psbt.h>
#include <stdint.h>
#include <string>
#include <tuple>
@ -26,12 +25,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 {

View file

@ -20,6 +20,7 @@
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <key_io.h>
#include <psbt.h>
#include <ui_interface.h>
#include <util/system.h> // for GetBoolArg
#include <wallet/coincontrol.h>

View file

@ -4,6 +4,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <httpserver.h>
#include <interfaces/chain.h>
#include <key_io.h>
#include <node/context.h>
#include <outputtype.h>
@ -363,7 +364,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;
}