Files
ObsidianDragon/src/resources/embedded_resources.h
DanS 393f3d147e feat(recovery): bundle & embed the offline wallet-rebuild helper in every release
The dragonx-wallet-rebuild helper is the only thing that repairs a genuinely
BDB-inconsistent wallet.dat — plain "Restore" just re-triggers the daemon's
salvage cascade — yet it was silently dropped from every packaged build:

- Linux zip/AppImage copied a hand-picked file list that omitted it.
- Windows bundled it only behind a soft `[[ -f ]]` guard (silent skip).
- macOS never wired Berkeley DB, never built it, never bundled it.

build.sh now HARD-REQUIRES the helper for full-node releases (fails the build if
the vendored Berkeley DB depends are missing, rather than shipping recovery-less),
and ships it in the Linux zip + AppImage, the Windows zip, and the macOS .app.

It also compiles the helper standalone for Windows and INCBINs it, and
embedded_resources gains ensureWalletRebuildHelperExtracted() to extract it on
demand — so a self-contained ObsidianDragon.exe carries recovery exactly like the
embedded daemon, even on a machine where first-run param extraction already ran.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-10 22:10:57 -05:00

122 lines
4.4 KiB
C++

#pragma once
#include <string>
#include <cstdint>
namespace dragonx {
namespace resources {
// Embedded resource data (generated at build time)
struct EmbeddedResource {
const uint8_t* data;
size_t size;
const char* filename;
};
// Check if embedded resources are available
bool hasEmbeddedResources();
// Get embedded resource by name
// Returns nullptr if not found or not embedded
const EmbeddedResource* getEmbeddedResource(const std::string& name);
// Extract all embedded resources to appropriate locations
// Returns true if all resources extracted successfully
bool extractEmbeddedResources();
// Check if params need to be extracted (not already present)
bool needsParamsExtraction();
// Get the params directory path
std::string getParamsDirectory();
// --- Daemon binary management (Settings → daemon binary panel) ------------------------------
// Info about the dragonxd binary currently installed in the dragonx/ extraction directory.
struct DaemonBinaryInfo {
bool exists = false;
std::string path;
std::uintmax_t size = 0;
std::string version; // scanned from the binary ("vX.Y.Z-<commit>"), empty if not found
std::int64_t modifiedEpoch = 0; // last-write time as unix epoch seconds, 0 if unknown
};
// Info about the dragonxd binary bundled inside this wallet build.
struct BundledDaemonInfo {
bool available = false; // a daemon resource is embedded in this build
std::uintmax_t size = 0;
std::string version;
};
// Read + scan the installed dragonxd (reads the file; call off the UI thread or cache the result).
DaemonBinaryInfo getInstalledDaemonInfo();
// Info about the bundled daemon (scans the embedded bytes once, cached).
BundledDaemonInfo getBundledDaemonInfo();
// Force-overwrite the installed dragonx binaries (dragonxd/cli/tx) with the bundled ones. The
// caller should stop the daemon first. Returns true if all present resources were written.
bool reextractBundledDaemon();
// Ensure the embedded offline wallet-rebuild recovery helper is extracted to the daemon dir, and
// return its path ("" if not embedded in this build or extraction failed). Idempotent — extracts only
// when missing. Unlike the first-run extractEmbeddedResources() (gated on needsParamsExtraction()),
// this runs on demand so recovery works from a self-contained exe on ANY run, not just the first.
std::string ensureWalletRebuildHelperExtracted();
// Resource names
constexpr const char* RESOURCE_SAPLING_SPEND = "sapling-spend.params";
constexpr const char* RESOURCE_SAPLING_OUTPUT = "sapling-output.params";
constexpr const char* RESOURCE_ASMAP = "asmap.dat";
constexpr const char* RESOURCE_DRAGONXD = "dragonxd.exe";
constexpr const char* RESOURCE_DRAGONX_CLI = "dragonx-cli.exe";
constexpr const char* RESOURCE_DRAGONX_TX = "dragonx-tx.exe";
constexpr const char* RESOURCE_DRAGONX_WALLET_REBUILD = "dragonx-wallet-rebuild.exe";
constexpr const char* RESOURCE_XMRIG = "xmrig.exe";
constexpr const char* RESOURCE_DARK_GRADIENT = "dark_gradient.png";
constexpr const char* RESOURCE_LOGO = "logo_ObsidianDragon_dark.png";
// Embedded theme overlay info (for iterating bundled themes)
struct EmbeddedTheme {
const uint8_t* data;
size_t size;
const char* filename; // e.g. "dark.toml"
};
// Get array of embedded overlay themes (nullptr-terminated)
const EmbeddedTheme* getEmbeddedThemes();
// Extract bundled overlay themes to the given directory
// Returns number of themes extracted
int extractBundledThemes(const std::string& destDir);
// Update stale bundled theme files in the given directory.
// Compares on-disk file size to embedded size; overwrites on mismatch.
// Returns number of themes updated.
int updateBundledThemes(const std::string& dir);
// Check if daemon needs to be extracted
bool needsDaemonExtraction();
// Get daemon binary directory (<exe_dir>/dragonx/)
std::string getDaemonDirectory();
// Check if daemon is available (embedded or in app directory)
bool hasDaemonAvailable();
// Get daemon executable path (extracts if needed)
std::string getDaemonPath();
// Check if xmrig needs to be extracted
bool needsXmrigExtraction();
// Check if xmrig is available (embedded or in app directory)
bool hasXmrigAvailable();
// Force re-extract xmrig binary from embedded resources
// (bypasses exists-check; use when Defender deletes the file)
bool forceExtractXmrig();
// Get xmrig executable path (extracts if needed)
std::string getXmrigPath();
} // namespace resources
} // namespace dragonx