mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 19:23:26 -03:00
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.
This commit is contained in:
parent
31c0006a6c
commit
1dde238f2c
4 changed files with 26 additions and 3 deletions
|
@ -280,6 +280,12 @@ public:
|
||||||
|
|
||||||
//! Shut down client.
|
//! Shut down client.
|
||||||
virtual void stop() = 0;
|
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.
|
//! Return implementation of Chain interface.
|
||||||
|
|
|
@ -251,8 +251,9 @@ public:
|
||||||
std::vector<std::unique_ptr<Wallet>> getWallets() override
|
std::vector<std::unique_ptr<Wallet>> getWallets() override
|
||||||
{
|
{
|
||||||
std::vector<std::unique_ptr<Wallet>> wallets;
|
std::vector<std::unique_ptr<Wallet>> wallets;
|
||||||
for (const std::shared_ptr<CWallet>& wallet : GetWallets()) {
|
for (auto& client : m_context.chain_clients) {
|
||||||
wallets.emplace_back(MakeWallet(wallet));
|
auto client_wallets = client->getWallets();
|
||||||
|
std::move(client_wallets.begin(), client_wallets.end(), std::back_inserter(wallets));
|
||||||
}
|
}
|
||||||
return wallets;
|
return wallets;
|
||||||
}
|
}
|
||||||
|
|
|
@ -529,6 +529,15 @@ public:
|
||||||
void start(CScheduler& scheduler) override { return StartWallets(scheduler); }
|
void start(CScheduler& scheduler) override { return StartWallets(scheduler); }
|
||||||
void flush() override { return FlushWallets(); }
|
void flush() override { return FlushWallets(); }
|
||||||
void stop() override { return StopWallets(); }
|
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(); }
|
~WalletClientImpl() override { UnloadWallets(); }
|
||||||
|
|
||||||
Chain& m_chain;
|
Chain& m_chain;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <httpserver.h>
|
#include <httpserver.h>
|
||||||
|
#include <interfaces/chain.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <outputtype.h>
|
#include <outputtype.h>
|
||||||
|
@ -356,7 +357,13 @@ static UniValue setmocktime(const JSONRPCRequest& request)
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
RPCTypeCheck(request.params, {UniValue::VNUM});
|
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;
|
return NullUniValue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue