Skip to content

Commit 1dde238

Browse files
committed
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.
1 parent 31c0006 commit 1dde238

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

src/interfaces/chain.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ class ChainClient
280280

281281
//! Shut down client.
282282
virtual void stop() = 0;
283+
284+
//! Set mock time.
285+
virtual void setMockTime(int64_t time) = 0;
286+
287+
//! Return interfaces for accessing wallets (if any).
288+
virtual std::vector<std::unique_ptr<Wallet>> getWallets() = 0;
283289
};
284290

285291
//! Return implementation of Chain interface.

src/interfaces/node.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,9 @@ class NodeImpl : public Node
251251
std::vector<std::unique_ptr<Wallet>> getWallets() override
252252
{
253253
std::vector<std::unique_ptr<Wallet>> wallets;
254-
for (const std::shared_ptr<CWallet>& wallet : GetWallets()) {
255-
wallets.emplace_back(MakeWallet(wallet));
254+
for (auto& client : m_context.chain_clients) {
255+
auto client_wallets = client->getWallets();
256+
std::move(client_wallets.begin(), client_wallets.end(), std::back_inserter(wallets));
256257
}
257258
return wallets;
258259
}

src/interfaces/wallet.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,15 @@ class WalletClientImpl : public ChainClient
529529
void start(CScheduler& scheduler) override { return StartWallets(scheduler); }
530530
void flush() override { return FlushWallets(); }
531531
void stop() override { return StopWallets(); }
532+
void setMockTime(int64_t time) override { return SetMockTime(time); }
533+
std::vector<std::unique_ptr<Wallet>> getWallets() override
534+
{
535+
std::vector<std::unique_ptr<Wallet>> wallets;
536+
for (const auto& wallet : GetWallets()) {
537+
wallets.emplace_back(MakeWallet(wallet));
538+
}
539+
return wallets;
540+
}
532541
~WalletClientImpl() override { UnloadWallets(); }
533542

534543
Chain& m_chain;

src/rpc/misc.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#include <httpserver.h>
7+
#include <interfaces/chain.h>
78
#include <key_io.h>
89
#include <node/context.h>
910
#include <outputtype.h>
@@ -356,7 +357,13 @@ static UniValue setmocktime(const JSONRPCRequest& request)
356357
LOCK(cs_main);
357358

358359
RPCTypeCheck(request.params, {UniValue::VNUM});
359-
SetMockTime(request.params[0].get_int64());
360+
int64_t time = request.params[0].get_int64();
361+
SetMockTime(time);
362+
if (g_rpc_node) {
363+
for (const auto& chain_client : g_rpc_node->chain_clients) {
364+
chain_client->setMockTime(time);
365+
}
366+
}
360367

361368
return NullUniValue;
362369
}

0 commit comments

Comments
 (0)