diff --git a/src/lez_core_module.cpp b/src/lez_core_module.cpp index 3098727..17f02fc 100644 --- a/src/lez_core_module.cpp +++ b/src/lez_core_module.cpp @@ -283,6 +283,14 @@ std::string LEZCoreModule::version() const { return "0.3.0"; } +// === Wallet Location === + +std::string LEZCoreModule::wallet_dir() { + if (!isContextReady() || instancePersistencePath().empty()) + return LEZ_NO_WALLET_DIR; + return instancePersistencePath(); +} + // === Account Management === std::string LEZCoreModule::create_account_public() { @@ -1334,4 +1342,4 @@ std::vector LEZCoreModule::get_all_labels_for_account(const std::st } return result; -} \ No newline at end of file +} diff --git a/src/lez_core_module.h b/src/lez_core_module.h index ca73013..fe99edd 100644 --- a/src/lez_core_module.h +++ b/src/lez_core_module.h @@ -5,11 +5,14 @@ #include #include +#include extern "C" { #include } +constexpr const char* LEZ_NO_WALLET_DIR = "-"; + // Universal (Qt-free) execution-zone core module. The Qt glue (provider // object + plugin) is generated from this header by logos-cpp-generator, which // maps the std return types below to the Qt signatures callers invoke: @@ -18,7 +21,7 @@ extern "C" { // NOTE: the generator parses this header line-by-line and only recognises a // method when its declaration ends with ';' on a single line. Keep every // method declaration on ONE line — multi-line signatures are silently dropped. -class LEZCoreModule { +class LEZCoreModule : public LogosModuleContext { public: LEZCoreModule(); ~LEZCoreModule(); @@ -28,8 +31,8 @@ public: std::string name() const; std::string version() const; + std::string wallet_dir(); - // === Wallet Lifecycle === std::string create_new(const std::string& config_path, const std::string& storage_path, const std::string& statistics_path, const std::string& password); int64_t open(const std::string& config_path, const std::string& storage_path, const std::string& statistics_path); int64_t save(); diff --git a/tests/test_lez_core.cpp b/tests/test_lez_core.cpp index 3af98ef..e9eb015 100644 --- a/tests/test_lez_core.cpp +++ b/tests/test_lez_core.cpp @@ -32,6 +32,24 @@ LOGOS_TEST(name_and_version) { LOGOS_ASSERT_EQ(module.version(), std::string("0.3.0")); } +// ============================================================================ +// Wallet location +// ============================================================================ + +// Constructed directly, so no host has stamped a persistence path onto it. It +// must say so rather than invent one: a caller that receives a plausible-looking +// path here would write a wallet somewhere the host does not manage and will +// never clean up. +// Never "" -- that answer is reserved for a call that never arrived, so a caller +// can tell "no directory here" from "I could not reach you" and retry instead of +// writing a wallet somewhere it invented. +LOGOS_TEST(wallet_dir_reports_no_directory_without_a_provisioning_host) { + LEZCoreModule module; + LOGOS_ASSERT(!module.isContextReady()); + LOGOS_ASSERT_EQ(module.wallet_dir(), std::string(LEZ_NO_WALLET_DIR)); + LOGOS_ASSERT(!module.wallet_dir().empty()); +} + // ============================================================================ // Account management // ============================================================================