A lite-wallet-only "Network" tab (full-node keeps the Peers tab; exactly one shows per variant) to manage lightwalletd servers, replacing the basic selector that was in Settings. - Card list of servers with per-server latency + status dot, DNS host + resolved IP, and an Official/Custom pill. Official DragonX servers get a glowing outline. - Pick a server (Sticky) by clicking its card, or toggle "use a random server" (Random mode); selection applies immediately (App::rebuildLiteWallet(force=true) tears down + rebuilds the controller against the new server and resyncs — its dtor detaches the uninterruptible sync thread, so this doesn't block). - Add custom servers; hide/unhide servers (persisted set, revealed by a "Show hidden" toggle). - Latency/IP come from a new background probe (util/LiteServerProbe): libcurl CONNECT_ONLY does the TCP+TLS handshake (works for gRPC lightwalletd, no HTTP response needed), recording APPCONNECT_TIME as latency and CURLINFO_PRIMARY_IP. Auto-runs on tab open + a Refresh button. Wiring: WalletUiSurface::LiteNetwork (gated !fullNodePagesAvailable) + NavPage::LiteNetwork in the sidebar + app.cpp dispatch; settings gains a hidden-servers set; isOfficialLiteServer() added to lite_connection_service. The Settings page lite-server selector + its plumbing are removed (single source of truth = the tab). Reuses the existing server model (LiteServerPreference, Sticky/Random, selectLiteServer) and UI primitives (DrawGlassPanel, ThemeEffects glow, peers-tab ping-dot idiom). Unit-tested (liteServerHost, isOfficialLiteServer) + an env-gated live probe (verified vs lite.dragonx.is: online, latency, IP). Both variants + lite-backend build; suite passes; hygiene clean; GUI smoke-launched without crash. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
125 lines
3.7 KiB
C++
125 lines
3.7 KiB
C++
// DragonX Wallet - ImGui Edition
|
|
// Copyright 2024-2026 The Hush Developers
|
|
// Released under the GPLv3
|
|
|
|
#pragma once
|
|
|
|
#include "lite_client_bridge.h"
|
|
#include "wallet_backend.h"
|
|
#include "wallet_capabilities.h"
|
|
|
|
#include <cstddef>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace dragonx {
|
|
namespace wallet {
|
|
|
|
// The SDXL litelib backend identifies the production chain as "main" (its mainnet
|
|
// module carries DragonX's coin params). It hard-panics on any other chain name, so
|
|
// this MUST be one of {"main","test","regtest"} — not the coin ticker.
|
|
constexpr const char* kDragonXLiteChainName = "main";
|
|
constexpr const char* kDefaultDragonXLiteServer = "https://lite.dragonx.is";
|
|
|
|
enum class LiteServerSelectionMode {
|
|
Sticky,
|
|
Random
|
|
};
|
|
|
|
enum class LiteConnectionAvailability {
|
|
Ready,
|
|
UnsupportedBuild,
|
|
BackendUnavailable,
|
|
BridgeUnavailable,
|
|
NoUsableServer
|
|
};
|
|
|
|
struct LiteServerEndpoint {
|
|
std::string url;
|
|
std::string label;
|
|
bool enabled = true;
|
|
};
|
|
|
|
struct LiteConnectionSettings {
|
|
std::vector<LiteServerEndpoint> servers;
|
|
LiteServerSelectionMode selectionMode = LiteServerSelectionMode::Sticky;
|
|
std::string stickyServerUrl = kDefaultDragonXLiteServer;
|
|
std::string chainName = kDragonXLiteChainName;
|
|
std::size_t randomSelectionSeed = 0;
|
|
};
|
|
|
|
struct LiteServerSelectionResult {
|
|
bool ok = false;
|
|
LiteServerEndpoint server;
|
|
std::size_t serverIndex = 0;
|
|
bool customServer = false;
|
|
std::string error;
|
|
};
|
|
|
|
struct LiteWalletExistsRequest {
|
|
std::string chainName = kDragonXLiteChainName;
|
|
};
|
|
|
|
struct LiteServerHealthRequest {
|
|
LiteServerEndpoint server;
|
|
std::size_t serverIndex = 0;
|
|
bool customServer = false;
|
|
};
|
|
|
|
struct LiteWalletExistsCheckResult {
|
|
bool ok = false;
|
|
bool attempted = false;
|
|
bool walletExists = false;
|
|
LiteWalletExistsRequest request;
|
|
WalletBackendStatus status;
|
|
std::string error;
|
|
};
|
|
|
|
struct LiteServerHealthCheckResult {
|
|
bool ok = false;
|
|
bool attempted = false;
|
|
bool serverOnline = false;
|
|
LiteServerHealthRequest request;
|
|
WalletBackendStatus status;
|
|
std::string error;
|
|
};
|
|
|
|
std::vector<LiteServerEndpoint> defaultDragonXLiteServers();
|
|
LiteConnectionSettings defaultLiteConnectionSettings();
|
|
bool isLiteServerUrlUsable(const std::string& serverUrl);
|
|
// True if the URL is one of the built-in official DragonX lite servers (gets a glowing outline).
|
|
bool isOfficialLiteServer(const std::string& serverUrl);
|
|
const char* liteServerSelectionModeName(LiteServerSelectionMode mode);
|
|
const char* liteConnectionAvailabilityName(LiteConnectionAvailability availability);
|
|
LiteServerSelectionResult selectLiteServer(const LiteConnectionSettings& settings);
|
|
|
|
class LiteConnectionService {
|
|
public:
|
|
LiteConnectionService(WalletCapabilities capabilities,
|
|
LiteConnectionSettings settings,
|
|
LiteClientBridge bridge);
|
|
|
|
const LiteConnectionSettings& settings() const { return settings_; }
|
|
const WalletCapabilities& capabilities() const { return capabilities_; }
|
|
|
|
LiteConnectionAvailability availability() const;
|
|
WalletBackendStatus status() const;
|
|
LiteServerSelectionResult selectedServer() const;
|
|
LiteWalletExistsRequest walletExistsRequest() const;
|
|
LiteServerHealthRequest serverHealthRequest() const;
|
|
|
|
LiteWalletExistsCheckResult checkWalletExists();
|
|
LiteServerHealthCheckResult checkSelectedServerHealth();
|
|
|
|
private:
|
|
WalletBackendStatus statusFor(LiteConnectionAvailability availability,
|
|
const std::string& detail = {}) const;
|
|
WalletBackendStatus bridgeReadinessStatus() const;
|
|
|
|
WalletCapabilities capabilities_;
|
|
LiteConnectionSettings settings_;
|
|
LiteClientBridge bridge_;
|
|
};
|
|
|
|
} // namespace wallet
|
|
} // namespace dragonx
|