Skip to content

Commit 03c76f5

Browse files
committed
interfaces: Implement snapshot loading functionality in node interface
- Added a new virtual method `loadSnapshot` to the node interface for loading UTXO snapshots. - Introduced a handler for tracking snapshot load progress with `handleSnapshotLoadProgress`. - Updated the implementation in `interfaces.cpp` to activate the snapshot using the provided file and metadata. This enhancement exposes UTXO snapshots loading functionaility to the GUI.
1 parent b8025b3 commit 03c76f5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/interfaces/node.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <net_types.h>
1313
#include <netaddress.h>
1414
#include <netbase.h>
15+
#include <node/utxo_snapshot.h>
1516
#include <support/allocators/secure.h>
1617
#include <util/translation.h>
1718

@@ -204,6 +205,9 @@ class Node
204205
//! List rpc commands.
205206
virtual std::vector<std::string> listRpcCommands() = 0;
206207

208+
//! Load UTXO Snapshot.
209+
virtual bool loadSnapshot(AutoFile& afile, const node::SnapshotMetadata& metadata, bool in_memory) = 0;
210+
207211
//! Get unspent output associated with a transaction.
208212
virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0;
209213

@@ -233,6 +237,10 @@ class Node
233237
using ShowProgressFn = std::function<void(const std::string& title, int progress, bool resume_possible)>;
234238
virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
235239

240+
//! Register handler for snapshot load progress.
241+
using SnapshotLoadProgressFn = std::function<void(double progress)>;
242+
virtual std::unique_ptr<Handler> handleSnapshotLoadProgress(SnapshotLoadProgressFn fn) = 0;
243+
236244
//! Register handler for wallet loader constructed messages.
237245
using InitWalletFn = std::function<void()>;
238246
virtual std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) = 0;

src/node/interfaces.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <node/kernel_notifications.h>
3939
#include <node/transaction.h>
4040
#include <node/types.h>
41+
#include <node/utxo_snapshot.h>
4142
#include <node/warnings.h>
4243
#include <policy/feerate.h>
4344
#include <policy/fees.h>
@@ -356,6 +357,11 @@ class NodeImpl : public Node
356357
return ::tableRPC.execute(req);
357358
}
358359
std::vector<std::string> listRpcCommands() override { return ::tableRPC.listCommands(); }
360+
bool loadSnapshot(AutoFile& coins_file, const SnapshotMetadata& metadata, bool in_memory) override
361+
{
362+
auto activation_result{chainman().ActivateSnapshot(coins_file, metadata, in_memory)};
363+
return activation_result.has_value();
364+
}
359365
std::optional<Coin> getUnspentOutput(const COutPoint& output) override
360366
{
361367
LOCK(::cs_main);

0 commit comments

Comments
 (0)