feat(lite): auto-open existing wallet on startup + gate full-node RPC refreshes
Auto-open: on the first update() tick (kept off init() so a slow
initialize_existing network call can't freeze startup before the window), if a
wallet file exists, open it. initialize_existing needs no passphrase — it loads
the file; a previously-synced + saved wallet resumes from its height (fast)
instead of rescanning from the checkpoint. Adds LiteWalletController::walletExists()
(bridge.walletExists on the connection's chain) + a chainName_ member.
RPC-refresh gating: the earlier connected=walletOpen() fix (so the wallet UI is
enabled in lite) had a side effect — the full-node periodic + per-page RPC
refreshes (mining/balance/peers/txs, and setCurrentPage's immediate refresh)
gate on state_.connected, so they began firing in lite and failing
("X error: Not connected"). Re-gate those on ACTUAL RPC connectivity
(rpc_ && rpc_->isConnected()) instead of the lite proxy. Full-node is unchanged
(state_.connected ⟺ rpc connected there); lite no longer issues any RPC.
Runtime-verified in WSLg with a pre-seeded wallet: app auto-opens (Starting
Mempool + sync begins), and "Not connected" / getMiningInfo / RPC-connect noise
all drop to 0 — a fully clean lite run. tests pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -188,6 +188,7 @@ LiteWalletController::LiteWalletController(WalletCapabilities capabilities,
|
||||
LiteClientBridge bridge,
|
||||
LiteWalletControllerOptions options)
|
||||
: bridge_(std::make_shared<LiteClientBridge>(std::move(bridge))),
|
||||
chainName_(connectionSettings.chainName),
|
||||
lifecycle_(capabilities, connectionSettings, bridge_.get(),
|
||||
LiteWalletLifecycleOptions{options.allowBridgeCalls}),
|
||||
gateway_(capabilities, connectionSettings, bridge_.get(),
|
||||
@@ -502,6 +503,13 @@ bool LiteWalletController::saveWallet()
|
||||
return bridge_->execute("save", "").ok;
|
||||
}
|
||||
|
||||
bool LiteWalletController::walletExists() const
|
||||
{
|
||||
// chainName_ is always a backend-accepted value ("main"/"test"/"regtest"); litelib_wallet_
|
||||
// exists panics on unknown chains, but settings migration guarantees a valid one.
|
||||
return bridge_ && bridge_->walletExists(chainName_);
|
||||
}
|
||||
|
||||
bool LiteWalletController::refreshWalletState(dragonx::WalletState& state)
|
||||
{
|
||||
auto model = refreshModel();
|
||||
|
||||
@@ -127,6 +127,9 @@ public:
|
||||
void setPersistCallback(std::function<void()> callback) { persist_ = std::move(callback); }
|
||||
|
||||
bool walletOpen() const { return walletOpen_; }
|
||||
// True if a wallet file already exists on disk for this chain. Use to auto-open on startup
|
||||
// (open via openWallet({}) needs no passphrase — initialize_existing just loads the file).
|
||||
bool walletExists() const;
|
||||
const WalletBackendStatus& status() const { return status_; }
|
||||
LiteWalletLifecycleAvailability availability() const { return lifecycle_.availability(); }
|
||||
|
||||
@@ -214,6 +217,7 @@ private:
|
||||
// sync_status separately), so concurrent execute() calls cannot corrupt state. A coarse
|
||||
// mutex would instead serialize sync against syncstatus polling and defeat the design.
|
||||
std::shared_ptr<LiteClientBridge> bridge_;
|
||||
std::string chainName_; // backend chain id (for walletExists); from connection settings
|
||||
LiteWalletLifecycleService lifecycle_;
|
||||
LiteWalletGateway gateway_;
|
||||
LiteSyncService sync_;
|
||||
|
||||
Reference in New Issue
Block a user