feat(lite): real backend integration — controller, M0-M2a wiring, smoke tool, tests
- LiteWalletController (src/wallet/lite_wallet_controller.*): App-owned; runs real create/open/restore via the linked SDXL bridge with allowBridgeCalls=true; wipes seed/passphrase with sodium_memzero; persists on a ready wallet. M2a: applyLiteRefreshModelToWalletState maps a parsed refresh bundle into WalletState (zatoshi->DRGX, z/t split, tx typing + confirmations, sync progress). - App wiring: liteWallet() accessor + init() construction when supportsLiteBackend(); persist -> settings save. - settings_page: "Validate" reroutes to the controller for real execution (validation- only fallback otherwise); wipes UI secret buffers after submit. - chain name default -> "main" with load-time migration of legacy "DRAGONX" (settings.cpp), preventing the backend "Unknown chain" panic. - M0: build.sh --lite-backend flag; lite_smoke real-backend tool + CMake targets; tests/fake_lite_backend.h deterministic harness. - Tests (test_phase4): injectable-fake bridge, controller lifecycle, chain-name migration, refresh->WalletState mapping; plus the lite test-suite churn-cleanup rewrite. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
85
src/wallet/lite_wallet_controller.h
Normal file
85
src/wallet/lite_wallet_controller.h
Normal file
@@ -0,0 +1,85 @@
|
||||
// DragonX Wallet - ImGui Edition
|
||||
// Copyright 2024-2026 The Hush Developers
|
||||
// Released under the GPLv3
|
||||
//
|
||||
// App-owned controller that drives the lite wallet. It constructs and owns the
|
||||
// lite services with bridge calls ENABLED (the services otherwise default to
|
||||
// allowBridgeCalls=false and are never instantiated), executes real create/open/
|
||||
// restore operations through the linked SDXL backend, securely wipes secrets after
|
||||
// use, tracks wallet-open state, and invokes a persistence callback on success.
|
||||
//
|
||||
// Construction:
|
||||
// - Production: LiteWalletController::createLinked(caps, connectionSettings)
|
||||
// (uses LiteClientBridge::linkedSdxl(); requires DRAGONX_ENABLE_LITE_BACKEND).
|
||||
// - Tests: construct directly with an injected bridge
|
||||
// (e.g. LiteClientBridge::fromApi(makeFakeLiteApi())).
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lite_client_bridge.h"
|
||||
#include "lite_connection_service.h"
|
||||
#include "lite_wallet_lifecycle_service.h"
|
||||
#include "lite_wallet_state_mapper.h"
|
||||
#include "wallet_backend.h"
|
||||
#include "wallet_capabilities.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace dragonx {
|
||||
struct WalletState; // data/wallet_state.h
|
||||
|
||||
namespace wallet {
|
||||
|
||||
// Securely zero and clear a string holding secret material (seed/passphrase).
|
||||
void secureWipeLiteSecret(std::string& secret);
|
||||
|
||||
// Apply a normalized lite refresh model onto the app's WalletState (the last hop the
|
||||
// existing Balance/Receive/Transactions tabs read from). Converts zatoshis -> DRGX,
|
||||
// splits addresses into shielded/transparent, and maps sync progress. Mutates in place
|
||||
// (WalletState is non-copyable); only sections present in the model are touched.
|
||||
void applyLiteRefreshModelToWalletState(const LiteWalletAppRefreshModel& model,
|
||||
dragonx::WalletState& state);
|
||||
|
||||
struct LiteWalletControllerOptions {
|
||||
bool allowBridgeCalls = true;
|
||||
};
|
||||
|
||||
class LiteWalletController {
|
||||
public:
|
||||
LiteWalletController(WalletCapabilities capabilities,
|
||||
LiteConnectionSettings connectionSettings,
|
||||
LiteClientBridge bridge,
|
||||
LiteWalletControllerOptions options = LiteWalletControllerOptions{});
|
||||
|
||||
// Production factory: links the SDXL backend compiled into this build.
|
||||
static std::unique_ptr<LiteWalletController> createLinked(
|
||||
WalletCapabilities capabilities,
|
||||
LiteConnectionSettings connectionSettings);
|
||||
|
||||
// Invoked after a wallet becomes ready, so the owner can persist settings.
|
||||
void setPersistCallback(std::function<void()> callback) { persist_ = std::move(callback); }
|
||||
|
||||
bool walletOpen() const { return walletOpen_; }
|
||||
const WalletBackendStatus& status() const { return status_; }
|
||||
LiteWalletLifecycleAvailability availability() const { return lifecycle_.availability(); }
|
||||
|
||||
// Execute a real lifecycle operation. The request is taken by value; its secret
|
||||
// fields are securely wiped before returning. On a ready wallet, walletOpen()
|
||||
// becomes true and the persist callback (if any) fires.
|
||||
LiteWalletLifecycleResult createWallet(LiteWalletCreateRequest request);
|
||||
LiteWalletLifecycleResult openWallet(LiteWalletOpenRequest request);
|
||||
LiteWalletLifecycleResult restoreWallet(LiteWalletRestoreRequest request);
|
||||
|
||||
private:
|
||||
void onLifecycleResult(const LiteWalletLifecycleResult& result);
|
||||
|
||||
LiteWalletLifecycleService lifecycle_;
|
||||
std::function<void()> persist_;
|
||||
bool walletOpen_ = false;
|
||||
WalletBackendStatus status_;
|
||||
};
|
||||
|
||||
} // namespace wallet
|
||||
} // namespace dragonx
|
||||
Reference in New Issue
Block a user