Compare commits
207 Commits
6f0f95f4fb
...
lite-v1.1.
| Author | SHA1 | Date | |
|---|---|---|---|
| cc2d383166 | |||
| f30fdc5ed1 | |||
| 290d3c31a2 | |||
| 27fb83ba04 | |||
| 0e78fe02e4 | |||
| 7914e9e9bb | |||
| 06d34dff5e | |||
| c7e48c16f8 | |||
| 4ee0f524d4 | |||
| 43c7be55c6 | |||
| d9fa00bb38 | |||
| 0a042df8e0 | |||
| a60a2f8e39 | |||
| d27f387d6d | |||
| ed675f90d8 | |||
| 4492aa3425 | |||
| 56d93b6128 | |||
| 398fb274fa | |||
| 0343d48c13 | |||
| a3892c0fd3 | |||
| f7df315695 | |||
| aec996a9ce | |||
| 90e02b1ddd | |||
| ef8ceeaf9a | |||
| ba1d760bb3 | |||
| 0942691eb3 | |||
| a2f84be2d4 | |||
| 7e8b99a82b | |||
| 29274c2f48 | |||
| 870793433b | |||
| 08cfeb0e08 | |||
| 5daf2d83b6 | |||
| 6d26ccd0ed | |||
| a7514becbc | |||
| 558cfcbe56 | |||
| d0bd55b9c1 | |||
| b37d3d97b6 | |||
| 8778398d31 | |||
| d5c30237d2 | |||
| a598217975 | |||
| 9205addf55 | |||
| ce8c7696d4 | |||
| 99d1e73676 | |||
| 755cf22ad0 | |||
| e24ca015d1 | |||
| 0de44569b7 | |||
| 06afbee4f8 | |||
| 6ee81a5abe | |||
| ea26c0cbbb | |||
| 13b225d8f5 | |||
| 08aed34bbe | |||
| 5edbe8a276 | |||
| 001e85ac1a | |||
| 393f3d147e | |||
| ac49f44f84 | |||
| 3216debc7d | |||
| 8ffcd9cc8c | |||
| bc183257b7 | |||
| b2e037bb67 | |||
| 975650f11b | |||
| 384d64ea5d | |||
| 3b7423f3a1 | |||
| d136916e80 | |||
| f88304fed2 | |||
| 5296dd7ae5 | |||
| a1d3964e34 | |||
| 5b6ba5094b | |||
| c3e81a5fa6 | |||
| d603a54618 | |||
| c61c211dfe | |||
| 16244d84a0 | |||
| 32be868dbc | |||
| 8bb3198562 | |||
| 4b3f0fa92b | |||
| c7c3440a7b | |||
| e779ded2e8 | |||
| 940dd21464 | |||
| 207f9074db | |||
| 05b00b158b | |||
| f9ddab059e | |||
| de1ae736de | |||
| 03c1b63e03 | |||
| 8c12b27c0a | |||
| c7d163f44a | |||
| 7e4822c021 | |||
| f9b622cb25 | |||
| 9204fa148a | |||
| da0e9f5915 | |||
| d188a08db7 | |||
| ff5f5ddf23 | |||
| 56f9802fb9 | |||
| efb271cb9a | |||
| eb69e491b9 | |||
| 2675b8ab93 | |||
| b3444e0a89 | |||
| 45b652f514 | |||
| c252e60f7f | |||
| fffee9f0b5 | |||
| 00ffc959e5 | |||
| b561406c23 | |||
| 5a0743a17b | |||
| a7b0770ad0 | |||
| 7d8323a622 | |||
| 320944fd18 | |||
| 6d5e0ac614 | |||
| 02554d523d | |||
| 21da9e75fc | |||
| c53b7f771e | |||
| bcee4bfe72 | |||
| e1870c3b23 | |||
| 7cf0bb8bc7 | |||
| 541a9e1fd5 | |||
| 07b8e0b2cb | |||
| de48414c65 | |||
| f0c681b0b5 | |||
| fdf2502ca8 | |||
| e393b0d847 | |||
| 3b041f20c1 | |||
| 77a0ad64b0 | |||
| d0ca2fdf52 | |||
| 9c07b6d33d | |||
| fedfe3d60c | |||
| 95ff9ce9ae | |||
| 203967411a | |||
| 3d0305a9ca | |||
| e7f38c2a45 | |||
| 3a2be661ea | |||
| 17525003c5 | |||
| 267d839d5b | |||
| 987d9b93c7 | |||
| 4c43f2e082 | |||
| 57fa6470b7 | |||
| c68889d276 | |||
| b0a4333cdf | |||
| 4471f54842 | |||
| e08121af2b | |||
| 31ebfc782e | |||
| f3776bcbe5 | |||
| 38f2aa2f8f | |||
| 40f8425d94 | |||
| 2157a30192 | |||
| bef3c0c47d | |||
| 5c570613c8 | |||
| 567732206e | |||
| 0dcc09fc5f | |||
| 82d3178119 | |||
| 7d47c6e14e | |||
| 973bc0d338 | |||
| e4c9b98ca2 | |||
| 1c38f68781 | |||
| 818c29fca7 | |||
| 0a43742897 | |||
| defe14d913 | |||
| 8b55a90102 | |||
| 0fd3d214a4 | |||
| 996e10ed02 | |||
| 2c909d35ea | |||
| 3b5db02e09 | |||
| 8d8cd337cf | |||
| acde8c0833 | |||
| a78b44246e | |||
| 63ed31d2ec | |||
| 64b27db2ff | |||
| 03fe6e077c | |||
| 125ffa8863 | |||
| 3465acc57b | |||
| 30bd0d99ff | |||
| 29fbe46cce | |||
| fc414eeed4 | |||
| fce873936e | |||
| 7351d8a06d | |||
| 76093fe82d | |||
| ef247c95ff | |||
| c291e8a587 | |||
| 06e55d6394 | |||
| 2072f70a60 | |||
| ee9ea15233 | |||
| 11de117331 | |||
| fac0245297 | |||
| 9cb91415d9 | |||
| 24c661f743 | |||
| fecc9015fb | |||
| bce69362eb | |||
| 7f46d9e2d5 | |||
| 100ed01469 | |||
| 055685a4c4 | |||
| 46f93e380b | |||
| 6f6ad89c9f | |||
| d9911a9bc9 | |||
| faf77de9ce | |||
| 7f414b3dcf | |||
| 994ddea6cd | |||
| 41e4e73e63 | |||
| 88091bd77c | |||
| 02839dc415 | |||
| 17b70a1388 | |||
| 42d59709f9 | |||
| 30bc80b2f2 | |||
| 3808b3ee82 | |||
| bb5124c1ae | |||
| e6c78da062 | |||
| 5874142186 | |||
| 928335dd6b | |||
| 63dcda0ad1 | |||
| 122db9d903 | |||
| fc509a9340 | |||
| f546d3e2b1 |
14
.gitignore
vendored
14
.gitignore
vendored
@@ -11,8 +11,8 @@ prebuilt-binaries/dragonxd-win/*
|
|||||||
!prebuilt-binaries/dragonxd-win/.gitkeep
|
!prebuilt-binaries/dragonxd-win/.gitkeep
|
||||||
prebuilt-binaries/dragonxd-mac/*
|
prebuilt-binaries/dragonxd-mac/*
|
||||||
!prebuilt-binaries/dragonxd-mac/.gitkeep
|
!prebuilt-binaries/dragonxd-mac/.gitkeep
|
||||||
prebuilt-binaries/xmrig-hac/*
|
prebuilt-binaries/drg-xmrig/*
|
||||||
!prebuilt-binaries/xmrig-hac/.gitkeep
|
!prebuilt-binaries/drg-xmrig/.gitkeep
|
||||||
|
|
||||||
|
|
||||||
# External sources / toolchains (created by scripts/setup.sh)
|
# External sources / toolchains (created by scripts/setup.sh)
|
||||||
@@ -33,7 +33,11 @@ imgui.ini
|
|||||||
*.bak*
|
*.bak*
|
||||||
*.params
|
*.params
|
||||||
asmap.dat
|
asmap.dat
|
||||||
/external/xmrig-hac
|
# Wallet files hold PRIVATE KEYS — never commit them
|
||||||
|
wallet.dat
|
||||||
|
wallet-*.dat
|
||||||
|
wallet.dat.*
|
||||||
|
/external/drg-xmrig
|
||||||
/memory
|
/memory
|
||||||
/todo.md
|
/todo.md
|
||||||
/.github/
|
/.github/
|
||||||
@@ -54,3 +58,7 @@ third_party/silentdragonxlite/lib/vendor/
|
|||||||
|
|
||||||
# Generated by configure_file from res/ObsidianDragon.manifest.in (do not track)
|
# Generated by configure_file from res/ObsidianDragon.manifest.in (do not track)
|
||||||
res/ObsidianDragon.manifest
|
res/ObsidianDragon.manifest
|
||||||
|
|
||||||
|
# Cross-built mingw FreeType (color emoji) — regenerated by scripts/build-freetype-mingw.sh
|
||||||
|
third_party/freetype-mingw/
|
||||||
|
third_party/.freetype-mingw-build/
|
||||||
|
|||||||
58
CHANGELOG.md
Normal file
58
CHANGELOG.md
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable user-facing changes to ObsidianDragon are documented here. The format loosely
|
||||||
|
follows [Keep a Changelog](https://keepachangelog.com/); the project uses Conventional Commits.
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### ⚠️ Breaking changes
|
||||||
|
|
||||||
|
- **Remote RPC over plain HTTP is now refused by default.** If your wallet is configured to
|
||||||
|
reach a **remote** `rpchost`/`rpcconnect` **without TLS**, it will no longer connect — it
|
||||||
|
previously sent your `rpcuser`/`rpcpassword` in cleartext (capturable by anyone on the
|
||||||
|
network path) after only a dismissible warning. To reconnect, either:
|
||||||
|
- add **`rpctls=1`** to `DRAGONX.conf` (preferred, if your daemon supports TLS), or
|
||||||
|
- add **`rpcallowplaintext=1`** to `DRAGONX.conf` to explicitly accept the plaintext link.
|
||||||
|
|
||||||
|
Local and embedded daemons (`127.0.0.0/8`, `localhost`, `::1`) are unaffected.
|
||||||
|
|
||||||
|
### Security
|
||||||
|
|
||||||
|
- Refuse remote plaintext RPC credential transmission by default (see Breaking changes above).
|
||||||
|
- Tightened localhost detection: a hostname that merely *starts* with `127.` (e.g.
|
||||||
|
`127.evil.com`) is no longer mistaken for a loopback address, so it can no longer bypass the
|
||||||
|
plaintext-RPC protection.
|
||||||
|
- Sapling parameters are now integrity-checked (SHA-256) against pinned canonical digests
|
||||||
|
before use, instead of only checking that the files exist. A truncated or corrupt parameter
|
||||||
|
file is caught up front rather than surfacing later as a confusing shielded-operation failure.
|
||||||
|
(Cached via a `size:mtime` marker so it doesn't re-hash ~48 MB on every launch.)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Daemon crashes are no longer occasionally missed: a race between the UI thread and the
|
||||||
|
process monitor could consume the daemon's exit status, hiding a crash and defeating the
|
||||||
|
automatic-restart cap. The monitor is now the sole reaper.
|
||||||
|
- A daemon that fails to launch (missing execute permission, wrong architecture, corrupt
|
||||||
|
binary) now reports a precise error immediately instead of briefly showing "running" and
|
||||||
|
then a generic "exited unexpectedly (exit code 127)".
|
||||||
|
- A quick stop→start no longer triggers a restart storm: the wallet now waits briefly for a
|
||||||
|
previous daemon to release the data-directory lock and shows a clear, non-crash message
|
||||||
|
instead of exhausting the crash-restart budget.
|
||||||
|
- Failures while writing the daemon binaries or Sapling parameters (disk full, permission
|
||||||
|
denied) are now surfaced clearly up front instead of failing opaquely when the daemon later
|
||||||
|
can't start.
|
||||||
|
- Directory-creation failures on startup (read-only home, permission denied) now produce a
|
||||||
|
clear "Cannot create <dir>" message instead of a confusing downstream "config missing" /
|
||||||
|
"binary not found" error (or, in one path, an uncaught exception).
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- A "Taking longer than expected" notice now appears if the daemon is reachable but hasn't
|
||||||
|
finished initializing after ~45 s (configurable via `ui.toml`), with guidance to restart the
|
||||||
|
daemon or open the Console — instead of an indefinite silent spinner. It clears itself
|
||||||
|
automatically once the daemon connects.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Engineering detail and the finding-by-finding rationale for this batch live in
|
||||||
|
`docs/daemon-startup-hardening.md`.
|
||||||
136
CMakeLists.txt
136
CMakeLists.txt
@@ -15,7 +15,7 @@ if(APPLE)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
project(ObsidianDragon
|
project(ObsidianDragon
|
||||||
VERSION 2.0.0
|
VERSION 2.0.1
|
||||||
LANGUAGES C CXX
|
LANGUAGES C CXX
|
||||||
DESCRIPTION "DragonX Cryptocurrency Wallet"
|
DESCRIPTION "DragonX Cryptocurrency Wallet"
|
||||||
)
|
)
|
||||||
@@ -26,7 +26,7 @@ set(DRAGONX_VERSION_SUFFIX "")
|
|||||||
# ObsidianDragonLite is versioned INDEPENDENTLY of the full-node app above. The active variant's
|
# ObsidianDragonLite is versioned INDEPENDENTLY of the full-node app above. The active variant's
|
||||||
# version flows to the generated header, the Windows .rc/manifest, and build.sh's release names via
|
# version flows to the generated header, the Windows .rc/manifest, and build.sh's release names via
|
||||||
# DRAGONX_APP_VERSION* (resolved in the lite/full block below).
|
# DRAGONX_APP_VERSION* (resolved in the lite/full block below).
|
||||||
set(DRAGONX_LITE_VERSION "1.0.0")
|
set(DRAGONX_LITE_VERSION "1.1.0")
|
||||||
set(DRAGONX_LITE_VERSION_SUFFIX "")
|
set(DRAGONX_LITE_VERSION_SUFFIX "")
|
||||||
|
|
||||||
# C++17 standard
|
# C++17 standard
|
||||||
@@ -53,7 +53,6 @@ set_property(CACHE DRAGONX_LITE_BACKEND_LINK_MODE PROPERTY STRINGS imported)
|
|||||||
set(DRAGONX_LITE_BACKEND_ABI "sdxl-c-v1" CACHE STRING "Expected lite backend C ABI version")
|
set(DRAGONX_LITE_BACKEND_ABI "sdxl-c-v1" CACHE STRING "Expected lite backend C ABI version")
|
||||||
set(DRAGONX_LITE_BACKEND_SYMBOLS_FILE "" CACHE FILEPATH "Path to generated lite backend exported-symbol inventory")
|
set(DRAGONX_LITE_BACKEND_SYMBOLS_FILE "" CACHE FILEPATH "Path to generated lite backend exported-symbol inventory")
|
||||||
set(DRAGONX_LITE_BACKEND_MANIFEST "" CACHE FILEPATH "Optional path to generated lite backend artifact manifest")
|
set(DRAGONX_LITE_BACKEND_MANIFEST "" CACHE FILEPATH "Optional path to generated lite backend artifact manifest")
|
||||||
option(DRAGONX_LITE_BACKEND_REQUIRE_SIGNATURE "Require verified signature metadata in the lite backend artifact manifest" OFF)
|
|
||||||
set(DRAGONX_LITE_BACKEND_REQUIRED_SYMBOLS
|
set(DRAGONX_LITE_BACKEND_REQUIRED_SYMBOLS
|
||||||
litelib_wallet_exists
|
litelib_wallet_exists
|
||||||
litelib_initialize_new
|
litelib_initialize_new
|
||||||
@@ -126,36 +125,24 @@ if(DRAGONX_ENABLE_LITE_BACKEND)
|
|||||||
if(DRAGONX_LITE_BACKEND_MANIFEST AND NOT EXISTS "${DRAGONX_LITE_BACKEND_MANIFEST}")
|
if(DRAGONX_LITE_BACKEND_MANIFEST AND NOT EXISTS "${DRAGONX_LITE_BACKEND_MANIFEST}")
|
||||||
message(FATAL_ERROR "DRAGONX_LITE_BACKEND_MANIFEST does not exist: ${DRAGONX_LITE_BACKEND_MANIFEST}")
|
message(FATAL_ERROR "DRAGONX_LITE_BACKEND_MANIFEST does not exist: ${DRAGONX_LITE_BACKEND_MANIFEST}")
|
||||||
endif()
|
endif()
|
||||||
if(DRAGONX_LITE_BACKEND_REQUIRE_SIGNATURE)
|
# Note (F15-1): the former signature-metadata gate was removed. It trusted a
|
||||||
if(NOT DRAGONX_LITE_BACKEND_MANIFEST)
|
# "verification_status: verified" field that scripts/build-lite-backend-artifact.sh
|
||||||
message(FATAL_ERROR "DRAGONX_LITE_BACKEND_REQUIRE_SIGNATURE requires DRAGONX_LITE_BACKEND_MANIFEST")
|
# self-attested with no cryptographic check (the "verified" SHA was just the artifact's
|
||||||
endif()
|
# own SHA). The trust root is now build-from-source: that script builds the backend from
|
||||||
file(READ "${DRAGONX_LITE_BACKEND_MANIFEST}" DRAGONX_LITE_BACKEND_MANIFEST_JSON)
|
# the vendored in-tree source and refuses prebuilt artifacts, so the library linked here
|
||||||
string(JSON DRAGONX_LITE_SIGNATURE_STATUS ERROR_VARIABLE DRAGONX_LITE_SIGNATURE_STATUS_ERROR GET "${DRAGONX_LITE_BACKEND_MANIFEST_JSON}" signature_verification verification_status)
|
# is the one built from reviewed source. The required-symbol inventory check above stays.
|
||||||
if(DRAGONX_LITE_SIGNATURE_STATUS_ERROR)
|
|
||||||
message(FATAL_ERROR "DRAGONX_LITE_BACKEND_MANIFEST is missing signature verification status")
|
|
||||||
endif()
|
|
||||||
if(NOT DRAGONX_LITE_SIGNATURE_STATUS STREQUAL "verified")
|
|
||||||
message(FATAL_ERROR "DRAGONX_LITE_BACKEND_REQUIRE_SIGNATURE requires verified signature metadata")
|
|
||||||
endif()
|
|
||||||
string(JSON DRAGONX_LITE_SIGNATURE_VERIFIED_SHA ERROR_VARIABLE DRAGONX_LITE_SIGNATURE_VERIFIED_SHA_ERROR GET "${DRAGONX_LITE_BACKEND_MANIFEST_JSON}" signature_verification verified_artifact_sha256)
|
|
||||||
string(JSON DRAGONX_LITE_ARTIFACT_SHA ERROR_VARIABLE DRAGONX_LITE_ARTIFACT_SHA_ERROR GET "${DRAGONX_LITE_BACKEND_MANIFEST_JSON}" artifact sha256)
|
|
||||||
if(DRAGONX_LITE_SIGNATURE_VERIFIED_SHA_ERROR OR DRAGONX_LITE_ARTIFACT_SHA_ERROR)
|
|
||||||
message(FATAL_ERROR "DRAGONX_LITE_BACKEND_MANIFEST is missing artifact/signature SHA-256 metadata")
|
|
||||||
endif()
|
|
||||||
if(NOT DRAGONX_LITE_SIGNATURE_VERIFIED_SHA STREQUAL DRAGONX_LITE_ARTIFACT_SHA)
|
|
||||||
message(FATAL_ERROR "DRAGONX_LITE_BACKEND_MANIFEST signature metadata does not verify the artifact SHA-256")
|
|
||||||
endif()
|
|
||||||
string(JSON DRAGONX_LITE_SIGNATURE_PERFORMED ERROR_VARIABLE DRAGONX_LITE_SIGNATURE_PERFORMED_ERROR GET "${DRAGONX_LITE_BACKEND_MANIFEST_JSON}" signature_verification verification_performed)
|
|
||||||
if(DRAGONX_LITE_SIGNATURE_PERFORMED_ERROR OR NOT DRAGONX_LITE_SIGNATURE_PERFORMED)
|
|
||||||
message(FATAL_ERROR "DRAGONX_LITE_BACKEND_REQUIRE_SIGNATURE requires verification_performed=true")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_library(dragonx_lite_backend UNKNOWN IMPORTED)
|
add_library(dragonx_lite_backend UNKNOWN IMPORTED)
|
||||||
set_target_properties(dragonx_lite_backend PROPERTIES
|
set_target_properties(dragonx_lite_backend PROPERTIES
|
||||||
IMPORTED_LOCATION "${DRAGONX_LITE_BACKEND_LIBRARY}"
|
IMPORTED_LOCATION "${DRAGONX_LITE_BACKEND_LIBRARY}"
|
||||||
)
|
)
|
||||||
|
if(APPLE)
|
||||||
|
# The Rust backend's TLS stack (security-framework / core-foundation crates)
|
||||||
|
# references Secure Transport (SSL*) + CoreFoundation symbols. Link the frameworks
|
||||||
|
# that provide them, or the static lib leaves ~130 symbols undefined at link time.
|
||||||
|
set_property(TARGET dragonx_lite_backend APPEND PROPERTY
|
||||||
|
INTERFACE_LINK_LIBRARIES "-framework Security" "-framework CoreFoundation")
|
||||||
|
endif()
|
||||||
if(DRAGONX_LITE_BACKEND_INCLUDE_DIR)
|
if(DRAGONX_LITE_BACKEND_INCLUDE_DIR)
|
||||||
if(NOT IS_DIRECTORY "${DRAGONX_LITE_BACKEND_INCLUDE_DIR}")
|
if(NOT IS_DIRECTORY "${DRAGONX_LITE_BACKEND_INCLUDE_DIR}")
|
||||||
message(FATAL_ERROR "DRAGONX_LITE_BACKEND_INCLUDE_DIR does not exist: ${DRAGONX_LITE_BACKEND_INCLUDE_DIR}")
|
message(FATAL_ERROR "DRAGONX_LITE_BACKEND_INCLUDE_DIR does not exist: ${DRAGONX_LITE_BACKEND_INCLUDE_DIR}")
|
||||||
@@ -226,7 +213,7 @@ include(FetchContent)
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
json
|
json
|
||||||
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
||||||
GIT_TAG v3.11.3
|
GIT_TAG 9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03 # v3.11.3 — pinned to immutable commit (L-08); tags are mutable
|
||||||
GIT_SHALLOW TRUE
|
GIT_SHALLOW TRUE
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(json)
|
FetchContent_MakeAvailable(json)
|
||||||
@@ -235,7 +222,7 @@ FetchContent_MakeAvailable(json)
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
tomlplusplus
|
tomlplusplus
|
||||||
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
|
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
|
||||||
GIT_TAG v3.4.0
|
GIT_TAG 30172438cee64926dc41fdd9c11fb3ba5b2ba9de # v3.4.0 — pinned to immutable commit (L-08); tags are mutable
|
||||||
GIT_SHALLOW TRUE
|
GIT_SHALLOW TRUE
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(tomlplusplus)
|
FetchContent_MakeAvailable(tomlplusplus)
|
||||||
@@ -302,8 +289,17 @@ message(STATUS "Fetching libwebp (decode-only, static)...")
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
libwebp
|
libwebp
|
||||||
GIT_REPOSITORY https://github.com/webmproject/libwebp.git
|
GIT_REPOSITORY https://github.com/webmproject/libwebp.git
|
||||||
GIT_TAG v1.4.0
|
GIT_TAG 845d5476a866141ba35ac133f856fa62f0b7445f # v1.4.0 — pinned to immutable commit (L-08); tags are mutable
|
||||||
GIT_SHALLOW TRUE
|
GIT_SHALLOW TRUE
|
||||||
|
# libwebp's cpu.cmake applies -mno-sse2/-mno-sse4.1 to its scalar reference DSP
|
||||||
|
# files when it can't probe SSE support. Under a macOS universal build
|
||||||
|
# (-arch arm64;x86_64) that probe fails, so the flags land on the x86_64 slice,
|
||||||
|
# where -mno-sse2 disables _Float16 and breaks the SDK's <math.h>. Neutralize
|
||||||
|
# those disable flags (SSE2 is x86_64 baseline). Portable + idempotent; a no-op
|
||||||
|
# for single-arch Linux/Windows/x86_64 builds. See cmake/patch-libwebp-simd.cmake.
|
||||||
|
PATCH_COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DCPU_CMAKE=<SOURCE_DIR>/cmake/cpu.cmake
|
||||||
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/patch-libwebp-simd.cmake
|
||||||
)
|
)
|
||||||
set(WEBP_LINK_STATIC ON CACHE BOOL "" FORCE)
|
set(WEBP_LINK_STATIC ON CACHE BOOL "" FORCE)
|
||||||
set(WEBP_BUILD_ANIM_UTILS OFF CACHE BOOL "" FORCE)
|
set(WEBP_BUILD_ANIM_UTILS OFF CACHE BOOL "" FORCE)
|
||||||
@@ -406,6 +402,35 @@ else()
|
|||||||
list(APPEND IMGUI_HEADERS ${IMGUI_DIR}/backends/imgui_impl_opengl3.h)
|
list(APPEND IMGUI_HEADERS ${IMGUI_DIR}/backends/imgui_impl_opengl3.h)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Optional FreeType font loader — enables color-emoji rendering (COLR/CPAL Twemoji) when the chat
|
||||||
|
# "color emoji" setting is on; otherwise the wallet falls back to the monochrome emoji subset.
|
||||||
|
# - Native Linux/macOS: use the system FreeType via find_package.
|
||||||
|
# - Windows (mingw cross): the toolchain ships no FreeType, so build.sh --win-release cross-builds a
|
||||||
|
# static one (scripts/build-freetype-mingw.sh) and passes -DDRAGONX_MINGW_FREETYPE_PREFIX here.
|
||||||
|
# - Other cross builds (osxcross) without FreeType: silently fall back to monochrome.
|
||||||
|
set(DRAGONX_FREETYPE OFF)
|
||||||
|
set(DRAGONX_FREETYPE_LIB "")
|
||||||
|
set(DRAGONX_FREETYPE_INC "")
|
||||||
|
if(DEFINED DRAGONX_MINGW_FREETYPE_PREFIX AND EXISTS "${DRAGONX_MINGW_FREETYPE_PREFIX}/lib/libfreetype.a")
|
||||||
|
set(DRAGONX_FREETYPE ON)
|
||||||
|
set(DRAGONX_FREETYPE_LIB "${DRAGONX_MINGW_FREETYPE_PREFIX}/lib/libfreetype.a")
|
||||||
|
set(DRAGONX_FREETYPE_INC "${DRAGONX_MINGW_FREETYPE_PREFIX}/include/freetype2")
|
||||||
|
message(STATUS "FreeType (mingw cross-built) found — chat color emoji enabled")
|
||||||
|
elseif(NOT CMAKE_CROSSCOMPILING)
|
||||||
|
find_package(Freetype QUIET)
|
||||||
|
if(FREETYPE_FOUND)
|
||||||
|
set(DRAGONX_FREETYPE ON)
|
||||||
|
set(DRAGONX_FREETYPE_LIB Freetype::Freetype) # imported target carries include dirs
|
||||||
|
message(STATUS "FreeType ${FREETYPE_VERSION_STRING} found — chat color emoji enabled")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if(DRAGONX_FREETYPE)
|
||||||
|
list(APPEND IMGUI_SOURCES ${IMGUI_DIR}/misc/freetype/imgui_freetype.cpp)
|
||||||
|
list(APPEND IMGUI_HEADERS ${IMGUI_DIR}/misc/freetype/imgui_freetype.h)
|
||||||
|
else()
|
||||||
|
message(STATUS "FreeType not found — chat color emoji falls back to monochrome")
|
||||||
|
endif()
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# QR Code library (bundled)
|
# QR Code library (bundled)
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@@ -496,6 +521,8 @@ set(APP_SOURCES
|
|||||||
src/ui/windows/settings_window.cpp
|
src/ui/windows/settings_window.cpp
|
||||||
src/ui/pages/settings_page.cpp
|
src/ui/pages/settings_page.cpp
|
||||||
src/ui/windows/about_dialog.cpp
|
src/ui/windows/about_dialog.cpp
|
||||||
|
src/ui/windows/faq_dialog.cpp
|
||||||
|
src/ui/windows/faq_content.cpp
|
||||||
src/ui/windows/key_export_dialog.cpp
|
src/ui/windows/key_export_dialog.cpp
|
||||||
src/ui/windows/transaction_details_dialog.cpp
|
src/ui/windows/transaction_details_dialog.cpp
|
||||||
src/ui/windows/qr_popup_dialog.cpp
|
src/ui/windows/qr_popup_dialog.cpp
|
||||||
@@ -519,6 +546,7 @@ set(APP_SOURCES
|
|||||||
src/util/async_task_manager.cpp
|
src/util/async_task_manager.cpp
|
||||||
src/util/amount_format.cpp
|
src/util/amount_format.cpp
|
||||||
src/util/address_validation.cpp
|
src/util/address_validation.cpp
|
||||||
|
src/util/seed_phrase.cpp
|
||||||
src/util/base64.cpp
|
src/util/base64.cpp
|
||||||
src/util/single_instance.cpp
|
src/util/single_instance.cpp
|
||||||
src/util/i18n.cpp
|
src/util/i18n.cpp
|
||||||
@@ -526,6 +554,7 @@ set(APP_SOURCES
|
|||||||
src/util/platform.cpp
|
src/util/platform.cpp
|
||||||
src/util/payment_uri.cpp
|
src/util/payment_uri.cpp
|
||||||
src/util/texture_loader.cpp
|
src/util/texture_loader.cpp
|
||||||
|
src/util/svg_texture.cpp
|
||||||
src/util/noise_texture.cpp
|
src/util/noise_texture.cpp
|
||||||
src/daemon/embedded_daemon.cpp
|
src/daemon/embedded_daemon.cpp
|
||||||
src/daemon/seed_wallet_creator.cpp
|
src/daemon/seed_wallet_creator.cpp
|
||||||
@@ -630,6 +659,8 @@ set(APP_HEADERS
|
|||||||
src/ui/windows/console_tab_helpers.h
|
src/ui/windows/console_tab_helpers.h
|
||||||
src/ui/windows/settings_window.h
|
src/ui/windows/settings_window.h
|
||||||
src/ui/windows/about_dialog.h
|
src/ui/windows/about_dialog.h
|
||||||
|
src/ui/windows/faq_dialog.h
|
||||||
|
src/ui/windows/faq_content.h
|
||||||
src/ui/windows/key_export_dialog.h
|
src/ui/windows/key_export_dialog.h
|
||||||
src/ui/windows/transaction_details_dialog.h
|
src/ui/windows/transaction_details_dialog.h
|
||||||
src/ui/windows/qr_popup_dialog.h
|
src/ui/windows/qr_popup_dialog.h
|
||||||
@@ -730,7 +761,9 @@ ${CMAKE_SOURCE_DIR}/res/fonts/Ubuntu-Medium.ttf;\
|
|||||||
${CMAKE_SOURCE_DIR}/res/fonts/UbuntuMono-R.ttf;\
|
${CMAKE_SOURCE_DIR}/res/fonts/UbuntuMono-R.ttf;\
|
||||||
${CMAKE_SOURCE_DIR}/res/fonts/MaterialIcons-Regular.ttf;\
|
${CMAKE_SOURCE_DIR}/res/fonts/MaterialIcons-Regular.ttf;\
|
||||||
${CMAKE_SOURCE_DIR}/res/fonts/MaterialDesignIcons-Pickaxe-Subset.ttf;\
|
${CMAKE_SOURCE_DIR}/res/fonts/MaterialDesignIcons-Pickaxe-Subset.ttf;\
|
||||||
${CMAKE_SOURCE_DIR}/res/fonts/NotoSansCJK-Subset.ttf"
|
${CMAKE_SOURCE_DIR}/res/fonts/NotoSansCJK-Subset.ttf;\
|
||||||
|
${CMAKE_SOURCE_DIR}/res/fonts/NotoEmoji-Subset.ttf;\
|
||||||
|
${CMAKE_SOURCE_DIR}/res/fonts/TwemojiMozilla-Color.ttf"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(ObsidianDragon
|
add_executable(ObsidianDragon
|
||||||
@@ -863,6 +896,15 @@ else()
|
|||||||
target_compile_definitions(ObsidianDragon PRIVATE DRAGONX_HAS_GLAD)
|
target_compile_definitions(ObsidianDragon PRIVATE DRAGONX_HAS_GLAD)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Color-emoji font loader (FreeType) — linked + flagged only when found (see DRAGONX_FREETYPE above).
|
||||||
|
if(DRAGONX_FREETYPE)
|
||||||
|
target_link_libraries(ObsidianDragon PRIVATE ${DRAGONX_FREETYPE_LIB})
|
||||||
|
if(DRAGONX_FREETYPE_INC)
|
||||||
|
target_include_directories(ObsidianDragon PRIVATE ${DRAGONX_FREETYPE_INC})
|
||||||
|
endif()
|
||||||
|
target_compile_definitions(ObsidianDragon PRIVATE DRAGONX_HAVE_FREETYPE)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(HushChatFixtureCheck
|
add_executable(HushChatFixtureCheck
|
||||||
tools/hushchat_fixture_check.cpp
|
tools/hushchat_fixture_check.cpp
|
||||||
src/chat/chat_protocol.cpp
|
src/chat/chat_protocol.cpp
|
||||||
@@ -1037,6 +1079,32 @@ install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/res
|
|||||||
OPTIONAL
|
OPTIONAL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# dragonx-wallet-rebuild — offline recovery helper for a BDB-inconsistent wallet.dat.
|
||||||
|
# Bundled next to the daemon; the app spawns it out-of-process. It is the ONLY thing that links
|
||||||
|
# Berkeley DB, so the AGPLv3 BDB never contaminates the GPLv3 GUI (same boundary as the daemon).
|
||||||
|
# Release builds should point DRAGONX_BDB_ROOT at the vendored static libdb (external/dragonx/depends);
|
||||||
|
# a dev build falls back to the system Berkeley DB. Skipped (with a note) if no BDB is found.
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
find_path(BDB_INCLUDE_DIR db.h HINTS ${DRAGONX_BDB_ROOT}/include /usr/include /usr/local/include)
|
||||||
|
find_library(BDB_LIBRARY NAMES db-6.2 db-6.0 db-5.3 db libdb
|
||||||
|
HINTS ${DRAGONX_BDB_ROOT}/lib /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu)
|
||||||
|
if(BDB_INCLUDE_DIR AND BDB_LIBRARY)
|
||||||
|
add_executable(dragonx-wallet-rebuild tools/wallet_rebuild/main.cpp)
|
||||||
|
target_include_directories(dragonx-wallet-rebuild PRIVATE ${CMAKE_SOURCE_DIR}/src ${BDB_INCLUDE_DIR})
|
||||||
|
target_link_libraries(dragonx-wallet-rebuild PRIVATE ${BDB_LIBRARY})
|
||||||
|
if(WIN32)
|
||||||
|
target_link_libraries(dragonx-wallet-rebuild PRIVATE ws2_32) # static libdb-6.2 pulls in winsock
|
||||||
|
else()
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
target_link_libraries(dragonx-wallet-rebuild PRIVATE Threads::Threads ${CMAKE_DL_LIBS}) # static libdb needs pthread/dl
|
||||||
|
endif()
|
||||||
|
set_target_properties(dragonx-wallet-rebuild PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
|
message(STATUS "wallet-rebuild helper: ON (Berkeley DB ${BDB_LIBRARY})")
|
||||||
|
else()
|
||||||
|
message(STATUS "wallet-rebuild helper: OFF (no Berkeley DB found; set DRAGONX_BDB_ROOT for release builds)")
|
||||||
|
endif()
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@@ -1085,6 +1153,7 @@ if(BUILD_TESTING)
|
|||||||
src/util/payment_uri.cpp
|
src/util/payment_uri.cpp
|
||||||
src/util/amount_format.cpp
|
src/util/amount_format.cpp
|
||||||
src/util/address_validation.cpp
|
src/util/address_validation.cpp
|
||||||
|
src/util/seed_phrase.cpp
|
||||||
src/util/i18n.cpp
|
src/util/i18n.cpp
|
||||||
src/util/text_format.cpp
|
src/util/text_format.cpp
|
||||||
src/data/wallet_state.cpp
|
src/data/wallet_state.cpp
|
||||||
@@ -1092,6 +1161,7 @@ if(BUILD_TESTING)
|
|||||||
src/data/address_book.cpp
|
src/data/address_book.cpp
|
||||||
src/data/wallet_index.cpp
|
src/data/wallet_index.cpp
|
||||||
src/daemon/lifecycle_adapters.cpp
|
src/daemon/lifecycle_adapters.cpp
|
||||||
|
src/daemon/embedded_daemon.cpp
|
||||||
src/rpc/connection.cpp
|
src/rpc/connection.cpp
|
||||||
src/config/settings.cpp
|
src/config/settings.cpp
|
||||||
src/resources/embedded_resources.cpp
|
src/resources/embedded_resources.cpp
|
||||||
@@ -1163,5 +1233,5 @@ message(STATUS " Lite backend: ${DRAGONX_LITE_BACKEND_READY}")
|
|||||||
message(STATUS " Lite lib: ${DRAGONX_LITE_BACKEND_LIBRARY}")
|
message(STATUS " Lite lib: ${DRAGONX_LITE_BACKEND_LIBRARY}")
|
||||||
message(STATUS " Lite symbols: ${DRAGONX_LITE_BACKEND_SYMBOLS_FILE}")
|
message(STATUS " Lite symbols: ${DRAGONX_LITE_BACKEND_SYMBOLS_FILE}")
|
||||||
message(STATUS " Lite manifest: ${DRAGONX_LITE_BACKEND_MANIFEST}")
|
message(STATUS " Lite manifest: ${DRAGONX_LITE_BACKEND_MANIFEST}")
|
||||||
message(STATUS " Lite signature: ${DRAGONX_LITE_BACKEND_REQUIRE_SIGNATURE}")
|
message(STATUS " Lite trust: built-from-source (vendored third_party/silentdragonxlite)")
|
||||||
message(STATUS "")
|
message(STATUS "")
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ Download linux and windows binaries of latest releases and place in binary direc
|
|||||||
- prebuilt-binaries/dragonxd-win/
|
- prebuilt-binaries/dragonxd-win/
|
||||||
- prebuilt-binaries/dragonxd-mac/
|
- prebuilt-binaries/dragonxd-mac/
|
||||||
|
|
||||||
**xmrig HAC fork** (https://git.dragonx.is/dragonx/xmrig-hac):
|
**DRG-XMRig fork** (https://git.dragonx.is/DragonX/drg-xmrig):
|
||||||
- prebuilt-binaries/xmrig-hac/
|
- prebuilt-binaries/drg-xmrig/
|
||||||
|
|
||||||
|
|
||||||
## Build Steps
|
## Build Steps
|
||||||
|
|||||||
230
build.sh
230
build.sh
@@ -131,7 +131,7 @@ fi
|
|||||||
# truth): the full-node app uses project() VERSION + DRAGONX_VERSION_SUFFIX; ObsidianDragonLite uses
|
# truth): the full-node app uses project() VERSION + DRAGONX_VERSION_SUFFIX; ObsidianDragonLite uses
|
||||||
# DRAGONX_LITE_VERSION + DRAGONX_LITE_VERSION_SUFFIX.
|
# DRAGONX_LITE_VERSION + DRAGONX_LITE_VERSION_SUFFIX.
|
||||||
_cml="$SCRIPT_DIR/CMakeLists.txt"
|
_cml="$SCRIPT_DIR/CMakeLists.txt"
|
||||||
_full_ver=$(sed -n 's/^[[:space:]]*VERSION[[:space:]]\+\([0-9][0-9.]*\).*/\1/p' "$_cml" | head -1)
|
_full_ver=$(sed -n 's/^[[:space:]]*VERSION[[:space:]][[:space:]]*\([0-9][0-9.]*\).*/\1/p' "$_cml" | head -1)
|
||||||
_full_suffix=$(sed -n 's/^set(DRAGONX_VERSION_SUFFIX[[:space:]]*"\([^"]*\)").*/\1/p' "$_cml" | head -1)
|
_full_suffix=$(sed -n 's/^set(DRAGONX_VERSION_SUFFIX[[:space:]]*"\([^"]*\)").*/\1/p' "$_cml" | head -1)
|
||||||
_lite_ver=$(sed -n 's/^set(DRAGONX_LITE_VERSION[[:space:]]*"\([^"]*\)").*/\1/p' "$_cml" | head -1)
|
_lite_ver=$(sed -n 's/^set(DRAGONX_LITE_VERSION[[:space:]]*"\([^"]*\)").*/\1/p' "$_cml" | head -1)
|
||||||
_lite_suffix=$(sed -n 's/^set(DRAGONX_LITE_VERSION_SUFFIX[[:space:]]*"\([^"]*\)").*/\1/p' "$_cml" | head -1)
|
_lite_suffix=$(sed -n 's/^set(DRAGONX_LITE_VERSION_SUFFIX[[:space:]]*"\([^"]*\)").*/\1/p' "$_cml" | head -1)
|
||||||
@@ -195,6 +195,39 @@ should_bundle_full_node_assets() {
|
|||||||
! $DO_LITE
|
! $DO_LITE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The offline 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. A full-node release must
|
||||||
|
# NEVER ship without it (the in-app "Repair automatically" option silently disappears otherwise), so
|
||||||
|
# treat a missing helper as a HARD build failure instead of degrading recovery to Restore-only.
|
||||||
|
# $1 = built helper path (e.g. bin/dragonx-wallet-rebuild[.exe]); $2 = the BDB depends dir for the hint.
|
||||||
|
require_wallet_rebuild_helper() {
|
||||||
|
local helper="$1" depends="$2"
|
||||||
|
should_bundle_full_node_assets || return 0 # lite builds have no BDB wallet.dat to rebuild
|
||||||
|
if [[ ! -f "$helper" ]]; then
|
||||||
|
err "wallet-rebuild helper was NOT built: $helper"
|
||||||
|
err " → the recovery 'Repair automatically' option would be MISSING from this release."
|
||||||
|
err " Cause: the vendored Berkeley DB depends are absent, so CMake skipped the dragonx-wallet-rebuild target."
|
||||||
|
err " Fix: provide ${depends}/{lib/libdb-6.2.a,include/db.h} (same static libdb the daemon links), then rebuild."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
info " wallet-rebuild helper present: $helper"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Vendored Berkeley DB depends directory for the macOS wallet-rebuild helper, by TARGET arch. The daemon
|
||||||
|
# links a static libdb-6.2; the helper must match the build arch, so derive the triple from it rather than
|
||||||
|
# hardcoding one. Single-arch: x86_64 -> x86_64-apple-darwin, arm64 -> aarch64-apple-darwin. "universal"
|
||||||
|
# (or anything unexpected) falls back to the host arch — a universal .app needs a universal libdb, so if
|
||||||
|
# only a single-arch libdb is vendored, build single-arch via DRAGONX_MAC_ARCHS.
|
||||||
|
mac_bdb_dir() {
|
||||||
|
local arch="$1" triple
|
||||||
|
case "$arch" in
|
||||||
|
x86_64) triple="x86_64-apple-darwin" ;;
|
||||||
|
arm64) triple="aarch64-apple-darwin" ;;
|
||||||
|
*) [[ "$(uname -m)" == "arm64" ]] && triple="aarch64-apple-darwin" || triple="x86_64-apple-darwin" ;;
|
||||||
|
esac
|
||||||
|
printf '%s/external/dragonx/depends/%s\n' "$SCRIPT_DIR" "$triple"
|
||||||
|
}
|
||||||
|
|
||||||
# ── Helper: find resource files ──────────────────────────────────────────────
|
# ── Helper: find resource files ──────────────────────────────────────────────
|
||||||
find_sapling_params() {
|
find_sapling_params() {
|
||||||
local dirs=(
|
local dirs=(
|
||||||
@@ -286,6 +319,9 @@ bundle_linux_daemon() {
|
|||||||
# asmap.dat
|
# asmap.dat
|
||||||
find_asmap && cp "$ASMAP_DAT" "$dest/asmap.dat" && info " Bundled asmap.dat"
|
find_asmap && cp "$ASMAP_DAT" "$dest/asmap.dat" && info " Bundled asmap.dat"
|
||||||
|
|
||||||
|
# (The dragonx-wallet-rebuild recovery helper is built into bin/ by CMake and packaged explicitly
|
||||||
|
# by each release path — required via require_wallet_rebuild_helper — so it is not copied here.)
|
||||||
|
|
||||||
return $found
|
return $found
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,11 +372,24 @@ build_release_linux() {
|
|||||||
mkdir -p "$bd" && cd "$bd"
|
mkdir -p "$bd" && cd "$bd"
|
||||||
|
|
||||||
# ── Compile ──────────────────────────────────────────────────────────────
|
# ── Compile ──────────────────────────────────────────────────────────────
|
||||||
|
# Point the wallet-rebuild helper at the vendored static Berkeley DB (same libdb the daemon links)
|
||||||
|
# so its output is a v6.2 btree the bundled dragonxd reads. Pass the paths EXPLICITLY (bypasses
|
||||||
|
# find_library + its cache); the helper target is simply not built if the depends tree is absent.
|
||||||
|
local lin_bdb="$SCRIPT_DIR/external/dragonx/depends/x86_64-unknown-linux-gnu"
|
||||||
|
local BDB_ARGS=()
|
||||||
|
if [[ -f "$lin_bdb/lib/libdb-6.2.a" && -f "$lin_bdb/include/db.h" ]]; then
|
||||||
|
BDB_ARGS=( -DBDB_INCLUDE_DIR="$lin_bdb/include" -DBDB_LIBRARY="$lin_bdb/lib/libdb-6.2.a" )
|
||||||
|
elif should_bundle_full_node_assets; then
|
||||||
|
err "Vendored Berkeley DB depends missing at $lin_bdb — the wallet-rebuild recovery helper cannot be built."
|
||||||
|
err " A full-node release must ship it; aborting rather than degrading recovery to Restore-only."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
info "Configuring ..."
|
info "Configuring ..."
|
||||||
cmake "$SCRIPT_DIR" \
|
cmake "$SCRIPT_DIR" \
|
||||||
-DCMAKE_BUILD_TYPE=Release \
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG" \
|
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG" \
|
||||||
-DDRAGONX_USE_SYSTEM_SDL3=ON \
|
-DDRAGONX_USE_SYSTEM_SDL3=ON \
|
||||||
|
"${BDB_ARGS[@]}" \
|
||||||
"${CMAKE_LITE_ARGS[@]}"
|
"${CMAKE_LITE_ARGS[@]}"
|
||||||
|
|
||||||
info "Building with $JOBS jobs ..."
|
info "Building with $JOBS jobs ..."
|
||||||
@@ -348,8 +397,12 @@ build_release_linux() {
|
|||||||
|
|
||||||
[[ -f "bin/${APP_BASENAME}" ]] || { err "Linux build failed"; exit 1; }
|
[[ -f "bin/${APP_BASENAME}" ]] || { err "Linux build failed"; exit 1; }
|
||||||
|
|
||||||
|
# A full-node release MUST include the recovery helper — fail loudly, never ship without it.
|
||||||
|
require_wallet_rebuild_helper "bin/dragonx-wallet-rebuild" "$lin_bdb"
|
||||||
|
|
||||||
info "Stripping ..."
|
info "Stripping ..."
|
||||||
strip "bin/${APP_BASENAME}"
|
strip "bin/${APP_BASENAME}"
|
||||||
|
[[ -f "bin/dragonx-wallet-rebuild" ]] && strip "bin/dragonx-wallet-rebuild"
|
||||||
info "Binary: $(du -h "bin/${APP_BASENAME}" | cut -f1)"
|
info "Binary: $(du -h "bin/${APP_BASENAME}" | cut -f1)"
|
||||||
|
|
||||||
if should_bundle_full_node_assets; then
|
if should_bundle_full_node_assets; then
|
||||||
@@ -384,9 +437,12 @@ build_release_linux() {
|
|||||||
[[ -f bin/asmap.dat ]] && cp bin/asmap.dat "$dist_dir/"
|
[[ -f bin/asmap.dat ]] && cp bin/asmap.dat "$dist_dir/"
|
||||||
[[ -f bin/sapling-spend.params ]] && cp bin/sapling-spend.params "$dist_dir/"
|
[[ -f bin/sapling-spend.params ]] && cp bin/sapling-spend.params "$dist_dir/"
|
||||||
[[ -f bin/sapling-output.params ]] && cp bin/sapling-output.params "$dist_dir/"
|
[[ -f bin/sapling-output.params ]] && cp bin/sapling-output.params "$dist_dir/"
|
||||||
|
# Offline wallet-rebuild recovery helper — required (asserted above); ships next to the app.
|
||||||
|
cp bin/dragonx-wallet-rebuild "$dist_dir/" && chmod +x "$dist_dir/dragonx-wallet-rebuild"
|
||||||
|
info " Bundled dragonx-wallet-rebuild"
|
||||||
fi
|
fi
|
||||||
# Bundle xmrig for mining support
|
# Bundle xmrig for mining support
|
||||||
local XMRIG_LINUX="$SCRIPT_DIR/prebuilt-binaries/xmrig-hac/xmrig"
|
local XMRIG_LINUX="$SCRIPT_DIR/prebuilt-binaries/drg-xmrig/xmrig"
|
||||||
[[ -f "$XMRIG_LINUX" ]] && { cp "$XMRIG_LINUX" "$dist_dir/"; chmod +x "$dist_dir/xmrig"; info "Bundled xmrig"; } || warn "xmrig not found — mining unavailable in zip"
|
[[ -f "$XMRIG_LINUX" ]] && { cp "$XMRIG_LINUX" "$dist_dir/"; chmod +x "$dist_dir/xmrig"; info "Bundled xmrig"; } || warn "xmrig not found — mining unavailable in zip"
|
||||||
cp -r bin/res "$dist_dir/" 2>/dev/null || true
|
cp -r bin/res "$dist_dir/" 2>/dev/null || true
|
||||||
|
|
||||||
@@ -417,9 +473,11 @@ build_release_linux() {
|
|||||||
[[ -f bin/asmap.dat ]] && cp bin/asmap.dat "$APPDIR/usr/bin/"
|
[[ -f bin/asmap.dat ]] && cp bin/asmap.dat "$APPDIR/usr/bin/"
|
||||||
[[ -f bin/sapling-spend.params ]] && cp bin/sapling-spend.params "$APPDIR/usr/bin/"
|
[[ -f bin/sapling-spend.params ]] && cp bin/sapling-spend.params "$APPDIR/usr/bin/"
|
||||||
[[ -f bin/sapling-output.params ]] && cp bin/sapling-output.params "$APPDIR/usr/bin/"
|
[[ -f bin/sapling-output.params ]] && cp bin/sapling-output.params "$APPDIR/usr/bin/"
|
||||||
|
# Offline wallet-rebuild recovery helper — required (asserted above); ships next to the app.
|
||||||
|
cp bin/dragonx-wallet-rebuild "$APPDIR/usr/bin/" && chmod +x "$APPDIR/usr/bin/dragonx-wallet-rebuild"
|
||||||
fi
|
fi
|
||||||
# Bundle xmrig for mining support
|
# Bundle xmrig for mining support
|
||||||
local XMRIG_LINUX_AI="$SCRIPT_DIR/prebuilt-binaries/xmrig-hac/xmrig"
|
local XMRIG_LINUX_AI="$SCRIPT_DIR/prebuilt-binaries/drg-xmrig/xmrig"
|
||||||
[[ -f "$XMRIG_LINUX_AI" ]] && { cp "$XMRIG_LINUX_AI" "$APPDIR/usr/bin/"; chmod +x "$APPDIR/usr/bin/xmrig"; }
|
[[ -f "$XMRIG_LINUX_AI" ]] && { cp "$XMRIG_LINUX_AI" "$APPDIR/usr/bin/"; chmod +x "$APPDIR/usr/bin/xmrig"; }
|
||||||
|
|
||||||
# Desktop entry
|
# Desktop entry
|
||||||
@@ -478,18 +536,28 @@ APPRUN
|
|||||||
done
|
done
|
||||||
[[ -f "$bd/_deps/sdl3-build/libSDL3.so" ]] && cp "$bd/_deps/sdl3-build/libSDL3.so"* "$APPDIR/usr/lib/" 2>/dev/null || true
|
[[ -f "$bd/_deps/sdl3-build/libSDL3.so" ]] && cp "$bd/_deps/sdl3-build/libSDL3.so"* "$APPDIR/usr/lib/" 2>/dev/null || true
|
||||||
|
|
||||||
# appimagetool
|
# appimagetool — pinned to a tagged release and SHA-256 verified before we exec it.
|
||||||
|
# The old "continuous" tag is a MOVING build fetched over the network and run on the release
|
||||||
|
# builder; a compromised/MITM'd artifact would execute here. Verify, or refuse to package.
|
||||||
|
local APPIMAGETOOL_URL="https://github.com/AppImage/appimagetool/releases/download/1.9.0/appimagetool-x86_64.AppImage"
|
||||||
|
local APPIMAGETOOL_SHA256="46fdd785094c7f6e545b61afcfb0f3d98d8eab243f644b4b17698c01d06083d1"
|
||||||
local APPIMAGETOOL=""
|
local APPIMAGETOOL=""
|
||||||
if command -v appimagetool &>/dev/null; then
|
if command -v appimagetool &>/dev/null; then
|
||||||
APPIMAGETOOL="appimagetool"
|
APPIMAGETOOL="appimagetool" # maintainer's own trusted system install
|
||||||
elif [[ -f "$bd/appimagetool-x86_64.AppImage" ]]; then
|
|
||||||
APPIMAGETOOL="$bd/appimagetool-x86_64.AppImage"
|
|
||||||
else
|
else
|
||||||
info "Downloading appimagetool ..."
|
local at="$bd/appimagetool-x86_64.AppImage"
|
||||||
wget -q -O "$bd/appimagetool-x86_64.AppImage" \
|
# Re-verify any cached copy too; a stale unverified download must not be trusted.
|
||||||
"https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
|
if [[ ! -f "$at" ]] || ! echo "${APPIMAGETOOL_SHA256} ${at}" | sha256sum -c --status; then
|
||||||
chmod +x "$bd/appimagetool-x86_64.AppImage"
|
info "Downloading appimagetool 1.9.0 (pinned) ..."
|
||||||
APPIMAGETOOL="$bd/appimagetool-x86_64.AppImage"
|
wget -q -O "$at" "$APPIMAGETOOL_URL"
|
||||||
|
if ! echo "${APPIMAGETOOL_SHA256} ${at}" | sha256sum -c --status; then
|
||||||
|
err "appimagetool SHA-256 verification failed — refusing to use it"
|
||||||
|
rm -f "$at"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
chmod +x "$at"
|
||||||
|
fi
|
||||||
|
APPIMAGETOOL="$at"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local ARCH
|
local ARCH
|
||||||
@@ -628,8 +696,32 @@ HDR
|
|||||||
info "Lite mode: skipping embedded daemon binaries"
|
info "Lite mode: skipping embedded daemon binaries"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── xmrig binary (from prebuilt-binaries/xmrig-hac/) ────────────────
|
# ── Wallet-rebuild recovery helper ───────────────────────────────
|
||||||
local XMRIG_DIR="$SCRIPT_DIR/prebuilt-binaries/xmrig-hac"
|
# Built in-tree (not a prebuilt like the daemon), so compile it standalone HERE — before the
|
||||||
|
# main app compiles embedded_resources.cpp — and INCBIN it, so a bare, self-extracting
|
||||||
|
# ObsidianDragon.exe carries the recovery tool exactly like it does the daemon.
|
||||||
|
if should_bundle_full_node_assets; then
|
||||||
|
local WBDB="$SCRIPT_DIR/external/dragonx/depends/x86_64-w64-mingw32"
|
||||||
|
if [[ -f "$WBDB/lib/libdb-6.2.a" && -f "$WBDB/include/db.h" ]]; then
|
||||||
|
info "Compiling + embedding wallet-rebuild helper ..."
|
||||||
|
x86_64-w64-mingw32-g++ -std=c++17 -O2 -static -static-libgcc -static-libstdc++ \
|
||||||
|
-I"$SCRIPT_DIR/src" -I"$WBDB/include" \
|
||||||
|
"$SCRIPT_DIR/tools/wallet_rebuild/main.cpp" \
|
||||||
|
"$WBDB/lib/libdb-6.2.a" -lws2_32 \
|
||||||
|
-o "$RES/dragonx-wallet-rebuild.exe" \
|
||||||
|
|| { err "wallet-rebuild helper failed to compile for embedding"; exit 1; }
|
||||||
|
x86_64-w64-mingw32-strip "$RES/dragonx-wallet-rebuild.exe" 2>/dev/null || true
|
||||||
|
echo -e "\n#define HAS_EMBEDDED_WALLET_REBUILD 1" >> "$GEN/embedded_data.h"
|
||||||
|
echo "INCBIN(dragonx_wallet_rebuild_exe, \"$RES/dragonx-wallet-rebuild.exe\");" >> "$GEN/embedded_data.h"
|
||||||
|
info " Embedded dragonx-wallet-rebuild.exe ($(du -h "$RES/dragonx-wallet-rebuild.exe" | cut -f1))"
|
||||||
|
else
|
||||||
|
err "Vendored mingw Berkeley DB missing at $WBDB — cannot embed the wallet-rebuild recovery helper."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ── xmrig binary (from prebuilt-binaries/drg-xmrig/) ────────────────
|
||||||
|
local XMRIG_DIR="$SCRIPT_DIR/prebuilt-binaries/drg-xmrig"
|
||||||
# The published DRG-XMRig archives ship the binary inside a versioned subdir, not as a flat
|
# The published DRG-XMRig archives ship the binary inside a versioned subdir, not as a flat
|
||||||
# xmrig.exe. Extract it from the matching win-x64 zip if it isn't already staged — otherwise
|
# xmrig.exe. Extract it from the matching win-x64 zip if it isn't already staged — otherwise
|
||||||
# the embed below never fires (HAS_EMBEDDED_XMRIG stays undefined) and the wallet ships with
|
# the embed below never fires (HAS_EMBEDDED_XMRIG stays undefined) and the wallet ships with
|
||||||
@@ -725,20 +817,56 @@ HDR
|
|||||||
"$SCRIPT_DIR/scripts/fetch-libsodium.sh" --win
|
"$SCRIPT_DIR/scripts/fetch-libsodium.sh" --win
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ── FreeType for Windows (color-emoji rendering) ───────────────────────
|
||||||
|
# The mingw toolchain ships no FreeType; cross-build a minimal static one (COLR/CPAL, no external
|
||||||
|
# deps). Failure is non-fatal — the wallet just falls back to monochrome emoji.
|
||||||
|
local FT_MINGW_PREFIX="$SCRIPT_DIR/third_party/freetype-mingw"
|
||||||
|
if [[ ! -f "$FT_MINGW_PREFIX/lib/libfreetype.a" ]]; then
|
||||||
|
info "Cross-building FreeType for Windows (color emoji) ..."
|
||||||
|
"$SCRIPT_DIR/scripts/build-freetype-mingw.sh" "$FT_MINGW_PREFIX" \
|
||||||
|
|| warn "FreeType cross-build failed — Windows build will use monochrome emoji"
|
||||||
|
fi
|
||||||
|
local FT_CMAKE_ARG=()
|
||||||
|
if [[ -f "$FT_MINGW_PREFIX/lib/libfreetype.a" ]]; then
|
||||||
|
FT_CMAKE_ARG=(-DDRAGONX_MINGW_FREETYPE_PREFIX="$FT_MINGW_PREFIX")
|
||||||
|
fi
|
||||||
|
|
||||||
# ── CMake + build ────────────────────────────────────────────────────────
|
# ── CMake + build ────────────────────────────────────────────────────────
|
||||||
|
# The wallet-rebuild helper links the vendored mingw static Berkeley DB (the mingw toolchain's
|
||||||
|
# find_library is sysroot-only, so pass the depends paths EXPLICITLY to bypass the search). Only
|
||||||
|
# enabled if the depends tree is present; guarded with -DBDB_* left empty otherwise.
|
||||||
|
local win_bdb="$SCRIPT_DIR/external/dragonx/depends/x86_64-w64-mingw32"
|
||||||
|
local BDB_ARGS=()
|
||||||
|
if [[ -f "$win_bdb/lib/libdb-6.2.a" && -f "$win_bdb/include/db.h" ]]; then
|
||||||
|
BDB_ARGS=( -DBDB_INCLUDE_DIR="$win_bdb/include" -DBDB_LIBRARY="$win_bdb/lib/libdb-6.2.a" )
|
||||||
|
elif should_bundle_full_node_assets; then
|
||||||
|
err "Vendored Berkeley DB depends missing at $win_bdb — the wallet-rebuild recovery helper cannot be built."
|
||||||
|
err " A full-node release must ship it; aborting rather than degrading recovery to Restore-only."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
info "Configuring (cross-compile) ..."
|
info "Configuring (cross-compile) ..."
|
||||||
cmake "$SCRIPT_DIR" \
|
cmake "$SCRIPT_DIR" \
|
||||||
-DCMAKE_TOOLCHAIN_FILE="$bd/mingw-toolchain.cmake" \
|
-DCMAKE_TOOLCHAIN_FILE="$bd/mingw-toolchain.cmake" \
|
||||||
-DCMAKE_BUILD_TYPE=Release \
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
-DDRAGONX_USE_SYSTEM_SDL3=OFF \
|
-DDRAGONX_USE_SYSTEM_SDL3=OFF \
|
||||||
|
"${BDB_ARGS[@]}" \
|
||||||
|
"${FT_CMAKE_ARG[@]}" \
|
||||||
"${CMAKE_LITE_ARGS[@]}"
|
"${CMAKE_LITE_ARGS[@]}"
|
||||||
|
|
||||||
info "Building with $JOBS jobs ..."
|
info "Building with $JOBS jobs ..."
|
||||||
cmake --build . -j "$JOBS"
|
cmake --build . -j "$JOBS"
|
||||||
|
|
||||||
[[ -f "bin/${APP_BASENAME}.exe" ]] || { err "Windows build failed"; exit 1; }
|
[[ -f "bin/${APP_BASENAME}.exe" ]] || { err "Windows build failed"; exit 1; }
|
||||||
|
# Strip the app exe — the Linux and macOS release paths already strip theirs, and even the Windows
|
||||||
|
# helper (dragonx-wallet-rebuild.exe) is stripped, but the main app exe was shipping unstripped
|
||||||
|
# (~5MB of symbols on the full node, ~19MB on the params-heavy lite build). Best-effort.
|
||||||
|
x86_64-w64-mingw32-strip --strip-all "bin/${APP_BASENAME}.exe" 2>/dev/null \
|
||||||
|
|| warn " strip unavailable — shipping unstripped ${APP_BASENAME}.exe"
|
||||||
info "Binary: $(du -h "bin/${APP_BASENAME}.exe" | cut -f1)"
|
info "Binary: $(du -h "bin/${APP_BASENAME}.exe" | cut -f1)"
|
||||||
|
|
||||||
|
# A full-node release MUST include the recovery helper — fail loudly, never ship without it.
|
||||||
|
require_wallet_rebuild_helper "bin/dragonx-wallet-rebuild.exe" "$win_bdb"
|
||||||
|
|
||||||
# ── Package: release/windows/ ────────────────────────────────────────────
|
# ── Package: release/windows/ ────────────────────────────────────────────
|
||||||
# Remove only THIS variant's prior artifacts so full-node and lite releases coexist here.
|
# Remove only THIS variant's prior artifacts so full-node and lite releases coexist here.
|
||||||
mkdir -p "$out"
|
mkdir -p "$out"
|
||||||
@@ -754,6 +882,9 @@ HDR
|
|||||||
for f in dragonxd.exe dragonx-cli.exe dragonx-tx.exe; do
|
for f in dragonxd.exe dragonx-cli.exe dragonx-tx.exe; do
|
||||||
[[ -f "$DD/$f" ]] && cp "$DD/$f" "$dist_dir/"
|
[[ -f "$DD/$f" ]] && cp "$DD/$f" "$dist_dir/"
|
||||||
done
|
done
|
||||||
|
# dragonx-wallet-rebuild helper (offline recovery for a BDB-inconsistent wallet.dat) — required.
|
||||||
|
cp "bin/dragonx-wallet-rebuild.exe" "$dist_dir/" && info " Bundled dragonx-wallet-rebuild.exe"
|
||||||
|
[[ -f "$dist_dir/dragonx-wallet-rebuild.exe" ]] || { err "Failed to bundle dragonx-wallet-rebuild.exe"; exit 1; }
|
||||||
|
|
||||||
# Bundle Sapling params + asmap for the zip distribution
|
# Bundle Sapling params + asmap for the zip distribution
|
||||||
# (The single-file exe has these embedded via INCBIN, but the zip
|
# (The single-file exe has these embedded via INCBIN, but the zip
|
||||||
@@ -766,7 +897,7 @@ HDR
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Bundle xmrig for mining support
|
# Bundle xmrig for mining support
|
||||||
local XMRIG_WIN="$SCRIPT_DIR/prebuilt-binaries/xmrig-hac/xmrig.exe"
|
local XMRIG_WIN="$SCRIPT_DIR/prebuilt-binaries/drg-xmrig/xmrig.exe"
|
||||||
[[ -f "$XMRIG_WIN" ]] && { cp "$XMRIG_WIN" "$dist_dir/"; info "Bundled xmrig.exe"; } || warn "xmrig.exe not found — mining unavailable in zip"
|
[[ -f "$XMRIG_WIN" ]] && { cp "$XMRIG_WIN" "$dist_dir/"; info "Bundled xmrig.exe"; } || warn "xmrig.exe not found — mining unavailable in zip"
|
||||||
|
|
||||||
cp -r bin/res "$dist_dir/" 2>/dev/null || true
|
cp -r bin/res "$dist_dir/" 2>/dev/null || true
|
||||||
@@ -876,8 +1007,26 @@ build_release_mac() {
|
|||||||
fi
|
fi
|
||||||
info "macOS cross-compiler: $OSXCROSS_CXX (arch: $MAC_ARCH)"
|
info "macOS cross-compiler: $OSXCROSS_CXX (arch: $MAC_ARCH)"
|
||||||
else
|
else
|
||||||
# Native macOS: build universal binary (arm64 + x86_64)
|
# Native macOS: build universal (arm64 + x86_64) by default. Override with
|
||||||
|
# DRAGONX_MAC_ARCHS (e.g. "x86_64").
|
||||||
|
MAC_ARCHS="${DRAGONX_MAC_ARCHS:-arm64;x86_64}"
|
||||||
|
# When linking the real lite backend, the app can only include architectures
|
||||||
|
# the backend static library actually provides. Its pinned ring 0.16.11 has no
|
||||||
|
# Apple-Silicon assembly, so that artifact is x86_64-only — constrain the app
|
||||||
|
# arch to the backend's (unless the user explicitly forced DRAGONX_MAC_ARCHS),
|
||||||
|
# otherwise the arm64 slice fails to link.
|
||||||
|
if $DO_LITE_BACKEND && [[ -z "${DRAGONX_MAC_ARCHS:-}" && -n "${lb_lib:-}" ]] && command -v lipo &>/dev/null; then
|
||||||
|
local _backend_archs; _backend_archs=$(lipo -archs "$lb_lib" 2>/dev/null | tr ' ' ';')
|
||||||
|
if [[ -n "$_backend_archs" && "$_backend_archs" != "$MAC_ARCHS" ]]; then
|
||||||
|
warn "Lite backend provides only [$_backend_archs] — building the app for that instead of universal."
|
||||||
|
MAC_ARCHS="$_backend_archs"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ "$MAC_ARCHS" == *";"* || "$MAC_ARCHS" == *","* ]]; then
|
||||||
MAC_ARCH="universal"
|
MAC_ARCH="universal"
|
||||||
|
else
|
||||||
|
MAC_ARCH="$MAC_ARCHS"
|
||||||
|
fi
|
||||||
export MACOSX_DEPLOYMENT_TARGET="11.0"
|
export MACOSX_DEPLOYMENT_TARGET="11.0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -949,6 +1098,12 @@ TOOLCHAIN
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
info "Configuring (cross-compile via osxcross) ..."
|
info "Configuring (cross-compile via osxcross) ..."
|
||||||
|
# Vendored static libdb for the recovery helper (full-node only), by target arch; see mac_bdb_dir.
|
||||||
|
local mac_bdb; mac_bdb="$(mac_bdb_dir "$MAC_ARCH")"
|
||||||
|
local BDB_ARGS=()
|
||||||
|
if should_bundle_full_node_assets && [[ -f "$mac_bdb/lib/libdb-6.2.a" && -f "$mac_bdb/include/db.h" ]]; then
|
||||||
|
BDB_ARGS=( -DBDB_INCLUDE_DIR="$mac_bdb/include" -DBDB_LIBRARY="$mac_bdb/lib/libdb-6.2.a" )
|
||||||
|
fi
|
||||||
cmake "$SCRIPT_DIR" \
|
cmake "$SCRIPT_DIR" \
|
||||||
-DCMAKE_TOOLCHAIN_FILE="$bd/osxcross-toolchain.cmake" \
|
-DCMAKE_TOOLCHAIN_FILE="$bd/osxcross-toolchain.cmake" \
|
||||||
-DCMAKE_BUILD_TYPE=Release \
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
@@ -956,6 +1111,7 @@ TOOLCHAIN
|
|||||||
-DDRAGONX_USE_SYSTEM_SDL3=OFF \
|
-DDRAGONX_USE_SYSTEM_SDL3=OFF \
|
||||||
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
|
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
|
||||||
${COMPILER_RT:+-DOSXCROSS_COMPILER_RT="$COMPILER_RT"} \
|
${COMPILER_RT:+-DOSXCROSS_COMPILER_RT="$COMPILER_RT"} \
|
||||||
|
"${BDB_ARGS[@]}" \
|
||||||
"${CMAKE_LITE_ARGS[@]}"
|
"${CMAKE_LITE_ARGS[@]}"
|
||||||
else
|
else
|
||||||
# Build libsodium as universal if needed
|
# Build libsodium as universal if needed
|
||||||
@@ -965,7 +1121,7 @@ TOOLCHAIN
|
|||||||
need_sodium=true
|
need_sodium=true
|
||||||
elif [[ -f "$SCRIPT_DIR/libs/libsodium/lib/libsodium.a" ]]; then
|
elif [[ -f "$SCRIPT_DIR/libs/libsodium/lib/libsodium.a" ]]; then
|
||||||
# Rebuild if existing lib is not universal (single-arch won't link)
|
# Rebuild if existing lib is not universal (single-arch won't link)
|
||||||
if ! lipo -info "$SCRIPT_DIR/libs/libsodium/lib/libsodium.a" 2>/dev/null | grep -q "arm64.*x86_64\|x86_64.*arm64"; then
|
if ! lipo -info "$SCRIPT_DIR/libs/libsodium/lib/libsodium.a" 2>/dev/null | grep -Eq "arm64.*x86_64|x86_64.*arm64"; then
|
||||||
info "Existing libsodium is not universal — rebuilding ..."
|
info "Existing libsodium is not universal — rebuilding ..."
|
||||||
rm -rf "$SCRIPT_DIR/libs/libsodium"
|
rm -rf "$SCRIPT_DIR/libs/libsodium"
|
||||||
need_sodium=true
|
need_sodium=true
|
||||||
@@ -976,13 +1132,20 @@ TOOLCHAIN
|
|||||||
"$SCRIPT_DIR/scripts/fetch-libsodium.sh"
|
"$SCRIPT_DIR/scripts/fetch-libsodium.sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Configuring (native universal arm64+x86_64) ..."
|
info "Configuring (native macOS, arch: $MAC_ARCHS) ..."
|
||||||
|
# Point CMake at the vendored static libdb for the recovery helper (full-node only); see mac_bdb_dir.
|
||||||
|
local mac_bdb; mac_bdb="$(mac_bdb_dir "$MAC_ARCH")"
|
||||||
|
local BDB_ARGS=()
|
||||||
|
if should_bundle_full_node_assets && [[ -f "$mac_bdb/lib/libdb-6.2.a" && -f "$mac_bdb/include/db.h" ]]; then
|
||||||
|
BDB_ARGS=( -DBDB_INCLUDE_DIR="$mac_bdb/include" -DBDB_LIBRARY="$mac_bdb/lib/libdb-6.2.a" )
|
||||||
|
fi
|
||||||
cmake "$SCRIPT_DIR" \
|
cmake "$SCRIPT_DIR" \
|
||||||
-DCMAKE_BUILD_TYPE=Release \
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG" \
|
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG" \
|
||||||
-DDRAGONX_USE_SYSTEM_SDL3=OFF \
|
-DDRAGONX_USE_SYSTEM_SDL3=OFF \
|
||||||
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
|
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
|
||||||
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
|
-DCMAKE_OSX_ARCHITECTURES="$MAC_ARCHS" \
|
||||||
|
"${BDB_ARGS[@]}" \
|
||||||
"${CMAKE_LITE_ARGS[@]}"
|
"${CMAKE_LITE_ARGS[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -991,6 +1154,11 @@ TOOLCHAIN
|
|||||||
|
|
||||||
[[ -f "bin/${APP_BASENAME}" ]] || { err "macOS build failed"; exit 1; }
|
[[ -f "bin/${APP_BASENAME}" ]] || { err "macOS build failed"; exit 1; }
|
||||||
|
|
||||||
|
# A full-node release MUST include the recovery helper. macOS needs a static libdb-6.2 (Homebrew
|
||||||
|
# berkeley-db for a native build, or a vendored external/dragonx/depends/<triple>) — otherwise CMake
|
||||||
|
# skips the target and this fails loudly rather than shipping a mac release with no recovery option.
|
||||||
|
require_wallet_rebuild_helper "bin/dragonx-wallet-rebuild" "$(mac_bdb_dir "$MAC_ARCH")"
|
||||||
|
|
||||||
# Strip — use osxcross strip for cross-builds
|
# Strip — use osxcross strip for cross-builds
|
||||||
if $IS_CROSS; then
|
if $IS_CROSS; then
|
||||||
local STRIP_CMD="${OSXCROSS}/target/bin/${OSXCROSS_TRIPLE}-strip"
|
local STRIP_CMD="${OSXCROSS}/target/bin/${OSXCROSS_TRIPLE}-strip"
|
||||||
@@ -1012,8 +1180,12 @@ TOOLCHAIN
|
|||||||
info "Binary: $(du -h "bin/${APP_BASENAME}" | cut -f1)"
|
info "Binary: $(du -h "bin/${APP_BASENAME}" | cut -f1)"
|
||||||
|
|
||||||
# ── Create .app bundle ───────────────────────────────────────────────────
|
# ── Create .app bundle ───────────────────────────────────────────────────
|
||||||
rm -rf "$out"
|
|
||||||
mkdir -p "$out"
|
mkdir -p "$out"
|
||||||
|
# Clean only THIS variant's prior artifacts so full-node and lite releases can
|
||||||
|
# coexist in release/mac/ (Linux/Windows scope their cleanup the same way). The
|
||||||
|
# "ObsidianDragon-" glob never matches "ObsidianDragonLite-" (and vice versa),
|
||||||
|
# and the ".app" names are exact.
|
||||||
|
rm -rf "$out/${APP_BASENAME}.app" "$out/${APP_BASENAME}-"*.app.zip "$out/${APP_BASENAME}-"*.dmg
|
||||||
|
|
||||||
local APP="$out/${APP_BASENAME}.app"
|
local APP="$out/${APP_BASENAME}.app"
|
||||||
local CONTENTS="$APP/Contents"
|
local CONTENTS="$APP/Contents"
|
||||||
@@ -1059,12 +1231,14 @@ TOOLCHAIN
|
|||||||
else
|
else
|
||||||
warn "prebuilt-binaries/dragonxd-mac/ not found — place macOS daemon binaries there for bundling"
|
warn "prebuilt-binaries/dragonxd-mac/ not found — place macOS daemon binaries there for bundling"
|
||||||
fi
|
fi
|
||||||
|
# Offline wallet-rebuild recovery helper — required (asserted after build); next to the daemon.
|
||||||
|
cp "bin/dragonx-wallet-rebuild" "$MACOS/" && chmod +x "$MACOS/dragonx-wallet-rebuild" && info " Bundled dragonx-wallet-rebuild"
|
||||||
else
|
else
|
||||||
info "Lite mode: skipping macOS daemon and Sapling/asmap bundling"
|
info "Lite mode: skipping macOS daemon and Sapling/asmap bundling"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# xmrig binary (from prebuilt-binaries/xmrig-hac/)
|
# xmrig binary (from prebuilt-binaries/drg-xmrig/)
|
||||||
local XMRIG_MAC="$SCRIPT_DIR/prebuilt-binaries/xmrig-hac/xmrig"
|
local XMRIG_MAC="$SCRIPT_DIR/prebuilt-binaries/drg-xmrig/xmrig"
|
||||||
if [[ -f "$XMRIG_MAC" ]]; then
|
if [[ -f "$XMRIG_MAC" ]]; then
|
||||||
cp "$XMRIG_MAC" "$MACOS/xmrig"
|
cp "$XMRIG_MAC" "$MACOS/xmrig"
|
||||||
chmod +x "$MACOS/xmrig"
|
chmod +x "$MACOS/xmrig"
|
||||||
@@ -1213,8 +1387,10 @@ PLIST
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# ── Create DMG ───────────────────────────────────────────────────────────
|
# ── Create DMG ───────────────────────────────────────────────────────────
|
||||||
local DMG_BASENAME="DragonX_Wallet"
|
# DMG filename matches the app bundle name (ObsidianDragon / ObsidianDragonLite).
|
||||||
$DO_LITE && DMG_BASENAME="DragonX_Wallet_Lite"
|
# The mounted volume + CFBundleName keep the "DragonX Wallet" display branding
|
||||||
|
# (APP_DISPLAY_NAME above).
|
||||||
|
local DMG_BASENAME="${APP_BASENAME}"
|
||||||
local DMG_NAME="${DMG_BASENAME}-${VERSION}-macOS-${MAC_ARCH}.dmg"
|
local DMG_NAME="${DMG_BASENAME}-${VERSION}-macOS-${MAC_ARCH}.dmg"
|
||||||
|
|
||||||
if command -v create-dmg &>/dev/null; then
|
if command -v create-dmg &>/dev/null; then
|
||||||
@@ -1296,3 +1472,9 @@ if $DO_LINUX || $DO_WIN || $DO_MAC; then
|
|||||||
[[ -d "$SCRIPT_DIR/release/windows" ]] && echo -e " ${CYAN}windows/${NC} — .exe + .zip"
|
[[ -d "$SCRIPT_DIR/release/windows" ]] && echo -e " ${CYAN}windows/${NC} — .exe + .zip"
|
||||||
[[ -d "$SCRIPT_DIR/release/mac" ]] && echo -e " ${CYAN}mac/${NC} — .app + .dmg"
|
[[ -d "$SCRIPT_DIR/release/mac" ]] && echo -e " ${CYAN}mac/${NC} — .app + .dmg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Reaching here means the build completed (real failures exit 1 at their point of failure).
|
||||||
|
# Exit 0 explicitly: the final `[[ -d release/mac ]] && echo` above returns non-zero on a
|
||||||
|
# non-mac build — and since set -e exempts the left side of an &&, that status would otherwise
|
||||||
|
# become the script's exit code and make a successful build report failure (e.g. to CI).
|
||||||
|
exit 0
|
||||||
|
|||||||
31
cmake/patch-libwebp-simd.cmake
Normal file
31
cmake/patch-libwebp-simd.cmake
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# patch-libwebp-simd.cmake — portable, idempotent FetchContent patch for libwebp.
|
||||||
|
#
|
||||||
|
# libwebp's cmake/cpu.cmake compiles its scalar *reference* DSP files with the
|
||||||
|
# SSE-disable flags "-mno-sse4.1;-mno-sse2" whenever it can't positively detect
|
||||||
|
# SSE support. Under a macOS *universal* build (-arch arm64;x86_64) the per-arch
|
||||||
|
# SSE flag probe fails (a flag valid for x86_64 is invalid for arm64), so those
|
||||||
|
# disable flags get applied to the x86_64 slice. clang gates the _Float16 type on
|
||||||
|
# SSE2 for x86_64, and the macOS 15+/26 SDK's <math.h> declares _Float16 math
|
||||||
|
# functions unconditionally — so any TU including <math.h> fails to compile with
|
||||||
|
# "_Float16 is not supported on this target".
|
||||||
|
#
|
||||||
|
# SSE2 is part of the x86_64 baseline ABI, so disabling it on the reference files
|
||||||
|
# is unnecessary on every platform we target. Blanking the SSE entries (indices
|
||||||
|
# must stay aligned with WEBP_SIMD_FLAGS) fixes the universal build and is a no-op
|
||||||
|
# for single-arch Linux/Windows/x86_64 builds. Idempotent: re-running is a no-op.
|
||||||
|
if(NOT DEFINED CPU_CMAKE OR NOT EXISTS "${CPU_CMAKE}")
|
||||||
|
message(FATAL_ERROR "patch-libwebp-simd: cpu.cmake not found at '${CPU_CMAKE}'")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
file(READ "${CPU_CMAKE}" _contents)
|
||||||
|
string(REPLACE
|
||||||
|
"set(SIMD_DISABLE_FLAGS \"-mno-sse4.1;-mno-sse2;;-mno-dspr2;;-mno-msa\")"
|
||||||
|
"set(SIMD_DISABLE_FLAGS \";;;-mno-dspr2;;-mno-msa\")"
|
||||||
|
_patched "${_contents}")
|
||||||
|
|
||||||
|
if(_patched STREQUAL _contents)
|
||||||
|
message(STATUS "patch-libwebp-simd: no change (already patched or pattern absent)")
|
||||||
|
else()
|
||||||
|
file(WRITE "${CPU_CMAKE}" "${_patched}")
|
||||||
|
message(STATUS "patch-libwebp-simd: neutralized x86 SSE-disable flags in cpu.cmake")
|
||||||
|
endif()
|
||||||
549
docs/daemon-startup-hardening.md
Normal file
549
docs/daemon-startup-hardening.md
Normal file
@@ -0,0 +1,549 @@
|
|||||||
|
# Daemon Startup Hardening — Implementation Plan
|
||||||
|
|
||||||
|
Eight verified edge-case defects in how ObsidianDragon brings up (and watches) the
|
||||||
|
`dragonxd` daemon at launch. Each entry is a buildable fix: the defect (with exact
|
||||||
|
line references), the chosen approach, the call sites, a representative change, and how
|
||||||
|
to verify it.
|
||||||
|
|
||||||
|
- **Scope:** full-node startup path (`--lite` excludes the embedded daemon entirely).
|
||||||
|
- **Source:** line references are exact against branch `dev` @ `45b652f`.
|
||||||
|
- **Provenance:** findings verified by direct source read; each fix designed by an
|
||||||
|
independent agent grounded in the cited files, with a sequencing pass for ordering,
|
||||||
|
shared helpers, and merge conflicts.
|
||||||
|
|
||||||
|
**Severity:** 2 High, 6 Medium · **Effort:** ≈ 25–35 engineering-hours · **7 landing steps.**
|
||||||
|
|
||||||
|
Status legend: ☐ not started · ◐ in progress · ☑ landed & verified
|
||||||
|
|
||||||
|
**Status: all 8 landed & verified** (build-clean, `ctest` green after each) across four commits on
|
||||||
|
`dev` — lifecycle cluster (F1/F2/F4), filesystem+params cluster (F7/F6/F5), F3, and F8. Six new
|
||||||
|
pure-helper unit tests added.
|
||||||
|
|
||||||
|
**Wrap-up done:** release notes added (`CHANGELOG.md`, F8 breaking change front and center); i18n
|
||||||
|
back-fill applied additively to `res/lang/*.json` (42 keys — all 6 for es/de/fr/pt/ru; 6 zh/ja/ko
|
||||||
|
entries whose glyphs aren't in the current `NotoSansCJK-Subset.ttf` were left on English fallback
|
||||||
|
rather than render as tofu).
|
||||||
|
|
||||||
|
**Still owed before release:** a **CJK subset-font rebuild** (`scripts/build_cjk_subset.py`, needs
|
||||||
|
the Noto CJK source font) to cover the 6 deferred zh/ja/ko strings. *(F1 and F2 now have headless
|
||||||
|
integration-test coverage — see the progress log — so their GUI repros are optional, not blocking.)*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Recommended rollout sequence
|
||||||
|
|
||||||
|
A real dependency order, not a checklist. The daemon-lifecycle cluster lands first
|
||||||
|
because it makes the `State::Error` / `crash_count_` contract trustworthy — which the
|
||||||
|
connect-stall panel and the lock gate both build on. The filesystem cluster lands
|
||||||
|
around a single shared helper. The connectivity-breaking security flip lands last.
|
||||||
|
|
||||||
|
| Step | Finding(s) | Site | Why here | Status |
|
||||||
|
|------|-----------|------|----------|--------|
|
||||||
|
| 1 | **F1** | `embedded_daemon.cpp` · `isRunning()` | Smallest/highest-severity; establishes the reliable Error/crash-count transition steps 3 & 6 depend on. | ☑ |
|
||||||
|
| 2 | **F2** | `embedded_daemon.cpp` · `startProcess()` | Same file family, different function; test the F1+F2 pair together with `kill -SEGV` / bad-binary repros. | ☑ |
|
||||||
|
| 3 | **F4** | `embedded_daemon.cpp` · `start()` | After F1/F2 so crash-count semantics are settled; its bail deliberately stays out of the crash path. | ☑ |
|
||||||
|
| 4 | **F7** | `util/platform` · `connection.cpp` | Structural owner of the fs-error idiom + `ConnectionConfig` that F5/F6/F8 reuse. | ☑ |
|
||||||
|
| 5 | **F6 + F5** | `app.cpp` · `verifySaplingParams()` | Same `startEmbeddedDaemon` / `verifySaplingParams` block; land together. | ☑ |
|
||||||
|
| 6 | **F3** | `app.cpp` · `renderLoadingOverlay()` | After F1 — panel is guarded off during `State::Error` (owned by the crash-count hint). | ☑ |
|
||||||
|
| 7 | **F8** | `connection.cpp` · `tryConnect()` | Largest; only connectivity-breaking default flip — land last, with release notes. | ☑ |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## F1 — Double-`waitpid` race can swallow a daemon crash
|
||||||
|
|
||||||
|
**Severity:** High · **Effort:** S (~1–2h) · **Status:** ☑ landed & verified
|
||||||
|
|
||||||
|
### The defect
|
||||||
|
`EmbeddedDaemon::isRunning()` (`embedded_daemon.cpp:1136`, POSIX branch) calls
|
||||||
|
`waitpid(WNOHANG)` — from the **UI thread, nearly every frame** — racing
|
||||||
|
`monitorProcess()`'s own reap at `:1244`. `waitpid` is one-shot: if the UI thread wins,
|
||||||
|
the monitor never decodes the exit, so `crash_count_` never increments, `State::Error`
|
||||||
|
never fires, and the 3-strike auto-restart cap (`app_network.cpp:479`) is defeated. The
|
||||||
|
sibling `XmrigManager::isRunning()` (`xmrig_manager.cpp:512`) already fixed exactly this
|
||||||
|
with an atomic read.
|
||||||
|
|
||||||
|
### The fix
|
||||||
|
Make `isRunning()` read the existing `std::atomic<State> state_` (member at
|
||||||
|
`embedded_daemon.h:253`) instead of calling `waitpid`, leaving `monitorProcess()` as the
|
||||||
|
sole reaper. Predicate is `Running || Stopping` — `Stopping` must stay "alive" because
|
||||||
|
`stop()`'s graceful/SIGTERM wait loops poll `isRunning()` before the process has exited.
|
||||||
|
|
||||||
|
### Files touched
|
||||||
|
- `src/daemon/embedded_daemon.cpp` — `isRunning()`, POSIX branch (~1136)
|
||||||
|
|
||||||
|
### Core change
|
||||||
|
```cpp
|
||||||
|
bool EmbeddedDaemon::isRunning() const // POSIX branch
|
||||||
|
{
|
||||||
|
// Read the atomic state_ instead of waitpid() — monitorProcess() is the
|
||||||
|
// sole reaper. Previously both threads reaped; if the UI thread won, the
|
||||||
|
// monitor never saw the exit (crash_count_ / exit code / Error all lost).
|
||||||
|
if (process_pid_ <= 0) return false;
|
||||||
|
|
||||||
|
State s = state_.load(std::memory_order_relaxed);
|
||||||
|
// Stopping stays "alive": stop()'s wait loops poll isRunning() while
|
||||||
|
// state_ == Stopping, before the process has actually terminated.
|
||||||
|
return (s == State::Running || s == State::Stopping);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verification
|
||||||
|
- Manual: `kill -SEGV` the daemon 10–20×; the monitor must report the exit and increment `crash_count_` every time (previously intermittent).
|
||||||
|
- Regression: a normal Settings-driven stop still escalates SIGTERM→SIGKILL (the `Stopping` predicate).
|
||||||
|
- Not unit-testable (real fork/exec/waitpid) — consistent with the no-process-spawn harness.
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
Mirrors `XmrigManager::isRunning()`. Flags a separate latent hazard (out of scope):
|
||||||
|
`stop()`'s final blocking `waitpid` (`:1220`) can still race a mid-sleep monitor
|
||||||
|
iteration — file as its own ticket.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## F2 — exec-after-fork silent failure: "Running" for a daemon that never started
|
||||||
|
|
||||||
|
**Severity:** High · **Effort:** S (~2–3h) · **Status:** ☑ landed & verified
|
||||||
|
|
||||||
|
### The defect
|
||||||
|
In `startProcess()` (`embedded_daemon.cpp:957–1061`, POSIX) the parent runs
|
||||||
|
`process_pid_ = pid; return true;` **unconditionally** after `fork()` — with no
|
||||||
|
exec-status handshake. On a non-executable / wrong-arch / corrupt binary the child's
|
||||||
|
`execv` fails and it `_exit(127)`s, but `start()` has already set `State::Running`
|
||||||
|
(`:565`). The real cause never reaches `last_error_`; it surfaces later, generically,
|
||||||
|
as "exited unexpectedly (exit code 127)".
|
||||||
|
|
||||||
|
### The fix
|
||||||
|
Add a **close-on-exec self-pipe** handshake — `pipe() + fcntl(FD_CLOEXEC)`, deliberately
|
||||||
|
**not** `pipe2()` (macOS lacks it; the POSIX branch is shared). The child writes `errno`
|
||||||
|
only on `execv` failure; a successful exec closes the write end for free. Parent reads:
|
||||||
|
EOF ⇒ success; 4 bytes ⇒ reap the zombie, set a precise `last_error_` ("not executable
|
||||||
|
or wrong architecture"), and return `false` so `start()` never reports Running. EINTR-safe
|
||||||
|
on both ends. Also comments the unchecked parent-side `setpgid` at `:1053`.
|
||||||
|
|
||||||
|
### Files touched
|
||||||
|
- `src/daemon/embedded_daemon.cpp` — `startProcess()` parent read path
|
||||||
|
- `src/daemon/embedded_daemon.cpp` — child `execv`-failure write (~1043)
|
||||||
|
- `src/daemon/embedded_daemon.cpp` — `setpgid` best-effort comment (~1053)
|
||||||
|
|
||||||
|
### Core change
|
||||||
|
```cpp
|
||||||
|
// Self-pipe exec handshake (pipe()+FD_CLOEXEC; NOT pipe2 — macOS lacks it).
|
||||||
|
int execpipe[2]; pipe(execpipe);
|
||||||
|
fcntl(execpipe[0], F_SETFD, FD_CLOEXEC);
|
||||||
|
fcntl(execpipe[1], F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
|
pid_t pid = fork();
|
||||||
|
if (pid == 0) { // child
|
||||||
|
close(execpipe[0]);
|
||||||
|
/* setpgid / chdir / dup2 / argv … */
|
||||||
|
execv(binary_path.c_str(), argv.data());
|
||||||
|
int e = errno; // execv failed
|
||||||
|
while (write(execpipe[1], &e, sizeof e) < 0 && errno == EINTR) {}
|
||||||
|
_exit(127);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(execpipe[1]); // parent: must close or read() never EOFs
|
||||||
|
int child_errno = 0, total = 0;
|
||||||
|
for (;;) { // EOF ⇒ exec ok; 4 bytes ⇒ exec failed
|
||||||
|
ssize_t n = read(execpipe[0], (char*)&child_errno + total, sizeof(int) - total);
|
||||||
|
if (n == 0) break;
|
||||||
|
if (n < 0) { if (errno == EINTR) continue; break; }
|
||||||
|
if ((total += n) >= (int)sizeof(int)) break;
|
||||||
|
}
|
||||||
|
close(execpipe[0]);
|
||||||
|
if (total >= (int)sizeof(int)) { // exec never happened
|
||||||
|
waitpid(pid, nullptr, 0); // reap the zombie
|
||||||
|
last_error_ = "dragonxd could not be executed: " +
|
||||||
|
std::string(strerror(child_errno)) +
|
||||||
|
" — not executable or wrong architecture";
|
||||||
|
return false; // start() no longer reports Running
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verification
|
||||||
|
- Point at a `chmod -x` / wrong-arch file → `start()` returns false immediately, precise message, no leftover zombie.
|
||||||
|
- Success path: real binary still starts with no perceptible added latency.
|
||||||
|
- Optional pure `formatExecFailureError(errno)` helper for a `test_phase4.cpp` unit test.
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
F1 (same function family; sequence F1→F2). **Highest-risk mistake:** forgetting
|
||||||
|
`FD_CLOEXEC` makes every successful start hang the parent read forever.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## F4 — Stale datadir-lock start → restart storm that wedges the UI
|
||||||
|
|
||||||
|
**Severity:** Medium · **Effort:** S (~3–5h) · **Status:** ☑ landed & verified
|
||||||
|
|
||||||
|
### The defect
|
||||||
|
`start()` (`embedded_daemon.cpp:466`) gates only on the RPC port (`:482`), never on
|
||||||
|
`isDaemonProcessRunning()` (`:1292`). A graceful shutdown frees the port but keeps the
|
||||||
|
datadir `.lock` for up to ~90s. A rapid stop→start spawns a daemon that dies "Cannot
|
||||||
|
obtain a lock on data directory" — routed to the generic crash path. With a ~4s retry
|
||||||
|
cadence, **three lock races in ~12s exhaust the 3-strike budget** and wedge the UI long
|
||||||
|
before the lock actually clears.
|
||||||
|
|
||||||
|
### The fix
|
||||||
|
Fail-fast with a **short bounded local wait (~300ms), not a 90s block**. After the port
|
||||||
|
bail, consult `isDaemonProcessRunning()` — gated by `!skip_port_check_` and exempt when
|
||||||
|
`override_datadir_` is set, so the isolated migrate-to-seed daemon still works. A pure
|
||||||
|
`evaluateDatadirLockGate()` returns a **distinct non-crash Error** that never increments
|
||||||
|
`crash_count_`. The connect loop's own retry then absorbs the transient.
|
||||||
|
|
||||||
|
### Files touched
|
||||||
|
- `src/daemon/embedded_daemon.h` — decision struct, helper decl, poll constants
|
||||||
|
- `src/daemon/embedded_daemon.cpp` — `start()` gate + `evaluateDatadirLockGate()`
|
||||||
|
|
||||||
|
### Core change
|
||||||
|
```cpp
|
||||||
|
static StartLockGateDecision evaluateDatadirLockGate(
|
||||||
|
bool skipPortCheck, bool isolatedOverride, bool stillRunningAfterWait) {
|
||||||
|
if (skipPortCheck || isolatedOverride) return {true, ""}; // migrate-to-seed exempt
|
||||||
|
if (!stillRunningAfterWait) return {true, ""};
|
||||||
|
return {false, "A previous dragonxd is still shutting down and holding the "
|
||||||
|
"data directory lock. Retrying shortly…"};
|
||||||
|
}
|
||||||
|
|
||||||
|
// start() — after the isPortInUse() bail, before setState(Starting):
|
||||||
|
if (!skip_port_check_ && override_datadir_.empty()) {
|
||||||
|
bool stillLocked = false; // ~300ms bounded wait, NOT ~90s
|
||||||
|
for (int i = 0; i < kDatadirLockWaitMaxPolls; ++i) {
|
||||||
|
if (!isDaemonProcessRunning()) { stillLocked = false; break; }
|
||||||
|
stillLocked = true;
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(kDatadirLockWaitPollMs));
|
||||||
|
}
|
||||||
|
auto gate = evaluateDatadirLockGate(false, false, stillLocked);
|
||||||
|
if (!gate.proceed) { setState(State::Error, gate.errorMessage); return false; }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verification
|
||||||
|
- Unit: `evaluateDatadirLockGate()` across the skip / isolated / still-running matrix.
|
||||||
|
- Manual: rapid restart into a lingering lock → distinct message, no crash-cap wedge.
|
||||||
|
- Migrate-to-seed second daemon still starts (isolated exemption).
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
F1/F2 (must not touch `crash_count_`; wording must not collide with the monitor's
|
||||||
|
"exited unexpectedly"). Same TU, different function.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## F5 — Extraction / copy write-failures never surfaced up front
|
||||||
|
|
||||||
|
**Severity:** Medium · **Effort:** S (~2–3h) · **Status:** ☑ landed & verified
|
||||||
|
|
||||||
|
### The defect
|
||||||
|
`startEmbeddedDaemon()` discards `extractEmbeddedResources()`'s `bool` return
|
||||||
|
(`app.cpp:4152`) and the second copy-fallback loop drops `copy_file`'s `error_code`
|
||||||
|
entirely (`:4236`). Only Sapling params **existence** is re-checked — never the daemon
|
||||||
|
binary/CLI/tx/asmap. A disk-full or truncated `dragonxd` write falls straight through to
|
||||||
|
spawn and fails opaquely. The innermost write already returns `false`
|
||||||
|
(`embedded_resources.cpp:307`) — the signal is simply thrown away.
|
||||||
|
|
||||||
|
### The fix
|
||||||
|
Minimal, surgical wiring — no new abstraction. Capture the extraction return and, on
|
||||||
|
failure, set `daemon_status_ = TR("sb_daemon_extract_failed")` and `return false` before
|
||||||
|
spawning. In the second copy loop, check `ec` after each `copy_file`, track `copyFailed`,
|
||||||
|
and abort with a dir-parameterized `sb_daemon_files_failed`. An **absent source** stays
|
||||||
|
fine (optional files); only an actual `error_code` counts. Written so F6/F7 slot in later
|
||||||
|
without re-touching this control flow.
|
||||||
|
|
||||||
|
### Files touched
|
||||||
|
- `src/app.cpp` — `startEmbeddedDaemon()` extraction check (~4152)
|
||||||
|
- `src/app.cpp` — second copy-fallback loop (~4210–4242)
|
||||||
|
- `src/util/i18n.cpp` + `res/lang/*.json` — 2 additive keys
|
||||||
|
|
||||||
|
### Core change
|
||||||
|
```cpp
|
||||||
|
// stop discarding the extraction result (~4152)
|
||||||
|
if (!resources::extractEmbeddedResources()) {
|
||||||
|
daemon_status_ = TR("sb_daemon_extract_failed"); // disk full / permission denied
|
||||||
|
return false; // abort before spawning
|
||||||
|
}
|
||||||
|
|
||||||
|
// second copy-fallback loop — was dropping ec entirely (~4236)
|
||||||
|
bool copyFailed = false;
|
||||||
|
for (const char* name : { "asmap.dat", "dragonxd", "dragonx-cli", "dragonx-tx" }) {
|
||||||
|
fs::path dst = fs::path(daemon_dir) / name;
|
||||||
|
if (fs::exists(dst)) continue; // already present — skip
|
||||||
|
for (const auto& dir : searchDirs) {
|
||||||
|
fs::path src = fs::path(dir) / name;
|
||||||
|
if (!fs::exists(src)) continue; // absent source is OK, not a failure
|
||||||
|
fs::copy_file(src, dst, ec);
|
||||||
|
if (ec) { copyFailed = true; ec.clear(); }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (copyFailed) {
|
||||||
|
char buf[512];
|
||||||
|
snprintf(buf, sizeof buf, TR("sb_daemon_files_failed"), daemon_dir.c_str());
|
||||||
|
daemon_status_ = buf;
|
||||||
|
return false; // don't fall through to spawn
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verification
|
||||||
|
- Unit: `extractEmbeddedResources()` returns false without embedded resources.
|
||||||
|
- Extract the copy loop into a testable helper; force one dst write to fail (dst is an existing directory).
|
||||||
|
- Manual: near-full tmpfs / read-only dir → clear status, daemon controller never constructed.
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
Shares the `daemon_status_` surfacing convention with F6; its early-return pattern is the
|
||||||
|
template F7 matches. Open item: remove truncated dst files so a retry re-copies.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## F6 — Sapling params validated by existence/size only, never hashed
|
||||||
|
|
||||||
|
**Severity:** Medium · **Effort:** S (~3–5h) · **Status:** ☑ landed & verified
|
||||||
|
|
||||||
|
> **As-built note.** `verifySaplingParams()` now delegates to a public, injectable
|
||||||
|
> `verifySaplingParamsIn(dir, digests)` so the integrity + marker-cache logic is unit-testable
|
||||||
|
> with synthetic small files (the real 48 MB params aren't in the repo). i18n keys for F5 were
|
||||||
|
> added to `i18n.cpp` (English source of truth); the `res/lang/*.json` back-fill via
|
||||||
|
> `scripts/add_missing_translations.py` is deferred to a single run at the end of the batch,
|
||||||
|
> per the cross-cutting note. Non-English locales fall back to English until then.
|
||||||
|
|
||||||
|
### The defect
|
||||||
|
`verifySaplingParams()` (`connection.cpp:123`) only calls `fs::exists()`;
|
||||||
|
`resourceNeedsUpdate()` (`embedded_resources.cpp:250`) is size-only. On Linux (no
|
||||||
|
embedded resources) a **truncated-but-present** param passes and is handed to the daemon,
|
||||||
|
which then fails to build shielded proofs mid-operation — far from the real cause.
|
||||||
|
|
||||||
|
### The fix
|
||||||
|
Add a pinned `{ filename → size, sha256 }` table (one source of truth, cross-referenced
|
||||||
|
to `scripts/build-lite-backend-artifact.sh`) and hash-check each param after the
|
||||||
|
existence check, reusing the existing `util::sha256Hex` (no second implementation). Since
|
||||||
|
these are ~48 MB, **cache the result** via a `.sapling_verified` marker keyed on
|
||||||
|
`size:mtime` — re-hash only when the stat line changes, so startup isn't slowed.
|
||||||
|
|
||||||
|
### Files touched
|
||||||
|
- `src/rpc/connection.h` — `verifySaplingParams` decl
|
||||||
|
- `src/rpc/connection.cpp` — digest table, marker helpers, rewrite
|
||||||
|
|
||||||
|
### Core change
|
||||||
|
```cpp
|
||||||
|
// connection.cpp — pinned known-good digests
|
||||||
|
// (source of truth: scripts/build-lite-backend-artifact.sh ensure_sapling_params)
|
||||||
|
constexpr SaplingParamDigest kSaplingParamDigests[] = {
|
||||||
|
{ "sapling-spend.params", 47958396, "8e48ffd2…efc13" },
|
||||||
|
{ "sapling-output.params", 3592860, "2f0ebbcb…fb0e4" },
|
||||||
|
};
|
||||||
|
|
||||||
|
bool Connection::verifySaplingParams() {
|
||||||
|
// existence check (unchanged) …
|
||||||
|
// cache: skip re-hashing a ~48 MB file unless size:mtime changed
|
||||||
|
if (readMarkerMatches(marker, statLines)) return true;
|
||||||
|
for (auto& d : kSaplingParamDigests)
|
||||||
|
if (util::sha256Hex(bytes) != d.sha256) return false; // reuse existing helper
|
||||||
|
writeMarker(marker, statLines);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verification
|
||||||
|
- Unit: good params pass; truncated / wrong-bytes rejected; marker cache short-circuits re-hash unless size/mtime changed. Real temp-file fixtures (matches existing `sha256Hex` tests).
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
F7 (reuse fs-error idiom; shares the `startEmbeddedDaemon`/`verifySaplingParams` block).
|
||||||
|
Third caller of the existing `util::sha256Hex`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## F7 — Directory-create errors universally ignored on the daemon-env path
|
||||||
|
|
||||||
|
**Severity:** Medium · **Effort:** S (~3–4h) · **Status:** ☑ landed & verified
|
||||||
|
|
||||||
|
> **As-built notes.** Two deviations from the original design, both confirmed against the code:
|
||||||
|
> (1) `embedded_resources.cpp:270` already checks its `error_code` and returns `false` on failure — it was **not** a bug, so it is left untouched.
|
||||||
|
> (2) Of the four `autoDetectConfig` callers, only the primary connect path (`app_network.cpp:243`) was wired to check `dir_error`; the other three degrade gracefully on their own — `app.cpp:4306` and `app_wizard.cpp:912` are stop paths that already gate on empty creds, and `settings_page.cpp:434` is read-only display. `dir_error` is set by `autoDetectConfig`, so they can be wired later if desired.
|
||||||
|
|
||||||
|
### The defect
|
||||||
|
Five startup directory-create sites either drop the `error_code` or use the throwing
|
||||||
|
overload with no `catch`: `main.cpp:730`, `connection.cpp:216` (can throw **uncaught**
|
||||||
|
through its callers), `embedded_resources.cpp:270`, `app.cpp:4172`/`4218`. A read-only
|
||||||
|
home or permission-denied yields a confusing "conf missing" / "binary not found"
|
||||||
|
downstream — or an uncaught `filesystem_error` — instead of a clear cause.
|
||||||
|
|
||||||
|
### The fix
|
||||||
|
One shared, non-throwing `Platform::ensureDirectory(dir, outError)` in
|
||||||
|
`util/platform.{h,cpp}` that produces a single consistent message. Replace all five
|
||||||
|
sites; `autoDetectConfig()` moves off the throwing overload and sets a new
|
||||||
|
`ConnectionConfig::dir_error` that its four callers check and bail on. This is the
|
||||||
|
**structural owner** of the fs-error idiom that F5 and F6 reuse.
|
||||||
|
|
||||||
|
### Files touched
|
||||||
|
- `src/util/platform.h` / `.cpp` — `ensureDirectory()`
|
||||||
|
- `src/rpc/connection.h` / `.cpp` — `dir_error` + `autoDetectConfig`
|
||||||
|
- `main.cpp`, `app.cpp`, `app_network.cpp`, `app_wizard.cpp`, `settings_page.cpp`, `embedded_resources.cpp` — 5 sites + 4 callers
|
||||||
|
- `tests/test_phase4.cpp` — `TestPlatformEnsureDirectory`
|
||||||
|
|
||||||
|
### Core change
|
||||||
|
```cpp
|
||||||
|
// util/platform.cpp — one shared, non-throwing helper
|
||||||
|
bool Platform::ensureDirectory(const std::string& dir, std::string* outError) {
|
||||||
|
std::error_code ec;
|
||||||
|
if (std::filesystem::is_directory(dir, ec)) return true;
|
||||||
|
ec.clear();
|
||||||
|
std::filesystem::create_directories(dir, ec);
|
||||||
|
if (ec) {
|
||||||
|
if (outError)
|
||||||
|
*outError = "Cannot create " + dir + ": " + ec.message() +
|
||||||
|
". Check permissions / free space.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Replaces 5 ad-hoc sites; autoDetectConfig() now sets ConnectionConfig::dir_error,
|
||||||
|
// and its 4 callers bail on it.
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verification
|
||||||
|
- Unit `TestPlatformEnsureDirectory`: existing dir → true; fresh nested → created; POSIX unwritable → false + message.
|
||||||
|
- All four `autoDetectConfig` callers tolerate `dir_error`. Pre-App-init site (main.cpp) reports via stderr / MessageBox.
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
**Owns** `Platform::ensureDirectory` (used by F5, F6) and the `ConnectionConfig`
|
||||||
|
extension (coordinated with F8). Land before F5/F6/F8.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## F8 — Plaintext-remote RPC credential transmission is warn-only
|
||||||
|
|
||||||
|
**Severity:** Medium · **Effort:** M (~6–9h) · **Status:** ☑ landed & verified
|
||||||
|
|
||||||
|
> **⚠️ RELEASE NOTES REQUIRED — breaking default flip.** A wallet configured to talk to a
|
||||||
|
> **remote** `rpchost` over **plain HTTP** (no `rpctls=1`) will now be **refused** at connect
|
||||||
|
> time instead of warned. Affected users must add **`rpcallowplaintext=1`** to `DRAGONX.conf`
|
||||||
|
> (or switch to `rpctls=1`) to reconnect. Local/embedded daemons (`127.0.0.0/8`, `localhost`,
|
||||||
|
> `::1`) are unaffected. Call this out prominently in the release notes.
|
||||||
|
>
|
||||||
|
> **As-built note.** Shipped the security-complete core: `isLocalHost` tightened to exact
|
||||||
|
> loopback (`isExactIPv4Loopback` — `127.evil.com` no longer passes), refuse-by-default in
|
||||||
|
> `tryConnect`, and the `rpcallowplaintext` conf-key opt-in. The **Settings toggle UI was
|
||||||
|
> deferred** — the RPC section of `settings_page.cpp` is read-only display and a security
|
||||||
|
> toggle there is riskier surface; the conf-key opt-in fully covers recovery, and the refusal
|
||||||
|
> status/notification tells the user exactly what to add. The toggle can be added later
|
||||||
|
> (persist a `Settings` flag and OR it into `allowsPlaintextRemote`).
|
||||||
|
|
||||||
|
### The defect
|
||||||
|
A remote `rpchost` without `rpctls=1` sends Basic-auth `rpcuser:rpcpassword` over
|
||||||
|
cleartext HTTP. `tryConnect()` (`app_network.cpp:314`) only shows a **dismissible
|
||||||
|
warning** then proceeds — a local-network MITM sees the credentials. Compounding it,
|
||||||
|
`isLocalHost()`'s naive `rfind("127.",0)==0` misclassifies `127.evil.com` as local,
|
||||||
|
suppressing even the warning.
|
||||||
|
|
||||||
|
### The fix
|
||||||
|
Change the policy to **refuse-by-default with an explicit, persisted opt-in** — a
|
||||||
|
`rpcallowplaintext=1` conf key (for hand-editors) and a Settings toggle. Block the
|
||||||
|
connect and show a **blocking modal** explaining the risk and how to enable TLS or opt
|
||||||
|
in; localhost is unaffected. Tighten `isLocalHost()` to exact `127.x.y.z` / `::1` /
|
||||||
|
`localhost` via `isExactIPv4Loopback()`. **Back-compat:** default off ⇒ existing remote
|
||||||
|
users hit a hard stop until they opt in — **ship with prominent release notes.**
|
||||||
|
|
||||||
|
### Files touched
|
||||||
|
- `src/rpc/connection.h` / `.cpp` — `isLocalHost`, `allow_plaintext_remote`, `parseConfFile`
|
||||||
|
- `src/config/settings.h` / `.cpp` — persisted opt-in
|
||||||
|
- `src/app_network.cpp`, `src/app.h` — refuse + modal dispatch
|
||||||
|
- `src/ui/windows/plaintext_remote_rpc_dialog.h` — new blocking modal
|
||||||
|
- `src/ui/pages/settings_page.cpp` — toggle UI
|
||||||
|
|
||||||
|
### Core change
|
||||||
|
```cpp
|
||||||
|
// Tightened loopback test — "127.evil.com" is NOT local
|
||||||
|
bool Connection::isLocalHost(const std::string& host) {
|
||||||
|
std::string h = stripBrackets(lowercase(host));
|
||||||
|
return h == "localhost" || h == "::1" || isExactIPv4Loopback(h); // exact 127.x.y.z
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refuse-by-default with an explicit, persisted opt-in
|
||||||
|
const bool plaintextRemote = rpc::Connection::usesPlaintextRemote(config);
|
||||||
|
const bool plaintextAllowed = config.allow_plaintext_remote // rpcallowplaintext=1
|
||||||
|
|| settings_.getAllowPlaintextRemoteRpc(); // Settings toggle
|
||||||
|
if (plaintextRemote && !plaintextAllowed) {
|
||||||
|
connection_status_ = TR("sb_plaintext_remote_blocked");
|
||||||
|
showPlaintextRemoteRpcDialog(config.host + ":" + config.port); // blocking modal
|
||||||
|
return; // no creds sent
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verification
|
||||||
|
- Unit: `isLocalHost` — `127.evil.com` false, `127.0.0.1`/`::1`/`localhost` true; `allowsPlaintextRemote` honors conf key + settings flag.
|
||||||
|
- Manual: remote plaintext blocked; modal fires; opt-in persists across restart.
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
F7 (second extender of `ConnectionConfig`/`parseConfFile`; land after so the struct grows
|
||||||
|
once). Wire `renderPlaintextRemoteRpcDialog` into the app modal-dispatch list.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Shared helpers & coordination points
|
||||||
|
|
||||||
|
| Helper | Purpose | Used by |
|
||||||
|
|--------|---------|---------|
|
||||||
|
| `Platform::ensureDirectory()` | Single non-throwing directory-create with one consistent message; replaces five ad-hoc sites. Owned by F7. | F7, F5, F6 |
|
||||||
|
| `ConnectionConfig` extension | Coordination point, not a function: F7 adds `dir_error`, F8 adds `allow_plaintext_remote`. Land F7→F8 so it grows once per step. | F7, F8 |
|
||||||
|
| `util::sha256Hex` *(existing)* | Already-compiled, curl-free SHA-256. F6 becomes its third caller — no second hash routine. | F6 |
|
||||||
|
| `connectHasStalled()` *(new, pure)* | Stall predicate split out of the ImGui/App code for unit testing, per the `*_updater_core.cpp` precedent. | F3 |
|
||||||
|
| `evaluateDatadirLockGate()` *(new, pure)* | Lock-gate decision as `{proceed, message}` from three booleans — unit-testable without real process/fs I/O. | F4 |
|
||||||
|
|
||||||
|
## F3 — Unbounded connect spinner (deferred to step 6)
|
||||||
|
|
||||||
|
**Severity:** Medium · **Effort:** S (~3–5h) · **Status:** ☑ landed & verified
|
||||||
|
|
||||||
|
> **As-built note.** `renderLoadingOverlay()` is a pure draw-list overlay with **no interactive
|
||||||
|
> widgets** (the existing crash case at ~5289 already communicates via guidance *text*, relying on
|
||||||
|
> the sidebar staying reachable). So rather than inject `ActionButton`s — which would fight the
|
||||||
|
> non-interactive overlay — the stall notice follows that same idiom: a "Taking longer than
|
||||||
|
> expected" title + a reassuring body (with elapsed seconds) + a full-node-gated hint ("Open
|
||||||
|
> Settings → Restart Daemon, or check the Console"). This let me drop the planned
|
||||||
|
> `WalletState::connect_stalled` flag too: the stalled state is computed locally in the overlay
|
||||||
|
> from `connect_stall_since_`, so the only new member is `App::connect_stall_since_`.
|
||||||
|
|
||||||
|
The connect loop retries forever while `!state_.connected` (`app.cpp:1239`);
|
||||||
|
`loading_timer_` only animates the spinner. Stamp `connect_stall_since_` when
|
||||||
|
"reachable but not ready" is first seen; a pure `connectHasStalled()` helper (new
|
||||||
|
`util/connect_stall.h`, default 45s from `ui.toml`) flips `state_.connect_stalled` at
|
||||||
|
threshold, and `renderLoadingOverlay()` shows a "Taking longer than expected" panel with
|
||||||
|
Retry / Restart daemon / Open console (full-node gated). The background retry keeps
|
||||||
|
firing — recovery clears the panel automatically. Guarded off while the daemon is in
|
||||||
|
`State::Error` (owned by F1's crash-count hint). Full detail lives in the sequencing/
|
||||||
|
design record; see the shared-helper table above.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Cross-cutting notes
|
||||||
|
|
||||||
|
- **One TU, three functions.** `embedded_daemon.cpp` is edited by F1 (`isRunning`),
|
||||||
|
F2 (`startProcess`) and F4 (`start`) — no literal hunk overlap, but land in order to
|
||||||
|
keep "monitorProcess is the sole reaper" coherent.
|
||||||
|
- **Connection struct grows twice.** `connection.h/.cpp` is touched by F6, F7 and F8;
|
||||||
|
F7 and F8 both extend `ConnectionConfig` and `parseConfFile` — highest collision risk.
|
||||||
|
Sequence F7→F6→F8.
|
||||||
|
- **Testability split.** The three new pure predicates all get `tests/test_phase4.cpp`
|
||||||
|
coverage. F1/F2's fork/exec/waitpid changes are **not** unit-testable — they rely on
|
||||||
|
manual `kill` / non-executable-binary repros, consistent with the no-process-spawn harness.
|
||||||
|
- **i18n is additive-only.** Add each finding's English keys to `strings_`, then run
|
||||||
|
`scripts/add_missing_translations.py` **once at the very end**
|
||||||
|
(`json.dump indent=4, sort_keys=True, ensure_ascii=False`) — never bulk-regenerate a
|
||||||
|
`res/lang/*.json`.
|
||||||
|
- **F8 is a breaking default flip.** Refuse-plaintext-by-default stops existing
|
||||||
|
remote-RPC users cold until they opt in. Lands last, gated behind a persisted opt-in,
|
||||||
|
with release notes calling out the new `rpcallowplaintext` key and the Settings toggle.
|
||||||
|
- **Latent hazard, out of scope.** F1 surfaces (but doesn't fix) a second
|
||||||
|
double-`waitpid` window between `stop()`'s final blocking reap (`:1220`) and a
|
||||||
|
mid-sleep monitor iteration — file it as its own ticket.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Progress log
|
||||||
|
|
||||||
|
- **F1/F2 integration tests** — ☑ added `testExecFailureReported` (F2) and `testDaemonCrashDetected` (F1) to `test_phase4.cpp`, driving the **real** `EmbeddedDaemon` fork/exec/waitpid code headlessly (POSIX; required linking `embedded_daemon.cpp` into the test target — its deps were already there). The F1 test hammers `isRunning()` from the test thread while the child exits, so it's a genuine regression test for the reap race. **The F2 test caught a real bug:** `start()`'s failure branch overwrote `startProcess()`'s precise `last_error_` ("…not executable or wrong architecture") with a generic "Failed to start dragonxd process" (because `setState(Error, …)` stores its message into `last_error_`), so the precise reason never reached `getLastError()`/the UI — **fixed** to preserve the detail (now also surfaced via the state callback / crash panel). Build-clean; `ctest` 1/1.
|
||||||
|
|
||||||
|
- **F1** — ☑ landed: `isRunning()` (POSIX) now reads the atomic `state_` (predicate `Running || Stopping`) instead of calling `waitpid`, leaving `monitorProcess()` the sole reaper. Clean build (all targets link); `ctest` 1/1 passing. Not unit-testable — needs the manual `kill -SEGV` repro before release.
|
||||||
|
- **F2** — ☑ landed: `startProcess()` (POSIX) now creates a `FD_CLOEXEC` self-pipe before `fork()`; the child writes `errno` to it on `execv` failure, the parent reads EOF-vs-errno and, on failure, reaps the zombie + sets a precise `last_error_` ("not executable or wrong architecture") + returns `false` (so `start()` no longer reports `Running` for a daemon that never started). Parent-side `setpgid` is now best-effort with a `DEBUG_LOGF` on failure. Clean build; `ctest` 1/1 passing. Not unit-testable — needs the manual non-executable / wrong-arch-binary repro before release.
|
||||||
|
- **F8** — ☑ landed: `isLocalHost()` tightened to exact loopback via `isExactIPv4Loopback` (a `127.`-prefixed *hostname* like `127.evil.com` is no longer misclassified as local). `tryConnect()` now **refuses** a plaintext connection to a remote host instead of warn-and-proceeding — a local-network MITM can no longer capture `rpcuser:rpcpassword` — unless the user opts in with `rpcallowplaintext=1` in `DRAGONX.conf` (new `ConnectionConfig::allow_plaintext_remote` + `allowsPlaintextRemote()` policy). The refusal surfaces via status line + a one-time notification. New `testIsLocalHost` (12 assertions) + `testAllowsPlaintextRemote` (5). Clean build; `ctest` 1/1 passing. **Breaking — needs release notes; Settings-toggle UI deferred (see as-built note).**
|
||||||
|
- **F3** — ☑ landed: the connect loop now stamps `connect_stall_since_ = ImGui::GetTime()` the moment the daemon first goes "reachable but not ready" (warmup branch + `applyDaemonInitStatus`), and clears it in `onConnected` / `onDisconnected` / warmup-complete — all in `app_network.cpp`. The pure `util::connectHasStalled(stallSince, now, threshold)` helper (new `util/connect_stall.h`, default 45 s from `ui.toml`) drives a draw-list "Taking longer than expected" notice in `renderLoadingOverlay()` (title + elapsed-seconds body + full-node hint), guarded off while the daemon is in `State::Error`. Background retry continues, so the notice self-clears on connect. New `testConnectHasStalled` unit test (7 assertions). Clean build; `ctest` 1/1 passing. (Draw-list text, not buttons — see as-built note above.)
|
||||||
|
- **F6** — ☑ landed: `verifySaplingParams()` now hash-verifies each Sapling param against its pinned canonical SHA-256 (from `build-lite-backend-artifact.sh`), replacing the existence-only check, so a truncated/corrupt-but-present param is rejected instead of failing later on a shielded op. A `<params_dir>/.sapling_verified` marker keyed on `size:mtime` skips re-hashing ~48 MB on every startup. Logic extracted to the injectable `verifySaplingParamsIn(dir, digests)`; new `testVerifySaplingParams` unit test (valid / marker fast-path / wrong-hash / truncated / missing). Clean build; `ctest` 1/1 passing.
|
||||||
|
- **F5** — ☑ landed: `startEmbeddedDaemon()` now checks `extractEmbeddedResources()`'s return (abort with `sb_daemon_extract_failed` on failure) and the previously-dropped `copy_file` `error_code` in the daemon-binary fallback loop (abort with `sb_daemon_files_failed` incl. the dir), so a disk-full / truncated `dragonxd` write is surfaced up front instead of failing opaquely at spawn. An absent source file stays non-fatal. Two i18n keys added to `i18n.cpp`. Clean build; `ctest` 1/1 passing.
|
||||||
|
- **F7** — ☑ landed: new non-throwing `Platform::ensureDirectory(dir, outError)` in `util/platform.{h,cpp}` with one consistent message. Replaces the unchecked/throwing directory-create sites at `main.cpp:730` (pre-init: now logs + `MessageBoxA` on Windows + `return 1`), `connection.cpp:216` (autoDetectConfig now uses the ec overload — **no more uncaught `filesystem_error`** — and sets the new `ConnectionConfig::dir_error`), and both `app.cpp` daemon-dir sites (surface via `daemon_status_` + `return false`). Primary connect path (`app_network.cpp:243`) checks `dir_error` and bails to the status line instead of mislabelling it "waiting for config". `embedded_resources.cpp:270` left as-is (already correct). New `testPlatformEnsureDirectory` unit test (existing-dir / fresh-nested / empty / parent-is-file). Clean build; `ctest` 1/1 passing.
|
||||||
|
- **F4** — ☑ landed: `start()` now gates on a lingering datadir lock after the port bail. When `!skip_port_check_ && override_datadir_.empty()`, it polls `isDaemonProcessRunning()` with a bounded ~300 ms wait (3 × 100 ms, breaks early), then a pure header-inline `evaluateDatadirLockGate()` decides: if a sibling `dragonxd` is still alive it bails with a distinct **non-crash** `State::Error` ("…holding the data directory lock. Retrying shortly…") that never touches `crash_count_`, so the 3-strike cap can't trip; the connect loop's retry resumes once the lock clears. Isolated migrate-to-seed starts are exempt. New `testDatadirLockGate` unit test (5 assertions, proceed/bail/2× exempt) added to `test_phase4.cpp`. Clean build; `ctest` 1/1 passing.
|
||||||
61
docs/release-notes/lite-v1.0.0.md
Normal file
61
docs/release-notes/lite-v1.0.0.md
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
**DragonX (DRGX) Lite Desktop Wallet — v1.0.0**
|
||||||
|
|
||||||
|
ObsidianDragonLite is a lightweight companion to the ObsidianDragon full-node wallet. It skips the embedded full node entirely — **no multi-gigabyte blockchain download and near-instant startup** — by connecting to a DragonX lite-wallet (lightwalletd-style) server, while keeping the same native ImGui interface and shielded-first workflow.
|
||||||
|
|
||||||
|
This is the **first release** of the Lite variant.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Why Lite?
|
||||||
|
|
||||||
|
- **No blockchain to download.** Sync in seconds instead of hours; a few MB of state instead of many GB.
|
||||||
|
- **Same wallet, lighter footprint.** The familiar ObsidianDragon UI, shielded and transparent addresses, and address book — without running a node or miner.
|
||||||
|
- **Portable.** A single self-contained binary that stores its data in its own `ObsidianDragonLite` folder, so it coexists cleanly alongside the full-node wallet.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Fast, node-free operation** — connect to a DragonX lite-wallet server and sync in seconds; minimal disk and RAM.
|
||||||
|
- **Wallet lifecycle** — create a new wallet, restore from a seed phrase, or open an existing one; wallets auto-open on startup, with a first-run welcome prompt and **guided seed backup** on creation.
|
||||||
|
- **Shielded + transparent** — send, shield, and receive DRGX; per-address balances computed from unspent notes and UTXOs.
|
||||||
|
- **Keys & seed** — export your seed phrase and keys, and import keys, from Settings.
|
||||||
|
- **Passphrase encryption** — encrypt, unlock, lock, and decrypt the wallet; you're prompted to unlock at send time and on startup when the wallet is locked.
|
||||||
|
- **Encrypted messaging (HushChat)** — built-in **Contacts** and **Chat** with a seed-derived, **SilentDragonXLite-compatible** identity and a seed-encrypted local message store, so you can message other DragonX users end-to-end.
|
||||||
|
- **Server management** — a built-in **server browser with automatic failover**; switch servers with live reconnect/recovery, and a **"Redownload blocks"** action to rescan from the server.
|
||||||
|
- **Status & diagnostics** — a **Network tab** showing connection and sync status, plus an **interactive Console** for running backend commands and copyable error output.
|
||||||
|
- **Multi-language UI** — full internationalization covering 8 languages: German, Spanish, French, Japanese, Korean, Portuguese, Russian, and Chinese.
|
||||||
|
- **Cross-platform** — native builds for Linux (AppImage + zip), Windows (portable exe + zip), and macOS (DMG + .app), x86-64.
|
||||||
|
- QR code generation for receiving addresses
|
||||||
|
- Extensive theme and appearance options
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## How it differs from the full-node wallet
|
||||||
|
|
||||||
|
- **No embedded `dragonxd`, no mining, no local blockchain explorer.** Chain data comes from the lite-wallet server rather than being verified locally by a full node — a lighter footprint in exchange for trusting the server for chain state.
|
||||||
|
- Everything key-related stays **on your device**: seed, keys, and (when enabled) the encryption passphrase never leave the machine.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Downloads
|
||||||
|
|
||||||
|
| File | SHA-256 |
|
||||||
|
|------|---------|
|
||||||
|
| ObsidianDragonLite-1.0.0.AppImage | `a1459d6081124a6b8df47aa898b60c0237875e8cbb132e4fd8ae637673055ed4` |
|
||||||
|
| ObsidianDragonLite-1.0.0-Linux-x64.zip | `573af502a6372334572e4dc88bd26e0cf36ed543b9df1e835fd8e4abd295108d` |
|
||||||
|
| ObsidianDragonLite-1.0.0.exe | `28659efb770fa573bd1b1d0fcab1c1a3f9c7e46574185c3916cc9f669684852c` |
|
||||||
|
| ObsidianDragonLite-1.0.0-Windows-x64.zip | `f6434a931e873e5936ebe249b044d6c7a413694767c667374c91ee438259b50c` |
|
||||||
|
| ObsidianDragonLite-1.0.0-macOS-x86_64.dmg | `10f976f1453e6b1978cb7a85026fd033c85a10c1e66f436475aa628379a298c7` |
|
||||||
|
| ObsidianDragonLite-1.0.0-macOS-x86_64.app.zip | `3e7259c363f7be2e9027c5282c94b742f4be280c998203752dc0a0551f6ab68b` |
|
||||||
|
|
||||||
|
## System Requirements
|
||||||
|
|
||||||
|
- **Linux:** x86-64, glibc 2.31+ (Ubuntu 20.04+, Fedora 33+, etc.)
|
||||||
|
- **Windows:** x86-64, Windows 10 or later
|
||||||
|
- **macOS:** x86-64 (Intel; runs on Apple Silicon via Rosetta 2), macOS 10.15 Catalina or later
|
||||||
|
- Network access to a DragonX lite-wallet server.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Released under the **GPLv3**. See [LICENSE](https://git.dragonx.is/DragonX/ObsidianDragon/src/branch/master/LICENSE) for details.
|
||||||
86
docs/release-notes/v2.0.0.md
Normal file
86
docs/release-notes/v2.0.0.md
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
**DragonX (DRGX) Full-Node Desktop Wallet — v2.0.0**
|
||||||
|
|
||||||
|
This is ObsidianDragon, a native ImGui-based wallet for the DragonX network. It ships with an embedded full-node daemon (`dragonxd`) and an integrated CPU miner (DRG-XMRig), giving users a complete, self-contained experience on Linux, Windows, and macOS.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## What's New in v2.0.0
|
||||||
|
|
||||||
|
v2.0.0 is a major release. It adds **end-to-end encrypted HushChat messaging** and **BIP39 seed-phrase wallets** (with migrate-to-seed for legacy wallets), lets the wallet **update its own node and miner** with each install cryptographically verified, and ships a **security-hardening pass** across the updater, RPC, and secret-storage surfaces — plus full support for the **new multi-threaded `dragonxd`** and a large stability and UX overhaul.
|
||||||
|
|
||||||
|
### New Features
|
||||||
|
|
||||||
|
- **Encrypted messaging (HushChat)** — new **Contacts** and **Chat** tabs bring DRGX-native, end-to-end encrypted messaging. Your chat identity is derived from your wallet seed, messages are encrypted with libsodium (XChaCha20-Poly1305 / secretstream) and stored in a **seed-encrypted local database**, and the wire format is interoperable with SilentDragonX / SilentDragonXLite.
|
||||||
|
- **BIP39 seed-phrase wallets & migrate-to-seed** — new wallets are backed by a mnemonic **seed phrase** you can back up from Settings. Existing **legacy wallets can be migrated into a seed wallet** — the wallet mints a new mnemonic wallet, sweeps your funds to it, and adopts it only once the sweep is mined, keeping a timestamped `wallet.dat` backup throughout. (The bundled `dragonxd` supports the required mnemonic RPCs; older nodes degrade gracefully.)
|
||||||
|
- **In-app daemon updater** — Settings → **Node & Security → Daemon binary → "Check for updates…"** downloads the latest `dragonxd` from the project Gitea, verifies its **SHA-256 and a detached ed25519 signature** before installing, and replaces the binary **atomically while the node keeps running** (the new build takes effect on the next daemon start). A two-pane version picker lets you pin, downgrade, or install any published/pre-release build.
|
||||||
|
- **In-app miner updater** — an **"Update miner…"** action in the Mining tab fetches, verifies (SHA-256 + ed25519), and installs the latest DRG-XMRig, with the same version picker and a display of current vs. latest.
|
||||||
|
- **Daemon binary management** — the wallet no longer auto-overwrites a node you've dropped in; a dedicated Settings panel shows the managed binary and gathers all node actions (restart, rescan, repair) onto one toolbar.
|
||||||
|
- **Repair Wallet** — a one-click `-zapwallettxes=2` recovery in Settings, plus automatic wallet reconciliation after a bootstrap and runtime rescan support for pruned nodes.
|
||||||
|
- **Explorer search** — fuzzy, live (debounced) filtering of the block list by partial hash or height.
|
||||||
|
- **History sorting & fast load** — sort transactions by date or amount, a "Loading older history (N%)" indicator during the initial bulk load, and persisted history that surfaces pending sends immediately.
|
||||||
|
- **Smarter mining** — the thread benchmark now measures **sustained (thermally-throttled) hashrate** instead of an inflated initial burst, with GPU-aware idle mining and corrected idle thread scaling.
|
||||||
|
|
||||||
|
### Security & Integrity
|
||||||
|
|
||||||
|
- **Mandatory signature verification** — both the daemon and miner updaters **require** a valid ed25519 signature (checked against a key pinned in the wallet) in addition to the SHA-256; an install is refused if the signature is missing or invalid.
|
||||||
|
- **Hardened secret handling** — RPC credentials are wiped from memory after use, RPC responses are size-capped and scrubbed of secrets in logs, generated node config is written **owner-only (0600)**, and secrets copied to the clipboard **auto-clear**.
|
||||||
|
- **Safe on-disk writes** — settings, address book, and secret files are written **atomically with owner-only permissions**; the PIN vault fsyncs its secure-delete overwrite; SQLite cache growth is bounded.
|
||||||
|
- **Recipient validation** — sends validate recipient address checksums (Base58Check + Bech32) before building a transaction.
|
||||||
|
- **Path-traversal protection** — archive extraction (chain bootstrap and the updaters) rejects any entry that would escape the target directory (zip-slip), and the bootstrap fails closed on a missing checksum rather than trusting an unverified archive.
|
||||||
|
- **Robustness** — malformed RPC error JSON is guarded and sends are single-flight, preventing duplicate/ill-formed submissions.
|
||||||
|
|
||||||
|
### Improvements
|
||||||
|
|
||||||
|
- **New multi-threaded daemon support** — live Sapling note-witness rebuild progress, accurate sync-speed display, reliable rescan-completion detection, and RPC polling throttled during sync so block download isn't slowed.
|
||||||
|
- **Networking** — DragonX DNS seed nodes, `-maxconnections` passed to the daemon, and a peer count that stays current on every tab.
|
||||||
|
- **Node resilience** — non-blocking warmup so you can connect while the daemon is still initializing, a live daemon-console tail on the startup overlay, fast-failing connect probes, and mid-session disconnect detection that keeps the UI responsive (in-flight RPC calls abort cleanly on disconnect/shutdown).
|
||||||
|
- **Address list** — modernized with drag-to-transfer, labels, and view-only handling.
|
||||||
|
- **UI / DPI** — overlay dialogs scale correctly with the font/DPI setting, improved CJK font rendering, native language names in the language picker, and format-incompatible translations are rejected.
|
||||||
|
- **Settings** — an "Open data folder" button and confirmation modals for rescan and restart-daemon.
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
Extensive fixes across history (shielded-tx ordering, stuck "refreshing history" banners, unconfirmed-badge stickiness), sends (correct fee passed to `z_sendmany`, fast-lane worker restart on reconnect, note-selection fee-gap workaround), rescan (accurate completion detection, no false "complete", no per-second error flood), RPC (mid-session disconnect handling, stale-refresh invalidation), and UI layout/i18n. See the commit history for the full list.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Full-node wallet** — send, receive, and verify DRGX transactions with a bundled `dragonxd` daemon; no external setup required.
|
||||||
|
- **Self-updating** — verify-and-install the latest node and miner from within the app (SHA-256 + ed25519 signature enforced).
|
||||||
|
- **Encrypted messaging** — built-in HushChat with a seed-derived identity, end-to-end encryption, and a seed-encrypted local message store, interoperable with SilentDragonX / SilentDragonXLite.
|
||||||
|
- **Seed-phrase wallets** — BIP39 mnemonic backup, and migrate-to-seed to upgrade a legacy wallet into a seed wallet.
|
||||||
|
- **Built-in CPU mining** — start/stop DRG-XMRig from the Mining tab with real-time hashrate and pool statistics, mine-when-idle support with configurable delay, and sustained-hashrate benchmarking.
|
||||||
|
- **Multi-language UI** — full internationalization covering 8 languages: German, Spanish, French, Japanese, Korean, Portuguese, Russian, and Chinese.
|
||||||
|
- **Cross-platform** — native builds for Linux (AppImage + zip), Windows (portable exe + zip), and macOS (**universal** DMG + .app); Linux/Windows x86-64, macOS Intel + Apple Silicon.
|
||||||
|
- Shielded (z-address) and transparent (t-address) send/receive
|
||||||
|
- QR code generation for receiving addresses
|
||||||
|
- Transaction history with memo support, date/amount sorting, and pending-send tracking
|
||||||
|
- Blockchain explorer with live block/transaction search
|
||||||
|
- Blockchain rescan and Sapling witness-rebuild with status-bar progress
|
||||||
|
- Repair Wallet and daemon-binary management in Settings
|
||||||
|
- Built-in console
|
||||||
|
- Extensive theme and appearance options
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Downloads
|
||||||
|
|
||||||
|
| File | SHA-256 |
|
||||||
|
|------|---------|
|
||||||
|
| ObsidianDragon-2.0.0.AppImage | `34c9ea57ec27bf415e59d2890d995ed9069bfce04d979d7d8d58aa18f4570aa1` |
|
||||||
|
| ObsidianDragon-2.0.0-Linux-x64.zip | `563004b4e45650dbfa9411d62fa1c59a3ca2199bd43a647b1614f2683bbdb5fa` |
|
||||||
|
| ObsidianDragon-2.0.0.exe | `56100ae59dc3c67445d015cac5412ca40465bf459ba182c5ad2477a3b95ff548` |
|
||||||
|
| ObsidianDragon-2.0.0-Windows-x64.zip | `ce9d067f36c5296288a473d3c2cceca7fcf807672a93a2084afc53c3b6e780d9` |
|
||||||
|
| ObsidianDragon-2.0.0-macOS-universal.dmg | `8a01b6c0c2b5bebd64a222ba4a5ad04a1b8851138f28458b5c7f767fbb65db66` |
|
||||||
|
| ObsidianDragon-2.0.0-macOS-universal.app.zip | `1bce1e5be15d9a2f3c6f42c95b23a0e89df142a73d65895252e4d8f50d19f541` |
|
||||||
|
|
||||||
|
## System Requirements
|
||||||
|
|
||||||
|
- **Linux:** x86-64, glibc 2.31+ (Ubuntu 20.04+, Fedora 33+, etc.)
|
||||||
|
- **Windows:** x86-64, Windows 10 or later
|
||||||
|
- **macOS:** Intel & Apple Silicon (universal binary), macOS 10.15 Catalina or later
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Released under the **GPLv3**. See [LICENSE](https://git.dragonx.is/DragonX/ObsidianDragon/src/branch/master/LICENSE) for details.
|
||||||
167
docs/wallet-hardening.md
Normal file
167
docs/wallet-hardening.md
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
# Wallet Loading & Management — Hardening Plan
|
||||||
|
|
||||||
|
Prioritized, grouped remediation for the wallet loading/management audit (33 verified findings +
|
||||||
|
diagnosability QoL). Companion to the findings artifact. Line references are against `dev`.
|
||||||
|
|
||||||
|
- **Provenance:** 7 parallel subsystem finders, each finding adversarially verified against the
|
||||||
|
code; the 3 highest-impact confirmed findings re-checked by hand. 32 confirmed, 1 refuted
|
||||||
|
(W1-5), 1 raised (W5-3 Low→Med).
|
||||||
|
- **Severity:** 8 High · 12 Medium · 13 Low.
|
||||||
|
|
||||||
|
Status legend: ☐ not started · ◐ in progress · ☑ landed & verified
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Roadmap (ordered by risk; shared fixes grouped)
|
||||||
|
|
||||||
|
| Phase | Findings | Theme | Status |
|
||||||
|
|-------|----------|-------|--------|
|
||||||
|
| **P0-A** | W7-1, W2-1, W4-1, W4-3, W2-3, W4-5, W5-3 ✓ | Secret hardening (console redaction + delete-export + memzero + lite encrypt-at-create) | ☑ 7/7 |
|
||||||
|
| **P0-B** | W2-2/W4-2, W2-4 | Encryption integrity (never silently unencrypted) | ☑ |
|
||||||
|
| **P1-A** | W3-1, W3-2, W3-4, W3-3 ✓ | Migrate-to-seed correctness (fund-adjacent) | ☑ 4/4 (W3-3 pending a live-mainnet run) |
|
||||||
|
| **P1-B** | W1-1, W1-2, W1-3, W1-4 ✓ + startup guard | Missing/wrong wallet-file safety | ☑ |
|
||||||
|
| **P2** | W5-1, W5-2, W6-1, W6-3, W6-2 ✓ | Stale state & lite save-failure surfacing | ☑ 5/5 |
|
||||||
|
| **F** | W7-2, W7-3, W7-4 ✓ · QoL: copy-diag + open-log + node-error-banner + staleness-badge + alert-history ✓ | Diagnostics foundation + QoL bundle | ☑ |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## P0-A — Secret hardening
|
||||||
|
|
||||||
|
Shared fix: a `SecureString` RAII buffer (zeroes on destruction) retrofitted onto the un-scrubbed
|
||||||
|
key/passphrase paths, plus console redaction and deleting the plaintext export.
|
||||||
|
|
||||||
|
- **W7-1 (High)** `console_tab.cpp:1419` — RPC console echoes/stores/clipboards raw secrets. Fix: an
|
||||||
|
allowlist of secret-bearing first-tokens (`walletpassphrase`, `walletpassphrasechange`,
|
||||||
|
`encryptwallet`, `importprivkey`, `importwallet`, `z_importkey`, `z_importviewingkey`,
|
||||||
|
`signrawtransaction`, `magicrecoverkey`, lite equivalents); echo `> walletpassphrase ****` and
|
||||||
|
keep the raw text out of `command_history_`. Extract a pure `redactConsoleCommand(cmd)` helper for
|
||||||
|
unit testing. **← implementing first (self-contained + testable).**
|
||||||
|
- **W2-1 (High)** `wallet_security_workflow.cpp:66` — delete the `obsidiandecryptexport<ts>` plaintext
|
||||||
|
key dump after `z_importwallet` succeeds (overwrite-then-unlink).
|
||||||
|
- **W4-3 (High)** `app_network.cpp:4481` — `sodium_memzero` the concatenated all-keys string in
|
||||||
|
`exportAllKeys`; write the backup 0600. (Also unify with `ExportAllKeysDialog` — QoL.)
|
||||||
|
- **W4-1 (High)** `app_network.cpp:3801` — zero the key copies in `importPrivateKey`/`sweepPrivateKey`
|
||||||
|
(local + worker-lambda copies).
|
||||||
|
- **W2-3 (Med)** `app_security.cpp:1481` — zero the passphrase threaded through the decrypt lambda chain.
|
||||||
|
- **W4-5 (Med)** `app.cpp:3577` — the seed-backup `.txt` is a permanent predictable cleartext seed;
|
||||||
|
at minimum warn + offer to delete, ideally discourage file save in favor of the on-screen phrase.
|
||||||
|
- **W5-3 (Med)** `lite_wallet_lifecycle_service.cpp:322` — remove the dead `passphrase` field from the
|
||||||
|
lite create/open/restore requests (unused; a secret copied for nothing).
|
||||||
|
|
||||||
|
## P0-B — Encryption integrity
|
||||||
|
|
||||||
|
- **W2-2 / W4-2 (High)** `wallet_security_controller.h:89` — the wizard's deferred encryption is
|
||||||
|
in-memory only and silently lost if the daemon doesn't connect or the app quits/crashes first, so a
|
||||||
|
wallet the user believes is encrypted stays plaintext. Fix: persist a lightweight
|
||||||
|
`encryption_requested_but_incomplete` settings flag (NEVER the passphrase) when
|
||||||
|
`beginDeferredEncryption` is called; surface a persistent warning banner while it's set; clear it
|
||||||
|
only on confirmed `encryptwallet` success; on next connect, if set, re-prompt for the passphrase to
|
||||||
|
complete it.
|
||||||
|
- **W2-4 (Med)** `app_security.cpp:480` — `lockWallet` only sets `locked` on RPC success; log the
|
||||||
|
failure and notify (currently a silent no-op that can leave the wallet unlocked).
|
||||||
|
|
||||||
|
## P1-A — Migrate-to-seed correctness (fund-adjacent; verify carefully)
|
||||||
|
|
||||||
|
- **W3-1 (High)** `app_network.cpp:4327` — adopt hardcodes `datadir + "/wallet.dat"`; use
|
||||||
|
`settings_->getActiveWalletFile()` so migrating a non-default active wallet swaps the right file.
|
||||||
|
- **W3-2 (High)** `seed_wallet_creator.cpp:57` — `remove_all(<config>/seed-migrate)` unconditionally
|
||||||
|
at Phase-1 start; refuse to wipe if a temp `DRAGONX/wallet.dat` already exists (a prior un-adopted
|
||||||
|
swept wallet) and surface it, so swept funds in the temp wallet can't be destroyed by re-entry.
|
||||||
|
- **W3-4 (Med)** `app_network.cpp:1124` — block wallet switching while a migration is *pending*
|
||||||
|
(`getSeedMigrationPending()`), not only while the dialog is open.
|
||||||
|
- **W3-3 (Med)** `app_network.cpp:4231` — persist the sweep opid so an app-close mid-Sweeping can
|
||||||
|
resume/re-poll it instead of silently dropping the txid.
|
||||||
|
|
||||||
|
## P1-B — Missing/wrong wallet-file safety
|
||||||
|
|
||||||
|
- **W1-1 (High)** `app_network.cpp:1109` — `fs::exists()`-check the target wallet file in
|
||||||
|
`switchToWallet()` and before the first daemon launch at startup; if missing, block with an explicit
|
||||||
|
"Wallet file not found — moved or deleted?" dialog (browse / create-new) instead of letting the
|
||||||
|
daemon fabricate an empty wallet.
|
||||||
|
- **W1-3 (Med)** `app_network.cpp:1095` — defer the `syncedHere=true` stamp to the first successful
|
||||||
|
address/balance readback (idHash non-empty), not bare `onConnected()`.
|
||||||
|
- **W1-2 (Med)** `app_network.cpp:198` — split `DB_CORRUPT`-specific strings from the generic "Error
|
||||||
|
loading wallet" fallback; give `DB_TOO_NEW` its own message/action (not a salvage offer).
|
||||||
|
- **W1-4 (Low)** `wallets_dialog.h:393` — re-`fs::exists()` the in-datadir row before switching (match
|
||||||
|
the out-of-datadir path).
|
||||||
|
|
||||||
|
## P2 — State & lite persistence
|
||||||
|
|
||||||
|
- **W6-2 (Med)** `network_refresh_service.cpp:1183` — record a per-field last-success timestamp / a
|
||||||
|
"refresh failed" flag so the UI can show a staleness badge instead of last-good-as-current.
|
||||||
|
- **W5-1 / W5-2 (Med)** `lite_wallet_controller.cpp:78,603` — `liteLog()` the failed save and bubble a
|
||||||
|
one-shot UI warning (both call sites currently discard the bool).
|
||||||
|
- **W6-1 (Med)** `wallet_state.h:313` — reset `mining`/`pool_mining` in `clear()` (or comment why not).
|
||||||
|
- **W6-3 (Low)** `address_book.cpp:46` — per-entry try/catch: skip + count malformed entries instead
|
||||||
|
of discarding the whole list.
|
||||||
|
|
||||||
|
## F — Diagnostics foundation + QoL
|
||||||
|
|
||||||
|
Land W7-2 first — it unblocks the rest.
|
||||||
|
|
||||||
|
- **W7-2 (Med)** `logger.cpp:31` — call `Logger::instance().init(<config>/dragonx-debug.log)` early in
|
||||||
|
`main()` on all platforms; add an "Open log folder" action.
|
||||||
|
- **W7-3 (Med)** `main.cpp:144` — add a `sigaction`-based crash handler writing `dragonx-crash.log` on
|
||||||
|
POSIX (mirror the Windows SEH path).
|
||||||
|
- **W7-4 (Low)** `logger.cpp:39` — size-cap/rotate the log on `init()`.
|
||||||
|
- **QoL** — "Copy diagnostics for support" bundle; persistent alert history; daemon/RPC error banner;
|
||||||
|
refresh-staleness badge; multi-wallet diagnostic panel; refresh-diagnostics panel; structured
|
||||||
|
switch/migration audit logging; restore-from-seed entry point (W4-4, effort L).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Progress log
|
||||||
|
|
||||||
|
- **Adversarial review of the 3 diagnostics UI features** — ran a 5-dimension finder → per-finding verify workflow over the node-banner + staleness-badge + alert-history commits (the hand-laid ImGui I couldn't visually verify). 4 confirmed, 1 refuted (banner title never overlaps its button — button is absolutely positioned + title is short), and the dedicated ImGui-stack-balance finder found **no** Push/Pop imbalance. Fixes landed:
|
||||||
|
- **(Med) Alert popup grew off the right edge** — pivot `(0,1)` pinned the panel's *left* edge at the bell (which sits near the window's right edge), so a 320px panel overflowed rightward (an explicit `SetNextWindowPos` pivot skips ImGui's on-screen clamp). Fixed to anchor the bottom-*right* corner at the bell (pivot `(1,1)`, at `bellMax.x`) so it grows left over the canvas.
|
||||||
|
- **(Low) Staleness badge could flash red on reconnect** — `WalletState::clear()` reset everything *except* the four `last_*_update` stamps, so after a reconnect the pre-outage timestamp survived and the badge briefly showed "Updated Nm ago" (red) on the same frame the node banner cleared — the exact contradiction the design forbids. Fixed by zeroing the four stamps in `clear()` (all readers treat 0 as "never"; verified `app_network.cpp:1473` guards on `!= 0`).
|
||||||
|
- **(Low) Banner min-height floor wasn't DPI-scaled** — `std::max(minH, baseH*vScale())` compared a raw-px floor against a scaled value; now `minH * dpiScale()`.
|
||||||
|
- **(Low) New i18n keys weren't in `res/lang/`** — back-filled all 16 diagnostics/QoL keys (this session's node_banner_*/data_stale_*/alerts_*/settings_*/tt_*) into all 8 language files, additively (128 insertions, 0 deletions). zh/ja/ko reworded around 2 glyphs missing from the CJK subset (提醒→通知; ko tooltip avoids 닐) and hard-asserted tofu-free against the subset font.
|
||||||
|
- **Foundation QoL / Persistent alert history** — ☑ landed. Toasts fade in 1–4s; there was no way to review what scrolled past. `Notifications` now retains every pushed alert in a capped (100) ring buffer with a wall-clock epoch (`AlertRecord`) — separate from the 5-item live-toast deque — plus a monotonic `total_pushed_` counter. A bell in the status-bar right cluster (`ICON_MD_NOTIFICATIONS`) opens an upward popup listing recent alerts newest-first with a severity icon/colour (reusing the toast palette), the message, and a relative age (`formatTimeAgoShort`), with a Clear-all action. An **unread dot** on the bell (coloured by the most-severe unseen alert) marks alerts that arrived since the panel was last opened — driven by `totalPushed()` deltas so it survives capping/clearing. Thread-safety: every push is on the UI thread (RPC results run as main-thread `MainCb`s), matching the class's existing lock-free model — documented as a no-raw-worker-thread invariant. Build-clean; `ctest` 1/1 (adds `testNotificationHistory`: retention, order, cap, monotonic counter, clear). **This closes the QoL bundle and the Foundation tier.**
|
||||||
|
- **W6-2 / Refresh-staleness badge** — ☑ landed. The Total Balance card now shows a small pill on its status line ("Updated 2m ago", amber → red past 3 min) **only when connected but the balance stopped refreshing** — a busy daemon can fail `z_gettotalbalance` without dropping the whole connection (only *both* core RPCs failing 3× triggers a disconnect), leaving stale numbers on screen while the node-status banner stays hidden. No refresh-path changes were needed: `WalletState::last_balance_update` is already stamped only on a successful fetch (`network_refresh_service.cpp:1187`), so the badge just reads it and computes age against the same `std::time` clock (`util::formatTimeAgoShort`). Decision is a pure, unit-tested helper (`ui/staleness_badge.h::evaluateStalenessBadge`, thresholds 45s/180s) gated on `connected` so it never contradicts the banner; hover shows a "may be out of date — check your node connection" tooltip. Build-clean; `ctest` 1/1 (adds `testStalenessBadge`). **This closes P2 (5/5).**
|
||||||
|
- **Foundation QoL / Persistent node-status banner** — ☑ landed. A persistent horizontal strip now sits at the top of the content column whenever the wallet can't reach its node — distinct from the transient toasts, so an offline wallet is never silently mistaken for a working one. The show/severity/action decision is a pure function (`ui/node_status_banner.h` → `evaluateNodeStatusBanner`, unit-tested) fed a state snapshot by `App::renderNodeStatusBanner()`. Three cases: **full-node offline** (amber, "Reconnect" → `tryConnect`), **embedded daemon crashed & auto-restart gave up** (red, "Restart node" → `restartDaemon`), **lite wallet failed to open** (red, message-only). Suppressed during the wizard / wallet-switch / daemon-restart / screenshot-sweep / shutdown, and while an expected startup phase (warmup/init/connect-in-progress) already owns the screen. Height in `res/themes/ui.toml` (`banners.node-status`); colours from the material semantic palette; detail text ellipsis-clipped so it can't shove the action button off-screen. Build-clean; `ctest` 1/1 (added `testNodeStatusBanner`). **Remaining QoL:** persistent alert history, and the W6-2 refresh-staleness badge.
|
||||||
|
- **Foundation QoL / "Copy diagnostics" + "Open log folder"** — ☑ landed: Settings (logging section) now has two actions. **Open log folder** opens the config dir (`Platform::openFolder`) so users can actually find `dragonx-debug.log`/`dragonx-crash.log`. **Copy diagnostics** copies a plaintext support snapshot to the clipboard via the new `App::buildDiagnosticsReport()` — version, build variant, platform, connection status, active wallet path + existence + size, encryption/lock state, sync heights, daemon status/running/crash-count/lastError (full-node), and the log paths. No secrets. Build-clean; `ctest` 1/1. **Remaining QoL:** persistent alert history, a daemon/RPC error banner, and the W6-2 refresh-staleness badge.
|
||||||
|
- **Foundation / W7-2 · W7-3 · W7-4 (diagnostics infrastructure)** — ☑ landed (answers the original "easier to diagnose" ask — the logging/crash foundation now actually works):
|
||||||
|
- **W7-2 (Med, keystone):** the app-level `Logger` file sink was never initialized, so `LOG`/`LOGF`/`VERBOSE_LOGF` went nowhere and `dragonx-debug.log` didn't exist on Linux/macOS at all. `main()` now calls `Logger::init(<config>/dragonx-debug.log)` on all platforms. Also fixed a **latent deadlock** this exposed: `init()` wrote its banner via `write()`, which re-locks the non-recursive `mutex_` it already holds — now written directly. On Windows the raw stdout/stderr `freopen` was moved to a separate `dragonx-stdout.log` so the two writers don't contend. New `testLoggerFileSink` (also a deadlock guard — it would hang if that regressed).
|
||||||
|
- **W7-3 (Med):** no crash handler existed on Linux/macOS. Added an **async-signal-safe** `sigaction` handler (SIGSEGV/ABRT/BUS/FPE/ILL) that writes a signal id + `backtrace_symbols_fd` backtrace to `dragonx-crash.log`, then re-raises the default disposition for a core dump — the POSIX counterpart of the Windows SEH filter.
|
||||||
|
- **W7-4 (Low):** `Logger::init` now rotates the log to a single `.1` backup when it exceeds 10 MB, so a long/verbose session can't grow it unbounded.
|
||||||
|
Build-clean; `ctest` 1/1. **Remaining Foundation:** the QoL bundle (mostly UI) — "copy diagnostics for support", an "open log folder" action, persistent alert history, a daemon/RPC error banner, and the W6-2 refresh-staleness badge.
|
||||||
|
- **P2 / W5-1 · W5-2 · W6-1 · W6-3 (localized batch)** — ☑ landed:
|
||||||
|
- **W5-1 (Med):** `persistAfterBroadcast` (lite send/shield save) returned false on a persistent save failure but both callers discarded it and it never logged — completely silent. It now `liteLog`s the failure (the note re-derives on next sync, so it's a robustness gap, not fund loss).
|
||||||
|
- **W5-2 (Med):** the post-**sync** and post-**rescan** `save` results (in the detached scan threads) were ignored; both now `liteLog` on failure (`LiteDiagnostics::log` is mutex-guarded, safe from those threads).
|
||||||
|
- **W6-1 (Med):** `WalletState::clear()` didn't reset `mining`/`pool_mining`, so a wallet switch could briefly show the previous wallet's hashrate/blocks. Now reset in `clear()` (the daemon restarts on switch, so mining genuinely stops).
|
||||||
|
- **W6-3 (Low):** `AddressBook::load()` did `entries_.clear()` then threw on the first non-object element — discarding **every** contact. Now it guards `is_object()` + per-entry try/catch, skipping and counting malformed entries.
|
||||||
|
Build-clean; `ctest` 1/1. **Remaining P2:** W6-2 (surface refresh staleness — the timestamps exist in `WalletState`; this needs the UI "updated Xs ago" badge, which overlaps the diagnostics/QoL Foundation bundle).
|
||||||
|
- **P1-B / W1-3 + startup wallet-existence guard** — ☑ landed:
|
||||||
|
- **W1-3 (Med):** `syncedHere` was stamped in the `markOpened` block at bare connect (idHash still empty), letting a freshly-restored wallet skip its needed rescan. It's now stamped only once the identity is verified (idHash non-empty), so it takes effect at the post-address-refresh index update (`updateWalletIndexForActiveWallet` after addresses load), while `lastOpenedEpoch` still records at open.
|
||||||
|
- **Startup guard (the W1-1 launch counterpart):** `App::init` now `exists()`-checks the recorded active wallet before the daemon is configured; a **non-default** active wallet that was moved/deleted between sessions falls back to the default `wallet.dat` with a warning, instead of the daemon silently auto-creating an empty wallet under the missing name. Runs before the PIN-vault init so the vault is scoped to the wallet actually opened.
|
||||||
|
Build-clean; `ctest` 1/1.
|
||||||
|
- **P1-A / W3-3 (sweep opid persistence)** — ☑ **implemented + two rounds of adversarial review** (the "live mainnet run" the migration code mandates is the remaining gate — see below). The deferral's core fear (re-tracking a stale opid hangs forever) was **refuted by the code**: the opid poller (`app.cpp:1122`) + `parseOperationStatusPoll` classify a tracked opid absent from a *successful* `z_getoperationstatus` as stale, remove it, and fire the callback `ok=false` — a thrown RPC aborts the poll so there's never a *false* stale. So re-tracking yields at worst one clean failure, never a hang.
|
||||||
|
- **What landed:** a persisted `seed_migration_sweep_opid` setting; the opid is adopted **atomically** with clearing any prior txid in the *same* `settings.save()` **only once the submit succeeds** (torn-write safe; txid always outranks opid on resume). Resume routing is a pure, unit-tested helper (`data/seed_migration_resume.h::decideSeedMigrationResume`): txid → Confirming; opid **and connected** → re-track (`Sweeping`); otherwise → the dismissable Sweep gate. The shared `makeSweepCompletionCallback(resumed)`: success → Confirming; resumed-stale → Sweep gate (re-fetch balance, honest "may have already completed" copy); fresh-fail → Error.
|
||||||
|
- **Round 1 (design review, 4 skeptics)** confirmed both safety facts (no fund loss — adopt gate + never-deleted `.bak` untouched; no hang) and caught 3 real resume-UX traps, all fixed: a missing **connectivity gate** (would trap the user in the buttonless `Sweeping` spinner while offline), a **missing balance re-fetch** on the stale fallback (permanent "Checking balance…"), and honest messaging since a daemon restart makes even a *successful* sweep read "stale".
|
||||||
|
- **Round 2 (implementation review, 3 reviewers)** caught one regression — clearing the old txid at sweep *entry* would forget an already-mined first sweep if a remainder re-sweep's submit failed; fixed by the atomic-on-success swap above. All other fixes verified present + correct.
|
||||||
|
- **⚑ Remaining gate — live mainnet run (user):** per CLAUDE.md this fund-moving path must be exercised once on mainnet before it ships. The self-verifiable parts (build, unit test, both review rounds) are green; a real interrupted-sweep resume on mainnet is the human gate I cannot perform.
|
||||||
|
- **P1-B / W1-1 (+ W1-4) · W1-2 (wallet-file safety)** — ☑ landed:
|
||||||
|
- **W1-1 (High):** `switchToWallet` never checked the target wallet file exists, so a moved/deleted file "opened" as a fresh empty wallet (dragonxd auto-creates for a missing `-wallet=`), looking exactly like fund loss. It now `std::filesystem::exists`-checks `datadir + "/" + walletFile` before switching and blocks with a "not found (moved or deleted?)" warning. Placed before the daemon-stop prompt, and — since the check runs no matter how `switchToWallet` is invoked — it also **closes W1-4** (the stale-switcher-row TOCTOU).
|
||||||
|
- **W1-2 (Med):** `walletOutputLooksCorrupt` matched the generic "Error loading wallet" string, so a `DB_TOO_NEW` (newer-version) wallet was offered a `-salvagewallet` repair that can't fix it. Now the generic match is excluded when the output also contains "newer version".
|
||||||
|
Build-clean; `ctest` 1/1. **Remaining P1-B:** W1-3 (defer the `syncedHere` stamp to a verified readback) + the startup-path existence check (`app.cpp` hands `getActiveWalletFile()` to the daemon with no `exists()` check — same silent-empty-wallet risk as W1-1 but at launch).
|
||||||
|
- **P1-A / W3-1 · W3-2 · W3-4 (migrate-to-seed correctness)** — ☑ landed (fund-adjacent — reviewed carefully):
|
||||||
|
- **W3-1 (High):** `beginAdoptSeedWallet` hardcoded `datadir + "/wallet.dat"` as the file to swap. With a non-default active wallet (e.g. `wallet-2.dat`), that installed the swept seed wallet into an unloaded `wallet.dat` and left the daemon reloading the emptied legacy — funds only recoverable via the seed phrase. Now swaps `datadir + "/" + getActiveWalletFile()` (captured on the main thread; switching is blocked during migration so it can't race).
|
||||||
|
- **W3-2 (High):** `SeedWalletCreator::create` did `remove_all(<config>/seed-migrate)` unconditionally at the start. A prior migration that swept funds into the temp wallet but was abandoned/crashed before adopting would have that fund-bearing wallet destroyed. It now refuses (with a clear message) when `DRAGONX/wallet.dat` already exists — a completed migration removes the dir on adopt, so a leftover means an unfinished one.
|
||||||
|
- **W3-4 (Med):** `switchToWallet` only blocked switching while the migration *dialog* was open; closing it via "Later" mid-migration dropped the guard. Now also blocks while `getSeedMigrationPending()`.
|
||||||
|
Build-clean; `ctest` 1/1. **Remaining P1-A:** W3-3 (persist the sweep opid so an app-close mid-sweep can resume/re-poll instead of silently dropping the txid).
|
||||||
|
|
||||||
|
- **P0-B / W2-2 (deferred encryption silently lost) + W2-4 (auto-lock silent-fail)** — ☑ landed:
|
||||||
|
- **W2-2:** the wizard's deferred encryption was stored only in memory, so a quit/crash or a failed daemon connect before it applied left the wallet unencrypted with **no record it was ever requested** — the user believing it was encrypted. Now a persisted `encryption_pending` settings flag is set the moment encryption is requested (**never the passphrase** — only the fact). `refreshWalletEncryptionState()` reconciles it on every connect: wallet observed **encrypted** → clear the flag; wallet **not** encrypted while the flag is set and no deferred encryption is pending/in-flight → a once-per-session **"your wallet is NOT encrypted — open Settings to finish"** warning (the flag stays set, so it recurs each launch until resolved). We deliberately don't persist the passphrase to auto-complete — surfacing it is the secure choice.
|
||||||
|
- **W2-4:** `lockWallet()`'s continuation only handled success — a failed `walletlock` silently left the wallet **unlocked** (an unfulfilled auto-lock). It now logs and warns once (reset on the next successful lock), so a failing auto-lock is visible instead of leaving the wallet exposed.
|
||||||
|
Touches `settings.{h,cpp}`, `app_wizard.cpp`, `app_security.cpp`, `app.h`. Not unit-testable at this layer (RPC/connect-driven state machine); build-clean, `ctest` 1/1.
|
||||||
|
|
||||||
|
- **P0-A / W5-3 (lite create-time passphrase)** — ☑ landed (chose option **(b) wire it up**). The lite create/open/restore passphrase was collected but never consumed by the backend — a "passphrase" field that did nothing. It now has a real meaning for all three operations, in `LiteWalletController`: **create/restore** → `encryptWallet(passphrase)` (the backend encrypts + locks + saves the brand-new wallet); **open** → `unlockWallet(passphrase)`, but only when `encryptionStatus()` reports the existing wallet is actually encrypted+locked (skips a spurious unlock otherwise). Encrypt/unlock take their own copy and wipe it; a post-create encrypt failure is `liteLog`'d (the wallet still exists — the create isn't failed). Six existing lite-controller tests carried an incidental `hunter2` create passphrase from the dead-field era; removed (they test non-encryption flows and want an unencrypted wallet), and added `testLiteWalletControllerCreateEncryptsWithPassphrase` to prove the new behavior. Build-clean; `ctest` 1/1. *(Follow-up UX polish: `settings_page` could show the passphrase field's meaning per operation — "encrypt" for create/restore vs "unlock" for open.)*
|
||||||
|
- **P0-A / W4-5 (seed-backup file)** — ☑ landed (proportionate): the seed "Save" already wrote 0600 + zeroed the in-memory buffer, but the success message was a bare "Saved to <path>". It now reads "**Saved an UNENCRYPTED seed file — move it to secure offline storage and delete this copy**: <path>", so the plaintext-on-disk risk is called out. `i18n.cpp` (English source; `res/lang` back-fill of this changed key is deferred to the batch i18n pass). A stronger fix (pre-save confirmation, or dropping the file-save in favor of on-screen + Copy) is a follow-up UX decision.
|
||||||
|
- **P0-A / W4-1 · W4-3 · W2-3 (memzero cluster)** — ☑ landed, using the file's established `sodium_memzero` pattern (matching the existing lambda-capture scrub at app_network.cpp:2885 and JSON scrub at :4025) rather than a new type, since this is fund-moving code:
|
||||||
|
- **W4-1** `importPrivateKey`/`sweepPrivateKey`: the spending/viewing key is now scrubbed on all paths — the calling-frame copy (after the worker post), the worker-lambda's captured copy (lambda made `mutable`, zeroed after the request is sent), and the JSON request `params` copy.
|
||||||
|
- **W4-3** `exportAllKeys`/`backupWallet`: the concatenated all-keys buffer is zeroed after the consumer uses it, and the backup file is now written via `Platform::writeFileAtomically(..., restrictPermissions=true)` (atomic + 0600) instead of a umask-default `ofstream`.
|
||||||
|
- **W2-3** decrypt-wallet passphrase: `std::move`-captured into the worker lambda (so no plaintext copy is left in the calling frame) and `sodium_memzero`'d right after `unlockWallet` (its only use).
|
||||||
|
Not unit-testable (the scrubbing has no observable RPC effect — the key value sent to the daemon is unchanged; only post-use memory zeroing is added). Build-clean; `ctest` 1/1 (no regression). **Remaining in P0-A:** W5-3 (remove the dead lite `passphrase` field), W4-5 (predictable plaintext seed-backup file).
|
||||||
|
- **P0-A / W2-1** — ☑ landed: the decrypt-wallet flow now scrubs (best-effort in-place zero-overwrite) and removes the plaintext key export (`obsidiandecryptexport…`) as soon as the `z_importwallet` attempt resolves — success or failure — so a full cleartext dump of every private key is no longer left on disk forever. Recovery remains the encrypted backup (`wallet.dat.encrypted.bak`). `app_security.cpp` (after the import call). Not unit-testable (fs I/O in a deep lambda); build-clean, `ctest` 1/1 (no regression).
|
||||||
|
- **P0-A / W7-1** — ☑ landed: `RedactConsoleCommand`/`ConsoleCommandCarriesSecret` in `console_tab_helpers` redact secret-bearing commands (an allowlist of 13 first-tokens: `walletpassphrase`, `encryptwallet`, `z_importkey`, …) to `> walletpassphrase ****` before they hit the console echo AND the recall history; the real command still executes unredacted. Wired into `submitConsoleCommand` (`console_tab.cpp`). New `testConsoleSecretRedaction` (11 assertions). Clean build; `ctest` 1/1. (Output-secret commands like `z_exportkey` — result redaction — remain a follow-up.)
|
||||||
@@ -67,7 +67,8 @@
|
|||||||
//#define IMGUI_USE_LEGACY_CRC32_ADLER
|
//#define IMGUI_USE_LEGACY_CRC32_ADLER
|
||||||
|
|
||||||
//---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
//---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
||||||
//#define IMGUI_USE_WCHAR32
|
//---- Enabled so chat can render emoji (U+1F300+, above the BMP) — see Typography::loadFont emoji merge (Q12).
|
||||||
|
#define IMGUI_USE_WCHAR32
|
||||||
|
|
||||||
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||||
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
||||||
|
|||||||
744
libs/imgui/misc/freetype/imgui_freetype.cpp
Normal file
744
libs/imgui/misc/freetype/imgui_freetype.cpp
Normal file
@@ -0,0 +1,744 @@
|
|||||||
|
// dear imgui: FreeType font builder (used as a replacement for the stb_truetype builder)
|
||||||
|
// (code)
|
||||||
|
|
||||||
|
// Get the latest version at https://github.com/ocornut/imgui/tree/master/misc/freetype
|
||||||
|
// Original code by @vuhdo (Aleksei Skriabin) in 2017, with improvements by @mikesart.
|
||||||
|
// Maintained since 2019 by @ocornut.
|
||||||
|
|
||||||
|
// CHANGELOG
|
||||||
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2025/06/11: refactored for the new ImFontLoader architecture, and ImGuiBackendFlags_RendererHasTextures support.
|
||||||
|
// 2024/10/17: added plutosvg support for SVG Fonts (seems faster/better than lunasvg). Enable by using '#define IMGUI_ENABLE_FREETYPE_PLUTOSVG'. (#7927)
|
||||||
|
// 2023/11/13: added support for ImFontConfig::RasterizationDensity field for scaling render density without scaling metrics.
|
||||||
|
// 2023/08/01: added support for SVG fonts, enable by using '#define IMGUI_ENABLE_FREETYPE_LUNASVG'. (#6591)
|
||||||
|
// 2023/01/04: fixed a packing issue which in some occurrences would prevent large amount of glyphs from being packed correctly.
|
||||||
|
// 2021/08/23: fixed crash when FT_Render_Glyph() fails to render a glyph and returns nullptr.
|
||||||
|
// 2021/03/05: added ImGuiFreeTypeBuilderFlags_Bitmap to load bitmap glyphs.
|
||||||
|
// 2021/03/02: set 'atlas->TexPixelsUseColors = true' to help some backends with deciding of a preferred texture format.
|
||||||
|
// 2021/01/28: added support for color-layered glyphs via ImGuiFreeTypeBuilderFlags_LoadColor (require Freetype 2.10+).
|
||||||
|
// 2021/01/26: simplified integration by using '#define IMGUI_ENABLE_FREETYPE'. renamed ImGuiFreeType::XXX flags to ImGuiFreeTypeBuilderFlags_XXX for consistency with other API. removed ImGuiFreeType::BuildFontAtlas().
|
||||||
|
// 2020/06/04: fix for rare case where FT_Get_Char_Index() succeed but FT_Load_Glyph() fails.
|
||||||
|
// 2019/02/09: added RasterizerFlags::Monochrome flag to disable font anti-aliasing (combine with ::MonoHinting for best results!)
|
||||||
|
// 2019/01/15: added support for imgui allocators + added FreeType only override function SetAllocatorFunctions().
|
||||||
|
// 2019/01/10: re-factored to match big update in STB builder. fixed texture height waste. fixed redundant glyphs when merging. support for glyph padding.
|
||||||
|
// 2018/06/08: added support for ImFontConfig::GlyphMinAdvanceX, GlyphMaxAdvanceX.
|
||||||
|
// 2018/02/04: moved to main imgui repository (away from http://www.github.com/ocornut/imgui_club)
|
||||||
|
// 2018/01/22: fix for addition of ImFontAtlas::TexUvscale member.
|
||||||
|
// 2017/10/22: minor inconsequential change to match change in master (removed an unnecessary statement).
|
||||||
|
// 2017/09/26: fixes for imgui internal changes.
|
||||||
|
// 2017/08/26: cleanup, optimizations, support for ImFontConfig::RasterizerFlags, ImFontConfig::RasterizerMultiply.
|
||||||
|
// 2017/08/16: imported from https://github.com/Vuhdo/imgui_freetype into http://www.github.com/ocornut/imgui_club, updated for latest changes in ImFontAtlas, minor tweaks.
|
||||||
|
|
||||||
|
// About Gamma Correct Blending:
|
||||||
|
// - FreeType assumes blending in linear space rather than gamma space.
|
||||||
|
// - See https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Render_Glyph
|
||||||
|
// - For correct results you need to be using sRGB and convert to linear space in the pixel shader output.
|
||||||
|
// - The default dear imgui styles will be impacted by this change (alpha values will need tweaking).
|
||||||
|
|
||||||
|
// FIXME: cfg.OversampleH, OversampleV are not supported, but generally not necessary with this rasterizer because Hinting makes everything look better.
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
#include "imgui_freetype.h"
|
||||||
|
#include "imgui_internal.h" // ImMin,ImMax,ImFontAtlasBuild*,
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ft2build.h>
|
||||||
|
#include FT_FREETYPE_H // <freetype/freetype.h>
|
||||||
|
#include FT_MODULE_H // <freetype/ftmodapi.h>
|
||||||
|
#include FT_GLYPH_H // <freetype/ftglyph.h>
|
||||||
|
#include FT_SIZES_H // <freetype/ftsizes.h>
|
||||||
|
#include FT_SYNTHESIS_H // <freetype/ftsynth.h>
|
||||||
|
|
||||||
|
// Handle LunaSVG and PlutoSVG
|
||||||
|
#if defined(IMGUI_ENABLE_FREETYPE_LUNASVG) && defined(IMGUI_ENABLE_FREETYPE_PLUTOSVG)
|
||||||
|
#error "Cannot enable both IMGUI_ENABLE_FREETYPE_LUNASVG and IMGUI_ENABLE_FREETYPE_PLUTOSVG"
|
||||||
|
#endif
|
||||||
|
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||||
|
#include FT_OTSVG_H // <freetype/otsvg.h>
|
||||||
|
#include FT_BBOX_H // <freetype/ftbbox.h>
|
||||||
|
#include <lunasvg.h>
|
||||||
|
#endif
|
||||||
|
#ifdef IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
||||||
|
#include <plutosvg.h>
|
||||||
|
#endif
|
||||||
|
#if defined(IMGUI_ENABLE_FREETYPE_LUNASVG) || defined (IMGUI_ENABLE_FREETYPE_PLUTOSVG)
|
||||||
|
#if !((FREETYPE_MAJOR >= 2) && (FREETYPE_MINOR >= 12))
|
||||||
|
#error IMGUI_ENABLE_FREETYPE_PLUTOSVG or IMGUI_ENABLE_FREETYPE_LUNASVG requires FreeType version >= 2.12
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (push)
|
||||||
|
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
|
||||||
|
#pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
|
||||||
|
#pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
|
||||||
|
#ifndef __clang__
|
||||||
|
#pragma GCC diagnostic ignored "-Wsubobject-linkage" // warning: 'xxxx' has a field 'xxxx' whose type uses the anonymous namespace
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Data
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Default memory allocators
|
||||||
|
static void* ImGuiFreeTypeDefaultAllocFunc(size_t size, void* user_data) { IM_UNUSED(user_data); return IM_ALLOC(size); }
|
||||||
|
static void ImGuiFreeTypeDefaultFreeFunc(void* ptr, void* user_data) { IM_UNUSED(user_data); IM_FREE(ptr); }
|
||||||
|
|
||||||
|
// Current memory allocators
|
||||||
|
static void* (*GImGuiFreeTypeAllocFunc)(size_t size, void* user_data) = ImGuiFreeTypeDefaultAllocFunc;
|
||||||
|
static void (*GImGuiFreeTypeFreeFunc)(void* ptr, void* user_data) = ImGuiFreeTypeDefaultFreeFunc;
|
||||||
|
static void* GImGuiFreeTypeAllocatorUserData = nullptr;
|
||||||
|
|
||||||
|
// Lunasvg support
|
||||||
|
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||||
|
static FT_Error ImGuiLunasvgPortInit(FT_Pointer* state);
|
||||||
|
static void ImGuiLunasvgPortFree(FT_Pointer* state);
|
||||||
|
static FT_Error ImGuiLunasvgPortRender(FT_GlyphSlot slot, FT_Pointer* _state);
|
||||||
|
static FT_Error ImGuiLunasvgPortPresetSlot(FT_GlyphSlot slot, FT_Bool cache, FT_Pointer* _state);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Code
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define FT_CEIL(X) (((X + 63) & -64) / 64) // From SDL_ttf: Handy routines for converting from fixed point
|
||||||
|
#define FT_SCALEFACTOR 64.0f
|
||||||
|
|
||||||
|
// Glyph metrics:
|
||||||
|
// --------------
|
||||||
|
//
|
||||||
|
// xmin xmax
|
||||||
|
// | |
|
||||||
|
// |<-------- width -------->|
|
||||||
|
// | |
|
||||||
|
// | +-------------------------+----------------- ymax
|
||||||
|
// | | ggggggggg ggggg | ^ ^
|
||||||
|
// | | g:::::::::ggg::::g | | |
|
||||||
|
// | | g:::::::::::::::::g | | |
|
||||||
|
// | | g::::::ggggg::::::gg | | |
|
||||||
|
// | | g:::::g g:::::g | | |
|
||||||
|
// offsetX -|-------->| g:::::g g:::::g | offsetY |
|
||||||
|
// | | g:::::g g:::::g | | |
|
||||||
|
// | | g::::::g g:::::g | | |
|
||||||
|
// | | g:::::::ggggg:::::g | | |
|
||||||
|
// | | g::::::::::::::::g | | height
|
||||||
|
// | | gg::::::::::::::g | | |
|
||||||
|
// baseline ---*---------|---- gggggggg::::::g-----*-------- |
|
||||||
|
// / | | g:::::g | |
|
||||||
|
// origin | | gggggg g:::::g | |
|
||||||
|
// | | g:::::gg gg:::::g | |
|
||||||
|
// | | g::::::ggg:::::::g | |
|
||||||
|
// | | gg:::::::::::::g | |
|
||||||
|
// | | ggg::::::ggg | |
|
||||||
|
// | | gggggg | v
|
||||||
|
// | +-------------------------+----------------- ymin
|
||||||
|
// | |
|
||||||
|
// |------------- advanceX ----------->|
|
||||||
|
|
||||||
|
// Stored in ImFontAtlas::FontLoaderData. ALLOCATED BY US.
|
||||||
|
struct ImGui_ImplFreeType_Data
|
||||||
|
{
|
||||||
|
FT_Library Library;
|
||||||
|
FT_MemoryRec_ MemoryManager;
|
||||||
|
ImGui_ImplFreeType_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Stored in ImFontConfig::FontLoaderData. ALLOCATED BY US.
|
||||||
|
struct ImGui_ImplFreeType_FontSrcData
|
||||||
|
{
|
||||||
|
// Initialize from an external data buffer. Doesn't copy data, and you must ensure it stays valid up to this object lifetime.
|
||||||
|
bool InitFont(FT_Library ft_library, const ImFontConfig* src, ImGuiFreeTypeLoaderFlags extra_user_flags);
|
||||||
|
void CloseFont();
|
||||||
|
ImGui_ImplFreeType_FontSrcData() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
|
~ImGui_ImplFreeType_FontSrcData() { CloseFont(); }
|
||||||
|
|
||||||
|
// Members
|
||||||
|
FT_Face FtFace;
|
||||||
|
ImGuiFreeTypeLoaderFlags UserFlags; // = ImFontConfig::FontLoaderFlags
|
||||||
|
FT_Int32 LoadFlags;
|
||||||
|
ImFontBaked* BakedLastActivated;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Stored in ImFontBaked::FontLoaderDatas: pointer to SourcesCount instances of this. ALLOCATED BY CORE.
|
||||||
|
struct ImGui_ImplFreeType_FontSrcBakedData
|
||||||
|
{
|
||||||
|
FT_Size FtSize; // This represent a FT_Face with a given size.
|
||||||
|
ImGui_ImplFreeType_FontSrcBakedData() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ImGui_ImplFreeType_FontSrcData::InitFont(FT_Library ft_library, const ImFontConfig* src, ImGuiFreeTypeLoaderFlags extra_font_loader_flags)
|
||||||
|
{
|
||||||
|
FT_Error error = FT_New_Memory_Face(ft_library, (const FT_Byte*)src->FontData, (FT_Long)src->FontDataSize, (FT_Long)src->FontNo, &FtFace);
|
||||||
|
if (error != 0)
|
||||||
|
return false;
|
||||||
|
error = FT_Select_Charmap(FtFace, FT_ENCODING_UNICODE);
|
||||||
|
if (error != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Convert to FreeType flags (NB: Bold and Oblique are processed separately)
|
||||||
|
UserFlags = (ImGuiFreeTypeLoaderFlags)(src->FontLoaderFlags | extra_font_loader_flags);
|
||||||
|
|
||||||
|
LoadFlags = 0;
|
||||||
|
if ((UserFlags & ImGuiFreeTypeLoaderFlags_Bitmap) == 0)
|
||||||
|
LoadFlags |= FT_LOAD_NO_BITMAP;
|
||||||
|
if (UserFlags & ImGuiFreeTypeLoaderFlags_NoHinting)
|
||||||
|
LoadFlags |= FT_LOAD_NO_HINTING;
|
||||||
|
if (UserFlags & ImGuiFreeTypeLoaderFlags_NoAutoHint)
|
||||||
|
LoadFlags |= FT_LOAD_NO_AUTOHINT;
|
||||||
|
if (UserFlags & ImGuiFreeTypeLoaderFlags_ForceAutoHint)
|
||||||
|
LoadFlags |= FT_LOAD_FORCE_AUTOHINT;
|
||||||
|
if (UserFlags & ImGuiFreeTypeLoaderFlags_LightHinting)
|
||||||
|
LoadFlags |= FT_LOAD_TARGET_LIGHT;
|
||||||
|
else if (UserFlags & ImGuiFreeTypeLoaderFlags_MonoHinting)
|
||||||
|
LoadFlags |= FT_LOAD_TARGET_MONO;
|
||||||
|
else
|
||||||
|
LoadFlags |= FT_LOAD_TARGET_NORMAL;
|
||||||
|
|
||||||
|
if (UserFlags & ImGuiFreeTypeLoaderFlags_LoadColor)
|
||||||
|
LoadFlags |= FT_LOAD_COLOR;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplFreeType_FontSrcData::CloseFont()
|
||||||
|
{
|
||||||
|
if (FtFace)
|
||||||
|
{
|
||||||
|
FT_Done_Face(FtFace);
|
||||||
|
FtFace = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const FT_Glyph_Metrics* ImGui_ImplFreeType_LoadGlyph(ImGui_ImplFreeType_FontSrcData* src_data, uint32_t codepoint)
|
||||||
|
{
|
||||||
|
uint32_t glyph_index = FT_Get_Char_Index(src_data->FtFace, codepoint);
|
||||||
|
if (glyph_index == 0)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
// If this crash for you: FreeType 2.11.0 has a crash bug on some bitmap/colored fonts.
|
||||||
|
// - https://gitlab.freedesktop.org/freetype/freetype/-/issues/1076
|
||||||
|
// - https://github.com/ocornut/imgui/issues/4567
|
||||||
|
// - https://github.com/ocornut/imgui/issues/4566
|
||||||
|
// You can use FreeType 2.10, or the patched version of 2.11.0 in VcPkg, or probably any upcoming FreeType version.
|
||||||
|
FT_Error error = FT_Load_Glyph(src_data->FtFace, glyph_index, src_data->LoadFlags);
|
||||||
|
if (error)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
// Need an outline for this to work
|
||||||
|
FT_GlyphSlot slot = src_data->FtFace->glyph;
|
||||||
|
#if defined(IMGUI_ENABLE_FREETYPE_LUNASVG) || defined(IMGUI_ENABLE_FREETYPE_PLUTOSVG)
|
||||||
|
IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP || slot->format == FT_GLYPH_FORMAT_SVG);
|
||||||
|
#else
|
||||||
|
#if ((FREETYPE_MAJOR >= 2) && (FREETYPE_MINOR >= 12))
|
||||||
|
IM_ASSERT(slot->format != FT_GLYPH_FORMAT_SVG && "The font contains SVG glyphs, you'll need to enable IMGUI_ENABLE_FREETYPE_PLUTOSVG or IMGUI_ENABLE_FREETYPE_LUNASVG in imconfig.h and install required libraries in order to use this font");
|
||||||
|
#endif
|
||||||
|
IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP);
|
||||||
|
#endif // IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||||
|
|
||||||
|
// Apply convenience transform (this is not picking from real "Bold"/"Italic" fonts! Merely applying FreeType helper transform. Oblique == Slanting)
|
||||||
|
if (src_data->UserFlags & ImGuiFreeTypeLoaderFlags_Bold)
|
||||||
|
FT_GlyphSlot_Embolden(slot);
|
||||||
|
if (src_data->UserFlags & ImGuiFreeTypeLoaderFlags_Oblique)
|
||||||
|
{
|
||||||
|
FT_GlyphSlot_Oblique(slot);
|
||||||
|
//FT_BBox bbox;
|
||||||
|
//FT_Outline_Get_BBox(&slot->outline, &bbox);
|
||||||
|
//slot->metrics.width = bbox.xMax - bbox.xMin;
|
||||||
|
//slot->metrics.height = bbox.yMax - bbox.yMin;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &slot->metrics;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplFreeType_BlitGlyph(const FT_Bitmap* ft_bitmap, uint32_t* dst, uint32_t dst_pitch)
|
||||||
|
{
|
||||||
|
IM_ASSERT(ft_bitmap != nullptr);
|
||||||
|
const uint32_t w = ft_bitmap->width;
|
||||||
|
const uint32_t h = ft_bitmap->rows;
|
||||||
|
const uint8_t* src = ft_bitmap->buffer;
|
||||||
|
const uint32_t src_pitch = ft_bitmap->pitch;
|
||||||
|
|
||||||
|
switch (ft_bitmap->pixel_mode)
|
||||||
|
{
|
||||||
|
case FT_PIXEL_MODE_GRAY: // Grayscale image, 1 byte per pixel.
|
||||||
|
{
|
||||||
|
for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
|
||||||
|
for (uint32_t x = 0; x < w; x++)
|
||||||
|
dst[x] = IM_COL32(255, 255, 255, src[x]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FT_PIXEL_MODE_MONO: // Monochrome image, 1 bit per pixel. The bits in each byte are ordered from MSB to LSB.
|
||||||
|
{
|
||||||
|
for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
|
||||||
|
{
|
||||||
|
uint8_t bits = 0;
|
||||||
|
const uint8_t* bits_ptr = src;
|
||||||
|
for (uint32_t x = 0; x < w; x++, bits <<= 1)
|
||||||
|
{
|
||||||
|
if ((x & 7) == 0)
|
||||||
|
bits = *bits_ptr++;
|
||||||
|
dst[x] = IM_COL32(255, 255, 255, (bits & 0x80) ? 255 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FT_PIXEL_MODE_BGRA:
|
||||||
|
{
|
||||||
|
// FIXME: Converting pre-multiplied alpha to straight. Doesn't smell good.
|
||||||
|
#define DE_MULTIPLY(color, alpha) ImMin((ImU32)(255.0f * (float)color / (float)(alpha + FLT_MIN) + 0.5f), 255u)
|
||||||
|
for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
|
||||||
|
for (uint32_t x = 0; x < w; x++)
|
||||||
|
{
|
||||||
|
uint8_t r = src[x * 4 + 2], g = src[x * 4 + 1], b = src[x * 4], a = src[x * 4 + 3];
|
||||||
|
dst[x] = IM_COL32(DE_MULTIPLY(r, a), DE_MULTIPLY(g, a), DE_MULTIPLY(b, a), a);
|
||||||
|
}
|
||||||
|
#undef DE_MULTIPLY
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
IM_ASSERT(0 && "FreeTypeFont::BlitGlyph(): Unknown bitmap pixel mode!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FreeType memory allocation callbacks
|
||||||
|
static void* FreeType_Alloc(FT_Memory /*memory*/, long size)
|
||||||
|
{
|
||||||
|
return GImGuiFreeTypeAllocFunc((size_t)size, GImGuiFreeTypeAllocatorUserData);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FreeType_Free(FT_Memory /*memory*/, void* block)
|
||||||
|
{
|
||||||
|
GImGuiFreeTypeFreeFunc(block, GImGuiFreeTypeAllocatorUserData);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void* FreeType_Realloc(FT_Memory /*memory*/, long cur_size, long new_size, void* block)
|
||||||
|
{
|
||||||
|
// Implement realloc() as we don't ask user to provide it.
|
||||||
|
if (block == nullptr)
|
||||||
|
return GImGuiFreeTypeAllocFunc((size_t)new_size, GImGuiFreeTypeAllocatorUserData);
|
||||||
|
|
||||||
|
if (new_size == 0)
|
||||||
|
{
|
||||||
|
GImGuiFreeTypeFreeFunc(block, GImGuiFreeTypeAllocatorUserData);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_size > cur_size)
|
||||||
|
{
|
||||||
|
void* new_block = GImGuiFreeTypeAllocFunc((size_t)new_size, GImGuiFreeTypeAllocatorUserData);
|
||||||
|
memcpy(new_block, block, (size_t)cur_size);
|
||||||
|
GImGuiFreeTypeFreeFunc(block, GImGuiFreeTypeAllocatorUserData);
|
||||||
|
return new_block;
|
||||||
|
}
|
||||||
|
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ImGui_ImplFreeType_LoaderInit(ImFontAtlas* atlas)
|
||||||
|
{
|
||||||
|
IM_ASSERT(atlas->FontLoaderData == nullptr);
|
||||||
|
ImGui_ImplFreeType_Data* bd = IM_NEW(ImGui_ImplFreeType_Data)();
|
||||||
|
|
||||||
|
// FreeType memory management: https://www.freetype.org/freetype2/docs/design/design-4.html
|
||||||
|
bd->MemoryManager.user = nullptr;
|
||||||
|
bd->MemoryManager.alloc = &FreeType_Alloc;
|
||||||
|
bd->MemoryManager.free = &FreeType_Free;
|
||||||
|
bd->MemoryManager.realloc = &FreeType_Realloc;
|
||||||
|
|
||||||
|
// https://www.freetype.org/freetype2/docs/reference/ft2-module_management.html#FT_New_Library
|
||||||
|
FT_Error error = FT_New_Library(&bd->MemoryManager, &bd->Library);
|
||||||
|
if (error != 0)
|
||||||
|
{
|
||||||
|
IM_DELETE(bd);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If you don't call FT_Add_Default_Modules() the rest of code may work, but FreeType won't use our custom allocator.
|
||||||
|
FT_Add_Default_Modules(bd->Library);
|
||||||
|
|
||||||
|
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||||
|
// Install svg hooks for FreeType
|
||||||
|
// https://freetype.org/freetype2/docs/reference/ft2-properties.html#svg-hooks
|
||||||
|
// https://freetype.org/freetype2/docs/reference/ft2-svg_fonts.html#svg_fonts
|
||||||
|
SVG_RendererHooks hooks = { ImGuiLunasvgPortInit, ImGuiLunasvgPortFree, ImGuiLunasvgPortRender, ImGuiLunasvgPortPresetSlot };
|
||||||
|
FT_Property_Set(bd->Library, "ot-svg", "svg-hooks", &hooks);
|
||||||
|
#endif // IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||||
|
#ifdef IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
||||||
|
// With plutosvg, use provided hooks
|
||||||
|
FT_Property_Set(bd->Library, "ot-svg", "svg-hooks", plutosvg_ft_svg_hooks());
|
||||||
|
#endif // IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
||||||
|
|
||||||
|
// Store our data
|
||||||
|
atlas->FontLoaderData = (void*)bd;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplFreeType_LoaderShutdown(ImFontAtlas* atlas)
|
||||||
|
{
|
||||||
|
ImGui_ImplFreeType_Data* bd = (ImGui_ImplFreeType_Data*)atlas->FontLoaderData;
|
||||||
|
IM_ASSERT(bd != nullptr);
|
||||||
|
FT_Done_Library(bd->Library);
|
||||||
|
IM_DELETE(bd);
|
||||||
|
atlas->FontLoaderData = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ImGui_ImplFreeType_FontSrcInit(ImFontAtlas* atlas, ImFontConfig* src)
|
||||||
|
{
|
||||||
|
ImGui_ImplFreeType_Data* bd = (ImGui_ImplFreeType_Data*)atlas->FontLoaderData;
|
||||||
|
ImGui_ImplFreeType_FontSrcData* bd_font_data = IM_NEW(ImGui_ImplFreeType_FontSrcData);
|
||||||
|
IM_ASSERT(src->FontLoaderData == nullptr);
|
||||||
|
src->FontLoaderData = bd_font_data;
|
||||||
|
|
||||||
|
if (!bd_font_data->InitFont(bd->Library, src, (ImGuiFreeTypeLoaderFlags)atlas->FontLoaderFlags))
|
||||||
|
{
|
||||||
|
IM_DELETE(bd_font_data);
|
||||||
|
src->FontLoaderData = nullptr;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplFreeType_FontSrcDestroy(ImFontAtlas* atlas, ImFontConfig* src)
|
||||||
|
{
|
||||||
|
IM_UNUSED(atlas);
|
||||||
|
ImGui_ImplFreeType_FontSrcData* bd_font_data = (ImGui_ImplFreeType_FontSrcData*)src->FontLoaderData;
|
||||||
|
IM_DELETE(bd_font_data);
|
||||||
|
src->FontLoaderData = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ImGui_ImplFreeType_FontBakedInit(ImFontAtlas* atlas, ImFontConfig* src, ImFontBaked* baked, void* loader_data_for_baked_src)
|
||||||
|
{
|
||||||
|
IM_UNUSED(atlas);
|
||||||
|
float size = baked->Size;
|
||||||
|
if (src->MergeMode && src->SizePixels != 0.0f)
|
||||||
|
size *= (src->SizePixels / baked->OwnerFont->Sources[0]->SizePixels);
|
||||||
|
size *= src->ExtraSizeScale;
|
||||||
|
|
||||||
|
ImGui_ImplFreeType_FontSrcData* bd_font_data = (ImGui_ImplFreeType_FontSrcData*)src->FontLoaderData;
|
||||||
|
bd_font_data->BakedLastActivated = baked;
|
||||||
|
|
||||||
|
// We use one FT_Size per (source + baked) combination.
|
||||||
|
ImGui_ImplFreeType_FontSrcBakedData* bd_baked_data = (ImGui_ImplFreeType_FontSrcBakedData*)loader_data_for_baked_src;
|
||||||
|
IM_ASSERT(bd_baked_data != nullptr);
|
||||||
|
IM_PLACEMENT_NEW(bd_baked_data) ImGui_ImplFreeType_FontSrcBakedData();
|
||||||
|
|
||||||
|
FT_New_Size(bd_font_data->FtFace, &bd_baked_data->FtSize);
|
||||||
|
FT_Activate_Size(bd_baked_data->FtSize);
|
||||||
|
|
||||||
|
// Vuhdo 2017: "I'm not sure how to deal with font sizes properly. As far as I understand, currently ImGui assumes that the 'pixel_height'
|
||||||
|
// is a maximum height of an any given glyph, i.e. it's the sum of font's ascender and descender. Seems strange to me.
|
||||||
|
// FT_Set_Pixel_Sizes() doesn't seem to get us the same result."
|
||||||
|
// (FT_Set_Pixel_Sizes() essentially calls FT_Request_Size() with FT_SIZE_REQUEST_TYPE_NOMINAL)
|
||||||
|
const float rasterizer_density = src->RasterizerDensity * baked->RasterizerDensity;
|
||||||
|
FT_Size_RequestRec req;
|
||||||
|
req.type = (bd_font_data->UserFlags & ImGuiFreeTypeLoaderFlags_Bitmap) ? FT_SIZE_REQUEST_TYPE_NOMINAL : FT_SIZE_REQUEST_TYPE_REAL_DIM;
|
||||||
|
req.width = 0;
|
||||||
|
req.height = (uint32_t)(size * 64 * rasterizer_density);
|
||||||
|
req.horiResolution = 0;
|
||||||
|
req.vertResolution = 0;
|
||||||
|
FT_Request_Size(bd_font_data->FtFace, &req);
|
||||||
|
|
||||||
|
// Output
|
||||||
|
if (src->MergeMode == false)
|
||||||
|
{
|
||||||
|
// Read metrics
|
||||||
|
FT_Size_Metrics metrics = bd_baked_data->FtSize->metrics;
|
||||||
|
const float scale = 1.0f / (rasterizer_density * src->ExtraSizeScale);
|
||||||
|
baked->Ascent = (float)FT_CEIL(metrics.ascender) * scale; // The pixel extents above the baseline in pixels (typically positive).
|
||||||
|
baked->Descent = (float)FT_CEIL(metrics.descender) * scale; // The extents below the baseline in pixels (typically negative).
|
||||||
|
//LineSpacing = (float)FT_CEIL(metrics.height) * scale; // The baseline-to-baseline distance. Note that it usually is larger than the sum of the ascender and descender taken as absolute values. There is also no guarantee that no glyphs extend above or below subsequent baselines when using this distance. Think of it as a value the designer of the font finds appropriate.
|
||||||
|
//LineGap = (float)FT_CEIL(metrics.height - metrics.ascender + metrics.descender) * scale; // The spacing in pixels between one row's descent and the next row's ascent.
|
||||||
|
//MaxAdvanceWidth = (float)FT_CEIL(metrics.max_advance) * scale; // This field gives the maximum horizontal cursor advance for all glyphs in the font.
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplFreeType_FontBakedDestroy(ImFontAtlas* atlas, ImFontConfig* src, ImFontBaked* baked, void* loader_data_for_baked_src)
|
||||||
|
{
|
||||||
|
IM_UNUSED(atlas);
|
||||||
|
IM_UNUSED(baked);
|
||||||
|
IM_UNUSED(src);
|
||||||
|
ImGui_ImplFreeType_FontSrcBakedData* bd_baked_data = (ImGui_ImplFreeType_FontSrcBakedData*)loader_data_for_baked_src;
|
||||||
|
IM_ASSERT(bd_baked_data != nullptr);
|
||||||
|
FT_Done_Size(bd_baked_data->FtSize);
|
||||||
|
bd_baked_data->~ImGui_ImplFreeType_FontSrcBakedData(); // ~IM_PLACEMENT_DELETE()
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ImGui_ImplFreeType_FontBakedLoadGlyph(ImFontAtlas* atlas, ImFontConfig* src, ImFontBaked* baked, void* loader_data_for_baked_src, ImWchar codepoint, ImFontGlyph* out_glyph, float* out_advance_x)
|
||||||
|
{
|
||||||
|
ImGui_ImplFreeType_FontSrcData* bd_font_data = (ImGui_ImplFreeType_FontSrcData*)src->FontLoaderData;
|
||||||
|
uint32_t glyph_index = FT_Get_Char_Index(bd_font_data->FtFace, codepoint);
|
||||||
|
if (glyph_index == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (bd_font_data->BakedLastActivated != baked) // <-- could use id
|
||||||
|
{
|
||||||
|
// Activate current size
|
||||||
|
ImGui_ImplFreeType_FontSrcBakedData* bd_baked_data = (ImGui_ImplFreeType_FontSrcBakedData*)loader_data_for_baked_src;
|
||||||
|
FT_Activate_Size(bd_baked_data->FtSize);
|
||||||
|
bd_font_data->BakedLastActivated = baked;
|
||||||
|
}
|
||||||
|
|
||||||
|
const FT_Glyph_Metrics* metrics = ImGui_ImplFreeType_LoadGlyph(bd_font_data, codepoint);
|
||||||
|
if (metrics == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
FT_Face face = bd_font_data->FtFace;
|
||||||
|
FT_GlyphSlot slot = face->glyph;
|
||||||
|
const float rasterizer_density = src->RasterizerDensity * baked->RasterizerDensity;
|
||||||
|
|
||||||
|
// Load metrics only mode
|
||||||
|
const float advance_x = (slot->advance.x / FT_SCALEFACTOR) / rasterizer_density;
|
||||||
|
if (out_advance_x != NULL)
|
||||||
|
{
|
||||||
|
IM_ASSERT(out_glyph == NULL);
|
||||||
|
*out_advance_x = advance_x;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render glyph into a bitmap (currently held by FreeType)
|
||||||
|
FT_Render_Mode render_mode = (bd_font_data->UserFlags & ImGuiFreeTypeLoaderFlags_Monochrome) ? FT_RENDER_MODE_MONO : FT_RENDER_MODE_NORMAL;
|
||||||
|
FT_Error error = FT_Render_Glyph(slot, render_mode);
|
||||||
|
const FT_Bitmap* ft_bitmap = &slot->bitmap;
|
||||||
|
if (error != 0 || ft_bitmap == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const int w = (int)ft_bitmap->width;
|
||||||
|
const int h = (int)ft_bitmap->rows;
|
||||||
|
const bool is_visible = (w != 0 && h != 0);
|
||||||
|
|
||||||
|
// Prepare glyph
|
||||||
|
out_glyph->Codepoint = codepoint;
|
||||||
|
out_glyph->AdvanceX = advance_x;
|
||||||
|
|
||||||
|
// Pack and retrieve position inside texture atlas
|
||||||
|
if (is_visible)
|
||||||
|
{
|
||||||
|
ImFontAtlasRectId pack_id = ImFontAtlasPackAddRect(atlas, w, h);
|
||||||
|
if (pack_id == ImFontAtlasRectId_Invalid)
|
||||||
|
{
|
||||||
|
// Pathological out of memory case (TexMaxWidth/TexMaxHeight set too small?)
|
||||||
|
IM_ASSERT(pack_id != ImFontAtlasRectId_Invalid && "Out of texture memory.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ImTextureRect* r = ImFontAtlasPackGetRect(atlas, pack_id);
|
||||||
|
|
||||||
|
// Render pixels to our temporary buffer
|
||||||
|
atlas->Builder->TempBuffer.resize(w * h * 4);
|
||||||
|
uint32_t* temp_buffer = (uint32_t*)atlas->Builder->TempBuffer.Data;
|
||||||
|
ImGui_ImplFreeType_BlitGlyph(ft_bitmap, temp_buffer, w);
|
||||||
|
|
||||||
|
const float ref_size = baked->OwnerFont->Sources[0]->SizePixels;
|
||||||
|
const float offsets_scale = (ref_size != 0.0f) ? (baked->Size / ref_size) : 1.0f;
|
||||||
|
float font_off_x = ImFloor(src->GlyphOffset.x * offsets_scale + 0.5f); // Snap scaled offset.
|
||||||
|
float font_off_y = ImFloor(src->GlyphOffset.y * offsets_scale + 0.5f) + baked->Ascent;
|
||||||
|
float recip_h = 1.0f / rasterizer_density;
|
||||||
|
float recip_v = 1.0f / rasterizer_density;
|
||||||
|
|
||||||
|
// Register glyph
|
||||||
|
float glyph_off_x = (float)face->glyph->bitmap_left;
|
||||||
|
float glyph_off_y = (float)-face->glyph->bitmap_top;
|
||||||
|
out_glyph->X0 = glyph_off_x * recip_h + font_off_x;
|
||||||
|
out_glyph->Y0 = glyph_off_y * recip_v + font_off_y;
|
||||||
|
out_glyph->X1 = (glyph_off_x + w) * recip_h + font_off_x;
|
||||||
|
out_glyph->Y1 = (glyph_off_y + h) * recip_v + font_off_y;
|
||||||
|
out_glyph->Visible = true;
|
||||||
|
out_glyph->Colored = (ft_bitmap->pixel_mode == FT_PIXEL_MODE_BGRA);
|
||||||
|
out_glyph->PackId = pack_id;
|
||||||
|
ImFontAtlasBakedSetFontGlyphBitmap(atlas, baked, src, out_glyph, r, (const unsigned char*)temp_buffer, ImTextureFormat_RGBA32, w * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ImGui_ImplFreetype_FontSrcContainsGlyph(ImFontAtlas* atlas, ImFontConfig* src, ImWchar codepoint)
|
||||||
|
{
|
||||||
|
IM_UNUSED(atlas);
|
||||||
|
ImGui_ImplFreeType_FontSrcData* bd_font_data = (ImGui_ImplFreeType_FontSrcData*)src->FontLoaderData;
|
||||||
|
int glyph_index = FT_Get_Char_Index(bd_font_data->FtFace, codepoint);
|
||||||
|
return glyph_index != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ImFontLoader* ImGuiFreeType::GetFontLoader()
|
||||||
|
{
|
||||||
|
static ImFontLoader loader;
|
||||||
|
loader.Name = "FreeType";
|
||||||
|
loader.LoaderInit = ImGui_ImplFreeType_LoaderInit;
|
||||||
|
loader.LoaderShutdown = ImGui_ImplFreeType_LoaderShutdown;
|
||||||
|
loader.FontSrcInit = ImGui_ImplFreeType_FontSrcInit;
|
||||||
|
loader.FontSrcDestroy = ImGui_ImplFreeType_FontSrcDestroy;
|
||||||
|
loader.FontSrcContainsGlyph = ImGui_ImplFreetype_FontSrcContainsGlyph;
|
||||||
|
loader.FontBakedInit = ImGui_ImplFreeType_FontBakedInit;
|
||||||
|
loader.FontBakedDestroy = ImGui_ImplFreeType_FontBakedDestroy;
|
||||||
|
loader.FontBakedLoadGlyph = ImGui_ImplFreeType_FontBakedLoadGlyph;
|
||||||
|
loader.FontBakedSrcLoaderDataSize = sizeof(ImGui_ImplFreeType_FontSrcBakedData);
|
||||||
|
return &loader;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGuiFreeType::SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data)
|
||||||
|
{
|
||||||
|
GImGuiFreeTypeAllocFunc = alloc_func;
|
||||||
|
GImGuiFreeTypeFreeFunc = free_func;
|
||||||
|
GImGuiFreeTypeAllocatorUserData = user_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGuiFreeType::DebugEditFontLoaderFlags(unsigned int* p_font_loader_flags)
|
||||||
|
{
|
||||||
|
bool edited = false;
|
||||||
|
edited |= ImGui::CheckboxFlags("NoHinting", p_font_loader_flags, ImGuiFreeTypeLoaderFlags_NoHinting);
|
||||||
|
edited |= ImGui::CheckboxFlags("NoAutoHint", p_font_loader_flags, ImGuiFreeTypeLoaderFlags_NoAutoHint);
|
||||||
|
edited |= ImGui::CheckboxFlags("ForceAutoHint",p_font_loader_flags, ImGuiFreeTypeLoaderFlags_ForceAutoHint);
|
||||||
|
edited |= ImGui::CheckboxFlags("LightHinting", p_font_loader_flags, ImGuiFreeTypeLoaderFlags_LightHinting);
|
||||||
|
edited |= ImGui::CheckboxFlags("MonoHinting", p_font_loader_flags, ImGuiFreeTypeLoaderFlags_MonoHinting);
|
||||||
|
edited |= ImGui::CheckboxFlags("Bold", p_font_loader_flags, ImGuiFreeTypeLoaderFlags_Bold);
|
||||||
|
edited |= ImGui::CheckboxFlags("Oblique", p_font_loader_flags, ImGuiFreeTypeLoaderFlags_Oblique);
|
||||||
|
edited |= ImGui::CheckboxFlags("Monochrome", p_font_loader_flags, ImGuiFreeTypeLoaderFlags_Monochrome);
|
||||||
|
edited |= ImGui::CheckboxFlags("LoadColor", p_font_loader_flags, ImGuiFreeTypeLoaderFlags_LoadColor);
|
||||||
|
edited |= ImGui::CheckboxFlags("Bitmap", p_font_loader_flags, ImGuiFreeTypeLoaderFlags_Bitmap);
|
||||||
|
return edited;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||||
|
// For more details, see https://gitlab.freedesktop.org/freetype/freetype-demos/-/blob/master/src/rsvg-port.c
|
||||||
|
// The original code from the demo is licensed under CeCILL-C Free Software License Agreement (https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/LICENSE.TXT)
|
||||||
|
struct LunasvgPortState
|
||||||
|
{
|
||||||
|
FT_Error err = FT_Err_Ok;
|
||||||
|
lunasvg::Matrix matrix;
|
||||||
|
std::unique_ptr<lunasvg::Document> svg = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
static FT_Error ImGuiLunasvgPortInit(FT_Pointer* _state)
|
||||||
|
{
|
||||||
|
*_state = IM_NEW(LunasvgPortState)();
|
||||||
|
return FT_Err_Ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGuiLunasvgPortFree(FT_Pointer* _state)
|
||||||
|
{
|
||||||
|
IM_DELETE(*(LunasvgPortState**)_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FT_Error ImGuiLunasvgPortRender(FT_GlyphSlot slot, FT_Pointer* _state)
|
||||||
|
{
|
||||||
|
LunasvgPortState* state = *(LunasvgPortState**)_state;
|
||||||
|
|
||||||
|
// If there was an error while loading the svg in ImGuiLunasvgPortPresetSlot(), the renderer hook still get called, so just returns the error.
|
||||||
|
if (state->err != FT_Err_Ok)
|
||||||
|
return state->err;
|
||||||
|
|
||||||
|
// rows is height, pitch (or stride) equals to width * sizeof(int32)
|
||||||
|
lunasvg::Bitmap bitmap((uint8_t*)slot->bitmap.buffer, slot->bitmap.width, slot->bitmap.rows, slot->bitmap.pitch);
|
||||||
|
#if LUNASVG_VERSION_MAJOR >= 3
|
||||||
|
state->svg->render(bitmap, state->matrix); // state->matrix is already scaled and translated
|
||||||
|
#else
|
||||||
|
state->svg->setMatrix(state->svg->matrix().identity()); // Reset the svg matrix to the default value
|
||||||
|
state->svg->render(bitmap, state->matrix); // state->matrix is already scaled and translated
|
||||||
|
#endif
|
||||||
|
state->err = FT_Err_Ok;
|
||||||
|
return state->err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FT_Error ImGuiLunasvgPortPresetSlot(FT_GlyphSlot slot, FT_Bool cache, FT_Pointer* _state)
|
||||||
|
{
|
||||||
|
FT_SVG_Document document = (FT_SVG_Document)slot->other;
|
||||||
|
LunasvgPortState* state = *(LunasvgPortState**)_state;
|
||||||
|
FT_Size_Metrics& metrics = document->metrics;
|
||||||
|
|
||||||
|
// This function is called twice, once in the FT_Load_Glyph() and another right before ImGuiLunasvgPortRender().
|
||||||
|
// If it's the latter, don't do anything because it's // already done in the former.
|
||||||
|
if (cache)
|
||||||
|
return state->err;
|
||||||
|
|
||||||
|
state->svg = lunasvg::Document::loadFromData((const char*)document->svg_document, document->svg_document_length);
|
||||||
|
if (state->svg == nullptr)
|
||||||
|
{
|
||||||
|
state->err = FT_Err_Invalid_SVG_Document;
|
||||||
|
return state->err;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if LUNASVG_VERSION_MAJOR >= 3
|
||||||
|
lunasvg::Box box = state->svg->boundingBox();
|
||||||
|
#else
|
||||||
|
lunasvg::Box box = state->svg->box();
|
||||||
|
#endif
|
||||||
|
double scale = std::min(metrics.x_ppem / box.w, metrics.y_ppem / box.h);
|
||||||
|
double xx = (double)document->transform.xx / (1 << 16);
|
||||||
|
double xy = -(double)document->transform.xy / (1 << 16);
|
||||||
|
double yx = -(double)document->transform.yx / (1 << 16);
|
||||||
|
double yy = (double)document->transform.yy / (1 << 16);
|
||||||
|
double x0 = (double)document->delta.x / 64 * box.w / metrics.x_ppem;
|
||||||
|
double y0 = -(double)document->delta.y / 64 * box.h / metrics.y_ppem;
|
||||||
|
|
||||||
|
#if LUNASVG_VERSION_MAJOR >= 3
|
||||||
|
// Scale, transform and pre-translate the matrix for the rendering step
|
||||||
|
state->matrix = lunasvg::Matrix::translated(-box.x, -box.y);
|
||||||
|
state->matrix.multiply(lunasvg::Matrix(xx, xy, yx, yy, x0, y0));
|
||||||
|
state->matrix.scale(scale, scale);
|
||||||
|
|
||||||
|
// Apply updated transformation to the bounding box
|
||||||
|
box.transform(state->matrix);
|
||||||
|
#else
|
||||||
|
// Scale and transform, we don't translate the svg yet
|
||||||
|
state->matrix.identity();
|
||||||
|
state->matrix.scale(scale, scale);
|
||||||
|
state->matrix.transform(xx, xy, yx, yy, x0, y0);
|
||||||
|
state->svg->setMatrix(state->matrix);
|
||||||
|
|
||||||
|
// Pre-translate the matrix for the rendering step
|
||||||
|
state->matrix.translate(-box.x, -box.y);
|
||||||
|
|
||||||
|
// Get the box again after the transformation
|
||||||
|
box = state->svg->box();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Calculate the bitmap size
|
||||||
|
slot->bitmap_left = FT_Int(box.x);
|
||||||
|
slot->bitmap_top = FT_Int(-box.y);
|
||||||
|
slot->bitmap.rows = (unsigned int)(ImCeil((float)box.h));
|
||||||
|
slot->bitmap.width = (unsigned int)(ImCeil((float)box.w));
|
||||||
|
slot->bitmap.pitch = slot->bitmap.width * 4;
|
||||||
|
slot->bitmap.pixel_mode = FT_PIXEL_MODE_BGRA;
|
||||||
|
|
||||||
|
// Compute all the bearings and set them correctly. The outline is scaled already, we just need to use the bounding box.
|
||||||
|
double metrics_width = box.w;
|
||||||
|
double metrics_height = box.h;
|
||||||
|
double horiBearingX = box.x;
|
||||||
|
double horiBearingY = -box.y;
|
||||||
|
double vertBearingX = slot->metrics.horiBearingX / 64.0 - slot->metrics.horiAdvance / 64.0 / 2.0;
|
||||||
|
double vertBearingY = (slot->metrics.vertAdvance / 64.0 - slot->metrics.height / 64.0) / 2.0;
|
||||||
|
slot->metrics.width = FT_Pos(IM_ROUND(metrics_width * 64.0)); // Using IM_ROUND() assume width and height are positive
|
||||||
|
slot->metrics.height = FT_Pos(IM_ROUND(metrics_height * 64.0));
|
||||||
|
slot->metrics.horiBearingX = FT_Pos(horiBearingX * 64);
|
||||||
|
slot->metrics.horiBearingY = FT_Pos(horiBearingY * 64);
|
||||||
|
slot->metrics.vertBearingX = FT_Pos(vertBearingX * 64);
|
||||||
|
slot->metrics.vertBearingY = FT_Pos(vertBearingY * 64);
|
||||||
|
|
||||||
|
if (slot->metrics.vertAdvance == 0)
|
||||||
|
slot->metrics.vertAdvance = FT_Pos(metrics_height * 1.2 * 64.0);
|
||||||
|
|
||||||
|
state->err = FT_Err_Ok;
|
||||||
|
return state->err;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // #ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
83
libs/imgui/misc/freetype/imgui_freetype.h
Normal file
83
libs/imgui/misc/freetype/imgui_freetype.h
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
// dear imgui: FreeType font builder (used as a replacement for the stb_truetype builder)
|
||||||
|
// (headers)
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "imgui.h" // IMGUI_API
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
|
||||||
|
// Usage:
|
||||||
|
// - Add '#define IMGUI_ENABLE_FREETYPE' in your imconfig to automatically enable support
|
||||||
|
// for imgui_freetype in imgui. It is equivalent to selecting the default loader with:
|
||||||
|
// io.Fonts->SetFontLoader(ImGuiFreeType::GetFontLoader())
|
||||||
|
|
||||||
|
// Optional support for OpenType SVG fonts:
|
||||||
|
// - Add '#define IMGUI_ENABLE_FREETYPE_PLUTOSVG' to use plutosvg (not provided). See #7927.
|
||||||
|
// - Add '#define IMGUI_ENABLE_FREETYPE_LUNASVG' to use lunasvg (not provided). See #6591.
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
struct ImFontAtlas;
|
||||||
|
struct ImFontLoader;
|
||||||
|
|
||||||
|
// Hinting greatly impacts visuals (and glyph sizes).
|
||||||
|
// - By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter.
|
||||||
|
// - When disabled, FreeType generates blurrier glyphs, more or less matches the stb_truetype.h
|
||||||
|
// - The Default hinting mode usually looks good, but may distort glyphs in an unusual way.
|
||||||
|
// - The Light hinting mode generates fuzzier glyphs but better matches Microsoft's rasterizer.
|
||||||
|
// You can set those flags globally in ImFontAtlas::FontLoaderFlags
|
||||||
|
// You can set those flags on a per font basis in ImFontConfig::FontLoaderFlags
|
||||||
|
typedef unsigned int ImGuiFreeTypeLoaderFlags;
|
||||||
|
enum ImGuiFreeTypeLoaderFlags_
|
||||||
|
{
|
||||||
|
ImGuiFreeTypeLoaderFlags_NoHinting = 1 << 0, // Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes.
|
||||||
|
ImGuiFreeTypeLoaderFlags_NoAutoHint = 1 << 1, // Disable auto-hinter.
|
||||||
|
ImGuiFreeTypeLoaderFlags_ForceAutoHint = 1 << 2, // Indicates that the auto-hinter is preferred over the font's native hinter.
|
||||||
|
ImGuiFreeTypeLoaderFlags_LightHinting = 1 << 3, // A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape. This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis), as is done by Microsoft's ClearType and Adobe's proprietary font renderer. This preserves inter-glyph spacing in horizontal text.
|
||||||
|
ImGuiFreeTypeLoaderFlags_MonoHinting = 1 << 4, // Strong hinting algorithm that should only be used for monochrome output.
|
||||||
|
ImGuiFreeTypeLoaderFlags_Bold = 1 << 5, // Styling: Should we artificially embolden the font?
|
||||||
|
ImGuiFreeTypeLoaderFlags_Oblique = 1 << 6, // Styling: Should we slant the font, emulating italic style?
|
||||||
|
ImGuiFreeTypeLoaderFlags_Monochrome = 1 << 7, // Disable anti-aliasing. Combine this with MonoHinting for best results!
|
||||||
|
ImGuiFreeTypeLoaderFlags_LoadColor = 1 << 8, // Enable FreeType color-layered glyphs
|
||||||
|
ImGuiFreeTypeLoaderFlags_Bitmap = 1 << 9, // Enable FreeType bitmap glyphs
|
||||||
|
|
||||||
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
ImGuiFreeTypeBuilderFlags_NoHinting = ImGuiFreeTypeLoaderFlags_NoHinting,
|
||||||
|
ImGuiFreeTypeBuilderFlags_NoAutoHint = ImGuiFreeTypeLoaderFlags_NoAutoHint,
|
||||||
|
ImGuiFreeTypeBuilderFlags_ForceAutoHint = ImGuiFreeTypeLoaderFlags_ForceAutoHint,
|
||||||
|
ImGuiFreeTypeBuilderFlags_LightHinting = ImGuiFreeTypeLoaderFlags_LightHinting,
|
||||||
|
ImGuiFreeTypeBuilderFlags_MonoHinting = ImGuiFreeTypeLoaderFlags_MonoHinting,
|
||||||
|
ImGuiFreeTypeBuilderFlags_Bold = ImGuiFreeTypeLoaderFlags_Bold,
|
||||||
|
ImGuiFreeTypeBuilderFlags_Oblique = ImGuiFreeTypeLoaderFlags_Oblique,
|
||||||
|
ImGuiFreeTypeBuilderFlags_Monochrome = ImGuiFreeTypeLoaderFlags_Monochrome,
|
||||||
|
ImGuiFreeTypeBuilderFlags_LoadColor = ImGuiFreeTypeLoaderFlags_LoadColor,
|
||||||
|
ImGuiFreeTypeBuilderFlags_Bitmap = ImGuiFreeTypeLoaderFlags_Bitmap,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
// Obsolete names (will be removed)
|
||||||
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
typedef ImGuiFreeTypeLoaderFlags_ ImGuiFreeTypeBuilderFlags_;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace ImGuiFreeType
|
||||||
|
{
|
||||||
|
// This is automatically assigned when using '#define IMGUI_ENABLE_FREETYPE'.
|
||||||
|
// If you need to dynamically select between multiple builders:
|
||||||
|
// - you can manually assign this builder with 'atlas->SetFontLoader(ImGuiFreeType::GetFontLoader())'
|
||||||
|
// - prefer deep-copying this into your own ImFontLoader instance if you use hot-reloading that messes up static data.
|
||||||
|
IMGUI_API const ImFontLoader* GetFontLoader();
|
||||||
|
|
||||||
|
// Override allocators. By default ImGuiFreeType will use IM_ALLOC()/IM_FREE()
|
||||||
|
// However, as FreeType does lots of allocations we provide a way for the user to redirect it to a separate memory heap if desired.
|
||||||
|
IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data = nullptr);
|
||||||
|
|
||||||
|
// Display UI to edit ImFontAtlas::FontLoaderFlags (shared) or ImFontConfig::FontLoaderFlags (single source)
|
||||||
|
IMGUI_API bool DebugEditFontLoaderFlags(ImGuiFreeTypeLoaderFlags* p_font_loader_flags);
|
||||||
|
|
||||||
|
// Obsolete names (will be removed)
|
||||||
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
//IMGUI_API const ImFontBuilderIO* GetBuilderForFreeType(); // Renamed/changed in 1.92. Change 'io.Fonts->FontBuilderIO = ImGuiFreeType::GetBuilderForFreeType()' to 'io.Fonts->SetFontLoader(ImGuiFreeType::GetFontLoader())' if you need runtime selection.
|
||||||
|
//static inline bool BuildFontAtlas(ImFontAtlas* atlas, unsigned int flags = 0) { atlas->FontBuilderIO = GetBuilderForFreeType(); atlas->FontLoaderFlags = flags; return atlas->Build(); } // Prefer using '#define IMGUI_ENABLE_FREETYPE'
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
3278
libs/nanosvg/nanosvg.h
Normal file
3278
libs/nanosvg/nanosvg.h
Normal file
File diff suppressed because it is too large
Load Diff
1472
libs/nanosvg/nanosvgrast.h
Normal file
1472
libs/nanosvg/nanosvgrast.h
Normal file
File diff suppressed because it is too large
Load Diff
0
prebuilt-binaries/drg-xmrig/.gitkeep
Normal file
0
prebuilt-binaries/drg-xmrig/.gitkeep
Normal file
BIN
res/fonts/NotoEmoji-Subset.ttf
Normal file
BIN
res/fonts/NotoEmoji-Subset.ttf
Normal file
Binary file not shown.
Binary file not shown.
BIN
res/fonts/TwemojiMozilla-Color.ttf
Normal file
BIN
res/fonts/TwemojiMozilla-Color.ttf
Normal file
Binary file not shown.
BIN
res/img/backgrounds/texture/jade_bg.png
Normal file
BIN
res/img/backgrounds/texture/jade_bg.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
23
res/img/logos/logo_dragonx.svg
Normal file
23
res/img/logos/logo_dragonx.svg
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
|
||||||
|
<defs>
|
||||||
|
<style>
|
||||||
|
.cls-1 {
|
||||||
|
fill: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cls-2 {
|
||||||
|
fill: #d82652;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</defs>
|
||||||
|
<path class="cls-2" d="M103.98,128s-6.29-24.7-18.73-34.43c-8.53-8.03-15.63-16.49-21.25-24.16-5.62,7.68-12.72,16.17-21.25,24.16-12.4,9.74-18.73,34.43-18.73,34.43-2.38-24.34,7.85-35.82,12.87-41.29,7.82-8.5,15.31-16.56,21.75-25.02-7.64-11.44-11.41-19.72-11.41-19.72-.89-3.27-3.84-6.64-3.84-6.64,6.08-8.1-1.6-16.98-1.6-16.98,5.79-5.62,6.71-10.02,8.32-18.34-1.96,22.35,4.02,39.09,13.93,54.12,9.84-15.03,15.81-31.77,13.86-54.12,1.6,8.35,2.52,12.72,8.32,18.34,0,0-7.68,8.88-1.6,16.98,0,0-2.95,3.38-3.84,6.64,0,0-3.77,8.28-11.37,19.72,6.43,8.45,13.97,16.56,21.75,25.02,4.97,5.47,15.21,16.95,12.83,41.29h0Z"/>
|
||||||
|
<g>
|
||||||
|
<path class="cls-1" d="M55.33,61.62c-3.55,4.55-7.39,8.99-11.44,13.47-5.29-4.48-11.23-5.33-11.23-5.33,22.92-7.82,2.81-15.17.28-16.31C9.28,42.78,9.1,14.78,9.1,14.78c11.51,34.15,36.42,32.3,36.42,32.3.35-.21.67-.46.92-.71,1.64,3.27,4.58,8.67,8.88,15.24h0Z"/>
|
||||||
|
<g>
|
||||||
|
<path class="cls-1" d="M68.62,40.41c-1.35,2.98-2.91,5.83-4.62,8.63-1.71-2.81-3.23-5.69-4.62-8.63,1.74-3.45,4.62-20.58,4.62-20.58,0,0,2.88,17.13,4.62,20.58Z"/>
|
||||||
|
<path class="cls-1" d="M76.01,97.93l-3.48,2.34s-.1-4.44-3.52-1.84c-.42.32-2.38,2.21-.03,4.27,0,0-4.05,4.08-4.97,8.21-.92-4.12-4.97-8.21-4.97-8.21,2.34-2.06.39-3.95-.03-4.27-3.41-2.59-3.52,1.84-3.52,1.84l-3.48-2.34c.28-3.55.1-6.68-.46-9.42,4.69-4.94,8.85-9.88,12.47-14.61,3.66,4.72,7.78,9.67,12.47,14.61-.57,2.74-.75,5.86-.46,9.42Z"/>
|
||||||
|
<path class="cls-1" d="M95.34,69.76s-5.94.85-11.23,5.33c-4.02-4.48-7.89-8.92-11.44-13.47,4.3-6.57,7.25-11.98,8.88-15.24.25.25.57.5.92.71,0,0,24.91,1.84,36.42-32.3,0,0-.18,28-23.84,38.66-2.52,1.14-22.64,8.5.28,16.31h0Z"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.9 KiB |
780
res/lang/de.json
780
res/lang/de.json
File diff suppressed because it is too large
Load Diff
780
res/lang/es.json
780
res/lang/es.json
File diff suppressed because it is too large
Load Diff
780
res/lang/fr.json
780
res/lang/fr.json
File diff suppressed because it is too large
Load Diff
776
res/lang/ja.json
776
res/lang/ja.json
File diff suppressed because it is too large
Load Diff
780
res/lang/ko.json
780
res/lang/ko.json
File diff suppressed because it is too large
Load Diff
780
res/lang/pt.json
780
res/lang/pt.json
File diff suppressed because it is too large
Load Diff
780
res/lang/ru.json
780
res/lang/ru.json
File diff suppressed because it is too large
Load Diff
776
res/lang/zh.json
776
res/lang/zh.json
File diff suppressed because it is too large
Load Diff
190
res/themes/jade.toml
Normal file
190
res/themes/jade.toml
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
[theme]
|
||||||
|
name = "Jade"
|
||||||
|
author = "The Hush Developers"
|
||||||
|
dark = true
|
||||||
|
elevation = { --elevation-0 = "#071210", --elevation-1 = "#0C1A16", --elevation-2 = "#16261F", --elevation-3 = "#1D3128", --elevation-4 = "#243B30" }
|
||||||
|
images = { background_image = "backgrounds/texture/jade_bg.png", logo = "logos/logo_ObsidianDragon_dark.png" }
|
||||||
|
|
||||||
|
[theme.palette]
|
||||||
|
--primary = "#2FA07A"
|
||||||
|
--primary-variant = "#1E7357"
|
||||||
|
--primary-light = "#7FD1B5"
|
||||||
|
--secondary = "#C9A24E"
|
||||||
|
--secondary-variant = "#A8842F"
|
||||||
|
--secondary-light = "#E0C583"
|
||||||
|
--background = "#071210"
|
||||||
|
--surface = "#0C1A16"
|
||||||
|
--surface-variant = "#16261F"
|
||||||
|
--on-primary = "#FFFFFF"
|
||||||
|
--on-secondary = "#000000"
|
||||||
|
--on-background = "#DCEDE4"
|
||||||
|
--on-surface = "#DCEDE4"
|
||||||
|
--on-surface-medium = "rgba(220,237,228,0.85)"
|
||||||
|
--on-surface-disabled = "rgba(220,237,228,0.58)"
|
||||||
|
--error = "#CF6679"
|
||||||
|
--on-error = "#000000"
|
||||||
|
--success = "#81C784"
|
||||||
|
--on-success = "#000000"
|
||||||
|
--warning = "#FFB74D"
|
||||||
|
--on-warning = "#000000"
|
||||||
|
--divider = "rgba(130,205,170,0.14)"
|
||||||
|
--outline = "rgba(130,205,170,0.16)"
|
||||||
|
--scrim = "rgba(0,0,0,0.6)"
|
||||||
|
--surface-hover = "rgba(130,205,170,0.07)"
|
||||||
|
--surface-alt = "rgba(130,205,170,0.05)"
|
||||||
|
--surface-active = "rgba(130,205,170,0.10)"
|
||||||
|
--glass-button = "rgba(130,205,170,0.06)"
|
||||||
|
--glass-button-hover = "rgba(130,205,170,0.12)"
|
||||||
|
--card-border = "rgba(130,205,170,0.26)"
|
||||||
|
--text-shadow = "rgba(0,0,0,0.50)"
|
||||||
|
--input-overlay-text = "rgba(220,237,228,0.30)"
|
||||||
|
--slider-text = "rgba(220,237,228,0.85)"
|
||||||
|
--thumb-fill = "rgba(130,205,170,0.15)"
|
||||||
|
--thumb-border = "rgba(130,205,170,0.50)"
|
||||||
|
--disabled-label = "rgba(130,205,170,0.18)"
|
||||||
|
--chart-grid = "rgba(130,205,170,0.05)"
|
||||||
|
--chart-crosshair = "rgba(130,205,170,0.15)"
|
||||||
|
--chart-hover-ring = "rgba(130,205,170,0.30)"
|
||||||
|
--tooltip-bg = "rgba(9,20,16,0.92)"
|
||||||
|
--tooltip-border = "rgba(130,205,170,0.12)"
|
||||||
|
--glass-fill = "rgba(130,205,170,0.08)"
|
||||||
|
--glass-border = "rgba(47,160,122,0.30)"
|
||||||
|
--glass-noise-tint = "rgba(130,205,170,0.03)"
|
||||||
|
--tactile-top = "rgba(130,205,170,0.06)"
|
||||||
|
--tactile-bottom = "rgba(130,205,170,0.0)"
|
||||||
|
--hover-overlay = "rgba(130,205,170,0.05)"
|
||||||
|
--active-overlay = "rgba(130,205,170,0.10)"
|
||||||
|
--rim-light = "rgba(130,205,170,0.14)"
|
||||||
|
--status-divider = "rgba(130,205,170,0.08)"
|
||||||
|
--sidebar-hover = "rgba(130,205,170,0.10)"
|
||||||
|
--sidebar-icon = "rgba(130,205,170,0.42)"
|
||||||
|
--sidebar-badge = "rgba(220,237,228,1.0)"
|
||||||
|
--sidebar-divider = "rgba(130,205,170,0.06)"
|
||||||
|
--chart-line = "rgba(130,205,170,0.10)"
|
||||||
|
--window-control = "rgba(220,237,228,0.78)"
|
||||||
|
--window-control-hover = "rgba(130,205,170,0.12)"
|
||||||
|
--window-close-hover = "rgba(232,17,35,0.78)"
|
||||||
|
--spinner-track = "rgba(130,205,170,0.10)"
|
||||||
|
--spinner-active = "rgba(79,184,154,0.85)"
|
||||||
|
--shutdown-panel-bg = "rgba(7,18,14,0.90)"
|
||||||
|
--shutdown-panel-border = "rgba(130,205,170,0.07)"
|
||||||
|
--ram-bar-app = "#2FA07A"
|
||||||
|
--ram-bar-system = "rgba(255,255,255,0.18)"
|
||||||
|
--accent-total = "#7FD1B5"
|
||||||
|
--accent-shielded = "#4FB89A"
|
||||||
|
--accent-transparent = "#C9A24E"
|
||||||
|
--accent-action = "#2FA07A"
|
||||||
|
--accent-market = "#4FB89A"
|
||||||
|
--accent-portfolio = "#7FD1B5"
|
||||||
|
--toast-info-accent = "#2FA07A"
|
||||||
|
--toast-info-text = "#7FD1B5"
|
||||||
|
--toast-success-accent = "rgba(50,180,80,1.0)"
|
||||||
|
--toast-success-text = "rgba(180,255,180,1.0)"
|
||||||
|
--toast-warning-accent = "rgba(204,166,50,1.0)"
|
||||||
|
--toast-warning-text = "rgba(255,230,130,1.0)"
|
||||||
|
--toast-error-accent = "rgba(204,64,64,1.0)"
|
||||||
|
--toast-error-text = "rgba(255,153,153,1.0)"
|
||||||
|
--snackbar-bg = "rgba(24,40,34,0.95)"
|
||||||
|
--snackbar-text = "rgba(220,237,228,0.87)"
|
||||||
|
--snackbar-action = "rgba(79,184,154,1.0)"
|
||||||
|
--snackbar-action-hover = "rgba(127,209,181,1.0)"
|
||||||
|
--switch-track-off = "rgba(130,205,170,0.12)"
|
||||||
|
--switch-track-on = "rgba(47,160,122,0.50)"
|
||||||
|
--switch-thumb-off = "#A0C0B4"
|
||||||
|
--switch-thumb-on = "#DCEDE4"
|
||||||
|
--control-shadow = "rgba(0,0,0,0.24)"
|
||||||
|
--checkbox-check = "#000000"
|
||||||
|
--app-bar-shadow = "rgba(0,0,0,0.25)"
|
||||||
|
|
||||||
|
[backdrop]
|
||||||
|
base-color-top = "rgba(14,32,26,210)"
|
||||||
|
base-color-bottom = "rgba(6,18,14,210)"
|
||||||
|
texture-tint-alpha = 120
|
||||||
|
gradient-top-r = 10
|
||||||
|
gradient-top-g = 30
|
||||||
|
gradient-top-b = 22
|
||||||
|
gradient-top-a = 90
|
||||||
|
gradient-bottom-r = 5
|
||||||
|
gradient-bottom-g = 16
|
||||||
|
gradient-bottom-b = 12
|
||||||
|
gradient-bottom-a = 70
|
||||||
|
background-alpha = 0.42
|
||||||
|
surface-alpha = 0.56
|
||||||
|
frame-alpha = 0.78
|
||||||
|
surface-inline-alpha = 0.58
|
||||||
|
background-inline-alpha = 0.40
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Theme Visual Effects — Jade (veins of gold shifting through the stone)
|
||||||
|
# Jade's signature is a slow jade→gold color-shifting border on every glass
|
||||||
|
# panel + the active nav button — a vein of gold surfacing through nephrite.
|
||||||
|
# It's drawn via AddRect so it hugs the real rounded corners (no polygonal
|
||||||
|
# edge-trace). Sparse jade motes drift up the viewport. No other theme turns
|
||||||
|
# gradient-border-panels on, so the panel-wide vein is Jade's own —
|
||||||
|
# deliberately NOT Obsidian's specular glare.
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
[effects]
|
||||||
|
hue-cycle-enabled = { size = 0.0 }
|
||||||
|
rainbow-border-enabled = { size = 0.0 }
|
||||||
|
|
||||||
|
# No shimmer sweep — replaced by specular glare
|
||||||
|
shimmer-enabled = { size = 0.0 }
|
||||||
|
|
||||||
|
positional-hue-enabled = { size = 0.0 }
|
||||||
|
|
||||||
|
glow-pulse-enabled = { size = 0.0 }
|
||||||
|
|
||||||
|
# Edge-trace OFF — its hand-walked perimeter chamfers rounded corners.
|
||||||
|
# Jade's vein is the gradient-border below (corner-clean via AddRect).
|
||||||
|
edge-trace-enabled = { size = 0.0 }
|
||||||
|
edge-trace-speed = { size = 0.16 }
|
||||||
|
edge-trace-length = { size = 0.34 }
|
||||||
|
edge-trace-thickness = { size = 1.6 }
|
||||||
|
edge-trace-alpha = { size = 0.55 }
|
||||||
|
edge-trace-color = { color = "#C9A24E" }
|
||||||
|
|
||||||
|
# Specular glare OFF — that's Obsidian's signature; Jade shouldn't echo it.
|
||||||
|
specular-glare-enabled = { size = 0.0 }
|
||||||
|
specular-glare-speed = { size = 0.018 }
|
||||||
|
specular-glare-intensity = { size = 0.008 }
|
||||||
|
specular-glare-radius = { size = 0.65 }
|
||||||
|
specular-glare-count = { size = 1.0 }
|
||||||
|
specular-glare-color = { color = "rgba(150,220,180,1.0)" }
|
||||||
|
|
||||||
|
# HERO — vein of gold: a slow jade→gold color-shifting border on the active
|
||||||
|
# nav button AND (via gradient-border-panels) every glass panel. Drawn with
|
||||||
|
# AddRect so it follows the rounded corners exactly. Panels drift at a softer
|
||||||
|
# alpha and position-phased offset, so a screenful reads like veins at
|
||||||
|
# different depths rather than one synchronized pulse.
|
||||||
|
gradient-border-enabled = { size = 1.0 }
|
||||||
|
gradient-border-panels = { size = 1.0 }
|
||||||
|
gradient-border-speed = { size = 0.10 }
|
||||||
|
gradient-border-thickness = { size = 1.5 }
|
||||||
|
gradient-border-alpha = { size = 0.55 }
|
||||||
|
gradient-border-color-a = { color = "#7FD1B5" }
|
||||||
|
gradient-border-color-b = { color = "#C9A24E" }
|
||||||
|
|
||||||
|
# Ambient jade motes — sparse, slow, cool green particles drifting up the
|
||||||
|
# viewport (recolored ember-rise; a different mood from dragonx's fire embers).
|
||||||
|
ember-rise-enabled = { size = 1.0 }
|
||||||
|
ember-rise-count = { size = 5.0 }
|
||||||
|
ember-rise-speed = { size = 0.18 }
|
||||||
|
ember-rise-particle-size = { size = 1.4 }
|
||||||
|
ember-rise-alpha = { size = 0.26 }
|
||||||
|
ember-rise-color = { color = "#7FD1B5" }
|
||||||
|
|
||||||
|
# Shader-like viewport overlay — deep green stone atmosphere
|
||||||
|
viewport-wash-enabled = { size = 1.0 }
|
||||||
|
viewport-wash-alpha = { size = 0.05 }
|
||||||
|
viewport-wash-tl = { color = "#12402E" }
|
||||||
|
viewport-wash-tr = { color = "#0E3828" }
|
||||||
|
viewport-wash-bl = { color = "#16442E" }
|
||||||
|
viewport-wash-br = { color = "#1A4A34" }
|
||||||
|
viewport-wash-rotate = { size = 0.015 }
|
||||||
|
viewport-wash-pulse = { size = 0.0 }
|
||||||
|
viewport-wash-pulse-depth = { size = 0.0 }
|
||||||
|
|
||||||
|
viewport-vignette-enabled = { size = 1.0 }
|
||||||
|
viewport-vignette-color = { color = "#04140D" }
|
||||||
|
viewport-vignette-radius = { size = 0.22 }
|
||||||
|
viewport-vignette-alpha = { size = 0.15 }
|
||||||
@@ -700,6 +700,12 @@ status-pill-bg-alpha = { size = 30 }
|
|||||||
status-pill-y-offset = { size = 1 }
|
status-pill-y-offset = { size = 1 }
|
||||||
confirmed-threshold = { size = 10 }
|
confirmed-threshold = { size = 10 }
|
||||||
|
|
||||||
|
# Persistent node/RPC error strip at the top of the content column (see App::renderNodeStatusBanner).
|
||||||
|
# Slightly taller than the per-tab sync banner so it comfortably holds the Reconnect/Restart action.
|
||||||
|
[banners.node-status]
|
||||||
|
min-height = { size = 26.0 }
|
||||||
|
height = { size = 30.0 }
|
||||||
|
|
||||||
[tabs.transactions]
|
[tabs.transactions]
|
||||||
search-max-width = 300.0
|
search-max-width = 300.0
|
||||||
search-width-ratio = 0.3
|
search-width-ratio = 0.3
|
||||||
@@ -959,6 +965,11 @@ edition-label = { position = 120 }
|
|||||||
link-button = { width = 100, font = "button-sm" }
|
link-button = { width = 100, font = "button-sm" }
|
||||||
close-button = { width = 120, font = "button", align = "center" }
|
close-button = { width = 120, font = "button", align = "center" }
|
||||||
|
|
||||||
|
[dialogs.faq]
|
||||||
|
width = 860.0
|
||||||
|
height = 660.0
|
||||||
|
window = { width = 860, height = 660 }
|
||||||
|
|
||||||
[dialogs.settings]
|
[dialogs.settings]
|
||||||
width = 600.0
|
width = 600.0
|
||||||
height = 550.0
|
height = 550.0
|
||||||
@@ -1503,6 +1514,7 @@ progress-bar = { height = 6.0, radius = 3.0 }
|
|||||||
progress-width = { size = 260.0 }
|
progress-width = { size = 260.0 }
|
||||||
backdrop-alpha = { opacity = 0.80 }
|
backdrop-alpha = { opacity = 0.80 }
|
||||||
vertical-gap = { size = 8.0 }
|
vertical-gap = { size = 8.0 }
|
||||||
|
stall-timeout-sec = { size = 45.0 }
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# First-Run Wizard Screens
|
# First-Run Wizard Screens
|
||||||
|
|||||||
94
scripts/build-freetype-mingw.sh
Executable file
94
scripts/build-freetype-mingw.sh
Executable file
@@ -0,0 +1,94 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Cross-build a MINIMAL static FreeType for the mingw-w64 (Windows) target.
|
||||||
|
#
|
||||||
|
# Why: the wallet's optional color-emoji rendering needs FreeType (to rasterize the COLR/CPAL Twemoji
|
||||||
|
# font). Native Linux/macOS pick up the system FreeType via find_package; the Debian/Ubuntu mingw-w64
|
||||||
|
# cross toolchain ships no FreeType, so we build one here. The Twemoji font is COLRv0 (layered vector),
|
||||||
|
# which FreeType renders WITHOUT libpng / harfbuzz / brotli / zlib — so this is a dependency-free static
|
||||||
|
# build (no external libs to also cross-compile), producing a self-contained libfreetype.a.
|
||||||
|
#
|
||||||
|
# Output: <prefix>/include/freetype2/... + <prefix>/lib/libfreetype.a (default prefix: third_party/freetype-mingw)
|
||||||
|
# build.sh --win-release runs this automatically and passes -DDRAGONX_MINGW_FREETYPE_PREFIX to CMake.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
FT_VERSION="2.13.3"
|
||||||
|
FT_SHA256="5c3a8e78f7b24c20b25b54ee575d6daa40007a5f4eea2845861c3409b3021747" # freetype-2.13.3.tar.gz
|
||||||
|
FT_URL="https://download.savannah.gnu.org/releases/freetype/freetype-${FT_VERSION}.tar.gz"
|
||||||
|
FT_URL_MIRROR="https://downloads.sourceforge.net/project/freetype/freetype2/${FT_VERSION}/freetype-${FT_VERSION}.tar.gz"
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
PREFIX="${1:-$SCRIPT_DIR/third_party/freetype-mingw}"
|
||||||
|
WORK="$SCRIPT_DIR/third_party/.freetype-mingw-build"
|
||||||
|
|
||||||
|
# Already built? (libfreetype.a present) → nothing to do.
|
||||||
|
if [[ -f "$PREFIX/lib/libfreetype.a" && -d "$PREFIX/include/freetype2" ]]; then
|
||||||
|
echo "FreeType (mingw) already built at: $PREFIX"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Pick the mingw compilers (posix threads variant preferred, matching build.sh).
|
||||||
|
if command -v x86_64-w64-mingw32-gcc-posix &>/dev/null; then
|
||||||
|
MINGW_GCC=x86_64-w64-mingw32-gcc-posix; MINGW_GXX=x86_64-w64-mingw32-g++-posix
|
||||||
|
elif command -v x86_64-w64-mingw32-gcc &>/dev/null; then
|
||||||
|
MINGW_GCC=x86_64-w64-mingw32-gcc; MINGW_GXX=x86_64-w64-mingw32-g++
|
||||||
|
else
|
||||||
|
echo "ERROR: x86_64-w64-mingw32-gcc not found (install mingw-w64)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$WORK"
|
||||||
|
cd "$WORK"
|
||||||
|
|
||||||
|
TARBALL="freetype-${FT_VERSION}.tar.gz"
|
||||||
|
if [[ ! -f "$TARBALL" ]]; then
|
||||||
|
echo "Downloading FreeType ${FT_VERSION} ..."
|
||||||
|
curl -fsSL -o "$TARBALL" "$FT_URL" || curl -fsSL -o "$TARBALL" "$FT_URL_MIRROR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Verifying SHA-256 ..."
|
||||||
|
echo "${FT_SHA256} ${TARBALL}" | sha256sum -c - || {
|
||||||
|
echo "ERROR: FreeType tarball checksum mismatch (expected ${FT_SHA256})." >&2
|
||||||
|
echo " got: $(sha256sum "$TARBALL" | cut -d' ' -f1)" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
rm -rf "freetype-${FT_VERSION}"
|
||||||
|
tar xf "$TARBALL"
|
||||||
|
SRC="$WORK/freetype-${FT_VERSION}"
|
||||||
|
|
||||||
|
# Minimal mingw toolchain for FreeType's own CMake.
|
||||||
|
cat > "$WORK/ft-mingw-toolchain.cmake" <<TOOLCHAIN
|
||||||
|
set(CMAKE_SYSTEM_NAME Windows)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||||
|
set(CMAKE_C_COMPILER ${MINGW_GCC})
|
||||||
|
set(CMAKE_CXX_COMPILER ${MINGW_GXX})
|
||||||
|
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||||
|
TOOLCHAIN
|
||||||
|
|
||||||
|
echo "Configuring FreeType (static, no external deps) ..."
|
||||||
|
rm -rf "$WORK/build"
|
||||||
|
cmake -S "$SRC" -B "$WORK/build" \
|
||||||
|
-DCMAKE_TOOLCHAIN_FILE="$WORK/ft-mingw-toolchain.cmake" \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
|
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||||
|
-DBUILD_SHARED_LIBS=OFF \
|
||||||
|
-DFT_DISABLE_ZLIB=ON \
|
||||||
|
-DFT_DISABLE_BZIP2=ON \
|
||||||
|
-DFT_DISABLE_PNG=ON \
|
||||||
|
-DFT_DISABLE_HARFBUZZ=ON \
|
||||||
|
-DFT_DISABLE_BROTLI=ON
|
||||||
|
|
||||||
|
echo "Building + installing FreeType ..."
|
||||||
|
cmake --build "$WORK/build" -j "$(nproc)"
|
||||||
|
cmake --install "$WORK/build"
|
||||||
|
|
||||||
|
if [[ -f "$PREFIX/lib/libfreetype.a" ]]; then
|
||||||
|
echo "OK: mingw FreeType -> $PREFIX/lib/libfreetype.a"
|
||||||
|
else
|
||||||
|
echo "ERROR: build did not produce libfreetype.a" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -1,5 +1,17 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# This script uses bash 4+ features (mapfile, safe empty-array expansion under
|
||||||
|
# `set -u`). macOS ships bash 3.2, so re-exec under a newer bash when one is
|
||||||
|
# present (Homebrew), and fail with a clear message otherwise.
|
||||||
|
if [ "${BASH_VERSINFO:-0}" -lt 4 ]; then
|
||||||
|
for _newer_bash in /opt/homebrew/bin/bash /usr/local/bin/bash; do
|
||||||
|
[ -x "$_newer_bash" ] && exec "$_newer_bash" "$0" "$@"
|
||||||
|
done
|
||||||
|
echo "ERROR: build-lite-backend-artifact.sh requires bash 4+ (found ${BASH_VERSION:-unknown})." >&2
|
||||||
|
echo " On macOS: brew install bash" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
@@ -67,25 +79,9 @@ Options:
|
|||||||
--backend-dir PATH SilentDragonXLite/lib source directory.
|
--backend-dir PATH SilentDragonXLite/lib source directory.
|
||||||
--silentdragonxlitelib-dir PATH Override the wrapper's silentdragonxlitelib dependency path.
|
--silentdragonxlitelib-dir PATH Override the wrapper's silentdragonxlitelib dependency path.
|
||||||
--out-dir PATH Output directory for copied artifact and metadata.
|
--out-dir PATH Output directory for copied artifact and metadata.
|
||||||
--artifact PATH Inventory an existing artifact instead of building.
|
|
||||||
--no-build Do not run cargo; requires --artifact.
|
|
||||||
--reproducible Add deterministic Rust path remaps for clean builds.
|
--reproducible Add deterministic Rust path remaps for clean builds.
|
||||||
--remap-path-prefix FROM=TO Extra rustc path remap used with --reproducible.
|
--remap-path-prefix FROM=TO Extra rustc path remap used with --reproducible.
|
||||||
--builder NAME Redacted builder/provenance label. Default: local.
|
--builder NAME Redacted builder/provenance label. Default: local.
|
||||||
--signature-required Fail if verified signature metadata is not supplied.
|
|
||||||
--signature-file PATH Existing sidecar signature file to record.
|
|
||||||
--signature-format FORMAT Signature format: minisign, gpg, sigstore, external, or other.
|
|
||||||
--signature-verification-tool T Verification tool and version used by the release builder.
|
|
||||||
--signature-verification-command C
|
|
||||||
Verification command already run by the release builder.
|
|
||||||
--signature-key-fingerprint F Reviewed public-key fingerprint, when applicable.
|
|
||||||
--signature-certificate-identity ID
|
|
||||||
Reviewed certificate identity, when applicable.
|
|
||||||
--signature-certificate-issuer I
|
|
||||||
Reviewed certificate issuer, when applicable.
|
|
||||||
--signature-transparency-log-url URL
|
|
||||||
Transparency log entry, when applicable.
|
|
||||||
--signature-verified-sha256 SHA Artifact SHA-256 verified by the signature check.
|
|
||||||
-j, --jobs N Cargo parallel jobs.
|
-j, --jobs N Cargo parallel jobs.
|
||||||
--cargo-arg ARG Extra argument forwarded to cargo build.
|
--cargo-arg ARG Extra argument forwarded to cargo build.
|
||||||
-h, --help Show this help.
|
-h, --help Show this help.
|
||||||
@@ -95,9 +91,13 @@ Outputs:
|
|||||||
<out>/<platform>/lite-backend-symbols.txt
|
<out>/<platform>/lite-backend-symbols.txt
|
||||||
<out>/<platform>/lite-backend-artifact-manifest.json
|
<out>/<platform>/lite-backend-artifact-manifest.json
|
||||||
|
|
||||||
The script captures symbols, checksums, and optional read-only signature
|
The lite backend is always built from the vendored in-tree source
|
||||||
verification metadata only. It does not load the library, resolve function
|
(third_party/silentdragonxlite), which is the trust root. Prebuilt artifacts
|
||||||
pointers, call SDXL, sign, upload, or publish artifacts.
|
and self-attested signature metadata are NOT accepted (F15-1) — the previous
|
||||||
|
scheme only recorded an unverified "verified" claim. The script captures the
|
||||||
|
freshly-built artifact's symbols and checksum, and records build provenance.
|
||||||
|
It does not load the library, resolve function pointers, call SDXL, sign,
|
||||||
|
upload, or publish artifacts.
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,15 +166,8 @@ while [[ $# -gt 0 ]]; do
|
|||||||
OUT_DIR="$(absolute_path "$2")"
|
OUT_DIR="$(absolute_path "$2")"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--artifact)
|
--artifact|--no-build)
|
||||||
[[ $# -ge 2 ]] || die "--artifact requires a value"
|
die "$1 was removed (F15-1): the lite backend must be built from the vendored in-tree source (third_party/silentdragonxlite); prebuilt artifacts are no longer accepted."
|
||||||
ARTIFACT_PATH="$(absolute_path "$2")"
|
|
||||||
BUILD_ARTIFACT=false
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--no-build)
|
|
||||||
BUILD_ARTIFACT=false
|
|
||||||
shift
|
|
||||||
;;
|
;;
|
||||||
--reproducible)
|
--reproducible)
|
||||||
REPRODUCIBLE=true
|
REPRODUCIBLE=true
|
||||||
@@ -191,54 +184,11 @@ while [[ $# -gt 0 ]]; do
|
|||||||
BUILDER="$2"
|
BUILDER="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--signature-required)
|
--signature-required|--signature-file|--signature-path|--signature-format|\
|
||||||
SIGNATURE_REQUIRED=true
|
--signature-verification-tool|--signature-tool|--signature-verification-command|\
|
||||||
shift
|
--signature-key-fingerprint|--signature-certificate-identity|--signature-certificate-issuer|\
|
||||||
;;
|
--signature-transparency-log-url|--signature-verified-sha256)
|
||||||
--signature-file|--signature-path)
|
die "signature-attestation flags were removed (F15-1): they recorded a self-attested \"verified\" claim without running any cryptographic verifier. The lite backend is built from the vendored in-tree source, which is the trust root."
|
||||||
[[ $# -ge 2 ]] || die "$1 requires a value"
|
|
||||||
SIGNATURE_FILE="$(absolute_path "$2")"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--signature-format)
|
|
||||||
[[ $# -ge 2 ]] || die "--signature-format requires a value"
|
|
||||||
SIGNATURE_FORMAT="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--signature-verification-tool|--signature-tool)
|
|
||||||
[[ $# -ge 2 ]] || die "$1 requires a value"
|
|
||||||
SIGNATURE_VERIFICATION_TOOL="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--signature-verification-command)
|
|
||||||
[[ $# -ge 2 ]] || die "--signature-verification-command requires a value"
|
|
||||||
SIGNATURE_VERIFICATION_COMMAND="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--signature-key-fingerprint)
|
|
||||||
[[ $# -ge 2 ]] || die "--signature-key-fingerprint requires a value"
|
|
||||||
SIGNATURE_KEY_FINGERPRINT="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--signature-certificate-identity)
|
|
||||||
[[ $# -ge 2 ]] || die "--signature-certificate-identity requires a value"
|
|
||||||
SIGNATURE_CERTIFICATE_IDENTITY="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--signature-certificate-issuer)
|
|
||||||
[[ $# -ge 2 ]] || die "--signature-certificate-issuer requires a value"
|
|
||||||
SIGNATURE_CERTIFICATE_ISSUER="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--signature-transparency-log-url)
|
|
||||||
[[ $# -ge 2 ]] || die "--signature-transparency-log-url requires a value"
|
|
||||||
SIGNATURE_TRANSPARENCY_LOG_URL="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--signature-verified-sha256)
|
|
||||||
[[ $# -ge 2 ]] || die "--signature-verified-sha256 requires a value"
|
|
||||||
SIGNATURE_VERIFIED_SHA256="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
;;
|
||||||
-j|--jobs)
|
-j|--jobs)
|
||||||
[[ $# -ge 2 ]] || die "--jobs requires a value"
|
[[ $# -ge 2 ]] || die "--jobs requires a value"
|
||||||
@@ -374,6 +324,9 @@ prepare_backend_source() {
|
|||||||
ln -s "$BACKEND_SOURCE_DIR/src" "$prepared_root/src"
|
ln -s "$BACKEND_SOURCE_DIR/src" "$prepared_root/src"
|
||||||
[[ -f "$BACKEND_SOURCE_DIR/Cargo.lock" ]] && ln -s "$BACKEND_SOURCE_DIR/Cargo.lock" "$prepared_root/Cargo.lock"
|
[[ -f "$BACKEND_SOURCE_DIR/Cargo.lock" ]] && ln -s "$BACKEND_SOURCE_DIR/Cargo.lock" "$prepared_root/Cargo.lock"
|
||||||
[[ -d "$BACKEND_SOURCE_DIR/.cargo" ]] && ln -s "$BACKEND_SOURCE_DIR/.cargo" "$prepared_root/.cargo"
|
[[ -d "$BACKEND_SOURCE_DIR/.cargo" ]] && ln -s "$BACKEND_SOURCE_DIR/.cargo" "$prepared_root/.cargo"
|
||||||
|
# Honor the pinned Rust toolchain (rust-toolchain.toml) inside the prepared root too,
|
||||||
|
# so builds using --silentdragonxlitelib-dir still select rustc 1.63.
|
||||||
|
[[ -f "$BACKEND_SOURCE_DIR/rust-toolchain.toml" ]] && ln -s "$BACKEND_SOURCE_DIR/rust-toolchain.toml" "$prepared_root/rust-toolchain.toml"
|
||||||
[[ -d "$BACKEND_SOURCE_DIR/libsodium-mingw" ]] && ln -s "$BACKEND_SOURCE_DIR/libsodium-mingw" "$prepared_root/libsodium-mingw"
|
[[ -d "$BACKEND_SOURCE_DIR/libsodium-mingw" ]] && ln -s "$BACKEND_SOURCE_DIR/libsodium-mingw" "$prepared_root/libsodium-mingw"
|
||||||
# Vendored crate deps (offline builds): the .cargo/config.toml's vendored-sources directory is
|
# Vendored crate deps (offline builds): the .cargo/config.toml's vendored-sources directory is
|
||||||
# "vendor" relative to the build root, so expose it inside the prepared root too.
|
# "vendor" relative to the build root, so expose it inside the prepared root too.
|
||||||
@@ -766,6 +719,7 @@ MANIFEST_FILE="$PLATFORM_OUT_DIR/lite-backend-artifact-manifest.json"
|
|||||||
printf ' },\n'
|
printf ' },\n'
|
||||||
printf ' "provenance": {\n'
|
printf ' "provenance": {\n'
|
||||||
printf ' "owner_ready": true,\n'
|
printf ' "owner_ready": true,\n'
|
||||||
|
printf ' "built_from_source": true,\n'
|
||||||
printf ' "metadata_provided": true,\n'
|
printf ' "metadata_provided": true,\n'
|
||||||
printf ' "source": '; json_escape "$BACKEND_SOURCE_DIR"; printf ',\n'
|
printf ' "source": '; json_escape "$BACKEND_SOURCE_DIR"; printf ',\n'
|
||||||
printf ' "cargo_build_source": '; json_escape "$BUILD_BACKEND_DIR"; printf ',\n'
|
printf ' "cargo_build_source": '; json_escape "$BUILD_BACKEND_DIR"; printf ',\n'
|
||||||
|
|||||||
87
scripts/build_emoji_subset.py
Normal file
87
scripts/build_emoji_subset.py
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Build a monochrome Noto Emoji subset for the chat/message UI.
|
||||||
|
|
||||||
|
Dear ImGui rasterizes fonts with stb_truetype, which handles only monochrome
|
||||||
|
(outline `glyf`) fonts — NOT color emoji (CBDT/sbix/COLR). So we use Google's
|
||||||
|
*monochrome* Noto Emoji (github.com/google/fonts, ofl/notoemoji, OFL-licensed)
|
||||||
|
and merge it into the text fonts (see Typography::loadFont, the block after the
|
||||||
|
CJK merge). ImGui renders one glyph per codepoint with no shaping, so ZWJ
|
||||||
|
sequences / regional-indicator flags won't compose — single-codepoint emoji
|
||||||
|
(😀 🎉 ❤ 🔥 👍 …) render fine, which covers the overwhelming majority of use.
|
||||||
|
|
||||||
|
Source is the variable font pinned to wght=400 → static, then subset to the
|
||||||
|
emoji planes plus the higher symbol/star ranges the base UI font doesn't cover.
|
||||||
|
The base Ubuntu font already owns U+2600–26FF etc.; ImGui's MergeMode gives the
|
||||||
|
first-loaded glyph precedence, so those stay text-styled and only the codepoints
|
||||||
|
the base lacks fall through to this font.
|
||||||
|
|
||||||
|
Get the source once (OFL, redistributable):
|
||||||
|
curl -fsSL -o /tmp/NotoEmoji-VF.ttf \
|
||||||
|
'https://github.com/google/fonts/raw/main/ofl/notoemoji/NotoEmoji%5Bwght%5D.ttf'
|
||||||
|
|
||||||
|
Then: python3 scripts/build_emoji_subset.py
|
||||||
|
Output: res/fonts/NotoEmoji-Subset.ttf (committed; embedded via INCBIN)
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
from fontTools import ttLib, subset
|
||||||
|
from fontTools.varLib.instancer import instantiateVariableFont
|
||||||
|
|
||||||
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
SOURCE_VF = '/tmp/NotoEmoji-VF.ttf'
|
||||||
|
STATIC = '/tmp/NotoEmoji-Static.ttf'
|
||||||
|
OUTPUT = os.path.join(ROOT, 'res', 'fonts', 'NotoEmoji-Subset.ttf')
|
||||||
|
|
||||||
|
# Emoji codepoints to keep. Ranges are inclusive.
|
||||||
|
RANGES = [
|
||||||
|
(0x1F000, 0x1FAFF), # all the main emoji planes (emoticons, pictographs, transport, supplement, extended)
|
||||||
|
(0x2600, 0x27BF), # Miscellaneous Symbols + Dingbats
|
||||||
|
(0x2B00, 0x2BFF), # stars (⭐ 2B50) and misc arrows
|
||||||
|
(0xFE00, 0xFE0F), # variation selectors (VS16 emoji-style)
|
||||||
|
(0x2194, 0x21AA), # arrows used as emoji
|
||||||
|
(0x231A, 0x231B), # ⌚ ⌛
|
||||||
|
(0x23E9, 0x23FA), # media-control emoji
|
||||||
|
(0x25AA, 0x25FE), # small squares
|
||||||
|
]
|
||||||
|
SINGLES = [0x200D, 0x2934, 0x2935, 0x3030, 0x303D, 0x3297, 0x3299,
|
||||||
|
0x00A9, 0x00AE, 0x2122, 0x2139, 0x24C2]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if not os.path.exists(SOURCE_VF):
|
||||||
|
raise SystemExit(f"missing source font {SOURCE_VF} — see the header for the curl command")
|
||||||
|
|
||||||
|
# 1. Pin the weight axis so stb_truetype rasterizes a clean static instance.
|
||||||
|
f = ttLib.TTFont(SOURCE_VF)
|
||||||
|
if 'fvar' in f:
|
||||||
|
instantiateVariableFont(f, {'wght': 400}, inplace=True)
|
||||||
|
f.save(STATIC)
|
||||||
|
|
||||||
|
unicodes = list(SINGLES)
|
||||||
|
for lo, hi in RANGES:
|
||||||
|
unicodes.extend(range(lo, hi + 1))
|
||||||
|
|
||||||
|
opts = subset.Options()
|
||||||
|
opts.layout_features = [] # ImGui does no shaping — drop GSUB/GPOS
|
||||||
|
opts.name_IDs = []
|
||||||
|
opts.notdef_outline = True
|
||||||
|
opts.glyph_names = False
|
||||||
|
opts.drop_tables = ['GSUB', 'GPOS', 'GDEF', 'morx', 'kern']
|
||||||
|
|
||||||
|
font = subset.load_font(STATIC, opts)
|
||||||
|
ss = subset.Subsetter(options=opts)
|
||||||
|
ss.populate(unicodes=unicodes)
|
||||||
|
ss.subset(font)
|
||||||
|
subset.save_font(font, OUTPUT, opts)
|
||||||
|
|
||||||
|
out = ttLib.TTFont(OUTPUT)
|
||||||
|
cmap = out.getBestCmap()
|
||||||
|
color = any(t in out.reader.keys() for t in ('CBDT', 'sbix', 'COLR'))
|
||||||
|
print(f"Output: {OUTPUT}")
|
||||||
|
print(f"Size: {os.path.getsize(OUTPUT)//1024} KB | glyphs: {len(cmap)} | color tables: {color}")
|
||||||
|
if color:
|
||||||
|
raise SystemExit("ERROR: subset has color tables — stb_truetype cannot render it")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -24,18 +24,27 @@ if [ ! -f "${BUILD_DIR}/bin/ObsidianDragon" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for appimagetool
|
# Check for appimagetool — pinned to a tagged release and SHA-256 verified before we exec it.
|
||||||
|
# The old "continuous" tag is a moving, unverified network download that runs on the release
|
||||||
|
# builder; verify it or refuse to package.
|
||||||
|
APPIMAGETOOL_URL="https://github.com/AppImage/appimagetool/releases/download/1.9.0/appimagetool-x86_64.AppImage"
|
||||||
|
APPIMAGETOOL_SHA256="46fdd785094c7f6e545b61afcfb0f3d98d8eab243f644b4b17698c01d06083d1"
|
||||||
APPIMAGETOOL=""
|
APPIMAGETOOL=""
|
||||||
if command -v appimagetool &> /dev/null; then
|
if command -v appimagetool &> /dev/null; then
|
||||||
APPIMAGETOOL="appimagetool"
|
APPIMAGETOOL="appimagetool" # maintainer's own trusted system install
|
||||||
elif [ -f "${BUILD_DIR}/appimagetool-x86_64.AppImage" ]; then
|
|
||||||
APPIMAGETOOL="${BUILD_DIR}/appimagetool-x86_64.AppImage"
|
|
||||||
else
|
else
|
||||||
print_status "Downloading appimagetool..."
|
AT="${BUILD_DIR}/appimagetool-x86_64.AppImage"
|
||||||
wget -q -O "${BUILD_DIR}/appimagetool-x86_64.AppImage" \
|
if [ ! -f "$AT" ] || ! echo "${APPIMAGETOOL_SHA256} ${AT}" | sha256sum -c --status; then
|
||||||
"https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
|
print_status "Downloading appimagetool 1.9.0 (pinned)..."
|
||||||
chmod +x "${BUILD_DIR}/appimagetool-x86_64.AppImage"
|
wget -q -O "$AT" "$APPIMAGETOOL_URL"
|
||||||
APPIMAGETOOL="${BUILD_DIR}/appimagetool-x86_64.AppImage"
|
if ! echo "${APPIMAGETOOL_SHA256} ${AT}" | sha256sum -c --status; then
|
||||||
|
print_error "appimagetool SHA-256 verification failed — refusing to use it"
|
||||||
|
rm -f "$AT"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
chmod +x "$AT"
|
||||||
|
fi
|
||||||
|
APPIMAGETOOL="$AT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_status "Creating AppDir structure..."
|
print_status "Creating AppDir structure..."
|
||||||
|
|||||||
@@ -256,8 +256,8 @@ HEADER_START
|
|||||||
echo -e "${YELLOW}Note: Daemon binaries not found in prebuilt-binaries/dragonxd-win/ — wallet only${NC}"
|
echo -e "${YELLOW}Note: Daemon binaries not found in prebuilt-binaries/dragonxd-win/ — wallet only${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── xmrig binary (from prebuilt-binaries/xmrig-hac/) ────────────────
|
# ── xmrig binary (from prebuilt-binaries/drg-xmrig/) ────────────────
|
||||||
XMRIG_DIR="$SCRIPT_DIR/prebuilt-binaries/xmrig-hac"
|
XMRIG_DIR="$SCRIPT_DIR/prebuilt-binaries/drg-xmrig"
|
||||||
if [ -f "$XMRIG_DIR/xmrig.exe" ]; then
|
if [ -f "$XMRIG_DIR/xmrig.exe" ]; then
|
||||||
cp -f "$XMRIG_DIR/xmrig.exe" "$EMBED_RES_DIR/xmrig.exe"
|
cp -f "$XMRIG_DIR/xmrig.exe" "$EMBED_RES_DIR/xmrig.exe"
|
||||||
echo " Staged xmrig.exe ($(du -h "$XMRIG_DIR/xmrig.exe" | cut -f1))"
|
echo " Staged xmrig.exe ($(du -h "$XMRIG_DIR/xmrig.exe" | cut -f1))"
|
||||||
|
|||||||
@@ -1,25 +1,31 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Sign dragonx full-node release archives for the wallet's in-app daemon updater (ed25519).
|
# Package the prebuilt dragonx full-node binaries into per-platform release archives and sign them
|
||||||
|
# for the wallet's in-app daemon updater (ed25519 over the EXACT archive bytes).
|
||||||
#
|
#
|
||||||
# The wallet verifies a detached ed25519 signature over the EXACT archive bytes against a public
|
# The wallet verifies a detached ed25519 signature over the archive bytes against a public key
|
||||||
# key pinned in src/util/daemon_updater.h (kDaemonSignaturePublicKeyBase64). Verification is
|
# pinned in src/util/daemon_updater.h (kDaemonSignaturePublicKeyBase64). Verification is MANDATORY
|
||||||
# MANDATORY (kDaemonRequireSignature = true): an in-app update is refused unless a valid signature
|
# (kDaemonRequireSignature = true): an in-app update is refused unless a valid "<archive>.sig" is
|
||||||
# is published. For each archive <name>.zip this produces <name>.zip.sig holding the base64 of the
|
# published next to the archive. The wallet also checks each archive's SHA-256 against a markdown
|
||||||
# raw 64-byte ed25519 signature — upload that .sig next to the .zip as a release asset.
|
# checksum table in the release body, so `release` prints that table for you to paste in.
|
||||||
#
|
#
|
||||||
# Uses OpenSSL (>= 1.1.1) only — no Python/PyNaCl needed. OpenSSL's ed25519 is PureEdDSA (RFC 8032),
|
# Uses OpenSSL (>= 1.1.1) only — no Python/PyNaCl. OpenSSL's ed25519 is PureEdDSA (RFC 8032), the
|
||||||
# the same primitive libsodium's crypto_sign_verify_detached checks, so signatures are compatible
|
# same primitive libsodium's crypto_sign_verify_detached checks, so the signatures are compatible.
|
||||||
# (the same flow the wallet's unit tests verify for the miner updater).
|
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# scripts/sign-daemon-release.sh keygen [out-prefix] # -> <prefix>.ed25519.{key,pub.b64}
|
# scripts/sign-daemon-release.sh keygen [out-prefix] # -> <prefix>.ed25519.{key,pub.b64}
|
||||||
# scripts/sign-daemon-release.sh pubkey <secret.key> # print the base64 public key to pin
|
# scripts/sign-daemon-release.sh pubkey <secret.key> # print the base64 public key to pin
|
||||||
# scripts/sign-daemon-release.sh sign <secret.key> <file>...# -> <file>.sig per file
|
# scripts/sign-daemon-release.sh sign <secret.key> <file>... # sign existing files -> <file>.sig
|
||||||
|
# scripts/sign-daemon-release.sh release <secret.key> <version> [--src DIR] [--out DIR]
|
||||||
|
# # zip prebuilt-binaries/dragonxd-{linux,mac,win}/ into dragonx-<version>-{linux-amd64,macos,
|
||||||
|
# # win64}.zip, sign each, and print the SHA-256 checksum table. Platforms with no dragonxd
|
||||||
|
# # binary staged are skipped.
|
||||||
#
|
#
|
||||||
# Keep the secret key (.ed25519.key) OFFLINE. Paste the base64 public key into
|
# Keep the secret key (.ed25519.key) OFFLINE (mode 600). Paste the base64 public key into
|
||||||
# kDaemonSignaturePublicKeyBase64 in src/util/daemon_updater.h.
|
# kDaemonSignaturePublicKeyBase64 in src/util/daemon_updater.h.
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
die() { echo "error: $*" >&2; exit 1; }
|
die() { echo "error: $*" >&2; exit 1; }
|
||||||
command -v openssl >/dev/null || die "openssl not found (need >= 1.1.1 with ed25519)"
|
command -v openssl >/dev/null || die "openssl not found (need >= 1.1.1 with ed25519)"
|
||||||
|
|
||||||
@@ -27,6 +33,26 @@ command -v openssl >/dev/null || die "openssl not found (need >= 1.1.1 with ed25
|
|||||||
# ed25519 is a fixed 12-byte prefix + the 32-byte key, so the trailing 32 bytes are the raw key.
|
# ed25519 is a fixed 12-byte prefix + the 32-byte key, so the trailing 32 bytes are the raw key.
|
||||||
pubkey_b64() { openssl pkey -in "$1" -pubout -outform DER | tail -c 32 | openssl base64 -A; }
|
pubkey_b64() { openssl pkey -in "$1" -pubout -outform DER | tail -c 32 | openssl base64 -A; }
|
||||||
|
|
||||||
|
sha256_of() {
|
||||||
|
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{print $1}';
|
||||||
|
else shasum -a 256 "$1" | awk '{print $1}'; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Detached ed25519 signature over the raw file bytes -> <file>.sig (base64 of the 64-byte sig).
|
||||||
|
sign_file() {
|
||||||
|
local key="$1" f="$2" raw
|
||||||
|
raw="$(mktemp)"
|
||||||
|
openssl pkeyutl -sign -inkey "$key" -rawin -in "$f" -out "$raw"
|
||||||
|
openssl base64 -A -in "$raw" > "$f.sig"
|
||||||
|
printf '\n' >> "$f.sig"
|
||||||
|
rm -f "$raw"
|
||||||
|
}
|
||||||
|
|
||||||
|
# platform -> (staging dir under prebuilt-binaries, release token, expected daemon binary name)
|
||||||
|
plat_dir() { case "$1" in linux) echo dragonxd-linux;; mac) echo dragonxd-mac;; win) echo dragonxd-win;; esac; }
|
||||||
|
plat_token() { case "$1" in linux) echo linux-amd64;; mac) echo macos;; win) echo win64;; esac; }
|
||||||
|
plat_daemon() { case "$1" in win) echo dragonxd.exe;; *) echo dragonxd;; esac; }
|
||||||
|
|
||||||
cmd="${1:-}"; shift || true
|
cmd="${1:-}"; shift || true
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
keygen)
|
keygen)
|
||||||
@@ -42,26 +68,90 @@ case "$cmd" in
|
|||||||
echo "Pin this in src/util/daemon_updater.h (kDaemonSignaturePublicKeyBase64):"
|
echo "Pin this in src/util/daemon_updater.h (kDaemonSignaturePublicKeyBase64):"
|
||||||
echo " $pub"
|
echo " $pub"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
pubkey)
|
pubkey)
|
||||||
[ $# -ge 1 ] || die "usage: pubkey <secret.key>"
|
[ $# -ge 1 ] || die "usage: pubkey <secret.key>"
|
||||||
pubkey_b64 "$1"
|
pubkey_b64 "$1"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
sign)
|
sign)
|
||||||
[ $# -ge 2 ] || die "usage: sign <secret.key> <file>..."
|
[ $# -ge 2 ] || die "usage: sign <secret.key> <file>..."
|
||||||
key="$1"; shift
|
key="$1"; shift
|
||||||
[ -f "$key" ] || die "no such key: $key"
|
[ -f "$key" ] || die "no such key: $key"
|
||||||
for f in "$@"; do
|
for f in "$@"; do
|
||||||
[ -f "$f" ] || die "no such file: $f"
|
[ -f "$f" ] || die "no such file: $f"
|
||||||
raw="$(mktemp)"
|
sign_file "$key" "$f"
|
||||||
openssl pkeyutl -sign -inkey "$key" -rawin -in "$f" -out "$raw"
|
|
||||||
openssl base64 -A -in "$raw" > "$f.sig"
|
|
||||||
printf '\n' >> "$f.sig"
|
|
||||||
rm -f "$raw"
|
|
||||||
echo "signed: $f -> $f.sig"
|
echo "signed: $f -> $f.sig"
|
||||||
done
|
done
|
||||||
echo "Upload each .sig as a release asset next to its archive."
|
echo "Upload each .sig as a release asset next to its archive."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
release)
|
||||||
|
[ $# -ge 2 ] || die "usage: release <secret.key> <version> [--src DIR] [--out DIR]"
|
||||||
|
key="$1"; version="$2"; shift 2
|
||||||
|
src="$PROJECT_ROOT/prebuilt-binaries"
|
||||||
|
out="$PROJECT_ROOT/release/daemon"
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
--src) [ $# -ge 2 ] || die "--src needs a value"; src="$2"; shift 2 ;;
|
||||||
|
--out) [ $# -ge 2 ] || die "--out needs a value"; out="$2"; shift 2 ;;
|
||||||
|
*) die "unknown option: $1" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
[ -f "$key" ] || die "no such key: $key"
|
||||||
|
[ -d "$src" ] || die "no such source dir: $src"
|
||||||
|
command -v zip >/dev/null 2>&1 || die "zip not found (install 'zip')"
|
||||||
|
mkdir -p "$out"
|
||||||
|
|
||||||
|
# Sanity: warn if this key does not match the public key pinned in the wallet (the wallet would
|
||||||
|
# then reject every signature made with it — only expected when deliberately rotating the key).
|
||||||
|
pinned="$(grep -oE '"[A-Za-z0-9+/]{43}="' "$PROJECT_ROOT/src/util/daemon_updater.h" 2>/dev/null | head -1 | tr -d '"')"
|
||||||
|
mine="$(pubkey_b64 "$key")"
|
||||||
|
if [ -n "$pinned" ] && [ "$pinned" != "$mine" ]; then
|
||||||
|
echo "WARNING: this key's public key does not match the one pinned in daemon_updater.h:" >&2
|
||||||
|
echo " signing key -> $mine" >&2
|
||||||
|
echo " pinned key -> $pinned" >&2
|
||||||
|
echo " The wallet will REJECT these signatures unless you are rotating the pinned key." >&2
|
||||||
|
echo >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
made=0
|
||||||
|
table=""
|
||||||
|
for plat in linux mac win; do
|
||||||
|
d="$src/$(plat_dir "$plat")"
|
||||||
|
daemon="$d/$(plat_daemon "$plat")"
|
||||||
|
if [ ! -f "$daemon" ]; then
|
||||||
|
echo "skip $plat: no $(plat_daemon "$plat") staged in $d" >&2
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
archive="dragonx-$version-$(plat_token "$plat").zip"
|
||||||
|
apath="$out/$archive"
|
||||||
|
rm -f "$apath"
|
||||||
|
# Zip the staged files at the archive root (binaries + sapling params + asmap), excluding
|
||||||
|
# the .gitkeep placeholder. The updater flattens paths via baseName(), so a flat zip is fine.
|
||||||
|
files=()
|
||||||
|
while IFS= read -r fn; do files+=("$fn"); done < <(cd "$d" && ls -A | grep -vx '.gitkeep')
|
||||||
|
[ "${#files[@]}" -gt 0 ] || { echo "skip $plat: nothing to package in $d" >&2; continue; }
|
||||||
|
( cd "$d" && zip -q -X "$apath" "${files[@]}" )
|
||||||
|
sign_file "$key" "$apath"
|
||||||
|
sum="$(sha256_of "$apath")"
|
||||||
|
table+="| $archive | \`$sum\` |"$'\n'
|
||||||
|
echo "packaged + signed: $apath (+ .sig) sha256=$sum"
|
||||||
|
made=$((made + 1))
|
||||||
|
done
|
||||||
|
[ "$made" -gt 0 ] || die "no platform had a staged daemon binary under $src/dragonxd-{linux,mac,win}/"
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Checksum table (paste into the release body so the wallet can verify SHA-256):"
|
||||||
|
echo "| Archive | SHA-256 |"
|
||||||
|
echo "|---|---|"
|
||||||
|
printf '%s' "$table"
|
||||||
|
echo
|
||||||
|
echo "Upload each .zip AND its .zip.sig as release assets. Wallet enforces the ed25519 signature"
|
||||||
|
echo "(kDaemonRequireSignature=true) and the SHA-256 from the table above."
|
||||||
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
die "usage: $0 {keygen [prefix] | pubkey <secret.key> | sign <secret.key> <file>...}"
|
die "usage: $0 {keygen [prefix] | pubkey <secret.key> | sign <secret.key> <file>... | release <secret.key> <version> [--src DIR] [--out DIR]}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
68
setup.sh
68
setup.sh
@@ -133,7 +133,7 @@ pkgs_core_arch="base-devel cmake git pkg-config
|
|||||||
libxkbcommon wayland libsodium curl
|
libxkbcommon wayland libsodium curl
|
||||||
autoconf automake libtool wget python xxd"
|
autoconf automake libtool wget python xxd"
|
||||||
|
|
||||||
pkgs_core_macos="cmake python xxd"
|
pkgs_core_macos="bash cmake python xxd"
|
||||||
|
|
||||||
# Windows cross-compile (from Linux)
|
# Windows cross-compile (from Linux)
|
||||||
pkgs_win_debian="mingw-w64 zip"
|
pkgs_win_debian="mingw-w64 zip"
|
||||||
@@ -284,6 +284,14 @@ fi
|
|||||||
header "Windows Cross-Compile"
|
header "Windows Cross-Compile"
|
||||||
|
|
||||||
if $SETUP_WIN; then
|
if $SETUP_WIN; then
|
||||||
|
# Only touch apt / update-alternatives (which need sudo) when the toolchain is missing. If it is
|
||||||
|
# already installed, skip them so `./setup.sh --win` can run WITHOUT sudo — important because the
|
||||||
|
# daemon cross-compile that follows should run as the invoking user. Running the whole setup under
|
||||||
|
# sudo leaves root-owned build artifacts under external/dragonx, which then break `make clean` on
|
||||||
|
# a later non-sudo build (stale objects get relinked -> the mingw link failure recurs).
|
||||||
|
if has_cmd x86_64-w64-mingw32-g++-posix || has_cmd x86_64-w64-mingw32-g++; then
|
||||||
|
ok "Windows cross-compile toolchain already present — skipping apt install"
|
||||||
|
else
|
||||||
win_pkgs="$(get_pkgs win)"
|
win_pkgs="$(get_pkgs win)"
|
||||||
if [[ -n "$win_pkgs" ]]; then
|
if [[ -n "$win_pkgs" ]]; then
|
||||||
install_pkgs "$win_pkgs" "Windows cross-compile"
|
install_pkgs "$win_pkgs" "Windows cross-compile"
|
||||||
@@ -298,6 +306,7 @@ if $SETUP_WIN; then
|
|||||||
/usr/bin/x86_64-w64-mingw32-g++-posix 2>/dev/null || true
|
/usr/bin/x86_64-w64-mingw32-g++-posix 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Fetch libsodium for Windows
|
# Fetch libsodium for Windows
|
||||||
if [[ ! -f "$PROJECT_DIR/libs/libsodium-win/lib/libsodium.a" ]]; then
|
if [[ ! -f "$PROJECT_DIR/libs/libsodium-win/lib/libsodium.a" ]]; then
|
||||||
@@ -391,11 +400,26 @@ elif $SETUP_SAPLING; then
|
|||||||
|
|
||||||
SPEND_URL="https://z.cash/downloads/sapling-spend.params"
|
SPEND_URL="https://z.cash/downloads/sapling-spend.params"
|
||||||
OUTPUT_URL="https://z.cash/downloads/sapling-output.params"
|
OUTPUT_URL="https://z.cash/downloads/sapling-output.params"
|
||||||
|
# Consensus-critical MPC parameters with fixed, well-known SHA-256 (identical across every
|
||||||
|
# Zcash-family node; also pinned in scripts/build-lite-backend-artifact.sh). z.cash is
|
||||||
|
# plain HTTPS with no signature, so verify the digest and refuse a tampered/corrupt file.
|
||||||
|
SPEND_SHA256="8e48ffd23abb3a5fd9c5589204f32d9c31285a04b78096ba40a79b75677efc13"
|
||||||
|
OUTPUT_SHA256="2f0ebbcbb9bb0bcffe95a397e7eba89c29eb4dde6191c339db88570e3f3fb0e4"
|
||||||
|
|
||||||
curl -fSL -o "$PARAMS_DIR/sapling-spend.params" "$SPEND_URL" && \
|
if curl -fSL -o "$PARAMS_DIR/sapling-spend.params" "$SPEND_URL" \
|
||||||
ok "Downloaded sapling-spend.params"
|
&& echo "${SPEND_SHA256} $PARAMS_DIR/sapling-spend.params" | sha256sum -c --status; then
|
||||||
curl -fSL -o "$PARAMS_DIR/sapling-output.params" "$OUTPUT_URL" && \
|
ok "Downloaded + verified sapling-spend.params"
|
||||||
ok "Downloaded sapling-output.params"
|
else
|
||||||
|
rm -f "$PARAMS_DIR/sapling-spend.params"
|
||||||
|
err "sapling-spend.params download or SHA-256 verification failed — not installed"
|
||||||
|
fi
|
||||||
|
if curl -fSL -o "$PARAMS_DIR/sapling-output.params" "$OUTPUT_URL" \
|
||||||
|
&& echo "${OUTPUT_SHA256} $PARAMS_DIR/sapling-output.params" | sha256sum -c --status; then
|
||||||
|
ok "Downloaded + verified sapling-output.params"
|
||||||
|
else
|
||||||
|
rm -f "$PARAMS_DIR/sapling-output.params"
|
||||||
|
err "sapling-output.params download or SHA-256 verification failed — not installed"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
skip "Sapling params not found (use --sapling to download, or they'll be extracted at runtime from embedded builds)"
|
skip "Sapling params not found (use --sapling to download, or they'll be extracted at runtime from embedded builds)"
|
||||||
@@ -684,11 +708,13 @@ if [[ "$STALE_DAEMON" -eq 1 ]]; then
|
|||||||
warn " Linux: ./setup.sh · Windows: ./setup.sh --win · macOS: ./setup.sh --mac"
|
warn " Linux: ./setup.sh · Windows: ./setup.sh --win · macOS: ./setup.sh --mac"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── 7. xmrig-hac (mining binary) ────────────────────────────────────────────
|
# ── 7. drg-xmrig (mining binary) ────────────────────────────────────────────
|
||||||
header "xmrig-hac Mining Binary"
|
header "drg-xmrig Mining Binary"
|
||||||
|
|
||||||
XMRIG_SRC="$PROJECT_DIR/external/xmrig-hac"
|
XMRIG_SRC="$PROJECT_DIR/external/drg-xmrig"
|
||||||
XMRIG_PREBUILT="$PROJECT_DIR/prebuilt-binaries/xmrig-hac"
|
# Output dir bundled by build.sh (Linux zip, AppImage, Windows embed, mac .app)
|
||||||
|
# and scripts/legacy/build-windows.sh — keep this path in sync with those.
|
||||||
|
XMRIG_PREBUILT="$PROJECT_DIR/prebuilt-binaries/drg-xmrig"
|
||||||
|
|
||||||
# Clean previous prebuilt xmrig binaries so we always rebuild
|
# Clean previous prebuilt xmrig binaries so we always rebuild
|
||||||
# Only clean the binary for the platform(s) we are actually building,
|
# Only clean the binary for the platform(s) we are actually building,
|
||||||
@@ -700,14 +726,14 @@ if ! $CHECK_ONLY; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Helper: clone xmrig-hac if not present
|
# Helper: clone drg-xmrig if not present
|
||||||
clone_xmrig_if_needed() {
|
clone_xmrig_if_needed() {
|
||||||
if [[ ! -d "$XMRIG_SRC" ]]; then
|
if [[ ! -d "$XMRIG_SRC" ]]; then
|
||||||
info "Cloning xmrig-hac..."
|
info "Cloning drg-xmrig..."
|
||||||
git clone https://git.dragonx.is/dragonx/xmrig-hac.git "$XMRIG_SRC"
|
git clone https://git.dragonx.is/DragonX/drg-xmrig.git "$XMRIG_SRC"
|
||||||
else
|
else
|
||||||
ok "xmrig-hac source already present"
|
ok "drg-xmrig source already present"
|
||||||
info "Pulling latest xmrig-hac..."
|
info "Pulling latest drg-xmrig..."
|
||||||
(cd "$XMRIG_SRC" && git pull --ff-only 2>/dev/null || true)
|
(cd "$XMRIG_SRC" && git pull --ff-only 2>/dev/null || true)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -728,15 +754,15 @@ else
|
|||||||
rm -rf "$XMRIG_SRC/build"
|
rm -rf "$XMRIG_SRC/build"
|
||||||
|
|
||||||
# Build dependencies (libuv, hwloc, openssl)
|
# Build dependencies (libuv, hwloc, openssl)
|
||||||
info "Building xmrig-hac dependencies (libuv, hwloc, openssl)..."
|
info "Building drg-xmrig dependencies (libuv, hwloc, openssl)..."
|
||||||
(
|
(
|
||||||
cd "$XMRIG_SRC/scripts"
|
cd "$XMRIG_SRC/scripts"
|
||||||
sh build_deps.sh
|
sh build_deps.sh
|
||||||
)
|
)
|
||||||
ok "xmrig-hac dependencies built"
|
ok "drg-xmrig dependencies built"
|
||||||
|
|
||||||
# Build xmrig
|
# Build xmrig
|
||||||
info "Building xmrig-hac (Linux)..."
|
info "Building drg-xmrig (Linux)..."
|
||||||
mkdir -p "$XMRIG_SRC/build"
|
mkdir -p "$XMRIG_SRC/build"
|
||||||
(
|
(
|
||||||
cd "$XMRIG_SRC/build"
|
cd "$XMRIG_SRC/build"
|
||||||
@@ -753,7 +779,7 @@ else
|
|||||||
mkdir -p "$XMRIG_PREBUILT"
|
mkdir -p "$XMRIG_PREBUILT"
|
||||||
if [[ -f "$XMRIG_SRC/build/xmrig" ]]; then
|
if [[ -f "$XMRIG_SRC/build/xmrig" ]]; then
|
||||||
cp "$XMRIG_SRC/build/xmrig" "$XMRIG_LINUX"
|
cp "$XMRIG_SRC/build/xmrig" "$XMRIG_LINUX"
|
||||||
ok "xmrig (Linux) built and installed to prebuilt-binaries/xmrig-hac/"
|
ok "xmrig (Linux) built and installed to prebuilt-binaries/drg-xmrig/"
|
||||||
else
|
else
|
||||||
err "xmrig (Linux) build failed — binary not found"
|
err "xmrig (Linux) build failed — binary not found"
|
||||||
MISSING=$((MISSING + 1))
|
MISSING=$((MISSING + 1))
|
||||||
@@ -777,7 +803,7 @@ else
|
|||||||
# Clean previous Windows build
|
# Clean previous Windows build
|
||||||
rm -rf "$XMRIG_SRC/build-windows"
|
rm -rf "$XMRIG_SRC/build-windows"
|
||||||
|
|
||||||
info "Building xmrig-hac (Windows cross-compile)..."
|
info "Building drg-xmrig (Windows cross-compile)..."
|
||||||
(
|
(
|
||||||
cd "$XMRIG_SRC/scripts"
|
cd "$XMRIG_SRC/scripts"
|
||||||
bash build_windows.sh
|
bash build_windows.sh
|
||||||
@@ -787,7 +813,7 @@ else
|
|||||||
mkdir -p "$XMRIG_PREBUILT"
|
mkdir -p "$XMRIG_PREBUILT"
|
||||||
if [[ -f "$XMRIG_SRC/build-windows/xmrig.exe" ]]; then
|
if [[ -f "$XMRIG_SRC/build-windows/xmrig.exe" ]]; then
|
||||||
cp "$XMRIG_SRC/build-windows/xmrig.exe" "$XMRIG_WIN"
|
cp "$XMRIG_SRC/build-windows/xmrig.exe" "$XMRIG_WIN"
|
||||||
ok "xmrig.exe (Windows) built and installed to prebuilt-binaries/xmrig-hac/"
|
ok "xmrig.exe (Windows) built and installed to prebuilt-binaries/drg-xmrig/"
|
||||||
else
|
else
|
||||||
err "xmrig.exe (Windows) build failed — binary not found"
|
err "xmrig.exe (Windows) build failed — binary not found"
|
||||||
MISSING=$((MISSING + 1))
|
MISSING=$((MISSING + 1))
|
||||||
@@ -797,7 +823,7 @@ fi
|
|||||||
# ── 8. Binary directories ───────────────────────────────────────────────────
|
# ── 8. Binary directories ───────────────────────────────────────────────────
|
||||||
header "Binary Directories"
|
header "Binary Directories"
|
||||||
|
|
||||||
for platform in dragonxd-linux dragonxd-win dragonxd-mac xmrig; do
|
for platform in dragonxd-linux dragonxd-win dragonxd-mac drg-xmrig; do
|
||||||
dir="$PROJECT_DIR/prebuilt-binaries/$platform"
|
dir="$PROJECT_DIR/prebuilt-binaries/$platform"
|
||||||
if [[ -d "$dir" ]]; then
|
if [[ -d "$dir" ]]; then
|
||||||
# Count actual files (not .gitkeep)
|
# Count actual files (not .gitkeep)
|
||||||
|
|||||||
2328
src/app.cpp
2328
src/app.cpp
File diff suppressed because it is too large
Load Diff
402
src/app.h
402
src/app.h
@@ -13,6 +13,8 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <deque>
|
||||||
|
#include <condition_variable>
|
||||||
#include <nlohmann/json_fwd.hpp>
|
#include <nlohmann/json_fwd.hpp>
|
||||||
#include "data/transaction_history_cache.h"
|
#include "data/transaction_history_cache.h"
|
||||||
#include "data/address_book.h"
|
#include "data/address_book.h"
|
||||||
@@ -70,6 +72,19 @@ enum class EncryptDialogPhase {
|
|||||||
Done // Finished — close dialog
|
Done // Finished — close dialog
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// A status string written by a background/worker thread and read every frame by the UI thread. Its
|
||||||
|
// operator= locks, so all the plain `x = "..."` assignment sites stay unchanged; readers call get()
|
||||||
|
// for a consistent per-frame snapshot instead of racing a non-atomic std::string. (M-05, L-06)
|
||||||
|
class GuardedStatus {
|
||||||
|
public:
|
||||||
|
GuardedStatus() = default;
|
||||||
|
GuardedStatus& operator=(std::string v) { std::lock_guard<std::mutex> lk(m_); v_ = std::move(v); return *this; }
|
||||||
|
std::string get() const { std::lock_guard<std::mutex> lk(m_); return v_; }
|
||||||
|
private:
|
||||||
|
mutable std::mutex m_;
|
||||||
|
std::string v_;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Main application class
|
* @brief Main application class
|
||||||
*
|
*
|
||||||
@@ -78,6 +93,7 @@ enum class EncryptDialogPhase {
|
|||||||
class App {
|
class App {
|
||||||
public:
|
public:
|
||||||
App();
|
App();
|
||||||
|
void wipeSecrets(); // scrub all resident secret buffers; called from ~App() AND the forced-exit path (L-05)
|
||||||
~App();
|
~App();
|
||||||
|
|
||||||
// Non-copyable
|
// Non-copyable
|
||||||
@@ -139,10 +155,25 @@ public:
|
|||||||
* @brief Whether we are in the shutdown phase
|
* @brief Whether we are in the shutdown phase
|
||||||
*/
|
*/
|
||||||
bool isShuttingDown() const { return shutting_down_; }
|
bool isShuttingDown() const { return shutting_down_; }
|
||||||
|
// True while the wallet-switch progress modal is open — keeps the frame loop redrawing so its live
|
||||||
|
// phase/spinner update in real time even when the app is otherwise idle.
|
||||||
|
bool isWalletSwitchInProgress() const { return wallet_switch_dialog_open_.load(); }
|
||||||
wallet::WalletCapabilities walletCapabilities() const { return wallet::currentWalletCapabilities(); }
|
wallet::WalletCapabilities walletCapabilities() const { return wallet::currentWalletCapabilities(); }
|
||||||
bool isLiteBuild() const { return wallet::isLiteBuild(walletCapabilities()); }
|
bool isLiteBuild() const { return wallet::isLiteBuild(walletCapabilities()); }
|
||||||
bool supportsEmbeddedDaemon() const { return wallet::supportsEmbeddedDaemon(walletCapabilities()); }
|
bool supportsEmbeddedDaemon() const { return wallet::supportsEmbeddedDaemon(walletCapabilities()); }
|
||||||
bool supportsFullNodeLifecycleActions() const { return wallet::supportsFullNodeLifecycleActions(walletCapabilities()); }
|
bool supportsFullNodeLifecycleActions() const { return wallet::supportsFullNodeLifecycleActions(walletCapabilities()); }
|
||||||
|
|
||||||
|
// Daemon (v1.3.0+) coinbase auto-shield status, from z_autoshieldstatus. "Not probed" / all-false on
|
||||||
|
// pre-1.3.0 daemons (no such RPC) — callers treat that as "the wallet handles auto-shield itself".
|
||||||
|
bool daemonAutoShieldProbed() const { return daemon_autoshield_probed_; }
|
||||||
|
bool daemonAutoShieldActive() const { return daemon_autoshield_active_; }
|
||||||
|
const std::string& daemonAutoShieldAddress() const { return daemon_autoshield_address_; }
|
||||||
|
const std::string& daemonAutoShieldDisabledReason() const { return daemon_autoshield_disabled_reason_; }
|
||||||
|
bool daemonAutoShieldSeedRecoverable() const { return daemon_autoshield_seed_recoverable_; }
|
||||||
|
|
||||||
|
// W7 QoL: a plaintext support-diagnostics snapshot (version, variant, daemon/RPC/wallet/log state)
|
||||||
|
// for the "Copy diagnostics" action. Contains no secrets.
|
||||||
|
std::string buildDiagnosticsReport();
|
||||||
bool supportsSoloMining() const { return wallet::supportsSoloMining(walletCapabilities()); }
|
bool supportsSoloMining() const { return wallet::supportsSoloMining(walletCapabilities()); }
|
||||||
bool supportsPoolMining() const { return wallet::supportsPoolMining(walletCapabilities()); }
|
bool supportsPoolMining() const { return wallet::supportsPoolMining(walletCapabilities()); }
|
||||||
bool supportsLiteBackend() const { return wallet::supportsLiteBackend(walletCapabilities()); }
|
bool supportsLiteBackend() const { return wallet::supportsLiteBackend(walletCapabilities()); }
|
||||||
@@ -152,6 +183,21 @@ public:
|
|||||||
*/
|
*/
|
||||||
void renderShutdownScreen();
|
void renderShutdownScreen();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Tail the last N lines of the daemon's debug.log (best-effort, reads only the file tail).
|
||||||
|
* Fallback for the shutdown screen when we have no captured stdout — e.g. an external daemon we
|
||||||
|
* attached to rather than spawned — so the user can still see the node flushing/exiting.
|
||||||
|
*/
|
||||||
|
std::vector<std::string> tailDaemonDebugLog(int maxLines) const;
|
||||||
|
|
||||||
|
// True when the daemon's debug.log shows an in-progress Sapling witness-cache rebuild (best-effort
|
||||||
|
// heuristic). Stopping the daemon during one discards it and forces a multi-minute redo next launch.
|
||||||
|
bool daemonWitnessRebuildActive() const;
|
||||||
|
// Whether beginShutdown() should pause and confirm before stopping the daemon (rebuild in progress).
|
||||||
|
bool shouldConfirmDaemonStop() const;
|
||||||
|
// The "node is rebuilding — stop anyway / keep running / cancel" modal, rendered from render().
|
||||||
|
void renderDaemonStopConfirm();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Render loading overlay in content area while daemon is starting/syncing
|
* @brief Render loading overlay in content area while daemon is starting/syncing
|
||||||
* @param contentH Height of the content area child window
|
* @param contentH Height of the content area child window
|
||||||
@@ -168,6 +214,9 @@ public:
|
|||||||
daemon::EmbeddedDaemon* consoleDaemon();
|
daemon::EmbeddedDaemon* consoleDaemon();
|
||||||
daemon::XmrigManager* consoleXmrig();
|
daemon::XmrigManager* consoleXmrig();
|
||||||
config::Settings* settings() { return settings_.get(); }
|
config::Settings* settings() { return settings_.get(); }
|
||||||
|
// Request a font-atlas rebuild before the next frame (e.g. after toggling color emoji). Handled in
|
||||||
|
// preFrame() via Typography::reload — safe to call from UI code mid-frame.
|
||||||
|
void requestFontRebuild() { font_rebuild_requested_ = true; }
|
||||||
// Lite wallet controller (non-null only in lite builds with a linked backend).
|
// Lite wallet controller (non-null only in lite builds with a linked backend).
|
||||||
wallet::LiteWalletController* liteWallet() { return lite_wallet_.get(); }
|
wallet::LiteWalletController* liteWallet() { return lite_wallet_.get(); }
|
||||||
// HushChat service (identity + in-memory message store); the Chat tab reads its store.
|
// HushChat service (identity + in-memory message store); the Chat tab reads its store.
|
||||||
@@ -176,6 +225,9 @@ public:
|
|||||||
// message (to a conversation whose peer key we know) / a new-conversation contact request.
|
// message (to a conversation whose peer key we know) / a new-conversation contact request.
|
||||||
void sendChatMessage(const std::string& conversationId, const std::string& text);
|
void sendChatMessage(const std::string& conversationId, const std::string& text);
|
||||||
void startChatConversation(const std::string& peerZaddr, const std::string& text);
|
void startChatConversation(const std::string& peerZaddr, const std::string& text);
|
||||||
|
// Send a contact request into an existing conversation (used to retry a failed request in place).
|
||||||
|
void sendContactRequestForCid(const std::string& cid, const std::string& peerZaddr,
|
||||||
|
const std::string& text);
|
||||||
// Debug/sweep convenience: give the Chat tab a demo identity + a few sample conversations
|
// Debug/sweep convenience: give the Chat tab a demo identity + a few sample conversations
|
||||||
// (in-memory only, not persisted) so the screenshot sweep captures the populated UI. No-op when
|
// (in-memory only, not persisted) so the screenshot sweep captures the populated UI. No-op when
|
||||||
// the chat feature is off.
|
// the chat feature is off.
|
||||||
@@ -198,10 +250,16 @@ public:
|
|||||||
data::AddressBook& addressBook() { return address_book_; }
|
data::AddressBook& addressBook() { return address_book_; }
|
||||||
const data::AddressBook& addressBook() const { return address_book_; }
|
const data::AddressBook& addressBook() const { return address_book_; }
|
||||||
|
|
||||||
// Hash of the active wallet's identity (derived from its address list), used to scope
|
// Hash of the active wallet's identity (derived from its address list). This is the tx-history
|
||||||
// per-wallet data (e.g. address-book contacts). Empty until addresses are known (pre-connect).
|
// cache key — it changes when the address set changes, so DON'T scope persistent user data on it.
|
||||||
std::string activeWalletIdentityHash() const;
|
std::string activeWalletIdentityHash() const;
|
||||||
|
|
||||||
|
// Stable per-wallet id ("w:"+hex) for scoping persistent per-wallet data (address-book contacts).
|
||||||
|
// Generated once and persisted in the wallet index (keyed by wallet file), never recomputed from
|
||||||
|
// the mutable address set — so creating addresses / locking / disconnecting never changes it.
|
||||||
|
// Empty only when there is no active wallet file. Establishes + persists the id on first call.
|
||||||
|
std::string activeWalletScopeId();
|
||||||
|
|
||||||
data::WalletIndex& walletIndex() { return wallet_index_; }
|
data::WalletIndex& walletIndex() { return wallet_index_; }
|
||||||
const data::WalletIndex& walletIndex() const { return wallet_index_; }
|
const data::WalletIndex& walletIndex() const { return wallet_index_; }
|
||||||
|
|
||||||
@@ -336,6 +394,10 @@ public:
|
|||||||
|
|
||||||
// Force refresh
|
// Force refresh
|
||||||
void refreshNow();
|
void refreshNow();
|
||||||
|
// Called on window restore: drop the daemon-output backlog that accumulated while minimized (the
|
||||||
|
// per-frame update loop was paused), so a background witness rebuild that started+finished during
|
||||||
|
// the minimize isn't parsed in one batch and mistaken for a completed rescan (spurious toast).
|
||||||
|
void skipDaemonOutputBacklog();
|
||||||
void refreshMiningInfo();
|
void refreshMiningInfo();
|
||||||
void refreshPeerInfo();
|
void refreshPeerInfo();
|
||||||
void refreshMarketData();
|
void refreshMarketData();
|
||||||
@@ -373,6 +435,9 @@ public:
|
|||||||
// each under every skin. Output: <config>/screenshots-full/<surface>/<skin>.png + an index.
|
// each under every skin. Output: <config>/screenshots-full/<surface>/<skin>.png + an index.
|
||||||
void startFullUiSweep();
|
void startFullUiSweep();
|
||||||
std::string screenshotFullDir() const;
|
std::string screenshotFullDir() const;
|
||||||
|
// Debug option: restrict either sweep to just the currently-active theme instead of cycling all.
|
||||||
|
bool sweepCurrentThemeOnly() const { return sweep_current_theme_only_; }
|
||||||
|
void setSweepCurrentThemeOnly(bool v) { sweep_current_theme_only_ = v; }
|
||||||
bool isScreenshotSweeping() const { return screenshot_sweep_active_; }
|
bool isScreenshotSweeping() const { return screenshot_sweep_active_; }
|
||||||
bool wantsScreenshotThisFrame() const { return sweep_capture_this_frame_; }
|
bool wantsScreenshotThisFrame() const { return sweep_capture_this_frame_; }
|
||||||
const std::string& screenshotSweepPath() const { return sweep_current_path_; }
|
const std::string& screenshotSweepPath() const { return sweep_current_path_; }
|
||||||
@@ -389,7 +454,16 @@ public:
|
|||||||
// True when the current full-node wallet is a legacy, pre-seed-phrase wallet (no BIP39 mnemonic)
|
// True when the current full-node wallet is a legacy, pre-seed-phrase wallet (no BIP39 mnemonic)
|
||||||
// that a capable daemon could migrate — the Migrate-to-seed button glows to nudge the user.
|
// that a capable daemon could migrate — the Migrate-to-seed button glows to nudge the user.
|
||||||
bool isPreSeedWallet() const { return wallet_seed_status_ == WalletSeedStatus::NoMnemonic; }
|
bool isPreSeedWallet() const { return wallet_seed_status_ == WalletSeedStatus::NoMnemonic; }
|
||||||
|
// Authoritative BIP39-mnemonic status of the ACTIVE wallet, decided at runtime by z_exportmnemonic
|
||||||
|
// (not the offline file probe, which can't tell an HD-but-no-mnemonic wallet from a seed-phrase one).
|
||||||
|
// 0 = unknown/undecidable, 1 = has a seed phrase, 2 = legacy (no mnemonic).
|
||||||
|
int activeWalletSeedBadge() const {
|
||||||
|
if (wallet_seed_status_ == WalletSeedStatus::HasMnemonic) return 1;
|
||||||
|
if (wallet_seed_status_ == WalletSeedStatus::NoMnemonic) return 2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
void showAboutDialog() { show_about_ = true; }
|
void showAboutDialog() { show_about_ = true; }
|
||||||
|
void showFaqDialog() { show_faq_ = true; }
|
||||||
|
|
||||||
// Legacy tab compat — maps int to NavPage
|
// Legacy tab compat — maps int to NavPage
|
||||||
void setCurrentTab(int tab);
|
void setCurrentTab(int tab);
|
||||||
@@ -407,6 +481,12 @@ public:
|
|||||||
// Embedded daemon control
|
// Embedded daemon control
|
||||||
bool startEmbeddedDaemon();
|
bool startEmbeddedDaemon();
|
||||||
void stopEmbeddedDaemon();
|
void stopEmbeddedDaemon();
|
||||||
|
// Stop the node specifically for a wallet switch, which MUST free the RPC port to relaunch on
|
||||||
|
// -wallet=<name>. Unlike stopEmbeddedDaemon() (whose DisconnectOnly policy leaves an adopted/external
|
||||||
|
// daemon running), this sends a graceful RPC "stop" — using our own connection creds, so only our
|
||||||
|
// daemon obeys it — even to an adopted daemon, then waits (bounded) for the port to actually release.
|
||||||
|
// Returns true once the RPC port is free (or we're shutting down).
|
||||||
|
bool stopDaemonForWalletSwitch();
|
||||||
bool isEmbeddedDaemonRunning() const;
|
bool isEmbeddedDaemonRunning() const;
|
||||||
bool isUsingEmbeddedDaemon() const { return supportsEmbeddedDaemon() && use_embedded_daemon_; }
|
bool isUsingEmbeddedDaemon() const { return supportsEmbeddedDaemon() && use_embedded_daemon_; }
|
||||||
void setUseEmbeddedDaemon(bool use) { use_embedded_daemon_ = use && supportsEmbeddedDaemon(); }
|
void setUseEmbeddedDaemon(bool use) { use_embedded_daemon_ = use && supportsEmbeddedDaemon(); }
|
||||||
@@ -449,6 +529,10 @@ public:
|
|||||||
// Coin logo texture accessor (DragonX currency icon for balance tab)
|
// Coin logo texture accessor (DragonX currency icon for balance tab)
|
||||||
ImTextureID getCoinLogoTexture() const { return coin_logo_tex_; }
|
ImTextureID getCoinLogoTexture() const { return coin_logo_tex_; }
|
||||||
|
|
||||||
|
// DragonX custom chat emoji (the ":drgx:" shortcode) — the mark recolored to the theme accent (like
|
||||||
|
// the logo), re-rasterized on theme change. Used by the emoji picker tile + inline in chat bubbles.
|
||||||
|
ImTextureID getDrgxEmojiTexture() const { return drgx_emoji_tex_; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reload theme images (background gradient + logo) from new paths
|
* @brief Reload theme images (background gradient + logo) from new paths
|
||||||
* @param bgPath Path to background image override (empty = use default)
|
* @param bgPath Path to background image override (empty = use default)
|
||||||
@@ -456,6 +540,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
void reloadThemeImages(const std::string& bgPath, const std::string& logoPath);
|
void reloadThemeImages(const std::string& bgPath, const std::string& logoPath);
|
||||||
|
|
||||||
|
// Load / recolor-per-theme the DragonX header logo (SVG rasterized to the theme accent). Called at
|
||||||
|
// the top of render() so the wizard, lock screen, and main header all show it.
|
||||||
|
void ensureLogoTexture();
|
||||||
|
|
||||||
// Wizard / first-run
|
// Wizard / first-run
|
||||||
WizardPhase getWizardPhase() const { return wizard_phase_; }
|
WizardPhase getWizardPhase() const { return wizard_phase_; }
|
||||||
bool isFirstRun() const;
|
bool isFirstRun() const;
|
||||||
@@ -474,7 +562,11 @@ public:
|
|||||||
// Switch the active wallet: persist the new -wallet=<name>, stop the node, restart on it
|
// Switch the active wallet: persist the new -wallet=<name>, stop the node, restart on it
|
||||||
// (rescan only if it was never synced in this datadir). Per-wallet data follows automatically
|
// (rescan only if it was never synced in this datadir). Per-wallet data follows automatically
|
||||||
// via the identity-scoped caches (P1). No-op if that wallet is already active.
|
// via the identity-scoped caches (P1). No-op if that wallet is already active.
|
||||||
void switchToWallet(const std::string& walletFile);
|
// stopDaemonConfirmed: skip the "stop the running node?" confirmation (set true when re-entered from
|
||||||
|
// that dialog). salvage: start the target node with -salvagewallet (repair a corrupt wallet).
|
||||||
|
void switchToWallet(const std::string& walletFile, bool stopDaemonConfirmed = false, bool salvage = false);
|
||||||
|
// Main-thread continuation: if a wallet switch's daemon failed to start, revert active_wallet_file.
|
||||||
|
void processWalletSwitchRevert();
|
||||||
|
|
||||||
// Wallet encryption helpers
|
// Wallet encryption helpers
|
||||||
void encryptWalletWithPassphrase(const std::string& passphrase);
|
void encryptWalletWithPassphrase(const std::string& passphrase);
|
||||||
@@ -531,6 +623,9 @@ public:
|
|||||||
// plaintext. Call pumpSecretClipboardClear() each frame to action the clear.
|
// plaintext. Call pumpSecretClipboardClear() each frame to action the clear.
|
||||||
void copySecretToClipboard(const std::string& secret);
|
void copySecretToClipboard(const std::string& secret);
|
||||||
void pumpSecretClipboardClear();
|
void pumpSecretClipboardClear();
|
||||||
|
// Immediately clear the clipboard if it still holds the armed secret (ignores the 45s timer).
|
||||||
|
// Called on app shutdown so a copied key/seed does not outlive the process in the OS clipboard.
|
||||||
|
void clearSecretClipboardIfArmed();
|
||||||
bool isTransactionRefreshInProgress() const {
|
bool isTransactionRefreshInProgress() const {
|
||||||
return network_refresh_.jobInProgress(services::NetworkRefreshService::Job::Transactions);
|
return network_refresh_.jobInProgress(services::NetworkRefreshService::Job::Transactions);
|
||||||
}
|
}
|
||||||
@@ -572,10 +667,13 @@ private:
|
|||||||
// the recipient `to`/`amount`/`memo`/`fee` used to record the optimistic pending-send row).
|
// the recipient `to`/`amount`/`memo`/`fee` used to record the optimistic pending-send row).
|
||||||
// When markFeeGapRetry is set, the returned opid is recorded in send_feegap_retried_opids_ so a
|
// When markFeeGapRetry is set, the returned opid is recorded in send_feegap_retried_opids_ so a
|
||||||
// retry of a retry is reported as a real error.
|
// retry of a retry is reported as a real error.
|
||||||
|
// background=true (autonomous chat sends / note-buffer splits): keep the single-flight + opid
|
||||||
|
// accounting but DON'T raise the global "transaction in progress" UI (status is on the chat message).
|
||||||
void submitZSendMany(const std::string& from, const std::string& to, double amount, double fee,
|
void submitZSendMany(const std::string& from, const std::string& to, double amount, double fee,
|
||||||
const std::string& memo, const nlohmann::json& recipients,
|
const std::string& memo, const nlohmann::json& recipients,
|
||||||
const char* traceLabel, bool markFeeGapRetry,
|
const char* traceLabel, bool markFeeGapRetry,
|
||||||
std::function<void(bool, const std::string&)> callback);
|
std::function<void(bool, const std::string&)> callback,
|
||||||
|
bool background = false);
|
||||||
void markPendingSendTransactionSucceeded(const std::string& opid,
|
void markPendingSendTransactionSucceeded(const std::string& opid,
|
||||||
const std::string& txid);
|
const std::string& txid);
|
||||||
void removePendingSendTransactions(const std::vector<std::string>& opids,
|
void removePendingSendTransactions(const std::vector<std::string>& opids,
|
||||||
@@ -653,29 +751,160 @@ private:
|
|||||||
chat::ChatDatabase chat_db_; // persistent backing (seed-derived encryption at rest)
|
chat::ChatDatabase chat_db_; // persistent backing (seed-derived encryption at rest)
|
||||||
bool chat_identity_provisioned_ = false; // identity set on the service this session
|
bool chat_identity_provisioned_ = false; // identity set on the service this session
|
||||||
bool chat_identity_fetch_in_flight_ = false; // a z_exportmnemonic worker job is pending
|
bool chat_identity_fetch_in_flight_ = false; // a z_exportmnemonic worker job is pending
|
||||||
|
// Bumped by resetChatSession() on every wallet change; an in-flight identity fetch captures the
|
||||||
|
// value at post time and its completion callback discards its (previous-wallet) secret if the id
|
||||||
|
// no longer matches — so wallet A's seed can't be provisioned under wallet B via a stale job.
|
||||||
|
int chat_session_generation_ = 0;
|
||||||
bool chat_identity_unavailable_ = false; // provisioning failed definitively (e.g. non-mnemonic wallet)
|
bool chat_identity_unavailable_ = false; // provisioning failed definitively (e.g. non-mnemonic wallet)
|
||||||
|
// Per-conversation "last seen" watermark (message timestamp) for unread tracking (Q1). Updated when a
|
||||||
|
// thread is viewed (markChatConversationSeen); wiped in resetChatSession so unread doesn't leak across
|
||||||
|
// wallets. In-memory only (resets on app restart).
|
||||||
|
std::map<std::string, std::int64_t> chat_seen_watermark_;
|
||||||
|
|
||||||
|
// ── Per-frame render caches (avoid O(N) recompute every frame; see the respective call sites) ──
|
||||||
|
// Chat nav-badge unread count — recomputed only when the store revision changes or after a short
|
||||||
|
// interval (mute/hide/seen changes don't bump the store). See App::chatUnreadCount().
|
||||||
|
mutable std::uint64_t chat_unread_rev_ = ~0ull; // ~0 forces the first compute
|
||||||
|
mutable int chat_unread_cached_ = 0;
|
||||||
|
mutable double chat_unread_computed_at_ = 0.0;
|
||||||
|
// Sidebar unconfirmed-tx badge — recomputed only when the tx list changes (keyed on last_tx_update +
|
||||||
|
// size), not every frame. See App::render().
|
||||||
|
std::int64_t sb_unconf_key_ts_ = -1;
|
||||||
|
std::size_t sb_unconf_key_n_ = 0;
|
||||||
|
int sb_unconf_count_ = 0;
|
||||||
|
// Daemon-memory probe is expensive (/proc scan on Linux, popen on macOS); throttle it to ~1.5s so the
|
||||||
|
// Mining tab's per-frame read doesn't hammer the OS. See App::getDaemonMemoryUsageMB().
|
||||||
|
mutable double daemon_mem_cached_mb_ = 0.0;
|
||||||
|
mutable double daemon_mem_probe_at_ = 0.0;
|
||||||
|
|
||||||
|
// ── Chat note buffer (BOTH variants) ────────────────────────────────────────────────────────
|
||||||
|
// Each chat message is a shielded tx that spends a note; its change needs a few confirmations before
|
||||||
|
// it's spendable again (lite: backend ANCHOR_OFFSET+1 = 5; full node: z_sendmany minconf = 1), so
|
||||||
|
// rapid sends run out of verified funds. We keep a buffer of ~kChatBufferTarget small self-notes so a
|
||||||
|
// burst of messages each spends a separate verified note, refilled from change + background self-
|
||||||
|
// splits. Chat sends, self-splits and user sends share the wallet's single send channel; inflight_op_
|
||||||
|
// + (lite) lite_send_callback_ / (full node) send_submissions_in_flight_+pending_opids_ serialize them
|
||||||
|
// so exactly one send is ever outstanding. Implemented in app_network.cpp; pumped from update().
|
||||||
|
enum class LiteOpKind { None, ChatSend, ContactRequest, Split, UserSend };
|
||||||
|
struct LiteInflightOp {
|
||||||
|
LiteOpKind kind = LiteOpKind::None;
|
||||||
|
std::string echoLocalId; // ChatSend/ContactRequest: the echo to resolve when it completes
|
||||||
|
int sessionGen = 0; // chat_session_generation_ snapshot at submit (stale-guard)
|
||||||
|
double submittedAt = 0.0;
|
||||||
|
};
|
||||||
|
struct QueuedChatOp {
|
||||||
|
LiteOpKind kind = LiteOpKind::ChatSend;
|
||||||
|
chat::OutgoingChatMemos memos; // kept so a transient-funds retry re-broadcasts, never recomposes
|
||||||
|
std::string echoLocalId;
|
||||||
|
int sessionGen = 0;
|
||||||
|
int retries = 0;
|
||||||
|
};
|
||||||
|
LiteInflightOp inflight_op_; // the single chat/split op currently on the send channel
|
||||||
|
std::deque<QueuedChatOp> chat_send_queue_; // chat/contact sends awaiting a free channel + verified note
|
||||||
|
// Note-availability estimate between refreshes/scans: reset from a fresh count, decremented on each chat
|
||||||
|
// submit (the count lags a spend by a cycle, but the wallet still picks a fresh note per send). Zeroed on
|
||||||
|
// a transient-funds failure so we stop draining until the next refresh/scan restores the truth.
|
||||||
|
int chat_verified_note_budget_ = 0;
|
||||||
|
int chat_pipeline_note_count_ = 0; // verified + maturing self-notes (drives shouldSplit)
|
||||||
|
std::uint64_t chat_verified_shielded_zat_ = 0; // verified shielded balance (split affordability)
|
||||||
|
bool chat_note_model_seen_ = false; // saw a refresh/scan carrying per-note visibility
|
||||||
|
// Single-split-in-flight guard: a self-split's OUTPUT notes are invisible until mined (~1 block), far
|
||||||
|
// longer than any wall-clock cooldown — so we permit only ONE outstanding split and clear the flag when
|
||||||
|
// the pipeline recovers (outputs mined) or a watchdog expires (a split that never mines mustn't wedge
|
||||||
|
// refill forever). Prevents runaway splitting that would drain balance into fees.
|
||||||
|
bool chat_split_outstanding_ = false;
|
||||||
|
double chat_split_submitted_at_ = 0.0; // ImGui time the outstanding split was submitted (watchdog)
|
||||||
|
// Full-node only: a coordinator-owned z_listunspent worker scan feeds the per-note counts (the shared
|
||||||
|
// balance poll discards per-note data). Mirrors chat_fast_scan_in_flight_.
|
||||||
|
bool chat_note_scan_in_flight_ = false;
|
||||||
|
double chat_note_scan_last_ = 0.0; // ImGui time of the last note scan (rate limit)
|
||||||
|
double chat_note_scan_ms_ = 0.0; // measured cost of the last note scan (adaptive back-off)
|
||||||
|
// Most-recent chain tip, cached across refreshes: a lite refresh model that carries spendableOutputs
|
||||||
|
// may NOT carry sync status that same cycle (tolerated partial refresh), so verifiedSelfNoteCount reads
|
||||||
|
// this cache rather than requiring the current model to have both — else the budget flickers to 0.
|
||||||
|
std::int64_t chat_last_chain_height_ = 0;
|
||||||
|
int chat_fast_scan_last_seen_ = -1; // dedup: last memo-note count logged by the 0-conf scan
|
||||||
|
|
||||||
|
// Coordinator helpers (both variants unless noted; see app_network.cpp).
|
||||||
|
void refreshChatNoteBudget(const wallet::LiteWalletAppRefreshModel& model); // lite: recompute caches on a fresh model
|
||||||
|
void refreshChatNoteBudgetNode(); // full node: rate-limited z_listunspent worker scan
|
||||||
|
// Feeds the SAME chat send-budget from an already-collected z_listunspent (the address refresh),
|
||||||
|
// so the dedicated scan above is skipped while the address refresh is active (dedup — see #3).
|
||||||
|
void updateChatNoteBudgetFromUnspent(const std::vector<services::NetworkRefreshService::UnspentNoteLite>& unspentNotes);
|
||||||
|
void pumpChatNoteBuffer(); // per-frame: drain the queue / build the buffer
|
||||||
|
int verifiedSelfNoteCount(const wallet::LiteWalletAppRefreshModel& model); // lite
|
||||||
|
int pipelineSelfNoteCount(const wallet::LiteWalletAppRefreshModel& model); // lite
|
||||||
|
bool shouldSplitChatBuffer();
|
||||||
|
bool broadcastSelfSplitLite(int noteCount); // lite: self-send minting noteCount reply-address notes
|
||||||
|
bool broadcastSelfSplitNode(int noteCount); // full node: z_sendmany self-send minting noteCount notes
|
||||||
|
void enqueueChatSend(LiteOpKind kind, const chat::OutgoingChatMemos& memos, const std::string& echoLocalId);
|
||||||
|
void onChatBroadcastResult(const LiteInflightOp& op, bool ok, const std::string& error);
|
||||||
|
static bool isTransientVerifiedFundsError(const std::string& error);
|
||||||
|
int chatConfsRequired() const; // verified-note confs threshold: 5 (lite) / 1 (full node)
|
||||||
|
public:
|
||||||
|
// Status-bar summary of the chat note buffer (empty when not applicable). Shown while the Chat tab is
|
||||||
|
// active so the buffer's state (ready / building / sending) is visible.
|
||||||
|
std::string chatBufferStatusText();
|
||||||
|
private:
|
||||||
|
public:
|
||||||
|
// Total unread incoming chat messages across all conversations (for the sidebar badge). 0 when the
|
||||||
|
// feature is off / no identity.
|
||||||
|
int chatUnreadCount() const;
|
||||||
|
// Mark a conversation read up to latestTs (called by the Chat tab while a thread is displayed).
|
||||||
|
void markChatConversationSeen(const std::string& cid, std::int64_t latestTs);
|
||||||
|
// Drop the seen-watermark for a conversation (used on revive-delete so a re-imported message — even one
|
||||||
|
// whose stamped time predates the deleted thread's last message — still badges as unread).
|
||||||
|
void forgetChatConversationSeen(const std::string& cid);
|
||||||
|
private:
|
||||||
// Provision the chat identity once the wallet seed is reachable+unlocked (per-tick, both
|
// Provision the chat identity once the wallet seed is reachable+unlocked (per-tick, both
|
||||||
// variants); derives via deriveChatIdentityFromSecret and wipes the secret. No-op when the
|
// variants); derives via deriveChatIdentityFromSecret and wipes the secret. No-op when the
|
||||||
// feature is off, already provisioned, in flight, or unavailable.
|
// feature is off, already provisioned, in flight, or unavailable.
|
||||||
void maybeProvisionChatIdentity();
|
void maybeProvisionChatIdentity();
|
||||||
|
// Drop the in-memory chat identity + decrypted message store, lock the chat DB, and re-arm
|
||||||
|
// provisioning. MUST be called whenever the loaded wallet changes (switch / seed-migration adopt)
|
||||||
|
// so wallet A's private chat can't surface — or be signed with A's keys — under wallet B.
|
||||||
|
void resetChatSession();
|
||||||
// One-time nudge: on a full-node wallet that has a mnemonic, remind the user (once per
|
// One-time nudge: on a full-node wallet that has a mnemonic, remind the user (once per
|
||||||
// install) to back up their seed phrase. Cheap early-outs keep it idle until it can act.
|
// install) to back up their seed phrase. Cheap early-outs keep it idle until it can act.
|
||||||
void maybeRemindSeedBackup();
|
void maybeRemindSeedBackup();
|
||||||
|
void maybeWarnEmptyWalletWithFundedSiblings(); // full-node: empty active wallet + a funded sibling → warn once
|
||||||
|
void maybeWarnLargeWallet(); // full-node: wallet.dat past bloat threshold → one-time toast + clickable alert
|
||||||
|
void scanFundedSiblingsAsync(); // off-UI-thread probe of sibling wallet files
|
||||||
|
static void scrubAndRemoveExport(const std::string& path); // zero + delete a plaintext key export (H-02)
|
||||||
|
void sweepStaleDecryptExports(); // startup net: purge stale obsidiandecryptexport* files (H-02)
|
||||||
|
|
||||||
// Seed-wallet migration (Phase 1: create a new mnemonic wallet in isolation, no funds moved).
|
// Seed-wallet migration (Phase 1: create a new mnemonic wallet in isolation, no funds moved).
|
||||||
void beginCreateSeedWallet(); // starts the isolated create on a background thread
|
void beginCreateSeedWallet(); // starts the isolated create on a background thread
|
||||||
void pumpSeedMigration(); // main thread: pick up background progress/result each frame
|
void pumpSeedMigration(); // main thread: pick up background progress/result each frame
|
||||||
// Phase 2: sweep all legacy funds into the new wallet, then adopt it as the primary wallet.
|
// Phase 2: sweep all legacy funds into the new wallet, then adopt it as the primary wallet.
|
||||||
void refreshSeedMigrationBalance(); // query the legacy total (shown on the Sweep step)
|
void refreshSeedMigrationBalance(); // query the legacy total (shown on the Sweep step)
|
||||||
|
// W3-3: the terminal callback for the sweep opid, shared by the initial submit and a resume
|
||||||
|
// re-track. `resumed` selects the failure behaviour: a fresh sweep that fails -> Error; a resumed
|
||||||
|
// opid the daemon no longer knows (stale) -> back to the dismissable Sweep gate (re-check balance).
|
||||||
|
std::function<void(bool, const std::string&)> makeSweepCompletionCallback(bool resumed);
|
||||||
void beginSweepToSeedWallet(); // z_mergetoaddress ["ANY_TADDR","ANY_ZADDR"] -> dest
|
void beginSweepToSeedWallet(); // z_mergetoaddress ["ANY_TADDR","ANY_ZADDR"] -> dest
|
||||||
void pollSweepStatus(); // Confirming step: poll sweep confirmations + legacy balance
|
void pollSweepStatus(); // Confirming step: poll sweep confirmations + legacy balance
|
||||||
void beginAdoptSeedWallet(); // stop daemon -> swap wallet.dat -> restart with -rescan
|
void beginAdoptSeedWallet(); // stop daemon -> swap wallet.dat -> restart with -rescan
|
||||||
void provisionChatIdentityFromSecret(std::string secret);
|
void provisionChatIdentityFromSecret(std::string secret);
|
||||||
std::string chatReplyZaddr(); // a stable (persisted) wallet z-addr for chat
|
std::string chatReplyZaddr(); // a stable (persisted) wallet z-addr — chat IDENTITY (reply-to)
|
||||||
|
// A spendable z-address that can actually PAY the fee (balance >= fee), preferring the identity
|
||||||
|
// reply address. The reply-to in the memo stays the identity address, so paying from a different
|
||||||
|
// funded note is transport-transparent. Empty if no z-address can cover the fee.
|
||||||
|
std::string chatPayFromZaddr(double fee) const;
|
||||||
std::string generateChatLocalId(const char* prefix, int numBytes) const; // unique echo id / cid
|
std::string generateChatLocalId(const char* prefix, int numBytes) const; // unique echo id / cid
|
||||||
bool broadcastChatMemos(const chat::OutgoingChatMemos& memos); // returns true if submitted
|
// Broadcast the memos and, when the async op resolves, flip the echo (echoLocalId) to Sent/Failed.
|
||||||
|
bool broadcastChatMemos(const chat::OutgoingChatMemos& memos, const std::string& echoLocalId); // true if submitted
|
||||||
bool broadcastChatMemosLite(const chat::OutgoingChatMemos& memos); // lite two-recipient send
|
bool broadcastChatMemosLite(const chat::OutgoingChatMemos& memos); // lite two-recipient send
|
||||||
void ingestLiteChatMemos(const wallet::LiteWalletAppRefreshModel& model); // lite chat receive harvest
|
void ingestLiteChatMemos(const wallet::LiteWalletAppRefreshModel& model); // lite chat receive harvest
|
||||||
|
// Full-node 0-conf fast path: re-scan just the chat reply address at minconf=0 every refresh cycle
|
||||||
|
// so incoming messages surface at mempool speed (before a block). Hidden conversations are skipped
|
||||||
|
// (they still un-hide via the normal confirmed harvest). Self-gated; no-op without a chat identity.
|
||||||
|
void fastScanChatMemos();
|
||||||
|
bool chat_fast_scan_in_flight_ = false; // guard against overlapping fast-scan RPCs
|
||||||
|
float chat_fast_scan_accum_ = 0.0f; // seconds since the last fast-scan (dedicated ~2.5s poll)
|
||||||
|
double chat_fast_scan_last_ = 0.0; // ImGui time of the last 0-conf fast scan (adaptive back-off)
|
||||||
|
double chat_fast_scan_ms_ = 0.0; // measured cost of the last fast scan (z_listreceivedbyaddress)
|
||||||
|
bool font_rebuild_requested_ = false; // set by requestFontRebuild(); consumed in preFrame()
|
||||||
// Lite first-run welcome prompt: dismissed for the session once the user picks an action.
|
// Lite first-run welcome prompt: dismissed for the session once the user picks an action.
|
||||||
bool lite_firstrun_dismissed_ = false;
|
bool lite_firstrun_dismissed_ = false;
|
||||||
// Lite send-time unlock: set to show the unlock modal when a spend is attempted while locked.
|
// Lite send-time unlock: set to show the unlock modal when a spend is attempted while locked.
|
||||||
@@ -684,6 +913,16 @@ private:
|
|||||||
bool lite_startup_lock_checked_ = false;
|
bool lite_startup_lock_checked_ = false;
|
||||||
std::unique_ptr<daemon::DaemonController> daemon_controller_;
|
std::unique_ptr<daemon::DaemonController> daemon_controller_;
|
||||||
std::unique_ptr<daemon::XmrigManager> xmrig_manager_;
|
std::unique_ptr<daemon::XmrigManager> xmrig_manager_;
|
||||||
|
// Serialized async mining-control queue: xmrig start/stop (SIGTERM->SIGKILL->join, up to ~3s) run on
|
||||||
|
// this dedicated FIFO thread instead of the render thread, so the UI never blocks and stop/start
|
||||||
|
// ordering is preserved across the ~13 call sites. (M-03/L-06/L-08/L-09/L-13)
|
||||||
|
std::thread mining_ctl_thread_;
|
||||||
|
std::mutex mining_ctl_mutex_;
|
||||||
|
std::condition_variable mining_ctl_cv_;
|
||||||
|
std::deque<std::function<void()>> mining_ctl_queue_;
|
||||||
|
bool mining_ctl_stop_ = false;
|
||||||
|
void postMiningControl(std::function<void()> job); // enqueue a blocking xmrig op onto the FIFO thread
|
||||||
|
void stopMiningControlThread(); // signal + join the control thread (shutdown)
|
||||||
// Auto-balance runtime state (pool mining, full-node only). The service fetches
|
// Auto-balance runtime state (pool mining, full-node only). The service fetches
|
||||||
// pool hashrates off-thread; the RNG drives the weighted-random pick.
|
// pool hashrates off-thread; the RNG drives the weighted-random pick.
|
||||||
util::PoolStatsService pool_stats_service_;
|
util::PoolStatsService pool_stats_service_;
|
||||||
@@ -716,8 +955,13 @@ private:
|
|||||||
std::atomic<bool> shutting_down_{false};
|
std::atomic<bool> shutting_down_{false};
|
||||||
std::atomic<bool> shutdown_complete_{false};
|
std::atomic<bool> shutdown_complete_{false};
|
||||||
bool address_list_dirty_ = false; // P8: dedup rebuildAddressList
|
bool address_list_dirty_ = false; // P8: dedup rebuildAddressList
|
||||||
std::string shutdown_status_;
|
GuardedStatus shutdown_status_; // thread-safe: written by the shutdown thread, read by the UI (M-05)
|
||||||
std::thread shutdown_thread_;
|
std::thread shutdown_thread_;
|
||||||
|
// Confirm-before-stopping-daemon-mid-witness-rebuild guard (see beginShutdown / renderDaemonStopConfirm)
|
||||||
|
bool pending_shutdown_confirm_ = false; // a quit is deferred, waiting to open the confirm modal
|
||||||
|
bool daemon_stop_confirm_open_ = false; // the confirm modal is currently showing
|
||||||
|
bool shutdown_confirmed_ = false; // user chose to proceed — bypass the guard on re-entry
|
||||||
|
bool shutdown_keep_daemon_override_ = false; // user chose "keep node running" for this shutdown only
|
||||||
float shutdown_timer_ = 0.0f;
|
float shutdown_timer_ = 0.0f;
|
||||||
bool force_quit_confirm_ = false;
|
bool force_quit_confirm_ = false;
|
||||||
std::chrono::steady_clock::time_point shutdown_start_time_;
|
std::chrono::steady_clock::time_point shutdown_start_time_;
|
||||||
@@ -725,6 +969,80 @@ private:
|
|||||||
// Daemon restart (e.g. after changing debug log categories)
|
// Daemon restart (e.g. after changing debug log categories)
|
||||||
std::atomic<bool> daemon_restarting_{false};
|
std::atomic<bool> daemon_restarting_{false};
|
||||||
|
|
||||||
|
// Wallet-switch failure recovery: the switch worker sets wallet_switch_failed_ when the new
|
||||||
|
// wallet's daemon won't start/stay up; the main loop then reverts active_wallet_file to
|
||||||
|
// wallet_switch_prev_file_ (settings writes stay on the main thread) so a broken wallet isn't
|
||||||
|
// persisted across restarts. daemon_restarting_ stays set until the revert re-arms the reconnect.
|
||||||
|
std::atomic<bool> wallet_switch_failed_{false};
|
||||||
|
// Distinguishes the failure reason for the revert message: true when the switch failed because the
|
||||||
|
// running node wouldn't release the RPC port in time (not because the target wallet is bad).
|
||||||
|
std::atomic<bool> switch_stop_failed_{false};
|
||||||
|
// True from a switch until the new wallet's daemon actually connects (onConnected). If the daemon
|
||||||
|
// instead crash-wedges (a wallet that fails LATE in init, past the fast start grace), the connect
|
||||||
|
// loop flags a revert so a broken wallet still can't stick.
|
||||||
|
std::atomic<bool> wallet_switch_pending_confirm_{false};
|
||||||
|
std::string wallet_switch_prev_file_;
|
||||||
|
// Confirm-before-stop for a switch that would stop an ADOPTED (externally-running) node. switchToWallet
|
||||||
|
// sets these and defers to renderSwitchStopDaemonDialog; confirming re-calls switchToWallet(w, true).
|
||||||
|
bool show_switch_stop_daemon_confirm_ = false;
|
||||||
|
std::string pending_switch_wallet_file_;
|
||||||
|
// Block-database recovery: set when the embedded node aborts because its block DB is unreadable
|
||||||
|
// (a daemon-vs-chaindata format mismatch after an update, or a corrupt index). While set, the
|
||||||
|
// connect loop STOPS crash-restarting into the same abort and offers a one-click reindex instead.
|
||||||
|
bool block_db_reindex_available_ = false; // node needs its block DB rebuilt (gates restart loop)
|
||||||
|
bool show_block_db_reindex_confirm_ = false; // auto-shown offer dialog
|
||||||
|
// Wallet auto-recovery: the daemon moved wallet.dat to wallet.<ts>.bak and loaded a salvaged copy
|
||||||
|
// (BDB-verify failure — often a false positive from stale/cross-platform env state). We warn loudly
|
||||||
|
// so a possibly-incomplete salvaged wallet isn't mistaken for fund loss. Warned once per session.
|
||||||
|
bool wallet_auto_recovered_ = false; // a salvage happened this session
|
||||||
|
bool wallet_auto_recovered_warned_ = false; // guard: only surface it once per session
|
||||||
|
bool wallet_degraded_ = false; // v1.3.0+ opened the wallet in DEGRADED mode (no new HD keys)
|
||||||
|
bool wallet_degraded_warned_ = false; // guard: surface the degraded-mode notice once per session
|
||||||
|
bool show_wallet_recovered_dialog_ = false; // auto-shown warning dialog
|
||||||
|
// Complementary on-disk safety net for a salvage we DIDN'T witness this launch (happened on a prior
|
||||||
|
// run, or under an external daemon whose startup output we never captured): if the active wallet loads
|
||||||
|
// empty while a sibling wallet file in the datadir still holds keys, warn once so the user's funds
|
||||||
|
// (likely in a wallet.<ts>.bak) aren't mistaken for loss. See maybeWarnEmptyWalletWithFundedSiblings().
|
||||||
|
struct FundedSibling { std::string fileName; int transparentKeys = 0; int shieldedKeys = 0; };
|
||||||
|
bool show_empty_wallet_warning_ = false; // auto-shown warning modal
|
||||||
|
bool empty_wallet_warn_checked_ = false; // evaluated this wallet-open already (reset in onConnected)
|
||||||
|
bool empty_wallet_scan_in_flight_ = false; // a sibling scan is running (main-thread only)
|
||||||
|
bool empty_wallet_has_salvage_bak_ = false; // modal variant: a funded salvage .bak → offer Restore
|
||||||
|
std::vector<FundedSibling> empty_wallet_funded_siblings_; // scan result (main-thread only)
|
||||||
|
// The recovery dialog is the ONE authoritative surface: it stays open through the async rebuild/
|
||||||
|
// restore, driven Offer → Working → Done/Failed (pumpWalletRestore sets the outcome). Presentation
|
||||||
|
// only — the fund-safety file ops in rebuildWalletDatabase()/restoreOriginalWallet() are unchanged.
|
||||||
|
enum class RecoveryPhase { Offer, Working, Done, Failed };
|
||||||
|
RecoveryPhase recovery_phase_ = RecoveryPhase::Offer;
|
||||||
|
int recovery_outcome_sev_ = 0; // 0 ok / 1 warn / 2 error, set at Done/Failed
|
||||||
|
std::string recovery_outcome_msg_; // honest result string for the Done/Failed body
|
||||||
|
bool recovery_last_action_rebuild_ = false; // which handler ran (for "try the other option")
|
||||||
|
// After a successful repair the daemon restarts with a full rescan — minutes long, and it won't
|
||||||
|
// answer RPC yet. This makes the loading overlay show a calm "finishing your wallet repair" screen
|
||||||
|
// (instead of the generic "daemon stuck / RPC timeout / restart daemon" text) and suppresses the
|
||||||
|
// daemon-crash toast. Set on repair success; cleared on connect (onConnected).
|
||||||
|
bool post_recovery_rescan_ = false;
|
||||||
|
double post_recovery_rescan_since_ = 0.0; // stamped on first overlay frame (ImGui::GetTime)
|
||||||
|
// "Restore original wallet" background op: worker sets these under the mutex, pumpWalletRestore()
|
||||||
|
// (main thread) shows the result. 0 = success, 1 = warning, 2 = error.
|
||||||
|
std::mutex wallet_restore_mutex_;
|
||||||
|
bool wallet_restore_done_ = false;
|
||||||
|
int wallet_restore_severity_ = 0;
|
||||||
|
std::string wallet_restore_msg_;
|
||||||
|
// Live progress for the switch modal: it stays open from confirm through stop → wait-for-exit → start →
|
||||||
|
// reconnect and auto-closes when the new node connects (onConnected). Phase is worker-updated;
|
||||||
|
// dialog_open_ gates rendering — both atomic since onConnected/the worker may run off the main thread.
|
||||||
|
// error_ is written only on the main thread (processWalletSwitchRevert) and read by the (main-thread) UI.
|
||||||
|
enum class WalletSwitchPhase : int { None = 0, Stopping, Starting, Reconnecting, Failed };
|
||||||
|
std::atomic<int> wallet_switch_phase_{0};
|
||||||
|
std::atomic<bool> wallet_switch_dialog_open_{false};
|
||||||
|
std::string wallet_switch_error_;
|
||||||
|
double wallet_switch_started_time_ = 0.0; // ImGui::GetTime() captured on first progress frame (elapsed)
|
||||||
|
// Set when a failed switch's node output indicates the target wallet is CORRUPT — the Failed modal then
|
||||||
|
// offers a one-click "-salvagewallet" repair, retrying the switch to wallet_switch_target_file_.
|
||||||
|
std::atomic<bool> switch_wallet_corrupt_{false};
|
||||||
|
std::string wallet_switch_target_file_; // the wallet we were switching TO (for a salvage retry)
|
||||||
|
|
||||||
// Set by the deleteBlockchainData worker (item count); the main loop surfaces a completion toast
|
// Set by the deleteBlockchainData worker (item count); the main loop surfaces a completion toast
|
||||||
// and resets it to -1. Atomic because the worker thread writes it and the UI thread reads/clears it.
|
// and resets it to -1. Atomic because the worker thread writes it and the UI thread reads/clears it.
|
||||||
std::atomic<int> pending_delete_result_{-1};
|
std::atomic<int> pending_delete_result_{-1};
|
||||||
@@ -737,6 +1055,7 @@ private:
|
|||||||
bool show_demo_window_ = false;
|
bool show_demo_window_ = false;
|
||||||
bool show_settings_ = false;
|
bool show_settings_ = false;
|
||||||
bool show_about_ = false;
|
bool show_about_ = false;
|
||||||
|
bool show_faq_ = false;
|
||||||
bool show_import_key_ = false;
|
bool show_import_key_ = false;
|
||||||
bool show_export_key_ = false;
|
bool show_export_key_ = false;
|
||||||
bool show_backup_ = false;
|
bool show_backup_ = false;
|
||||||
@@ -750,6 +1069,7 @@ private:
|
|||||||
bool seed_backup_loading_ = false;
|
bool seed_backup_loading_ = false;
|
||||||
bool seed_backup_no_mnemonic_ = false;
|
bool seed_backup_no_mnemonic_ = false;
|
||||||
bool seed_backup_reminder_in_flight_ = false; // guards the one-time backup nudge probe
|
bool seed_backup_reminder_in_flight_ = false; // guards the one-time backup nudge probe
|
||||||
|
bool large_wallet_checked_ = false; // gate: stat wallet.dat for the bloat nudge once per launch
|
||||||
|
|
||||||
// Cached mnemonic status of the current wallet, driving the Migrate-to-seed button glow. Probed
|
// Cached mnemonic status of the current wallet, driving the Migrate-to-seed button glow. Probed
|
||||||
// once per connect (probeWalletSeedStatus, via exportSeedPhrase); NoMnemonic = a legacy wallet a
|
// once per connect (probeWalletSeedStatus, via exportSeedPhrase); NoMnemonic = a legacy wallet a
|
||||||
@@ -843,10 +1163,30 @@ private:
|
|||||||
bool daemon_start_error_shown_ = false;
|
bool daemon_start_error_shown_ = false;
|
||||||
int daemon_last_seen_crashes_ = 0; // surface each new embedded-daemon crash reason once
|
int daemon_last_seen_crashes_ = 0; // surface each new embedded-daemon crash reason once
|
||||||
bool refresh_policy_syncing_ = false; // whether the sync-throttle refresh profile is active
|
bool refresh_policy_syncing_ = false; // whether the sync-throttle refresh profile is active
|
||||||
|
// Sync-settle hysteresis + adaptive balance-poll throttle. Balance polling (z_gettotalbalance) is
|
||||||
|
// O(mapWallet) and holds the daemon's cs_main, which starves block connection on a large shielded
|
||||||
|
// wallet — so we keep the low-impact profile briefly after catching up, and back the balance poll
|
||||||
|
// off in proportion to its own measured cost. See effectivelySyncing() / balanceRefreshDue().
|
||||||
|
bool was_core_syncing_ = false; // previous Core-refresh sync state, to detect the caught-up edge
|
||||||
|
std::time_t sync_settle_until_ = 0; // hold the sync-throttle until this wall-clock time (0 = not settling)
|
||||||
|
double last_balance_scan_ms_ = 0.0; // measured cost of the last z_gettotalbalance scan
|
||||||
|
bool force_balance_refresh_ = false; // a wallet mutation forces the next balance poll through the throttle
|
||||||
|
// Same adaptive back-off applied to the other two O(mapWallet) scans that hold the daemon's cs_main:
|
||||||
|
// the address scan (z_listunspent) and the history scan (z_listreceivedbyaddress). Without this, a
|
||||||
|
// large shielded wallet re-scans them every tab cadence (~seconds each), saturating cs_main and
|
||||||
|
// starving block connection near the tip (where effectivelySyncing() reads false). See
|
||||||
|
// addressRefreshDue() / txRefreshDue(); only the routine periodic poll is throttled — explicit
|
||||||
|
// refreshes (tab switch, dirty set, in-flight send) call the refresh directly and bypass this.
|
||||||
|
double last_address_scan_ms_ = 0.0; // measured cost of the last address scan
|
||||||
|
double last_tx_scan_ms_ = 0.0; // measured cost of the last history scan
|
||||||
// Auto-clear for secrets copied to the clipboard. Only a hash of the copied secret is kept.
|
// Auto-clear for secrets copied to the clipboard. Only a hash of the copied secret is kept.
|
||||||
std::uint64_t clipboard_secret_hash_ = 0;
|
std::uint64_t clipboard_secret_hash_ = 0;
|
||||||
double clipboard_clear_deadline_ = 0.0;
|
double clipboard_clear_deadline_ = 0.0;
|
||||||
float loading_timer_ = 0.0f; // spinner animation for loading overlay
|
float loading_timer_ = 0.0f; // spinner animation for loading overlay
|
||||||
|
double connect_stall_since_ = 0.0; // ImGui::GetTime() when the daemon first went "reachable but not ready"; 0 = not stalling (see util/connect_stall.h)
|
||||||
|
bool encryption_incomplete_warned_ = false; // W2-2: once-per-session guard for the "encryption didn't complete" warning
|
||||||
|
bool lock_failure_warned_ = false; // W2-4: guard so a repeatedly-failing auto-lock warns once, not every retry
|
||||||
|
std::uint64_t alerts_seen_total_ = 0; // Notifications::totalPushed() at last alert-panel open; drives the bell's unread dot
|
||||||
|
|
||||||
// Current page (sidebar navigation)
|
// Current page (sidebar navigation)
|
||||||
ui::NavPage current_page_ = ui::NavPage::Overview;
|
ui::NavPage current_page_ = ui::NavPage::Overview;
|
||||||
@@ -856,6 +1196,7 @@ private:
|
|||||||
|
|
||||||
// Debug screenshot sweep state.
|
// Debug screenshot sweep state.
|
||||||
bool screenshot_sweep_active_ = false;
|
bool screenshot_sweep_active_ = false;
|
||||||
|
bool sweep_current_theme_only_ = false; // Debug Options: sweep only the active theme
|
||||||
bool sweep_capture_this_frame_ = false;
|
bool sweep_capture_this_frame_ = false;
|
||||||
int sweep_skin_idx_ = 0;
|
int sweep_skin_idx_ = 0;
|
||||||
int sweep_settle_frames_ = 0; // frames to let a new skin/surface settle before capture
|
int sweep_settle_frames_ = 0; // frames to let a new skin/surface settle before capture
|
||||||
@@ -915,6 +1256,9 @@ private:
|
|||||||
int logo_h_ = 0;
|
int logo_h_ = 0;
|
||||||
bool logo_loaded_ = false;
|
bool logo_loaded_ = false;
|
||||||
bool logo_is_dark_variant_ = true; // tracks which variant is currently loaded
|
bool logo_is_dark_variant_ = true; // tracks which variant is currently loaded
|
||||||
|
ImU32 logo_accent_ = 0; // theme accent the SVG logo was last rasterized with (re-render on change)
|
||||||
|
ImTextureID drgx_emoji_tex_ = 0; // ":drgx:" custom chat emoji (themed to the accent, like the logo)
|
||||||
|
int drgx_emoji_w_ = 0, drgx_emoji_h_ = 0;
|
||||||
|
|
||||||
// Coin logo texture (DragonX currency icon, separate from wallet branding)
|
// Coin logo texture (DragonX currency icon, separate from wallet branding)
|
||||||
ImTextureID coin_logo_tex_ = 0;
|
ImTextureID coin_logo_tex_ = 0;
|
||||||
@@ -946,6 +1290,16 @@ private:
|
|||||||
|
|
||||||
// Auto-shield guard (prevents concurrent auto-shield operations)
|
// Auto-shield guard (prevents concurrent auto-shield operations)
|
||||||
std::atomic<bool> auto_shield_pending_{false};
|
std::atomic<bool> auto_shield_pending_{false};
|
||||||
|
// v1.3.0+ daemons auto-shield coinbase themselves; probe z_autoshieldstatus once per connection and
|
||||||
|
// defer the wallet's own client-side auto-shield when the daemon is doing it (otherwise both race for
|
||||||
|
// the same coinbase UTXOs and split funds across different z-addresses). Fail-closed: a pre-1.3.0
|
||||||
|
// daemon lacks the RPC → active stays false → the wallet keeps shielding client-side (no regression).
|
||||||
|
bool daemon_autoshield_probed_ = false;
|
||||||
|
bool daemon_autoshield_active_ = false;
|
||||||
|
std::atomic<bool> daemon_autoshield_probe_inflight_{false};
|
||||||
|
std::string daemon_autoshield_address_; // z_autoshieldstatus fields (O1); empty on old daemons
|
||||||
|
std::string daemon_autoshield_disabled_reason_; // daemon's reason auto-shield is off (e.g. seed not recoverable)
|
||||||
|
bool daemon_autoshield_seed_recoverable_ = false;
|
||||||
|
|
||||||
// P4: Incremental transaction cache
|
// P4: Incremental transaction cache
|
||||||
int last_tx_block_height_ = -1; // block height at last full tx fetch
|
int last_tx_block_height_ = -1; // block height at last full tx fetch
|
||||||
@@ -984,6 +1338,11 @@ private:
|
|||||||
// the per-second mining/rescan-status pollers are suppressed (the daemon holds cs_main for
|
// the per-second mining/rescan-status pollers are suppressed (the daemon holds cs_main for
|
||||||
// the whole scan and would block them); completion is signalled by the rescan RPC callback.
|
// the whole scan and would block them); completion is signalled by the rescan RPC callback.
|
||||||
bool runtime_rescan_active_ = false;
|
bool runtime_rescan_active_ = false;
|
||||||
|
// True only for a rescan the WALLET/USER initiated (the Rescan button, a -rescan/salvage/zap/reindex
|
||||||
|
// restart, key import, seed migration) — not an autonomous background witness rebuild the daemon does
|
||||||
|
// on its own. Gates the "Blockchain rescan complete" toast so background rebuilds don't fire it;
|
||||||
|
// cleared when the toast is shown.
|
||||||
|
std::atomic<bool> user_initiated_rescan_{false}; // atomic: some rescan triggers run on worker threads
|
||||||
// Set when a bootstrap completes; consumed once the daemon is connected to auto-run a rescan
|
// Set when a bootstrap completes; consumed once the daemon is connected to auto-run a rescan
|
||||||
// that reconciles the preserved wallet.dat against the freshly-imported chain.
|
// that reconciles the preserved wallet.dat against the freshly-imported chain.
|
||||||
bool post_bootstrap_rescan_pending_ = false;
|
bool post_bootstrap_rescan_pending_ = false;
|
||||||
@@ -1042,8 +1401,8 @@ private:
|
|||||||
services::WalletSecurityWorkflow wallet_security_workflow_;
|
services::WalletSecurityWorkflow wallet_security_workflow_;
|
||||||
|
|
||||||
// Wizard: stopping an external daemon before bootstrap
|
// Wizard: stopping an external daemon before bootstrap
|
||||||
bool wizard_stopping_external_ = false;
|
std::atomic<bool> wizard_stopping_external_{false}; // written by the stop worker, read by the UI (L-06)
|
||||||
std::string wizard_stop_status_;
|
GuardedStatus wizard_stop_status_; // thread-safe: written by the stop worker, read by the UI (L-06)
|
||||||
|
|
||||||
// PIN vault
|
// PIN vault
|
||||||
std::unique_ptr<util::SecureVault> vault_;
|
std::unique_ptr<util::SecureVault> vault_;
|
||||||
@@ -1109,6 +1468,13 @@ private:
|
|||||||
|
|
||||||
// Private methods - rendering
|
// Private methods - rendering
|
||||||
void renderStatusBar();
|
void renderStatusBar();
|
||||||
|
// Persistent node/RPC error strip at the top of the content column when the wallet can't
|
||||||
|
// reach its node (or the embedded daemon gave up crashing). Decision logic is the pure
|
||||||
|
// evaluateNodeStatusBanner() in ui/node_status_banner.h; this draws it and wires the action.
|
||||||
|
void renderNodeStatusBanner();
|
||||||
|
// Body of the status-bar alert-history popup: recent alerts (incl. ones whose toast faded),
|
||||||
|
// newest first, with severity icon + relative age + a Clear action. See src/ui/notifications.h.
|
||||||
|
void renderAlertHistoryPanel();
|
||||||
void renderLiteFirstRunPrompt(); // lite-only welcome modal when no wallet exists yet
|
void renderLiteFirstRunPrompt(); // lite-only welcome modal when no wallet exists yet
|
||||||
void renderLiteUnlockPrompt(); // lite-only send-time unlock modal
|
void renderLiteUnlockPrompt(); // lite-only send-time unlock modal
|
||||||
void renderImportKeyDialog();
|
void renderImportKeyDialog();
|
||||||
@@ -1125,6 +1491,17 @@ private:
|
|||||||
void renderDecryptWalletDialog();
|
void renderDecryptWalletDialog();
|
||||||
void renderPinDialogs();
|
void renderPinDialogs();
|
||||||
void renderAntivirusHelpDialog();
|
void renderAntivirusHelpDialog();
|
||||||
|
void renderSwitchStopDaemonDialog(); // confirm before stopping an adopted node to switch wallets
|
||||||
|
void renderBlockDbReindexDialog(); // offer to rebuild an unreadable block database (-reindex)
|
||||||
|
void reindexBlockDatabase(); // restart the daemon with -reindex to rebuild the block DB
|
||||||
|
void renderWalletRecoveredDialog(); // warn that the node auto-recovered/salvaged wallet.dat
|
||||||
|
void renderEmptyWalletWarningDialog();// warn that the active wallet is empty while a sibling holds funds
|
||||||
|
void detectWalletAutoRecovery(); // scan daemon output for a salvage; fire the warning once/session
|
||||||
|
void detectWalletDegraded(); // scan daemon output for a DEGRADED-mode open; warn once/session
|
||||||
|
void restoreOriginalWallet(); // swap the wallet.<ts>.bak back over the salvaged copy + restart
|
||||||
|
void pumpWalletRestore(); // main-thread: surface the restore/rebuild op's result
|
||||||
|
void rebuildWalletDatabase(); // rebuild a BDB-inconsistent wallet into a loadable one (helper)
|
||||||
|
bool walletRebuildAvailable() const; // the dragonx-wallet-rebuild helper is present
|
||||||
void processDeferredEncryption();
|
void processDeferredEncryption();
|
||||||
|
|
||||||
// Private methods - connection
|
// Private methods - connection
|
||||||
@@ -1155,6 +1532,13 @@ private:
|
|||||||
void refreshPrice();
|
void refreshPrice();
|
||||||
void refreshWalletEncryptionState();
|
void refreshWalletEncryptionState();
|
||||||
void applyRefreshPolicy(ui::NavPage page);
|
void applyRefreshPolicy(ui::NavPage page);
|
||||||
|
bool effectivelySyncing() const; // syncing, or within the post-sync settle window (hysteresis)
|
||||||
|
bool balanceRefreshDue() const; // adaptive: enough time elapsed given the last balance-scan cost?
|
||||||
|
bool addressRefreshDue() const; // same adaptive back-off for the address scan (z_listunspent)
|
||||||
|
bool txRefreshDue() const; // same adaptive back-off for the history scan (z_listreceivedbyaddress)
|
||||||
|
// Shared duty-cycle rule: a scan may resume only once (lastScanMs / kScanDutyCycle) has elapsed since
|
||||||
|
// lastUpdate, so any single O(mapWallet) scan can occupy at most ~kScanDutyCycle of wall-clock.
|
||||||
|
bool scanRefreshDue(std::int64_t lastUpdate, double lastScanMs) const;
|
||||||
bool currentPageNeedsWalletDataRefresh() const;
|
bool currentPageNeedsWalletDataRefresh() const;
|
||||||
bool shouldRunWalletTransactionRefresh() const;
|
bool shouldRunWalletTransactionRefresh() const;
|
||||||
bool shouldRefreshTransactions() const;
|
bool shouldRefreshTransactions() const;
|
||||||
|
|||||||
2103
src/app_network.cpp
2103
src/app_network.cpp
File diff suppressed because it is too large
Load Diff
@@ -33,6 +33,10 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
#include <sodium.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -234,6 +238,41 @@ private:
|
|||||||
// daemon off the main thread (to avoid stalling the UI), or ask the user to
|
// daemon off the main thread (to avoid stalling the UI), or ask the user to
|
||||||
// restart an external daemon. Shared by encryptWalletWithPassphrase() and
|
// restart an external daemon. Shared by encryptWalletWithPassphrase() and
|
||||||
// processDeferredEncryption(); must be called on the main thread.
|
// processDeferredEncryption(); must be called on the main thread.
|
||||||
|
// Zero (overwrite) then delete a plaintext key export so a full cleartext dump of every private key is
|
||||||
|
// never left readable on disk. Idempotent + error-tolerant (safe on a missing/locked file). (H-02)
|
||||||
|
void App::scrubAndRemoveExport(const std::string& path)
|
||||||
|
{
|
||||||
|
if (path.empty()) return;
|
||||||
|
std::error_code ec;
|
||||||
|
const auto sz = std::filesystem::file_size(path, ec);
|
||||||
|
if (!ec && sz > 0) {
|
||||||
|
std::fstream scrub(path, std::ios::binary | std::ios::in | std::ios::out);
|
||||||
|
if (scrub) {
|
||||||
|
const std::vector<char> zeros(static_cast<size_t>(sz), 0);
|
||||||
|
scrub.write(zeros.data(), static_cast<std::streamsize>(sz));
|
||||||
|
scrub.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::filesystem::remove(path, ec);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Startup net for H-02: a crash/kill/early-return between exporting the cleartext keys and scrubbing them
|
||||||
|
// could leave an obsidiandecryptexport* file behind. Purge any found in the data dir on launch.
|
||||||
|
void App::sweepStaleDecryptExports()
|
||||||
|
{
|
||||||
|
std::error_code ec;
|
||||||
|
const std::string dir = util::Platform::getDragonXDataDir();
|
||||||
|
std::filesystem::directory_iterator it(dir, ec), end;
|
||||||
|
for (; it != end; it.increment(ec)) {
|
||||||
|
if (ec) break;
|
||||||
|
const std::string name = it->path().filename().string();
|
||||||
|
if (name.rfind("obsidiandecryptexport", 0) == 0) {
|
||||||
|
scrubAndRemoveExport(it->path().string());
|
||||||
|
DEBUG_LOGF("[decrypt] swept stale plaintext key export: %s\n", name.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void App::restartDaemonAfterEncryption(const char* taskName, bool announceRestartStatus) {
|
void App::restartDaemonAfterEncryption(const char* taskName, bool announceRestartStatus) {
|
||||||
if (isUsingEmbeddedDaemon()) {
|
if (isUsingEmbeddedDaemon()) {
|
||||||
if (announceRestartStatus) {
|
if (announceRestartStatus) {
|
||||||
@@ -241,27 +280,34 @@ void App::restartDaemonAfterEncryption(const char* taskName, bool announceRestar
|
|||||||
// the daemon is restarting.
|
// the daemon is restarting.
|
||||||
connection_status_ = TR("restarting_after_encryption");
|
connection_status_ = TR("restarting_after_encryption");
|
||||||
}
|
}
|
||||||
|
// Gate the main-loop reconnect while the daemon is down (so tryConnect can't hit the stopped
|
||||||
|
// node or start a duplicate) and block a concurrent wallet switch/rescan, which check this flag.
|
||||||
|
daemon_restarting_ = true;
|
||||||
// Give daemon a moment to shut down, then restart
|
// Give daemon a moment to shut down, then restart
|
||||||
// (do this off the main thread to avoid stalling the UI)
|
// (do this off the main thread to avoid stalling the UI)
|
||||||
async_tasks_.submit(taskName, [this](const util::AsyncTaskManager::Token& token) {
|
async_tasks_.submit(taskName, [this](const util::AsyncTaskManager::Token& token) {
|
||||||
|
// daemon_restarting_ MUST be cleared on every exit (incl. an early-out or a throw), else it
|
||||||
|
// stays stuck true and wedges reconnect + all future switch/rescan/encryption operations.
|
||||||
|
try {
|
||||||
for (int i = 0; i < 20 && !token.cancelled() && !shutting_down_; ++i)
|
for (int i = 0; i < 20 && !token.cancelled() && !shutting_down_; ++i)
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
if (token.cancelled() || shutting_down_) return;
|
if (!token.cancelled() && !shutting_down_) {
|
||||||
stopEmbeddedDaemon();
|
stopEmbeddedDaemon();
|
||||||
if (token.cancelled() || shutting_down_) return;
|
if (!token.cancelled() && !shutting_down_) startEmbeddedDaemon();
|
||||||
startEmbeddedDaemon();
|
}
|
||||||
// tryConnect will be called by the update loop
|
} catch (...) {}
|
||||||
|
daemon_restarting_ = false; // re-arm reconnect (tryConnect runs from the update loop)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ui::Notifications::instance().warning(
|
ui::Notifications::instance().warning(
|
||||||
"Please restart your daemon for encryption to take effect.");
|
TR("sec_restart_daemon_for_encryption"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::encryptWalletWithPassphrase(const std::string& passphrase) {
|
void App::encryptWalletWithPassphrase(const std::string& passphrase) {
|
||||||
if (!rpc_ || !rpc_->isConnected()) return;
|
if (!rpc_ || !rpc_->isConnected()) return;
|
||||||
encrypt_in_progress_ = true;
|
encrypt_in_progress_ = true;
|
||||||
encrypt_status_ = "Encrypting wallet...";
|
encrypt_status_ = TR("sec_encrypting_wallet");
|
||||||
|
|
||||||
if (worker_) {
|
if (worker_) {
|
||||||
worker_->post([this, passphrase]() mutable -> rpc::RPCWorker::MainCb {
|
worker_->post([this, passphrase]() mutable -> rpc::RPCWorker::MainCb {
|
||||||
@@ -271,7 +317,7 @@ void App::encryptWalletWithPassphrase(const std::string& passphrase) {
|
|||||||
if (result.encrypted) {
|
if (result.encrypted) {
|
||||||
return [this]() {
|
return [this]() {
|
||||||
encrypt_in_progress_ = false;
|
encrypt_in_progress_ = false;
|
||||||
encrypt_status_ = "Wallet encrypted. Restarting daemon...";
|
encrypt_status_ = TR("sec_wallet_encrypted_restarting_daemon");
|
||||||
DEBUG_LOGF("[App] Wallet encrypted — restarting daemon\n");
|
DEBUG_LOGF("[App] Wallet encrypted — restarting daemon\n");
|
||||||
|
|
||||||
// Immediately update local encryption state so the
|
// Immediately update local encryption state so the
|
||||||
@@ -290,7 +336,7 @@ void App::encryptWalletWithPassphrase(const std::string& passphrase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui::Notifications::instance().info(
|
ui::Notifications::instance().info(
|
||||||
"Wallet encrypted successfully", 5.0f);
|
TR("sec_wallet_encrypted_successfully"), 5.0f);
|
||||||
|
|
||||||
// The daemon shuts itself down after encryptwallet.
|
// The daemon shuts itself down after encryptwallet.
|
||||||
// Update connection_status_ so the loading overlay
|
// Update connection_status_ so the loading overlay
|
||||||
@@ -302,11 +348,11 @@ void App::encryptWalletWithPassphrase(const std::string& passphrase) {
|
|||||||
std::string err = result.error;
|
std::string err = result.error;
|
||||||
return [this, err]() {
|
return [this, err]() {
|
||||||
encrypt_in_progress_ = false;
|
encrypt_in_progress_ = false;
|
||||||
encrypt_status_ = "Encryption failed: " + err;
|
encrypt_status_ = std::string(TR("sec_encryption_failed_prefix")) + err;
|
||||||
DEBUG_LOGF("[App] encryptwallet failed: %s\n", err.c_str());
|
DEBUG_LOGF("[App] encryptwallet failed: %s\n", err.c_str());
|
||||||
|
|
||||||
ui::Notifications::instance().error(
|
ui::Notifications::instance().error(
|
||||||
"Encryption failed: " + err);
|
std::string(TR("sec_encryption_failed_prefix")) + err);
|
||||||
|
|
||||||
// Return to passphrase entry on failure
|
// Return to passphrase entry on failure
|
||||||
if (show_encrypt_dialog_ &&
|
if (show_encrypt_dialog_ &&
|
||||||
@@ -347,7 +393,7 @@ void App::processDeferredEncryption() {
|
|||||||
std::string pin = std::move(deferredEncryption.pin);
|
std::string pin = std::move(deferredEncryption.pin);
|
||||||
|
|
||||||
encrypt_in_progress_ = true;
|
encrypt_in_progress_ = true;
|
||||||
encrypt_status_ = "Encrypting wallet...";
|
encrypt_status_ = TR("sec_encrypting_wallet");
|
||||||
|
|
||||||
if (worker_) {
|
if (worker_) {
|
||||||
worker_->post([this, request = services::WalletSecurityController::DeferredEncryptionSnapshot{std::move(passphrase), std::move(pin)}]() mutable -> rpc::RPCWorker::MainCb {
|
worker_->post([this, request = services::WalletSecurityController::DeferredEncryptionSnapshot{std::move(passphrase), std::move(pin)}]() mutable -> rpc::RPCWorker::MainCb {
|
||||||
@@ -367,13 +413,13 @@ void App::processDeferredEncryption() {
|
|||||||
if (result.pinStored) {
|
if (result.pinStored) {
|
||||||
settings_->setPinEnabled(true);
|
settings_->setPinEnabled(true);
|
||||||
settings_->save();
|
settings_->save();
|
||||||
ui::Notifications::instance().info("Wallet encrypted & PIN set", 5.0f);
|
ui::Notifications::instance().info(TR("sec_wallet_encrypted_and_pin_set"), 5.0f);
|
||||||
} else {
|
} else {
|
||||||
ui::Notifications::instance().warning(
|
ui::Notifications::instance().warning(
|
||||||
"Wallet encrypted but PIN vault failed");
|
TR("sec_wallet_encrypted_but_pin_vault_failed"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ui::Notifications::instance().info("Wallet encrypted successfully", 5.0f);
|
ui::Notifications::instance().info(TR("sec_wallet_encrypted_successfully"), 5.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
wallet_security_.clearDeferredEncryption();
|
wallet_security_.clearDeferredEncryption();
|
||||||
@@ -386,9 +432,9 @@ void App::processDeferredEncryption() {
|
|||||||
std::string err = result.error;
|
std::string err = result.error;
|
||||||
return [this, err]() {
|
return [this, err]() {
|
||||||
encrypt_in_progress_ = false;
|
encrypt_in_progress_ = false;
|
||||||
encrypt_status_ = "Encryption failed: " + err;
|
encrypt_status_ = std::string(TR("sec_encryption_failed_prefix")) + err;
|
||||||
DEBUG_LOGF("[App] Deferred encryptwallet failed: %s\n", err.c_str());
|
DEBUG_LOGF("[App] Deferred encryptwallet failed: %s\n", err.c_str());
|
||||||
ui::Notifications::instance().error("Encryption failed: " + err);
|
ui::Notifications::instance().error(std::string(TR("sec_encryption_failed_prefix")) + err);
|
||||||
wallet_security_.clearDeferredEncryption();
|
wallet_security_.clearDeferredEncryption();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -476,7 +522,17 @@ void App::lockWallet() {
|
|||||||
state_.locked = true;
|
state_.locked = true;
|
||||||
state_.unlocked_until = 0;
|
state_.unlocked_until = 0;
|
||||||
resetTransactionHistoryCacheSession();
|
resetTransactionHistoryCacheSession();
|
||||||
|
lock_failure_warned_ = false;
|
||||||
DEBUG_LOGF("[App] Wallet locked\n");
|
DEBUG_LOGF("[App] Wallet locked\n");
|
||||||
|
} else {
|
||||||
|
// The walletlock RPC failed — the wallet is still UNLOCKED. Surface it (once) rather
|
||||||
|
// than silently leaving an auto-lock unfulfilled and the wallet exposed (W2-4).
|
||||||
|
DEBUG_LOGF("[App] walletlock failed — wallet remains unlocked\n");
|
||||||
|
if (!lock_failure_warned_) {
|
||||||
|
lock_failure_warned_ = true;
|
||||||
|
ui::Notifications::instance().warning(
|
||||||
|
TR("sec_couldnt_lock_wallet"), 12.0f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -485,7 +541,7 @@ void App::lockWallet() {
|
|||||||
void App::changePassphrase(const std::string& oldPass, const std::string& newPass) {
|
void App::changePassphrase(const std::string& oldPass, const std::string& newPass) {
|
||||||
if (!rpc_ || !rpc_->isConnected() || !worker_) return;
|
if (!rpc_ || !rpc_->isConnected() || !worker_) return;
|
||||||
encrypt_in_progress_ = true;
|
encrypt_in_progress_ = true;
|
||||||
encrypt_status_ = "Changing passphrase...";
|
encrypt_status_ = TR("sec_changing_passphrase");
|
||||||
|
|
||||||
auto* w = (fast_worker_ && fast_worker_->isRunning()) ? fast_worker_.get() : worker_.get();
|
auto* w = (fast_worker_ && fast_worker_->isRunning()) ? fast_worker_.get() : worker_.get();
|
||||||
auto* r = (fast_rpc_ && fast_rpc_->isConnected()) ? fast_rpc_.get() : rpc_.get();
|
auto* r = (fast_rpc_ && fast_rpc_->isConnected()) ? fast_rpc_.get() : rpc_.get();
|
||||||
@@ -518,9 +574,9 @@ void App::changePassphrase(const std::string& oldPass, const std::string& newPas
|
|||||||
memset(change_confirm_buf_, 0, sizeof(change_confirm_buf_));
|
memset(change_confirm_buf_, 0, sizeof(change_confirm_buf_));
|
||||||
unlockTransactionHistoryCacheWithPassphrase(newPass);
|
unlockTransactionHistoryCacheWithPassphrase(newPass);
|
||||||
storeTransactionHistoryCacheIfAvailable();
|
storeTransactionHistoryCacheIfAvailable();
|
||||||
ui::Notifications::instance().info("Passphrase changed successfully");
|
ui::Notifications::instance().info(TR("sec_passphrase_changed_successfully"));
|
||||||
} else {
|
} else {
|
||||||
encrypt_status_ = "Failed: " + err_msg;
|
encrypt_status_ = std::string(TR("sec_failed_prefix")) + err_msg;
|
||||||
}
|
}
|
||||||
util::SecureVault::secureZero(newPass.data(), newPass.size());
|
util::SecureVault::secureZero(newPass.data(), newPass.size());
|
||||||
};
|
};
|
||||||
@@ -553,6 +609,12 @@ void App::refreshWalletEncryptionState() {
|
|||||||
state_.unlocked_until = until;
|
state_.unlocked_until = until;
|
||||||
state_.locked = (until == 0);
|
state_.locked = (until == 0);
|
||||||
state_.encryption_state_known = true;
|
state_.encryption_state_known = true;
|
||||||
|
// Wallet is encrypted — any pending deferred-encryption request has now been
|
||||||
|
// satisfied (however it completed). Clear the persisted flag (W2-2).
|
||||||
|
if (settings_ && settings_->getEncryptionPending()) {
|
||||||
|
settings_->setEncryptionPending(false);
|
||||||
|
settings_->save();
|
||||||
|
}
|
||||||
if (state_.locked) {
|
if (state_.locked) {
|
||||||
resetTransactionHistoryCacheSession();
|
resetTransactionHistoryCacheSession();
|
||||||
} else if (state_.transactions.empty()) {
|
} else if (state_.transactions.empty()) {
|
||||||
@@ -565,6 +627,18 @@ void App::refreshWalletEncryptionState() {
|
|||||||
state_.locked = false;
|
state_.locked = false;
|
||||||
state_.unlocked_until = 0;
|
state_.unlocked_until = 0;
|
||||||
state_.encryption_state_known = true;
|
state_.encryption_state_known = true;
|
||||||
|
// W2-2: encryption was requested (persisted flag) but the wallet is NOT encrypted,
|
||||||
|
// and no deferred encryption is pending/in-flight — it was lost to a quit/crash or a
|
||||||
|
// failed connect before it applied. Warn (once/session) instead of silently leaving
|
||||||
|
// an unencrypted wallet the user believes is protected. The flag stays set until the
|
||||||
|
// wallet is actually encrypted, so the warning recurs each launch until resolved.
|
||||||
|
if (settings_ && settings_->getEncryptionPending() &&
|
||||||
|
!wallet_security_.hasDeferredEncryption() && !encrypt_in_progress_ &&
|
||||||
|
!encryption_incomplete_warned_) {
|
||||||
|
encryption_incomplete_warned_ = true;
|
||||||
|
ui::Notifications::instance().warning(
|
||||||
|
TR("sec_encryption_did_not_complete"), 30.0f);
|
||||||
|
}
|
||||||
if (state_.transactions.empty()) {
|
if (state_.transactions.empty()) {
|
||||||
loadTransactionHistoryCacheIfAvailable();
|
loadTransactionHistoryCacheIfAvailable();
|
||||||
} else {
|
} else {
|
||||||
@@ -684,6 +758,10 @@ void App::checkIdleMining() {
|
|||||||
// Resolve auto values: active defaults to half, idle defaults to all
|
// Resolve auto values: active defaults to half, idle defaults to all
|
||||||
if (activeThreads <= 0) activeThreads = std::max(1, maxThreads / 2);
|
if (activeThreads <= 0) activeThreads = std::max(1, maxThreads / 2);
|
||||||
if (idleThreads <= 0) idleThreads = maxThreads;
|
if (idleThreads <= 0) idleThreads = maxThreads;
|
||||||
|
// Clamp to [1, logical cores] before these reach setgenerate / startPoolMining — a settings field
|
||||||
|
// could otherwise carry an arbitrary count straight past every bound. (M-06)
|
||||||
|
activeThreads = std::clamp(activeThreads, 1, maxThreads);
|
||||||
|
idleThreads = std::clamp(idleThreads, 1, maxThreads);
|
||||||
|
|
||||||
if (systemIdle) {
|
if (systemIdle) {
|
||||||
// System is idle — scale up to idle thread count
|
// System is idle — scale up to idle thread count
|
||||||
@@ -872,7 +950,7 @@ void App::renderLockScreen() {
|
|||||||
ImU32 textCol = ui::material::OnSurface();
|
ImU32 textCol = ui::material::OnSurface();
|
||||||
|
|
||||||
{
|
{
|
||||||
const char* title = "Wallet Locked";
|
const char* title = TR("sec_wallet_locked_title");
|
||||||
ImVec2 ts = titleFont->CalcTextSizeA(titleFont->LegacySize, FLT_MAX, 0, title);
|
ImVec2 ts = titleFont->CalcTextSizeA(titleFont->LegacySize, FLT_MAX, 0, title);
|
||||||
dl->AddText(titleFont, titleFont->LegacySize,
|
dl->AddText(titleFont, titleFont->LegacySize,
|
||||||
ImVec2(cardX + (cardW - ts.x) * 0.5f, cy), textCol, title);
|
ImVec2(cardX + (cardW - ts.x) * 0.5f, cy), textCol, title);
|
||||||
@@ -885,23 +963,23 @@ void App::renderLockScreen() {
|
|||||||
if (lock_lockout_timer_ < 0) lock_lockout_timer_ = 0;
|
if (lock_lockout_timer_ < 0) lock_lockout_timer_ = 0;
|
||||||
|
|
||||||
char msg[128];
|
char msg[128];
|
||||||
snprintf(msg, sizeof(msg), "Too many attempts. Wait %.0f seconds...", lock_lockout_timer_);
|
snprintf(msg, sizeof(msg), TR("sec_too_many_attempts_wait"), lock_lockout_timer_);
|
||||||
ImVec2 ms = captionFont->CalcTextSizeA(captionFont->LegacySize, FLT_MAX, 0, msg);
|
ImVec2 ms = captionFont->CalcTextSizeA(captionFont->LegacySize, FLT_MAX, 0, msg);
|
||||||
dl->AddText(captionFont, captionFont->LegacySize,
|
dl->AddText(captionFont, captionFont->LegacySize,
|
||||||
ImVec2(cardX + (cardW - ms.x) * 0.5f, cy), ui::material::Warning(), msg);
|
ImVec2(cardX + (cardW - ms.x) * 0.5f, cy), ui::material::Warning(), msg);
|
||||||
cy += captionFont->LegacySize + 12.0f * dp;
|
cy += captionFont->LegacySize + 12.0f * dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if PIN vault is available
|
// Check if PIN vault is available (per-wallet vault presence; not the global getPinEnabled flag).
|
||||||
bool hasPinVault = vault_ && vault_->hasVault() && settings_ && settings_->getPinEnabled();
|
bool hasPinVault = vault_ && vault_->hasVault();
|
||||||
|
|
||||||
// Mode toggle (PIN / Passphrase) — only show if PIN vault exists
|
// Mode toggle (PIN / Passphrase) — only show if PIN vault exists
|
||||||
if (hasPinVault) {
|
if (hasPinVault) {
|
||||||
const char* modeIcon = lock_use_pin_ ? ICON_MD_DIALPAD : ICON_MD_PASSWORD;
|
const char* modeIcon = lock_use_pin_ ? ICON_MD_DIALPAD : ICON_MD_PASSWORD;
|
||||||
const char* modeText = lock_use_pin_ ? " PIN" : " Passphrase";
|
const char* modeText = lock_use_pin_ ? " PIN" : TR("sec_mode_passphrase");
|
||||||
const char* switchLabel = lock_use_pin_
|
const char* switchLabel = lock_use_pin_
|
||||||
? "Use passphrase instead"
|
? TR("sec_use_passphrase_instead")
|
||||||
: "Use PIN instead";
|
: TR("sec_use_pin_instead");
|
||||||
|
|
||||||
// Current mode indicator — icon with icon font, text with caption font
|
// Current mode indicator — icon with icon font, text with caption font
|
||||||
ImFont* iconFont = ui::material::Type().iconSmall();
|
ImFont* iconFont = ui::material::Type().iconSmall();
|
||||||
@@ -1003,7 +1081,7 @@ void App::renderLockScreen() {
|
|||||||
if (lock_unlock_in_progress_) {
|
if (lock_unlock_in_progress_) {
|
||||||
// Animated spinner dots
|
// Animated spinner dots
|
||||||
char msg[64];
|
char msg[64];
|
||||||
snprintf(msg, sizeof(msg), "Unlocking%s", ui::material::LoadingDots());
|
snprintf(msg, sizeof(msg), TR("sec_unlocking_fmt"), ui::material::LoadingDots());
|
||||||
ImVec2 ms = captionFont->CalcTextSizeA(captionFont->LegacySize, FLT_MAX, 0, msg);
|
ImVec2 ms = captionFont->CalcTextSizeA(captionFont->LegacySize, FLT_MAX, 0, msg);
|
||||||
dl->AddText(captionFont, captionFont->LegacySize,
|
dl->AddText(captionFont, captionFont->LegacySize,
|
||||||
ImVec2(cardX + (cardW - ms.x) * 0.5f, cy),
|
ImVec2(cardX + (cardW - ms.x) * 0.5f, cy),
|
||||||
@@ -1027,7 +1105,7 @@ void App::renderLockScreen() {
|
|||||||
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::ColorConvertU32ToFloat4(ui::material::OnPrimary()));
|
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::ColorConvertU32ToFloat4(ui::material::OnPrimary()));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 8.0f * dp);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 8.0f * dp);
|
||||||
ImGui::BeginDisabled(!canSubmit);
|
ImGui::BeginDisabled(!canSubmit);
|
||||||
bool btnClicked = ui::material::TactileButton("Unlock", ImVec2(unlockW, unlockH));
|
bool btnClicked = ui::material::TactileButton(TR("sec_unlock_button"), ImVec2(unlockW, unlockH));
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
@@ -1081,7 +1159,7 @@ void App::renderLockScreen() {
|
|||||||
r->call("walletpassphrase", {passphrase, timeout});
|
r->call("walletpassphrase", {passphrase, timeout});
|
||||||
rpcOk = true;
|
rpcOk = true;
|
||||||
} else {
|
} else {
|
||||||
rpcErr = "Not connected to daemon";
|
rpcErr = TR("sec_not_connected_to_daemon");
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
rpcErr = e.what();
|
rpcErr = e.what();
|
||||||
@@ -1097,7 +1175,7 @@ void App::renderLockScreen() {
|
|||||||
// so route through applyUnlockFailure so the lockout curve applies
|
// so route through applyUnlockFailure so the lockout curve applies
|
||||||
// (this path previously bumped the counter but skipped the lockout math).
|
// (this path previously bumped the counter but skipped the lockout math).
|
||||||
return [this, rpcErr, passphrase = std::move(passphrase)]() mutable {
|
return [this, rpcErr, passphrase = std::move(passphrase)]() mutable {
|
||||||
applyUnlockFailure("Unlock failed: " + rpcErr);
|
applyUnlockFailure(std::string(TR("sec_unlock_failed_prefix")) + rpcErr);
|
||||||
util::SecureVault::secureZero(passphrase.data(), passphrase.size());
|
util::SecureVault::secureZero(passphrase.data(), passphrase.size());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1186,7 +1264,7 @@ void App::renderEncryptWalletDialog() {
|
|||||||
else if (tier == 1) { strengthLabel = TR("wiz_strength_fair"); strengthCol = ImVec4(1,0.7f,0.3f,1); strengthPct = 0.5f; }
|
else if (tier == 1) { strengthLabel = TR("wiz_strength_fair"); strengthCol = ImVec4(1,0.7f,0.3f,1); strengthPct = 0.5f; }
|
||||||
|
|
||||||
float barW = ImGui::GetContentRegionAvail().x;
|
float barW = ImGui::GetContentRegionAvail().x;
|
||||||
float barH = 4.0f;
|
float barH = 4.0f * ui::Layout::dpiScale();
|
||||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||||
dl->AddRectFilled(p, ImVec2(p.x + barW, p.y + barH),
|
dl->AddRectFilled(p, ImVec2(p.x + barW, p.y + barH),
|
||||||
@@ -1236,7 +1314,7 @@ void App::renderEncryptWalletDialog() {
|
|||||||
// Indeterminate progress bar
|
// Indeterminate progress bar
|
||||||
{
|
{
|
||||||
float barW = ImGui::GetContentRegionAvail().x;
|
float barW = ImGui::GetContentRegionAvail().x;
|
||||||
float barH = 6.0f;
|
float barH = 6.0f * ui::Layout::dpiScale();
|
||||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||||
dl->AddRectFilled(p, ImVec2(p.x + barW, p.y + barH),
|
dl->AddRectFilled(p, ImVec2(p.x + barW, p.y + barH),
|
||||||
@@ -1304,9 +1382,13 @@ void App::renderEncryptWalletDialog() {
|
|||||||
enc_dlg_pin_status_.clear();
|
enc_dlg_pin_status_.clear();
|
||||||
std::string savedPass = enc_dlg_saved_passphrase_;
|
std::string savedPass = enc_dlg_saved_passphrase_;
|
||||||
if (worker_ && vault_) {
|
if (worker_ && vault_) {
|
||||||
worker_->post([this, pinStr, savedPass]() -> rpc::RPCWorker::MainCb {
|
worker_->post([this, pinStr, savedPass]() mutable -> rpc::RPCWorker::MainCb {
|
||||||
// Argon2id runs here (worker thread)
|
// Argon2id runs here (worker thread)
|
||||||
bool ok = vault_->store(pinStr, savedPass);
|
bool ok = vault_->store(pinStr, savedPass);
|
||||||
|
// Scrub the captured PIN + passphrase copies (they live in the worker's task
|
||||||
|
// queue until this runs); the source member is scrubbed in the MainCb. (L-03)
|
||||||
|
if (!savedPass.empty()) util::SecureVault::secureZero(&savedPass[0], savedPass.size());
|
||||||
|
if (!pinStr.empty()) util::SecureVault::secureZero(&pinStr[0], pinStr.size());
|
||||||
return [this, ok]() {
|
return [this, ok]() {
|
||||||
if (ok) {
|
if (ok) {
|
||||||
settings_->setPinEnabled(true);
|
settings_->setPinEnabled(true);
|
||||||
@@ -1367,6 +1449,11 @@ void App::renderEncryptWalletDialog() {
|
|||||||
ov.cardWidth = 460.0f; ov.idSuffix = "changepass";
|
ov.cardWidth = 460.0f; ov.idSuffix = "changepass";
|
||||||
if (BeginOverlayDialog(ov)) {
|
if (BeginOverlayDialog(ov)) {
|
||||||
|
|
||||||
|
// Same fund-loss consequence as Encrypt/Remove Encryption if the new
|
||||||
|
// passphrase is lost — reuse their warning string/header for consistency.
|
||||||
|
DialogWarningHeader(TR("wiz_encrypt_warning"));
|
||||||
|
ImGui::Spacing();
|
||||||
|
|
||||||
ImGui::TextUnformatted(TR("change_pass_current"));
|
ImGui::TextUnformatted(TR("change_pass_current"));
|
||||||
ImGui::PushItemWidth(-1);
|
ImGui::PushItemWidth(-1);
|
||||||
ImGui::InputText("##chg_old", change_old_pass_buf_, sizeof(change_old_pass_buf_),
|
ImGui::InputText("##chg_old", change_old_pass_buf_, sizeof(change_old_pass_buf_),
|
||||||
@@ -1393,12 +1480,22 @@ void App::renderEncryptWalletDialog() {
|
|||||||
bool valid = strlen(change_old_pass_buf_) > 0 &&
|
bool valid = strlen(change_old_pass_buf_) > 0 &&
|
||||||
strlen(change_new_pass_buf_) >= 8 &&
|
strlen(change_new_pass_buf_) >= 8 &&
|
||||||
strcmp(change_new_pass_buf_, change_confirm_buf_) == 0;
|
strcmp(change_new_pass_buf_, change_confirm_buf_) == 0;
|
||||||
|
|
||||||
|
// Two-button footer (primary + Cancel) to match the encrypt/decrypt siblings.
|
||||||
|
float btnW = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
|
||||||
ImGui::BeginDisabled(!valid || encrypt_in_progress_);
|
ImGui::BeginDisabled(!valid || encrypt_in_progress_);
|
||||||
if (ui::material::TactileButton(TR("change_pass_title"), ImVec2(-1, 40))) {
|
if (ui::material::TactileButton(TR("change_pass_title"), ImVec2(btnW, 40))) {
|
||||||
changePassphrase(std::string(change_old_pass_buf_),
|
changePassphrase(std::string(change_old_pass_buf_),
|
||||||
std::string(change_new_pass_buf_));
|
std::string(change_new_pass_buf_));
|
||||||
}
|
}
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
// Cancel does what Esc/close does — dismiss without applying. Buffers are wiped by
|
||||||
|
// the !show_change_passphrase_ cleanup block below.
|
||||||
|
if (ui::material::TactileButton(TR("cancel"), ImVec2(btnW, 40))) {
|
||||||
|
show_change_passphrase_ = false;
|
||||||
|
}
|
||||||
EndOverlayDialog();
|
EndOverlayDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1471,15 +1568,17 @@ void App::renderDecryptWalletDialog() {
|
|||||||
|
|
||||||
// Run entire decrypt flow on worker thread
|
// Run entire decrypt flow on worker thread
|
||||||
if (worker_) {
|
if (worker_) {
|
||||||
worker_->post([this, passphrase]() -> rpc::RPCWorker::MainCb {
|
worker_->post([this, passphrase = std::move(passphrase)]() mutable -> rpc::RPCWorker::MainCb {
|
||||||
WalletSecurityDecryptRpcAdapter decryptRpc(rpc_.get(),
|
WalletSecurityDecryptRpcAdapter decryptRpc(rpc_.get(),
|
||||||
[this](rpc::RPCClient& client, const char* context) {
|
[this](rpc::RPCClient& client, const char* context) {
|
||||||
return sendStopCommandSafely(client, context);
|
return sendStopCommandSafely(client, context);
|
||||||
});
|
});
|
||||||
auto unlock = services::WalletSecurityWorkflowExecutor::unlockWallet(passphrase, decryptRpc);
|
auto unlock = services::WalletSecurityWorkflowExecutor::unlockWallet(passphrase, decryptRpc);
|
||||||
|
// Scrub the passphrase — unlock is its only use in this flow.
|
||||||
|
if (!passphrase.empty()) sodium_memzero(&passphrase[0], passphrase.size());
|
||||||
if (!unlock.ok) {
|
if (!unlock.ok) {
|
||||||
return [this]() {
|
return [this]() {
|
||||||
wallet_security_workflow_.failEntry("Incorrect passphrase");
|
wallet_security_workflow_.failEntry(TR("sec_incorrect_passphrase_decrypt"));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1546,6 +1645,11 @@ void App::renderDecryptWalletDialog() {
|
|||||||
std::chrono::steady_clock::now());
|
std::chrono::steady_clock::now());
|
||||||
|
|
||||||
auto restartAndImport = [this, exportPath](const util::AsyncTaskManager::Token& token) {
|
auto restartAndImport = [this, exportPath](const util::AsyncTaskManager::Token& token) {
|
||||||
|
// Scrub + delete the plaintext key export (obsidiandecryptexport…) on EVERY exit path —
|
||||||
|
// success, a restart-failure early return, or an exception. A full cleartext dump of all
|
||||||
|
// private keys must never outlive this step. The startup sweep is a further net for a
|
||||||
|
// crash/kill mid-flight. (H-02)
|
||||||
|
struct ExportScrub { std::string p; ~ExportScrub() { App::scrubAndRemoveExport(p); } } exportScrub{exportPath};
|
||||||
WalletSecurityDaemonAdapter daemonAdapter(*this, token);
|
WalletSecurityDaemonAdapter daemonAdapter(*this, token);
|
||||||
WalletSecurityDecryptRpcAdapter decryptRpc(rpc_.get(),
|
WalletSecurityDecryptRpcAdapter decryptRpc(rpc_.get(),
|
||||||
[this](rpc::RPCClient& client, const char* context) {
|
[this](rpc::RPCClient& client, const char* context) {
|
||||||
@@ -1590,7 +1694,7 @@ void App::renderDecryptWalletDialog() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ui::Notifications::instance().info(
|
ui::Notifications::instance().info(
|
||||||
"Importing keys & rescanning blockchain — wallet is usable while this runs",
|
TR("sec_importing_keys_rescanning"),
|
||||||
8.0f);
|
8.0f);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -1599,6 +1703,8 @@ void App::renderDecryptWalletDialog() {
|
|||||||
WalletSecurityImportRpcAdapter importAdapter(rpc_.get(), saved_config_);
|
WalletSecurityImportRpcAdapter importAdapter(rpc_.get(), saved_config_);
|
||||||
auto importResult = services::WalletSecurityWorkflowExecutor::importWallet(
|
auto importResult = services::WalletSecurityWorkflowExecutor::importWallet(
|
||||||
importAdapter, exportPath);
|
importAdapter, exportPath);
|
||||||
|
// (exportScrub scrubs + deletes the plaintext key export on scope exit — H-02)
|
||||||
|
|
||||||
if (!importResult.ok) {
|
if (!importResult.ok) {
|
||||||
std::string err = importResult.error;
|
std::string err = importResult.error;
|
||||||
if (worker_) {
|
if (worker_) {
|
||||||
@@ -1607,7 +1713,7 @@ void App::renderDecryptWalletDialog() {
|
|||||||
wallet_security_workflow_.finishImport();
|
wallet_security_workflow_.finishImport();
|
||||||
ui::Notifications::instance().error(
|
ui::Notifications::instance().error(
|
||||||
err +
|
err +
|
||||||
"\nEncrypted backup: wallet.dat.encrypted.bak",
|
TR("sec_encrypted_backup_suffix"),
|
||||||
12.0f);
|
12.0f);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -1633,7 +1739,7 @@ void App::renderDecryptWalletDialog() {
|
|||||||
refreshPeerInfo();
|
refreshPeerInfo();
|
||||||
|
|
||||||
ui::Notifications::instance().success(
|
ui::Notifications::instance().success(
|
||||||
"Wallet decrypted successfully! All keys imported.",
|
TR("sec_wallet_decrypted_all_keys_imported"),
|
||||||
8.0f);
|
8.0f);
|
||||||
DEBUG_LOGF("[App] Wallet decrypted successfully\n");
|
DEBUG_LOGF("[App] Wallet decrypted successfully\n");
|
||||||
};
|
};
|
||||||
@@ -1723,7 +1829,7 @@ void App::renderDecryptWalletDialog() {
|
|||||||
// Indeterminate progress bar
|
// Indeterminate progress bar
|
||||||
{
|
{
|
||||||
float barW = ImGui::GetContentRegionAvail().x;
|
float barW = ImGui::GetContentRegionAvail().x;
|
||||||
float barH = 6.0f;
|
float barH = 6.0f * ui::Layout::dpiScale();
|
||||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||||
dl->AddRectFilled(p, ImVec2(p.x + barW, p.y + barH),
|
dl->AddRectFilled(p, ImVec2(p.x + barW, p.y + barH),
|
||||||
@@ -1755,7 +1861,7 @@ void App::renderDecryptWalletDialog() {
|
|||||||
int tMins = (int)(totalElapsed / 60);
|
int tMins = (int)(totalElapsed / 60);
|
||||||
int tSecs = (int)(totalElapsed % 60);
|
int tSecs = (int)(totalElapsed % 60);
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
ImGui::TextDisabled("Total elapsed: %dm %02ds", tMins, tSecs);
|
ImGui::TextDisabled(TR("sec_total_elapsed_fmt"), tMins, tSecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Phase 2: Success ----
|
// ---- Phase 2: Success ----
|
||||||
@@ -1853,10 +1959,12 @@ void App::renderPinDialogs() {
|
|||||||
util::SecureVault::isValidPin(pinStr) &&
|
util::SecureVault::isValidPin(pinStr) &&
|
||||||
strcmp(pin_buf_, pin_confirm_buf_) == 0;
|
strcmp(pin_buf_, pin_confirm_buf_) == 0;
|
||||||
|
|
||||||
|
// Two-button footer (primary + Cancel) to match the encrypt/decrypt siblings.
|
||||||
|
float btnW = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
|
||||||
ImGui::BeginDisabled(!valid || pin_in_progress_);
|
ImGui::BeginDisabled(!valid || pin_in_progress_);
|
||||||
if (ui::material::TactileButton(TR("settings_set_pin"), ImVec2(-1, 40))) {
|
if (ui::material::TactileButton(TR("settings_set_pin"), ImVec2(btnW, 40))) {
|
||||||
pin_in_progress_ = true;
|
pin_in_progress_ = true;
|
||||||
pin_status_ = "Verifying passphrase...";
|
pin_status_ = TR("sec_verifying_passphrase");
|
||||||
|
|
||||||
// Verify passphrase + store vault on worker thread to avoid
|
// Verify passphrase + store vault on worker thread to avoid
|
||||||
// blocking the UI with Argon2id key derivation.
|
// blocking the UI with Argon2id key derivation.
|
||||||
@@ -1867,20 +1975,25 @@ void App::renderPinDialogs() {
|
|||||||
memset(pin_confirm_buf_, 0, sizeof(pin_confirm_buf_));
|
memset(pin_confirm_buf_, 0, sizeof(pin_confirm_buf_));
|
||||||
|
|
||||||
if (rpc_ && rpc_->isConnected() && worker_) {
|
if (rpc_ && rpc_->isConnected() && worker_) {
|
||||||
worker_->post([this, passphrase, pin]() -> rpc::RPCWorker::MainCb {
|
worker_->post([this, passphrase, pin]() mutable -> rpc::RPCWorker::MainCb {
|
||||||
// Verify passphrase via RPC (worker thread)
|
// Verify passphrase via RPC (worker thread)
|
||||||
try {
|
try {
|
||||||
rpc::RPCClient::TraceScope trace("Security / PIN setup");
|
rpc::RPCClient::TraceScope trace("Security / PIN setup");
|
||||||
rpc_->call("walletpassphrase", {passphrase, 5});
|
rpc_->call("walletpassphrase", {passphrase, 5});
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
|
if (!passphrase.empty()) util::SecureVault::secureZero(&passphrase[0], passphrase.size());
|
||||||
|
if (!pin.empty()) util::SecureVault::secureZero(&pin[0], pin.size());
|
||||||
return [this]() {
|
return [this]() {
|
||||||
pin_status_ = "Incorrect passphrase";
|
pin_status_ = TR("sec_incorrect_passphrase_pin_setup");
|
||||||
pin_in_progress_ = false;
|
pin_in_progress_ = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Passphrase correct — store in vault (Argon2id, worker thread)
|
// Passphrase correct — store in vault (Argon2id, worker thread)
|
||||||
bool storeOk = vault_ && vault_->store(pin, passphrase);
|
bool storeOk = vault_ && vault_->store(pin, passphrase);
|
||||||
|
// Captured passphrase + PIN are no longer needed — scrub the worker-queue copies. (M-01)
|
||||||
|
if (!passphrase.empty()) util::SecureVault::secureZero(&passphrase[0], passphrase.size());
|
||||||
|
if (!pin.empty()) util::SecureVault::secureZero(&pin[0], pin.size());
|
||||||
|
|
||||||
// Lock wallet back
|
// Lock wallet back
|
||||||
try {
|
try {
|
||||||
@@ -1895,19 +2008,26 @@ void App::renderPinDialogs() {
|
|||||||
pin_status_.clear();
|
pin_status_.clear();
|
||||||
pin_in_progress_ = false;
|
pin_in_progress_ = false;
|
||||||
show_pin_setup_ = false;
|
show_pin_setup_ = false;
|
||||||
ui::Notifications::instance().info("PIN set successfully");
|
ui::Notifications::instance().info(TR("sec_pin_set_successfully"));
|
||||||
} else {
|
} else {
|
||||||
pin_status_ = "Failed to create vault";
|
pin_status_ = TR("sec_failed_to_create_vault");
|
||||||
pin_in_progress_ = false;
|
pin_in_progress_ = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
pin_status_ = "Not connected to daemon";
|
pin_status_ = TR("sec_not_connected_to_daemon_pin");
|
||||||
pin_in_progress_ = false;
|
pin_in_progress_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
// Cancel does what Esc/close does — dismiss without applying. Buffers are wiped by
|
||||||
|
// the !show_pin_setup_ cleanup block below.
|
||||||
|
if (ui::material::TactileButton(TR("cancel"), ImVec2(btnW, 40))) {
|
||||||
|
show_pin_setup_ = false;
|
||||||
|
}
|
||||||
EndOverlayDialog();
|
EndOverlayDialog();
|
||||||
}
|
}
|
||||||
// Wipe the passphrase/PIN buffers if the dialog was dismissed (X / Esc /
|
// Wipe the passphrase/PIN buffers if the dialog was dismissed (X / Esc /
|
||||||
@@ -1961,7 +2081,7 @@ void App::renderPinDialogs() {
|
|||||||
ImGui::BeginDisabled(!valid || pin_in_progress_);
|
ImGui::BeginDisabled(!valid || pin_in_progress_);
|
||||||
if (ui::material::TactileButton(TR("settings_change_pin"), ImVec2(-1, 40))) {
|
if (ui::material::TactileButton(TR("settings_change_pin"), ImVec2(-1, 40))) {
|
||||||
pin_in_progress_ = true;
|
pin_in_progress_ = true;
|
||||||
pin_status_ = "Changing PIN...";
|
pin_status_ = TR("sec_changing_pin");
|
||||||
std::string oldPin(pin_old_buf_);
|
std::string oldPin(pin_old_buf_);
|
||||||
std::string newPinCopy = newPin;
|
std::string newPinCopy = newPin;
|
||||||
memset(pin_old_buf_, 0, sizeof(pin_old_buf_));
|
memset(pin_old_buf_, 0, sizeof(pin_old_buf_));
|
||||||
@@ -1977,15 +2097,15 @@ void App::renderPinDialogs() {
|
|||||||
pin_status_.clear();
|
pin_status_.clear();
|
||||||
pin_in_progress_ = false;
|
pin_in_progress_ = false;
|
||||||
show_pin_change_ = false;
|
show_pin_change_ = false;
|
||||||
ui::Notifications::instance().info("PIN changed successfully");
|
ui::Notifications::instance().info(TR("sec_pin_changed_successfully"));
|
||||||
} else {
|
} else {
|
||||||
pin_status_ = "Incorrect current PIN";
|
pin_status_ = TR("sec_incorrect_current_pin");
|
||||||
pin_in_progress_ = false;
|
pin_in_progress_ = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
pin_status_ = "Internal error";
|
pin_status_ = TR("sec_internal_error_change_pin");
|
||||||
pin_in_progress_ = false;
|
pin_in_progress_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2026,7 +2146,7 @@ void App::renderPinDialogs() {
|
|||||||
ImGui::BeginDisabled(!valid || pin_in_progress_);
|
ImGui::BeginDisabled(!valid || pin_in_progress_);
|
||||||
if (ui::material::TactileButton(TR("settings_remove_pin"), ImVec2(-1, 40))) {
|
if (ui::material::TactileButton(TR("settings_remove_pin"), ImVec2(-1, 40))) {
|
||||||
pin_in_progress_ = true;
|
pin_in_progress_ = true;
|
||||||
pin_status_ = "Verifying PIN...";
|
pin_status_ = TR("sec_verifying_pin");
|
||||||
std::string oldPin(pin_old_buf_);
|
std::string oldPin(pin_old_buf_);
|
||||||
memset(pin_old_buf_, 0, sizeof(pin_old_buf_));
|
memset(pin_old_buf_, 0, sizeof(pin_old_buf_));
|
||||||
|
|
||||||
@@ -2046,15 +2166,15 @@ void App::renderPinDialogs() {
|
|||||||
pin_status_.clear();
|
pin_status_.clear();
|
||||||
pin_in_progress_ = false;
|
pin_in_progress_ = false;
|
||||||
show_pin_remove_ = false;
|
show_pin_remove_ = false;
|
||||||
ui::Notifications::instance().info("PIN removed");
|
ui::Notifications::instance().info(TR("sec_pin_removed"));
|
||||||
} else {
|
} else {
|
||||||
pin_status_ = "Incorrect PIN";
|
pin_status_ = TR("sec_incorrect_pin_remove");
|
||||||
pin_in_progress_ = false;
|
pin_in_progress_ = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
pin_status_ = "Internal error";
|
pin_status_ = TR("sec_internal_error_remove_pin");
|
||||||
pin_in_progress_ = false;
|
pin_in_progress_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,10 +170,10 @@ void App::installDemoWalletData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto zaddr = [](const char* a, double bal, const char* label) {
|
auto zaddr = [](const char* a, double bal, const char* label) {
|
||||||
AddressInfo i; i.address = a; i.balance = bal; i.type = "shielded"; i.label = label; return i;
|
AddressInfo i; i.address = a; i.balance = bal; i.spendableBalance = bal; i.type = "shielded"; i.label = label; return i;
|
||||||
};
|
};
|
||||||
auto taddr = [](const char* a, double bal, const char* label) {
|
auto taddr = [](const char* a, double bal, const char* label) {
|
||||||
AddressInfo i; i.address = a; i.balance = bal; i.type = "transparent"; i.label = label; return i;
|
AddressInfo i; i.address = a; i.balance = bal; i.spendableBalance = bal; i.type = "transparent"; i.label = label; return i;
|
||||||
};
|
};
|
||||||
state_.z_addresses = {
|
state_.z_addresses = {
|
||||||
zaddr("zs1demoprimaryshieldedaddressforuisweep000000000000000000000000000", 12.0, "Savings"),
|
zaddr("zs1demoprimaryshieldedaddressforuisweep000000000000000000000000000", 12.0, "Savings"),
|
||||||
@@ -310,6 +310,8 @@ void App::buildSweepCatalog()
|
|||||||
[](App& a) { ui::BootstrapDownloadDialog::show(&a); }, [](App&) { ui::BootstrapDownloadDialog::hide(); });
|
[](App& a) { ui::BootstrapDownloadDialog::show(&a); }, [](App&) { ui::BootstrapDownloadDialog::hide(); });
|
||||||
add("modal-backup", ui::NavPage::Overview,
|
add("modal-backup", ui::NavPage::Overview,
|
||||||
[](App& a) { a.show_backup_ = true; }, [](App& a) { a.show_backup_ = false; a.backup_status_.clear(); });
|
[](App& a) { a.show_backup_ = true; }, [](App& a) { a.show_backup_ = false; a.backup_status_.clear(); });
|
||||||
|
add("modal-faq", ui::NavPage::Overview,
|
||||||
|
[](App& a) { a.show_faq_ = true; }, [](App& a) { a.show_faq_ = false; });
|
||||||
// Encrypt-wallet dialog — the redesigned passphrase-entry phase (never fires the async encrypt).
|
// Encrypt-wallet dialog — the redesigned passphrase-entry phase (never fires the async encrypt).
|
||||||
add("modal-encrypt", ui::NavPage::Settings,
|
add("modal-encrypt", ui::NavPage::Settings,
|
||||||
[](App& a) { a.encrypt_dialog_phase_ = EncryptDialogPhase::PassphraseEntry; a.show_encrypt_dialog_ = true; },
|
[](App& a) { a.encrypt_dialog_phase_ = EncryptDialogPhase::PassphraseEntry; a.show_encrypt_dialog_ = true; },
|
||||||
@@ -376,6 +378,14 @@ void App::buildSweepCatalog()
|
|||||||
add("modal-antivirus", ui::NavPage::Mining,
|
add("modal-antivirus", ui::NavPage::Mining,
|
||||||
[](App& a) { a.pending_antivirus_dialog_ = true; },
|
[](App& a) { a.pending_antivirus_dialog_ = true; },
|
||||||
[](App& a) { a.pending_antivirus_dialog_ = false; });
|
[](App& a) { a.pending_antivirus_dialog_ = false; });
|
||||||
|
add("modal-switch-stopnode", ui::NavPage::Settings,
|
||||||
|
[](App& a) { a.pending_switch_wallet_file_ = "wallet-savings.dat"; a.show_switch_stop_daemon_confirm_ = true; },
|
||||||
|
[](App& a) { a.show_switch_stop_daemon_confirm_ = false; a.pending_switch_wallet_file_.clear(); });
|
||||||
|
add("modal-switch-progress", ui::NavPage::Settings,
|
||||||
|
[](App& a) { a.wallet_switch_phase_.store(static_cast<int>(App::WalletSwitchPhase::Stopping));
|
||||||
|
a.wallet_switch_dialog_open_.store(true); },
|
||||||
|
[](App& a) { a.wallet_switch_dialog_open_.store(false);
|
||||||
|
a.wallet_switch_phase_.store(static_cast<int>(App::WalletSwitchPhase::None)); });
|
||||||
// Wave-2 fund/secret dialogs (setup never fires the async RPC — no button is clicked).
|
// Wave-2 fund/secret dialogs (setup never fires the async RPC — no button is clicked).
|
||||||
add("modal-shield", ui::NavPage::Send,
|
add("modal-shield", ui::NavPage::Send,
|
||||||
[](App&) { ui::ShieldDialog::showShieldCoinbase(); },
|
[](App&) { ui::ShieldDialog::showShieldCoinbase(); },
|
||||||
@@ -696,9 +706,26 @@ void App::startSweepImpl(bool full)
|
|||||||
if (sk.valid) sweep_skins_.push_back(sk.id);
|
if (sk.valid) sweep_skins_.push_back(sk.id);
|
||||||
if (sweep_skins_.empty()) return;
|
if (sweep_skins_.empty()) return;
|
||||||
|
|
||||||
|
// Debug Options "Current theme only": sweep just the active skin instead of cycling every theme.
|
||||||
|
if (sweep_current_theme_only_)
|
||||||
|
sweep_skins_.assign(1, ui::schema::SkinManager::instance().activeSkinId());
|
||||||
|
|
||||||
|
// DEV/TEST hook (dormant unless the env is set): DRAGONX_SWEEP_ONLY="send,receive" restricts the
|
||||||
|
// sweep to the named surfaces and the dark skin, so a slow large-window run captures just the tab
|
||||||
|
// under review instead of all surfaces x every skin.
|
||||||
|
const char* sweepOnly = std::getenv("DRAGONX_SWEEP_ONLY");
|
||||||
|
std::string sweepOnlyStr = sweepOnly ? sweepOnly : "";
|
||||||
|
if (!sweepOnlyStr.empty()) sweep_skins_.assign(1, std::string("dark"));
|
||||||
|
|
||||||
sweep_full_ = full;
|
sweep_full_ = full;
|
||||||
if (full) { capture_mode_ = true; installDemoWalletData(); }
|
if (full) { capture_mode_ = true; installDemoWalletData(); }
|
||||||
buildSweepCatalog();
|
buildSweepCatalog();
|
||||||
|
if (!sweepOnlyStr.empty()) {
|
||||||
|
std::vector<SweepTarget> keep;
|
||||||
|
for (const auto& t : sweep_targets_)
|
||||||
|
if (sweepOnlyStr.find(t.name) != std::string::npos) keep.push_back(t);
|
||||||
|
sweep_targets_.swap(keep);
|
||||||
|
}
|
||||||
if (sweep_targets_.empty()) { if (full) { clearDemoWalletData(); capture_mode_ = false; sweep_full_ = false; } return; }
|
if (sweep_targets_.empty()) { if (full) { clearDemoWalletData(); capture_mode_ = false; sweep_full_ = false; } return; }
|
||||||
|
|
||||||
sweep_dir_ = full ? screenshotFullDir() : screenshotDir();
|
sweep_dir_ = full ? screenshotFullDir() : screenshotDir();
|
||||||
|
|||||||
@@ -177,8 +177,36 @@ void App::renderFirstRunWizard() {
|
|||||||
// DPI scale factor — multiply all pixel constants by dp
|
// DPI scale factor — multiply all pixel constants by dp
|
||||||
const float dp = ui::Layout::dpiScale();
|
const float dp = ui::Layout::dpiScale();
|
||||||
|
|
||||||
|
// Vertical scroll: the wizard cards are hand-drawn at absolute Y offsets and grow ~1.5x with the
|
||||||
|
// font-scale setting, so at high scale the focused card's primary button (Continue / Encrypt & Continue
|
||||||
|
// / Skip) can fall below the fixed window. Offset the whole layout by a wheel-driven scroll, clamped to
|
||||||
|
// last frame's measured content height, so every control stays reachable. The window keeps
|
||||||
|
// NoScrollWithMouse, so ImGui doesn't consume the wheel — we read the raw delta and apply our own offset.
|
||||||
|
static float s_wizScroll = 0.0f, s_wizContentH = 0.0f;
|
||||||
|
if (ImGui::IsWindowAppearing()) s_wizScroll = 0.0f;
|
||||||
|
const float wizMaxScroll = std::max(0.0f, s_wizContentH - winSize.y);
|
||||||
|
// Don't steal the wheel from an open combo popup (e.g. the 9-item Language dropdown, which is a
|
||||||
|
// scrollable popup): NoPopupHierarchy stops the popup counting as hovering the wizard, and the
|
||||||
|
// IsPopupOpen guard ensures no wheel is consumed for the whole wizard while any popup is showing.
|
||||||
|
const bool wizPopupOpen = ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel);
|
||||||
|
if (wizMaxScroll > 0.0f && !wizPopupOpen &&
|
||||||
|
ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy)) {
|
||||||
|
float wheel = ImGui::GetIO().MouseWheel;
|
||||||
|
if (wheel != 0.0f) s_wizScroll -= wheel * 60.0f * dp;
|
||||||
|
}
|
||||||
|
s_wizScroll = std::max(0.0f, std::min(s_wizScroll, wizMaxScroll));
|
||||||
|
const float scrollY = s_wizScroll;
|
||||||
|
|
||||||
// --- Header: Logo + Welcome ---
|
// --- Header: Logo + Welcome ---
|
||||||
float headerCy = winPos.y + 20.0f * dp;
|
// Vertically center the content when it fits (mirrors the horizontal centering below): on a tall
|
||||||
|
// monitor top-anchoring leaves a large void under the cards. Using last frame's measured block
|
||||||
|
// height, when the content fits inside the window (and we're NOT overflowing, so this doesn't
|
||||||
|
// fight the scroll), push everything down by half the leftover space. No-op once content
|
||||||
|
// fills/exceeds the window (s_wizContentH >= winSize.y ⇒ wizMaxScroll > 0 ⇒ vCenter skipped).
|
||||||
|
float vCenter = 0.0f;
|
||||||
|
if (wizMaxScroll == 0.0f && s_wizContentH > 0.0f && s_wizContentH < winSize.y)
|
||||||
|
vCenter = std::max(0.0f, (winSize.y - s_wizContentH) * 0.5f);
|
||||||
|
float headerCy = winPos.y - scrollY + 20.0f * dp + vCenter;
|
||||||
float logoSize = S.drawElement("screens.first-run", "logo").sizeOr(56.0f);
|
float logoSize = S.drawElement("screens.first-run", "logo").sizeOr(56.0f);
|
||||||
if (logo_tex_ != 0) {
|
if (logo_tex_ != 0) {
|
||||||
float aspect = (logo_h_ > 0) ? (float)logo_w_ / (float)logo_h_ : 1.0f;
|
float aspect = (logo_h_ > 0) ? (float)logo_w_ / (float)logo_h_ : 1.0f;
|
||||||
@@ -266,10 +294,23 @@ void App::renderFirstRunWizard() {
|
|||||||
{
|
{
|
||||||
int state = cardState(0);
|
int state = cardState(0);
|
||||||
bool isFocused = (state == 1);
|
bool isFocused = (state == 1);
|
||||||
|
bool isCollapsed = (state == 2); // Completed: minimize to a compact pill (mirrors Card 1)
|
||||||
float cx = leftX + cardPad;
|
float cx = leftX + cardPad;
|
||||||
float cy = card0Top + cardPad;
|
float cy = card0Top + cardPad;
|
||||||
float contentW = colW - 2 * cardPad;
|
float contentW = colW - 2 * cardPad;
|
||||||
|
|
||||||
|
// Step indicator + title (inline when collapsed)
|
||||||
|
if (isCollapsed) {
|
||||||
|
// Compact single-line: check icon + "Step 1" + "Appearance"
|
||||||
|
float iconW = iconFont->CalcTextSizeA(iconFont->LegacySize, FLT_MAX, 0, stepIcon(state)).x;
|
||||||
|
dl->AddText(iconFont, iconFont->LegacySize, ImVec2(cx, cy), dimCol, stepIcon(state));
|
||||||
|
float labelX = cx + iconW + 4.0f * dp;
|
||||||
|
dl->AddText(captionFont, captionFont->LegacySize, ImVec2(labelX, cy), dimCol, TR("wiz_step1"));
|
||||||
|
float step1W = captionFont->CalcTextSizeA(captionFont->LegacySize, FLT_MAX, 0, TR("wiz_step1")).x;
|
||||||
|
float titleX = labelX + step1W + 12.0f * dp;
|
||||||
|
dl->AddText(bodyFont, bodyFont->LegacySize, ImVec2(titleX, cy), dimCol, TR("wiz_appearance"));
|
||||||
|
cy += captionFont->LegacySize + 4.0f * dp;
|
||||||
|
} else {
|
||||||
// Step indicator
|
// Step indicator
|
||||||
{
|
{
|
||||||
float iconW = iconFont->CalcTextSizeA(iconFont->LegacySize, FLT_MAX, 0, stepIcon(state)).x;
|
float iconW = iconFont->CalcTextSizeA(iconFont->LegacySize, FLT_MAX, 0, stepIcon(state)).x;
|
||||||
@@ -289,6 +330,7 @@ void App::renderFirstRunWizard() {
|
|||||||
dl->AddLine(ImVec2(cx, cy), ImVec2(cx + contentW, cy),
|
dl->AddLine(ImVec2(cx, cy), ImVec2(cx + contentW, cy),
|
||||||
(textCol & 0x00FFFFFF) | IM_COL32(0,0,0,40), 1.0f * dp);
|
(textCol & 0x00FFFFFF) | IM_COL32(0,0,0,40), 1.0f * dp);
|
||||||
cy += 14.0f * dp;
|
cy += 14.0f * dp;
|
||||||
|
}
|
||||||
|
|
||||||
float& wiz_blur_amount = wizardUi.blur_amount;
|
float& wiz_blur_amount = wizardUi.blur_amount;
|
||||||
bool& wiz_theme_effects = wizardUi.theme_effects;
|
bool& wiz_theme_effects = wizardUi.theme_effects;
|
||||||
@@ -324,6 +366,9 @@ void App::renderFirstRunWizard() {
|
|||||||
wiz_appearance_init = true;
|
wiz_appearance_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Controls: rendered for the focused and upcoming states so content is visible under
|
||||||
|
// the dim overlay; skipped entirely once completed so the card shrinks to a compact pill.
|
||||||
|
if (!isCollapsed) {
|
||||||
// Render controls always so content is visible under the dim
|
// Render controls always so content is visible under the dim
|
||||||
// overlay when not focused; disable interaction when not active.
|
// overlay when not focused; disable interaction when not active.
|
||||||
ImGui::BeginDisabled(!isFocused);
|
ImGui::BeginDisabled(!isFocused);
|
||||||
@@ -640,14 +685,22 @@ void App::renderFirstRunWizard() {
|
|||||||
cy += btnH;
|
cy += btnH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // if (!isCollapsed)
|
||||||
|
|
||||||
cy += cardPad;
|
cy += cardPad;
|
||||||
// Lock card height to the tallest content ever seen
|
// Lock card height to the tallest content ever seen (but not when collapsed)
|
||||||
float& card0MaxH = wizardUi.card0_max_h;
|
float& card0MaxH = wizardUi.card0_max_h;
|
||||||
|
if (isCollapsed) {
|
||||||
|
// Completed: finalize immediately as a compact pill (do not stretch to the
|
||||||
|
// right column height, and skip the deferred stretch below).
|
||||||
|
card0Bot = card0Top + (cy - card0Top);
|
||||||
|
finalizeCard(leftX, colW, card0Top, card0Bot, state);
|
||||||
|
} else {
|
||||||
card0MaxH = std::max(card0MaxH, cy - card0Top);
|
card0MaxH = std::max(card0MaxH, cy - card0Top);
|
||||||
card0Bot = card0Top + card0MaxH;
|
card0Bot = card0Top + card0MaxH;
|
||||||
|
|
||||||
// Card 0 finalization deferred until after cards 1+2 are sized
|
// Card 0 finalization deferred until after cards 1+2 are sized
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ======================= CARD 1: Bootstrap =======================
|
// ======================= CARD 1: Bootstrap =======================
|
||||||
@@ -889,8 +942,9 @@ void App::renderFirstRunWizard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wizard_stopping_external_) {
|
if (wizard_stopping_external_) {
|
||||||
|
const std::string ws = wizard_stop_status_.get();
|
||||||
dl->AddText(captionFont, captionFont->LegacySize, ImVec2(cx, cy), dimCol,
|
dl->AddText(captionFont, captionFont->LegacySize, ImVec2(cx, cy), dimCol,
|
||||||
wizard_stop_status_.c_str());
|
ws.c_str());
|
||||||
cy += captionFont->LegacySize + 8.0f * dp;
|
cy += captionFont->LegacySize + 8.0f * dp;
|
||||||
} else {
|
} else {
|
||||||
float stopW = 150.0f * dp;
|
float stopW = 150.0f * dp;
|
||||||
@@ -1338,6 +1392,10 @@ void App::renderFirstRunWizard() {
|
|||||||
wallet_security_.beginDeferredEncryption(
|
wallet_security_.beginDeferredEncryption(
|
||||||
std::string(encrypt_pass_buf_),
|
std::string(encrypt_pass_buf_),
|
||||||
(pinEntered && pinOk) ? pinStr : std::string());
|
(pinEntered && pinOk) ? pinStr : std::string());
|
||||||
|
// Persist that encryption was requested (never the passphrase) so a quit/crash or
|
||||||
|
// failed daemon connect before it applies isn't silent — reconciled on the next
|
||||||
|
// connect in refreshWalletEncryptionState (W2-2). Saved with the wizard state below.
|
||||||
|
settings_->setEncryptionPending(true);
|
||||||
|
|
||||||
// Clear sensitive buffers
|
// Clear sensitive buffers
|
||||||
memset(encrypt_pass_buf_, 0, sizeof(encrypt_pass_buf_));
|
memset(encrypt_pass_buf_, 0, sizeof(encrypt_pass_buf_));
|
||||||
@@ -1372,6 +1430,13 @@ void App::renderFirstRunWizard() {
|
|||||||
encrypt_status_ = TR("wiz_skip_confirm");
|
encrypt_status_ = TR("wiz_skip_confirm");
|
||||||
} else {
|
} else {
|
||||||
s_skipEncConfirm = false;
|
s_skipEncConfirm = false;
|
||||||
|
// Skipping leaves the wallet UNENCRYPTED — wipe the passphrase/PIN the user may have
|
||||||
|
// typed so it doesn't linger in these process-lifetime buffers (only the Encrypt
|
||||||
|
// path cleared them before). (L-07)
|
||||||
|
memset(encrypt_pass_buf_, 0, sizeof(encrypt_pass_buf_));
|
||||||
|
memset(encrypt_confirm_buf_, 0, sizeof(encrypt_confirm_buf_));
|
||||||
|
memset(wizard_pin_buf_, 0, sizeof(wizard_pin_buf_));
|
||||||
|
memset(wizard_pin_confirm_buf_, 0, sizeof(wizard_pin_confirm_buf_));
|
||||||
wizard_phase_ = WizardPhase::Done;
|
wizard_phase_ = WizardPhase::Done;
|
||||||
settings_->setWizardCompleted(true);
|
settings_->setWizardCompleted(true);
|
||||||
settings_->save();
|
settings_->save();
|
||||||
@@ -1407,7 +1472,9 @@ void App::renderFirstRunWizard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Deferred Card 0 finalization: match right column total height ---
|
// --- Deferred Card 0 finalization: match right column total height ---
|
||||||
{
|
// Only for the focused/upcoming Appearance card; a completed one was already finalized
|
||||||
|
// above as a compact pill and must not be re-stretched.
|
||||||
|
if (cardState(0) != 2) {
|
||||||
float rightColBot = card2Bot;
|
float rightColBot = card2Bot;
|
||||||
if (rightColBot > card0Bot) card0Bot = rightColBot;
|
if (rightColBot > card0Bot) card0Bot = rightColBot;
|
||||||
finalizeCard(leftX, colW, card0Top, card0Bot, cardState(0));
|
finalizeCard(leftX, colW, card0Top, card0Bot, cardState(0));
|
||||||
@@ -1416,6 +1483,24 @@ void App::renderFirstRunWizard() {
|
|||||||
// Merge channels: backgrounds → content → overlays
|
// Merge channels: backgrounds → content → overlays
|
||||||
dl->ChannelsMerge();
|
dl->ChannelsMerge();
|
||||||
|
|
||||||
|
// Measure this frame's content height (feeds next frame's scroll clamp) and, when it overflows the
|
||||||
|
// window, draw a slim scroll indicator so the off-screen content is discoverable.
|
||||||
|
{
|
||||||
|
float contentBottom = std::max(card0Bot, std::max(card1Bot, card2Bot));
|
||||||
|
// Subtract vCenter back out: everything below the header was shifted down by it, so the raw
|
||||||
|
// span includes it. We want s_wizContentH to be the true (un-centered) content height, or the
|
||||||
|
// vertical-centering above would feed on itself and oscillate frame-to-frame.
|
||||||
|
s_wizContentH = (contentBottom - winPos.y + scrollY - vCenter) + 24.0f * dp;
|
||||||
|
if (wizMaxScroll > 0.0f && s_wizContentH > 0.0f) {
|
||||||
|
float trackH = winSize.y - 8.0f * dp;
|
||||||
|
float thumbH = std::min(trackH, std::max(32.0f * dp, trackH * (winSize.y / s_wizContentH)));
|
||||||
|
float thumbY = winPos.y + 4.0f * dp + (trackH - thumbH) * (scrollY / wizMaxScroll);
|
||||||
|
float barX = winPos.x + winSize.x - 6.0f * dp;
|
||||||
|
dl->AddRectFilled(ImVec2(barX, thumbY), ImVec2(barX + 3.0f * dp, thumbY + thumbH),
|
||||||
|
ui::material::WithAlpha(ui::material::OnSurface(), 55), 1.5f * dp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ bool ChatDatabase::unlockWithSecret(const std::string& secret)
|
|||||||
lock();
|
lock();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
loadTombstones();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,11 +98,13 @@ void ChatDatabase::lock()
|
|||||||
sodium_memzero(key_.data(), key_.size());
|
sodium_memzero(key_.data(), key_.size());
|
||||||
key_ready_ = false;
|
key_ready_ = false;
|
||||||
wallet_tag_.clear();
|
wallet_tag_.clear();
|
||||||
|
tombstones_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatDatabase::append(const ChatMessage& message)
|
bool ChatDatabase::append(const ChatMessage& message)
|
||||||
{
|
{
|
||||||
if (!key_ready_ || !ensureOpen()) return false;
|
if (!key_ready_ || !ensureOpen()) return false;
|
||||||
|
if (isTombstoned(message)) return false; // locally deleted — don't re-persist on a chain re-scan
|
||||||
|
|
||||||
std::vector<unsigned char> nonce;
|
std::vector<unsigned char> nonce;
|
||||||
std::vector<unsigned char> cipher;
|
std::vector<unsigned char> cipher;
|
||||||
@@ -129,6 +132,35 @@ bool ChatDatabase::append(const ChatMessage& message)
|
|||||||
return sqlite3_changes(db_) > 0;
|
return sqlite3_changes(db_) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChatDatabase::upsert(const ChatMessage& message)
|
||||||
|
{
|
||||||
|
if (!key_ready_ || !ensureOpen()) return false;
|
||||||
|
|
||||||
|
std::vector<unsigned char> nonce;
|
||||||
|
std::vector<unsigned char> cipher;
|
||||||
|
std::string plain = serialize(message);
|
||||||
|
const bool encrypted = encrypt(plain, nonce, cipher);
|
||||||
|
if (!plain.empty()) sodium_memzero(&plain[0], plain.size());
|
||||||
|
if (!encrypted) return false;
|
||||||
|
|
||||||
|
const std::string dedup = dedupHash(message.txid, message.payload_position);
|
||||||
|
|
||||||
|
sqlite3_stmt* stmt = nullptr;
|
||||||
|
if (sqlite3_prepare_v2(db_,
|
||||||
|
"INSERT INTO chat_messages (wallet_tag, dedup_hash, nonce, payload) VALUES (?, ?, ?, ?) "
|
||||||
|
"ON CONFLICT(wallet_tag, dedup_hash) DO UPDATE SET nonce=excluded.nonce, payload=excluded.payload",
|
||||||
|
-1, &stmt, nullptr) != SQLITE_OK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
sqlite3_bind_text(stmt, 1, wallet_tag_.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
|
sqlite3_bind_text(stmt, 2, dedup.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
|
sqlite3_bind_blob(stmt, 3, nonce.data(), static_cast<int>(nonce.size()), SQLITE_TRANSIENT);
|
||||||
|
sqlite3_bind_blob(stmt, 4, cipher.data(), static_cast<int>(cipher.size()), SQLITE_TRANSIENT);
|
||||||
|
const bool done = sqlite3_step(stmt) == SQLITE_DONE;
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<ChatMessage> ChatDatabase::load()
|
std::vector<ChatMessage> ChatDatabase::load()
|
||||||
{
|
{
|
||||||
std::vector<ChatMessage> out;
|
std::vector<ChatMessage> out;
|
||||||
@@ -164,13 +196,79 @@ std::vector<ChatMessage> ChatDatabase::load()
|
|||||||
void ChatDatabase::clearWallet()
|
void ChatDatabase::clearWallet()
|
||||||
{
|
{
|
||||||
if (wallet_tag_.empty() || !ensureOpen()) return;
|
if (wallet_tag_.empty() || !ensureOpen()) return;
|
||||||
|
for (const char* sql : {"DELETE FROM chat_messages WHERE wallet_tag = ?",
|
||||||
|
"DELETE FROM chat_deleted WHERE wallet_tag = ?"}) {
|
||||||
sqlite3_stmt* stmt = nullptr;
|
sqlite3_stmt* stmt = nullptr;
|
||||||
if (sqlite3_prepare_v2(db_, "DELETE FROM chat_messages WHERE wallet_tag = ?", -1, &stmt, nullptr)
|
if (sqlite3_prepare_v2(db_, sql, -1, &stmt, nullptr) != SQLITE_OK) continue;
|
||||||
!= SQLITE_OK) {
|
sqlite3_bind_text(stmt, 1, wallet_tag_.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
|
sqlite3_step(stmt);
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
}
|
||||||
|
tombstones_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChatDatabase::deleteMessages(const std::vector<ChatMessage>& messages, bool tombstone)
|
||||||
|
{
|
||||||
|
if (!key_ready_ || !ensureOpen()) return false;
|
||||||
|
if (messages.empty()) return true;
|
||||||
|
|
||||||
|
if (!exec("BEGIN")) return false;
|
||||||
|
bool ok = true;
|
||||||
|
for (const auto& m : messages) {
|
||||||
|
const std::string dedup = dedupHash(m.txid, m.payload_position);
|
||||||
|
|
||||||
|
sqlite3_stmt* del = nullptr;
|
||||||
|
if (sqlite3_prepare_v2(db_, "DELETE FROM chat_messages WHERE wallet_tag = ? AND dedup_hash = ?",
|
||||||
|
-1, &del, nullptr) == SQLITE_OK) {
|
||||||
|
sqlite3_bind_text(del, 1, wallet_tag_.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
|
sqlite3_bind_text(del, 2, dedup.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
|
if (sqlite3_step(del) != SQLITE_DONE) ok = false;
|
||||||
|
sqlite3_finalize(del);
|
||||||
|
} else {
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tombstone) {
|
||||||
|
sqlite3_stmt* ins = nullptr;
|
||||||
|
if (sqlite3_prepare_v2(db_,
|
||||||
|
"INSERT OR IGNORE INTO chat_deleted (wallet_tag, dedup_hash) VALUES (?, ?)",
|
||||||
|
-1, &ins, nullptr) == SQLITE_OK) {
|
||||||
|
sqlite3_bind_text(ins, 1, wallet_tag_.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
|
sqlite3_bind_text(ins, 2, dedup.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
|
if (sqlite3_step(ins) != SQLITE_DONE) ok = false;
|
||||||
|
sqlite3_finalize(ins);
|
||||||
|
} else {
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!exec(ok ? "COMMIT" : "ROLLBACK")) ok = false;
|
||||||
|
// Only reflect the tombstones in the in-memory cache once they are durably committed.
|
||||||
|
if (ok && tombstone)
|
||||||
|
for (const auto& m : messages) tombstones_.insert(dedupHash(m.txid, m.payload_position));
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChatDatabase::isTombstoned(const ChatMessage& message) const
|
||||||
|
{
|
||||||
|
if (!key_ready_ || tombstones_.empty()) return false;
|
||||||
|
return tombstones_.count(dedupHash(message.txid, message.payload_position)) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatDatabase::loadTombstones()
|
||||||
|
{
|
||||||
|
tombstones_.clear();
|
||||||
|
if (!key_ready_ || !ensureOpen()) return;
|
||||||
|
sqlite3_stmt* stmt = nullptr;
|
||||||
|
if (sqlite3_prepare_v2(db_, "SELECT dedup_hash FROM chat_deleted WHERE wallet_tag = ?",
|
||||||
|
-1, &stmt, nullptr) != SQLITE_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sqlite3_bind_text(stmt, 1, wallet_tag_.c_str(), -1, SQLITE_TRANSIENT);
|
sqlite3_bind_text(stmt, 1, wallet_tag_.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
sqlite3_step(stmt);
|
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||||
|
const auto* h = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
|
||||||
|
if (h) tombstones_.insert(h);
|
||||||
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,6 +297,17 @@ bool ChatDatabase::ensureOpen()
|
|||||||
exec("PRAGMA journal_mode=WAL");
|
exec("PRAGMA journal_mode=WAL");
|
||||||
exec("PRAGMA synchronous=NORMAL");
|
exec("PRAGMA synchronous=NORMAL");
|
||||||
|
|
||||||
|
// C3-1: restrict the chat DB and its WAL/SHM sidecars to owner-only. sqlite creates them with
|
||||||
|
// umask-derived permissions (often world/group-readable); they hold per-row nonces + AEAD
|
||||||
|
// ciphertext of the user's messages. Best-effort (errors swallowed; a no-op-ish on Windows).
|
||||||
|
{
|
||||||
|
std::error_code perr;
|
||||||
|
const auto ownerOnly = std::filesystem::perms::owner_read | std::filesystem::perms::owner_write;
|
||||||
|
std::filesystem::permissions(database_path_, ownerOnly, std::filesystem::perm_options::replace, perr);
|
||||||
|
std::filesystem::permissions(database_path_ + "-wal", ownerOnly, std::filesystem::perm_options::replace, perr);
|
||||||
|
std::filesystem::permissions(database_path_ + "-shm", ownerOnly, std::filesystem::perm_options::replace, perr);
|
||||||
|
}
|
||||||
|
|
||||||
if (!createSchema()) {
|
if (!createSchema()) {
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
@@ -220,11 +329,18 @@ bool ChatDatabase::exec(const char* sql)
|
|||||||
|
|
||||||
bool ChatDatabase::createSchema()
|
bool ChatDatabase::createSchema()
|
||||||
{
|
{
|
||||||
return exec("CREATE TABLE IF NOT EXISTS chat_messages ("
|
if (!exec("CREATE TABLE IF NOT EXISTS chat_messages ("
|
||||||
"wallet_tag TEXT NOT NULL, "
|
"wallet_tag TEXT NOT NULL, "
|
||||||
"dedup_hash TEXT NOT NULL, "
|
"dedup_hash TEXT NOT NULL, "
|
||||||
"nonce BLOB NOT NULL, "
|
"nonce BLOB NOT NULL, "
|
||||||
"payload BLOB NOT NULL, "
|
"payload BLOB NOT NULL, "
|
||||||
|
"PRIMARY KEY (wallet_tag, dedup_hash))"))
|
||||||
|
return false;
|
||||||
|
// Tombstones for locally-deleted messages (dedup_hash only — the same keyed, non-revealing hash the
|
||||||
|
// message rows use). A chain re-scan checks this so a deleted message never re-imports.
|
||||||
|
return exec("CREATE TABLE IF NOT EXISTS chat_deleted ("
|
||||||
|
"wallet_tag TEXT NOT NULL, "
|
||||||
|
"dedup_hash TEXT NOT NULL, "
|
||||||
"PRIMARY KEY (wallet_tag, dedup_hash))");
|
"PRIMARY KEY (wallet_tag, dedup_hash))");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +383,10 @@ bool ChatDatabase::deserialize(const std::string& json, ChatMessage& out) const
|
|||||||
out.body = parsed.value("b", std::string());
|
out.body = parsed.value("b", std::string());
|
||||||
out.timestamp = parsed.value("ts", static_cast<std::int64_t>(0));
|
out.timestamp = parsed.value("ts", static_cast<std::int64_t>(0));
|
||||||
out.payload_position = static_cast<std::size_t>(parsed.value("pos", static_cast<std::uint64_t>(0)));
|
out.payload_position = static_cast<std::size_t>(parsed.value("pos", static_cast<std::uint64_t>(0)));
|
||||||
out.delivery = static_cast<ChatDelivery>(parsed.value("dl", 0)); // old rows → Sent
|
out.delivery = static_cast<ChatDelivery>(parsed.value("dl", 0)); // old rows → Sent (0)
|
||||||
|
// A persisted "Sending" means we crashed mid-broadcast; the outcome is unknown. Resolve it
|
||||||
|
// optimistically to Sent on load so it can't show a stuck spinner forever.
|
||||||
|
if (out.delivery == ChatDelivery::Sending) out.delivery = ChatDelivery::Sent;
|
||||||
return true;
|
return true;
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct sqlite3;
|
struct sqlite3;
|
||||||
@@ -43,14 +44,31 @@ public:
|
|||||||
// Returns true if newly inserted; false on duplicate or while locked.
|
// Returns true if newly inserted; false on duplicate or while locked.
|
||||||
bool append(const ChatMessage& message);
|
bool append(const ChatMessage& message);
|
||||||
|
|
||||||
|
// Persist-or-overwrite one message by its (txid+position) dedup key. Unlike append(), this
|
||||||
|
// updates an existing row's payload — used for outgoing echoes whose delivery status changes
|
||||||
|
// (Sending → Sent/Failed). Returns true on success; false while locked / on error.
|
||||||
|
bool upsert(const ChatMessage& message);
|
||||||
|
|
||||||
// Decrypt and return every stored message for the unlocked wallet, in insertion order. Empty
|
// Decrypt and return every stored message for the unlocked wallet, in insertion order. Empty
|
||||||
// while locked or if none. Rows that fail to decrypt/parse are skipped.
|
// while locked or if none. Rows that fail to decrypt/parse are skipped.
|
||||||
std::vector<ChatMessage> load();
|
std::vector<ChatMessage> load();
|
||||||
|
|
||||||
void clearWallet(); // delete the unlocked wallet's rows
|
void clearWallet(); // delete the unlocked wallet's rows
|
||||||
|
|
||||||
|
// Per-conversation local delete. Removes the given messages' rows; when `tombstone` is true it also
|
||||||
|
// records their (txid,position) dedup keys so a chain re-scan never re-imports them — this backs the
|
||||||
|
// "delete, but a NEW message revives the thread" path. With `tombstone` false the rows are simply
|
||||||
|
// removed (used by "delete & block", where a settings-level cid block suppresses re-import until the
|
||||||
|
// user unblocks, at which point the history re-imports from chain). Atomic; no-op while locked.
|
||||||
|
bool deleteMessages(const std::vector<ChatMessage>& messages, bool tombstone);
|
||||||
|
|
||||||
|
// True if this message's (txid,position) was locally deleted with a tombstone. Checked against an
|
||||||
|
// in-memory cache loaded on unlock — O(1), no SQL. False while locked.
|
||||||
|
bool isTombstoned(const ChatMessage& message) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool ensureOpen();
|
bool ensureOpen();
|
||||||
|
void loadTombstones(); // populate tombstones_ from chat_deleted for the unlocked wallet
|
||||||
bool exec(const char* sql);
|
bool exec(const char* sql);
|
||||||
bool createSchema();
|
bool createSchema();
|
||||||
std::string dedupHash(const std::string& txid, std::size_t position) const;
|
std::string dedupHash(const std::string& txid, std::size_t position) const;
|
||||||
@@ -69,6 +87,7 @@ private:
|
|||||||
std::array<unsigned char, 32> key_{}; // AEAD storage key (seed-derived)
|
std::array<unsigned char, 32> key_{}; // AEAD storage key (seed-derived)
|
||||||
std::string wallet_tag_; // seed-derived row partition (a keyed hash, hex)
|
std::string wallet_tag_; // seed-derived row partition (a keyed hash, hex)
|
||||||
bool key_ready_ = false;
|
bool key_ready_ = false;
|
||||||
|
std::unordered_set<std::string> tombstones_; // dedup_hash cache of locally-deleted messages
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dragonx::chat
|
} // namespace dragonx::chat
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ namespace dragonx::chat {
|
|||||||
|
|
||||||
enum class ChatDirection { Incoming, Outgoing };
|
enum class ChatDirection { Incoming, Outgoing };
|
||||||
enum class ChatMessageKind { Message, ContactRequest };
|
enum class ChatMessageKind { Message, ContactRequest };
|
||||||
// Outgoing delivery: Sent = the broadcast was submitted; Failed = it wasn't (not connected, no
|
// Outgoing delivery status. Sending = broadcast in flight (async op not yet resolved); Sent = the
|
||||||
// spendable address, a send already in progress). Always Sent for incoming.
|
// daemon accepted + broadcast the tx; Failed = it didn't (not connected, no funded address, rejected).
|
||||||
enum class ChatDelivery { Sent, Failed };
|
// Always Sent for incoming. NB: the values are persisted (chat DB serializes the int), so Sent MUST
|
||||||
|
// stay 0 and new states are APPENDED — never reordered.
|
||||||
|
enum class ChatDelivery { Sent, Failed, Sending };
|
||||||
|
|
||||||
struct ChatMessage {
|
struct ChatMessage {
|
||||||
ChatDirection direction = ChatDirection::Incoming;
|
ChatDirection direction = ChatDirection::Incoming;
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ std::string buildHeaderMemo(const std::string& replyZaddr,
|
|||||||
const std::string& conversationId,
|
const std::string& conversationId,
|
||||||
const char* type,
|
const char* type,
|
||||||
const std::string& streamHeaderHex,
|
const std::string& streamHeaderHex,
|
||||||
const std::string& publicKeyHex)
|
const std::string& publicKeyHex,
|
||||||
|
std::int64_t sentAt)
|
||||||
{
|
{
|
||||||
nlohmann::json header;
|
nlohmann::json header;
|
||||||
header["h"] = 1; // header number (>= 1)
|
header["h"] = 1; // header number (>= 1)
|
||||||
@@ -26,6 +27,7 @@ std::string buildHeaderMemo(const std::string& replyZaddr,
|
|||||||
header["t"] = type; // "Memo" or "Cont"
|
header["t"] = type; // "Memo" or "Cont"
|
||||||
header["e"] = streamHeaderHex; // 48-hex secretstream header (Memo) / "" (Cont)
|
header["e"] = streamHeaderHex; // 48-hex secretstream header (Memo) / "" (Cont)
|
||||||
header["p"] = publicKeyHex; // my 64-hex crypto_kx public key
|
header["p"] = publicKeyHex; // my 64-hex crypto_kx public key
|
||||||
|
if (sentAt > 0) header["ts"] = sentAt; // optional sender compose time (Unix s) — receiver shows this
|
||||||
return header.dump();
|
return header.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +69,8 @@ ChatComposeStatus buildOutgoingMessage(const ChatKeyPair& mine,
|
|||||||
|
|
||||||
OutgoingChatMemos memos;
|
OutgoingChatMemos memos;
|
||||||
memos.recipientZaddr = peerZaddr;
|
memos.recipientZaddr = peerZaddr;
|
||||||
memos.headerMemo = buildHeaderMemo(myReplyZaddr, conversationId, "Memo", streamHeaderHex, myPublicKeyHex);
|
memos.headerMemo = buildHeaderMemo(myReplyZaddr, conversationId, "Memo", streamHeaderHex, myPublicKeyHex,
|
||||||
|
static_cast<std::int64_t>(std::time(nullptr)));
|
||||||
memos.payloadMemo = ciphertextHex;
|
memos.payloadMemo = ciphertextHex;
|
||||||
if (memos.headerMemo.size() > kHushChatMemoByteLimit ||
|
if (memos.headerMemo.size() > kHushChatMemoByteLimit ||
|
||||||
memos.payloadMemo.size() > kHushChatMemoByteLimit) {
|
memos.payloadMemo.size() > kHushChatMemoByteLimit) {
|
||||||
@@ -95,7 +98,8 @@ ChatComposeStatus buildOutgoingContactRequest(const std::string& myPublicKeyHex,
|
|||||||
|
|
||||||
OutgoingChatMemos memos;
|
OutgoingChatMemos memos;
|
||||||
memos.recipientZaddr = peerZaddr;
|
memos.recipientZaddr = peerZaddr;
|
||||||
memos.headerMemo = buildHeaderMemo(myReplyZaddr, conversationId, "Cont", "", myPublicKeyHex);
|
memos.headerMemo = buildHeaderMemo(myReplyZaddr, conversationId, "Cont", "", myPublicKeyHex,
|
||||||
|
static_cast<std::int64_t>(std::time(nullptr)));
|
||||||
memos.payloadMemo = requestText;
|
memos.payloadMemo = requestText;
|
||||||
if (memos.headerMemo.size() > kHushChatMemoByteLimit ||
|
if (memos.headerMemo.size() > kHushChatMemoByteLimit ||
|
||||||
memos.payloadMemo.size() > kHushChatMemoByteLimit) {
|
memos.payloadMemo.size() > kHushChatMemoByteLimit) {
|
||||||
|
|||||||
@@ -124,6 +124,10 @@ HushChatHeaderParseResult parseHushChatHeaderMemo(const std::string& memo)
|
|||||||
if (!readRequiredString(object, "t", type, error)) return fail(error);
|
if (!readRequiredString(object, "t", type, error)) return fail(error);
|
||||||
if (!readRequiredString(object, "e", header.secretstream_header_hex, error)) return fail(error);
|
if (!readRequiredString(object, "e", header.secretstream_header_hex, error)) return fail(error);
|
||||||
if (!readRequiredString(object, "p", header.public_key_hex, error)) return fail(error);
|
if (!readRequiredString(object, "p", header.public_key_hex, error)) return fail(error);
|
||||||
|
// Optional sender compose time (Unix seconds). Absent on older senders — leave sent_at = 0 so the
|
||||||
|
// receiver falls back to the tx/receive time. Read leniently; never fail the header on a bad value.
|
||||||
|
if (auto it = object.find("ts"); it != object.end() && it->is_number_integer())
|
||||||
|
header.sent_at = it->get<std::int64_t>();
|
||||||
|
|
||||||
if (header.header_number < 1) return fail("header number must be positive");
|
if (header.header_number < 1) return fail("header number must be positive");
|
||||||
if (header.version != kHushChatSupportedVersion) return fail("unsupported HushChat version");
|
if (header.version != kHushChatSupportedVersion) return fail("unsupported HushChat version");
|
||||||
@@ -303,6 +307,7 @@ HushChatTransactionExtractionResult extractHushChatTransactionMetadata(
|
|||||||
metadata.sender_public_key_hex = pair.header.public_key_hex;
|
metadata.sender_public_key_hex = pair.header.public_key_hex;
|
||||||
metadata.secretstream_header_hex = pair.header.secretstream_header_hex;
|
metadata.secretstream_header_hex = pair.header.secretstream_header_hex;
|
||||||
metadata.payload_memo = pair.payload_memo;
|
metadata.payload_memo = pair.payload_memo;
|
||||||
|
metadata.sent_at = pair.header.sent_at; // carry the sender's compose time (0 if absent)
|
||||||
result.metadata.push_back(std::move(metadata));
|
result.metadata.push_back(std::move(metadata));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ struct HushChatHeader {
|
|||||||
HushChatHeaderType type = HushChatHeaderType::Message;
|
HushChatHeaderType type = HushChatHeaderType::Message;
|
||||||
std::string secretstream_header_hex;
|
std::string secretstream_header_hex;
|
||||||
std::string public_key_hex;
|
std::string public_key_hex;
|
||||||
|
// Optional sender-stamped compose time (header "ts", Unix seconds). 0 = absent (older sender) → the
|
||||||
|
// receiver falls back to the tx/receive time. Lets both sides show the SAME (send) time.
|
||||||
|
std::int64_t sent_at = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HushChatHeaderParseResult {
|
struct HushChatHeaderParseResult {
|
||||||
@@ -80,6 +83,7 @@ struct HushChatTransactionMetadata {
|
|||||||
std::string sender_public_key_hex; // header "p": peer crypto_kx public key (hex)
|
std::string sender_public_key_hex; // header "p": peer crypto_kx public key (hex)
|
||||||
std::string secretstream_header_hex; // header "e": secretstream header (hex; empty for ContactRequest)
|
std::string secretstream_header_hex; // header "e": secretstream header (hex; empty for ContactRequest)
|
||||||
std::string payload_memo; // ciphertext hex (Message) or plaintext request text (ContactRequest)
|
std::string payload_memo; // ciphertext hex (Message) or plaintext request text (ContactRequest)
|
||||||
|
std::int64_t sent_at = 0; // header "ts": sender compose time (Unix s); 0 = absent → use tx time
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HushChatTransactionExtractionResult {
|
struct HushChatTransactionExtractionResult {
|
||||||
|
|||||||
@@ -25,21 +25,54 @@ void ChatService::clearIdentity() {
|
|||||||
|
|
||||||
int ChatService::ingest(const std::vector<HushChatTransactionMetadata>& metadata,
|
int ChatService::ingest(const std::vector<HushChatTransactionMetadata>& metadata,
|
||||||
const std::unordered_map<std::string, std::int64_t>& txTimestamps,
|
const std::unordered_map<std::string, std::int64_t>& txTimestamps,
|
||||||
std::int64_t fallbackTimestamp) {
|
std::int64_t fallbackTimestamp,
|
||||||
|
std::vector<std::string>* newIncomingCids) {
|
||||||
if (!has_identity_) return 0;
|
if (!has_identity_) return 0;
|
||||||
|
// Persistence is attached but not unlocked (e.g. the DB failed to open with the seed): we can't
|
||||||
|
// consult tombstones, so ingesting now would resurface locally-deleted messages into the store.
|
||||||
|
// Skip until the DB is usable — chat is degraded anyway without its store.
|
||||||
|
if (db_ && !db_->hasKey()) return 0;
|
||||||
|
|
||||||
|
const std::string myPubKey = chatIdentityPublicKeyHex(identity_);
|
||||||
|
|
||||||
int added = 0;
|
int added = 0;
|
||||||
for (const auto& meta : metadata) {
|
for (const auto& meta : metadata) {
|
||||||
|
// A memo whose sender is our OWN identity is something we sent (only we hold our key). The local
|
||||||
|
// echo already records it as outgoing — ingesting it as incoming would duplicate it as a phantom
|
||||||
|
// "from peer" message. (This also collapses same-seed self-chat, where the "peer" wallet shares
|
||||||
|
// our identity, so every message would otherwise loop back.)
|
||||||
|
if (!myPubKey.empty() && meta.sender_public_key_hex == myPubKey) continue;
|
||||||
|
|
||||||
ChatMessage message;
|
ChatMessage message;
|
||||||
message.direction = ChatDirection::Incoming;
|
message.direction = ChatDirection::Incoming;
|
||||||
message.txid = meta.txid;
|
message.txid = meta.txid;
|
||||||
message.conversation_id = meta.conversation_id;
|
message.conversation_id = meta.conversation_id;
|
||||||
message.peer_zaddr = meta.reply_zaddr;
|
message.peer_zaddr = meta.reply_zaddr;
|
||||||
message.peer_public_key_hex = meta.sender_public_key_hex;
|
message.peer_public_key_hex = meta.sender_public_key_hex;
|
||||||
|
// Reference time: the tx/receive time (block time if confirmed, else the receiver's wall clock for
|
||||||
|
// a mempool receive).
|
||||||
const auto timeIt = txTimestamps.find(meta.txid);
|
const auto timeIt = txTimestamps.find(meta.txid);
|
||||||
message.timestamp = timeIt != txTimestamps.end() ? timeIt->second : fallbackTimestamp;
|
const std::int64_t refTime = timeIt != txTimestamps.end() ? timeIt->second : fallbackTimestamp;
|
||||||
|
// Prefer the sender's stamped compose time (header "ts") — the true send time, shown identically on
|
||||||
|
// both ends. But REJECT a value implausibly in the FUTURE vs the reference: a wrong/ahead peer clock
|
||||||
|
// would otherwise pin their messages to the bottom of the thread forever. A compose time in the
|
||||||
|
// PAST is fine — the note buffer can broadcast a queued message long after it was composed, and a
|
||||||
|
// confirmed tx's block time is always >= the compose time.
|
||||||
|
constexpr std::int64_t kSenderTsFutureToleranceSec = 3600; // 1 hour of clock skew tolerated
|
||||||
|
if (meta.sent_at > 0 && (refTime <= 0 || meta.sent_at <= refTime + kSenderTsFutureToleranceSec)) {
|
||||||
|
message.timestamp = meta.sent_at;
|
||||||
|
} else {
|
||||||
|
message.timestamp = refTime;
|
||||||
|
}
|
||||||
message.payload_position = meta.payload_position;
|
message.payload_position = meta.payload_position;
|
||||||
|
|
||||||
|
// Suppress locally-removed conversations before the (relatively costly) decrypt. A blocked cid
|
||||||
|
// is dropped outright (old + future messages) until unblocked; a tombstoned (txid,position) was
|
||||||
|
// deleted with "revive on new message", so only that exact message is skipped — a new message
|
||||||
|
// in the same conversation has a different txid and flows through normally.
|
||||||
|
if (blocked_pred_ && blocked_pred_(message.conversation_id)) continue;
|
||||||
|
if (db_ && db_->isTombstoned(message)) continue;
|
||||||
|
|
||||||
if (meta.type == HushChatHeaderType::ContactRequest) {
|
if (meta.type == HushChatHeaderType::ContactRequest) {
|
||||||
message.kind = ChatMessageKind::ContactRequest;
|
message.kind = ChatMessageKind::ContactRequest;
|
||||||
message.body = meta.payload_memo; // plaintext request text
|
message.body = meta.payload_memo; // plaintext request text
|
||||||
@@ -59,6 +92,9 @@ int ChatService::ingest(const std::vector<HushChatTransactionMetadata>& metadata
|
|||||||
if (store_.append(message)) {
|
if (store_.append(message)) {
|
||||||
if (db_) db_->append(message);
|
if (db_) db_->append(message);
|
||||||
++added;
|
++added;
|
||||||
|
// Every ingested message is incoming — report its cid so the caller can notify without
|
||||||
|
// relying on a seen-watermark delta (which block-time vs wall-clock skew can swallow).
|
||||||
|
if (newIncomingCids) newIncomingCids->push_back(message.conversation_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return added;
|
return added;
|
||||||
@@ -67,10 +103,28 @@ int ChatService::ingest(const std::vector<HushChatTransactionMetadata>& metadata
|
|||||||
void ChatService::loadFromDatabase() {
|
void ChatService::loadFromDatabase() {
|
||||||
if (!db_) return;
|
if (!db_) return;
|
||||||
for (const auto& message : db_->load()) {
|
for (const auto& message : db_->load()) {
|
||||||
|
// Never surface a blocked conversation, even if a prior "delete & block" failed to remove its
|
||||||
|
// rows (defense-in-depth): the ingest guard already drops live scans, this covers the reload path.
|
||||||
|
if (blocked_pred_ && blocked_pred_(message.conversation_id)) continue;
|
||||||
store_.append(message);
|
store_.append(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChatService::deleteConversation(const std::string& conversationId, bool block) {
|
||||||
|
// Delete the persisted rows FIRST and only mutate the in-memory view if that succeeds. Doing it the
|
||||||
|
// other way round means a failed DB write (disk full / locked) would empty the store while the rows
|
||||||
|
// survive — and on the next reload the conversation silently reappears with no tombstone.
|
||||||
|
// Revive-on-new-message => tombstone the removed rows so a re-scan won't re-import them.
|
||||||
|
// Block => remove the rows without a tombstone; the caller's blocked predicate suppresses re-import
|
||||||
|
// until unblocked, at which point the conversation re-imports from chain.
|
||||||
|
if (db_) {
|
||||||
|
std::vector<ChatMessage> msgs = store_.conversation(conversationId); // snapshot (copy)
|
||||||
|
if (!db_->deleteMessages(msgs, /*tombstone=*/!block)) return false;
|
||||||
|
}
|
||||||
|
store_.eraseConversation(conversationId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::string ChatService::identityPublicKeyHex() const {
|
std::string ChatService::identityPublicKeyHex() const {
|
||||||
if (!has_identity_) return {};
|
if (!has_identity_) return {};
|
||||||
return chatIdentityPublicKeyHex(identity_);
|
return chatIdentityPublicKeyHex(identity_);
|
||||||
@@ -105,4 +159,18 @@ bool ChatService::recordOutgoing(const ChatMessage& message) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChatService::recordOutgoingPending(const ChatMessage& message) {
|
||||||
|
// Persist immediately (as Sending) so a send survives an app quit before the broadcast resolves;
|
||||||
|
// resolveOutgoing() then UPSERTS the row to the final status. A stray persisted Sending (crash mid-
|
||||||
|
// broadcast) loads as Sent (see ChatDatabase::deserialize).
|
||||||
|
const bool appended = store_.append(message);
|
||||||
|
if (appended && db_) db_->upsert(message);
|
||||||
|
return appended;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatService::resolveOutgoing(const std::string& txid, ChatDelivery delivery) {
|
||||||
|
const ChatMessage* updated = store_.updateDelivery(txid, delivery);
|
||||||
|
if (updated && db_) db_->upsert(*updated); // overwrite the Sending row with the final status
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dragonx::chat
|
} // namespace dragonx::chat
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "chat_store.h"
|
#include "chat_store.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -40,9 +41,13 @@ public:
|
|||||||
// when the txid isn't present. Newly-added messages are also persisted (if a database is
|
// when the txid isn't present. Newly-added messages are also persisted (if a database is
|
||||||
// attached). Returns the number of NEW messages added; 0 with no identity. Undecryptable
|
// attached). Returns the number of NEW messages added; 0 with no identity. Undecryptable
|
||||||
// Messages are dropped silently (no logging of memo/plaintext).
|
// Messages are dropped silently (no logging of memo/plaintext).
|
||||||
|
// When `newIncomingCids` is non-null it is filled with the conversation ids of the genuinely-new
|
||||||
|
// incoming (non-request) messages appended this call — a reliable "a new message arrived here"
|
||||||
|
// signal for notifications that doesn't depend on any timestamp/seen-watermark comparison.
|
||||||
int ingest(const std::vector<HushChatTransactionMetadata>& metadata,
|
int ingest(const std::vector<HushChatTransactionMetadata>& metadata,
|
||||||
const std::unordered_map<std::string, std::int64_t>& txTimestamps,
|
const std::unordered_map<std::string, std::int64_t>& txTimestamps,
|
||||||
std::int64_t fallbackTimestamp = 0);
|
std::int64_t fallbackTimestamp = 0,
|
||||||
|
std::vector<std::string>* newIncomingCids = nullptr);
|
||||||
|
|
||||||
// Attach a persistent backing store (Phase 2). Not owned. Pass nullptr to detach. New messages
|
// Attach a persistent backing store (Phase 2). Not owned. Pass nullptr to detach. New messages
|
||||||
// from ingest() are written through; loadFromDatabase() rehydrates the in-memory store from it.
|
// from ingest() are written through; loadFromDatabase() rehydrates the in-memory store from it.
|
||||||
@@ -51,6 +56,19 @@ public:
|
|||||||
// the seed-derived key) into the in-memory store. No-op without an unlocked database.
|
// the seed-derived key) into the in-memory store. No-op without an unlocked database.
|
||||||
void loadFromDatabase();
|
void loadFromDatabase();
|
||||||
|
|
||||||
|
// Set a predicate returning true for a BLOCKED conversation id. ingest() drops those messages
|
||||||
|
// entirely (they are never stored or persisted) until the predicate stops returning true — this is
|
||||||
|
// how "delete & block" suppresses old and future messages. Typically wired to Settings::isChatBlocked.
|
||||||
|
void setBlockedPredicate(std::function<bool(const std::string&)> pred) { blocked_pred_ = std::move(pred); }
|
||||||
|
|
||||||
|
// Locally delete a conversation: remove its messages from the store and the database. When `block`
|
||||||
|
// is false, the removed messages are tombstoned so a chain re-scan won't re-import them, but a
|
||||||
|
// genuinely NEW message (new txid) revives the thread. When `block` is true, the rows are removed
|
||||||
|
// WITHOUT a tombstone (the caller also records the cid as blocked via the predicate above); unblocking
|
||||||
|
// later lets the conversation re-import from chain. Returns false (leaving the store untouched) if the
|
||||||
|
// persisted rows couldn't be removed, so the caller can avoid a store/DB divergence.
|
||||||
|
bool deleteConversation(const std::string& conversationId, bool block);
|
||||||
|
|
||||||
// --- Outgoing (compose) ---
|
// --- Outgoing (compose) ---
|
||||||
// My chat public key (hex), or "" without an identity — goes in an outgoing header's "p".
|
// My chat public key (hex), or "" without an identity — goes in an outgoing header's "p".
|
||||||
std::string identityPublicKeyHex() const;
|
std::string identityPublicKeyHex() const;
|
||||||
@@ -72,6 +90,12 @@ public:
|
|||||||
// only local record of what we sent.)
|
// only local record of what we sent.)
|
||||||
bool recordOutgoing(const ChatMessage& message);
|
bool recordOutgoing(const ChatMessage& message);
|
||||||
|
|
||||||
|
// Two-phase echo for delivery tracking: record + persist immediately as Sending (survives an app
|
||||||
|
// quit), then resolveOutgoing() upserts the final status once the broadcast completes. A stray
|
||||||
|
// persisted Sending (crash mid-broadcast) loads back as Sent.
|
||||||
|
bool recordOutgoingPending(const ChatMessage& message);
|
||||||
|
void resolveOutgoing(const std::string& txid, ChatDelivery delivery);
|
||||||
|
|
||||||
const ChatStore& store() const { return store_; }
|
const ChatStore& store() const { return store_; }
|
||||||
ChatStore& store() { return store_; }
|
ChatStore& store() { return store_; }
|
||||||
|
|
||||||
@@ -80,6 +104,7 @@ private:
|
|||||||
bool has_identity_ = false;
|
bool has_identity_ = false;
|
||||||
ChatStore store_;
|
ChatStore store_;
|
||||||
ChatDatabase* db_ = nullptr; // optional; not owned
|
ChatDatabase* db_ = nullptr; // optional; not owned
|
||||||
|
std::function<bool(const std::string&)> blocked_pred_; // true => cid is blocked (drop its messages)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dragonx::chat
|
} // namespace dragonx::chat
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "chat_store.h"
|
#include "chat_store.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace dragonx::chat {
|
namespace dragonx::chat {
|
||||||
|
|
||||||
std::string ChatStore::dedupKey(const ChatMessage& message) {
|
std::string ChatStore::dedupKey(const ChatMessage& message) {
|
||||||
@@ -11,6 +13,7 @@ std::string ChatStore::dedupKey(const ChatMessage& message) {
|
|||||||
bool ChatStore::append(const ChatMessage& message) {
|
bool ChatStore::append(const ChatMessage& message) {
|
||||||
if (!seen_.insert(dedupKey(message)).second) return false;
|
if (!seen_.insert(dedupKey(message)).second) return false;
|
||||||
messages_.push_back(message);
|
messages_.push_back(message);
|
||||||
|
++revision_;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,9 +22,41 @@ std::vector<ChatMessage> ChatStore::conversation(const std::string& conversation
|
|||||||
for (const auto& message : messages_) {
|
for (const auto& message : messages_) {
|
||||||
if (message.conversation_id == conversationId) out.push_back(message);
|
if (message.conversation_id == conversationId) out.push_back(message);
|
||||||
}
|
}
|
||||||
|
// Return chronological (oldest→newest). messages_ is in scan/insertion order, which is NOT
|
||||||
|
// time-ordered (a full scan harvests txids in std::set/unordered_map order) — that would mis-order the
|
||||||
|
// rendered thread AND let the reply-target pin (first-seen peer address) latch onto a non-establishing
|
||||||
|
// message (B2). timestamp is the block/tx time (peer can't set it); tie-break txid + payload_position
|
||||||
|
// for determinism.
|
||||||
|
std::stable_sort(out.begin(), out.end(), [](const ChatMessage& a, const ChatMessage& b) {
|
||||||
|
if (a.timestamp != b.timestamp) return a.timestamp < b.timestamp;
|
||||||
|
if (a.txid != b.txid) return a.txid < b.txid;
|
||||||
|
return a.payload_position < b.payload_position;
|
||||||
|
});
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ChatMessage* ChatStore::updateDelivery(const std::string& txid, ChatDelivery delivery) {
|
||||||
|
for (auto& message : messages_) {
|
||||||
|
if (message.txid == txid) {
|
||||||
|
message.delivery = delivery;
|
||||||
|
++revision_;
|
||||||
|
return &message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ChatStore::countUnread(const std::function<bool(const std::string&)>& excluded,
|
||||||
|
const std::function<std::int64_t(const std::string&)>& seenFor) const {
|
||||||
|
int unread = 0;
|
||||||
|
for (const auto& m : messages_) {
|
||||||
|
if (m.direction != ChatDirection::Incoming) continue;
|
||||||
|
if (excluded && excluded(m.conversation_id)) continue;
|
||||||
|
if (m.timestamp > seenFor(m.conversation_id)) ++unread;
|
||||||
|
}
|
||||||
|
return unread;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> ChatStore::conversationIds() const {
|
std::vector<std::string> ChatStore::conversationIds() const {
|
||||||
std::vector<std::string> ids;
|
std::vector<std::string> ids;
|
||||||
std::unordered_set<std::string> seenIds;
|
std::unordered_set<std::string> seenIds;
|
||||||
@@ -31,9 +66,27 @@ std::vector<std::string> ChatStore::conversationIds() const {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<ChatMessage> ChatStore::eraseConversation(const std::string& conversationId) {
|
||||||
|
std::vector<ChatMessage> removed;
|
||||||
|
std::vector<ChatMessage> kept;
|
||||||
|
kept.reserve(messages_.size());
|
||||||
|
for (auto& m : messages_) {
|
||||||
|
if (m.conversation_id == conversationId) {
|
||||||
|
seen_.erase(dedupKey(m));
|
||||||
|
removed.push_back(std::move(m));
|
||||||
|
} else {
|
||||||
|
kept.push_back(std::move(m));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
messages_.swap(kept);
|
||||||
|
if (!removed.empty()) ++revision_;
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
void ChatStore::clear() {
|
void ChatStore::clear() {
|
||||||
messages_.clear();
|
messages_.clear();
|
||||||
seen_.clear();
|
seen_.clear();
|
||||||
|
++revision_;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dragonx::chat
|
} // namespace dragonx::chat
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "chat_message.h"
|
#include "chat_message.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -21,18 +23,49 @@ public:
|
|||||||
// Messages in a conversation, in insertion order.
|
// Messages in a conversation, in insertion order.
|
||||||
std::vector<ChatMessage> conversation(const std::string& conversationId) const;
|
std::vector<ChatMessage> conversation(const std::string& conversationId) const;
|
||||||
|
|
||||||
|
// Update an outgoing echo's delivery status by its local txid. Returns a pointer to the updated
|
||||||
|
// message (for the caller to persist), or nullptr if no message has that txid.
|
||||||
|
const ChatMessage* updateDelivery(const std::string& txid, ChatDelivery delivery);
|
||||||
|
|
||||||
// Distinct conversation ids, in first-seen order.
|
// Distinct conversation ids, in first-seen order.
|
||||||
std::vector<std::string> conversationIds() const;
|
std::vector<std::string> conversationIds() const;
|
||||||
|
|
||||||
|
// The set of on-chain txids that carried a chat message (sent or received, messages + contact
|
||||||
|
// requests) — used by the History tab to badge / filter chat transactions. O(messages), no copies.
|
||||||
|
std::unordered_set<std::string> chatTxids() const {
|
||||||
|
std::unordered_set<std::string> out;
|
||||||
|
out.reserve(messages_.size());
|
||||||
|
for (const auto& m : messages_)
|
||||||
|
if (!m.txid.empty()) out.insert(m.txid);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove every message in a conversation from the in-memory view and return the removed messages
|
||||||
|
// (so the caller can delete/tombstone their persisted rows). Re-appends are prevented by the ingest
|
||||||
|
// guard (blocked-cid predicate / DB tombstone), not here.
|
||||||
|
std::vector<ChatMessage> eraseConversation(const std::string& conversationId);
|
||||||
|
|
||||||
std::size_t size() const { return messages_.size(); }
|
std::size_t size() const { return messages_.size(); }
|
||||||
bool empty() const { return messages_.empty(); }
|
bool empty() const { return messages_.empty(); }
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
// Monotonic counter bumped on every mutation (append / updateDelivery change / eraseConversation /
|
||||||
|
// clear). Callers memoize expensive per-frame reads (conversation-list build, unread count) against it
|
||||||
|
// so they only rebuild when the store actually changed.
|
||||||
|
std::uint64_t revision() const { return revision_; }
|
||||||
|
|
||||||
|
// Count unread incoming messages in a SINGLE pass over the store: an incoming message counts when its
|
||||||
|
// cid is not `excluded` and its timestamp is newer than `seenFor(cid)`. Avoids the per-conversation
|
||||||
|
// copy+sort that conversation() does — the count doesn't need ordering.
|
||||||
|
int countUnread(const std::function<bool(const std::string&)>& excluded,
|
||||||
|
const std::function<std::int64_t(const std::string&)>& seenFor) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::string dedupKey(const ChatMessage& message);
|
static std::string dedupKey(const ChatMessage& message);
|
||||||
|
|
||||||
std::vector<ChatMessage> messages_;
|
std::vector<ChatMessage> messages_;
|
||||||
std::unordered_set<std::string> seen_;
|
std::unordered_set<std::string> seen_;
|
||||||
|
std::uint64_t revision_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dragonx::chat
|
} // namespace dragonx::chat
|
||||||
|
|||||||
@@ -108,6 +108,20 @@ void loadClamped(const json& j, const char* key, T& field, T lo, T hi)
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
std::vector<Settings::LiteServerPreference> Settings::defaultLiteServers()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
{"https://lite.dragonx.is", "DragonX Lite", true},
|
||||||
|
{"https://lite1.dragonx.is", "DragonX Lite 1", true},
|
||||||
|
{"https://lite2.dragonx.is", "DragonX Lite 2", true},
|
||||||
|
{"https://lite3.dragonx.is", "DragonX Lite 3", true},
|
||||||
|
{"https://lite4.dragonx.is", "DragonX Lite 4", true},
|
||||||
|
{"https://lite5.dragonx.is", "DragonX Lite 5", true},
|
||||||
|
{"https://lite6.dragonx.is", "DragonX Lite 6", true},
|
||||||
|
{"https://lite7.dragonx.is", "DragonX Lite 7", true}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
std::string Settings::getDefaultPath()
|
std::string Settings::getDefaultPath()
|
||||||
{
|
{
|
||||||
// Single per-platform, per-variant config dir (util::Platform::getConfigDir handles the
|
// Single per-platform, per-variant config dir (util::Platform::getConfigDir handles the
|
||||||
@@ -147,6 +161,33 @@ bool Settings::load(const std::string& path)
|
|||||||
loadScalar(j, "language", language_);
|
loadScalar(j, "language", language_);
|
||||||
loadScalar(j, "skin_id", skin_id_);
|
loadScalar(j, "skin_id", skin_id_);
|
||||||
loadScalar(j, "chat_reply_zaddr", chat_reply_zaddr_);
|
loadScalar(j, "chat_reply_zaddr", chat_reply_zaddr_);
|
||||||
|
if (j.contains("muted_chat_cids") && j["muted_chat_cids"].is_array()) {
|
||||||
|
muted_chat_cids_.clear();
|
||||||
|
for (const auto& c : j["muted_chat_cids"])
|
||||||
|
if (c.is_string()) muted_chat_cids_.push_back(c.get<std::string>());
|
||||||
|
}
|
||||||
|
if (j.contains("hidden_chat_cids") && j["hidden_chat_cids"].is_array()) {
|
||||||
|
hidden_chat_cids_.clear();
|
||||||
|
for (const auto& c : j["hidden_chat_cids"])
|
||||||
|
if (c.is_string()) hidden_chat_cids_.push_back(c.get<std::string>());
|
||||||
|
}
|
||||||
|
if (j.contains("blocked_chat_convs") && j["blocked_chat_convs"].is_array()) {
|
||||||
|
blocked_chat_convs_.clear();
|
||||||
|
for (const auto& c : j["blocked_chat_convs"])
|
||||||
|
if (c.is_object() && c.contains("cid") && c["cid"].is_string())
|
||||||
|
blocked_chat_convs_.push_back({c["cid"].get<std::string>(),
|
||||||
|
c.value("name", std::string())});
|
||||||
|
}
|
||||||
|
// Chat-tab customization (re-clamped through the setters so hand-edited JSON stays in range).
|
||||||
|
loadScalar(j, "chat_emoji_color", chat_emoji_color_);
|
||||||
|
loadScalar(j, "chat_poll_rate_sec", chat_poll_rate_sec_); setChatPollRateSec(chat_poll_rate_sec_);
|
||||||
|
loadScalar(j, "chat_bubble_style", chat_bubble_style_); setChatBubbleStyle(chat_bubble_style_);
|
||||||
|
loadScalar(j, "chat_bubble_accent", chat_bubble_accent_); setChatBubbleAccent(chat_bubble_accent_);
|
||||||
|
loadScalar(j, "chat_density", chat_density_); setChatDensity(chat_density_);
|
||||||
|
loadScalar(j, "chat_font_scale", chat_font_scale_); setChatFontScale(chat_font_scale_);
|
||||||
|
loadScalar(j, "chat_time_format", chat_time_format_); setChatTimeFormat(chat_time_format_);
|
||||||
|
loadScalar(j, "chat_enter_sends", chat_enter_sends_);
|
||||||
|
loadScalar(j, "time_format", time_format_); setTimeFormat(time_format_);
|
||||||
loadScalar(j, "acrylic_enabled", acrylic_enabled_);
|
loadScalar(j, "acrylic_enabled", acrylic_enabled_);
|
||||||
loadScalar(j, "acrylic_quality", acrylic_quality_);
|
loadScalar(j, "acrylic_quality", acrylic_quality_);
|
||||||
loadScalar(j, "blur_multiplier", blur_multiplier_);
|
loadScalar(j, "blur_multiplier", blur_multiplier_);
|
||||||
@@ -176,12 +217,15 @@ bool Settings::load(const std::string& path)
|
|||||||
if (portfolio_style_ < 0 || portfolio_style_ > 2) portfolio_style_ = 0;
|
if (portfolio_style_ < 0 || portfolio_style_ > 2) portfolio_style_ = 0;
|
||||||
loadScalar(j, "contacts_view_mode", contacts_view_mode_);
|
loadScalar(j, "contacts_view_mode", contacts_view_mode_);
|
||||||
if (contacts_view_mode_ < 0 || contacts_view_mode_ > 2) contacts_view_mode_ = 0;
|
if (contacts_view_mode_ < 0 || contacts_view_mode_ > 2) contacts_view_mode_ = 0;
|
||||||
|
loadScalar(j, "contacts_avatar_shape", contacts_avatar_shape_); setContactsAvatarShape(contacts_avatar_shape_);
|
||||||
|
loadScalar(j, "contacts_list_scale", contacts_list_scale_); setContactsListScale(contacts_list_scale_);
|
||||||
loadScalar(j, "animate_avatars", animate_avatars_);
|
loadScalar(j, "animate_avatars", animate_avatars_);
|
||||||
loadScalar(j, "scanline_enabled", scanline_enabled_);
|
loadScalar(j, "scanline_enabled", scanline_enabled_);
|
||||||
loadScalar(j, "console_line_accents", console_line_accents_);
|
loadScalar(j, "console_line_accents", console_line_accents_);
|
||||||
loadScalar(j, "console_text_color", console_text_color_);
|
loadScalar(j, "console_text_color", console_text_color_);
|
||||||
loadScalar(j, "console_zoom", console_zoom_);
|
loadScalar(j, "console_zoom", console_zoom_);
|
||||||
if (!(console_zoom_ >= 0.25f && console_zoom_ <= 4.0f)) console_zoom_ = 1.0f; // guard bad/NaN
|
if (!(console_zoom_ >= 0.25f && console_zoom_ <= 4.0f)) console_zoom_ = 1.0f; // guard bad/NaN
|
||||||
|
loadScalar(j, "console_auto_focus", console_auto_focus_);
|
||||||
if (j.contains("hidden_addresses") && j["hidden_addresses"].is_array()) {
|
if (j.contains("hidden_addresses") && j["hidden_addresses"].is_array()) {
|
||||||
hidden_addresses_.clear();
|
hidden_addresses_.clear();
|
||||||
for (const auto& a : j["hidden_addresses"])
|
for (const auto& a : j["hidden_addresses"])
|
||||||
@@ -209,18 +253,28 @@ bool Settings::load(const std::string& path)
|
|||||||
}
|
}
|
||||||
loadScalar(j, "wizard_completed", wizard_completed_);
|
loadScalar(j, "wizard_completed", wizard_completed_);
|
||||||
loadScalar(j, "seed_backup_reminded", seed_backup_reminded_);
|
loadScalar(j, "seed_backup_reminded", seed_backup_reminded_);
|
||||||
|
loadScalar(j, "large_wallet_warned", large_wallet_warned_);
|
||||||
|
if (j.contains("empty_wallet_warning_acked") && j["empty_wallet_warning_acked"].is_array()) {
|
||||||
|
empty_wallet_warning_acked_.clear();
|
||||||
|
for (const auto& w : j["empty_wallet_warning_acked"])
|
||||||
|
if (w.is_string()) empty_wallet_warning_acked_.insert(w.get<std::string>());
|
||||||
|
}
|
||||||
|
loadScalar(j, "encryption_pending", encryption_pending_);
|
||||||
loadScalar(j, "daemon_update_prompted_size", daemon_update_prompted_size_);
|
loadScalar(j, "daemon_update_prompted_size", daemon_update_prompted_size_);
|
||||||
loadScalar(j, "active_wallet_file", active_wallet_file_);
|
loadScalar(j, "active_wallet_file", active_wallet_file_);
|
||||||
loadScalar(j, "seed_migration_pending", seed_migration_pending_);
|
loadScalar(j, "seed_migration_pending", seed_migration_pending_);
|
||||||
loadScalar(j, "seed_migration_dest", seed_migration_dest_);
|
loadScalar(j, "seed_migration_dest", seed_migration_dest_);
|
||||||
loadScalar(j, "seed_migration_temp_dir", seed_migration_temp_dir_);
|
loadScalar(j, "seed_migration_temp_dir", seed_migration_temp_dir_);
|
||||||
loadScalar(j, "seed_migration_sweep_txid", seed_migration_sweep_txid_);
|
loadScalar(j, "seed_migration_sweep_txid", seed_migration_sweep_txid_);
|
||||||
|
loadScalar(j, "seed_migration_sweep_opid", seed_migration_sweep_opid_);
|
||||||
loadScalar(j, "auto_lock_timeout", auto_lock_timeout_);
|
loadScalar(j, "auto_lock_timeout", auto_lock_timeout_);
|
||||||
loadScalar(j, "unlock_duration", unlock_duration_);
|
loadScalar(j, "unlock_duration", unlock_duration_);
|
||||||
loadScalar(j, "pin_enabled", pin_enabled_);
|
loadScalar(j, "pin_enabled", pin_enabled_);
|
||||||
loadScalar(j, "keep_daemon_running", keep_daemon_running_);
|
loadScalar(j, "keep_daemon_running", keep_daemon_running_);
|
||||||
loadScalar(j, "stop_external_daemon", stop_external_daemon_);
|
loadScalar(j, "stop_external_daemon", stop_external_daemon_);
|
||||||
loadScalar(j, "max_connections", max_connections_);
|
loadScalar(j, "max_connections", max_connections_);
|
||||||
|
loadScalar(j, "stratum_host_enabled", stratum_host_enabled_);
|
||||||
|
loadScalar(j, "stratum_allowip", stratum_allowip_);
|
||||||
if (j.contains("lite_wallet") && j["lite_wallet"].is_object()) {
|
if (j.contains("lite_wallet") && j["lite_wallet"].is_object()) {
|
||||||
const auto& lite = j["lite_wallet"];
|
const auto& lite = j["lite_wallet"];
|
||||||
if (lite.contains("server_selection_mode")) {
|
if (lite.contains("server_selection_mode")) {
|
||||||
@@ -267,6 +321,16 @@ bool Settings::load(const std::string& path)
|
|||||||
}
|
}
|
||||||
lite_servers_.push_back(preference);
|
lite_servers_.push_back(preference);
|
||||||
}
|
}
|
||||||
|
// Surface newly-shipped default servers (e.g. lite6/lite7) on an existing
|
||||||
|
// install whose saved list predates them. Servers are hidden (see
|
||||||
|
// lite_hidden_servers_), never deleted, so appending a missing default won't
|
||||||
|
// resurrect one the user intentionally removed.
|
||||||
|
for (const auto& def : defaultLiteServers()) {
|
||||||
|
bool present = false;
|
||||||
|
for (const auto& s : lite_servers_)
|
||||||
|
if (s.url == def.url) { present = true; break; }
|
||||||
|
if (!present) lite_servers_.push_back(def);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (lite.contains("rollout_override") && lite["rollout_override"].is_string()) {
|
if (lite.contains("rollout_override") && lite["rollout_override"].is_string()) {
|
||||||
const auto v = lite["rollout_override"].get<std::string>();
|
const auto v = lite["rollout_override"].get<std::string>();
|
||||||
@@ -422,6 +486,28 @@ bool Settings::save(const std::string& path)
|
|||||||
j["language"] = language_;
|
j["language"] = language_;
|
||||||
j["skin_id"] = skin_id_;
|
j["skin_id"] = skin_id_;
|
||||||
j["chat_reply_zaddr"] = chat_reply_zaddr_;
|
j["chat_reply_zaddr"] = chat_reply_zaddr_;
|
||||||
|
j["muted_chat_cids"] = json::array();
|
||||||
|
for (const auto& c : muted_chat_cids_)
|
||||||
|
j["muted_chat_cids"].push_back(c);
|
||||||
|
j["hidden_chat_cids"] = json::array();
|
||||||
|
for (const auto& c : hidden_chat_cids_)
|
||||||
|
j["hidden_chat_cids"].push_back(c);
|
||||||
|
j["blocked_chat_convs"] = json::array();
|
||||||
|
for (const auto& b : blocked_chat_convs_) {
|
||||||
|
json o;
|
||||||
|
o["cid"] = b.cid;
|
||||||
|
o["name"] = b.name;
|
||||||
|
j["blocked_chat_convs"].push_back(o);
|
||||||
|
}
|
||||||
|
j["chat_emoji_color"] = chat_emoji_color_;
|
||||||
|
j["chat_poll_rate_sec"] = chat_poll_rate_sec_;
|
||||||
|
j["chat_bubble_style"] = chat_bubble_style_;
|
||||||
|
j["chat_bubble_accent"] = chat_bubble_accent_;
|
||||||
|
j["chat_density"] = chat_density_;
|
||||||
|
j["chat_font_scale"] = chat_font_scale_;
|
||||||
|
j["chat_time_format"] = chat_time_format_;
|
||||||
|
j["chat_enter_sends"] = chat_enter_sends_;
|
||||||
|
j["time_format"] = time_format_;
|
||||||
j["acrylic_enabled"] = acrylic_enabled_;
|
j["acrylic_enabled"] = acrylic_enabled_;
|
||||||
j["acrylic_quality"] = acrylic_quality_;
|
j["acrylic_quality"] = acrylic_quality_;
|
||||||
j["blur_multiplier"] = blur_multiplier_;
|
j["blur_multiplier"] = blur_multiplier_;
|
||||||
@@ -432,11 +518,14 @@ bool Settings::save(const std::string& path)
|
|||||||
j["balance_layout"] = balance_layout_; // saved as string ID
|
j["balance_layout"] = balance_layout_; // saved as string ID
|
||||||
j["portfolio_style"] = portfolio_style_;
|
j["portfolio_style"] = portfolio_style_;
|
||||||
j["contacts_view_mode"] = contacts_view_mode_;
|
j["contacts_view_mode"] = contacts_view_mode_;
|
||||||
|
j["contacts_avatar_shape"] = contacts_avatar_shape_;
|
||||||
|
j["contacts_list_scale"] = contacts_list_scale_;
|
||||||
j["animate_avatars"] = animate_avatars_;
|
j["animate_avatars"] = animate_avatars_;
|
||||||
j["scanline_enabled"] = scanline_enabled_;
|
j["scanline_enabled"] = scanline_enabled_;
|
||||||
j["console_line_accents"] = console_line_accents_;
|
j["console_line_accents"] = console_line_accents_;
|
||||||
j["console_text_color"] = console_text_color_;
|
j["console_text_color"] = console_text_color_;
|
||||||
j["console_zoom"] = console_zoom_;
|
j["console_zoom"] = console_zoom_;
|
||||||
|
j["console_auto_focus"] = console_auto_focus_;
|
||||||
j["hidden_addresses"] = json::array();
|
j["hidden_addresses"] = json::array();
|
||||||
for (const auto& addr : hidden_addresses_)
|
for (const auto& addr : hidden_addresses_)
|
||||||
j["hidden_addresses"].push_back(addr);
|
j["hidden_addresses"].push_back(addr);
|
||||||
@@ -458,18 +547,26 @@ bool Settings::save(const std::string& path)
|
|||||||
}
|
}
|
||||||
j["wizard_completed"] = wizard_completed_;
|
j["wizard_completed"] = wizard_completed_;
|
||||||
j["seed_backup_reminded"] = seed_backup_reminded_;
|
j["seed_backup_reminded"] = seed_backup_reminded_;
|
||||||
|
j["large_wallet_warned"] = large_wallet_warned_;
|
||||||
|
j["empty_wallet_warning_acked"] = json::array();
|
||||||
|
for (const auto& w : empty_wallet_warning_acked_)
|
||||||
|
j["empty_wallet_warning_acked"].push_back(w);
|
||||||
|
j["encryption_pending"] = encryption_pending_;
|
||||||
j["daemon_update_prompted_size"] = daemon_update_prompted_size_;
|
j["daemon_update_prompted_size"] = daemon_update_prompted_size_;
|
||||||
j["active_wallet_file"] = active_wallet_file_;
|
j["active_wallet_file"] = active_wallet_file_;
|
||||||
j["seed_migration_pending"] = seed_migration_pending_;
|
j["seed_migration_pending"] = seed_migration_pending_;
|
||||||
j["seed_migration_dest"] = seed_migration_dest_;
|
j["seed_migration_dest"] = seed_migration_dest_;
|
||||||
j["seed_migration_temp_dir"] = seed_migration_temp_dir_;
|
j["seed_migration_temp_dir"] = seed_migration_temp_dir_;
|
||||||
j["seed_migration_sweep_txid"] = seed_migration_sweep_txid_;
|
j["seed_migration_sweep_txid"] = seed_migration_sweep_txid_;
|
||||||
|
j["seed_migration_sweep_opid"] = seed_migration_sweep_opid_;
|
||||||
j["auto_lock_timeout"] = auto_lock_timeout_;
|
j["auto_lock_timeout"] = auto_lock_timeout_;
|
||||||
j["unlock_duration"] = unlock_duration_;
|
j["unlock_duration"] = unlock_duration_;
|
||||||
j["pin_enabled"] = pin_enabled_;
|
j["pin_enabled"] = pin_enabled_;
|
||||||
j["keep_daemon_running"] = keep_daemon_running_;
|
j["keep_daemon_running"] = keep_daemon_running_;
|
||||||
j["stop_external_daemon"] = stop_external_daemon_;
|
j["stop_external_daemon"] = stop_external_daemon_;
|
||||||
j["max_connections"] = max_connections_;
|
j["max_connections"] = max_connections_;
|
||||||
|
j["stratum_host_enabled"] = stratum_host_enabled_;
|
||||||
|
j["stratum_allowip"] = stratum_allowip_;
|
||||||
{
|
{
|
||||||
json lite = json::object();
|
json lite = json::object();
|
||||||
lite["server_selection_mode"] = liteServerSelectionPreferenceModeName(lite_server_selection_mode_);
|
lite["server_selection_mode"] = liteServerSelectionPreferenceModeName(lite_server_selection_mode_);
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ public:
|
|||||||
bool showValue = true; // show the converted/fiat value on the card
|
bool showValue = true; // show the converted/fiat value on the card
|
||||||
bool show24h = false; // show the 24h % change (live-market bases only)
|
bool show24h = false; // show the 24h % change (live-market bases only)
|
||||||
bool showSparkline = false; // show a price-trend sparkline (live-market bases only)
|
bool showSparkline = false; // show a price-trend sparkline (live-market bases only)
|
||||||
int sparklineInterval = 0; // 0=minute 1=hour 2=day 3=week 4=month (resample of price history)
|
int sparklineInterval = 4; // 0=minute 1=hour 2=day 3=week 4=month (default month: a real curve
|
||||||
|
// from the daily series, vs the young in-session minute buffer)
|
||||||
// Per-wallet visibility: "" (shown in every wallet — legacy/global) or a wallet-identity
|
// Per-wallet visibility: "" (shown in every wallet — legacy/global) or a wallet-identity
|
||||||
// hash (shown only when that wallet is active). New entries are tagged with the current
|
// hash (shown only when that wallet is active). New entries are tagged with the current
|
||||||
// wallet so a portfolio built for wallet A doesn't clutter wallet B.
|
// wallet so a portfolio built for wallet A doesn't clutter wallet B.
|
||||||
@@ -118,6 +119,72 @@ public:
|
|||||||
std::string getChatReplyZaddr() const { return chat_reply_zaddr_; }
|
std::string getChatReplyZaddr() const { return chat_reply_zaddr_; }
|
||||||
void setChatReplyZaddr(const std::string& z) { chat_reply_zaddr_ = z; }
|
void setChatReplyZaddr(const std::string& z) { chat_reply_zaddr_ = z; }
|
||||||
|
|
||||||
|
// Muted chat conversations (by cid) — muted conversations don't badge or raise a toast (Q10).
|
||||||
|
bool isChatMuted(const std::string& cid) const {
|
||||||
|
return std::find(muted_chat_cids_.begin(), muted_chat_cids_.end(), cid) != muted_chat_cids_.end();
|
||||||
|
}
|
||||||
|
void setChatMuted(const std::string& cid, bool muted) {
|
||||||
|
const bool already = isChatMuted(cid);
|
||||||
|
if (muted && !already) muted_chat_cids_.push_back(cid);
|
||||||
|
else if (!muted && already)
|
||||||
|
muted_chat_cids_.erase(std::remove(muted_chat_cids_.begin(), muted_chat_cids_.end(), cid),
|
||||||
|
muted_chat_cids_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hidden chat conversations (by cid) — hidden ones are filtered out of the list; a new incoming
|
||||||
|
// message un-hides them (you can't un-receive) so nothing is silently lost.
|
||||||
|
bool isChatHidden(const std::string& cid) const {
|
||||||
|
return std::find(hidden_chat_cids_.begin(), hidden_chat_cids_.end(), cid) != hidden_chat_cids_.end();
|
||||||
|
}
|
||||||
|
void setChatHidden(const std::string& cid, bool hidden) {
|
||||||
|
const bool already = isChatHidden(cid);
|
||||||
|
if (hidden && !already) hidden_chat_cids_.push_back(cid);
|
||||||
|
else if (!hidden && already)
|
||||||
|
hidden_chat_cids_.erase(std::remove(hidden_chat_cids_.begin(), hidden_chat_cids_.end(), cid),
|
||||||
|
hidden_chat_cids_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Blocked chat conversations (by cid). Unlike hide (reversible, keeps messages), block DELETES the
|
||||||
|
// local history AND suppresses every message for the cid — old and future — until you unblock, at
|
||||||
|
// which point the conversation re-imports from the chain. The last-known peer name is kept so the
|
||||||
|
// "Blocked" list can label the entry (its messages are gone from the local store).
|
||||||
|
struct BlockedChatConv { std::string cid; std::string name; };
|
||||||
|
bool isChatBlocked(const std::string& cid) const {
|
||||||
|
for (const auto& b : blocked_chat_convs_) if (b.cid == cid) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void setChatBlocked(const std::string& cid, const std::string& name, bool blocked) {
|
||||||
|
const bool already = isChatBlocked(cid);
|
||||||
|
if (blocked && !already) blocked_chat_convs_.push_back({cid, name});
|
||||||
|
else if (!blocked && already)
|
||||||
|
blocked_chat_convs_.erase(
|
||||||
|
std::remove_if(blocked_chat_convs_.begin(), blocked_chat_convs_.end(),
|
||||||
|
[&](const BlockedChatConv& b) { return b.cid == cid; }),
|
||||||
|
blocked_chat_convs_.end());
|
||||||
|
}
|
||||||
|
const std::vector<BlockedChatConv>& blockedChatConversations() const { return blocked_chat_convs_; }
|
||||||
|
|
||||||
|
// ── Chat-tab customization (chat settings modal + Settings → Chat & Contacts) ──────
|
||||||
|
bool getChatEmojiColor() const { return chat_emoji_color_; }
|
||||||
|
void setChatEmojiColor(bool v) { chat_emoji_color_ = v; }
|
||||||
|
float getChatPollRateSec() const { return chat_poll_rate_sec_; }
|
||||||
|
void setChatPollRateSec(float v) { chat_poll_rate_sec_ = std::max(0.5f, std::min(15.0f, v)); }
|
||||||
|
int getChatBubbleStyle() const { return chat_bubble_style_; }
|
||||||
|
void setChatBubbleStyle(int v) { chat_bubble_style_ = (v < 0 || v > 2) ? 0 : v; }
|
||||||
|
int getChatBubbleAccent() const { return chat_bubble_accent_; }
|
||||||
|
void setChatBubbleAccent(int v) { chat_bubble_accent_ = (v < 0 || v > 5) ? 0 : v; }
|
||||||
|
int getChatDensity() const { return chat_density_; }
|
||||||
|
void setChatDensity(int v) { chat_density_ = (v < 0 || v > 1) ? 0 : v; }
|
||||||
|
float getChatFontScale() const { return chat_font_scale_; }
|
||||||
|
void setChatFontScale(float v) { chat_font_scale_ = std::max(0.8f, std::min(1.5f, v)); }
|
||||||
|
int getChatTimeFormat() const { return chat_time_format_; } // 0=follow global, 1=24h, 2=12h
|
||||||
|
void setChatTimeFormat(int v) { chat_time_format_ = (v < 0 || v > 2) ? 0 : v; }
|
||||||
|
bool getChatEnterSends() const { return chat_enter_sends_; }
|
||||||
|
void setChatEnterSends(bool v) { chat_enter_sends_ = v; }
|
||||||
|
// Global clock format (0=24h, 1=12h) — chat can override it for the Chat tab only.
|
||||||
|
int getTimeFormat() const { return time_format_; }
|
||||||
|
void setTimeFormat(int v) { time_format_ = (v < 0 || v > 1) ? 0 : v; }
|
||||||
|
|
||||||
// Privacy
|
// Privacy
|
||||||
bool getSaveZtxs() const { return save_ztxs_; }
|
bool getSaveZtxs() const { return save_ztxs_; }
|
||||||
void setSaveZtxs(bool save) { save_ztxs_ = save; }
|
void setSaveZtxs(bool save) { save_ztxs_ = save; }
|
||||||
@@ -180,13 +247,19 @@ public:
|
|||||||
std::string getBalanceLayout() const { return balance_layout_; }
|
std::string getBalanceLayout() const { return balance_layout_; }
|
||||||
void setBalanceLayout(const std::string& v) { balance_layout_ = v; }
|
void setBalanceLayout(const std::string& v) { balance_layout_ = v; }
|
||||||
|
|
||||||
// Market-tab portfolio row style: 0 = single-line, 1 = two-line, 2 = value-hero. Cycled with
|
// Market-tab portfolio row style: 0 = Table (borderless grid), 1 = Cards (glass card + Z/T bar),
|
||||||
// Left/Right arrows on the Market tab (like the Overview layouts).
|
// 2 = Spotlight (hero value). Cycled with Left/Right arrows or set in the Market settings modal.
|
||||||
int getPortfolioStyle() const { return portfolio_style_; }
|
int getPortfolioStyle() const { return portfolio_style_; }
|
||||||
void setPortfolioStyle(int v) { portfolio_style_ = (v < 0 || v > 2) ? 0 : v; }
|
void setPortfolioStyle(int v) { portfolio_style_ = (v < 0 || v > 2) ? 0 : v; }
|
||||||
// Contacts tab address-list view: 0 = cards, 1 = list, 2 = table.
|
// Contacts tab address-list view: 0 = cards, 1 = list, 2 = table.
|
||||||
int getContactsViewMode() const { return contacts_view_mode_; }
|
int getContactsViewMode() const { return contacts_view_mode_; }
|
||||||
void setContactsViewMode(int v) { contacts_view_mode_ = (v < 0 || v > 2) ? 0 : v; }
|
void setContactsViewMode(int v) { contacts_view_mode_ = (v < 0 || v > 2) ? 0 : v; }
|
||||||
|
// Contacts customization (gear modal): avatar shape + card/list row scale.
|
||||||
|
// Avatar shape: 0 = circle, 1 = rounded square, 2 = full-row-height left tab (rounded-left, flat right).
|
||||||
|
int getContactsAvatarShape() const { return contacts_avatar_shape_; }
|
||||||
|
void setContactsAvatarShape(int v) { contacts_avatar_shape_ = (v < 0 || v > 2) ? 0 : v; }
|
||||||
|
float getContactsListScale() const { return contacts_list_scale_; }
|
||||||
|
void setContactsListScale(float v) { contacts_list_scale_ = std::max(0.8f, std::min(1.5f, v)); }
|
||||||
// Play animated contact avatars (GIF/WebP). Off = show the first frame only.
|
// Play animated contact avatars (GIF/WebP). Off = show the first frame only.
|
||||||
bool getAnimateAvatars() const { return animate_avatars_; }
|
bool getAnimateAvatars() const { return animate_avatars_; }
|
||||||
void setAnimateAvatars(bool v) { animate_avatars_ = v; }
|
void setAnimateAvatars(bool v) { animate_avatars_ = v; }
|
||||||
@@ -203,6 +276,9 @@ public:
|
|||||||
void setConsoleTextColor(bool v) { console_text_color_ = v; }
|
void setConsoleTextColor(bool v) { console_text_color_ = v; }
|
||||||
float getConsoleZoom() const { return console_zoom_; }
|
float getConsoleZoom() const { return console_zoom_; }
|
||||||
void setConsoleZoom(float v) { console_zoom_ = v; }
|
void setConsoleZoom(float v) { console_zoom_ = v; }
|
||||||
|
// Auto-place the text cursor in the command box when the Console tab is opened.
|
||||||
|
bool getConsoleAutoFocus() const { return console_auto_focus_; }
|
||||||
|
void setConsoleAutoFocus(bool v) { console_auto_focus_ = v; }
|
||||||
|
|
||||||
// Hidden addresses (addresses hidden from the UI by the user)
|
// Hidden addresses (addresses hidden from the UI by the user)
|
||||||
const std::set<std::string>& getHiddenAddresses() const { return hidden_addresses_; }
|
const std::set<std::string>& getHiddenAddresses() const { return hidden_addresses_; }
|
||||||
@@ -274,6 +350,24 @@ public:
|
|||||||
bool getSeedBackupReminded() const { return seed_backup_reminded_; }
|
bool getSeedBackupReminded() const { return seed_backup_reminded_; }
|
||||||
void setSeedBackupReminded(bool v) { seed_backup_reminded_ = v; }
|
void setSeedBackupReminded(bool v) { seed_backup_reminded_ = v; }
|
||||||
|
|
||||||
|
// One-time nudge when wallet.dat grows past the bloat threshold (re-armed if it shrinks back).
|
||||||
|
bool getLargeWalletWarned() const { return large_wallet_warned_; }
|
||||||
|
void setLargeWalletWarned(bool v) { large_wallet_warned_ = v; }
|
||||||
|
|
||||||
|
// Wallet filenames for which the one-time "this wallet is empty but a sibling holds funds"
|
||||||
|
// warning has been dismissed. Keyed per active wallet file so switching to a different empty
|
||||||
|
// wallet can warn again (see App::maybeWarnEmptyWalletWithFundedSiblings).
|
||||||
|
bool isEmptyWalletWarnAcked(const std::string& walletFile) const {
|
||||||
|
return empty_wallet_warning_acked_.count(walletFile) > 0;
|
||||||
|
}
|
||||||
|
void ackEmptyWalletWarn(const std::string& walletFile) { empty_wallet_warning_acked_.insert(walletFile); }
|
||||||
|
|
||||||
|
// Persisted the moment deferred (wizard) encryption is requested; cleared only once the wallet is
|
||||||
|
// observed to be actually encrypted. Lets a quit/crash/failed-connect before it applies be detected
|
||||||
|
// and surfaced (W2-2). NEVER stores the passphrase — only the fact that encryption was requested.
|
||||||
|
bool getEncryptionPending() const { return encryption_pending_; }
|
||||||
|
void setEncryptionPending(bool v) { encryption_pending_ = v; }
|
||||||
|
|
||||||
// Bundled-daemon size we last prompted to install (see App::renderDaemonUpdatePrompt). Lets the
|
// Bundled-daemon size we last prompted to install (see App::renderDaemonUpdatePrompt). Lets the
|
||||||
// "a newer node is bundled — update?" prompt fire once per wallet version, never re-nagging.
|
// "a newer node is bundled — update?" prompt fire once per wallet version, never re-nagging.
|
||||||
long long getDaemonUpdatePromptedSize() const { return daemon_update_prompted_size_; }
|
long long getDaemonUpdatePromptedSize() const { return daemon_update_prompted_size_; }
|
||||||
@@ -297,6 +391,11 @@ public:
|
|||||||
// migration is past the sweep, so a resume goes to the confirm/adopt stage (not sweep again).
|
// migration is past the sweep, so a resume goes to the confirm/adopt stage (not sweep again).
|
||||||
std::string getSeedMigrationSweepTxid() const { return seed_migration_sweep_txid_; }
|
std::string getSeedMigrationSweepTxid() const { return seed_migration_sweep_txid_; }
|
||||||
void setSeedMigrationSweepTxid(const std::string& v) { seed_migration_sweep_txid_ = v; }
|
void setSeedMigrationSweepTxid(const std::string& v) { seed_migration_sweep_txid_ = v; }
|
||||||
|
// W3-3: the async sweep operation id, persisted while the sweep is in flight (before it resolves
|
||||||
|
// to a txid). Lets a resume re-poll a mid-sweep interruption instead of dropping the txid. Cleared
|
||||||
|
// in the same write that persists the txid, so the txid always outranks it (see [[decideSeedMigrationResume]]).
|
||||||
|
std::string getSeedMigrationSweepOpid() const { return seed_migration_sweep_opid_; }
|
||||||
|
void setSeedMigrationSweepOpid(const std::string& v) { seed_migration_sweep_opid_ = v; }
|
||||||
|
|
||||||
// Security — auto-lock timeout (seconds; 0 = disabled)
|
// Security — auto-lock timeout (seconds; 0 = disabled)
|
||||||
int getAutoLockTimeout() const { return auto_lock_timeout_; }
|
int getAutoLockTimeout() const { return auto_lock_timeout_; }
|
||||||
@@ -321,6 +420,11 @@ public:
|
|||||||
// Daemon — maximum peer connections (0 = daemon default)
|
// Daemon — maximum peer connections (0 = daemon default)
|
||||||
int getMaxConnections() const { return max_connections_; }
|
int getMaxConnections() const { return max_connections_; }
|
||||||
void setMaxConnections(int v) { max_connections_ = std::max(0, v); }
|
void setMaxConnections(int v) { max_connections_ = std::max(0, v); }
|
||||||
|
// Host a RandomX stratum pool from the node (v1.3.0+ daemons). Empty allow-IP = loopback only (safe).
|
||||||
|
bool getStratumHost() const { return stratum_host_enabled_; }
|
||||||
|
void setStratumHost(bool v) { stratum_host_enabled_ = v; }
|
||||||
|
const std::string& getStratumAllowIp() const { return stratum_allowip_; }
|
||||||
|
void setStratumAllowIp(const std::string& v) { stratum_allowip_ = v; }
|
||||||
|
|
||||||
// Lite wallet server selection
|
// Lite wallet server selection
|
||||||
LiteServerSelectionPreferenceMode getLiteServerSelectionMode() const { return lite_server_selection_mode_; }
|
LiteServerSelectionPreferenceMode getLiteServerSelectionMode() const { return lite_server_selection_mode_; }
|
||||||
@@ -335,6 +439,9 @@ public:
|
|||||||
void setLitePersistSelectedServer(bool persist) { lite_persist_selected_server_ = persist; }
|
void setLitePersistSelectedServer(bool persist) { lite_persist_selected_server_ = persist; }
|
||||||
const std::vector<LiteServerPreference>& getLiteServers() const { return lite_servers_; }
|
const std::vector<LiteServerPreference>& getLiteServers() const { return lite_servers_; }
|
||||||
void setLiteServers(const std::vector<LiteServerPreference>& servers) { lite_servers_ = servers; }
|
void setLiteServers(const std::vector<LiteServerPreference>& servers) { lite_servers_ = servers; }
|
||||||
|
// Servers shipped as defaults. Also merged into an existing install's saved list on load
|
||||||
|
// (see Settings::load), so upgrades surface newly-added servers (e.g. lite6/lite7).
|
||||||
|
static std::vector<LiteServerPreference> defaultLiteServers();
|
||||||
|
|
||||||
// User-defined portfolio entries (Market tab). "All funds" is implicit, not stored here.
|
// User-defined portfolio entries (Market tab). "All funds" is implicit, not stored here.
|
||||||
const std::vector<PortfolioEntry>& getPortfolioEntries() const { return portfolio_entries_; }
|
const std::vector<PortfolioEntry>& getPortfolioEntries() const { return portfolio_entries_; }
|
||||||
@@ -473,6 +580,19 @@ private:
|
|||||||
std::string theme_ = "dragonx";
|
std::string theme_ = "dragonx";
|
||||||
std::string skin_id_ = "dragonx";
|
std::string skin_id_ = "dragonx";
|
||||||
std::string chat_reply_zaddr_;
|
std::string chat_reply_zaddr_;
|
||||||
|
std::vector<std::string> muted_chat_cids_; // muted chat conversations by cid (Q10)
|
||||||
|
std::vector<std::string> hidden_chat_cids_; // hidden chat conversations by cid
|
||||||
|
std::vector<BlockedChatConv> blocked_chat_convs_; // blocked chat conversations (cid + last-known name)
|
||||||
|
// Chat-tab customization (chat settings modal + Settings → Chat & Contacts).
|
||||||
|
bool chat_emoji_color_ = true; // true = color (needs FreeType; falls back to mono if absent), false = monochrome
|
||||||
|
float chat_poll_rate_sec_ = 2.5f; // 0-conf chat fast-scan cadence (full node)
|
||||||
|
int chat_bubble_style_ = 0; // 0 = rounded, 1 = square, 2 = minimal
|
||||||
|
int chat_bubble_accent_ = 0; // outgoing-bubble accent preset (0 = theme primary)
|
||||||
|
int chat_density_ = 0; // 0 = comfortable, 1 = compact
|
||||||
|
float chat_font_scale_ = 1.0f; // message text scale
|
||||||
|
int chat_time_format_ = 0; // 0 = follow global, 1 = 24h, 2 = 12h (Chat tab only)
|
||||||
|
bool chat_enter_sends_ = true; // Enter sends (vs. inserts newline; Ctrl+Enter sends)
|
||||||
|
int time_format_ = 0; // global clock: 0 = 24h, 1 = 12h
|
||||||
bool save_ztxs_ = true;
|
bool save_ztxs_ = true;
|
||||||
bool auto_shield_ = true;
|
bool auto_shield_ = true;
|
||||||
bool use_tor_ = false;
|
bool use_tor_ = false;
|
||||||
@@ -495,30 +615,39 @@ private:
|
|||||||
float window_opacity_ = 1.0f; // Mac/Linux: default fully opaque
|
float window_opacity_ = 1.0f; // Mac/Linux: default fully opaque
|
||||||
#endif
|
#endif
|
||||||
std::string balance_layout_ = "classic";
|
std::string balance_layout_ = "classic";
|
||||||
int portfolio_style_ = 0; // Market portfolio row style (0 single / 1 two-line / 2 hero)
|
int portfolio_style_ = 0; // Market portfolio row style (0 Table / 1 Cards / 2 Spotlight)
|
||||||
int contacts_view_mode_ = 0; // Contacts address-list view (0 cards / 1 list / 2 table)
|
int contacts_view_mode_ = 0; // Contacts address-list view (0 cards / 1 list / 2 table)
|
||||||
|
int contacts_avatar_shape_ = 0; // 0 = circle, 1 = rounded square, 2 = full-height left tab
|
||||||
|
float contacts_list_scale_ = 1.0f; // card/list row scale (does not affect the table view)
|
||||||
bool animate_avatars_ = true; // play animated (GIF/WebP) contact avatars
|
bool animate_avatars_ = true; // play animated (GIF/WebP) contact avatars
|
||||||
bool scanline_enabled_ = true;
|
bool scanline_enabled_ = true;
|
||||||
bool console_line_accents_ = true; // left color accent bars in console output
|
bool console_line_accents_ = true; // left color accent bars in console output
|
||||||
bool console_text_color_ = true; // per-channel text coloring in console output
|
bool console_text_color_ = true; // per-channel text coloring in console output
|
||||||
float console_zoom_ = 1.0f; // console output font zoom factor
|
float console_zoom_ = 1.0f; // console output font zoom factor
|
||||||
|
bool console_auto_focus_ = false; // focus the command input when the Console tab is opened (opt-in)
|
||||||
std::set<std::string> hidden_addresses_;
|
std::set<std::string> hidden_addresses_;
|
||||||
std::set<std::string> favorite_addresses_;
|
std::set<std::string> favorite_addresses_;
|
||||||
std::map<std::string, AddressMeta> address_meta_;
|
std::map<std::string, AddressMeta> address_meta_;
|
||||||
bool wizard_completed_ = false;
|
bool wizard_completed_ = false;
|
||||||
bool seed_backup_reminded_ = false;
|
bool seed_backup_reminded_ = false;
|
||||||
|
bool large_wallet_warned_ = false;
|
||||||
|
std::set<std::string> empty_wallet_warning_acked_; // wallet files whose empty-wallet warning was dismissed
|
||||||
|
bool encryption_pending_ = false;
|
||||||
long long daemon_update_prompted_size_ = 0; // bundled daemon size last offered via the update prompt
|
long long daemon_update_prompted_size_ = 0; // bundled daemon size last offered via the update prompt
|
||||||
std::string active_wallet_file_ = "wallet.dat"; // -wallet=<name> the daemon loads (multi-wallet)
|
std::string active_wallet_file_ = "wallet.dat"; // -wallet=<name> the daemon loads (multi-wallet)
|
||||||
bool seed_migration_pending_ = false;
|
bool seed_migration_pending_ = false;
|
||||||
std::string seed_migration_dest_;
|
std::string seed_migration_dest_;
|
||||||
std::string seed_migration_temp_dir_;
|
std::string seed_migration_temp_dir_;
|
||||||
std::string seed_migration_sweep_txid_;
|
std::string seed_migration_sweep_txid_;
|
||||||
|
std::string seed_migration_sweep_opid_;
|
||||||
int auto_lock_timeout_ = 900; // 15 minutes
|
int auto_lock_timeout_ = 900; // 15 minutes
|
||||||
int unlock_duration_ = 600; // 10 minutes
|
int unlock_duration_ = 600; // 10 minutes
|
||||||
bool pin_enabled_ = false;
|
bool pin_enabled_ = false;
|
||||||
bool keep_daemon_running_ = false;
|
bool keep_daemon_running_ = false;
|
||||||
bool stop_external_daemon_ = false;
|
bool stop_external_daemon_ = false;
|
||||||
int max_connections_ = 0; // 0 = daemon default
|
int max_connections_ = 0; // 0 = daemon default
|
||||||
|
bool stratum_host_enabled_ = false; // host a RandomX stratum pool from the node (v1.3.0+ daemons)
|
||||||
|
std::string stratum_allowip_; // -stratumallowip filter (empty = daemon default: loopback only)
|
||||||
|
|
||||||
// Lite wallet server preferences. These are user/server settings only;
|
// Lite wallet server preferences. These are user/server settings only;
|
||||||
// wallet secrets, wallet files, and lifecycle state are never stored here.
|
// wallet secrets, wallet files, and lifecycle state are never stored here.
|
||||||
@@ -529,14 +658,7 @@ private:
|
|||||||
bool lite_persist_selected_server_ = true;
|
bool lite_persist_selected_server_ = true;
|
||||||
std::string lite_rollout_override_ = "auto"; // auto|force_on|force_off
|
std::string lite_rollout_override_ = "auto"; // auto|force_on|force_off
|
||||||
std::string lite_install_id_; // random local-only id; rollout-bucket source
|
std::string lite_install_id_; // random local-only id; rollout-bucket source
|
||||||
std::vector<LiteServerPreference> lite_servers_ = {
|
std::vector<LiteServerPreference> lite_servers_ = defaultLiteServers();
|
||||||
{"https://lite.dragonx.is", "DragonX Lite", true},
|
|
||||||
{"https://lite1.dragonx.is", "DragonX Lite 1", true},
|
|
||||||
{"https://lite2.dragonx.is", "DragonX Lite 2", true},
|
|
||||||
{"https://lite3.dragonx.is", "DragonX Lite 3", true},
|
|
||||||
{"https://lite4.dragonx.is", "DragonX Lite 4", true},
|
|
||||||
{"https://lite5.dragonx.is", "DragonX Lite 5", true}
|
|
||||||
};
|
|
||||||
std::set<std::string> lite_hidden_servers_; // server URLs hidden from the Network tab
|
std::set<std::string> lite_hidden_servers_; // server URLs hidden from the Network tab
|
||||||
|
|
||||||
std::vector<PortfolioEntry> portfolio_entries_; // Market tab custom portfolio groups
|
std::vector<PortfolioEntry> portfolio_entries_; // Market tab custom portfolio groups
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ void DaemonController::syncSettings(const config::Settings* settings)
|
|||||||
if (!settings) return;
|
if (!settings) return;
|
||||||
daemon_->setDebugCategories(settings->getDebugCategories());
|
daemon_->setDebugCategories(settings->getDebugCategories());
|
||||||
daemon_->setMaxConnections(settings->getMaxConnections());
|
daemon_->setMaxConnections(settings->getMaxConnections());
|
||||||
|
daemon_->setStratumHosting(settings->getStratumHost(), settings->getStratumAllowIp());
|
||||||
|
|
||||||
std::string walletFile = settings->getActiveWalletFile();
|
std::string walletFile = settings->getActiveWalletFile();
|
||||||
// The Wallets dialog opens an out-of-datadir wallet by linking it into the datadir under a
|
// The Wallets dialog opens an out-of-datadir wallet by linking it into the datadir under a
|
||||||
@@ -61,14 +62,21 @@ bool DaemonController::externalDaemonDetected() const
|
|||||||
return daemon_->externalDaemonDetected();
|
return daemon_->externalDaemonDetected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DaemonController::clearExternalDaemonDetected()
|
||||||
|
{
|
||||||
|
daemon_->clearExternalDaemonDetected();
|
||||||
|
}
|
||||||
|
|
||||||
DaemonController::State DaemonController::state() const
|
DaemonController::State DaemonController::state() const
|
||||||
{
|
{
|
||||||
return daemon_->getState();
|
return daemon_->getState();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& DaemonController::lastError() const
|
std::string DaemonController::lastError() const
|
||||||
{
|
{
|
||||||
return daemon_->getLastError();
|
// By value — getLastError() now returns a mutex-locked COPY, so forwarding it by reference would
|
||||||
|
// dangle (bind a reference to that temporary). (M-04 follow-through)
|
||||||
|
return daemon_ ? daemon_->getLastError() : std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DaemonController::crashCount() const
|
int DaemonController::crashCount() const
|
||||||
@@ -116,6 +124,16 @@ void DaemonController::setZapOnNextStart(bool enabled)
|
|||||||
daemon_->setZapOnNextStart(enabled);
|
daemon_->setZapOnNextStart(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DaemonController::setSalvageOnNextStart(bool enabled)
|
||||||
|
{
|
||||||
|
daemon_->setSalvageOnNextStart(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DaemonController::setReindexOnNextStart(bool enabled)
|
||||||
|
{
|
||||||
|
daemon_->setReindexOnNextStart(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
bool DaemonController::zapOnNextStart() const
|
bool DaemonController::zapOnNextStart() const
|
||||||
{
|
{
|
||||||
return daemon_->zapOnNextStart();
|
return daemon_->zapOnNextStart();
|
||||||
|
|||||||
@@ -93,8 +93,9 @@ public:
|
|||||||
|
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
bool externalDaemonDetected() const;
|
bool externalDaemonDetected() const;
|
||||||
|
void clearExternalDaemonDetected();
|
||||||
State state() const;
|
State state() const;
|
||||||
const std::string& lastError() const;
|
std::string lastError() const; // by value: EmbeddedDaemon::getLastError() returns a locked copy (M-04)
|
||||||
int crashCount() const;
|
int crashCount() const;
|
||||||
int lastBlockHeight() const;
|
int lastBlockHeight() const;
|
||||||
double memoryUsageMB() const;
|
double memoryUsageMB() const;
|
||||||
@@ -106,6 +107,8 @@ public:
|
|||||||
bool rescanOnNextStart() const;
|
bool rescanOnNextStart() const;
|
||||||
void setZapOnNextStart(bool enabled);
|
void setZapOnNextStart(bool enabled);
|
||||||
bool zapOnNextStart() const;
|
bool zapOnNextStart() const;
|
||||||
|
void setSalvageOnNextStart(bool enabled);
|
||||||
|
void setReindexOnNextStart(bool enabled); // -reindex: rebuild the block DB from raw blocks on next start
|
||||||
|
|
||||||
static ShutdownDecision evaluateShutdownPolicy(bool hasDaemon,
|
static ShutdownDecision evaluateShutdownPolicy(bool hasDaemon,
|
||||||
bool externalDaemonDetected,
|
bool externalDaemonDetected,
|
||||||
|
|||||||
107
src/daemon/daemon_startup_diagnosis.h
Normal file
107
src/daemon/daemon_startup_diagnosis.h
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
// DragonX Wallet - ImGui Edition
|
||||||
|
// Copyright 2024-2026 The Hush Developers
|
||||||
|
// Released under the GPLv3
|
||||||
|
//
|
||||||
|
// daemon_startup_diagnosis.h — pure classifiers over a crashed daemon's captured console output,
|
||||||
|
// so the app can offer a targeted one-click fix instead of a bare "daemon crashed" / silent no-funds.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace dragonx {
|
||||||
|
namespace daemon {
|
||||||
|
|
||||||
|
// True when dragonxd aborted because its BLOCK DATABASE could not be loaded — either a
|
||||||
|
// daemon-vs-chaindata serialization-format mismatch after a daemon update (the deterministic
|
||||||
|
// "non-canonical optional discriminant" → "Error loading block database" → "Aborted block database
|
||||||
|
// rebuild. Exiting." sequence) or a genuinely corrupt/incomplete block index. In BOTH cases the fix
|
||||||
|
// is the same: `-reindex` rebuilds the index + chainstate from the intact raw blocks (blk*.dat).
|
||||||
|
// This is what otherwise silently presents as a wallet with zero balance — the node never starts.
|
||||||
|
inline bool blockDbOutputLooksBroken(const std::string& out)
|
||||||
|
{
|
||||||
|
return out.find("Error loading block database") != std::string::npos
|
||||||
|
|| out.find("non-canonical optional discriminant") != std::string::npos
|
||||||
|
|| out.find("Aborted block database rebuild") != std::string::npos
|
||||||
|
|| out.find("LoadBlockIndex()") != std::string::npos; // "... : failed to read value"
|
||||||
|
}
|
||||||
|
|
||||||
|
// True when dragonxd AUTO-RECOVERED the wallet on startup: on any BDB-verify failure it moves the
|
||||||
|
// original wallet.dat to "wallet.{timestamp}.bak", salvages readable keys into a fresh wallet.dat, and
|
||||||
|
// keeps running — no flag required (CWallet::Verify → CDBEnv::Verify(walletFile, CWalletDB::Recover)).
|
||||||
|
// The salvage can be incomplete (or a false positive from stale/cross-platform BDB env state), so the
|
||||||
|
// node silently comes up on a possibly-empty wallet — which reads as fund loss unless we surface it.
|
||||||
|
inline bool walletAutoRecovered(const std::string& out)
|
||||||
|
{
|
||||||
|
// Cover BOTH salvage outcomes. A successful salvage prints the "data salvaged"/"saved as wallet.<ts>.bak"
|
||||||
|
// warning; a FAILED one (e.g. an inconsistent-but-readable file where aggressive salvage finds no
|
||||||
|
// records) prints "salvage failed"/"found no records". In every case CWalletDB::Recover first logs
|
||||||
|
// "Renamed <wallet> to wallet.<ts>.bak" and CDBEnv::Salvage logs its own banner — those two fire the
|
||||||
|
// instant a salvage begins, before the daemon may abort, so they're the earliest reliable signal.
|
||||||
|
return out.find("CDBEnv::Salvage") != std::string::npos // salvage is running
|
||||||
|
|| out.find("wallet.dat corrupt, data salvaged") != std::string::npos // RECOVER_OK
|
||||||
|
|| out.find("Original wallet.dat saved as wallet.") != std::string::npos
|
||||||
|
|| out.find("wallet.dat corrupt, salvage failed") != std::string::npos // RECOVER_FAIL
|
||||||
|
|| out.find("found no records in wallet") != std::string::npos // aggressive salvage empty
|
||||||
|
|| (out.find("Renamed ") != std::string::npos && out.find(" to wallet.") != std::string::npos
|
||||||
|
&& out.find(".bak") != std::string::npos); // Recover moved wallet.dat aside
|
||||||
|
}
|
||||||
|
|
||||||
|
// True when dragonxd (v1.3.0+) opened the wallet in DEGRADED mode: a wallet.dat that lost its hdchain
|
||||||
|
// record (e.g. an old `-salvagewallet` output) now OPENS — existing keys stay intact and spendable —
|
||||||
|
// instead of aborting, but the daemon can no longer derive NEW HD keys, so z_getnewaddress /
|
||||||
|
// z_shieldcoinbase / a t->z z_sendmany fail with "HD seed not found". The only signal is a startup log
|
||||||
|
// line; pre-1.3.0 daemons never emit it, so this classifier is naturally a no-op against them.
|
||||||
|
inline bool walletOpenedDegraded(const std::string& out)
|
||||||
|
{
|
||||||
|
return out.find("Wallet opened in DEGRADED mode") != std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If `name` is a daemon salvage backup "wallet.<unixtime>.bak", return its timestamp; else -1.
|
||||||
|
inline long long parseWalletSalvageBakTs(const std::string& name)
|
||||||
|
{
|
||||||
|
if (name.rfind("wallet.", 0) != 0) return -1; // must start "wallet."
|
||||||
|
if (name.size() < 12 || name.compare(name.size() - 4, 4, ".bak") != 0) return -1; // ...and end ".bak"
|
||||||
|
const std::string mid = name.substr(7, name.size() - 7 - 4); // digits between the dots
|
||||||
|
if (mid.empty() || mid.size() > 18) return -1;
|
||||||
|
for (char c : mid) if (c < '0' || c > '9') return -1;
|
||||||
|
long long ts = 0;
|
||||||
|
for (char c : mid) ts = ts * 10 + (c - '0');
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Most RECENT salvage backup (highest timestamp). Pure, testable.
|
||||||
|
inline std::string newestWalletSalvageBak(const std::vector<std::string>& filenames)
|
||||||
|
{
|
||||||
|
long long best = -1;
|
||||||
|
std::string bestName;
|
||||||
|
for (const auto& f : filenames) {
|
||||||
|
const long long ts = parseWalletSalvageBakTs(f);
|
||||||
|
if (ts > best) { best = ts; bestName = f; }
|
||||||
|
}
|
||||||
|
return bestName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// LARGEST salvage backup, from (filename, fileSize) pairs — the least-salvaged one, i.e. the original.
|
||||||
|
// This is what "Restore original wallet" should use: a salvage CASCADE shrinks the wallet each round, so
|
||||||
|
// the newest .bak is the WORST and the largest is the pristine pre-salvage original (an emptied salvage
|
||||||
|
// is tiny; a real wallet is large). Ties break toward the newest timestamp. Returns "" if none present.
|
||||||
|
inline std::string largestWalletSalvageBak(const std::vector<std::pair<std::string, unsigned long long>>& files)
|
||||||
|
{
|
||||||
|
std::string bestName;
|
||||||
|
unsigned long long bestSize = 0;
|
||||||
|
long long bestTs = -1;
|
||||||
|
for (const auto& fp : files) {
|
||||||
|
const long long ts = parseWalletSalvageBakTs(fp.first);
|
||||||
|
if (ts < 0) continue;
|
||||||
|
if (fp.second > bestSize || (fp.second == bestSize && ts > bestTs)) {
|
||||||
|
bestSize = fp.second; bestTs = ts; bestName = fp.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestName;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace daemon
|
||||||
|
} // namespace dragonx
|
||||||
@@ -205,11 +205,13 @@ std::vector<std::string> EmbeddedDaemon::getChainParams()
|
|||||||
"-ac_reward=300000000",
|
"-ac_reward=300000000",
|
||||||
"-ac_blocktime=36",
|
"-ac_blocktime=36",
|
||||||
"-ac_private=1",
|
"-ac_private=1",
|
||||||
"-addnode=node.dragonx.is",
|
// Seeds: seed.dragonx.is is a round-robin A record over the live seed set (self-updates without
|
||||||
|
// a wallet release), with node1/node5 as static fallbacks — mirrors the daemon's own vSeeds.
|
||||||
|
// Plain -addnode hostname resolution works on EVERY daemon version, and is load-bearing for
|
||||||
|
// pre-1.3.0 daemons whose built-in peer discovery was broken (they rely on these to find peers).
|
||||||
|
"-addnode=seed.dragonx.is",
|
||||||
"-addnode=node1.dragonx.is",
|
"-addnode=node1.dragonx.is",
|
||||||
"-addnode=node2.dragonx.is",
|
"-addnode=node5.dragonx.is",
|
||||||
"-addnode=node3.dragonx.is",
|
|
||||||
"-addnode=node4.dragonx.is",
|
|
||||||
"-experimentalfeatures",
|
"-experimentalfeatures",
|
||||||
"-developerencryptwallet",
|
"-developerencryptwallet",
|
||||||
// Create fresh wallets from a BIP39 mnemonic so their 24-word phrase can be
|
// Create fresh wallets from a BIP39 mnemonic so their 24-word phrase can be
|
||||||
@@ -224,11 +226,10 @@ std::vector<std::string> EmbeddedDaemon::getChainParams()
|
|||||||
void EmbeddedDaemon::setState(State s, const std::string& message)
|
void EmbeddedDaemon::setState(State s, const std::string& message)
|
||||||
{
|
{
|
||||||
state_ = s;
|
state_ = s;
|
||||||
if (!message.empty()) {
|
if (!message.empty() && s == State::Error) {
|
||||||
if (s == State::Error) {
|
std::lock_guard<std::mutex> lk(error_mutex_); // dedicated mutex — never taken with output_mutex_ held
|
||||||
last_error_ = message;
|
last_error_ = message;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (state_callback_) {
|
if (state_callback_) {
|
||||||
state_callback_(s, message);
|
state_callback_(s, message);
|
||||||
@@ -386,52 +387,80 @@ static std::string getPortOwnerInfo(int port)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a TCP port is already in use (something is LISTENING)
|
// Check if a TCP port is already in use (something is LISTENING). The daemon binds BOTH 127.0.0.1 (IPv4)
|
||||||
|
// and ::1 (IPv6); during shutdown one can linger after the other releases (and a "Binding RPC on ::1 …
|
||||||
|
// failed" is fatal to a fresh start), so we treat the port as in use if EITHER localhost family has it.
|
||||||
static bool isPortInUse(int port)
|
static bool isPortInUse(int port)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsa;
|
WSADATA wsa;
|
||||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) return false;
|
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) return false;
|
||||||
|
bool inUse = false;
|
||||||
|
{ // IPv4 127.0.0.1
|
||||||
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (sock == INVALID_SOCKET) { WSACleanup(); return false; }
|
if (sock != INVALID_SOCKET) {
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr; memset(&addr, 0, sizeof(addr));
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(static_cast<u_short>(port));
|
addr.sin_port = htons(static_cast<u_short>(port));
|
||||||
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||||
int result = connect(sock, (struct sockaddr*)&addr, sizeof(addr));
|
if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) == 0) inUse = true;
|
||||||
closesocket(sock);
|
closesocket(sock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!inUse) { // IPv6 ::1
|
||||||
|
SOCKET sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||||
|
if (sock != INVALID_SOCKET) {
|
||||||
|
struct sockaddr_in6 addr; memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sin6_family = AF_INET6;
|
||||||
|
addr.sin6_port = htons(static_cast<u_short>(port));
|
||||||
|
addr.sin6_addr = in6addr_loopback; // ::1 — avoids inet_pton's _WIN32_WINNT gating on mingw
|
||||||
|
if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) == 0) inUse = true;
|
||||||
|
closesocket(sock);
|
||||||
|
}
|
||||||
|
}
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return (result == 0);
|
return inUse;
|
||||||
#else
|
#else
|
||||||
// On macOS /proc doesn't exist; on Linux prefer /proc/net/tcp to avoid
|
// On macOS /proc doesn't exist; on Linux prefer /proc/net/tcp{,6} to avoid creating sockets. The
|
||||||
// creating sockets. Fall back to connect() if /proc is unavailable.
|
// parse is family-agnostic: %*X skips the local IP (8 hex for v4, 32 for v6), %X grabs the port.
|
||||||
FILE* fp = fopen("/proc/net/tcp", "r");
|
auto scanProc = [port](const char* path) -> bool {
|
||||||
if (fp) {
|
FILE* fp = fopen(path, "r");
|
||||||
char line[256];
|
if (!fp) return false;
|
||||||
|
char line[512];
|
||||||
unsigned int localPort, state;
|
unsigned int localPort, state;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
while (fgets(line, sizeof(line), fp)) {
|
while (fgets(line, sizeof(line), fp)) {
|
||||||
if (sscanf(line, " %*d: %*X:%X %*X:%*X %X", &localPort, &state) == 2) {
|
if (sscanf(line, " %*d: %*X:%X %*X:%*X %X", &localPort, &state) == 2) {
|
||||||
if (localPort == static_cast<unsigned int>(port) && state == 0x0A) {
|
if (localPort == static_cast<unsigned int>(port) && state == 0x0A) { found = true; break; }
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return found;
|
return found;
|
||||||
|
};
|
||||||
|
if (FILE* probe = fopen("/proc/net/tcp", "r")) { // /proc available → authoritative LISTEN check
|
||||||
|
fclose(probe);
|
||||||
|
return scanProc("/proc/net/tcp") || scanProc("/proc/net/tcp6");
|
||||||
}
|
}
|
||||||
// Fallback (macOS): try to connect
|
// Fallback (macOS): connect() probe on both loopback families.
|
||||||
int sock = socket(AF_INET, SOCK_STREAM, 0);
|
auto connProbe = [port](int family, const char* addr) -> bool {
|
||||||
|
int sock = socket(family, SOCK_STREAM, 0);
|
||||||
if (sock < 0) return false;
|
if (sock < 0) return false;
|
||||||
struct sockaddr_in addr;
|
bool ok = false;
|
||||||
memset(&addr, 0, sizeof(addr));
|
if (family == AF_INET) {
|
||||||
addr.sin_family = AF_INET;
|
struct sockaddr_in a; memset(&a, 0, sizeof(a));
|
||||||
addr.sin_port = htons(static_cast<uint16_t>(port));
|
a.sin_family = AF_INET; a.sin_port = htons(static_cast<uint16_t>(port));
|
||||||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
a.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||||
int result = connect(sock, (struct sockaddr*)&addr, sizeof(addr));
|
ok = (connect(sock, (struct sockaddr*)&a, sizeof(a)) == 0);
|
||||||
|
} else {
|
||||||
|
struct sockaddr_in6 a; memset(&a, 0, sizeof(a));
|
||||||
|
a.sin6_family = AF_INET6; a.sin6_port = htons(static_cast<uint16_t>(port));
|
||||||
|
inet_pton(AF_INET6, addr, &a.sin6_addr);
|
||||||
|
ok = (connect(sock, (struct sockaddr*)&a, sizeof(a)) == 0);
|
||||||
|
}
|
||||||
close(sock);
|
close(sock);
|
||||||
return (result == 0);
|
return ok;
|
||||||
|
};
|
||||||
|
return connProbe(AF_INET, "127.0.0.1") || connProbe(AF_INET6, "::1");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,6 +490,34 @@ bool EmbeddedDaemon::start(const std::string& binary_path)
|
|||||||
}
|
}
|
||||||
external_daemon_detected_ = false;
|
external_daemon_detected_ = false;
|
||||||
|
|
||||||
|
// A previous dragonxd can release the RPC port well before it releases the datadir
|
||||||
|
// .lock — a graceful shutdown can take up to ~90s (see isDaemonProcessRunning). Starting
|
||||||
|
// into a still-held lock spawns a process that dies instantly with "Cannot obtain a lock
|
||||||
|
// on data directory"; the crash monitor reports that generically and, three times in
|
||||||
|
// ~12s, that is enough to trip the 3-strike restart cap before the lock's ~90s life
|
||||||
|
// elapses. Gate on the process actually still being alive, with a SHORT bounded wait
|
||||||
|
// (not the full ~90s — start() runs on the UI thread). Isolated starts (migrate-to-seed:
|
||||||
|
// skip_port_check_ / -datadir override) are exempt; they run their own datadir+port.
|
||||||
|
{
|
||||||
|
constexpr int kDatadirLockWaitPollMs = 100;
|
||||||
|
constexpr int kDatadirLockWaitMaxPolls = 3; // ~300ms total, breaks early on exit
|
||||||
|
bool stillRunning = false;
|
||||||
|
if (!skip_port_check_ && override_datadir_.empty()) {
|
||||||
|
stillRunning = isDaemonProcessRunning();
|
||||||
|
for (int i = 0; stillRunning && i < kDatadirLockWaitMaxPolls; ++i) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(kDatadirLockWaitPollMs));
|
||||||
|
stillRunning = isDaemonProcessRunning();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const StartLockGateDecision gate =
|
||||||
|
evaluateDatadirLockGate(skip_port_check_, !override_datadir_.empty(), stillRunning);
|
||||||
|
if (!gate.proceed) {
|
||||||
|
VERBOSE_LOGF("[INFO] %s\n", gate.errorMessage);
|
||||||
|
setState(State::Error, gate.errorMessage);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setState(State::Starting, "Looking for dragonxd binary...");
|
setState(State::Starting, "Looking for dragonxd binary...");
|
||||||
|
|
||||||
std::string daemon_path = binary_path;
|
std::string daemon_path = binary_path;
|
||||||
@@ -488,6 +545,15 @@ bool EmbeddedDaemon::start(const std::string& binary_path)
|
|||||||
args.push_back("-maxconnections=" + std::to_string(max_connections_));
|
args.push_back("-maxconnections=" + std::to_string(max_connections_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Host a RandomX stratum pool from this node (-stratum). Only v1.3.0+ daemons implement it; older
|
||||||
|
// ones ignore the unknown flag (no fatal arg check), and the Settings toggle is gated on daemon
|
||||||
|
// version, so this is only enabled against a daemon that supports it. Without -stratumallowip the
|
||||||
|
// daemon serves loopback only (safe default); a subnet opens it to that LAN.
|
||||||
|
if (stratum_enabled_) {
|
||||||
|
args.push_back("-stratum");
|
||||||
|
if (!stratum_allowip_.empty()) args.push_back("-stratumallowip=" + stratum_allowip_);
|
||||||
|
}
|
||||||
|
|
||||||
// Active wallet file (multi-wallet). The daemon loads <datadir>/<name>. Only pass it for a
|
// Active wallet file (multi-wallet). The daemon loads <datadir>/<name>. Only pass it for a
|
||||||
// non-default name so the common case's command line is unchanged; skip during an isolated
|
// non-default name so the common case's command line is unchanged; skip during an isolated
|
||||||
// start (seed migration manages its own throwaway wallet).
|
// start (seed migration manages its own throwaway wallet).
|
||||||
@@ -496,9 +562,16 @@ bool EmbeddedDaemon::start(const std::string& binary_path)
|
|||||||
args.push_back("-wallet=" + wallet_file_);
|
args.push_back("-wallet=" + wallet_file_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add wallet-repair flag if requested (one-shot). -zapwallettxes=2 wipes all wallet tx/note
|
// Add wallet-repair flag if requested (one-shot). Precedence: salvage > zap > rescan; each implies a
|
||||||
// records and rebuilds them from the chain; it implies -rescan, so don't also pass -rescan.
|
// rescan in the daemon, so we don't stack them.
|
||||||
if (zap_on_next_start_.exchange(false)) {
|
if (salvage_on_next_start_.exchange(false)) {
|
||||||
|
// -salvagewallet recovers readable keypairs from a corrupt wallet.dat; the daemon then implies -rescan.
|
||||||
|
DEBUG_LOGF("[INFO] Adding -salvagewallet flag to recover a corrupt wallet\n");
|
||||||
|
args.push_back("-salvagewallet");
|
||||||
|
zap_on_next_start_.store(false);
|
||||||
|
rescan_on_next_start_.store(false);
|
||||||
|
} else if (zap_on_next_start_.exchange(false)) {
|
||||||
|
// -zapwallettxes=2 wipes all wallet tx/note records and rebuilds them from the chain (implies -rescan).
|
||||||
DEBUG_LOGF("[INFO] Adding -zapwallettxes=2 flag for wallet repair (zap & rebuild)\n");
|
DEBUG_LOGF("[INFO] Adding -zapwallettxes=2 flag for wallet repair (zap & rebuild)\n");
|
||||||
args.push_back("-zapwallettxes=2");
|
args.push_back("-zapwallettxes=2");
|
||||||
rescan_on_next_start_.store(false); // implied by zap; avoid redundant -rescan
|
rescan_on_next_start_.store(false); // implied by zap; avoid redundant -rescan
|
||||||
@@ -508,6 +581,14 @@ bool EmbeddedDaemon::start(const std::string& binary_path)
|
|||||||
args.push_back("-rescan");
|
args.push_back("-rescan");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -reindex rebuilds the block index + chainstate from the raw blocks (fixes an unreadable/format-
|
||||||
|
// mismatched block DB). It's about the CHAIN, not the wallet, so it's independent of the wallet-repair
|
||||||
|
// chain above (and implies its own wallet rescan). One-shot, consumed here.
|
||||||
|
if (reindex_on_next_start_.exchange(false)) {
|
||||||
|
DEBUG_LOGF("[INFO] Adding -reindex flag to rebuild the block database from raw blocks\n");
|
||||||
|
args.push_back("-reindex");
|
||||||
|
}
|
||||||
|
|
||||||
// One-shot isolated-datadir override (migrate-to-seed flow): run this start against a
|
// One-shot isolated-datadir override (migrate-to-seed flow): run this start against a
|
||||||
// throwaway datadir, plus any extra args (e.g. -connect=0). Consumed here so later starts
|
// throwaway datadir, plus any extra args (e.g. -connect=0). Consumed here so later starts
|
||||||
// revert to the normal datadir. The datadir's basename MUST be the assetchain name (DRAGONX)
|
// revert to the normal datadir. The datadir's basename MUST be the assetchain name (DRAGONX)
|
||||||
@@ -522,8 +603,14 @@ bool EmbeddedDaemon::start(const std::string& binary_path)
|
|||||||
override_extra_args_.clear();
|
override_extra_args_.clear();
|
||||||
|
|
||||||
if (!startProcess(daemon_path, args)) {
|
if (!startProcess(daemon_path, args)) {
|
||||||
DEBUG_LOGF("[ERROR] Failed to start dragonxd process: %s\\n", last_error_.c_str());
|
// startProcess() sets a precise last_error_ (e.g. "dragonxd could not be executed:
|
||||||
setState(State::Error, "Failed to start dragonxd process");
|
// ... not executable or wrong architecture"). Surface THAT via setState — which also
|
||||||
|
// stores the Error message into last_error_ — instead of clobbering it with a generic
|
||||||
|
// string that would then be all getLastError()/the UI ever sees.
|
||||||
|
std::string detail = last_error_.empty() ? std::string("Failed to start dragonxd process")
|
||||||
|
: last_error_;
|
||||||
|
DEBUG_LOGF("[ERROR] %s\n", detail.c_str());
|
||||||
|
setState(State::Error, detail);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,12 +631,28 @@ bool EmbeddedDaemon::start(const std::string& binary_path)
|
|||||||
// Forward declaration — defined after startProcess
|
// Forward declaration — defined after startProcess
|
||||||
static DWORD findProcessByName(const char* name);
|
static DWORD findProcessByName(const char* name);
|
||||||
|
|
||||||
|
// Quote a single argument per the CommandLineToArgvW rules (MSDN) so a value containing a space or a
|
||||||
|
// quote is delivered as ONE argv token to the daemon instead of splitting/corrupting argv (L-02).
|
||||||
|
static std::string quoteWinArg(const std::string& arg) {
|
||||||
|
if (!arg.empty() && arg.find_first_of(" \t\n\v\"") == std::string::npos) return arg;
|
||||||
|
std::string out = "\"";
|
||||||
|
for (size_t i = 0; ; ++i) {
|
||||||
|
size_t nbs = 0;
|
||||||
|
while (i < arg.size() && arg[i] == '\\') { ++nbs; ++i; }
|
||||||
|
if (i == arg.size()) { out.append(nbs * 2, '\\'); break; }
|
||||||
|
if (arg[i] == '"') { out.append(nbs * 2 + 1, '\\'); out.push_back('"'); }
|
||||||
|
else { out.append(nbs, '\\'); out.push_back(arg[i]); }
|
||||||
|
}
|
||||||
|
out.push_back('"');
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
bool EmbeddedDaemon::startProcess(const std::string& binary_path, const std::vector<std::string>& args)
|
bool EmbeddedDaemon::startProcess(const std::string& binary_path, const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
// Build command line
|
// Build command line (binary path always quoted; each arg quoted/escaped per Windows rules — L-02)
|
||||||
std::string cmd = "\"" + binary_path + "\"";
|
std::string cmd = "\"" + binary_path + "\"";
|
||||||
for (const auto& arg : args) {
|
for (const auto& arg : args) {
|
||||||
cmd += " " + arg;
|
cmd += " " + quoteWinArg(arg);
|
||||||
}
|
}
|
||||||
DEBUG_LOGF("[INFO] Starting daemon: %s\n", cmd.c_str());
|
DEBUG_LOGF("[INFO] Starting daemon: %s\n", cmd.c_str());
|
||||||
|
|
||||||
@@ -597,7 +700,10 @@ bool EmbeddedDaemon::startProcess(const std::string& binary_path, const std::vec
|
|||||||
debug_log_path_.c_str(), debug_log_offset_);
|
debug_log_path_.c_str(), debug_log_offset_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Launch daemon with CREATE_NEW_CONSOLE (hidden via SW_HIDE).
|
// Launch daemon windowless. Use CREATE_NO_WINDOW (NOT CREATE_NEW_CONSOLE): CREATE_NEW_CONSOLE
|
||||||
|
// allocates a console window that briefly flashes on screen before SW_HIDE can hide it, which is
|
||||||
|
// visible as a console-window flash on wallet launch. CREATE_NO_WINDOW gives the console child no
|
||||||
|
// window at all (same approach as the xmrig launcher). The daemon logs to debug.log, not a console.
|
||||||
// The daemon binary must NOT be in the data directory (%APPDATA%\Hush\DRAGONX)
|
// The daemon binary must NOT be in the data directory (%APPDATA%\Hush\DRAGONX)
|
||||||
// — it must be in <exe_dir>/dragonx/ to avoid conflicts with lock files and data.
|
// — it must be in <exe_dir>/dragonx/ to avoid conflicts with lock files and data.
|
||||||
STARTUPINFOA si;
|
STARTUPINFOA si;
|
||||||
@@ -615,7 +721,7 @@ bool EmbeddedDaemon::startProcess(const std::string& binary_path, const std::vec
|
|||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
FALSE,
|
FALSE,
|
||||||
CREATE_NEW_CONSOLE,
|
CREATE_NO_WINDOW,
|
||||||
NULL,
|
NULL,
|
||||||
work_dir.c_str(),
|
work_dir.c_str(),
|
||||||
&si,
|
&si,
|
||||||
@@ -656,17 +762,24 @@ static DWORD findProcessByName(const char* name)
|
|||||||
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||||
if (snap == INVALID_HANDLE_VALUE) return 0;
|
if (snap == INVALID_HANDLE_VALUE) return 0;
|
||||||
|
|
||||||
PROCESSENTRY32 entry;
|
// Use the explicit WIDE Toolhelp API + a wide compare so this is correct regardless of the UNICODE
|
||||||
|
// macro. (The non-suffixed PROCESSENTRY32/Process32First map to the wide variants when UNICODE is
|
||||||
|
// defined, in which case szExeFile is WCHAR[] and an ANSI _stricmp would compare garbage and NEVER
|
||||||
|
// match — silently making findProcessByName a no-op that returns 0 for a running process.)
|
||||||
|
wchar_t wname[MAX_PATH];
|
||||||
|
if (MultiByteToWideChar(CP_ACP, 0, name, -1, wname, MAX_PATH) == 0) { CloseHandle(snap); return 0; }
|
||||||
|
|
||||||
|
PROCESSENTRY32W entry;
|
||||||
entry.dwSize = sizeof(entry);
|
entry.dwSize = sizeof(entry);
|
||||||
|
|
||||||
DWORD pid = 0;
|
DWORD pid = 0;
|
||||||
if (Process32First(snap, &entry)) {
|
if (Process32FirstW(snap, &entry)) {
|
||||||
do {
|
do {
|
||||||
if (_stricmp(entry.szExeFile, name) == 0) {
|
if (lstrcmpiW(entry.szExeFile, wname) == 0) { // Win32 case-insensitive wide compare
|
||||||
pid = entry.th32ProcessID;
|
pid = entry.th32ProcessID;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (Process32Next(snap, &entry));
|
} while (Process32NextW(snap, &entry));
|
||||||
}
|
}
|
||||||
CloseHandle(snap);
|
CloseHandle(snap);
|
||||||
return pid;
|
return pid;
|
||||||
@@ -703,6 +816,16 @@ void EmbeddedDaemon::drainOutput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t currentSize = static_cast<size_t>(fileSize.QuadPart);
|
size_t currentSize = static_cast<size_t>(fileSize.QuadPart);
|
||||||
|
// Truncation / rotation detection. dragonxd shrinks debug.log on startup (ShrinkDebugFile keeps
|
||||||
|
// only the tail once it has grown large), so the file can become SMALLER than where we left off.
|
||||||
|
// Our offset was set to the PRE-shrink size at spawn, so without this reset it stays stranded ahead
|
||||||
|
// of the freshly-truncated file and we read NOTHING for the whole session — no block height (status
|
||||||
|
// bar shows "Block: 0") and, worse, no witness-rebuild progress, since the "Setting Initial Sapling
|
||||||
|
// Witness …" lines the warmup progress bar parses only exist in debug.log on Windows. On a shrink,
|
||||||
|
// restart from the new beginning; the parser is monotonic and converges as it reaches current output.
|
||||||
|
if (currentSize < debug_log_offset_) {
|
||||||
|
debug_log_offset_ = 0;
|
||||||
|
}
|
||||||
if (currentSize <= debug_log_offset_) {
|
if (currentSize <= debug_log_offset_) {
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
return; // No new data
|
return; // No new data
|
||||||
@@ -921,17 +1044,37 @@ bool EmbeddedDaemon::startProcess(const std::string& binary_path, const std::vec
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Self-pipe used purely as an exec-success/failure handshake, separate from
|
||||||
|
// the stdout pipe above. Both ends are close-on-exec, so a successful execv()
|
||||||
|
// closes the write end for free (parent reads EOF); on execv() failure the
|
||||||
|
// child writes errno here, so the parent learns synchronously instead of
|
||||||
|
// reporting State::Running for a child that never became dragonxd. We use
|
||||||
|
// pipe()+FD_CLOEXEC (not pipe2) because this POSIX branch is shared with
|
||||||
|
// macOS, which has no pipe2().
|
||||||
|
int execpipe[2];
|
||||||
|
if (pipe(execpipe) == -1) {
|
||||||
|
last_error_ = "Failed to create exec-status pipe: " + std::string(strerror(errno));
|
||||||
|
close(pipefd[0]);
|
||||||
|
close(pipefd[1]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fcntl(execpipe[0], F_SETFD, FD_CLOEXEC);
|
||||||
|
fcntl(execpipe[1], F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == -1) {
|
if (pid == -1) {
|
||||||
last_error_ = "Fork failed: " + std::string(strerror(errno));
|
last_error_ = "Fork failed: " + std::string(strerror(errno));
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
close(pipefd[1]);
|
close(pipefd[1]);
|
||||||
|
close(execpipe[0]);
|
||||||
|
close(execpipe[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
// Child process
|
// Child process
|
||||||
close(pipefd[0]); // Close read end
|
close(pipefd[0]); // Close read end of the stdout pipe
|
||||||
|
close(execpipe[0]); // Child only writes the exec-status pipe
|
||||||
|
|
||||||
// Put child in its own process group so we can kill the entire
|
// Put child in its own process group so we can kill the entire
|
||||||
// group later (including dragonxd spawned by a wrapper script).
|
// group later (including dragonxd spawned by a wrapper script).
|
||||||
@@ -998,17 +1141,56 @@ bool EmbeddedDaemon::startProcess(const std::string& binary_path, const std::vec
|
|||||||
execv(binary_path.c_str(), argv.data());
|
execv(binary_path.c_str(), argv.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here, exec failed
|
// If we get here, execv() failed — the child never became dragonxd.
|
||||||
fprintf(stderr, "execv failed: %s\n", strerror(errno));
|
// Capture errno before fprintf/strerror can clobber it, report it to
|
||||||
|
// the parent over the exec-status pipe (EINTR-safe), then exit.
|
||||||
|
int exec_errno = errno;
|
||||||
|
fprintf(stderr, "execv failed: %s\n", strerror(exec_errno));
|
||||||
|
ssize_t w;
|
||||||
|
do {
|
||||||
|
w = write(execpipe[1], &exec_errno, sizeof(exec_errno));
|
||||||
|
} while (w < 0 && errno == EINTR);
|
||||||
_exit(127);
|
_exit(127);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parent process
|
// Parent process
|
||||||
close(pipefd[1]); // Close write end
|
close(pipefd[1]); // Close our copy of the stdout write end
|
||||||
|
close(execpipe[1]); // Must close our copy, or the read() below never sees EOF
|
||||||
|
|
||||||
|
// Exec-status handshake: EOF => execv() succeeded (its write end was closed
|
||||||
|
// on exec); a full sizeof(int) => execv() failed and the child sent errno.
|
||||||
|
int child_errno = 0;
|
||||||
|
size_t got = 0;
|
||||||
|
char* ep = reinterpret_cast<char*>(&child_errno);
|
||||||
|
for (;;) {
|
||||||
|
ssize_t n = read(execpipe[0], ep + got, sizeof(child_errno) - got);
|
||||||
|
if (n == 0) break; // EOF: exec succeeded
|
||||||
|
if (n < 0) { if (errno == EINTR) continue; break; } // other error: assume success
|
||||||
|
got += static_cast<size_t>(n);
|
||||||
|
if (got >= sizeof(child_errno)) break; // full errno: exec failed
|
||||||
|
}
|
||||||
|
close(execpipe[0]);
|
||||||
|
|
||||||
|
if (got >= sizeof(child_errno)) {
|
||||||
|
// execv() never replaced the child; it fprintf'd and _exit(127)'d. Reap
|
||||||
|
// the already-dead zombie here — monitorProcess() is only started after
|
||||||
|
// this function returns true, so there is no competing reaper.
|
||||||
|
close(pipefd[0]);
|
||||||
|
int status;
|
||||||
|
waitpid(pid, &status, 0);
|
||||||
|
last_error_ = "dragonxd could not be executed: " + std::string(strerror(child_errno)) +
|
||||||
|
" — not executable or wrong architecture";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
stdout_fd_ = pipefd[0];
|
stdout_fd_ = pipefd[0];
|
||||||
|
|
||||||
// Also set process group from parent side (race with child's setpgid)
|
// Best-effort: the child already calls setpgid(0, 0); this parent-side call
|
||||||
setpgid(pid, pid);
|
// just closes the fork/exec race window. A failure here is not fatal to
|
||||||
|
// startup, so we log rather than abort.
|
||||||
|
if (setpgid(pid, pid) != 0) {
|
||||||
|
DEBUG_LOGF("[WARN] setpgid(%d) from parent failed: %s\n", (int)pid, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
// Set non-blocking
|
// Set non-blocking
|
||||||
int flags = fcntl(stdout_fd_, F_GETFL, 0);
|
int flags = fcntl(stdout_fd_, F_GETFL, 0);
|
||||||
@@ -1093,17 +1275,21 @@ double EmbeddedDaemon::getMemoryUsageMB() const
|
|||||||
|
|
||||||
bool EmbeddedDaemon::isRunning() const
|
bool EmbeddedDaemon::isRunning() const
|
||||||
{
|
{
|
||||||
|
// Read the atomic state_ instead of calling waitpid() here. monitorProcess()
|
||||||
|
// is the sole thread allowed to waitpid() process_pid_ during normal operation.
|
||||||
|
// Calling waitpid() from this method too (as it used to, and this is invoked
|
||||||
|
// from the UI thread nearly every frame) meant whichever thread reaped the
|
||||||
|
// child's exit first consumed the status; if isRunning() won that race,
|
||||||
|
// monitorProcess() never saw the exit, so crash_count_ / the decoded exit
|
||||||
|
// code / the State::Error transition were all silently lost. Mirrors the
|
||||||
|
// fix already in XmrigManager::isRunning().
|
||||||
if (process_pid_ <= 0) return false;
|
if (process_pid_ <= 0) return false;
|
||||||
|
|
||||||
int status;
|
const State s = state_.load(std::memory_order_relaxed);
|
||||||
pid_t result = waitpid(process_pid_, &status, WNOHANG);
|
// State::Stopping is included: stop()'s graceful/SIGTERM wait loops poll
|
||||||
|
// isRunning() while state_ == Stopping — before the process has actually
|
||||||
if (result == 0) {
|
// terminated — and must keep seeing "alive" to wait/escalate correctly.
|
||||||
// Still running
|
return (s == State::Running || s == State::Stopping);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmbeddedDaemon::drainOutput()
|
void EmbeddedDaemon::drainOutput()
|
||||||
@@ -1247,5 +1433,28 @@ bool EmbeddedDaemon::tcpPortInUse(int port)
|
|||||||
return isPortInUse(port);
|
return isPortInUse(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EmbeddedDaemon::isDaemonProcessRunning()
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
return findProcessByName("dragonxd.exe") != 0;
|
||||||
|
#elif defined(__linux__)
|
||||||
|
// Scan /proc for a process whose comm is exactly "dragonxd". Iterate with an error_code so a proc
|
||||||
|
// entry vanishing mid-scan (a process exiting) can't throw.
|
||||||
|
std::error_code ec;
|
||||||
|
fs::directory_iterator it("/proc", ec), end;
|
||||||
|
for (; !ec && it != end; it.increment(ec)) {
|
||||||
|
const std::string pid = it->path().filename().string();
|
||||||
|
if (pid.empty() || pid[0] < '0' || pid[0] > '9') continue; // numeric pid dirs only
|
||||||
|
std::ifstream f((it->path() / "comm").string());
|
||||||
|
std::string comm;
|
||||||
|
if (f && std::getline(f, comm) && comm == "dragonxd") return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
// macOS has no /proc; fall back to the RPC-port probe (best-effort).
|
||||||
|
return isPortInUse(std::atoi(DRAGONX_DEFAULT_RPC_PORT));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace daemon
|
} // namespace daemon
|
||||||
} // namespace dragonx
|
} // namespace dragonx
|
||||||
|
|||||||
@@ -79,7 +79,9 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Get last error message
|
* @brief Get last error message
|
||||||
*/
|
*/
|
||||||
const std::string& getLastError() const { return last_error_; }
|
// Copy under lock: last_error_ is written from the monitor thread (setState on an unexpected exit)
|
||||||
|
// while the UI thread reads it — a reference would be a torn-read / use-after-free race (M-04).
|
||||||
|
std::string getLastError() const { std::lock_guard<std::mutex> lk(error_mutex_); return last_error_; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get dragonxd process output (thread-safe copy)
|
* @brief Get dragonxd process output (thread-safe copy)
|
||||||
@@ -142,6 +144,10 @@ public:
|
|||||||
* When true the wallet should connect to it instead of showing an error.
|
* When true the wallet should connect to it instead of showing an error.
|
||||||
*/
|
*/
|
||||||
bool externalDaemonDetected() const { return external_daemon_detected_; }
|
bool externalDaemonDetected() const { return external_daemon_detected_; }
|
||||||
|
// Clear the adopted-external latch before relaunching our OWN process (e.g. a wallet switch that
|
||||||
|
// stopped the adopted daemon), so the freshly spawned daemon is treated as owned. start() also
|
||||||
|
// clears it on the port-free fall-through, but only if not short-circuited by an early guard.
|
||||||
|
void clearExternalDaemonDetected() { external_daemon_detected_ = false; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set callback for state changes
|
* @brief Set callback for state changes
|
||||||
@@ -176,6 +182,7 @@ public:
|
|||||||
* @brief Set maximum peer connections (0 = use daemon default)
|
* @brief Set maximum peer connections (0 = use daemon default)
|
||||||
*/
|
*/
|
||||||
void setMaxConnections(int v) { max_connections_ = v; }
|
void setMaxConnections(int v) { max_connections_ = v; }
|
||||||
|
void setStratumHosting(bool enabled, const std::string& allowIp) { stratum_enabled_ = enabled; stratum_allowip_ = allowIp; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Request a blockchain rescan on the next daemon start
|
* @brief Request a blockchain rescan on the next daemon start
|
||||||
@@ -197,6 +204,18 @@ public:
|
|||||||
void setZapOnNextStart(bool v) { zap_on_next_start_ = v; }
|
void setZapOnNextStart(bool v) { zap_on_next_start_ = v; }
|
||||||
bool zapOnNextStart() const { return zap_on_next_start_.load(); }
|
bool zapOnNextStart() const { return zap_on_next_start_.load(); }
|
||||||
|
|
||||||
|
// -salvagewallet: attempt to recover keys from a corrupt wallet.dat on startup (implies -rescan in
|
||||||
|
// the daemon). One-shot, consumed on the next start. Used to repair a wallet a switch flagged corrupt.
|
||||||
|
void setSalvageOnNextStart(bool v) { salvage_on_next_start_ = v; }
|
||||||
|
bool salvageOnNextStart() const { return salvage_on_next_start_.load(); }
|
||||||
|
|
||||||
|
// -reindex: rebuild the block index + chainstate from the raw blocks (blk*.dat) on startup. One-shot,
|
||||||
|
// consumed on the next start. Offered when the node aborts on an unreadable block database (a
|
||||||
|
// daemon-vs-chaindata format mismatch after an update, or a corrupt index). It implies a wallet
|
||||||
|
// rescan, so it's the block-DB analogue of -salvagewallet and coexists with the wallet-repair flags.
|
||||||
|
void setReindexOnNextStart(bool v) { reindex_on_next_start_ = v; }
|
||||||
|
bool reindexOnNextStart() const { return reindex_on_next_start_.load(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief One-shot isolated-datadir override for the NEXT start(): run the daemon against a
|
* @brief One-shot isolated-datadir override for the NEXT start(): run the daemon against a
|
||||||
* different datadir (with its own DRAGONX.conf) plus the given extra args. Used by the
|
* different datadir (with its own DRAGONX.conf) plus the given extra args. Used by the
|
||||||
@@ -217,6 +236,41 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setSkipPortCheck(bool v) { skip_port_check_ = v; }
|
void setSkipPortCheck(bool v) { skip_port_check_ = v; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief True while ANY dragonxd process is running (by process name), regardless of who started it.
|
||||||
|
* Unlike isRpcPortInUse()/isRunning(), this reflects the actual PROCESS still being alive — a
|
||||||
|
* graceful shutdown stops accepting RPC (port reads "free") but keeps the datadir lock until the
|
||||||
|
* process exits, which can take up to ~90s. Use this to know a stopped node has FULLY released
|
||||||
|
* the datadir before starting a replacement. Matches the daemon binary name on all platforms.
|
||||||
|
*/
|
||||||
|
static bool isDaemonProcessRunning();
|
||||||
|
|
||||||
|
/** Decision returned by evaluateDatadirLockGate(): whether start() may spawn now. */
|
||||||
|
struct StartLockGateDecision {
|
||||||
|
bool proceed = true; // false => bail before spawning
|
||||||
|
const char* errorMessage = ""; // set (a string literal) when proceed == false
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Pure decision for start(): bail because a previous dragonxd still holds the
|
||||||
|
* shared datadir lock? Isolated instances (skip_port_check_ / an active -datadir
|
||||||
|
* override) are exempt — they run their own throwaway datadir+port and can coexist
|
||||||
|
* with the main daemon. Does no process/fs I/O itself (the caller does the probing),
|
||||||
|
* so it is directly unit-testable; defined inline so tests need only this header.
|
||||||
|
*/
|
||||||
|
static StartLockGateDecision evaluateDatadirLockGate(bool skipPortCheck,
|
||||||
|
bool isolatedOverride,
|
||||||
|
bool stillRunningAfterWait)
|
||||||
|
{
|
||||||
|
if (skipPortCheck || isolatedOverride) return {true, ""};
|
||||||
|
if (stillRunningAfterWait) {
|
||||||
|
return {false,
|
||||||
|
"A previous dragonxd is still shutting down and holding the data "
|
||||||
|
"directory lock. Retrying shortly…"};
|
||||||
|
}
|
||||||
|
return {true, ""};
|
||||||
|
}
|
||||||
|
|
||||||
/** @brief Is an arbitrary TCP port currently in use on localhost? (used to pick a free port) */
|
/** @brief Is an arbitrary TCP port currently in use on localhost? (used to pick a free port) */
|
||||||
static bool tcpPortInUse(int port);
|
static bool tcpPortInUse(int port);
|
||||||
|
|
||||||
@@ -235,6 +289,7 @@ private:
|
|||||||
std::atomic<State> state_{State::Stopped};
|
std::atomic<State> state_{State::Stopped};
|
||||||
std::atomic<bool> external_daemon_detected_{false};
|
std::atomic<bool> external_daemon_detected_{false};
|
||||||
std::string last_error_;
|
std::string last_error_;
|
||||||
|
mutable std::mutex error_mutex_; // protects last_error_ (written by main + monitor threads)
|
||||||
mutable std::mutex output_mutex_; // protects process_output_
|
mutable std::mutex output_mutex_; // protects process_output_
|
||||||
std::string process_output_;
|
std::string process_output_;
|
||||||
StateCallback state_callback_;
|
StateCallback state_callback_;
|
||||||
@@ -257,10 +312,14 @@ private:
|
|||||||
std::atomic<bool> should_stop_{false};
|
std::atomic<bool> should_stop_{false};
|
||||||
std::set<std::string> debug_categories_;
|
std::set<std::string> debug_categories_;
|
||||||
int max_connections_ = 0; // 0 = daemon default
|
int max_connections_ = 0; // 0 = daemon default
|
||||||
|
bool stratum_enabled_ = false; // -stratum: host a RandomX pool (v1.3.0+; older daemons ignore it)
|
||||||
|
std::string stratum_allowip_; // -stratumallowip subnet (empty = daemon default: loopback only)
|
||||||
std::string wallet_file_; // -wallet=<name> for the active wallet; empty/"wallet.dat" = default
|
std::string wallet_file_; // -wallet=<name> for the active wallet; empty/"wallet.dat" = default
|
||||||
std::atomic<int> crash_count_{0}; // consecutive crash counter
|
std::atomic<int> crash_count_{0}; // consecutive crash counter
|
||||||
std::atomic<bool> rescan_on_next_start_{false}; // -rescan flag for next start
|
std::atomic<bool> rescan_on_next_start_{false}; // -rescan flag for next start
|
||||||
std::atomic<bool> zap_on_next_start_{false}; // -zapwallettxes=2 flag for next start
|
std::atomic<bool> zap_on_next_start_{false}; // -zapwallettxes=2 flag for next start
|
||||||
|
std::atomic<bool> salvage_on_next_start_{false}; // -salvagewallet flag for next start
|
||||||
|
std::atomic<bool> reindex_on_next_start_{false}; // -reindex flag for next start (rebuild block DB)
|
||||||
std::string override_datadir_; // one-shot: -datadir for the next start
|
std::string override_datadir_; // one-shot: -datadir for the next start
|
||||||
std::vector<std::string> override_extra_args_; // one-shot: extra args for the next start
|
std::vector<std::string> override_extra_args_; // one-shot: extra args for the next start
|
||||||
bool skip_port_check_ = false; // isolated instance on a non-default port
|
bool skip_port_check_ = false; // isolated instance on a non-default port
|
||||||
|
|||||||
@@ -54,6 +54,16 @@ SeedWalletResult SeedWalletCreator::create(bool keepDatadir,
|
|||||||
// RPC port. So the wallet lives in <base>/DRAGONX; `base` is the migration root we clean up.
|
// RPC port. So the wallet lives in <base>/DRAGONX; `base` is the migration root we clean up.
|
||||||
const std::string base = util::Platform::getConfigDir() + "/seed-migrate";
|
const std::string base = util::Platform::getConfigDir() + "/seed-migrate";
|
||||||
const std::string dataDir = base + "/DRAGONX";
|
const std::string dataDir = base + "/DRAGONX";
|
||||||
|
// W3-2: never blindly wipe a pre-existing temp seed wallet. A prior migration that swept funds into
|
||||||
|
// it but was abandoned or crashed before adopting would otherwise have its (fund-bearing) wallet
|
||||||
|
// destroyed here. A completed migration removes this dir on adopt, so a leftover means an unfinished
|
||||||
|
// one — refuse and point the user at it rather than silently destroying it.
|
||||||
|
if (fs::exists(dataDir + "/wallet.dat")) {
|
||||||
|
r.error = "A previous seed migration looks unfinished — its temporary wallet is still at\n" + base +
|
||||||
|
"\nResume or cancel it first. If you are certain its funds are already in your main "
|
||||||
|
"wallet, delete that folder and try again.";
|
||||||
|
return r;
|
||||||
|
}
|
||||||
fs::remove_all(base, ec);
|
fs::remove_all(base, ec);
|
||||||
fs::create_directories(dataDir, ec);
|
fs::create_directories(dataDir, ec);
|
||||||
if (ec) { r.error = "Could not create the temporary wallet directory."; return r; }
|
if (ec) { r.error = "Could not create the temporary wallet directory."; return r; }
|
||||||
@@ -110,9 +120,13 @@ SeedWalletResult SeedWalletCreator::create(bool keepDatadir,
|
|||||||
|
|
||||||
// 6. Export the new seed phrase + a fresh shielded receive address (the future sweep target).
|
// 6. Export the new seed phrase + a fresh shielded receive address (the future sweep target).
|
||||||
try {
|
try {
|
||||||
auto m = cli.call("z_exportmnemonic");
|
auto m = cli.callSecret("z_exportmnemonic"); // zero the raw body too (B7)
|
||||||
if (m.contains("mnemonic") && m["mnemonic"].is_string())
|
if (m.contains("mnemonic") && m["mnemonic"].is_string()) {
|
||||||
r.seedPhrase = m["mnemonic"].get<std::string>();
|
// Take our copy, then scrub the json node's own copy so it isn't freed in the clear (B7).
|
||||||
|
auto& mn = m["mnemonic"].get_ref<std::string&>();
|
||||||
|
r.seedPhrase = mn;
|
||||||
|
if (!mn.empty()) sodium_memzero(&mn[0], mn.size());
|
||||||
|
}
|
||||||
r.destAddress = cli.call("z_getnewaddress").get<std::string>();
|
r.destAddress = cli.call("z_getnewaddress").get<std::string>();
|
||||||
r.ok = !r.seedPhrase.empty() && !r.destAddress.empty();
|
r.ok = !r.seedPhrase.empty() && !r.destAddress.empty();
|
||||||
if (!r.ok) r.error = "The isolated node returned an empty seed or address.";
|
if (!r.ok) r.error = "The isolated node returned an empty seed or address.";
|
||||||
@@ -132,6 +146,14 @@ SeedWalletResult SeedWalletCreator::create(bool keepDatadir,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// W1-2: never hand back a live seed on a failure path. If the mnemonic was exported but a
|
||||||
|
// later step failed (empty address, or z_getnewaddress threw), the caller discards this
|
||||||
|
// result without wiping it, which would leave the seed resident. Success keeps it deliberately.
|
||||||
|
if (!r.ok && !r.seedPhrase.empty()) {
|
||||||
|
sodium_memzero(&r.seedPhrase[0], r.seedPhrase.size());
|
||||||
|
r.seedPhrase.clear();
|
||||||
|
}
|
||||||
|
|
||||||
// 7. Stop the isolated node (graceful; it flushes its tiny empty chain quickly).
|
// 7. Stop the isolated node (graceful; it flushes its tiny empty chain quickly).
|
||||||
cli.disconnect();
|
cli.disconnect();
|
||||||
temp.stop(20000);
|
temp.stop(20000);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// Copyright 2024-2026 The Hush Developers
|
// Copyright 2024-2026 The Hush Developers
|
||||||
// Released under the GPLv3
|
// Released under the GPLv3
|
||||||
//
|
//
|
||||||
// xmrig_manager.cpp — Pool mining process management via xmrig-hac.
|
// xmrig_manager.cpp — Pool mining process management via drg-xmrig.
|
||||||
// Spawns xmrig, monitors via HTTP API, tracks hashrate and shares.
|
// Spawns xmrig, monitors via HTTP API, tracks hashrate and shares.
|
||||||
|
|
||||||
#include "xmrig_manager.h"
|
#include "xmrig_manager.h"
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#include "../util/logger.h"
|
#include "../util/logger.h"
|
||||||
|
#include "../util/platform.h"
|
||||||
#include "../util/pool_registry.h"
|
#include "../util/pool_registry.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -89,8 +90,32 @@ static std::string getConfigDir() {
|
|||||||
// libcurl write callback
|
// libcurl write callback
|
||||||
static size_t curlWriteCb(void* ptr, size_t sz, size_t n, void* userdata) {
|
static size_t curlWriteCb(void* ptr, size_t sz, size_t n, void* userdata) {
|
||||||
auto* s = static_cast<std::string*>(userdata);
|
auto* s = static_cast<std::string*>(userdata);
|
||||||
s->append(static_cast<char*>(ptr), sz * n);
|
const size_t add = sz * n;
|
||||||
return sz * n;
|
// Stats JSON (local xmrig HTTP API + pool API) is tiny; refuse an unbounded body from a hostile or
|
||||||
|
// MITM'd endpoint so it can't grow this string until OOM. Returning < add aborts the transfer. (L-02)
|
||||||
|
constexpr size_t kMaxStatsBytes = 1u << 20; // 1 MiB
|
||||||
|
if (s->size() + add > kMaxStatsBytes) return 0;
|
||||||
|
s->append(static_cast<char*>(ptr), add);
|
||||||
|
return add;
|
||||||
|
}
|
||||||
|
|
||||||
|
// True if `host` (already stripped of scheme+port) is a loopback/private/link-local/single-label target
|
||||||
|
// that a public mining pool would never be — used to refuse a background stats GET to it (M-09).
|
||||||
|
static bool hostLooksInternal(const std::string& host) {
|
||||||
|
if (host.empty() || host == "localhost") return true;
|
||||||
|
if (host.rfind("127.", 0) == 0 || host.rfind("10.", 0) == 0 ||
|
||||||
|
host.rfind("192.168.", 0) == 0 || host.rfind("169.254.", 0) == 0) return true;
|
||||||
|
if (host.rfind("172.", 0) == 0) { // 172.16.0.0 - 172.31.255.255
|
||||||
|
const int second = std::atoi(host.c_str() + 4);
|
||||||
|
if (second >= 16 && second <= 31) return true;
|
||||||
|
}
|
||||||
|
if (host.find(':') != std::string::npos) { // IPv6 literal: loopback / ULA / link-local
|
||||||
|
if (host == "::1" || host.rfind("fc", 0) == 0 || host.rfind("fd", 0) == 0 ||
|
||||||
|
host.rfind("fe80", 0) == 0) return true;
|
||||||
|
}
|
||||||
|
if (host.size() >= 6 && host.compare(host.size() - 6, 6, ".local") == 0) return true;
|
||||||
|
if (host.find('.') == std::string::npos) return true; // bare single-label name = LAN/hosts, not a pool
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -100,9 +125,14 @@ static size_t curlWriteCb(void* ptr, size_t sz, size_t n, void* userdata) {
|
|||||||
XmrigManager::XmrigManager() = default;
|
XmrigManager::XmrigManager() = default;
|
||||||
|
|
||||||
XmrigManager::~XmrigManager() {
|
XmrigManager::~XmrigManager() {
|
||||||
|
should_stop_ = true;
|
||||||
if (isRunning()) {
|
if (isRunning()) {
|
||||||
stop(3000);
|
stop(3000);
|
||||||
}
|
}
|
||||||
|
// Join a monitor thread left joinable by an unexpected xmrig exit (State::Error, so isRunning() is
|
||||||
|
// false and stop() above was skipped) — std::thread's destructor would otherwise std::terminate(). (M-04)
|
||||||
|
if (monitor_thread_.joinable())
|
||||||
|
monitor_thread_.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -116,32 +146,18 @@ std::string XmrigManager::findXmrigBinary() {
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: system PATH
|
// Fallback: system PATH — windowless so it never flashes a console.
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
FILE* f = _popen("where xmrig.exe 2>nul", "r");
|
std::string out = util::Platform::runHiddenCapture("where xmrig.exe");
|
||||||
#else
|
#else
|
||||||
FILE* f = popen("which xmrig 2>/dev/null", "r");
|
std::string out = util::Platform::runHiddenCapture("which xmrig");
|
||||||
#endif
|
|
||||||
if (f) {
|
|
||||||
char line[512];
|
|
||||||
if (fgets(line, sizeof(line), f)) {
|
|
||||||
std::string s(line);
|
|
||||||
while (!s.empty() && (s.back() == '\n' || s.back() == '\r'))
|
|
||||||
s.pop_back();
|
|
||||||
if (!s.empty() && fs::exists(s)) {
|
|
||||||
#ifdef _WIN32
|
|
||||||
_pclose(f);
|
|
||||||
#else
|
|
||||||
pclose(f);
|
|
||||||
#endif
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef _WIN32
|
|
||||||
_pclose(f);
|
|
||||||
#else
|
|
||||||
pclose(f);
|
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
std::string s = out;
|
||||||
|
const auto nl = s.find_first_of("\r\n"); // first line only
|
||||||
|
if (nl != std::string::npos) s.erase(nl);
|
||||||
|
while (!s.empty() && (s.back() == ' ' || s.back() == '\t')) s.pop_back();
|
||||||
|
if (!s.empty() && fs::exists(s)) return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@@ -208,22 +224,43 @@ bool XmrigManager::generateConfig(const Config& cfg, const std::string& outPath)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
fs::create_directories(fs::path(outPath).parent_path());
|
fs::create_directories(fs::path(outPath).parent_path());
|
||||||
std::ofstream ofs(outPath);
|
const std::string dumped = j.dump(4);
|
||||||
if (!ofs.is_open()) {
|
#ifndef _WIN32
|
||||||
last_error_ = "Cannot write xmrig config: " + outPath;
|
// Create the config 0600 AT CREATION (open with mode) so the API token + wallet address are never
|
||||||
|
// in a world/group-readable file — even for a local attacker who opened it in the old
|
||||||
|
// create-then-chmod window and held the fd open across the chmod. (L-01)
|
||||||
|
int fd = ::open(outPath.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0600);
|
||||||
|
if (fd < 0) {
|
||||||
|
setLastError("Cannot write xmrig config: " + outPath);
|
||||||
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ofs << j.dump(4);
|
size_t off = 0;
|
||||||
ofs.close();
|
bool wrote = true;
|
||||||
|
while (off < dumped.size()) {
|
||||||
#ifndef _WIN32
|
ssize_t nw = ::write(fd, dumped.data() + off, dumped.size() - off);
|
||||||
// 0600 permissions — only owner can read/write
|
if (nw <= 0) { wrote = false; break; }
|
||||||
chmod(outPath.c_str(), 0600);
|
off += static_cast<size_t>(nw);
|
||||||
#endif
|
}
|
||||||
|
::close(fd);
|
||||||
|
if (!wrote) {
|
||||||
|
setLastError("Cannot write xmrig config: " + outPath);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
#else
|
||||||
|
std::ofstream ofs(outPath, std::ios::trunc);
|
||||||
|
if (!ofs.is_open()) {
|
||||||
|
setLastError("Cannot write xmrig config: " + outPath);
|
||||||
|
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ofs << dumped;
|
||||||
|
ofs.close();
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
last_error_ = std::string("Config write error: ") + e.what();
|
setLastError(std::string("Config write error: ") + e.what());
|
||||||
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -235,19 +272,22 @@ bool XmrigManager::generateConfig(const Config& cfg, const std::string& outPath)
|
|||||||
|
|
||||||
bool XmrigManager::start(const Config& cfg) {
|
bool XmrigManager::start(const Config& cfg) {
|
||||||
if (state_ == State::Running || state_ == State::Starting) {
|
if (state_ == State::Running || state_ == State::Starting) {
|
||||||
last_error_ = "Already running";
|
setLastError("Already running");
|
||||||
DEBUG_LOGF("[WARN] XmrigManager: %s\n", last_error_.c_str());
|
DEBUG_LOGF("[WARN] XmrigManager: %s\n", last_error_.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
state_ = State::Starting;
|
state_ = State::Starting;
|
||||||
should_stop_ = false;
|
should_stop_ = false;
|
||||||
last_error_.clear();
|
setLastError(std::string());
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lk(output_mutex_);
|
std::lock_guard<std::mutex> lk(output_mutex_);
|
||||||
process_output_.clear();
|
process_output_.clear();
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(stats_mutex_);
|
||||||
stats_ = PoolStats{};
|
stats_ = PoolStats{};
|
||||||
|
}
|
||||||
|
|
||||||
// Extract pool hostname for stats API queries
|
// Extract pool hostname for stats API queries
|
||||||
{
|
{
|
||||||
@@ -264,7 +304,7 @@ bool XmrigManager::start(const Config& cfg) {
|
|||||||
// Find binary
|
// Find binary
|
||||||
std::string binary = findXmrigBinary();
|
std::string binary = findXmrigBinary();
|
||||||
if (binary.empty()) {
|
if (binary.empty()) {
|
||||||
last_error_ = "xmrig binary not found";
|
setLastError("xmrig binary not found");
|
||||||
state_ = State::Error;
|
state_ = State::Error;
|
||||||
DEBUG_LOGF("[ERROR] XmrigManager: xmrig binary not found\n");
|
DEBUG_LOGF("[ERROR] XmrigManager: xmrig binary not found\n");
|
||||||
return false;
|
return false;
|
||||||
@@ -292,7 +332,11 @@ bool XmrigManager::start(const Config& cfg) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start monitor thread
|
// Join a prior monitor thread before move-assigning: if xmrig exited unexpectedly, monitorProcess set
|
||||||
|
// State::Error and returned, leaving monitor_thread_ joinable — move-assigning over a joinable
|
||||||
|
// std::thread calls std::terminate() and aborts the whole wallet. (M-04)
|
||||||
|
if (monitor_thread_.joinable())
|
||||||
|
monitor_thread_.join();
|
||||||
monitor_thread_ = std::thread(&XmrigManager::monitorProcess, this);
|
monitor_thread_ = std::thread(&XmrigManager::monitorProcess, this);
|
||||||
state_ = State::Running;
|
state_ = State::Running;
|
||||||
DEBUG_LOGF("[INFO] XmrigManager: started\n");
|
DEBUG_LOGF("[INFO] XmrigManager: started\n");
|
||||||
@@ -367,7 +411,7 @@ bool XmrigManager::startProcess(const std::string& xmrigPath, const std::string&
|
|||||||
|
|
||||||
HANDLE hRead = nullptr, hWrite = nullptr;
|
HANDLE hRead = nullptr, hWrite = nullptr;
|
||||||
if (!CreatePipe(&hRead, &hWrite, &sa, 0)) {
|
if (!CreatePipe(&hRead, &hWrite, &sa, 0)) {
|
||||||
last_error_ = "CreatePipe failed";
|
setLastError("CreatePipe failed");
|
||||||
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -399,7 +443,7 @@ bool XmrigManager::startProcess(const std::string& xmrigPath, const std::string&
|
|||||||
char errBuf[256];
|
char errBuf[256];
|
||||||
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
NULL, err, 0, errBuf, sizeof(errBuf), NULL);
|
NULL, err, 0, errBuf, sizeof(errBuf), NULL);
|
||||||
last_error_ = "CreateProcess failed for xmrig (error " + std::to_string(err) + "): " + errBuf;
|
setLastError("CreateProcess failed for xmrig (error " + std::to_string(err) + "): " + errBuf);
|
||||||
DEBUG_LOGF("[ERROR] XmrigManager: %s\nCommand: %s\n", last_error_.c_str(), cmdLine.c_str());
|
DEBUG_LOGF("[ERROR] XmrigManager: %s\nCommand: %s\n", last_error_.c_str(), cmdLine.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -450,14 +494,14 @@ void XmrigManager::drainOutput() {
|
|||||||
bool XmrigManager::startProcess(const std::string& xmrigPath, const std::string& cfgPath, int threads) {
|
bool XmrigManager::startProcess(const std::string& xmrigPath, const std::string& cfgPath, int threads) {
|
||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
if (pipe(pipefd) != 0) {
|
if (pipe(pipefd) != 0) {
|
||||||
last_error_ = "pipe() failed";
|
setLastError("pipe() failed");
|
||||||
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
last_error_ = "fork() failed";
|
setLastError("fork() failed");
|
||||||
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
DEBUG_LOGF("[ERROR] XmrigManager: %s\n", last_error_.c_str());
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
close(pipefd[1]);
|
close(pipefd[1]);
|
||||||
@@ -628,7 +672,7 @@ void XmrigManager::monitorProcess() {
|
|||||||
if (GetExitCodeProcess(process_handle_, &exitCode) && exitCode != STILL_ACTIVE) {
|
if (GetExitCodeProcess(process_handle_, &exitCode) && exitCode != STILL_ACTIVE) {
|
||||||
DEBUG_LOGF("[ERROR] XmrigManager: process exited (code %lu)\n", exitCode);
|
DEBUG_LOGF("[ERROR] XmrigManager: process exited (code %lu)\n", exitCode);
|
||||||
state_ = State::Error;
|
state_ = State::Error;
|
||||||
last_error_ = "xmrig process exited unexpectedly";
|
setLastError("xmrig process exited unexpectedly");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -639,7 +683,7 @@ void XmrigManager::monitorProcess() {
|
|||||||
if (ret == process_pid_ || ret < 0) {
|
if (ret == process_pid_ || ret < 0) {
|
||||||
DEBUG_LOGF("[ERROR] XmrigManager: process exited (waitpid=%d)\n", ret);
|
DEBUG_LOGF("[ERROR] XmrigManager: process exited (waitpid=%d)\n", ret);
|
||||||
state_ = State::Error;
|
state_ = State::Error;
|
||||||
last_error_ = "xmrig process exited unexpectedly";
|
setLastError("xmrig process exited unexpectedly");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -779,6 +823,11 @@ void XmrigManager::fetchPoolApiStats() {
|
|||||||
// own API shape (pool.dragonx.is = custom /api/stats; pool.dragonx.cc = Miningcore
|
// own API shape (pool.dragonx.is = custom /api/stats; pool.dragonx.cc = Miningcore
|
||||||
// /api/pools); unknown/custom hosts fall back to the .is convention.
|
// /api/pools); unknown/custom hosts fall back to the .is convention.
|
||||||
const util::KnownPool* known = util::findKnownPoolByUrl(pool_host_);
|
const util::KnownPool* known = util::findKnownPoolByUrl(pool_host_);
|
||||||
|
// SSRF guard: for an UNKNOWN (user-typed) pool host, don't let the wallet issue a background GET to a
|
||||||
|
// loopback/private/link-local/single-label target — those aren't public mining pools, and a
|
||||||
|
// paste-a-pool-config lure could otherwise point us at an internal host. Known pools use their trusted
|
||||||
|
// registry statsUrl and are exempt. (M-09)
|
||||||
|
if (!known && hostLooksInternal(pool_host_)) return;
|
||||||
const std::string url = known ? known->statsUrl
|
const std::string url = known ? known->statsUrl
|
||||||
: ("https://" + pool_host_ + "/api/stats");
|
: ("https://" + pool_host_ + "/api/stats");
|
||||||
|
|
||||||
@@ -857,25 +906,18 @@ void XmrigManager::startVersionDetection()
|
|||||||
std::thread([]() {
|
std::thread([]() {
|
||||||
const std::string bin = findXmrigBinary();
|
const std::string bin = findXmrigBinary();
|
||||||
std::string ver;
|
std::string ver;
|
||||||
if (!bin.empty()) {
|
// Don't hand a path containing shell/cmd metacharacters to popen()'s shell — bin is normally an
|
||||||
const std::string cmd = "\"" + bin + "\" --version 2>&1";
|
// app-controlled path, but this closes command injection if it ever isn't. (M-10)
|
||||||
#ifdef _WIN32
|
// Reject only chars that stay shell-special INSIDE the double-quotes we wrap bin in ("\"" + bin + "\"")
|
||||||
FILE* fp = _popen(cmd.c_str(), "r");
|
// on cmd.exe or /bin/sh. Parens are inert when quoted, so they're excluded — otherwise common Windows
|
||||||
#else
|
// paths like "C:\Program Files (x86)\..." would be rejected and version detection would silently fail. (M-10)
|
||||||
FILE* fp = popen(cmd.c_str(), "r");
|
const bool binShellSafe =
|
||||||
#endif
|
!bin.empty() && bin.find_first_of("\"'`$;&|<>^%\n\r") == std::string::npos;
|
||||||
if (fp) {
|
if (binShellSafe) {
|
||||||
std::string out;
|
// Windowless capture (mergeStderr: xmrig may print --version to stderr) — never flashes.
|
||||||
char buf[256];
|
const std::string cmd = "\"" + bin + "\" --version";
|
||||||
size_t n;
|
const std::string out = util::Platform::runHiddenCapture(cmd, /*mergeStderr=*/true);
|
||||||
while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) out.append(buf, n);
|
if (!out.empty()) ver = parseMinerVersion(out);
|
||||||
#ifdef _WIN32
|
|
||||||
_pclose(fp);
|
|
||||||
#else
|
|
||||||
pclose(fp);
|
|
||||||
#endif
|
|
||||||
ver = parseMinerVersion(out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
std::lock_guard<std::mutex> lk(g_installed_ver_mutex);
|
std::lock_guard<std::mutex> lk(g_installed_ver_mutex);
|
||||||
g_installed_ver = ver;
|
g_installed_ver = ver;
|
||||||
|
|||||||
@@ -86,8 +86,10 @@ public:
|
|||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
State getState() const { return state_.load(std::memory_order_relaxed); }
|
State getState() const { return state_.load(std::memory_order_relaxed); }
|
||||||
|
|
||||||
const PoolStats& getStats() const { return stats_; }
|
// Return COPIES under lock: stats_ and last_error_ are mutated by the monitor thread while the UI
|
||||||
const std::string& getLastError() const { return last_error_; }
|
// thread reads them, so handing out a reference is a torn-read / use-after-free race (M-03, M-04).
|
||||||
|
PoolStats getStats() const { std::lock_guard<std::mutex> lk(stats_mutex_); return stats_; }
|
||||||
|
std::string getLastError() const { std::lock_guard<std::mutex> lk(error_mutex_); return last_error_; }
|
||||||
|
|
||||||
/// Thread count requested at start() — available immediately, unlike
|
/// Thread count requested at start() — available immediately, unlike
|
||||||
/// PoolStats::threads_active which requires an API response.
|
/// PoolStats::threads_active which requires an API response.
|
||||||
@@ -156,11 +158,14 @@ private:
|
|||||||
void monitorProcess();
|
void monitorProcess();
|
||||||
void drainOutput();
|
void drainOutput();
|
||||||
void appendOutput(const char* data, size_t len);
|
void appendOutput(const char* data, size_t len);
|
||||||
|
// Set last_error_ under error_mutex_ (writers run on both the main thread and the monitor thread).
|
||||||
|
void setLastError(std::string e) { std::lock_guard<std::mutex> lk(error_mutex_); last_error_ = std::move(e); }
|
||||||
void fetchStatsHttp(); // Blocking HTTP call — runs on monitor thread only
|
void fetchStatsHttp(); // Blocking HTTP call — runs on monitor thread only
|
||||||
void fetchPoolApiStats(); // Fetch pool-side stats (hashrate) from pool HTTP API
|
void fetchPoolApiStats(); // Fetch pool-side stats (hashrate) from pool HTTP API
|
||||||
|
|
||||||
std::atomic<State> state_{State::Stopped};
|
std::atomic<State> state_{State::Stopped};
|
||||||
std::string last_error_;
|
std::string last_error_;
|
||||||
|
mutable std::mutex error_mutex_; // guards last_error_ (written by main + monitor threads)
|
||||||
|
|
||||||
mutable std::mutex output_mutex_;
|
mutable std::mutex output_mutex_;
|
||||||
std::string process_output_;
|
std::string process_output_;
|
||||||
|
|||||||
@@ -46,7 +46,12 @@ bool AddressBook::load()
|
|||||||
entries_.clear();
|
entries_.clear();
|
||||||
|
|
||||||
if (j.contains("entries") && j["entries"].is_array()) {
|
if (j.contains("entries") && j["entries"].is_array()) {
|
||||||
|
size_t skipped = 0;
|
||||||
for (const auto& entry : j["entries"]) {
|
for (const auto& entry : j["entries"]) {
|
||||||
|
// W6-3: skip (and count) a malformed element rather than letting one bad entry throw and
|
||||||
|
// abort the whole load — which would discard EVERY contact (entries_ was already cleared).
|
||||||
|
if (!entry.is_object()) { ++skipped; continue; }
|
||||||
|
try {
|
||||||
AddressBookEntry e;
|
AddressBookEntry e;
|
||||||
e.label = entry.value("label", "");
|
e.label = entry.value("label", "");
|
||||||
e.address = entry.value("address", "");
|
e.address = entry.value("address", "");
|
||||||
@@ -55,14 +60,15 @@ bool AddressBook::load()
|
|||||||
// multi-wallet scoping lands — a contact you already had stays visible everywhere.
|
// multi-wallet scoping lands — a contact you already had stays visible everywhere.
|
||||||
e.scope = entry.value("scope", "global");
|
e.scope = entry.value("scope", "global");
|
||||||
e.avatar = entry.value("avatar", "");
|
e.avatar = entry.value("avatar", "");
|
||||||
|
if (!e.address.empty()) entries_.push_back(e);
|
||||||
if (!e.address.empty()) {
|
} catch (const std::exception&) { ++skipped; }
|
||||||
entries_.push_back(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (skipped > 0)
|
||||||
|
DEBUG_LOGF("Address book: skipped %zu malformed entr%s\n", skipped, skipped == 1 ? "y" : "ies");
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_LOGF("Address book loaded: %zu entries\n", entries_.size());
|
DEBUG_LOGF("Address book loaded: %zu entries\n", entries_.size());
|
||||||
|
++revision_;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
@@ -116,6 +122,7 @@ bool AddressBook::addEntry(const AddressBookEntry& entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries_.push_back(entry);
|
entries_.push_back(entry);
|
||||||
|
++revision_;
|
||||||
return save();
|
return save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +138,7 @@ bool AddressBook::updateEntry(size_t index, const AddressBookEntry& entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries_[index] = entry;
|
entries_[index] = entry;
|
||||||
|
++revision_;
|
||||||
return save();
|
return save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,9 +149,24 @@ bool AddressBook::removeEntry(size_t index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries_.erase(entries_.begin() + index);
|
entries_.erase(entries_.begin() + index);
|
||||||
|
++revision_;
|
||||||
return save();
|
return save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AddressBook::reattachLegacyScopes(const std::string& scopeId)
|
||||||
|
{
|
||||||
|
if (scopeId.empty()) return 0;
|
||||||
|
int rescoped = 0;
|
||||||
|
for (auto& e : entries_) {
|
||||||
|
if (e.isGlobal()) continue; // global stays global
|
||||||
|
if (e.scope.rfind("w:", 0) == 0) continue; // already a stable scope
|
||||||
|
e.scope = scopeId;
|
||||||
|
++rescoped;
|
||||||
|
}
|
||||||
|
if (rescoped > 0) { ++revision_; save(); }
|
||||||
|
return rescoped;
|
||||||
|
}
|
||||||
|
|
||||||
int AddressBook::findByAddress(const std::string& address) const
|
int AddressBook::findByAddress(const std::string& address) const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < entries_.size(); i++) {
|
for (size_t i = 0; i < entries_.size(); i++) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -86,6 +87,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool removeEntry(size_t index);
|
bool removeEntry(size_t index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Re-attach contacts stuck on a legacy (drifting address-hash) scope to a stable wallet id.
|
||||||
|
* Rewrites every non-global entry whose scope is NOT already a stable "w:"-prefixed id to
|
||||||
|
* `scopeId`, and saves once if anything changed. Recovery for contacts orphaned when the
|
||||||
|
* old address-set-hash scope shifted (e.g. after creating a new address).
|
||||||
|
* @return number of entries re-scoped.
|
||||||
|
*/
|
||||||
|
int reattachLegacyScopes(const std::string& scopeId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Find entry by address (any scope). Used for contact-label lookups.
|
* @brief Find entry by address (any scope). Used for contact-label lookups.
|
||||||
* @param address Address to search for
|
* @param address Address to search for
|
||||||
@@ -112,11 +122,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
size_t size() const { return entries_.size(); }
|
size_t size() const { return entries_.size(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Monotonic counter bumped on every content change (add/update/remove/load/sweep). Consumers
|
||||||
|
* (e.g. the chat conversation-list memo) key their caches off this so an IN-PLACE edit — a rename or
|
||||||
|
* address change that keeps size() constant — still invalidates them.
|
||||||
|
*/
|
||||||
|
std::uint64_t revision() const { return revision_; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief UI-sweep ONLY: replace the in-memory entries WITHOUT persisting to disk, so the sweep can
|
* @brief UI-sweep ONLY: replace the in-memory entries WITHOUT persisting to disk, so the sweep can
|
||||||
* seed demo contacts and restore the real book without a disk write. Do not use outside the sweep.
|
* seed demo contacts and restore the real book without a disk write. Do not use outside the sweep.
|
||||||
*/
|
*/
|
||||||
void sweepSetEntries(std::vector<AddressBookEntry> e) { entries_ = std::move(e); }
|
void sweepSetEntries(std::vector<AddressBookEntry> e) { entries_ = std::move(e); ++revision_; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if empty
|
* @brief Check if empty
|
||||||
@@ -125,6 +142,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<AddressBookEntry> entries_;
|
std::vector<AddressBookEntry> entries_;
|
||||||
|
std::uint64_t revision_ = 0;
|
||||||
std::string file_path_;
|
std::string file_path_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
37
src/data/seed_migration_resume.h
Normal file
37
src/data/seed_migration_resume.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// Pure routing decision for resuming a pending migrate-to-seed flow (finding W3-3). Kept free of
|
||||||
|
// App/UI/RPC state so the highest-risk branch — where a reopened migration lands — is unit-testable
|
||||||
|
// and reviewable in isolation. App::showSeedMigrationDialog feeds it the persisted state + live
|
||||||
|
// connectivity and switches on the result. See src/app_network.cpp.
|
||||||
|
namespace dragonx {
|
||||||
|
|
||||||
|
enum class MigrationResume {
|
||||||
|
Intro, // no pending migration → start fresh at the intro
|
||||||
|
Confirming, // a sweep txid is persisted → resume at the confirm/adopt gate (re-derived from chain)
|
||||||
|
RetrackOpid, // a sweep opid (but no txid yet) is persisted AND we're connected → re-poll it
|
||||||
|
SweepGate, // otherwise → the dismissable Sweep step (reload balance, offer re-sweep)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Decide where reopening the migration dialog lands.
|
||||||
|
//
|
||||||
|
// Invariant: the txid outranks the opid — once a sweep resolves to a txid the opid is cleared in the
|
||||||
|
// same settings write, so a persisted txid always means "past the sweep". A persisted opid is only
|
||||||
|
// re-tracked when connected, because the buttonless "Sweeping" spinner relies on the opid poller
|
||||||
|
// (which needs an RPC connection) to ever exit; disconnected, we fall back to the dismissable Sweep
|
||||||
|
// gate (which reloads the balance and, if the earlier sweep already drained it, short-circuits to
|
||||||
|
// adopt) — never trapping the user.
|
||||||
|
inline MigrationResume decideSeedMigrationResume(bool pending,
|
||||||
|
bool haveDest,
|
||||||
|
const std::string& sweepTxid,
|
||||||
|
const std::string& sweepOpid,
|
||||||
|
bool connected) {
|
||||||
|
if (!pending || !haveDest) return MigrationResume::Intro;
|
||||||
|
if (!sweepTxid.empty()) return MigrationResume::Confirming;
|
||||||
|
if (!sweepOpid.empty() && connected) return MigrationResume::RetrackOpid;
|
||||||
|
return MigrationResume::SweepGate;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dragonx
|
||||||
@@ -25,6 +25,7 @@ bool sameEntry(const WalletIndexEntry& a, const WalletIndexEntry& b)
|
|||||||
return a.fileName == b.fileName
|
return a.fileName == b.fileName
|
||||||
&& a.displayName == b.displayName
|
&& a.displayName == b.displayName
|
||||||
&& a.walletIdentityHash == b.walletIdentityHash
|
&& a.walletIdentityHash == b.walletIdentityHash
|
||||||
|
&& a.scopeId == b.scopeId
|
||||||
&& a.cachedBalance == b.cachedBalance
|
&& a.cachedBalance == b.cachedBalance
|
||||||
&& a.cachedAddressCount == b.cachedAddressCount
|
&& a.cachedAddressCount == b.cachedAddressCount
|
||||||
&& a.lastOpenedEpoch == b.lastOpenedEpoch
|
&& a.lastOpenedEpoch == b.lastOpenedEpoch
|
||||||
@@ -61,6 +62,7 @@ bool WalletIndex::load()
|
|||||||
if (w.fileName.empty()) continue;
|
if (w.fileName.empty()) continue;
|
||||||
w.displayName = e.value("name", w.fileName);
|
w.displayName = e.value("name", w.fileName);
|
||||||
w.walletIdentityHash = e.value("identity", "");
|
w.walletIdentityHash = e.value("identity", "");
|
||||||
|
w.scopeId = e.value("scopeId", "");
|
||||||
w.cachedBalance = e.value("balance", -1.0);
|
w.cachedBalance = e.value("balance", -1.0);
|
||||||
w.cachedAddressCount = e.value("addresses", (long long)-1);
|
w.cachedAddressCount = e.value("addresses", (long long)-1);
|
||||||
w.lastOpenedEpoch = e.value("lastOpened", (long long)0);
|
w.lastOpenedEpoch = e.value("lastOpened", (long long)0);
|
||||||
@@ -96,6 +98,7 @@ bool WalletIndex::save()
|
|||||||
e["file"] = w.fileName;
|
e["file"] = w.fileName;
|
||||||
e["name"] = w.displayName;
|
e["name"] = w.displayName;
|
||||||
e["identity"] = w.walletIdentityHash;
|
e["identity"] = w.walletIdentityHash;
|
||||||
|
e["scopeId"] = w.scopeId;
|
||||||
e["balance"] = w.cachedBalance;
|
e["balance"] = w.cachedBalance;
|
||||||
e["addresses"] = w.cachedAddressCount;
|
e["addresses"] = w.cachedAddressCount;
|
||||||
e["lastOpened"] = w.lastOpenedEpoch;
|
e["lastOpened"] = w.lastOpenedEpoch;
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ struct WalletIndexEntry {
|
|||||||
std::string fileName; // plain wallet filename in the datadir (e.g. "wallet.dat")
|
std::string fileName; // plain wallet filename in the datadir (e.g. "wallet.dat")
|
||||||
std::string displayName; // user-facing name (defaults to fileName)
|
std::string displayName; // user-facing name (defaults to fileName)
|
||||||
std::string walletIdentityHash; // address-derived identity of the last load; "" = unknown
|
std::string walletIdentityHash; // address-derived identity of the last load; "" = unknown
|
||||||
|
std::string scopeId; // stable per-wallet id ("w:"+hex) for scoping contacts etc.;
|
||||||
|
// generated once, never recomputed from the (mutable) address set
|
||||||
double cachedBalance = -1.0; // last-known total balance; < 0 = unknown (never opened)
|
double cachedBalance = -1.0; // last-known total balance; < 0 = unknown (never opened)
|
||||||
long long cachedAddressCount = -1;// < 0 = unknown
|
long long cachedAddressCount = -1;// < 0 = unknown
|
||||||
long long lastOpenedEpoch = 0; // unix seconds of last open; 0 = never opened
|
long long lastOpenedEpoch = 0; // unix seconds of last open; 0 = never opened
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// Released under the GPLv3
|
// Released under the GPLv3
|
||||||
|
|
||||||
#include "wallet_state.h"
|
#include "wallet_state.h"
|
||||||
|
#include "../util/text_format.h" // util::formatClockDateTime (app-wide 24h/12h clock)
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -18,12 +19,13 @@ std::vector<size_t> sortedSpendableAddressIndices(const std::vector<AddressInfo>
|
|||||||
for (size_t i = 0; i < addresses.size(); ++i) {
|
for (size_t i = 0; i < addresses.size(); ++i) {
|
||||||
const auto& address = addresses[i];
|
const auto& address = addresses[i];
|
||||||
if (!address.isSpendable()) continue;
|
if (!address.isSpendable()) continue;
|
||||||
if (requirePositiveBalance && address.balance <= 0.0) continue;
|
// Rank/filter by the CONFIRMED balance — an address holding only 0-conf change can't be sent from.
|
||||||
|
if (requirePositiveBalance && address.spendableBalance <= 0.0) continue;
|
||||||
indices.push_back(i);
|
indices.push_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(indices.begin(), indices.end(), [&](size_t lhs, size_t rhs) {
|
std::sort(indices.begin(), indices.end(), [&](size_t lhs, size_t rhs) {
|
||||||
return addresses[lhs].balance > addresses[rhs].balance;
|
return addresses[lhs].spendableBalance > addresses[rhs].spendableBalance;
|
||||||
});
|
});
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
@@ -33,8 +35,8 @@ int bestSpendableAddressIndex(const std::vector<AddressInfo>& addresses)
|
|||||||
int bestIndex = -1;
|
int bestIndex = -1;
|
||||||
double bestBalance = 0.0;
|
double bestBalance = 0.0;
|
||||||
for (size_t i = 0; i < addresses.size(); ++i) {
|
for (size_t i = 0; i < addresses.size(); ++i) {
|
||||||
if (addresses[i].isSpendable() && addresses[i].balance > bestBalance) {
|
if (addresses[i].isSpendable() && addresses[i].spendableBalance > bestBalance) {
|
||||||
bestBalance = addresses[i].balance;
|
bestBalance = addresses[i].spendableBalance;
|
||||||
bestIndex = static_cast<int>(i);
|
bestIndex = static_cast<int>(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,13 +46,7 @@ int bestSpendableAddressIndex(const std::vector<AddressInfo>& addresses)
|
|||||||
std::string TransactionInfo::getTimeString() const
|
std::string TransactionInfo::getTimeString() const
|
||||||
{
|
{
|
||||||
if (timestamp == 0) return "Unknown";
|
if (timestamp == 0) return "Unknown";
|
||||||
|
return util::formatClockDateTime(timestamp);
|
||||||
std::time_t t = static_cast<std::time_t>(timestamp);
|
|
||||||
std::tm* tm = std::localtime(&t);
|
|
||||||
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << std::put_time(tm, "%Y-%m-%d %H:%M");
|
|
||||||
return ss.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TransactionInfo::getTypeDisplay() const
|
std::string TransactionInfo::getTypeDisplay() const
|
||||||
@@ -77,13 +73,7 @@ std::string PeerInfo::getConnectionTime() const
|
|||||||
std::string BannedPeer::getBannedUntilString() const
|
std::string BannedPeer::getBannedUntilString() const
|
||||||
{
|
{
|
||||||
if (banned_until == 0) return "Never";
|
if (banned_until == 0) return "Never";
|
||||||
|
return util::formatClockDateTime(banned_until);
|
||||||
std::time_t t = static_cast<std::time_t>(banned_until);
|
|
||||||
std::tm* tm = std::localtime(&t);
|
|
||||||
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << std::put_time(tm, "%Y-%m-%d %H:%M");
|
|
||||||
return ss.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dragonx
|
} // namespace dragonx
|
||||||
|
|||||||
@@ -21,13 +21,17 @@ namespace dragonx {
|
|||||||
*/
|
*/
|
||||||
struct AddressInfo {
|
struct AddressInfo {
|
||||||
std::string address;
|
std::string address;
|
||||||
double balance = 0.0;
|
double balance = 0.0; // DISPLAY total incl. pending 0-conf change (minconf=0)
|
||||||
std::string type; // "shielded" or "transparent"
|
std::string type; // "shielded" or "transparent"
|
||||||
bool has_spending_key = true; // false for view-only (imported via z_importviewingkey)
|
bool has_spending_key = true; // false for view-only (imported via z_importviewingkey)
|
||||||
|
|
||||||
// For display
|
// For display
|
||||||
std::string label;
|
std::string label;
|
||||||
|
|
||||||
|
// CONFIRMED balance (minconf>=1) — what z_sendmany can actually spend now. Kept last so positional
|
||||||
|
// brace-init of the leading fields (used in tests) still compiles.
|
||||||
|
double spendableBalance = 0.0;
|
||||||
|
|
||||||
// Derived
|
// Derived
|
||||||
bool isZAddr() const { return !address.empty() && address[0] == 'z'; }
|
bool isZAddr() const { return !address.empty() && address[0] == 'z'; }
|
||||||
bool isShielded() const { return type == "shielded"; }
|
bool isShielded() const { return type == "shielded"; }
|
||||||
@@ -252,11 +256,17 @@ struct WalletState {
|
|||||||
// Sync status
|
// Sync status
|
||||||
SyncInfo sync;
|
SyncInfo sync;
|
||||||
|
|
||||||
// Balances (named to match UI usage)
|
// Balances (named to match UI usage). These are the DISPLAY totals — minconf=0, so they include the
|
||||||
double privateBalance = 0.0; // shielded balance
|
// user's own pending change and don't crater during an unconfirmed send.
|
||||||
|
double privateBalance = 0.0; // shielded balance (display, incl. pending change)
|
||||||
double transparentBalance = 0.0;
|
double transparentBalance = 0.0;
|
||||||
double totalBalance = 0.0;
|
double totalBalance = 0.0;
|
||||||
double unconfirmedBalance = 0.0;
|
double unconfirmedBalance = 0.0; // = totalBalance - spendableTotalBalance (the pending portion)
|
||||||
|
// CONFIRMED / spendable totals (minconf>=1) — what can actually be sent right now. z_sendmany runs at
|
||||||
|
// minconf=1, so the Send form / Max / spend validation must size off these, never the display totals.
|
||||||
|
double spendablePrivateBalance = 0.0;
|
||||||
|
double spendableTransparentBalance = 0.0;
|
||||||
|
double spendableTotalBalance = 0.0;
|
||||||
|
|
||||||
// Aliases for backward compatibility
|
// Aliases for backward compatibility
|
||||||
double& shielded_balance = privateBalance;
|
double& shielded_balance = privateBalance;
|
||||||
@@ -302,6 +312,7 @@ struct WalletState {
|
|||||||
|
|
||||||
// Timestamps for refresh logic
|
// Timestamps for refresh logic
|
||||||
int64_t last_balance_update = 0;
|
int64_t last_balance_update = 0;
|
||||||
|
int64_t last_address_update = 0; // set when an address-list refresh applies; 0 = never loaded yet
|
||||||
int64_t last_tx_update = 0;
|
int64_t last_tx_update = 0;
|
||||||
int64_t last_peer_update = 0;
|
int64_t last_peer_update = 0;
|
||||||
int64_t last_mining_update = 0;
|
int64_t last_mining_update = 0;
|
||||||
@@ -325,6 +336,7 @@ struct WalletState {
|
|||||||
sync = SyncInfo{};
|
sync = SyncInfo{};
|
||||||
privateBalance = transparentBalance = totalBalance = 0.0;
|
privateBalance = transparentBalance = totalBalance = 0.0;
|
||||||
unconfirmedBalance = 0.0;
|
unconfirmedBalance = 0.0;
|
||||||
|
spendablePrivateBalance = spendableTransparentBalance = spendableTotalBalance = 0.0;
|
||||||
encrypted = false;
|
encrypted = false;
|
||||||
locked = false;
|
locked = false;
|
||||||
unlocked_until = 0;
|
unlocked_until = 0;
|
||||||
@@ -335,6 +347,15 @@ struct WalletState {
|
|||||||
transactions.clear();
|
transactions.clear();
|
||||||
peers.clear();
|
peers.clear();
|
||||||
bannedPeers.clear();
|
bannedPeers.clear();
|
||||||
|
// W6-1: reset node-level mining state too — the daemon restarts on a wallet switch (mining
|
||||||
|
// stops), so leaving the previous wallet's hashrate/blocks would show stale mining stats.
|
||||||
|
mining = MiningInfo{};
|
||||||
|
pool_mining = PoolMiningState{};
|
||||||
|
// After a disconnect / wallet switch nothing is freshly known, so drop the "last successful
|
||||||
|
// refresh" stamps. Otherwise the pre-teardown time survives and, on reconnect, the staleness
|
||||||
|
// badge (and any "updated X ago" reader) briefly reports it as current until the first refresh
|
||||||
|
// re-stamps it. All readers treat 0 as "never" (formatTimeAgoShort/timeAgo return "").
|
||||||
|
last_balance_update = last_address_update = last_tx_update = last_peer_update = last_mining_update = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rebuild combined addresses list from z/t lists
|
// Rebuild combined addresses list from z/t lists
|
||||||
|
|||||||
@@ -15,3 +15,5 @@ INCBIN(ubuntu_mono, "@CMAKE_SOURCE_DIR@/res/fonts/UbuntuMono-R.ttf");
|
|||||||
INCBIN(material_icons, "@CMAKE_SOURCE_DIR@/res/fonts/MaterialIcons-Regular.ttf");
|
INCBIN(material_icons, "@CMAKE_SOURCE_DIR@/res/fonts/MaterialIcons-Regular.ttf");
|
||||||
INCBIN(mdi_pickaxe_subset, "@CMAKE_SOURCE_DIR@/res/fonts/MaterialDesignIcons-Pickaxe-Subset.ttf");
|
INCBIN(mdi_pickaxe_subset, "@CMAKE_SOURCE_DIR@/res/fonts/MaterialDesignIcons-Pickaxe-Subset.ttf");
|
||||||
INCBIN(noto_cjk_subset, "@CMAKE_SOURCE_DIR@/res/fonts/NotoSansCJK-Subset.ttf");
|
INCBIN(noto_cjk_subset, "@CMAKE_SOURCE_DIR@/res/fonts/NotoSansCJK-Subset.ttf");
|
||||||
|
INCBIN(noto_emoji_subset, "@CMAKE_SOURCE_DIR@/res/fonts/NotoEmoji-Subset.ttf");
|
||||||
|
INCBIN(twemoji_color, "@CMAKE_SOURCE_DIR@/res/fonts/TwemojiMozilla-Color.ttf");
|
||||||
|
|||||||
@@ -35,4 +35,11 @@ extern "C" {
|
|||||||
|
|
||||||
extern const unsigned char g_noto_cjk_subset_data[];
|
extern const unsigned char g_noto_cjk_subset_data[];
|
||||||
extern const unsigned int g_noto_cjk_subset_size;
|
extern const unsigned int g_noto_cjk_subset_size;
|
||||||
|
|
||||||
|
extern const unsigned char g_noto_emoji_subset_data[];
|
||||||
|
extern const unsigned int g_noto_emoji_subset_size;
|
||||||
|
|
||||||
|
// Twemoji COLR/CPAL color-emoji font (used only when color emoji is enabled + FreeType is available).
|
||||||
|
extern const unsigned char g_twemoji_color_data[];
|
||||||
|
extern const unsigned int g_twemoji_color_size;
|
||||||
}
|
}
|
||||||
|
|||||||
39
src/embedded/logo_dragonx_svg.h
Normal file
39
src/embedded/logo_dragonx_svg.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
// DragonX Wallet - ImGui Edition
|
||||||
|
// Copyright 2024-2026 The Hush Developers
|
||||||
|
// Released under the GPLv3
|
||||||
|
//
|
||||||
|
// Embedded source of the DragonX mark (res/img/logos/logo_dragonx.svg). Kept as a string so the logo
|
||||||
|
// is available in every build (dev + portable single-file) with no resource-pipeline or file dependency.
|
||||||
|
// It is rasterized + recolored per theme at runtime (see util/svg_texture.*). Two fills: the crimson
|
||||||
|
// body (.cls-2 #d82652) becomes the theme accent; the white detail (.cls-1 #fff) becomes the light tone.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Global `embedded` namespace to match the generated embedded resources (embedded::ui_toml_data, etc.).
|
||||||
|
namespace embedded {
|
||||||
|
|
||||||
|
inline constexpr const char* kLogoDragonXSvg = R"SVG(<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
|
||||||
|
<defs>
|
||||||
|
<style>
|
||||||
|
.cls-1 {
|
||||||
|
fill: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cls-2 {
|
||||||
|
fill: #d82652;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</defs>
|
||||||
|
<path class="cls-2" d="M103.98,128s-6.29-24.7-18.73-34.43c-8.53-8.03-15.63-16.49-21.25-24.16-5.62,7.68-12.72,16.17-21.25,24.16-12.4,9.74-18.73,34.43-18.73,34.43-2.38-24.34,7.85-35.82,12.87-41.29,7.82-8.5,15.31-16.56,21.75-25.02-7.64-11.44-11.41-19.72-11.41-19.72-.89-3.27-3.84-6.64-3.84-6.64,6.08-8.1-1.6-16.98-1.6-16.98,5.79-5.62,6.71-10.02,8.32-18.34-1.96,22.35,4.02,39.09,13.93,54.12,9.84-15.03,15.81-31.77,13.86-54.12,1.6,8.35,2.52,12.72,8.32,18.34,0,0-7.68,8.88-1.6,16.98,0,0-2.95,3.38-3.84,6.64,0,0-3.77,8.28-11.37,19.72,6.43,8.45,13.97,16.56,21.75,25.02,4.97,5.47,15.21,16.95,12.83,41.29h0Z"/>
|
||||||
|
<g>
|
||||||
|
<path class="cls-1" d="M55.33,61.62c-3.55,4.55-7.39,8.99-11.44,13.47-5.29-4.48-11.23-5.33-11.23-5.33,22.92-7.82,2.81-15.17.28-16.31C9.28,42.78,9.1,14.78,9.1,14.78c11.51,34.15,36.42,32.3,36.42,32.3.35-.21.67-.46.92-.71,1.64,3.27,4.58,8.67,8.88,15.24h0Z"/>
|
||||||
|
<g>
|
||||||
|
<path class="cls-1" d="M68.62,40.41c-1.35,2.98-2.91,5.83-4.62,8.63-1.71-2.81-3.23-5.69-4.62-8.63,1.74-3.45,4.62-20.58,4.62-20.58,0,0,2.88,17.13,4.62,20.58Z"/>
|
||||||
|
<path class="cls-1" d="M76.01,97.93l-3.48,2.34s-.1-4.44-3.52-1.84c-.42.32-2.38,2.21-.03,4.27,0,0-4.05,4.08-4.97,8.21-.92-4.12-4.97-8.21-4.97-8.21,2.34-2.06.39-3.95-.03-4.27-3.41-2.59-3.52,1.84-3.52,1.84l-3.48-2.34c.28-3.55.1-6.68-.46-9.42,4.69-4.94,8.85-9.88,12.47-14.61,3.66,4.72,7.78,9.67,12.47,14.61-.57,2.74-.75,5.86-.46,9.42Z"/>
|
||||||
|
<path class="cls-1" d="M95.34,69.76s-5.94.85-11.23,5.33c-4.02-4.48-7.89-8.92-11.44-13.47,4.3-6.57,7.25-11.98,8.88-15.24.25.25.57.5.92.71,0,0,24.91,1.84,36.42-32.3,0,0-.18,28-23.84,38.66-2.52,1.14-22.64,8.5.28,16.31h0Z"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>)SVG";
|
||||||
|
|
||||||
|
} // namespace embedded
|
||||||
175
src/main.cpp
175
src/main.cpp
@@ -439,8 +439,16 @@ static bool InitImGui(SDL_Window* window, SDL_GLContext gl_context);
|
|||||||
static void Shutdown(SDL_Window* window, SDL_GLContext gl_context);
|
static void Shutdown(SDL_Window* window, SDL_GLContext gl_context);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Global single instance lock
|
// Global single instance lock. Keyed PER VARIANT so the full node and Lite can run side by side —
|
||||||
|
// their config dirs are already separate (DRAGONX_APP_NAME), so only this lock kept them apart.
|
||||||
|
// NB: DRAGONX_LITE_BUILD is ALWAYS defined (0 for the full node, 1 for Lite) via $<BOOL:...>, so this
|
||||||
|
// must be #if (value), not #ifdef (existence) — #ifdef is true for both and made the full node grab
|
||||||
|
// the Lite lock.
|
||||||
|
#if DRAGONX_LITE_BUILD
|
||||||
|
static dragonx::util::SingleInstance g_single_instance("obsidiandragonlite");
|
||||||
|
#else
|
||||||
static dragonx::util::SingleInstance g_single_instance("obsidiandragon");
|
static dragonx::util::SingleInstance g_single_instance("obsidiandragon");
|
||||||
|
#endif
|
||||||
|
|
||||||
// Check for payment URI in command line args
|
// Check for payment URI in command line args
|
||||||
static std::string findPaymentURI(int argc, char* argv[])
|
static std::string findPaymentURI(int argc, char* argv[])
|
||||||
@@ -713,20 +721,105 @@ static void handleDisplayScaleChange(SDL_Window* window, float newScale,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
#include <csignal>
|
||||||
|
#include <cstring>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#if defined(__has_include)
|
||||||
|
# if __has_include(<execinfo.h>)
|
||||||
|
# include <execinfo.h>
|
||||||
|
# define DRAGONX_HAVE_BACKTRACE 1
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Absolute path to the crash log, filled at install time so the async-signal handler needs no
|
||||||
|
// allocation. (POSIX counterpart of the Windows SEH CrashHandler above — W7-3.)
|
||||||
|
static char g_crashLogPath[1024] = {0};
|
||||||
|
|
||||||
|
// Async-signal-safe crash handler: only open()/write()/backtrace_symbols_fd()/raise() are used —
|
||||||
|
// no stdio, std::filesystem or malloc (all unsafe inside a signal handler).
|
||||||
|
static void PosixCrashHandler(int sig)
|
||||||
|
{
|
||||||
|
int fd = g_crashLogPath[0] ? open(g_crashLogPath, O_WRONLY | O_CREAT | O_APPEND, 0600) : -1;
|
||||||
|
if (fd >= 0) {
|
||||||
|
auto put = [fd](const char* s) { ssize_t n = write(fd, s, std::strlen(s)); (void)n; };
|
||||||
|
put("\n=== CRASH: signal ");
|
||||||
|
char num[16]; int i = 0, v = sig; // signal number -> decimal, no stdio
|
||||||
|
if (v == 0) { num[i++] = '0'; }
|
||||||
|
else { char tmp[16]; int t = 0; while (v > 0) { tmp[t++] = char('0' + v % 10); v /= 10; }
|
||||||
|
while (t > 0) num[i++] = tmp[--t]; }
|
||||||
|
num[i] = '\n';
|
||||||
|
ssize_t nn = write(fd, num, i + 1); (void)nn;
|
||||||
|
#ifdef DRAGONX_HAVE_BACKTRACE
|
||||||
|
void* frames[64];
|
||||||
|
int nframes = backtrace(frames, 64);
|
||||||
|
backtrace_symbols_fd(frames, nframes, fd); // async-signal-safe
|
||||||
|
#endif
|
||||||
|
put("=== END CRASH ===\n");
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
// Restore the default disposition and re-raise so we still get a core dump / normal termination.
|
||||||
|
signal(sig, SIG_DFL);
|
||||||
|
raise(sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void installPosixCrashHandler(const std::string& crashLogPath)
|
||||||
|
{
|
||||||
|
std::snprintf(g_crashLogPath, sizeof(g_crashLogPath), "%s", crashLogPath.c_str());
|
||||||
|
struct sigaction sa;
|
||||||
|
std::memset(&sa, 0, sizeof(sa));
|
||||||
|
sa.sa_handler = PosixCrashHandler;
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_flags = 0;
|
||||||
|
for (int sig : {SIGSEGV, SIGABRT, SIGBUS, SIGFPE, SIGILL}) {
|
||||||
|
sigaction(sig, &sa, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // !_WIN32
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// Ensure ObsidianDragon config directory exists early (before any file I/O)
|
// Ensure ObsidianDragon config directory exists early (before any file I/O)
|
||||||
{
|
{
|
||||||
std::string odDir = dragonx::util::Platform::getObsidianDragonDir();
|
std::string odDir = dragonx::util::Platform::getObsidianDragonDir();
|
||||||
std::error_code ec;
|
std::string odErr;
|
||||||
std::filesystem::create_directories(odDir, ec);
|
if (!dragonx::util::Platform::ensureDirectory(odDir, &odErr)) {
|
||||||
|
// Pre-App-init: nothing (ini, logs, config) can persist if this fails, and the
|
||||||
|
// Windows log redirect below isn't set up yet — report loudly before any setup.
|
||||||
|
std::fprintf(stderr, "%s\n", odErr.c_str());
|
||||||
|
#ifdef _WIN32
|
||||||
|
MessageBoxA(nullptr, odErr.c_str(), DRAGONX_APP_NAME, MB_OK | MB_ICONERROR);
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
// W7-2: initialize the app-level Logger's file sink on ALL platforms so LOG/LOGF/VERBOSE_LOGF are
|
||||||
// Redirect stdout/stderr to a log file so diagnostic output is visible
|
// actually persisted to dragonx-debug.log. Previously init() was never called, so on Linux/macOS the
|
||||||
// even when built as a GUI app (WIN32_EXECUTABLE hides the console).
|
// file never existed at all (the Windows-only stdout freopen below is a separate mechanism).
|
||||||
{
|
{
|
||||||
std::string logPath = (std::filesystem::path(dragonx::util::Platform::getObsidianDragonDir()) / "dragonx-debug.log").string();
|
const std::string logPath =
|
||||||
|
(std::filesystem::path(dragonx::util::Platform::getObsidianDragonDir()) / "dragonx-debug.log").string();
|
||||||
|
dragonx::util::Logger::instance().init(logPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
// W7-3: install the POSIX crash handler (the Windows SEH filter is installed below). A segfault or
|
||||||
|
// abort now leaves a backtrace in dragonx-crash.log instead of vanishing silently on Linux/macOS.
|
||||||
|
{
|
||||||
|
const std::string crashPath =
|
||||||
|
(std::filesystem::path(dragonx::util::Platform::getObsidianDragonDir()) / "dragonx-crash.log").string();
|
||||||
|
installPosixCrashHandler(crashPath);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Redirect raw stdout/stderr (library / daemon-pipe writes) to a log file so it's visible even when
|
||||||
|
// built as a GUI app (WIN32_EXECUTABLE hides the console). Separate file from the structured Logger
|
||||||
|
// above so the two writers don't interleave/contend on one file.
|
||||||
|
{
|
||||||
|
std::string logPath = (std::filesystem::path(dragonx::util::Platform::getObsidianDragonDir()) / "dragonx-stdout.log").string();
|
||||||
freopen(logPath.c_str(), "w", stdout);
|
freopen(logPath.c_str(), "w", stdout);
|
||||||
freopen(logPath.c_str(), "a", stderr);
|
freopen(logPath.c_str(), "a", stderr);
|
||||||
}
|
}
|
||||||
@@ -764,11 +857,12 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// Check for existing instance
|
// Check for existing instance
|
||||||
if (!g_single_instance.tryLock()) {
|
if (!g_single_instance.tryLock()) {
|
||||||
fprintf(stderr, "Another instance of ObsidianDragon is already running.\n");
|
fprintf(stderr, "Another instance of %s is already running.\n", DRAGONX_APP_NAME);
|
||||||
DEBUG_LOGF("Please close the existing instance first.\n");
|
DEBUG_LOGF("Please close the existing instance first.\n");
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
MessageBoxW(nullptr, L"Another instance of ObsidianDragon is already running.\nPlease close it first.",
|
const std::string msg = std::string("Another instance of ") + DRAGONX_APP_NAME +
|
||||||
L"ObsidianDragon", MB_OK | MB_ICONINFORMATION);
|
" is already running.\nPlease close it first.";
|
||||||
|
MessageBoxA(nullptr, msg.c_str(), DRAGONX_APP_NAME, MB_OK | MB_ICONINFORMATION);
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -1169,6 +1263,36 @@ int main(int argc, char* argv[])
|
|||||||
SDL_SetWindowMinimumSize(window, (int)(1024 * currentDpiScale), (int)(720 * currentDpiScale));
|
SDL_SetWindowMinimumSize(window, (int)(1024 * currentDpiScale), (int)(720 * currentDpiScale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DEV/TEST hook (dormant unless the env is set): DRAGONX_WIN_GEOM="WxH" forces an exact window
|
||||||
|
// size, placing it on the largest display that can hold it and bypassing the primary-monitor
|
||||||
|
// clamp. Lets a headless WSLg sweep render at sizes wider than the 1280 primary (e.g. 2560x1440
|
||||||
|
// on the mirrored 4K/1440p outputs). Needs the x11 backend so absolute positioning takes effect.
|
||||||
|
int wantW = 0, wantH = 0;
|
||||||
|
if (const char* geom = std::getenv("DRAGONX_WIN_GEOM"))
|
||||||
|
sscanf(geom, "%dx%d", &wantW, &wantH);
|
||||||
|
if (wantW > 0 && wantH > 0) {
|
||||||
|
int count = 0;
|
||||||
|
SDL_DisplayID* disp = SDL_GetDisplays(&count);
|
||||||
|
SDL_DisplayID best = 0; SDL_Rect bestUsable{0, 0, 0, 0};
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
|
SDL_Rect u;
|
||||||
|
if (!SDL_GetDisplayUsableBounds(disp[i], &u)) continue;
|
||||||
|
bool fits = (u.w >= wantW && u.h >= wantH);
|
||||||
|
bool bestFits = (bestUsable.w >= wantW && bestUsable.h >= wantH);
|
||||||
|
// Prefer a display that fits; among those, the smallest; else the largest available.
|
||||||
|
if ((fits && !bestFits) ||
|
||||||
|
(fits && bestFits && (long)u.w * u.h < (long)bestUsable.w * bestUsable.h) ||
|
||||||
|
(!fits && !bestFits && (long)u.w * u.h > (long)bestUsable.w * bestUsable.h)) {
|
||||||
|
bestUsable = u; best = disp[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (disp) SDL_free(disp);
|
||||||
|
if (best) {
|
||||||
|
SDL_SetWindowMinimumSize(window, 320, 240);
|
||||||
|
SDL_SetWindowPosition(window, bestUsable.x + 10, bestUsable.y + 10);
|
||||||
|
SDL_SetWindowSize(window, wantW, wantH);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// Clamp to the current display's work area — runs on EVERY startup (this clamp used to live
|
// Clamp to the current display's work area — runs on EVERY startup (this clamp used to live
|
||||||
// inside the HiDPI branch, so a size saved on a larger/disconnected monitor could open the
|
// inside the HiDPI branch, so a size saved on a larger/disconnected monitor could open the
|
||||||
// window off-screen or bigger than the screen on a same-DPI cold start).
|
// window off-screen or bigger than the screen on a same-DPI cold start).
|
||||||
@@ -1188,6 +1312,7 @@ int main(int argc, char* argv[])
|
|||||||
curW, curH, newW, newH, currentDpiScale);
|
curW, curH, newW, newH, currentDpiScale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
winlog("STARTUP savedSize=%dx%d currentDpiScale=%.3f", savedWinW, savedWinH, currentDpiScale);
|
winlog("STARTUP savedSize=%dx%d currentDpiScale=%.3f", savedWinW, savedWinH, currentDpiScale);
|
||||||
winlogState(window, " startup");
|
winlogState(window, " startup");
|
||||||
@@ -1375,6 +1500,7 @@ int main(int argc, char* argv[])
|
|||||||
// WINDOW_RESIZED events during the transition can't corrupt savedSizeForScale / lastKnownW/H.
|
// WINDOW_RESIZED events during the transition can't corrupt savedSizeForScale / lastKnownW/H.
|
||||||
int dpiSettleFrames = 0;
|
int dpiSettleFrames = 0;
|
||||||
SDL_DisplayID lastLoggedDisplay = 0; // [WINLOG] throttle: log MOVED only when the display changes
|
SDL_DisplayID lastLoggedDisplay = 0; // [WINLOG] throttle: log MOVED only when the display changes
|
||||||
|
Uint64 minimizedLastTickMs = 0; // real-clock tick for the minimized "keep syncing" update
|
||||||
{
|
{
|
||||||
float s = dragonx::ui::material::Typography::instance().getDpiScale();
|
float s = dragonx::ui::material::Typography::instance().getDpiScale();
|
||||||
int w = 0, h = 0;
|
int w = 0, h = 0;
|
||||||
@@ -1458,6 +1584,7 @@ int main(int argc, char* argv[])
|
|||||||
// Window restored from minimized — trigger immediate data refresh
|
// Window restored from minimized — trigger immediate data refresh
|
||||||
if (waitEvent.type == SDL_EVENT_WINDOW_RESTORED &&
|
if (waitEvent.type == SDL_EVENT_WINDOW_RESTORED &&
|
||||||
waitEvent.window.windowID == SDL_GetWindowID(window)) {
|
waitEvent.window.windowID == SDL_GetWindowID(window)) {
|
||||||
|
app.skipDaemonOutputBacklog(); // drop the minimized-period backlog (avoids a spurious "rescan complete" toast)
|
||||||
app.refreshNow();
|
app.refreshNow();
|
||||||
}
|
}
|
||||||
// Handle DPI change that arrived while idle (same logic as poll loop)
|
// Handle DPI change that arrived while idle (same logic as poll loop)
|
||||||
@@ -1587,6 +1714,7 @@ int main(int argc, char* argv[])
|
|||||||
// Window restored from minimized — trigger immediate data refresh
|
// Window restored from minimized — trigger immediate data refresh
|
||||||
if (event.type == SDL_EVENT_WINDOW_RESTORED &&
|
if (event.type == SDL_EVENT_WINDOW_RESTORED &&
|
||||||
event.window.windowID == SDL_GetWindowID(window)) {
|
event.window.windowID == SDL_GetWindowID(window)) {
|
||||||
|
app.skipDaemonOutputBacklog(); // drop the minimized-period backlog (avoids a spurious "rescan complete" toast)
|
||||||
app.refreshNow();
|
app.refreshNow();
|
||||||
}
|
}
|
||||||
// Handle DPI/display scale changes (e.g. window dragged to a
|
// Handle DPI/display scale changes (e.g. window dragged to a
|
||||||
@@ -1607,13 +1735,28 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// Check if window is minimized
|
// Check if window is minimized
|
||||||
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
|
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
|
||||||
// Still check shouldQuit while minimized to avoid hang
|
// Keep the wallet syncing while minimized: run the logic update (drains RPC results, ticks the
|
||||||
if (app.shouldQuit()) {
|
// refresh scheduler, keeps the daemon connection/reconnect + sync status live) but skip the
|
||||||
running = false;
|
// ImGui frame + GPU present since nothing is visible. app.update() only reads
|
||||||
}
|
// GetIO()/GetTime()/IsAnyItemActive() — all valid outside a frame — so it's safe without a
|
||||||
SDL_Delay(10);
|
// NewFrame; feed it a real-clock DeltaTime (NewFrame, which normally sets it, is skipped) and
|
||||||
|
// let app.update() clamp it. Throttled to ~5 Hz so CPU stays near-idle (refresh cadences are
|
||||||
|
// seconds-scale). shouldQuit is still checked so a quit request never hangs behind minimize.
|
||||||
|
Uint64 nowMs = SDL_GetTicks();
|
||||||
|
float minDelta = (minimizedLastTickMs == 0) ? 0.001f
|
||||||
|
: (float)(nowMs - minimizedLastTickMs) / 1000.0f;
|
||||||
|
minimizedLastTickMs = nowMs;
|
||||||
|
ImGui::GetIO().DeltaTime = (minDelta > 0.0f) ? minDelta : 0.001f;
|
||||||
|
try {
|
||||||
|
app.update();
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
DEBUG_LOGF("[Main] minimized app.update() threw: %s\n", e.what());
|
||||||
|
} catch (...) {}
|
||||||
|
if (app.shouldQuit()) running = false;
|
||||||
|
SDL_Delay(200);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
minimizedLastTickMs = 0; // visible again — reset the minimized clock
|
||||||
|
|
||||||
// --- PerfLog: begin frame ---
|
// --- PerfLog: begin frame ---
|
||||||
dragonx::util::PerfLog::instance().beginFrame();
|
dragonx::util::PerfLog::instance().beginFrame();
|
||||||
@@ -1966,6 +2109,7 @@ int main(int argc, char* argv[])
|
|||||||
bool backdropNeedsFrames = (backdrop_active || app.getGradientTexture() != 0)
|
bool backdropNeedsFrames = (backdrop_active || app.getGradientTexture() != 0)
|
||||||
&& !opaqueBackground;
|
&& !opaqueBackground;
|
||||||
bool animating = app.isShuttingDown()
|
bool animating = app.isShuttingDown()
|
||||||
|
|| app.isWalletSwitchInProgress()
|
||||||
|| backdropNeedsFrames
|
|| backdropNeedsFrames
|
||||||
|| app.hasTransactionSendProgress()
|
|| app.hasTransactionSendProgress()
|
||||||
|| app.isTransactionRefreshInProgress()
|
|| app.isTransactionRefreshInProgress()
|
||||||
@@ -2032,6 +2176,7 @@ int main(int argc, char* argv[])
|
|||||||
// deadlocks waiting for detached pthreads. On Linux, static
|
// deadlocks waiting for detached pthreads. On Linux, static
|
||||||
// destructors and atexit handlers can also block. _Exit() bypasses
|
// destructors and atexit handlers can also block. _Exit() bypasses
|
||||||
// all of that.
|
// all of that.
|
||||||
|
app.wipeSecrets(); // _Exit() below bypasses ~App(), so scrub secret buffers here (L-05)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
_Exit(0);
|
_Exit(0);
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ static const EmbeddedResource s_resources[] = {
|
|||||||
{ g_dragonx_cli_exe_data, g_dragonx_cli_exe_size, RESOURCE_DRAGONX_CLI },
|
{ g_dragonx_cli_exe_data, g_dragonx_cli_exe_size, RESOURCE_DRAGONX_CLI },
|
||||||
{ g_dragonx_tx_exe_data, g_dragonx_tx_exe_size, RESOURCE_DRAGONX_TX },
|
{ g_dragonx_tx_exe_data, g_dragonx_tx_exe_size, RESOURCE_DRAGONX_TX },
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAS_EMBEDDED_WALLET_REBUILD
|
||||||
|
{ g_dragonx_wallet_rebuild_exe_data, g_dragonx_wallet_rebuild_exe_size, RESOURCE_DRAGONX_WALLET_REBUILD },
|
||||||
|
#endif
|
||||||
#ifdef HAS_EMBEDDED_XMRIG
|
#ifdef HAS_EMBEDDED_XMRIG
|
||||||
{ g_xmrig_exe_data, g_xmrig_exe_size, RESOURCE_XMRIG },
|
{ g_xmrig_exe_data, g_xmrig_exe_size, RESOURCE_XMRIG },
|
||||||
#endif
|
#endif
|
||||||
@@ -436,6 +439,24 @@ bool extractEmbeddedResources()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_EMBEDDED_WALLET_REBUILD
|
||||||
|
// Offline wallet-rebuild recovery helper — extracted next to the daemon so a bare, self-extracting
|
||||||
|
// ObsidianDragon.exe still offers "Repair automatically" (findWalletRebuildHelper() checks this dir).
|
||||||
|
const EmbeddedResource* rebuildRes = getEmbeddedResource(RESOURCE_DRAGONX_WALLET_REBUILD);
|
||||||
|
if (rebuildRes) {
|
||||||
|
std::string dest = daemonDir + pathSep + RESOURCE_DRAGONX_WALLET_REBUILD;
|
||||||
|
if (!std::filesystem::exists(dest)) {
|
||||||
|
DEBUG_LOGF("[INFO] Extracting dragonx-wallet-rebuild (%zu MB)...\n", rebuildRes->size / (1024*1024));
|
||||||
|
if (!extractResource(rebuildRes, dest)) {
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
#ifndef _WIN32
|
||||||
|
else { chmod(dest.c_str(), 0755); }
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Best-effort cleanup of any ".old" binaries left behind by a previous in-use replacement.
|
// Best-effort cleanup of any ".old" binaries left behind by a previous in-use replacement.
|
||||||
// Once the old daemon/xmrig process has exited, the file is no longer locked and removes cleanly;
|
// Once the old daemon/xmrig process has exited, the file is no longer locked and removes cleanly;
|
||||||
// if it's still running, the remove fails harmlessly and we retry on the next startup.
|
// if it's still running, the remove fails harmlessly and we retry on the next startup.
|
||||||
@@ -450,6 +471,32 @@ bool extractEmbeddedResources()
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ensureWalletRebuildHelperExtracted()
|
||||||
|
{
|
||||||
|
#ifdef HAS_EMBEDDED_WALLET_REBUILD
|
||||||
|
const EmbeddedResource* res = getEmbeddedResource(RESOURCE_DRAGONX_WALLET_REBUILD);
|
||||||
|
if (!res || res->size == 0) return {};
|
||||||
|
#ifdef _WIN32
|
||||||
|
const char sep = '\\';
|
||||||
|
#else
|
||||||
|
const char sep = '/';
|
||||||
|
#endif
|
||||||
|
const std::string dir = getDaemonDirectory();
|
||||||
|
const std::string dest = dir + sep + RESOURCE_DRAGONX_WALLET_REBUILD;
|
||||||
|
std::error_code ec;
|
||||||
|
if (std::filesystem::exists(dest, ec)) return dest; // already extracted
|
||||||
|
std::filesystem::create_directories(dir, ec);
|
||||||
|
if (!extractResource(res, dest)) return {};
|
||||||
|
#ifndef _WIN32
|
||||||
|
chmod(dest.c_str(), 0755);
|
||||||
|
#endif
|
||||||
|
DEBUG_LOGF("[INFO] Extracted wallet-rebuild helper on demand: %s\n", dest.c_str());
|
||||||
|
return dest;
|
||||||
|
#else
|
||||||
|
return {};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
std::string getDaemonDirectory()
|
std::string getDaemonDirectory()
|
||||||
{
|
{
|
||||||
// Daemon binaries live in %APPDATA%/ObsidianDragon/dragonx/ (Windows) or
|
// Daemon binaries live in %APPDATA%/ObsidianDragon/dragonx/ (Windows) or
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ BundledDaemonInfo getBundledDaemonInfo();
|
|||||||
// caller should stop the daemon first. Returns true if all present resources were written.
|
// caller should stop the daemon first. Returns true if all present resources were written.
|
||||||
bool reextractBundledDaemon();
|
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
|
// Resource names
|
||||||
constexpr const char* RESOURCE_SAPLING_SPEND = "sapling-spend.params";
|
constexpr const char* RESOURCE_SAPLING_SPEND = "sapling-spend.params";
|
||||||
constexpr const char* RESOURCE_SAPLING_OUTPUT = "sapling-output.params";
|
constexpr const char* RESOURCE_SAPLING_OUTPUT = "sapling-output.params";
|
||||||
@@ -62,6 +68,7 @@ constexpr const char* RESOURCE_ASMAP = "asmap.dat";
|
|||||||
constexpr const char* RESOURCE_DRAGONXD = "dragonxd.exe";
|
constexpr const char* RESOURCE_DRAGONXD = "dragonxd.exe";
|
||||||
constexpr const char* RESOURCE_DRAGONX_CLI = "dragonx-cli.exe";
|
constexpr const char* RESOURCE_DRAGONX_CLI = "dragonx-cli.exe";
|
||||||
constexpr const char* RESOURCE_DRAGONX_TX = "dragonx-tx.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_XMRIG = "xmrig.exe";
|
||||||
constexpr const char* RESOURCE_DARK_GRADIENT = "dark_gradient.png";
|
constexpr const char* RESOURCE_DARK_GRADIENT = "dark_gradient.png";
|
||||||
constexpr const char* RESOURCE_LOGO = "logo_ObsidianDragon_dark.png";
|
constexpr const char* RESOURCE_LOGO = "logo_ObsidianDragon_dark.png";
|
||||||
|
|||||||
@@ -14,8 +14,12 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <vector>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include "../util/logger.h"
|
#include "../util/logger.h"
|
||||||
|
#include "../util/platform.h"
|
||||||
|
#include "../util/xmrig_updater.h" // util::sha256Hex
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
@@ -120,30 +124,121 @@ std::string Connection::getSaplingParamsDir()
|
|||||||
return resources::getDaemonDirectory();
|
return resources::getDaemonDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Connection::verifySaplingParams()
|
namespace {
|
||||||
|
|
||||||
|
std::string joinParamPath(const std::string& dir, const std::string& file) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return dir + "\\" + file;
|
||||||
|
#else
|
||||||
|
return dir + "/" + file;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// "<size>:<mtime>" fingerprint used to skip re-hashing an unchanged file. Empty on error.
|
||||||
|
std::string paramStatLine(const std::string& path) {
|
||||||
|
std::error_code ec;
|
||||||
|
auto sz = fs::file_size(path, ec);
|
||||||
|
if (ec) return {};
|
||||||
|
auto mtime = fs::last_write_time(path, ec);
|
||||||
|
long long ticks = ec ? 0 :
|
||||||
|
std::chrono::duration_cast<std::chrono::seconds>(mtime.time_since_epoch()).count();
|
||||||
|
return std::to_string(static_cast<unsigned long long>(sz)) + ":" + std::to_string(ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool paramHashMatches(const std::string& path, const std::string& expectedHex) {
|
||||||
|
std::ifstream f(path, std::ios::binary | std::ios::ate);
|
||||||
|
if (!f) return false;
|
||||||
|
std::streamsize sz = f.tellg();
|
||||||
|
if (sz <= 0) return false;
|
||||||
|
f.seekg(0, std::ios::beg);
|
||||||
|
std::vector<char> buf(static_cast<size_t>(sz));
|
||||||
|
if (!f.read(buf.data(), sz)) return false;
|
||||||
|
std::string got = util::sha256Hex(buf.data(), buf.size());
|
||||||
|
return !got.empty() && got == expectedHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The verification cache: <params_dir>/.sapling_verified holds one paramStatLine per param,
|
||||||
|
// in list order, from the last successful hash check.
|
||||||
|
bool saplingMarkerMatches(const std::string& markerPath, const std::vector<std::string>& expected) {
|
||||||
|
for (const auto& s : expected) if (s.empty()) return false; // couldn't stat -> don't trust
|
||||||
|
std::ifstream f(markerPath);
|
||||||
|
if (!f) return false;
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
std::string l;
|
||||||
|
while (std::getline(f, l)) lines.push_back(l);
|
||||||
|
return lines == expected;
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeSaplingMarker(const std::string& markerPath, const std::vector<std::string>& lines) {
|
||||||
|
std::ofstream f(markerPath, std::ios::trunc);
|
||||||
|
if (!f) return;
|
||||||
|
for (const auto& l : lines) f << l << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Canonical Zcash-family Sapling trusted-setup param digests — identical bytes across every
|
||||||
|
// fork/platform. Source of truth: scripts/build-lite-backend-artifact.sh ensure_sapling_params().
|
||||||
|
// Keep in sync if the params are ever rotated.
|
||||||
|
const std::pair<std::string, std::string> kSaplingParamDigests[] = {
|
||||||
|
{ "sapling-spend.params", "8e48ffd23abb3a5fd9c5589204f32d9c31285a04b78096ba40a79b75677efc13" },
|
||||||
|
{ "sapling-output.params", "2f0ebbcbb9bb0bcffe95a397e7eba89c29eb4dde6191c339db88570e3f3fb0e4" },
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
bool Connection::verifySaplingParamsIn(
|
||||||
|
const std::string& dir,
|
||||||
|
const std::vector<std::pair<std::string, std::string>>& digests)
|
||||||
{
|
{
|
||||||
std::string params_dir = getSaplingParamsDir();
|
if (dir.empty()) {
|
||||||
if (params_dir.empty()) {
|
|
||||||
DEBUG_LOGF("verifySaplingParams: params dir is empty\n");
|
DEBUG_LOGF("verifySaplingParams: params dir is empty\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (digests.empty()) return false;
|
||||||
|
|
||||||
#ifdef _WIN32
|
// 1) Every param must exist.
|
||||||
std::string spend_path = params_dir + "\\sapling-spend.params";
|
std::vector<std::string> paths;
|
||||||
std::string output_path = params_dir + "\\sapling-output.params";
|
paths.reserve(digests.size());
|
||||||
#else
|
for (const auto& d : digests) {
|
||||||
std::string spend_path = params_dir + "/sapling-spend.params";
|
std::string p = joinParamPath(dir, d.first);
|
||||||
std::string output_path = params_dir + "/sapling-output.params";
|
if (!fs::exists(p)) {
|
||||||
#endif
|
DEBUG_LOGF("verifySaplingParams: %s MISSING\n", p.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
paths.push_back(std::move(p));
|
||||||
|
}
|
||||||
|
|
||||||
bool spend_exists = fs::exists(spend_path);
|
// 2) Fast path: if the cached marker matches the current size:mtime of every param, trust
|
||||||
bool output_exists = fs::exists(output_path);
|
// the previous successful hash instead of re-hashing ~48MB on every startup.
|
||||||
|
const std::string markerPath = joinParamPath(dir, ".sapling_verified");
|
||||||
|
std::vector<std::string> current;
|
||||||
|
current.reserve(paths.size());
|
||||||
|
for (const auto& p : paths) current.push_back(paramStatLine(p));
|
||||||
|
if (saplingMarkerMatches(markerPath, current)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG_LOGF("verifySaplingParams: dir=%s\n", params_dir.c_str());
|
// 3) Integrity-check each param against its pinned SHA-256. A truncated or corrupt param
|
||||||
DEBUG_LOGF(" spend: %s -> %s\n", spend_path.c_str(), spend_exists ? "found" : "MISSING");
|
// (a partial extraction, or a Linux bundle where the file merely *exists*) is rejected
|
||||||
DEBUG_LOGF(" output: %s -> %s\n", output_path.c_str(), output_exists ? "found" : "MISSING");
|
// here instead of being handed to the daemon and failing later on a shielded operation.
|
||||||
|
for (size_t i = 0; i < paths.size(); ++i) {
|
||||||
|
if (!paramHashMatches(paths[i], digests[i].second)) {
|
||||||
|
DEBUG_LOGF("verifySaplingParams: %s FAILED integrity check (truncated or corrupt)\n",
|
||||||
|
paths[i].c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return spend_exists && output_exists;
|
// 4) Record the verified state so later startups take the fast path.
|
||||||
|
writeSaplingMarker(markerPath, current);
|
||||||
|
DEBUG_LOGF("verifySaplingParams: %zu params verified (sha256)\n", paths.size());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Connection::verifySaplingParams()
|
||||||
|
{
|
||||||
|
std::vector<std::pair<std::string, std::string>> digests;
|
||||||
|
for (const auto& d : kSaplingParamDigests) digests.emplace_back(d.first, d.second);
|
||||||
|
return verifySaplingParamsIn(getSaplingParamsDir(), digests);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionConfig Connection::parseConfFile(const std::string& path)
|
ConnectionConfig Connection::parseConfFile(const std::string& path)
|
||||||
@@ -195,6 +290,8 @@ ConnectionConfig Connection::parseConfFile(const std::string& path)
|
|||||||
config.proxy = value;
|
config.proxy = value;
|
||||||
} else if (key == "rpctls" || key == "rpcssl" || key == "use_tls" || key == "rpcuse_tls") {
|
} else if (key == "rpctls" || key == "rpcssl" || key == "use_tls" || key == "rpcuse_tls") {
|
||||||
config.use_tls = parseBoolValue(value);
|
config.use_tls = parseBoolValue(value);
|
||||||
|
} else if (key == "rpcallowplaintext") {
|
||||||
|
config.allow_plaintext_remote = parseBoolValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,11 +306,14 @@ ConnectionConfig Connection::autoDetectConfig()
|
|||||||
{
|
{
|
||||||
ConnectionConfig config;
|
ConnectionConfig config;
|
||||||
|
|
||||||
// Ensure data directory exists
|
// Ensure the data directory exists. Use the non-throwing helper and report any failure
|
||||||
|
// via config.dir_error so callers can surface it — the old throwing create_directories()
|
||||||
|
// overload could raise an uncaught filesystem_error straight through autoDetectConfig()'s
|
||||||
|
// callers (read-only home, permission denied, etc.).
|
||||||
std::string data_dir = getDefaultDataDir();
|
std::string data_dir = getDefaultDataDir();
|
||||||
if (!fs::exists(data_dir)) {
|
if (!util::Platform::ensureDirectory(data_dir, &config.dir_error)) {
|
||||||
DEBUG_LOGF("Creating data directory: %s\n", data_dir.c_str());
|
DEBUG_LOGF("[ERROR] autoDetectConfig: %s\n", config.dir_error.c_str());
|
||||||
fs::create_directories(data_dir);
|
return config; // data dir unusable — bail early with dir_error set
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find DRAGONX.conf
|
// Try to find DRAGONX.conf
|
||||||
@@ -268,6 +368,31 @@ bool Connection::buildCookieAuthConfig(const ConnectionConfig& base, ConnectionC
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// True only for a well-formed IPv4 loopback literal (127.0.0.0/8): exactly four dot-separated
|
||||||
|
// 0-255 octets with the first == 127. Rejects "127.evil.com", "127.0.0.1.attacker",
|
||||||
|
// "127.300.0.1", "1270.0.0.1", etc. — the old rfind("127.",0)==0 prefix matched all of those.
|
||||||
|
static bool isExactIPv4Loopback(const std::string& host)
|
||||||
|
{
|
||||||
|
int octets = 0, value = 0, digits = 0;
|
||||||
|
bool firstIs127 = false;
|
||||||
|
for (size_t i = 0; i <= host.size(); ++i) {
|
||||||
|
const char c = (i < host.size()) ? host[i] : '.'; // trailing sentinel flushes the last octet
|
||||||
|
if (c == '.') {
|
||||||
|
if (digits == 0 || digits > 3 || value > 255) return false;
|
||||||
|
if (octets == 0) firstIs127 = (value == 127);
|
||||||
|
++octets;
|
||||||
|
value = 0;
|
||||||
|
digits = 0;
|
||||||
|
} else if (c >= '0' && c <= '9') {
|
||||||
|
value = value * 10 + (c - '0');
|
||||||
|
++digits;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return octets == 4 && firstIs127;
|
||||||
|
}
|
||||||
|
|
||||||
bool Connection::isLocalHost(const std::string& host)
|
bool Connection::isLocalHost(const std::string& host)
|
||||||
{
|
{
|
||||||
std::string lowered = lowercase(host);
|
std::string lowered = lowercase(host);
|
||||||
@@ -277,7 +402,7 @@ bool Connection::isLocalHost(const std::string& host)
|
|||||||
|
|
||||||
return lowered == "localhost" || lowered == "localhost." ||
|
return lowered == "localhost" || lowered == "localhost." ||
|
||||||
lowered == "::1" || lowered == "0:0:0:0:0:0:0:1" ||
|
lowered == "::1" || lowered == "0:0:0:0:0:0:0:1" ||
|
||||||
lowered == "127.0.0.1" || lowered.rfind("127.", 0) == 0;
|
isExactIPv4Loopback(lowered);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Connection::usesPlaintextRemote(const ConnectionConfig& config)
|
bool Connection::usesPlaintextRemote(const ConnectionConfig& config)
|
||||||
@@ -285,6 +410,13 @@ bool Connection::usesPlaintextRemote(const ConnectionConfig& config)
|
|||||||
return !config.use_tls && !isLocalHost(config.host);
|
return !config.use_tls && !isLocalHost(config.host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Connection::allowsPlaintextRemote(const ConnectionConfig& config)
|
||||||
|
{
|
||||||
|
// Explicit opt-in (DRAGONX.conf: rpcallowplaintext=1) to send credentials over a plaintext
|
||||||
|
// link to a remote host. Off by default — see usesPlaintextRemote().
|
||||||
|
return config.allow_plaintext_remote;
|
||||||
|
}
|
||||||
|
|
||||||
const char* Connection::authSourceName(AuthSource source)
|
const char* Connection::authSourceName(AuthSource source)
|
||||||
{
|
{
|
||||||
switch (source) {
|
switch (source) {
|
||||||
@@ -324,11 +456,11 @@ bool Connection::createDefaultConfig(const std::string& path)
|
|||||||
file << "exportdir=" << dataDir << "\n";
|
file << "exportdir=" << dataDir << "\n";
|
||||||
file << "experimentalfeatures=1\n";
|
file << "experimentalfeatures=1\n";
|
||||||
file << "developerencryptwallet=1\n";
|
file << "developerencryptwallet=1\n";
|
||||||
file << "addnode=node.dragonx.is\n";
|
// Round-robin DNS seed (self-updating) + static fallbacks; mirrors the daemon's vSeeds and keeps
|
||||||
|
// pre-1.3.0 daemons (broken peer discovery) able to find peers. Works on every daemon version.
|
||||||
|
file << "addnode=seed.dragonx.is\n";
|
||||||
file << "addnode=node1.dragonx.is\n";
|
file << "addnode=node1.dragonx.is\n";
|
||||||
file << "addnode=node2.dragonx.is\n";
|
file << "addnode=node5.dragonx.is\n";
|
||||||
file << "addnode=node3.dragonx.is\n";
|
|
||||||
file << "addnode=node4.dragonx.is\n";
|
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace dragonx {
|
namespace dragonx {
|
||||||
namespace rpc {
|
namespace rpc {
|
||||||
@@ -27,7 +29,11 @@ struct ConnectionConfig {
|
|||||||
std::string proxy; // SOCKS5 proxy for Tor
|
std::string proxy; // SOCKS5 proxy for Tor
|
||||||
bool use_embedded = true;
|
bool use_embedded = true;
|
||||||
bool use_tls = false;
|
bool use_tls = false;
|
||||||
|
bool allow_plaintext_remote = false; // rpcallowplaintext=1 — opt in to plaintext creds to a remote host
|
||||||
AuthSource auth_source = AuthSource::Missing;
|
AuthSource auth_source = AuthSource::Missing;
|
||||||
|
// Non-empty when autoDetectConfig() could not create the data directory; callers
|
||||||
|
// should surface it and abort the connect rather than proceeding blindly.
|
||||||
|
std::string dir_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,6 +75,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
static bool verifySaplingParams();
|
static bool verifySaplingParams();
|
||||||
|
|
||||||
|
// Verify the Sapling params in `dir` against a { filename, expected-sha256-hex } list.
|
||||||
|
// Exposed with an injectable dir + digest list so the integrity + marker-cache logic is
|
||||||
|
// unit-testable without the real ~48MB params; verifySaplingParams() calls it with the
|
||||||
|
// pinned production digests and getSaplingParamsDir().
|
||||||
|
static bool verifySaplingParamsIn(
|
||||||
|
const std::string& dir,
|
||||||
|
const std::vector<std::pair<std::string, std::string>>& digests);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Sapling params directory
|
* @brief Get the Sapling params directory
|
||||||
*/
|
*/
|
||||||
@@ -119,6 +133,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
static bool usesPlaintextRemote(const ConnectionConfig& config);
|
static bool usesPlaintextRemote(const ConnectionConfig& config);
|
||||||
|
|
||||||
|
// Whether plaintext credentials to a remote host are explicitly allowed (opt-in via the
|
||||||
|
// DRAGONX.conf rpcallowplaintext key). Off by default: usesPlaintextRemote() && !this
|
||||||
|
// means the connect is refused.
|
||||||
|
static bool allowsPlaintextRemote(const ConnectionConfig& config);
|
||||||
|
|
||||||
static const char* authSourceName(AuthSource source);
|
static const char* authSourceName(AuthSource source);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -23,6 +23,19 @@ namespace rpc {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// Recursively zero every string value in a JSON tree in place — used to wipe a discarded parse tree
|
||||||
|
// that held a secret (B7). Operates on the underlying std::string buffers via get_ref.
|
||||||
|
// Templated so it works on both nlohmann::json and nlohmann::ordered_json (callRaw uses the latter).
|
||||||
|
template <typename J>
|
||||||
|
void scrubJsonSecrets(J& j) {
|
||||||
|
if (j.is_string()) {
|
||||||
|
auto& s = j.template get_ref<std::string&>();
|
||||||
|
if (!s.empty()) sodium_memzero(&s[0], s.size());
|
||||||
|
} else if (j.is_object() || j.is_array()) {
|
||||||
|
for (auto& el : j) scrubJsonSecrets(el);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::mutex g_trace_mutex;
|
std::mutex g_trace_mutex;
|
||||||
RPCClient::TraceCallback g_trace_callback;
|
RPCClient::TraceCallback g_trace_callback;
|
||||||
std::atomic_bool g_trace_enabled{false};
|
std::atomic_bool g_trace_enabled{false};
|
||||||
@@ -85,6 +98,10 @@ void RPCClient::setTraceSource(std::string source)
|
|||||||
// Callback for libcurl to write response data
|
// Callback for libcurl to write response data
|
||||||
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* userp) {
|
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* userp) {
|
||||||
size_t totalSize = size * nmemb;
|
size_t totalSize = size * nmemb;
|
||||||
|
// Bound accumulation so a hostile/compromised daemon cannot OOM the client with an unbounded
|
||||||
|
// response body. 256 MiB is far above any legitimate JSON-RPC response yet prevents exhaustion.
|
||||||
|
static constexpr size_t kMaxRpcResponseBytes = 256u * 1024 * 1024;
|
||||||
|
if (userp->size() + totalSize > kMaxRpcResponseBytes) return 0; // short count aborts the transfer
|
||||||
userp->append((char*)contents, totalSize);
|
userp->append((char*)contents, totalSize);
|
||||||
return totalSize;
|
return totalSize;
|
||||||
}
|
}
|
||||||
@@ -129,7 +146,11 @@ RPCClient::RPCClient() : impl_(std::make_unique<Impl>())
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RPCClient::~RPCClient() = default;
|
RPCClient::~RPCClient() {
|
||||||
|
// Scrub the persistent Basic-auth secret on destruction (disconnect() may not have run). impl_ is
|
||||||
|
// still destroyed normally afterward (curl cleanup unchanged). (L-04)
|
||||||
|
if (!auth_.empty()) sodium_memzero(auth_.data(), auth_.size());
|
||||||
|
}
|
||||||
|
|
||||||
bool RPCClient::connect(const std::string& host, const std::string& port,
|
bool RPCClient::connect(const std::string& host, const std::string& port,
|
||||||
const std::string& user, const std::string& password)
|
const std::string& user, const std::string& password)
|
||||||
@@ -149,6 +170,7 @@ bool RPCClient::connect(const std::string& host, const std::string& port,
|
|||||||
// Create Basic auth header with proper base64 encoding, then wipe the plaintext
|
// Create Basic auth header with proper base64 encoding, then wipe the plaintext
|
||||||
// "user:password" temporary (std::string does not zero its buffer on destruction).
|
// "user:password" temporary (std::string does not zero its buffer on destruction).
|
||||||
std::string credentials = user + ":" + password;
|
std::string credentials = user + ":" + password;
|
||||||
|
if (!auth_.empty()) sodium_memzero(auth_.data(), auth_.size()); // wipe any prior secret before overwrite (L-04)
|
||||||
auth_ = util::base64_encode(credentials);
|
auth_ = util::base64_encode(credentials);
|
||||||
if (!credentials.empty()) sodium_memzero(credentials.data(), credentials.size());
|
if (!credentials.empty()) sodium_memzero(credentials.data(), credentials.size());
|
||||||
|
|
||||||
@@ -176,6 +198,7 @@ bool RPCClient::connect(const std::string& host, const std::string& port,
|
|||||||
impl_->headers = curl_slist_append(nullptr, "Content-Type: text/plain");
|
impl_->headers = curl_slist_append(nullptr, "Content-Type: text/plain");
|
||||||
std::string auth_header = "Authorization: Basic " + auth_;
|
std::string auth_header = "Authorization: Basic " + auth_;
|
||||||
impl_->headers = curl_slist_append(impl_->headers, auth_header.c_str());
|
impl_->headers = curl_slist_append(impl_->headers, auth_header.c_str());
|
||||||
|
if (!auth_header.empty()) sodium_memzero(auth_header.data(), auth_header.size()); // curl copied it (L-04)
|
||||||
|
|
||||||
// Configure curl
|
// Configure curl
|
||||||
curl_easy_setopt(impl_->curl, CURLOPT_URL, impl_->url.c_str());
|
curl_easy_setopt(impl_->curl, CURLOPT_URL, impl_->url.c_str());
|
||||||
@@ -191,6 +214,10 @@ bool RPCClient::connect(const std::string& host, const std::string& port,
|
|||||||
// budget for the TCP + TLS handshake over real network latency (1s would spuriously fail).
|
// budget for the TCP + TLS handshake over real network latency (1s would spuriously fail).
|
||||||
const long connectTimeout = Connection::isLocalHost(host) ? 2L : 10L;
|
const long connectTimeout = Connection::isLocalHost(host) ? 2L : 10L;
|
||||||
curl_easy_setopt(impl_->curl, CURLOPT_CONNECTTIMEOUT, connectTimeout);
|
curl_easy_setopt(impl_->curl, CURLOPT_CONNECTTIMEOUT, connectTimeout);
|
||||||
|
// Enforce TLS certificate + hostname verification explicitly rather than relying on libcurl's
|
||||||
|
// build defaults. Harmless on the localhost http:// case; essential for a remote https daemon.
|
||||||
|
curl_easy_setopt(impl_->curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||||
|
curl_easy_setopt(impl_->curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
||||||
|
|
||||||
// Test connection with getinfo. Use a SHORT timeout for the probe on localhost: a healthy
|
// Test connection with getinfo. Use a SHORT timeout for the probe on localhost: a healthy
|
||||||
// local daemon answers in milliseconds and a warming one returns -28 just as fast, so a long
|
// local daemon answers in milliseconds and a warming one returns -28 just as fast, so a long
|
||||||
@@ -278,6 +305,7 @@ void RPCClient::disconnect()
|
|||||||
curl_slist_free_all(impl_->headers);
|
curl_slist_free_all(impl_->headers);
|
||||||
impl_->headers = nullptr;
|
impl_->headers = nullptr;
|
||||||
}
|
}
|
||||||
|
if (!auth_.empty()) { sodium_memzero(auth_.data(), auth_.size()); auth_.clear(); } // scrub Basic-auth secret (L-04)
|
||||||
}
|
}
|
||||||
|
|
||||||
json RPCClient::makePayload(const std::string& method, const json& params)
|
json RPCClient::makePayload(const std::string& method, const json& params)
|
||||||
@@ -317,7 +345,7 @@ std::string RPCClient::performCall(const std::string& method, const json& params
|
|||||||
return response_data;
|
return response_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
json RPCClient::parseRpcResult(long httpCode, const std::string& body)
|
json RPCClient::parseRpcResult(long httpCode, const std::string& body, bool scrubSource)
|
||||||
{
|
{
|
||||||
// Bitcoin/Hush RPC returns HTTP 500 for application-level errors
|
// Bitcoin/Hush RPC returns HTTP 500 for application-level errors
|
||||||
// (insufficient funds, bad params, etc.) with a valid JSON body.
|
// (insufficient funds, bad params, etc.) with a valid JSON body.
|
||||||
@@ -355,7 +383,9 @@ json RPCClient::parseRpcResult(long httpCode, const std::string& body)
|
|||||||
throw RpcError(errCode, "RPC error: " + err_msg);
|
throw RpcError(errCode, "RPC error: " + err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response["result"];
|
json result = response["result"]; // a COPY of the subobject (operator[] yields an lvalue ref)
|
||||||
|
if (scrubSource) scrubJsonSecrets(response); // zero the discarded tree's secret before it frees (B7)
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
json RPCClient::call(const std::string& method, const json& params)
|
json RPCClient::call(const std::string& method, const json& params)
|
||||||
@@ -370,6 +400,56 @@ json RPCClient::call(const std::string& method, const json& params)
|
|||||||
return parseRpcResult(http_code, response_data);
|
return parseRpcResult(http_code, response_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json RPCClient::callSecret(const std::string& method, const json& params)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::recursive_mutex> lk(curl_mutex_);
|
||||||
|
if (!impl_->curl) {
|
||||||
|
throw std::runtime_error("Not connected");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zero the raw response body whether parsing succeeds or throws — it holds the secret in the
|
||||||
|
// clear (the curl write buffer performCall returns), and would otherwise be freed un-wiped (B7).
|
||||||
|
long http_code = 0;
|
||||||
|
std::string response_data = performCall(method, params, http_code);
|
||||||
|
try {
|
||||||
|
json result = parseRpcResult(http_code, response_data, /*scrubSource=*/true);
|
||||||
|
if (!response_data.empty()) sodium_memzero(&response_data[0], response_data.size());
|
||||||
|
return result;
|
||||||
|
} catch (...) {
|
||||||
|
if (!response_data.empty()) sodium_memzero(&response_data[0], response_data.size());
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RPCClient::callSecretString(const std::string& method, const json& params)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::recursive_mutex> lk(curl_mutex_);
|
||||||
|
if (!impl_->curl) {
|
||||||
|
throw std::runtime_error("Not connected");
|
||||||
|
}
|
||||||
|
|
||||||
|
long http_code = 0;
|
||||||
|
std::string response_data = performCall(method, params, http_code);
|
||||||
|
try {
|
||||||
|
json result = parseRpcResult(http_code, response_data, /*scrubSource=*/true);
|
||||||
|
std::string out;
|
||||||
|
if (result.is_string()) {
|
||||||
|
// Copy the secret out, then zero the json node's OWN heap buffer — parseRpcResult's
|
||||||
|
// json::parse allocates this independently of response_data, so scrubbing the raw body
|
||||||
|
// alone would leave it behind (B7). `out` is now the only live copy; the caller wipes it.
|
||||||
|
auto& s = result.get_ref<std::string&>();
|
||||||
|
out = s;
|
||||||
|
if (!s.empty()) sodium_memzero(&s[0], s.size());
|
||||||
|
}
|
||||||
|
if (!response_data.empty()) sodium_memzero(&response_data[0], response_data.size());
|
||||||
|
if (!result.is_string()) throw std::runtime_error("RPC result is not a string");
|
||||||
|
return out;
|
||||||
|
} catch (...) {
|
||||||
|
if (!response_data.empty()) sodium_memzero(&response_data[0], response_data.size());
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
json RPCClient::call(const std::string& method, const json& params, long timeoutSec)
|
json RPCClient::call(const std::string& method, const json& params, long timeoutSec)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::recursive_mutex> lk(curl_mutex_);
|
std::lock_guard<std::recursive_mutex> lk(curl_mutex_);
|
||||||
@@ -445,14 +525,22 @@ std::string RPCClient::callRaw(const std::string& method, const json& params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto& result = oj["result"];
|
auto& result = oj["result"];
|
||||||
|
std::string out;
|
||||||
if (result.is_null()) {
|
if (result.is_null()) {
|
||||||
return "null";
|
out = "null";
|
||||||
} else if (result.is_string()) {
|
} else if (result.is_string()) {
|
||||||
// Return the raw string (not JSON-encoded) — caller wraps as needed
|
// Return the raw string (not JSON-encoded) — caller wraps as needed
|
||||||
return result.get<std::string>();
|
out = result.get<std::string>();
|
||||||
} else {
|
} else {
|
||||||
return result.dump(4);
|
out = result.dump(4);
|
||||||
}
|
}
|
||||||
|
// B7: this raw path serves arbitrary console commands including dumpprivkey / z_exportkey,
|
||||||
|
// whose response carries plaintext key material. Zero the raw buffer and the parsed tree so
|
||||||
|
// the secret does not linger in freed heap (matching callSecret). The single returned copy is
|
||||||
|
// the caller's to manage.
|
||||||
|
scrubJsonSecrets(oj);
|
||||||
|
if (!response_data.empty()) sodium_memzero(&response_data[0], response_data.size());
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RPCClient::doRPC(const std::string& method, const json& params, Callback cb, ErrorCallback err)
|
void RPCClient::doRPC(const std::string& method, const json& params, Callback cb, ErrorCallback err)
|
||||||
|
|||||||
@@ -133,6 +133,26 @@ public:
|
|||||||
*/
|
*/
|
||||||
json call(const std::string& method, const json& params = json::array());
|
json call(const std::string& method, const json& params = json::array());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Like call(), but zeroes the raw HTTP response body after parsing (B7).
|
||||||
|
*
|
||||||
|
* For RPCs whose response carries a secret (z_exportmnemonic / z_exportkey), the parsed
|
||||||
|
* value is scrubbed by the caller — but the raw response string this method builds also
|
||||||
|
* holds that secret and is otherwise freed without zeroing. Use this variant so the largest,
|
||||||
|
* longest-lived plaintext copy doesn't linger in freed heap. Slightly slower (an extra wipe);
|
||||||
|
* only worth it for secret-bearing calls.
|
||||||
|
*/
|
||||||
|
json callSecret(const std::string& method, const json& params = json::array());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief callSecret() for RPCs whose result is a bare secret string (z_exportkey / dumpprivkey /
|
||||||
|
* z_exportviewingkey). Returns the result string with BOTH the raw response body AND the
|
||||||
|
* parsed json's own copy of the secret zeroed — so no un-scrubbed heap copy survives the
|
||||||
|
* call. The returned std::string is the only remaining copy; the caller owns it and must
|
||||||
|
* wipe it (sodium_memzero) when done. Throws if the result is not a JSON string.
|
||||||
|
*/
|
||||||
|
std::string callSecretString(const std::string& method, const json& params = json::array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Make a raw RPC call with a custom timeout
|
* @brief Make a raw RPC call with a custom timeout
|
||||||
* @param method RPC method name
|
* @param method RPC method name
|
||||||
@@ -250,8 +270,10 @@ private:
|
|||||||
// hold curl_mutex_ and have verified impl_->curl.
|
// hold curl_mutex_ and have verified impl_->curl.
|
||||||
std::string performCall(const std::string& method, const json& params, long& httpCodeOut);
|
std::string performCall(const std::string& method, const json& params, long& httpCodeOut);
|
||||||
// Centralizes the HTTP-code check and JSON error->RpcError extraction, returning
|
// Centralizes the HTTP-code check and JSON error->RpcError extraction, returning
|
||||||
// response["result"] on success.
|
// response["result"] on success. When scrubSource is true (secret-bearing calls), the intermediate
|
||||||
static json parseRpcResult(long httpCode, const std::string& body);
|
// parse tree's string values are zeroed before it is discarded — parseRpcResult returns a COPY of
|
||||||
|
// the result node, so its own tree would otherwise free the secret un-wiped (B7).
|
||||||
|
static json parseRpcResult(long httpCode, const std::string& body, bool scrubSource = false);
|
||||||
|
|
||||||
// Splits a UnifiedCallback into the (Callback, ErrorCallback) pair used by doRPC.
|
// Splits a UnifiedCallback into the (Callback, ErrorCallback) pair used by doRPC.
|
||||||
static std::pair<Callback, ErrorCallback> splitUnified(UnifiedCallback cb);
|
static std::pair<Callback, ErrorCallback> splitUnified(UnifiedCallback cb);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -37,16 +38,27 @@ void applyBalancesFromUnspent(std::vector<AddressInfo>& addresses, const json& u
|
|||||||
{
|
{
|
||||||
if (!unspent.is_array()) return;
|
if (!unspent.is_array()) return;
|
||||||
|
|
||||||
std::map<std::string, double> balances;
|
// Partition each note/utxo by its per-entry "confirmations": `total` (minconf=0 — DISPLAY, includes
|
||||||
|
// the user's own pending 0-conf change) vs `spendable` (confirmations>=1 — what z_sendmany, run at
|
||||||
|
// minconf=1, can actually spend). This lets a single z_listunspent(0)/listunspent(0) feed both.
|
||||||
|
std::map<std::string, double> total;
|
||||||
|
std::map<std::string, double> spendable;
|
||||||
for (const auto& output : unspent) {
|
for (const auto& output : unspent) {
|
||||||
auto address = readOptional<std::string>(output, "address");
|
auto address = readOptional<std::string>(output, "address");
|
||||||
auto amount = readOptional<double>(output, "amount");
|
auto amount = readOptional<double>(output, "amount");
|
||||||
if (address && amount) balances[*address] += *amount;
|
if (!address || !amount) continue;
|
||||||
|
total[*address] += *amount;
|
||||||
|
auto conf = readOptional<int>(output, "confirmations");
|
||||||
|
if (conf && *conf >= 1) spendable[*address] += *amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The address lists are rebuilt fresh (default 0) each refresh, so hard-set both — an address with no
|
||||||
|
// notes in this set is 0, and spendableBalance is always a subset sum of balance.
|
||||||
for (auto& info : addresses) {
|
for (auto& info : addresses) {
|
||||||
auto balance = balances.find(info.address);
|
auto t = total.find(info.address);
|
||||||
if (balance != balances.end()) info.balance = balance->second;
|
auto s = spendable.find(info.address);
|
||||||
|
info.balance = (t != total.end()) ? t->second : 0.0;
|
||||||
|
info.spendableBalance = (s != spendable.end()) ? s->second : 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,20 +180,6 @@ void appendExtractedHushChatMetadata(std::vector<chat::HushChatTransactionMetada
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendExtractedHushChatMetadata(std::vector<chat::HushChatTransactionMetadata>& destination,
|
|
||||||
const std::string& txid,
|
|
||||||
const NetworkRefreshService::TransactionViewCacheEntry& entry)
|
|
||||||
{
|
|
||||||
if (!chat::hushChatFeatureEnabledAtBuild()) return;
|
|
||||||
|
|
||||||
std::vector<chat::HushChatMemoOutput> outputs;
|
|
||||||
outputs.reserve(entry.outgoing_outputs.size());
|
|
||||||
for (const auto& output : entry.outgoing_outputs) {
|
|
||||||
if (!output.memo.empty()) outputs.push_back(chat::HushChatMemoOutput{output.position, output.memo});
|
|
||||||
}
|
|
||||||
appendExtractedHushChatMetadata(destination, txid, outputs);
|
|
||||||
}
|
|
||||||
|
|
||||||
void appendExtractedHushChatMetadata(std::vector<chat::HushChatTransactionMetadata>& destination,
|
void appendExtractedHushChatMetadata(std::vector<chat::HushChatTransactionMetadata>& destination,
|
||||||
const HushChatMemoOutputMap& outputsByTxid)
|
const HushChatMemoOutputMap& outputsByTxid)
|
||||||
{
|
{
|
||||||
@@ -263,7 +261,7 @@ NetworkRefreshService::ConnectionInitResult NetworkRefreshService::collectConnec
|
|||||||
}
|
}
|
||||||
|
|
||||||
NetworkRefreshService::CoreRefreshResult NetworkRefreshService::parseCoreRefreshResult(
|
NetworkRefreshService::CoreRefreshResult NetworkRefreshService::parseCoreRefreshResult(
|
||||||
const json& totalBalance, bool balanceOk, const json& blockInfo, bool blockOk)
|
const json& totalBalance, const json& spendableBalance, bool balanceOk, const json& blockInfo, bool blockOk)
|
||||||
{
|
{
|
||||||
CoreRefreshResult result;
|
CoreRefreshResult result;
|
||||||
result.balanceOk = balanceOk && totalBalance.is_object();
|
result.balanceOk = balanceOk && totalBalance.is_object();
|
||||||
@@ -272,6 +270,11 @@ NetworkRefreshService::CoreRefreshResult NetworkRefreshService::parseCoreRefresh
|
|||||||
result.transparentBalance = readBalanceString(totalBalance, "transparent");
|
result.transparentBalance = readBalanceString(totalBalance, "transparent");
|
||||||
result.totalBalance = readBalanceString(totalBalance, "total");
|
result.totalBalance = readBalanceString(totalBalance, "total");
|
||||||
}
|
}
|
||||||
|
if (spendableBalance.is_object()) { // confirmed totals (minconf=1); left unset on old daemons
|
||||||
|
result.spendableShieldedBalance = readBalanceString(spendableBalance, "private");
|
||||||
|
result.spendableTransparentBalance = readBalanceString(spendableBalance, "transparent");
|
||||||
|
result.spendableTotalBalance = readBalanceString(spendableBalance, "total");
|
||||||
|
}
|
||||||
|
|
||||||
result.blockchainOk = blockOk && blockInfo.is_object();
|
result.blockchainOk = blockOk && blockInfo.is_object();
|
||||||
if (result.blockchainOk) {
|
if (result.blockchainOk) {
|
||||||
@@ -288,19 +291,17 @@ NetworkRefreshService::CoreRefreshResult NetworkRefreshService::parseCoreRefresh
|
|||||||
NetworkRefreshService::CoreRefreshResult NetworkRefreshService::collectCoreRefreshResult(RefreshRpcGateway& rpc, bool includeBalance)
|
NetworkRefreshService::CoreRefreshResult NetworkRefreshService::collectCoreRefreshResult(RefreshRpcGateway& rpc, bool includeBalance)
|
||||||
{
|
{
|
||||||
json totalBalance;
|
json totalBalance;
|
||||||
|
json spendableBalance;
|
||||||
json blockInfo;
|
json blockInfo;
|
||||||
bool balanceOk = false;
|
bool balanceOk = false;
|
||||||
bool blockOk = false;
|
bool blockOk = false;
|
||||||
|
double balanceScanMs = 0.0;
|
||||||
|
|
||||||
if (includeBalance) {
|
// getblockchaininfo FIRST — it's cheap, and the sync state it returns gates everything else
|
||||||
try {
|
// (the balance/address/tx throttles and kSyncProfile). Running it BEFORE the O(mapWallet) balance
|
||||||
totalBalance = rpc.call("z_gettotalbalance", json::array());
|
// scan keeps sync detection from being delayed behind (or, under contention, starved by) that
|
||||||
balanceOk = true;
|
// scan — the failure mode where the wallet kept reading "synced" while actually falling behind,
|
||||||
} catch (const std::exception& e) {
|
// so kSyncProfile never engaged. See effectivelySyncing()'s sticky-behind latch.
|
||||||
DEBUG_LOGF("Balance error: %s\n", e.what());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
blockInfo = rpc.call("getblockchaininfo", json::array());
|
blockInfo = rpc.call("getblockchaininfo", json::array());
|
||||||
blockOk = true;
|
blockOk = true;
|
||||||
@@ -308,7 +309,39 @@ NetworkRefreshService::CoreRefreshResult NetworkRefreshService::collectCoreRefre
|
|||||||
DEBUG_LOGF("BlockchainInfo error: %s\n", e.what());
|
DEBUG_LOGF("BlockchainInfo error: %s\n", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseCoreRefreshResult(totalBalance, balanceOk, blockInfo, blockOk);
|
// If getblockchaininfo shows we're behind (same 2-block tolerance as applyCoreRefreshResult), skip
|
||||||
|
// the balance scan this cycle regardless of includeBalance: the balance is incomplete mid-sync
|
||||||
|
// anyway, and skipping it lets the sync-state update — and hence kSyncProfile — take effect at the
|
||||||
|
// end of THIS (now-cheap) task instead of being delayed ~20s behind the scan. This is what lets the
|
||||||
|
// sticky-behind latch engage promptly the first time the node falls behind.
|
||||||
|
bool behind = false;
|
||||||
|
if (blockOk && blockInfo.is_object()) {
|
||||||
|
const long long b = blockInfo.value("blocks", 0LL);
|
||||||
|
const long long lc = blockInfo.value("longestchain", 0LL);
|
||||||
|
if (lc > 0 && b < lc - 2) behind = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeBalance && !behind) {
|
||||||
|
// z_gettotalbalance is O(mapWallet) and holds the daemon's cs_main for its whole duration —
|
||||||
|
// seconds on a large shielded wallet. Time it so the caller can throttle how often it polls
|
||||||
|
// (balanceRefreshDue()), keeping balance scans from starving block connection.
|
||||||
|
const auto balanceStart = std::chrono::steady_clock::now();
|
||||||
|
try { // DISPLAY total: minconf=0 — includes the user's own pending change so it doesn't crater
|
||||||
|
totalBalance = rpc.call("z_gettotalbalance", json::array({0}));
|
||||||
|
balanceOk = true;
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
DEBUG_LOGF("Balance error: %s\n", e.what());
|
||||||
|
}
|
||||||
|
try { // SPENDABLE total: minconf=1 (confirmed). If absent, spendable degrades to display in apply.
|
||||||
|
spendableBalance = rpc.call("z_gettotalbalance", json::array({1}));
|
||||||
|
} catch (...) {}
|
||||||
|
balanceScanMs = std::chrono::duration<double, std::milli>(
|
||||||
|
std::chrono::steady_clock::now() - balanceStart).count();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto result = parseCoreRefreshResult(totalBalance, spendableBalance, balanceOk, blockInfo, blockOk);
|
||||||
|
result.balanceScanMs = balanceScanMs;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRefreshService::MiningRefreshResult NetworkRefreshService::parseMiningRefreshResult(
|
NetworkRefreshService::MiningRefreshResult NetworkRefreshService::parseMiningRefreshResult(
|
||||||
@@ -440,16 +473,32 @@ std::optional<NetworkRefreshService::PriceRefreshResult> NetworkRefreshService::
|
|||||||
if (!parsed.contains("dragonx-2")) return std::nullopt;
|
if (!parsed.contains("dragonx-2")) return std::nullopt;
|
||||||
|
|
||||||
const auto& data = parsed["dragonx-2"];
|
const auto& data = parsed["dragonx-2"];
|
||||||
|
// CoinGecko emits JSON null (not an omitted key) for fields it can't currently compute —
|
||||||
|
// commonly usd_24h_change on illiquid/newly-listed tokens — while still returning a valid
|
||||||
|
// spot price in the same object. .value(key, default) throws type_error on a PRESENT null,
|
||||||
|
// which the outer catch turns into "no price update at all", so read null-tolerantly and
|
||||||
|
// keep the valid usd/btc rather than discarding the whole refresh.
|
||||||
|
auto num = [&data](const char* key, double def) {
|
||||||
|
auto it = data.find(key);
|
||||||
|
return (it != data.end() && it->is_number()) ? it->get<double>() : def;
|
||||||
|
};
|
||||||
PriceRefreshResult result;
|
PriceRefreshResult result;
|
||||||
result.market.price_usd = data.value("usd", 0.0);
|
result.market.price_usd = num("usd", 0.0);
|
||||||
result.market.price_btc = data.value("btc", 0.0);
|
result.market.price_btc = num("btc", 0.0);
|
||||||
result.market.change_24h = data.value("usd_24h_change", 0.0);
|
result.market.change_24h = num("usd_24h_change", 0.0);
|
||||||
result.market.volume_24h = data.value("usd_24h_vol", 0.0);
|
result.market.volume_24h = num("usd_24h_vol", 0.0);
|
||||||
result.market.market_cap = data.value("usd_market_cap", 0.0);
|
result.market.market_cap = num("usd_market_cap", 0.0);
|
||||||
|
|
||||||
char buf[64];
|
char buf[64];
|
||||||
std::tm* tm = std::localtime(&fetchedAt);
|
// Runs on the RPC worker thread — std::localtime shares a process-wide static tm, so use the
|
||||||
if (tm && std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm) > 0) {
|
// reentrant variant into a local tm (matches the rest of the codebase).
|
||||||
|
std::tm tmv{};
|
||||||
|
#ifdef _WIN32
|
||||||
|
localtime_s(&tmv, &fetchedAt);
|
||||||
|
#else
|
||||||
|
localtime_r(&fetchedAt, &tmv);
|
||||||
|
#endif
|
||||||
|
if (std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tmv) > 0) {
|
||||||
result.market.last_updated = buf;
|
result.market.last_updated = buf;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -571,6 +620,10 @@ NetworkRefreshService::AddressRefreshResult NetworkRefreshService::collectAddres
|
|||||||
const AddressRefreshSnapshot& snapshot)
|
const AddressRefreshSnapshot& snapshot)
|
||||||
{
|
{
|
||||||
AddressRefreshResult result;
|
AddressRefreshResult result;
|
||||||
|
// Time the whole scan — z_listunspent (and per-address z_getbalance fallback) hold the daemon's
|
||||||
|
// cs_main for the duration, seconds on a large shielded wallet. The measured cost feeds the
|
||||||
|
// caller's adaptive throttle so the address poll can't starve block connection.
|
||||||
|
const auto scanStart = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json zList = rpc.call("z_listaddresses", json::array());
|
json zList = rpc.call("z_listaddresses", json::array());
|
||||||
@@ -606,18 +659,39 @@ NetworkRefreshService::AddressRefreshResult NetworkRefreshService::collectAddres
|
|||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
DEBUG_LOGF("z_listaddresses error: %s\n", e.what());
|
DEBUG_LOGF("z_listaddresses error: %s\n", e.what());
|
||||||
|
result.addressListOk = false; // enumeration failed → the shielded list may be falsely short
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json unspent = rpc.call("z_listunspent", json::array());
|
json unspent = rpc.call("z_listunspent", json::array({0, 9999999, false})); // minconf=0 → include 0-conf change
|
||||||
applyShieldedBalancesFromUnspent(result.shieldedAddresses, unspent);
|
applyShieldedBalancesFromUnspent(result.shieldedAddresses, unspent);
|
||||||
|
// Retain a minimal view so a downstream consumer (chat note-budget) can reuse this scan instead
|
||||||
|
// of issuing its own z_listunspent. rawconfirmations is the TRUE depth; `confirmations` is
|
||||||
|
// dPoW-clamped to 1 and understates it.
|
||||||
|
if (unspent.is_array()) {
|
||||||
|
result.unspentNotes.reserve(unspent.size());
|
||||||
|
for (const auto& nz : unspent) {
|
||||||
|
if (!nz.is_object()) continue;
|
||||||
|
UnspentNoteLite lite;
|
||||||
|
lite.amount = nz.value("amount", 0.0);
|
||||||
|
lite.locked = nz.value("locked", false);
|
||||||
|
lite.confirmations = (nz.contains("rawconfirmations") && nz["rawconfirmations"].is_number_integer())
|
||||||
|
? nz["rawconfirmations"].get<int>()
|
||||||
|
: nz.value("confirmations", 0);
|
||||||
|
result.unspentNotes.push_back(lite);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
DEBUG_LOGF("z_listunspent unavailable (%s), falling back to z_getbalance\n", e.what());
|
DEBUG_LOGF("z_listunspent unavailable (%s), falling back to z_getbalance\n", e.what());
|
||||||
for (auto& info : result.shieldedAddresses) {
|
for (auto& info : result.shieldedAddresses) {
|
||||||
try {
|
try { // display total (minconf=0, includes pending change)
|
||||||
json balance = rpc.call("z_getbalance", json::array({info.address}));
|
json total = rpc.call("z_getbalance", json::array({info.address, 0}));
|
||||||
if (!balance.is_null()) info.balance = balance.get<double>();
|
if (!total.is_null()) info.balance = total.get<double>();
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
|
try { // spendable (minconf=1); degrade to the display value on old daemons
|
||||||
|
json conf = rpc.call("z_getbalance", json::array({info.address, 1}));
|
||||||
|
info.spendableBalance = (!conf.is_null()) ? conf.get<double>() : info.balance;
|
||||||
|
} catch (...) { info.spendableBalance = info.balance; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,15 +700,18 @@ NetworkRefreshService::AddressRefreshResult NetworkRefreshService::collectAddres
|
|||||||
result.transparentAddresses = parseTransparentAddressList(tList);
|
result.transparentAddresses = parseTransparentAddressList(tList);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
DEBUG_LOGF("getaddressesbyaccount error: %s\n", e.what());
|
DEBUG_LOGF("getaddressesbyaccount error: %s\n", e.what());
|
||||||
|
result.addressListOk = false; // enumeration failed → the transparent list may be falsely short
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json unspent = rpc.call("listunspent", json::array());
|
json unspent = rpc.call("listunspent", json::array({0})); // minconf=0 → include 0-conf change
|
||||||
applyTransparentBalancesFromUnspent(result.transparentAddresses, unspent);
|
applyTransparentBalancesFromUnspent(result.transparentAddresses, unspent);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
DEBUG_LOGF("listunspent error: %s\n", e.what());
|
DEBUG_LOGF("listunspent error: %s\n", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.scanMs = std::chrono::duration<double, std::milli>(
|
||||||
|
std::chrono::steady_clock::now() - scanStart).count();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -826,6 +903,10 @@ NetworkRefreshService::TransactionRefreshResult NetworkRefreshService::collectTr
|
|||||||
result.blockHeight = currentBlockHeight;
|
result.blockHeight = currentBlockHeight;
|
||||||
result.shieldedAddressCount = snapshot.shieldedAddresses.size();
|
result.shieldedAddressCount = snapshot.shieldedAddresses.size();
|
||||||
result.shieldedScanHeights = snapshot.shieldedScanHeights;
|
result.shieldedScanHeights = snapshot.shieldedScanHeights;
|
||||||
|
// Time the whole scan — the per-address z_listreceivedbyaddress pass is O(mapWallet) and holds the
|
||||||
|
// daemon's cs_main. The measured cost feeds the caller's adaptive throttle (txRefreshDue()) so the
|
||||||
|
// routine full history rescan can't starve block connection on a large wallet.
|
||||||
|
const auto scanStart = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
std::set<std::string> knownTxids;
|
std::set<std::string> knownTxids;
|
||||||
HushChatMemoOutputMap hushChatReceivedOutputs;
|
HushChatMemoOutputMap hushChatReceivedOutputs;
|
||||||
@@ -920,7 +1001,10 @@ NetworkRefreshService::TransactionRefreshResult NetworkRefreshService::collectTr
|
|||||||
if (cached != snapshot.viewTxCache.end()) {
|
if (cached != snapshot.viewTxCache.end()) {
|
||||||
if (!trackedSend || !cached->second.outgoing_outputs.empty()) {
|
if (!trackedSend || !cached->second.outgoing_outputs.empty()) {
|
||||||
appendViewTransactionOutputs(result.transactions, txid, cached->second);
|
appendViewTransactionOutputs(result.transactions, txid, cached->second);
|
||||||
appendExtractedHushChatMetadata(result.hushChatMetadata, txid, cached->second);
|
// NB: do NOT extract chat metadata from our OWN outgoing memos here — ingest marks
|
||||||
|
// everything Incoming, so that duplicates every sent message as a phantom "from peer"
|
||||||
|
// entry. Genuine incoming comes from the z_listreceivedbyaddress path; our sends are
|
||||||
|
// recorded by the local echo. (The recent-refresh variant already omits this.)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -945,7 +1029,8 @@ NetworkRefreshService::TransactionRefreshResult NetworkRefreshService::collectTr
|
|||||||
|
|
||||||
auto entry = parseViewTransactionCacheEntry(viewTransaction);
|
auto entry = parseViewTransactionCacheEntry(viewTransaction);
|
||||||
appendViewTransactionOutputs(result.transactions, txid, entry);
|
appendViewTransactionOutputs(result.transactions, txid, entry);
|
||||||
appendExtractedHushChatMetadata(result.hushChatMetadata, txid, entry);
|
// (Chat metadata is harvested only from RECEIVED notes, not our own outgoing memos — see
|
||||||
|
// the cached-view branch above.)
|
||||||
|
|
||||||
json rawTransaction;
|
json rawTransaction;
|
||||||
bool hasRawTransaction = false;
|
bool hasRawTransaction = false;
|
||||||
@@ -1002,6 +1087,8 @@ NetworkRefreshService::TransactionRefreshResult NetworkRefreshService::collectTr
|
|||||||
}
|
}
|
||||||
|
|
||||||
sortTransactionsNewestFirst(result.transactions);
|
sortTransactionsNewestFirst(result.transactions);
|
||||||
|
result.scanMs = std::chrono::duration<double, std::milli>(
|
||||||
|
std::chrono::steady_clock::now() - scanStart).count();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1021,6 +1108,22 @@ NetworkRefreshService::TransactionRefreshResult NetworkRefreshService::collectRe
|
|||||||
? &hushChatReceivedOutputs
|
? &hushChatReceivedOutputs
|
||||||
: nullptr;
|
: nullptr;
|
||||||
|
|
||||||
|
// Index result.transactions by (txid, type) once so the two replace-loops below
|
||||||
|
// can find-and-replace in O(1) instead of a nested linear scan over the full
|
||||||
|
// (potentially thousands-large) tx list on every 'recent' refresh cycle. The map
|
||||||
|
// holds the index of the FIRST occurrence of each key (preserving the linear
|
||||||
|
// scan's break-on-first-match), and is kept in sync on every append so a later
|
||||||
|
// entry in the same cycle still finds an earlier appended one — exactly as the
|
||||||
|
// re-scanned vector did before.
|
||||||
|
auto txKey = [](const TransactionInfo& tx) {
|
||||||
|
return tx.txid + '\x1f' + tx.type;
|
||||||
|
};
|
||||||
|
std::unordered_map<std::string, std::size_t> byKey;
|
||||||
|
byKey.reserve(result.transactions.size());
|
||||||
|
for (std::size_t i = 0; i < result.transactions.size(); ++i) {
|
||||||
|
byKey.emplace(txKey(result.transactions[i]), i); // keep first-occurrence index
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::set<std::string> recentTxids;
|
std::set<std::string> recentTxids;
|
||||||
std::vector<TransactionInfo> recentTransactions;
|
std::vector<TransactionInfo> recentTransactions;
|
||||||
@@ -1028,16 +1131,14 @@ NetworkRefreshService::TransactionRefreshResult NetworkRefreshService::collectRe
|
|||||||
appendTransparentTransactions(recentTransactions, recentTxids, transactions, snapshot.miningAddresses);
|
appendTransparentTransactions(recentTransactions, recentTxids, transactions, snapshot.miningAddresses);
|
||||||
|
|
||||||
for (auto& recent : recentTransactions) {
|
for (auto& recent : recentTransactions) {
|
||||||
bool replaced = false;
|
auto it = byKey.find(txKey(recent));
|
||||||
for (auto& existing : result.transactions) {
|
if (it != byKey.end()) {
|
||||||
if (existing.txid == recent.txid && existing.type == recent.type) {
|
result.transactions[it->second] = recent;
|
||||||
existing = recent;
|
} else {
|
||||||
replaced = true;
|
byKey.emplace(txKey(recent), result.transactions.size());
|
||||||
break;
|
result.transactions.push_back(std::move(recent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!replaced) result.transactions.push_back(std::move(recent));
|
|
||||||
}
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
DEBUG_LOGF("recent listtransactions error: %s\n", e.what());
|
DEBUG_LOGF("recent listtransactions error: %s\n", e.what());
|
||||||
}
|
}
|
||||||
@@ -1062,16 +1163,14 @@ NetworkRefreshService::TransactionRefreshResult NetworkRefreshService::collectRe
|
|||||||
snapshot.miningAddresses,
|
snapshot.miningAddresses,
|
||||||
hushChatReceivedOutputsPtr);
|
hushChatReceivedOutputsPtr);
|
||||||
for (auto& scanned : scannedTransactions) {
|
for (auto& scanned : scannedTransactions) {
|
||||||
bool replaced = false;
|
auto it = byKey.find(txKey(scanned));
|
||||||
for (auto& existing : result.transactions) {
|
if (it != byKey.end()) {
|
||||||
if (existing.txid == scanned.txid && existing.type == scanned.type) {
|
result.transactions[it->second] = scanned;
|
||||||
existing = scanned;
|
} else {
|
||||||
replaced = true;
|
byKey.emplace(txKey(scanned), result.transactions.size());
|
||||||
break;
|
result.transactions.push_back(std::move(scanned));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!replaced) result.transactions.push_back(std::move(scanned));
|
|
||||||
}
|
|
||||||
if (currentBlockHeight >= 0) result.shieldedScanHeights[address] = currentBlockHeight;
|
if (currentBlockHeight >= 0) result.shieldedScanHeights[address] = currentBlockHeight;
|
||||||
++result.shieldedAddressesScanned;
|
++result.shieldedAddressesScanned;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
@@ -1104,12 +1203,16 @@ NetworkRefreshService::OperationStatusPollResult NetworkRefreshService::parseOpe
|
|||||||
std::set<std::string> reported;
|
std::set<std::string> reported;
|
||||||
for (const auto& op : result) {
|
for (const auto& op : result) {
|
||||||
if (!op.is_object()) continue;
|
if (!op.is_object()) continue;
|
||||||
std::string opid = op.value("id", std::string());
|
// Type-checked reads: .value(key, default) throws if the key is PRESENT with a non-string
|
||||||
|
// type, which would abort the whole poll (and wedge it for the session — see the call site).
|
||||||
|
if (!op.contains("id") || !op["id"].is_string()) continue;
|
||||||
|
std::string opid = op["id"].get<std::string>();
|
||||||
if (opid.empty()) continue;
|
if (opid.empty()) continue;
|
||||||
if (requested.find(opid) == requested.end()) continue; // not one of ours — ignore
|
if (requested.find(opid) == requested.end()) continue; // not one of ours — ignore
|
||||||
reported.insert(opid);
|
reported.insert(opid);
|
||||||
|
|
||||||
std::string status = op.value("status", std::string());
|
std::string status = (op.contains("status") && op["status"].is_string())
|
||||||
|
? op["status"].get<std::string>() : std::string();
|
||||||
if (status == "success") {
|
if (status == "success") {
|
||||||
parsed.doneOpids.push_back(opid);
|
parsed.doneOpids.push_back(opid);
|
||||||
parsed.anySuccess = true;
|
parsed.anySuccess = true;
|
||||||
@@ -1187,6 +1290,12 @@ void NetworkRefreshService::applyCoreRefreshResult(WalletState& state,
|
|||||||
if (result.shieldedBalance) state.shielded_balance = *result.shieldedBalance;
|
if (result.shieldedBalance) state.shielded_balance = *result.shieldedBalance;
|
||||||
if (result.transparentBalance) state.transparent_balance = *result.transparentBalance;
|
if (result.transparentBalance) state.transparent_balance = *result.transparentBalance;
|
||||||
if (result.totalBalance) state.total_balance = *result.totalBalance;
|
if (result.totalBalance) state.total_balance = *result.totalBalance;
|
||||||
|
// Confirmed/spendable totals; if the minconf=1 call was unavailable (old daemon) degrade to the
|
||||||
|
// display value so nothing is *over*-reported as spendable (z_sendmany stays the final gate).
|
||||||
|
state.spendablePrivateBalance = result.spendableShieldedBalance.value_or(state.privateBalance);
|
||||||
|
state.spendableTransparentBalance = result.spendableTransparentBalance.value_or(state.transparentBalance);
|
||||||
|
state.spendableTotalBalance = result.spendableTotalBalance.value_or(state.totalBalance);
|
||||||
|
state.unconfirmedBalance = std::max(0.0, state.totalBalance - state.spendableTotalBalance);
|
||||||
state.last_balance_update = updatedAt;
|
state.last_balance_update = updatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,9 +98,12 @@ public:
|
|||||||
|
|
||||||
struct CoreRefreshResult {
|
struct CoreRefreshResult {
|
||||||
bool balanceOk = false;
|
bool balanceOk = false;
|
||||||
std::optional<double> shieldedBalance;
|
std::optional<double> shieldedBalance; // display (minconf=0, incl. pending change)
|
||||||
std::optional<double> transparentBalance;
|
std::optional<double> transparentBalance;
|
||||||
std::optional<double> totalBalance;
|
std::optional<double> totalBalance;
|
||||||
|
std::optional<double> spendableShieldedBalance; // confirmed (minconf=1)
|
||||||
|
std::optional<double> spendableTransparentBalance;
|
||||||
|
std::optional<double> spendableTotalBalance;
|
||||||
bool blockchainOk = false;
|
bool blockchainOk = false;
|
||||||
std::optional<int> blocks;
|
std::optional<int> blocks;
|
||||||
std::optional<int> headers;
|
std::optional<int> headers;
|
||||||
@@ -108,6 +111,7 @@ public:
|
|||||||
std::optional<double> verificationProgress;
|
std::optional<double> verificationProgress;
|
||||||
std::optional<int> longestChain;
|
std::optional<int> longestChain;
|
||||||
std::optional<int> notarized;
|
std::optional<int> notarized;
|
||||||
|
double balanceScanMs = 0.0; // wall-clock spent in z_gettotalbalance this refresh (0 if balance skipped)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MiningRefreshResult {
|
struct MiningRefreshResult {
|
||||||
@@ -143,9 +147,27 @@ public:
|
|||||||
std::string errorMessage;
|
std::string errorMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Minimal per-note view of a z_listunspent entry — just what a downstream consumer needs to derive
|
||||||
|
// spendable-note budgets without re-scanning. Kept UI/feature-agnostic (no chat specifics here).
|
||||||
|
struct UnspentNoteLite {
|
||||||
|
double amount = 0.0; // note value, DRGX
|
||||||
|
bool locked = false; // tied up by an in-flight send
|
||||||
|
int confirmations = 0; // TRUE depth (rawconfirmations when present, else confirmations)
|
||||||
|
};
|
||||||
|
|
||||||
struct AddressRefreshResult {
|
struct AddressRefreshResult {
|
||||||
std::vector<AddressInfo> shieldedAddresses;
|
std::vector<AddressInfo> shieldedAddresses;
|
||||||
std::vector<AddressInfo> transparentAddresses;
|
std::vector<AddressInfo> transparentAddresses;
|
||||||
|
// False if either address-enumeration RPC (z_listaddresses / getaddressesbyaccount) threw, so the
|
||||||
|
// lists may be falsely short. Consumers that treat an empty list as authoritative (e.g. the
|
||||||
|
// empty-wallet warning) must not trust a 0 count unless this is true.
|
||||||
|
bool addressListOk = true;
|
||||||
|
// Wall-clock spent in the address scan (dominated by z_listunspent — O(mapWallet), holds the
|
||||||
|
// daemon's cs_main). Lets the caller throttle how often it polls (addressRefreshDue()).
|
||||||
|
double scanMs = 0.0;
|
||||||
|
// The wallet's unspent notes from this same z_listunspent scan, so a consumer (e.g. the chat
|
||||||
|
// note-budget) can be fed for free instead of running its own duplicate z_listunspent.
|
||||||
|
std::vector<UnspentNoteLite> unspentNotes;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AddressRefreshSnapshot {
|
struct AddressRefreshSnapshot {
|
||||||
@@ -197,6 +219,9 @@ public:
|
|||||||
std::size_t shieldedAddressCount = 0;
|
std::size_t shieldedAddressCount = 0;
|
||||||
std::unordered_map<std::string, int> shieldedScanHeights;
|
std::unordered_map<std::string, int> shieldedScanHeights;
|
||||||
bool shieldedScanComplete = true;
|
bool shieldedScanComplete = true;
|
||||||
|
// Wall-clock spent in the history scan (z_listreceivedbyaddress — O(mapWallet), holds cs_main).
|
||||||
|
// Lets the caller throttle the routine full rescan by its measured cost (txRefreshDue()).
|
||||||
|
double scanMs = 0.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OperationStatusPollResult {
|
struct OperationStatusPollResult {
|
||||||
@@ -227,6 +252,7 @@ public:
|
|||||||
RefreshRpcGateway& rpc,
|
RefreshRpcGateway& rpc,
|
||||||
const std::optional<ConnectionInfoResult>& prefetchedInfo = std::nullopt);
|
const std::optional<ConnectionInfoResult>& prefetchedInfo = std::nullopt);
|
||||||
static CoreRefreshResult parseCoreRefreshResult(const nlohmann::json& totalBalance,
|
static CoreRefreshResult parseCoreRefreshResult(const nlohmann::json& totalBalance,
|
||||||
|
const nlohmann::json& spendableBalance,
|
||||||
bool balanceOk,
|
bool balanceOk,
|
||||||
const nlohmann::json& blockInfo,
|
const nlohmann::json& blockInfo,
|
||||||
bool blockOk);
|
bool blockOk);
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#include "wallet_security_controller.h"
|
#include "wallet_security_controller.h"
|
||||||
#include "../util/secure_vault.h"
|
#include "../util/secure_vault.h"
|
||||||
|
#include "../util/address_validation.h"
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace dragonx {
|
namespace dragonx {
|
||||||
namespace services {
|
namespace services {
|
||||||
@@ -108,18 +111,35 @@ WalletSecurityController::KeyKind WalletSecurityController::classifyPrivateKey(c
|
|||||||
|
|
||||||
bool WalletSecurityController::isViewingKey(const std::string& key)
|
bool WalletSecurityController::isViewingKey(const std::string& key)
|
||||||
{
|
{
|
||||||
// Sapling extended full viewing key (mainnet HRP "zxviews"; "zxview" also matches the prefix the
|
// DragonX's z_exportviewingkey returns a Sapling *incoming* viewing key (mainnet HRP "zivks");
|
||||||
// lite backend recognizes). Watch-only: reveals the address's funds but cannot spend them.
|
// z_importviewingkey only decodes that form. Recognize it structurally — a valid Bech32 checksum
|
||||||
return key.rfind("zxview", 0) == 0;
|
// plus a known HRP — instead of a bare prefix, and cover testnet/regtest too. (The old check
|
||||||
|
// looked for Zcash's "zxview" extended-FVK HRP, which DragonX never emits, so every real viewing
|
||||||
|
// key was rejected client-side.) Watch-only: reveals the address's funds but cannot spend them.
|
||||||
|
const std::string hrp = util::bech32Hrp(key);
|
||||||
|
return hrp == "zivks" // mainnet
|
||||||
|
|| hrp == "zivktestsapling" // testnet
|
||||||
|
|| hrp == "zivkregtestsapling"; // regtest
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WalletSecurityController::isRecognizedPrivateKey(const std::string& key)
|
bool WalletSecurityController::isRecognizedPrivateKey(const std::string& key)
|
||||||
{
|
{
|
||||||
|
// Sapling z spending key (HRP "secret-extended-key-{main,test,regtest}"). These run ~300 chars,
|
||||||
|
// past the Bech32 length cap, so match by HRP prefix and let the daemon vet the payload.
|
||||||
if (key.rfind("secret-extended-key-", 0) == 0) return true; // Sapling z spending key
|
if (key.rfind("secret-extended-key-", 0) == 0) return true; // Sapling z spending key
|
||||||
if (key.size() >= 2 && key[0] == 'S' && key[1] == 'K') return true; // Sprout z spending key
|
if (key.size() >= 2 && key[0] == 'S' && key[1] == 'K') return true; // Sprout z spending key
|
||||||
// Transparent WIF: base58, ~51-52 chars, common version prefixes.
|
// Transparent WIF: decode Base58Check and confirm it is actually a secret key — version byte plus
|
||||||
if (key.size() >= 51 && key.size() <= 52 &&
|
// a 32-byte key, optionally a compression flag (payload 33 or 34 bytes). This accepts BOTH the
|
||||||
(key[0] == '5' || key[0] == 'K' || key[0] == 'L' || key[0] == 'U')) return true;
|
// compressed ("U…") and uncompressed ("7…") mainnet forms and the testnet form, and rejects
|
||||||
|
// addresses / typos via the real checksum — the old length+first-char heuristic dropped the
|
||||||
|
// uncompressed mainnet key (which starts with '7', not one of 5/K/L/U).
|
||||||
|
std::vector<std::uint8_t> payload;
|
||||||
|
if (util::decodeBase58Check(key, payload) &&
|
||||||
|
(payload.size() == 33 || payload.size() == 34) &&
|
||||||
|
(payload[0] == 188 /* DragonX main/regtest SECRET_KEY */ ||
|
||||||
|
payload[0] == 128 /* DragonX testnet SECRET_KEY */)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public:
|
|||||||
std::size_t minLength = 4);
|
std::size_t minLength = 4);
|
||||||
static KeyKind classifyAddress(const std::string& address);
|
static KeyKind classifyAddress(const std::string& address);
|
||||||
static KeyKind classifyPrivateKey(const std::string& key);
|
static KeyKind classifyPrivateKey(const std::string& key);
|
||||||
// True if `key` is a shielded viewing key (extended full viewing key, "zxview…" — watch-only).
|
// True if `key` is a shielded viewing key (Sapling incoming viewing key, "zivks…" — watch-only).
|
||||||
static bool isViewingKey(const std::string& key);
|
static bool isViewingKey(const std::string& key);
|
||||||
// True if `key` looks like a recognized Z (Sapling/Sprout spending) or T (WIF) private key.
|
// True if `key` looks like a recognized Z (Sapling/Sprout spending) or T (WIF) private key.
|
||||||
static bool isRecognizedPrivateKey(const std::string& key);
|
static bool isRecognizedPrivateKey(const std::string& key);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "theme_effects.h"
|
#include "theme_effects.h"
|
||||||
#include "low_spec.h"
|
#include "low_spec.h"
|
||||||
#include "../schema/ui_schema.h"
|
#include "../schema/ui_schema.h"
|
||||||
|
#include "../layout.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -58,6 +59,7 @@ void ThemeEffects::beginFrame() {
|
|||||||
|
|
||||||
void ThemeEffects::loadFromTheme() {
|
void ThemeEffects::loadFromTheme() {
|
||||||
auto& S = schema::UI();
|
auto& S = schema::UI();
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
auto eff = [&](const char* name) {
|
auto eff = [&](const char* name) {
|
||||||
return S.drawElement("effects", name);
|
return S.drawElement("effects", name);
|
||||||
};
|
};
|
||||||
@@ -98,7 +100,7 @@ void ThemeEffects::loadFromTheme() {
|
|||||||
// ---- Shimmer ----
|
// ---- Shimmer ----
|
||||||
shimmer_.enabled = eff("shimmer-enabled").sizeOr(0.0f) > 0.5f;
|
shimmer_.enabled = eff("shimmer-enabled").sizeOr(0.0f) > 0.5f;
|
||||||
shimmer_.speed = eff("shimmer-speed").sizeOr(0.12f);
|
shimmer_.speed = eff("shimmer-speed").sizeOr(0.12f);
|
||||||
shimmer_.width = eff("shimmer-width").sizeOr(80.0f);
|
shimmer_.width = eff("shimmer-width").sizeOr(80.0f) * dp;
|
||||||
shimmer_.alpha = eff("shimmer-alpha").sizeOr(0.06f);
|
shimmer_.alpha = eff("shimmer-alpha").sizeOr(0.06f);
|
||||||
shimmer_.angle = eff("shimmer-angle").sizeOr(30.0f);
|
shimmer_.angle = eff("shimmer-angle").sizeOr(30.0f);
|
||||||
// Shimmer color: read from the schema's color resolver
|
// Shimmer color: read from the schema's color resolver
|
||||||
@@ -124,7 +126,7 @@ void ThemeEffects::loadFromTheme() {
|
|||||||
glow_pulse_.speed = eff("glow-pulse-speed").sizeOr(2.0f);
|
glow_pulse_.speed = eff("glow-pulse-speed").sizeOr(2.0f);
|
||||||
glow_pulse_.minAlpha = eff("glow-pulse-min-alpha").sizeOr(0.0f);
|
glow_pulse_.minAlpha = eff("glow-pulse-min-alpha").sizeOr(0.0f);
|
||||||
glow_pulse_.maxAlpha = eff("glow-pulse-max-alpha").sizeOr(0.15f);
|
glow_pulse_.maxAlpha = eff("glow-pulse-max-alpha").sizeOr(0.15f);
|
||||||
glow_pulse_.radius = eff("glow-pulse-radius").sizeOr(4.0f);
|
glow_pulse_.radius = eff("glow-pulse-radius").sizeOr(4.0f) * dp;
|
||||||
auto glowColorElem = eff("glow-pulse-color");
|
auto glowColorElem = eff("glow-pulse-color");
|
||||||
if (!glowColorElem.color.empty()) {
|
if (!glowColorElem.color.empty()) {
|
||||||
glow_pulse_.color = S.resolveColor(glowColorElem.color, IM_COL32(255, 218, 0, 255));
|
glow_pulse_.color = S.resolveColor(glowColorElem.color, IM_COL32(255, 218, 0, 255));
|
||||||
@@ -136,7 +138,7 @@ void ThemeEffects::loadFromTheme() {
|
|||||||
edge_trace_.enabled = eff("edge-trace-enabled").sizeOr(0.0f) > 0.5f;
|
edge_trace_.enabled = eff("edge-trace-enabled").sizeOr(0.0f) > 0.5f;
|
||||||
edge_trace_.speed = eff("edge-trace-speed").sizeOr(0.3f);
|
edge_trace_.speed = eff("edge-trace-speed").sizeOr(0.3f);
|
||||||
edge_trace_.length = eff("edge-trace-length").sizeOr(0.20f);
|
edge_trace_.length = eff("edge-trace-length").sizeOr(0.20f);
|
||||||
edge_trace_.thickness = eff("edge-trace-thickness").sizeOr(1.5f);
|
edge_trace_.thickness = eff("edge-trace-thickness").sizeOr(1.5f) * dp;
|
||||||
edge_trace_.alpha = eff("edge-trace-alpha").sizeOr(0.6f);
|
edge_trace_.alpha = eff("edge-trace-alpha").sizeOr(0.6f);
|
||||||
auto edgeColorElem = eff("edge-trace-color");
|
auto edgeColorElem = eff("edge-trace-color");
|
||||||
if (!edgeColorElem.color.empty()) {
|
if (!edgeColorElem.color.empty()) {
|
||||||
@@ -149,7 +151,7 @@ void ThemeEffects::loadFromTheme() {
|
|||||||
ember_rise_.enabled = eff("ember-rise-enabled").sizeOr(0.0f) > 0.5f;
|
ember_rise_.enabled = eff("ember-rise-enabled").sizeOr(0.0f) > 0.5f;
|
||||||
ember_rise_.count = (int)eff("ember-rise-count").sizeOr(8.0f);
|
ember_rise_.count = (int)eff("ember-rise-count").sizeOr(8.0f);
|
||||||
ember_rise_.speed = eff("ember-rise-speed").sizeOr(0.4f);
|
ember_rise_.speed = eff("ember-rise-speed").sizeOr(0.4f);
|
||||||
ember_rise_.particleSize = eff("ember-rise-particle-size").sizeOr(1.5f);
|
ember_rise_.particleSize = eff("ember-rise-particle-size").sizeOr(1.5f) * dp;
|
||||||
ember_rise_.alpha = eff("ember-rise-alpha").sizeOr(0.5f);
|
ember_rise_.alpha = eff("ember-rise-alpha").sizeOr(0.5f);
|
||||||
auto emberColorElem = eff("ember-rise-color");
|
auto emberColorElem = eff("ember-rise-color");
|
||||||
if (!emberColorElem.color.empty()) {
|
if (!emberColorElem.color.empty()) {
|
||||||
@@ -160,8 +162,12 @@ void ThemeEffects::loadFromTheme() {
|
|||||||
|
|
||||||
// ---- Gradient Border Shift ----
|
// ---- Gradient Border Shift ----
|
||||||
gradient_border_.enabled = eff("gradient-border-enabled").sizeOr(0.0f) > 0.5f;
|
gradient_border_.enabled = eff("gradient-border-enabled").sizeOr(0.0f) > 0.5f;
|
||||||
|
// Opt-in: also draw the shifting border on every glass panel (not just the
|
||||||
|
// active nav button). Off by default so themes that only want the button
|
||||||
|
// accent (e.g. Obsidian) are unaffected; Jade turns it on as its hero.
|
||||||
|
gradient_border_.panels = eff("gradient-border-panels").sizeOr(0.0f) > 0.5f;
|
||||||
gradient_border_.speed = eff("gradient-border-speed").sizeOr(0.15f);
|
gradient_border_.speed = eff("gradient-border-speed").sizeOr(0.15f);
|
||||||
gradient_border_.thickness = eff("gradient-border-thickness").sizeOr(1.5f);
|
gradient_border_.thickness = eff("gradient-border-thickness").sizeOr(1.5f) * dp;
|
||||||
gradient_border_.alpha = eff("gradient-border-alpha").sizeOr(0.6f);
|
gradient_border_.alpha = eff("gradient-border-alpha").sizeOr(0.6f);
|
||||||
auto gbColorA = eff("gradient-border-color-a");
|
auto gbColorA = eff("gradient-border-color-a");
|
||||||
if (!gbColorA.color.empty()) {
|
if (!gbColorA.color.empty()) {
|
||||||
@@ -190,7 +196,7 @@ void ThemeEffects::loadFromTheme() {
|
|||||||
sandstorm_.count = (int)eff("sandstorm-count").sizeOr(80.0f);
|
sandstorm_.count = (int)eff("sandstorm-count").sizeOr(80.0f);
|
||||||
sandstorm_.speed = eff("sandstorm-speed").sizeOr(0.35f);
|
sandstorm_.speed = eff("sandstorm-speed").sizeOr(0.35f);
|
||||||
sandstorm_.windAngle = eff("sandstorm-wind-angle").sizeOr(15.0f);
|
sandstorm_.windAngle = eff("sandstorm-wind-angle").sizeOr(15.0f);
|
||||||
sandstorm_.particleSize = eff("sandstorm-particle-size").sizeOr(1.5f);
|
sandstorm_.particleSize = eff("sandstorm-particle-size").sizeOr(1.5f) * dp;
|
||||||
sandstorm_.alpha = eff("sandstorm-alpha").sizeOr(0.35f);
|
sandstorm_.alpha = eff("sandstorm-alpha").sizeOr(0.35f);
|
||||||
sandstorm_.gustSpeed = eff("sandstorm-gust-speed").sizeOr(0.07f);
|
sandstorm_.gustSpeed = eff("sandstorm-gust-speed").sizeOr(0.07f);
|
||||||
sandstorm_.gustStrength = eff("sandstorm-gust-strength").sizeOr(0.4f);
|
sandstorm_.gustStrength = eff("sandstorm-gust-strength").sizeOr(0.4f);
|
||||||
@@ -512,11 +518,15 @@ void ThemeEffects::drawGlowPulse(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax,
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
void ThemeEffects::drawGradientBorderShift(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax,
|
void ThemeEffects::drawGradientBorderShift(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax,
|
||||||
float rounding) const {
|
float rounding, float phaseOffset,
|
||||||
|
float alphaMul) const {
|
||||||
if (!enabled_ || !gradient_border_.enabled) return;
|
if (!enabled_ || !gradient_border_.enabled) return;
|
||||||
|
|
||||||
// Smooth sinusoidal oscillation between color A and color B
|
// Smooth sinusoidal oscillation between color A and color B.
|
||||||
float phase = std::sin(time_ * gradient_border_.speed * 2.0f * 3.14159265f) * 0.5f + 0.5f;
|
// phaseOffset shifts where in the cycle this element sits so a wall of
|
||||||
|
// panels reads like veins at different depths rather than one pulse.
|
||||||
|
float phase = std::sin((time_ * gradient_border_.speed + phaseOffset)
|
||||||
|
* 2.0f * 3.14159265f) * 0.5f + 0.5f;
|
||||||
|
|
||||||
// Extract RGBA from both colors and lerp
|
// Extract RGBA from both colors and lerp
|
||||||
RGB ca = unpackRGB(gradient_border_.colorA);
|
RGB ca = unpackRGB(gradient_border_.colorA);
|
||||||
@@ -525,7 +535,7 @@ void ThemeEffects::drawGradientBorderShift(ImDrawList* dl, ImVec2 pMin, ImVec2 p
|
|||||||
int r = ca.r + (int)((cb.r - ca.r) * phase);
|
int r = ca.r + (int)((cb.r - ca.r) * phase);
|
||||||
int g = ca.g + (int)((cb.g - ca.g) * phase);
|
int g = ca.g + (int)((cb.g - ca.g) * phase);
|
||||||
int b = ca.b + (int)((cb.b - ca.b) * phase);
|
int b = ca.b + (int)((cb.b - ca.b) * phase);
|
||||||
int a = scaledAlpha(gradient_border_.alpha, bgOpacity_);
|
int a = scaledAlpha(gradient_border_.alpha * alphaMul, bgOpacity_);
|
||||||
|
|
||||||
// Draw the shifting border
|
// Draw the shifting border
|
||||||
dl->AddRect(pMin, pMax, IM_COL32(r, g, b, a),
|
dl->AddRect(pMin, pMax, IM_COL32(r, g, b, a),
|
||||||
@@ -686,6 +696,7 @@ void ThemeEffects::drawEdgeTrace(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax,
|
|||||||
void ThemeEffects::drawEmberRise(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax) const {
|
void ThemeEffects::drawEmberRise(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax) const {
|
||||||
if (!enabled_ || !ember_rise_.enabled) return;
|
if (!enabled_ || !ember_rise_.enabled) return;
|
||||||
|
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
float w = pMax.x - pMin.x;
|
float w = pMax.x - pMin.x;
|
||||||
float h = pMax.y - pMin.y;
|
float h = pMax.y - pMin.y;
|
||||||
if (w <= 0 || h <= 0) return;
|
if (w <= 0 || h <= 0) return;
|
||||||
@@ -699,7 +710,7 @@ void ThemeEffects::drawEmberRise(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax) const
|
|||||||
// Deterministic pseudo-random x position per particle
|
// Deterministic pseudo-random x position per particle
|
||||||
// Simple hash: sin of large prime multiples
|
// Simple hash: sin of large prime multiples
|
||||||
float xHash = std::sin((float)(i + 1) * 127.1f) * 0.5f + 0.5f;
|
float xHash = std::sin((float)(i + 1) * 127.1f) * 0.5f + 0.5f;
|
||||||
float xDrift = std::sin(time_ * 0.7f + i * 2.4f) * 4.0f; // gentle sway
|
float xDrift = std::sin(time_ * 0.7f + i * 2.4f) * 4.0f * dp; // gentle sway
|
||||||
|
|
||||||
float x = pMin.x + w * xHash + xDrift;
|
float x = pMin.x + w * xHash + xDrift;
|
||||||
float y = pMax.y - phase * (h + 8.0f); // rise from bottom past top
|
float y = pMax.y - phase * (h + 8.0f); // rise from bottom past top
|
||||||
@@ -737,6 +748,7 @@ void ThemeEffects::drawEmberRise(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax) const
|
|||||||
void ThemeEffects::drawViewportEmbers(ImDrawList* dl) const {
|
void ThemeEffects::drawViewportEmbers(ImDrawList* dl) const {
|
||||||
if (!enabled_ || !ember_rise_.enabled) return;
|
if (!enabled_ || !ember_rise_.enabled) return;
|
||||||
|
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
ImGuiViewport* vp = ImGui::GetMainViewport();
|
ImGuiViewport* vp = ImGui::GetMainViewport();
|
||||||
float vpW = vp->WorkSize.x;
|
float vpW = vp->WorkSize.x;
|
||||||
float vpH = vp->WorkSize.y;
|
float vpH = vp->WorkSize.y;
|
||||||
@@ -757,7 +769,7 @@ void ThemeEffects::drawViewportEmbers(ImDrawList* dl) const {
|
|||||||
float xHash = std::sin((float)(i + 1) * 127.1f) * 43758.5453f;
|
float xHash = std::sin((float)(i + 1) * 127.1f) * 43758.5453f;
|
||||||
xHash = xHash - (int)xHash; // fractional part
|
xHash = xHash - (int)xHash; // fractional part
|
||||||
if (xHash < 0) xHash += 1.0f;
|
if (xHash < 0) xHash += 1.0f;
|
||||||
float xDrift = std::sin(time_ * 0.5f + i * 1.7f) * 8.0f;
|
float xDrift = std::sin(time_ * 0.5f + i * 1.7f) * 8.0f * dp;
|
||||||
|
|
||||||
float x = vpX + vpW * xHash + xDrift;
|
float x = vpX + vpW * xHash + xDrift;
|
||||||
float y = vpY + vpH * (1.0f - phase); // rise from bottom to top
|
float y = vpY + vpH * (1.0f - phase); // rise from bottom to top
|
||||||
@@ -896,6 +908,22 @@ void ThemeEffects::drawPanelEffects(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax,
|
|||||||
float rounding) const {
|
float rounding) const {
|
||||||
if (!enabled_ || effects::isLowSpecMode()) return;
|
if (!enabled_ || effects::isLowSpecMode()) return;
|
||||||
|
|
||||||
|
// Gradient border on panels — a slow color-shifting outline that hugs the
|
||||||
|
// panel's rounded corners (drawn via AddRect, so it follows the rounding
|
||||||
|
// exactly — no polygonal corners). Position-based phase offset makes each
|
||||||
|
// panel drift like a vein at a different depth; softer than the active
|
||||||
|
// nav button (alphaMul 0.6) so a screenful of panels stays calm.
|
||||||
|
if (gradient_border_.enabled && gradient_border_.panels) {
|
||||||
|
float w = pMax.x - pMin.x;
|
||||||
|
float h = pMax.y - pMin.y;
|
||||||
|
if (w > 80 && h > 40) { // skip small panels
|
||||||
|
float posKey = (pMin.x * 0.0073f + pMin.y * 0.0137f);
|
||||||
|
posKey = posKey - (int)posKey; // fractional 0..1
|
||||||
|
if (posKey < 0) posKey += 1.0f;
|
||||||
|
drawGradientBorderShift(dl, pMin, pMax, rounding, posKey, 0.6f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Edge trace on panels — use position-based phase offset so each
|
// Edge trace on panels — use position-based phase offset so each
|
||||||
// panel's tracer is at a different position around the border
|
// panel's tracer is at a different position around the border
|
||||||
if (edge_trace_.enabled) {
|
if (edge_trace_.enabled) {
|
||||||
|
|||||||
@@ -69,9 +69,12 @@ public:
|
|||||||
void drawEdgeTrace(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax,
|
void drawEdgeTrace(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax,
|
||||||
float rounding) const;
|
float rounding) const;
|
||||||
|
|
||||||
/// Draw a border that shifts between two colors over time (gem-like)
|
/// Draw a border that shifts between two colors over time (gem-like).
|
||||||
|
/// phaseOffset (0..1) shifts this element's point in the color cycle so
|
||||||
|
/// many panels don't pulse in unison; alphaMul scales the whole effect.
|
||||||
void drawGradientBorderShift(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax,
|
void drawGradientBorderShift(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax,
|
||||||
float rounding) const;
|
float rounding, float phaseOffset = 0.0f,
|
||||||
|
float alphaMul = 1.0f) const;
|
||||||
|
|
||||||
/// Draw ember particles that rise from an element (fire theme)
|
/// Draw ember particles that rise from an element (fire theme)
|
||||||
void drawEmberRise(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax) const;
|
void drawEmberRise(ImDrawList* dl, ImVec2 pMin, ImVec2 pMax) const;
|
||||||
@@ -186,6 +189,7 @@ private:
|
|||||||
|
|
||||||
struct GradientBorderConfig {
|
struct GradientBorderConfig {
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
|
bool panels = false; ///< also draw on glass panels, not just the active nav button
|
||||||
float speed = 0.15f; ///< full color shift cycles per second
|
float speed = 0.15f; ///< full color shift cycles per second
|
||||||
float thickness = 1.5f; ///< border line thickness in pixels
|
float thickness = 1.5f; ///< border line thickness in pixels
|
||||||
float alpha = 0.6f; ///< peak alpha
|
float alpha = 0.6f; ///< peak alpha
|
||||||
|
|||||||
@@ -173,6 +173,24 @@ inline float kSidePanelMinWidth() { return schema::UI().drawElement("panels",
|
|||||||
inline float kSidePanelMaxWidth() { return schema::UI().drawElement("panels", "side-panel").getFloat("max-width", 450.0f) * dpiScale(); }
|
inline float kSidePanelMaxWidth() { return schema::UI().drawElement("panels", "side-panel").getFloat("max-width", 450.0f) * dpiScale(); }
|
||||||
inline float kSidePanelWidthRatio() { return schema::UI().drawElement("panels", "side-panel").getFloat("width-ratio", 0.4f); }
|
inline float kSidePanelWidthRatio() { return schema::UI().drawElement("panels", "side-panel").getFloat("width-ratio", 0.4f); }
|
||||||
|
|
||||||
|
// Overall content-column cap: the max width a tab's content occupies before it is centered in wider
|
||||||
|
// windows. <= 0 disables the cap so tab content fills ALL available horizontal width (the default —
|
||||||
|
// requested so large windows don't leave a big empty gutter on the right). Set a positive
|
||||||
|
// ui.toml [layout] content-max-width to re-enable a centered readable column.
|
||||||
|
inline float kContentMaxWidth() { return schema::UI().drawElement("layout", "content-max-width").sizeOr(0.0f) * dpiScale(); }
|
||||||
|
|
||||||
|
// Shared compose-card envelope for the Send + Receive tabs (and any tab wanting the same box): fill the
|
||||||
|
// available column up to the content-max-width cap, then center the leftover as margin. Both tabs MUST
|
||||||
|
// derive their card width/offset from this so the two envelopes stay byte-for-byte identical — they
|
||||||
|
// previously drifted (Send capped at 760dp, Receive at 860dp), so the Send card rendered narrower than
|
||||||
|
// Receive on any window wider than ~860dp. Returns {width, offsetX} in the same units as availW.
|
||||||
|
struct CardBox { float width; float offsetX; };
|
||||||
|
inline CardBox mainComposeCardBox(float availW) {
|
||||||
|
float cap = kContentMaxWidth();
|
||||||
|
float w = (cap > 0.0f) ? std::min(availW, cap) : availW; // cap <= 0 -> fill full width
|
||||||
|
return CardBox{ w, std::max(0.0f, (availW - w) * 0.5f) };
|
||||||
|
}
|
||||||
|
|
||||||
inline float kTableMinHeight() { return schema::UI().drawElement("panels", "table").getFloat("min-height", 150.0f) * dpiScale(); }
|
inline float kTableMinHeight() { return schema::UI().drawElement("panels", "table").getFloat("min-height", 150.0f) * dpiScale(); }
|
||||||
inline float kTableHeightRatio() { return schema::UI().drawElement("panels", "table").getFloat("height-ratio", 0.45f); }
|
inline float kTableHeightRatio() { return schema::UI().drawElement("panels", "table").getFloat("height-ratio", 0.45f); }
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,26 @@ inline ImVec4 WarningVec4() { return ImGui::ColorConvertU32ToFloat4(Warni
|
|||||||
// Convenience Functions for Common Patterns
|
// Convenience Functions for Common Patterns
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Theme-aware translucent overlay for tracks / hover fills / dividers.
|
||||||
|
*
|
||||||
|
* A raw white overlay (IM_COL32(255,255,255,a)) reads on dark skins but vanishes
|
||||||
|
* on light/pastel skins (white-on-white). This picks a dark overlay on light
|
||||||
|
* themes and a white overlay on dark themes so the alpha reads either way.
|
||||||
|
* (Self-contained luminance check so colors.h stays free of draw_helpers.h.)
|
||||||
|
*
|
||||||
|
* @param alpha 0-255 opacity of the overlay
|
||||||
|
*/
|
||||||
|
inline ImU32 SurfaceOverlay(int alpha)
|
||||||
|
{
|
||||||
|
ImU32 bg = Background();
|
||||||
|
float r = ((bg >> IM_COL32_R_SHIFT) & 0xFF) / 255.0f;
|
||||||
|
float g = ((bg >> IM_COL32_G_SHIFT) & 0xFF) / 255.0f;
|
||||||
|
float b = ((bg >> IM_COL32_B_SHIFT) & 0xFF) / 255.0f;
|
||||||
|
bool light = (0.299f * r + 0.587f * g + 0.114f * b) > 0.5f;
|
||||||
|
return light ? IM_COL32(0, 0, 0, alpha) : IM_COL32(255, 255, 255, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get color with applied state overlay
|
* @brief Get color with applied state overlay
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -57,6 +57,21 @@ inline ImU32 ReadableError() {
|
|||||||
return IM_COL32(r, g, b, (e >> IM_COL32_A_SHIFT) & 0xFF);
|
return IM_COL32(r, g, b, (e >> IM_COL32_A_SHIFT) & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Middle-ellipsis truncation ("front...back", roughly equal halves) so `text` fits within
|
||||||
|
// maxWidth pixels when drawn with `font` at `fontSize`. Returns `text` unchanged if it already
|
||||||
|
// fits (or maxWidth is non-positive). Display-only — never mutate the underlying value with this.
|
||||||
|
inline std::string TruncateToWidth(const std::string& text, ImFont* font, float fontSize, float maxWidth) {
|
||||||
|
if (text.empty() || !font || maxWidth <= 0.0f) return text;
|
||||||
|
if (font->CalcTextSizeA(fontSize, FLT_MAX, 0.0f, text.c_str()).x <= maxWidth) return text;
|
||||||
|
const int n = static_cast<int>(text.size());
|
||||||
|
for (int f = n / 2; f >= 3; --f) {
|
||||||
|
const int b = (f - 2 > 3) ? (f - 2) : 3; // keep the two halves roughly equal
|
||||||
|
std::string t = text.substr(0, f) + "..." + text.substr(n - b);
|
||||||
|
if (font->CalcTextSizeA(fontSize, FLT_MAX, 0.0f, t.c_str()).x <= maxWidth) return t;
|
||||||
|
}
|
||||||
|
return n > 6 ? (text.substr(0, 3) + "..." + text.substr(n - 3)) : text;
|
||||||
|
}
|
||||||
|
|
||||||
// Animated "loading" ellipsis: "", ".", "..", "..." cycling on a ~3Hz phase.
|
// Animated "loading" ellipsis: "", ".", "..", "..." cycling on a ~3Hz phase.
|
||||||
inline const char* LoadingDots() {
|
inline const char* LoadingDots() {
|
||||||
int n = ((int)(ImGui::GetTime() * 3.0f)) % 4;
|
int n = ((int)(ImGui::GetTime() * 3.0f)) % 4;
|
||||||
@@ -64,6 +79,63 @@ inline const char* LoadingDots() {
|
|||||||
return kDots[n];
|
return kDots[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Centered empty state ─────────────────────────────────────────────────
|
||||||
|
// A big muted icon + title + optional wrapped hint, centered on BOTH axes within
|
||||||
|
// GetContentRegionAvail(). Mirrors chat_tab's centeredEmptyState so list-empty states
|
||||||
|
// read the same across tabs. Call at the start of the region you want it centered in
|
||||||
|
// (e.g. right after a BeginChild / a leading Dummy). Font metrics use the live font
|
||||||
|
// scale (LegacySize * FontScaleMain) and PushFont draws at that same scale, so this is
|
||||||
|
// crisp at HiDPI / font_scale 1.5 without any manual dpiScale multiply on the metrics.
|
||||||
|
inline void DrawEmptyState(const char* iconGlyph, const char* title, const char* hint = nullptr)
|
||||||
|
{
|
||||||
|
auto scaled = [](ImFont* f) { return f->LegacySize * ImGui::GetStyle().FontScaleMain; };
|
||||||
|
const ImVec2 avail = ImGui::GetContentRegionAvail();
|
||||||
|
const ImVec2 origin = ImGui::GetCursorPos();
|
||||||
|
ImFont* iconF = Type().iconXL();
|
||||||
|
ImFont* titleF = Type().subtitle1();
|
||||||
|
ImFont* hintF = Type().body2();
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
|
const float gap = 8.0f * dp;
|
||||||
|
const float wrap = std::min(avail.x - 40.0f * dp, 360.0f * dp);
|
||||||
|
const float iconSz = iconF ? scaled(iconF) : 40.0f;
|
||||||
|
const float iconH = (iconF && iconGlyph) ? iconF->CalcTextSizeA(iconSz, FLT_MAX, 0.0f, iconGlyph).y : 0.0f;
|
||||||
|
const float titleH = titleF->CalcTextSizeA(scaled(titleF), FLT_MAX, 0.0f, title).y;
|
||||||
|
const float hintH = hint ? hintF->CalcTextSizeA(scaled(hintF), wrap, wrap, hint).y : 0.0f;
|
||||||
|
const float totalH = iconH + (iconH > 0.0f ? gap : 0.0f) + titleH + (hint ? gap + hintH : 0.0f);
|
||||||
|
float y = origin.y + std::max(0.0f, (avail.y - totalH) * 0.5f);
|
||||||
|
|
||||||
|
if (iconF && iconGlyph && iconGlyph[0]) {
|
||||||
|
const float iw = iconF->CalcTextSizeA(iconSz, FLT_MAX, 0.0f, iconGlyph).x;
|
||||||
|
ImGui::SetCursorPos(ImVec2(origin.x + (avail.x - iw) * 0.5f, y));
|
||||||
|
ImGui::PushFont(iconF);
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text, WithAlpha(OnSurface(), 70));
|
||||||
|
ImGui::TextUnformatted(iconGlyph);
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
ImGui::PopFont();
|
||||||
|
y += iconH + gap;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const float tw = titleF->CalcTextSizeA(scaled(titleF), FLT_MAX, 0.0f, title).x;
|
||||||
|
ImGui::SetCursorPos(ImVec2(origin.x + (avail.x - tw) * 0.5f, y));
|
||||||
|
ImGui::PushFont(titleF);
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text, OnSurfaceMedium());
|
||||||
|
ImGui::TextUnformatted(title);
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
ImGui::PopFont();
|
||||||
|
y += titleH + gap;
|
||||||
|
}
|
||||||
|
if (hint) {
|
||||||
|
ImGui::SetCursorPos(ImVec2(origin.x + (avail.x - wrap) * 0.5f, y));
|
||||||
|
ImGui::PushFont(hintF);
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text, WithAlpha(OnSurface(), 120));
|
||||||
|
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap);
|
||||||
|
ImGui::TextUnformatted(hint);
|
||||||
|
ImGui::PopTextWrapPos();
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
ImGui::PopFont();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Text Drop Shadow
|
// Text Drop Shadow
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -472,11 +544,16 @@ inline bool TactileButton(const char* label, const ImVec2& size = ImVec2(0, 0),
|
|||||||
ImVec2 bMin = ImGui::GetItemRectMin();
|
ImVec2 bMin = ImGui::GetItemRectMin();
|
||||||
ImVec2 bMax = ImGui::GetItemRectMax();
|
ImVec2 bMax = ImGui::GetItemRectMax();
|
||||||
|
|
||||||
// For icon fonts, manually draw centered icon after getting button rect
|
// For icon fonts, manually draw centered icon after getting button rect. Measure/draw only the
|
||||||
|
// VISIBLE label (up to the "##id" separator): CalcTextSizeA/AddText don't strip "##" the way
|
||||||
|
// ImGui's own text render does, so an id suffix like "##pickContact" would inflate textSz and
|
||||||
|
// shove the glyph left off-center (and try to draw the notdef id chars).
|
||||||
if (isIconFont && size.x > 0 && size.y > 0) {
|
if (isIconFont && size.x > 0 && size.y > 0) {
|
||||||
ImVec2 textSz = useFont->CalcTextSizeA(useFont->LegacySize, FLT_MAX, 0, label);
|
const char* labelEnd = label;
|
||||||
|
while (*labelEnd && !(labelEnd[0] == '#' && labelEnd[1] == '#')) ++labelEnd;
|
||||||
|
ImVec2 textSz = useFont->CalcTextSizeA(useFont->LegacySize, FLT_MAX, 0, label, labelEnd);
|
||||||
ImVec2 textPos(bMin.x + (size.x - textSz.x) * 0.5f, bMin.y + (size.y - textSz.y) * 0.5f);
|
ImVec2 textPos(bMin.x + (size.x - textSz.x) * 0.5f, bMin.y + (size.y - textSz.y) * 0.5f);
|
||||||
dl->AddText(useFont, useFont->LegacySize, textPos, ImGui::GetColorU32(ImGuiCol_Text), label);
|
dl->AddText(useFont, useFont->LegacySize, textPos, ImGui::GetColorU32(ImGuiCol_Text), label, labelEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
float rounding = ImGui::GetStyle().FrameRounding;
|
float rounding = ImGui::GetStyle().FrameRounding;
|
||||||
@@ -848,7 +925,7 @@ inline void DrawStatCard(ImDrawList* dl,
|
|||||||
// Draw a full-height rounded rect with card rounding (left corners)
|
// Draw a full-height rounded rect with card rounding (left corners)
|
||||||
// and clip to stripe width so the shape follows the corner radius.
|
// and clip to stripe width so the shape follows the corner radius.
|
||||||
if ((card.accentCol & IM_COL32_A_MASK) != 0) {
|
if ((card.accentCol & IM_COL32_A_MASK) != 0) {
|
||||||
float stripeW = 4.0f;
|
float stripeW = 4.0f * Layout::dpiScale();
|
||||||
dl->PushClipRect(cMin, ImVec2(cMin.x + stripeW, cMax.y), true);
|
dl->PushClipRect(cMin, ImVec2(cMin.x + stripeW, cMax.y), true);
|
||||||
dl->AddRectFilled(cMin, cMax, card.accentCol, rnd,
|
dl->AddRectFilled(cMin, cMax, card.accentCol, rnd,
|
||||||
ImDrawFlags_RoundCornersLeft);
|
ImDrawFlags_RoundCornersLeft);
|
||||||
@@ -1205,7 +1282,8 @@ inline bool DrawDialogTitleBar(const char* title, bool* p_open, ImU32 accent_col
|
|||||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||||
ImVec2 winPos = ImGui::GetWindowPos();
|
ImVec2 winPos = ImGui::GetWindowPos();
|
||||||
float winWidth = ImGui::GetWindowWidth();
|
float winWidth = ImGui::GetWindowWidth();
|
||||||
float barHeight = 36.0f;
|
const float dp = Layout::dpiScale();
|
||||||
|
float barHeight = 36.0f * dp;
|
||||||
|
|
||||||
// Get accent color from theme if not provided
|
// Get accent color from theme if not provided
|
||||||
if (!accent_col) {
|
if (!accent_col) {
|
||||||
@@ -1229,15 +1307,15 @@ inline bool DrawDialogTitleBar(const char* title, bool* p_open, ImU32 accent_col
|
|||||||
ImFont* titleFont = Type().subtitle1();
|
ImFont* titleFont = Type().subtitle1();
|
||||||
ImGui::PushFont(titleFont);
|
ImGui::PushFont(titleFont);
|
||||||
ImVec2 titleSize = ImGui::CalcTextSize(title);
|
ImVec2 titleSize = ImGui::CalcTextSize(title);
|
||||||
float titleX = barMin.x + 16.0f;
|
float titleX = barMin.x + 16.0f * dp;
|
||||||
float titleY = barMin.y + (barHeight - titleSize.y) * 0.5f;
|
float titleY = barMin.y + (barHeight - titleSize.y) * 0.5f;
|
||||||
DrawTextShadow(dl, ImVec2(titleX, titleY), OnSurface(), title);
|
DrawTextShadow(dl, ImVec2(titleX, titleY), OnSurface(), title);
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
|
|
||||||
// Close button (X) on right side
|
// Close button (X) on right side
|
||||||
if (p_open) {
|
if (p_open) {
|
||||||
float btnSize = 24.0f;
|
float btnSize = 24.0f * dp;
|
||||||
float btnX = barMax.x - btnSize - 12.0f;
|
float btnX = barMax.x - btnSize - 12.0f * dp;
|
||||||
float btnY = barMin.y + (barHeight - btnSize) * 0.5f;
|
float btnY = barMin.y + (barHeight - btnSize) * 0.5f;
|
||||||
ImVec2 btnMin(btnX, btnY);
|
ImVec2 btnMin(btnX, btnY);
|
||||||
ImVec2 btnMax(btnX + btnSize, btnY + btnSize);
|
ImVec2 btnMax(btnX + btnSize, btnY + btnSize);
|
||||||
@@ -1250,7 +1328,7 @@ inline bool DrawDialogTitleBar(const char* title, bool* p_open, ImU32 accent_col
|
|||||||
|
|
||||||
// Button background on hover
|
// Button background on hover
|
||||||
if (hovered) {
|
if (hovered) {
|
||||||
dl->AddRectFilled(btnMin, btnMax, IM_COL32(255, 255, 255, held ? 40 : 25), 4.0f);
|
dl->AddRectFilled(btnMin, btnMax, IM_COL32(255, 255, 255, held ? 40 : 25), 4.0f * dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw X icon
|
// Draw X icon
|
||||||
@@ -1271,7 +1349,7 @@ inline bool DrawDialogTitleBar(const char* title, bool* p_open, ImU32 accent_col
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reserve space for title bar so content starts below it
|
// Reserve space for title bar so content starts below it
|
||||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + barHeight + 8.0f);
|
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + barHeight + 8.0f * dp);
|
||||||
|
|
||||||
return closeClicked;
|
return closeClicked;
|
||||||
}
|
}
|
||||||
@@ -1347,10 +1425,17 @@ inline int SegmentedControl(ImDrawList* dl, ImVec2 origin, float totalW, float h
|
|||||||
ImVec2(cMax.x - 2.0f * dp, cMax.y - 2.0f * dp),
|
ImVec2(cMax.x - 2.0f * dp, cMax.y - 2.0f * dp),
|
||||||
WithAlpha(Primary(), 210), (height - 4.0f * dp) * 0.5f);
|
WithAlpha(Primary(), 210), (height - 4.0f * dp) * 0.5f);
|
||||||
ImVec2 ts = font->CalcTextSizeA(font->LegacySize, FLT_MAX, 0, labels[i]);
|
ImVec2 ts = font->CalcTextSizeA(font->LegacySize, FLT_MAX, 0, labels[i]);
|
||||||
|
// Center when the label fits; otherwise left-align with a small pad (so a long translation clips
|
||||||
|
// on the right, not on BOTH sides). Clip to the cell so no label can bleed into a neighbouring
|
||||||
|
// segment or past the rounded track — English fits, but de/es/fr/pt/ru labels can overrun.
|
||||||
|
const float lpad = 4.0f * dp;
|
||||||
|
const float tx = (ts.x <= cellW - 2.0f * lpad) ? (cellW - ts.x) * 0.5f : lpad;
|
||||||
|
dl->PushClipRect(cMin, cMax, true);
|
||||||
dl->AddText(font, font->LegacySize,
|
dl->AddText(font, font->LegacySize,
|
||||||
ImVec2(cMin.x + (cellW - ts.x) * 0.5f, cMin.y + (height - ts.y) * 0.5f),
|
ImVec2(cMin.x + tx, cMin.y + (height - ts.y) * 0.5f),
|
||||||
active ? IM_COL32(255, 255, 255, 255) : (hov ? OnSurface() : OnSurfaceMedium()),
|
active ? IM_COL32(255, 255, 255, 255) : (hov ? OnSurface() : OnSurfaceMedium()),
|
||||||
labels[i]);
|
labels[i]);
|
||||||
|
dl->PopClipRect();
|
||||||
ImGui::PushID(i);
|
ImGui::PushID(i);
|
||||||
ImGui::SetCursorScreenPos(cMin);
|
ImGui::SetCursorScreenPos(cMin);
|
||||||
if (ImGui::InvisibleButton(idBase, ImVec2(cellW, height))) clicked = i;
|
if (ImGui::InvisibleButton(idBase, ImVec2(cellW, height))) clicked = i;
|
||||||
@@ -1381,6 +1466,7 @@ struct OverlayCardState {
|
|||||||
int stableCount = 0; // consecutive frames the height held steady (within 1px)
|
int stableCount = 0; // consecutive frames the height held steady (within 1px)
|
||||||
int appearFrames = 0; // frames since (re)appearing while still hidden — a safety cap
|
int appearFrames = 0; // frames since (re)appearing while still hidden — a safety cap
|
||||||
bool shown = false; // revealed (centered) at least once this open; don't re-hide after
|
bool shown = false; // revealed (centered) at least once this open; don't re-hide after
|
||||||
|
bool overflow = false; // content once exceeded the viewport → clamp to viewport + scroll (sticky/open)
|
||||||
};
|
};
|
||||||
inline std::unordered_map<std::string, OverlayCardState> g_overlayCardHeights;
|
inline std::unordered_map<std::string, OverlayCardState> g_overlayCardHeights;
|
||||||
inline std::string g_overlayCurrentKey;
|
inline std::string g_overlayCurrentKey;
|
||||||
@@ -1506,6 +1592,7 @@ inline bool BeginOverlayDialog(const OverlayDialogSpec& spec)
|
|||||||
float cardX = vp_pos.x + (vp_size.x - cardWidth) * 0.5f;
|
float cardX = vp_pos.x + (vp_size.x - cardWidth) * 0.5f;
|
||||||
float cardY, cardBottomY;
|
float cardY, cardBottomY;
|
||||||
bool hideForMeasure = false; // true on an auto-height dialog's first (unmeasured) frame
|
bool hideForMeasure = false; // true on an auto-height dialog's first (unmeasured) frame
|
||||||
|
bool autoOverflow = false; // auto-height content taller than the viewport → clamp + scroll
|
||||||
const bool fixedHeight = (spec.cardHeight > 0.0f);
|
const bool fixedHeight = (spec.cardHeight > 0.0f);
|
||||||
if (fixedHeight) {
|
if (fixedHeight) {
|
||||||
float cardH = std::min(spec.cardHeight * dp, vp_size.y - 32.0f);
|
float cardH = std::min(spec.cardHeight * dp, vp_size.y - 32.0f);
|
||||||
@@ -1515,9 +1602,16 @@ inline bool BeginOverlayDialog(const OverlayDialogSpec& spec)
|
|||||||
} else {
|
} else {
|
||||||
g_overlayCurrentKey = childId;
|
g_overlayCurrentKey = childId;
|
||||||
OverlayCardState& cs = g_overlayCardHeights[childId];
|
OverlayCardState& cs = g_overlayCardHeights[childId];
|
||||||
if (scrimAppearing) { cs.shown = false; cs.stableCount = 0; cs.appearFrames = 0; }
|
if (scrimAppearing) { cs.shown = false; cs.stableCount = 0; cs.appearFrames = 0; cs.overflow = false; }
|
||||||
if (!cs.shown) cs.appearFrames++;
|
if (!cs.shown) cs.appearFrames++;
|
||||||
const float measuredH = cs.height;
|
const float measuredH = cs.height;
|
||||||
|
const float maxCardH = vp_size.y - 32.0f;
|
||||||
|
// Once the measured content is taller than the viewport, lock the card to the viewport height and
|
||||||
|
// let its content child scroll (autoOverflow) so the footer/actions stay reachable. Sticky for this
|
||||||
|
// open: clamping makes next frame's measured height the clamped value, so re-deciding from it would
|
||||||
|
// oscillate — decide once and hold until the dialog re-opens.
|
||||||
|
if (measuredH > maxCardH) cs.overflow = true;
|
||||||
|
autoOverflow = cs.overflow;
|
||||||
// Reveal once the measured height has settled (auto-resize converges in ~2 frames) or it's
|
// Reveal once the measured height has settled (auto-resize converges in ~2 frames) or it's
|
||||||
// already been shown this open (don't re-hide on a mid-dialog content change); a frame cap
|
// already been shown this open (don't re-hide on a mid-dialog content change); a frame cap
|
||||||
// guarantees a pathological ever-changing height can't hide the dialog forever.
|
// guarantees a pathological ever-changing height can't hide the dialog forever.
|
||||||
@@ -1525,11 +1619,18 @@ inline bool BeginOverlayDialog(const OverlayDialogSpec& spec)
|
|||||||
(cs.shown || cs.stableCount >= 1 || cs.appearFrames >= 8);
|
(cs.shown || cs.stableCount >= 1 || cs.appearFrames >= 8);
|
||||||
if (ready) {
|
if (ready) {
|
||||||
cs.shown = true;
|
cs.shown = true;
|
||||||
|
if (autoOverflow) {
|
||||||
|
// Taller than the screen: top-anchor at the 16px margin, clamp to the viewport; the
|
||||||
|
// content child (below) becomes the scroll region so the footer/actions stay reachable.
|
||||||
|
cardY = vp_pos.y + 16.0f;
|
||||||
|
cardBottomY = cardY + maxCardH;
|
||||||
|
} else {
|
||||||
// Center the measured content; if it's taller than the window, anchor at the top margin.
|
// Center the measured content; if it's taller than the window, anchor at the top margin.
|
||||||
cardY = (measuredH < vp_size.y - 32.0f)
|
cardY = (measuredH < maxCardH)
|
||||||
? vp_pos.y + (vp_size.y - measuredH) * 0.5f
|
? vp_pos.y + (vp_size.y - measuredH) * 0.5f
|
||||||
: vp_pos.y + 16.0f;
|
: vp_pos.y + 16.0f;
|
||||||
cardBottomY = cardY + measuredH;
|
cardBottomY = cardY + measuredH;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Still settling: lay the content out (so the auto-height child gets measured) but keep
|
// Still settling: lay the content out (so the auto-height child gets measured) but keep
|
||||||
// the card hidden (hideForMeasure below) so it never flashes off-center — it appears,
|
// the card hidden (hideForMeasure below) so it never flashes off-center — it appears,
|
||||||
@@ -1545,7 +1646,10 @@ inline bool BeginOverlayDialog(const OverlayDialogSpec& spec)
|
|||||||
// the measuring frame (its geometry is a placeholder; the whole card is hidden until centered).
|
// the measuring frame (its geometry is a placeholder; the whole card is hidden until centered).
|
||||||
if (!floating && !hideForMeasure) {
|
if (!floating && !hideForMeasure) {
|
||||||
GlassPanelSpec cardGlass;
|
GlassPanelSpec cardGlass;
|
||||||
cardGlass.rounding = 16.0f; cardGlass.fillAlpha = 35; cardGlass.borderAlpha = 50; cardGlass.borderWidth = 1.0f;
|
// Fill/border alpha govern every overlay dialog's card boundary — kept well above the default
|
||||||
|
// glass panel so the card reads as a distinct surface over busy backdrops (tx lists, mining
|
||||||
|
// tiles, chat) while staying translucent rather than opaque.
|
||||||
|
cardGlass.rounding = 16.0f * dp; cardGlass.fillAlpha = 60; cardGlass.borderAlpha = 90; cardGlass.borderWidth = 1.0f;
|
||||||
DrawGlassPanel(dl, cardMin, cardMax, cardGlass);
|
DrawGlassPanel(dl, cardMin, cardMax, cardGlass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1559,17 +1663,24 @@ inline bool BeginOverlayDialog(const OverlayDialogSpec& spec)
|
|||||||
|
|
||||||
// Content child.
|
// Content child.
|
||||||
ImGui::SetCursorScreenPos(ImVec2(cardX, cardY));
|
ImGui::SetCursorScreenPos(ImVec2(cardX, cardY));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, floating ? 20.0f : 16.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, floating ? 20.0f * dp : 16.0f * dp);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, floating ? ImVec2(28, 20) : ImVec2(28, 24));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, floating ? ImVec2(28 * dp, 20 * dp) : ImVec2(28 * dp, 24 * dp));
|
||||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 0)); // transparent (glass/blur behind)
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 0)); // transparent (glass/blur behind)
|
||||||
ImGuiChildFlags cflags = ImGuiChildFlags_AlwaysUseWindowPadding | (fixedHeight ? 0 : ImGuiChildFlags_AutoResizeY);
|
// A card with a known height is a fixed frame (fixed-height dialogs, and auto-height dialogs whose
|
||||||
|
// content overflowed the viewport); otherwise the child auto-resizes to its content.
|
||||||
|
const bool clampedCard = fixedHeight || autoOverflow;
|
||||||
|
ImGuiChildFlags cflags = ImGuiChildFlags_AlwaysUseWindowPadding | (clampedCard ? 0 : ImGuiChildFlags_AutoResizeY);
|
||||||
// NoScrollWithMouse (not just NoScrollbar): a modal is a fixed frame — the wheel must never drift
|
// NoScrollWithMouse (not just NoScrollbar): a modal is a fixed frame — the wheel must never drift
|
||||||
// the WHOLE card. If content marginally overflows a fixed card, the wheel would otherwise scroll
|
// the WHOLE card. If content marginally overflows a fixed card, the wheel would otherwise scroll
|
||||||
// the entire dialog (title + footer and all). Inner scroll regions (lists, notes) still scroll on
|
// the entire dialog (title + footer and all). Inner scroll regions (lists, notes) still scroll on
|
||||||
// their own; auto-height cards resize to content so they never overflow anyway.
|
// their own; auto-height cards resize to content so they normally never overflow — EXCEPT when the
|
||||||
|
// content is taller than the viewport (autoOverflow), where the card itself IS the scroll region.
|
||||||
|
ImGuiWindowFlags childScroll = autoOverflow
|
||||||
|
? ImGuiWindowFlags_None
|
||||||
|
: (ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
|
||||||
bool childVisible = ImGui::BeginChild(childId.c_str(),
|
bool childVisible = ImGui::BeginChild(childId.c_str(),
|
||||||
ImVec2(cardWidth, fixedHeight ? (cardBottomY - cardY) : 0.0f),
|
ImVec2(cardWidth, clampedCard ? (cardBottomY - cardY) : 0.0f),
|
||||||
cflags, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
|
cflags, childScroll);
|
||||||
// Floating (portfolio-style) cards: the padding applies to this content child only, so pop it
|
// Floating (portfolio-style) cards: the padding applies to this content child only, so pop it
|
||||||
// now (nested children mustn't inherit it), and center button labels. Net style-var count stays
|
// now (nested children mustn't inherit it), and center button labels. Net style-var count stays
|
||||||
// at 2 (ChildRounding + ButtonTextAlign) so EndOverlayDialog's PopStyleVar(2) is unchanged.
|
// at 2 (ChildRounding + ButtonTextAlign) so EndOverlayDialog's PopStyleVar(2) is unchanged.
|
||||||
@@ -1692,7 +1803,7 @@ inline void DialogWarningHeader(const char* warningLabel, const ImVec4& col = Wa
|
|||||||
inline void DialogConfirmFooter(const char* cancelId, const char* confirmLabel,
|
inline void DialogConfirmFooter(const char* cancelId, const char* confirmLabel,
|
||||||
bool danger, bool& outCancel, bool& outConfirm)
|
bool danger, bool& outCancel, bool& outConfirm)
|
||||||
{
|
{
|
||||||
float btnH = schema::UI().drawElement("components.overlay-dialog", "confirm-btn-height").sizeOr(40.0f);
|
float btnH = schema::UI().drawElement("components.overlay-dialog", "confirm-btn-height").sizeOr(40.0f) * Layout::dpiScale();
|
||||||
float btnW = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
|
float btnW = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
|
||||||
if (ImGui::Button(cancelId, ImVec2(btnW, btnH))) {
|
if (ImGui::Button(cancelId, ImVec2(btnW, btnH))) {
|
||||||
outCancel = true;
|
outCancel = true;
|
||||||
|
|||||||
195
src/ui/material/settings_controls.h
Normal file
195
src/ui/material/settings_controls.h
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
// DragonX Wallet - ImGui Edition
|
||||||
|
// Copyright 2024-2026 The Hush Developers
|
||||||
|
// Released under the GPLv3
|
||||||
|
//
|
||||||
|
// Settings design-system controls — the polished chat-settings look (accent subsection headers,
|
||||||
|
// labeled rows with right-aligned controls, iOS-style segmented controls) promoted to reusable
|
||||||
|
// components, plus a tiered ActionButton (Primary/Secondary/Tertiary/Destructive) with optional
|
||||||
|
// leading Material icon and a ButtonFlow that wraps rows of buttons instead of shrinking them.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "draw_helpers.h" // colors, type, layout, icons, WithAlpha, ScaleAlpha, DrawButtonGlassOverlay
|
||||||
|
#include "imgui.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace dragonx {
|
||||||
|
namespace ui {
|
||||||
|
namespace material {
|
||||||
|
|
||||||
|
// Accent small-caps subsection header ("KEYS & BACKUP", "APPEARANCE"…) — the chat-settings section() look.
|
||||||
|
inline void SettingsSubheader(const char* text) {
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
|
ImGui::Dummy(ImVec2(0.0f, 8.0f * dp));
|
||||||
|
ImGui::PushFont(Type().caption());
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text, WithAlpha(Primary(), 235));
|
||||||
|
ImGui::TextUnformatted(text);
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
ImGui::PopFont();
|
||||||
|
ImGui::Dummy(ImVec2(0.0f, 2.0f * dp));
|
||||||
|
}
|
||||||
|
|
||||||
|
// A labeled settings row: label left, control right-aligned in a fixed column. Construct once per card
|
||||||
|
// section with the content width (0 = auto), then call .label(text) before drawing each control (leaves
|
||||||
|
// the cursor at the control origin and sets the next item width to the control column).
|
||||||
|
struct SettingsRow {
|
||||||
|
float leftX, rowW, ctrlW, rowGap;
|
||||||
|
explicit SettingsRow(float contentWidth, float controlWidth = 250.0f) {
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
|
leftX = ImGui::GetCursorPosX();
|
||||||
|
rowW = (contentWidth > 0.0f) ? contentWidth : ImGui::GetContentRegionAvail().x;
|
||||||
|
ctrlW = controlWidth * dp;
|
||||||
|
rowGap = 5.0f * dp;
|
||||||
|
}
|
||||||
|
void label(const char* text) {
|
||||||
|
ImGui::Dummy(ImVec2(0.0f, rowGap));
|
||||||
|
ImGui::AlignTextToFramePadding();
|
||||||
|
ImGui::TextUnformatted(text);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPosX(std::max(ImGui::GetCursorPosX(), leftX + std::max(0.0f, rowW - ctrlW)));
|
||||||
|
ImGui::SetNextItemWidth(ctrlW);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// iOS-style segmented control (rounded track + inset pill on the selection). Draws its own labeled row
|
||||||
|
// and returns the (possibly changed) index.
|
||||||
|
inline int SegmentedControl(SettingsRow& row, const char* label, const char* const* items, int count, int value) {
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
|
row.label(label);
|
||||||
|
const ImVec2 origin = ImGui::GetCursorScreenPos();
|
||||||
|
const float h = ImGui::GetFrameHeight();
|
||||||
|
const float seg = row.ctrlW / static_cast<float>(count);
|
||||||
|
const float round = 7.0f * dp;
|
||||||
|
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||||
|
dl->AddRectFilled(origin, ImVec2(origin.x + row.ctrlW, origin.y + h), WithAlpha(OnSurface(), 20), round);
|
||||||
|
int result = value;
|
||||||
|
ImGui::PushID(label);
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
|
ImGui::PushID(i);
|
||||||
|
const ImVec2 mn(origin.x + i * seg, origin.y), mx(origin.x + (i + 1) * seg, origin.y + h);
|
||||||
|
ImGui::SetCursorScreenPos(mn);
|
||||||
|
if (ImGui::InvisibleButton("##s", ImVec2(seg, h))) result = i;
|
||||||
|
const bool hov = ImGui::IsItemHovered();
|
||||||
|
if (hov) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
||||||
|
const bool sel = (value == i);
|
||||||
|
if (sel) {
|
||||||
|
const float in = 2.0f * dp;
|
||||||
|
dl->AddRectFilled(ImVec2(mn.x + in, mn.y + in), ImVec2(mx.x - in, mx.y - in),
|
||||||
|
WithAlpha(Primary(), 210), std::max(1.0f, round - in));
|
||||||
|
} else if (hov) {
|
||||||
|
dl->AddRectFilled(mn, mx, WithAlpha(OnSurface(), 26), round);
|
||||||
|
}
|
||||||
|
const ImVec2 ts = ImGui::CalcTextSize(items[i]);
|
||||||
|
const float lpad = 4.0f * dp;
|
||||||
|
const float tx = (ts.x <= seg - 2.0f * lpad) ? (seg - ts.x) * 0.5f : lpad;
|
||||||
|
ImGui::PushClipRect(mn, mx, true);
|
||||||
|
dl->AddText(ImVec2(mn.x + tx, mn.y + (h - ts.y) * 0.5f),
|
||||||
|
sel ? IM_COL32(255, 255, 255, 236) : OnSurfaceMedium(), items[i]);
|
||||||
|
ImGui::PopClipRect();
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
ImGui::PopID();
|
||||||
|
ImGui::SetCursorScreenPos(origin);
|
||||||
|
ImGui::Dummy(ImVec2(row.ctrlW, h)); // reserve the control's rect for layout flow
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Tiered action buttons ───────────────────────────────────────────────────
|
||||||
|
// Primary = filled accent (the one main action of a group)
|
||||||
|
// Secondary = glass (default — common actions)
|
||||||
|
// Tertiary = ghost / low-emphasis (rarely used)
|
||||||
|
// Destructive = error-tinted outline (delete / reset)
|
||||||
|
enum class ActionTier { Primary, Secondary, Tertiary, Destructive };
|
||||||
|
|
||||||
|
// The width an ActionButton will occupy (for ButtonFlow / manual layout).
|
||||||
|
inline float ActionButtonWidth(const char* label, const char* icon, float minWidth = 0.0f) {
|
||||||
|
ImFont* lf = Type().button();
|
||||||
|
ImFont* icf = Type().iconSmall();
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
|
const float padX = 9.0f * dp, gap = 6.0f * dp; // mockup .btn padding: 9px horizontal
|
||||||
|
const float labelW = lf->CalcTextSizeA(lf->LegacySize, FLT_MAX, 0, label).x;
|
||||||
|
const float iconW = (icon && icon[0] && icf) ? icf->CalcTextSizeA(icf->LegacySize, FLT_MAX, 0, icon).x : 0.0f;
|
||||||
|
const float w = padX * 2.0f + iconW + (iconW > 0.0f ? gap : 0.0f) + labelW;
|
||||||
|
return std::max(w, minWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
// A tiered action button with an optional leading Material icon (ICON_MD_* or nullptr). Auto-sizes to
|
||||||
|
// its content (>= minWidth). Respects BeginDisabled() (dims via the style alpha, not clickable).
|
||||||
|
inline bool ActionButton(const char* id, const char* label, const char* icon, ActionTier tier, float minWidth = 0.0f) {
|
||||||
|
ImFont* lf = Type().button();
|
||||||
|
ImFont* icf = Type().iconSmall();
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
|
const float gap = 6.0f * dp;
|
||||||
|
const float h = ImGui::GetFrameHeight();
|
||||||
|
const bool hasIcon = icon && icon[0] && icf;
|
||||||
|
const float labelW = lf->CalcTextSizeA(lf->LegacySize, FLT_MAX, 0, label).x;
|
||||||
|
const float iconW = hasIcon ? icf->CalcTextSizeA(icf->LegacySize, FLT_MAX, 0, icon).x : 0.0f;
|
||||||
|
const float w = ActionButtonWidth(label, icon, minWidth);
|
||||||
|
|
||||||
|
const ImVec2 pos = ImGui::GetCursorScreenPos();
|
||||||
|
const bool pressed = ImGui::InvisibleButton(id, ImVec2(w, h));
|
||||||
|
const bool hov = ImGui::IsItemHovered(), act = ImGui::IsItemActive();
|
||||||
|
if (hov) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
||||||
|
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||||
|
const ImVec2 pMax(pos.x + w, pos.y + h);
|
||||||
|
const float round = 7.0f * dp; // mockup .btn radius: 7px (softer than the global 4px frame)
|
||||||
|
const float a = ImGui::GetStyle().Alpha; // BeginDisabled() lowers this
|
||||||
|
|
||||||
|
ImU32 bg = 0, border = 0, fg = OnSurface();
|
||||||
|
bool glass = false;
|
||||||
|
switch (tier) {
|
||||||
|
case ActionTier::Primary:
|
||||||
|
// Mockup .btn.acc: a dark accent-tinted chip with accent TEXT — not a bright filled button.
|
||||||
|
bg = WithAlpha(Primary(), hov ? 52 : 38);
|
||||||
|
border = WithAlpha(Primary(), hov ? 150 : 110);
|
||||||
|
fg = Primary();
|
||||||
|
break;
|
||||||
|
case ActionTier::Secondary:
|
||||||
|
bg = WithAlpha(OnSurface(), hov ? 30 : 20);
|
||||||
|
border = WithAlpha(OnSurface(), 48);
|
||||||
|
glass = true;
|
||||||
|
fg = OnSurface();
|
||||||
|
break;
|
||||||
|
case ActionTier::Tertiary:
|
||||||
|
bg = hov ? WithAlpha(OnSurface(), 18) : 0;
|
||||||
|
fg = OnSurfaceMedium();
|
||||||
|
break;
|
||||||
|
case ActionTier::Destructive:
|
||||||
|
bg = hov ? WithAlpha(Error(), 32) : WithAlpha(Error(), 12);
|
||||||
|
border = WithAlpha(Error(), 90);
|
||||||
|
fg = Error();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (bg) dl->AddRectFilled(pos, pMax, ScaleAlpha(bg, a), round);
|
||||||
|
if (border) dl->AddRect(pos, pMax, ScaleAlpha(border, a), round, 0, 1.0f);
|
||||||
|
if (glass) DrawButtonGlassOverlay(dl, pos, pMax, round, act, hov);
|
||||||
|
fg = ScaleAlpha(fg, a);
|
||||||
|
|
||||||
|
const float contentW = iconW + (iconW > 0.0f ? gap : 0.0f) + labelW;
|
||||||
|
float cx = pos.x + (w - contentW) * 0.5f;
|
||||||
|
if (hasIcon) {
|
||||||
|
dl->AddText(icf, icf->LegacySize, ImVec2(cx, pos.y + (h - icf->LegacySize) * 0.5f), fg, icon);
|
||||||
|
cx += iconW + gap;
|
||||||
|
}
|
||||||
|
dl->AddText(lf, lf->LegacySize, ImVec2(cx, pos.y + (h - lf->LegacySize) * 0.5f), fg, label);
|
||||||
|
return pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Places ActionButtons left→right, wrapping to a new row when the next one won't fit (instead of the
|
||||||
|
// old font-scale-to-fit). Call next(width) before each ActionButton.
|
||||||
|
struct ButtonFlow {
|
||||||
|
float availW, gap; float x = 0.0f; bool firstOnRow = true;
|
||||||
|
explicit ButtonFlow(float availWidth, float gapPx = 8.0f) : availW(availWidth) {
|
||||||
|
gap = gapPx * Layout::dpiScale();
|
||||||
|
}
|
||||||
|
void next(float w) {
|
||||||
|
if (firstOnRow) { firstOnRow = false; x = w; return; }
|
||||||
|
if (x + gap + w <= availW) { ImGui::SameLine(0, gap); x += gap + w; }
|
||||||
|
else { x = w; } // natural newline wraps to the next row
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace material
|
||||||
|
} // namespace ui
|
||||||
|
} // namespace dragonx
|
||||||
@@ -15,6 +15,11 @@
|
|||||||
#include "../embedded/IconsMaterialDesign.h" // Icon codepoint defines
|
#include "../embedded/IconsMaterialDesign.h" // Icon codepoint defines
|
||||||
#include "../../util/logger.h"
|
#include "../../util/logger.h"
|
||||||
|
|
||||||
|
#ifdef DRAGONX_HAVE_FREETYPE
|
||||||
|
#include "imgui_internal.h" // ImFontAtlasGetFontLoaderForStbTruetype
|
||||||
|
#include "misc/freetype/imgui_freetype.h" // ImGuiFreeType::GetFontLoader + LoadColor flag
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace dragonx {
|
namespace dragonx {
|
||||||
namespace ui {
|
namespace ui {
|
||||||
namespace material {
|
namespace material {
|
||||||
@@ -126,6 +131,15 @@ bool Typography::load(ImGuiIO& io, float dpiScale)
|
|||||||
DEBUG_LOGF("Typography: Loading Material Design type scale (DPI: %.2f, fontScale: %.2f, userFontScale: %.2f, combined: %.2f)\n",
|
DEBUG_LOGF("Typography: Loading Material Design type scale (DPI: %.2f, fontScale: %.2f, userFontScale: %.2f, combined: %.2f)\n",
|
||||||
dpiScale, Layout::kFontScale(), Layout::userFontScale(), scale);
|
dpiScale, Layout::kFontScale(), Layout::userFontScale(), scale);
|
||||||
|
|
||||||
|
#ifdef DRAGONX_HAVE_FREETYPE
|
||||||
|
// Choose the atlas font loader BEFORE any font is added: FreeType (required to rasterize COLR
|
||||||
|
// color-emoji glyphs) when color emoji is enabled, else the default stb_truetype loader. Toggling
|
||||||
|
// the setting + reload() flips this cleanly.
|
||||||
|
io.Fonts->SetFontLoader(color_emoji_ ? ImGuiFreeType::GetFontLoader()
|
||||||
|
: ImFontAtlasGetFontLoaderForStbTruetype());
|
||||||
|
DEBUG_LOGF("Typography: font loader = %s\n", color_emoji_ ? "FreeType (color emoji)" : "stb_truetype");
|
||||||
|
#endif
|
||||||
|
|
||||||
// For ImGui, we need to load fonts at specific pixel sizes.
|
// For ImGui, we need to load fonts at specific pixel sizes.
|
||||||
// Font sizes come from Layout:: accessors (backed by UISchema JSON)
|
// Font sizes come from Layout:: accessors (backed by UISchema JSON)
|
||||||
|
|
||||||
@@ -325,6 +339,63 @@ ImFont* Typography::loadFont(ImGuiIO& io, int weight, float size, const char* na
|
|||||||
name, g_noto_cjk_subset_size);
|
name, g_noto_cjk_subset_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge monochrome emoji for chat + user text (Q12). Only into the small text fonts — baking
|
||||||
|
// ~1400 emoji at heading sizes would bloat the atlas for glyphs no heading needs. ImGui does no
|
||||||
|
// shaping, so single-codepoint emoji render but ZWJ sequences / flags won't compose. The
|
||||||
|
// >0xFFFF ranges require IMGUI_USE_WCHAR32 (imconfig.h).
|
||||||
|
static const char* const kEmojiFonts[] = {
|
||||||
|
"Body1", "Body2", "Subtitle1", "Subtitle2", "Caption", "Overline", "Button", "ButtonSm"
|
||||||
|
};
|
||||||
|
bool wantEmoji = false;
|
||||||
|
for (const char* n : kEmojiFonts) if (strcmp(name, n) == 0) { wantEmoji = true; break; }
|
||||||
|
|
||||||
|
// Emoji blob: the COLR/CPAL color font (FreeType-rendered) when color emoji is enabled and this
|
||||||
|
// is a FreeType build, else the monochrome subset (default / non-FreeType path).
|
||||||
|
const unsigned char* emojiData = g_noto_emoji_subset_data;
|
||||||
|
unsigned int emojiSize = g_noto_emoji_subset_size;
|
||||||
|
bool colorGlyphs = false;
|
||||||
|
#ifdef DRAGONX_HAVE_FREETYPE
|
||||||
|
if (color_emoji_ && g_twemoji_color_size > 0) {
|
||||||
|
emojiData = g_twemoji_color_data;
|
||||||
|
emojiSize = g_twemoji_color_size;
|
||||||
|
colorGlyphs = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (wantEmoji && emojiSize > 0) {
|
||||||
|
void* emojiCopy = IM_ALLOC(emojiSize);
|
||||||
|
memcpy(emojiCopy, emojiData, emojiSize);
|
||||||
|
|
||||||
|
ImFontConfig emojiCfg;
|
||||||
|
emojiCfg.FontDataOwnedByAtlas = true;
|
||||||
|
emojiCfg.MergeMode = true; // merge into the text font just loaded
|
||||||
|
emojiCfg.OversampleH = 1;
|
||||||
|
emojiCfg.OversampleV = 1;
|
||||||
|
emojiCfg.PixelSnapH = true;
|
||||||
|
emojiCfg.GlyphMinAdvanceX = 0;
|
||||||
|
#ifdef DRAGONX_HAVE_FREETYPE
|
||||||
|
if (colorGlyphs) emojiCfg.FontLoaderFlags |= ImGuiFreeTypeLoaderFlags_LoadColor; // render COLR in color
|
||||||
|
#endif
|
||||||
|
// The base Ubuntu font already owns U+2600–26FF etc.; MergeMode keeps the first-loaded glyph,
|
||||||
|
// so its text-style symbols win and only the codepoints it lacks fall through to emoji.
|
||||||
|
static const ImWchar emojiRanges[] = {
|
||||||
|
0x2600, 0x27BF, // Misc Symbols + Dingbats
|
||||||
|
0x2B00, 0x2BFF, // stars (⭐) + arrows
|
||||||
|
0x1F000, 0x1FAFF, // emoji planes (emoticons, pictographs, transport, supplement, extended)
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
emojiCfg.GlyphRanges = emojiRanges;
|
||||||
|
snprintf(emojiCfg.Name, sizeof(emojiCfg.Name), "%s %.0fpx (merge)",
|
||||||
|
colorGlyphs ? "Twemoji" : "NotoEmoji", size);
|
||||||
|
|
||||||
|
ImFont* emojiMerge = io.Fonts->AddFontFromMemoryTTF(emojiCopy, emojiSize, size, &emojiCfg);
|
||||||
|
if (emojiMerge) {
|
||||||
|
DEBUG_LOGF("Typography: Merged %s emoji (%u bytes) into %s OK\n",
|
||||||
|
colorGlyphs ? "color" : "mono", emojiSize, name);
|
||||||
|
} else {
|
||||||
|
DEBUG_LOGF("Typography: WARNING — emoji merge FAILED for %s (size=%u)\n", name, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
DEBUG_LOGF("Typography: Failed to load %s\n", name);
|
DEBUG_LOGF("Typography: Failed to load %s\n", name);
|
||||||
IM_FREE(fontDataCopy);
|
IM_FREE(fontDataCopy);
|
||||||
|
|||||||
@@ -113,6 +113,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
float getDpiScale() const { return dpiScale_; }
|
float getDpiScale() const { return dpiScale_; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Select color vs monochrome emoji for the next (re)load. Color needs a FreeType-enabled
|
||||||
|
* build (DRAGONX_HAVE_FREETYPE); otherwise this is inert and monochrome is always used.
|
||||||
|
* Set before load()/reload() (App does this from the chat_emoji_color setting).
|
||||||
|
*/
|
||||||
|
void setColorEmoji(bool enabled) { color_emoji_ = enabled; }
|
||||||
|
bool colorEmoji() const { return color_emoji_; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get font for a type style
|
* @brief Get font for a type style
|
||||||
*
|
*
|
||||||
@@ -261,6 +269,7 @@ private:
|
|||||||
|
|
||||||
bool loaded_ = false;
|
bool loaded_ = false;
|
||||||
float dpiScale_ = 1.0f;
|
float dpiScale_ = 1.0f;
|
||||||
|
bool color_emoji_ = false; // when true + FreeType present, merge the COLR color-emoji font
|
||||||
|
|
||||||
// Fonts for each type style
|
// Fonts for each type style
|
||||||
ImFont* fonts_[15] = {};
|
ImFont* fonts_[15] = {};
|
||||||
|
|||||||
111
src/ui/node_status_banner.h
Normal file
111
src/ui/node_status_banner.h
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// Persistent node-connectivity banner shown at the top of the content column when the wallet
|
||||||
|
// cannot reach its node. Distinct from the transient toast notifications: it stays visible for
|
||||||
|
// as long as the fault persists, so an offline wallet is never silently mistaken for a working
|
||||||
|
// one. The decision (whether to show, how severe, which action) is a pure function of a state
|
||||||
|
// snapshot so it can be unit-tested; App::renderNodeStatusBanner() feeds it the live state and
|
||||||
|
// draws the strip. See src/app.cpp.
|
||||||
|
namespace dragonx::ui {
|
||||||
|
|
||||||
|
// Visual weight. Warning (amber) = recoverable / a reconnect is offered; Error (red) = a hard
|
||||||
|
// fault the user must act on (the daemon gave up crashing, or a lite wallet failed to open).
|
||||||
|
enum class NodeBannerSeverity {
|
||||||
|
Warning,
|
||||||
|
Error,
|
||||||
|
};
|
||||||
|
|
||||||
|
// What the banner's action button does. App maps this to the concrete call.
|
||||||
|
enum class NodeBannerAction {
|
||||||
|
None, // no button — nothing the user can usefully do from here
|
||||||
|
Reconnect, // full node: re-run the RPC connect state machine (App::tryConnect)
|
||||||
|
RestartNode, // full node: the embedded daemon crashed & auto-restart gave up (App::restartDaemon)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Why the banner is up. App maps this to a translated headline; `detail` carries the live,
|
||||||
|
// already-human-readable status text (connection_status_ / daemon lastError / lite open error).
|
||||||
|
enum class NodeBannerReason {
|
||||||
|
None,
|
||||||
|
FullNodeOffline, // a reachable node was lost, or never came up; reconnect offered
|
||||||
|
DaemonCrashed, // the embedded daemon crashed repeatedly and auto-restart stopped
|
||||||
|
LiteOpenFailed, // lite build: the wallet failed to open
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NodeBannerState {
|
||||||
|
bool show = false;
|
||||||
|
NodeBannerSeverity severity = NodeBannerSeverity::Warning;
|
||||||
|
NodeBannerReason reason = NodeBannerReason::None;
|
||||||
|
NodeBannerAction action = NodeBannerAction::None;
|
||||||
|
std::string detail; // passthrough status/error text (may be empty)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Snapshot of the connection state the banner reads. Plain values so the decision is testable
|
||||||
|
// without an App instance.
|
||||||
|
struct NodeBannerInputs {
|
||||||
|
bool lite = false; // lite build (no embedded daemon / RPC)
|
||||||
|
bool connected = false; // state_.connected — the master "online" flag
|
||||||
|
bool warming_up = false; // daemon reachable, RPC warmup (code -28)
|
||||||
|
bool daemon_initializing = false; // daemon launching / block index loading
|
||||||
|
bool connection_in_progress = false; // a connect attempt is actively running
|
||||||
|
|
||||||
|
// Full-node embedded-daemon crash signal.
|
||||||
|
bool using_embedded_daemon = false;
|
||||||
|
bool has_daemon_controller = false;
|
||||||
|
bool daemon_running = false;
|
||||||
|
int daemon_crash_count = 0;
|
||||||
|
|
||||||
|
std::string connection_status; // human-readable status line (already translated)
|
||||||
|
std::string daemon_last_error; // DaemonController::lastError() (may be empty)
|
||||||
|
std::string lite_open_error; // lite: last wallet-open failure reason
|
||||||
|
};
|
||||||
|
|
||||||
|
// Auto-restart give-up threshold — mirrors the crash cap in app_network.cpp's connect loop.
|
||||||
|
inline constexpr int kNodeBannerCrashGiveUpCount = 3;
|
||||||
|
|
||||||
|
inline NodeBannerState evaluateNodeStatusBanner(const NodeBannerInputs& in) {
|
||||||
|
NodeBannerState s;
|
||||||
|
|
||||||
|
if (in.lite) {
|
||||||
|
// Lite has no daemon/RPC; "online" == wallet open. Only a genuine open failure is a
|
||||||
|
// fault worth a persistent banner (a not-yet-created wallet is handled by the normal
|
||||||
|
// "No wallet open" prompt, and leaves lite_open_error empty).
|
||||||
|
if (!in.connected && !in.lite_open_error.empty()) {
|
||||||
|
s.show = true;
|
||||||
|
s.severity = NodeBannerSeverity::Error;
|
||||||
|
s.reason = NodeBannerReason::LiteOpenFailed;
|
||||||
|
s.action = NodeBannerAction::None;
|
||||||
|
s.detail = in.lite_open_error;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Full node. Connected, or in an expected startup phase → the loading/warmup overlay owns
|
||||||
|
// the screen, so no banner. An active connect attempt likewise shows progress, not an
|
||||||
|
// error — don't flicker a banner over it.
|
||||||
|
if (in.connected) return s;
|
||||||
|
if (in.warming_up || in.daemon_initializing) return s;
|
||||||
|
if (in.connection_in_progress) return s;
|
||||||
|
|
||||||
|
// Genuinely offline. Distinguish "the embedded daemon crashed and we stopped retrying" (a
|
||||||
|
// hard fault needing a manual restart) from an ordinary lost/failed connection (retryable).
|
||||||
|
if (in.using_embedded_daemon && in.has_daemon_controller && !in.daemon_running &&
|
||||||
|
in.daemon_crash_count >= kNodeBannerCrashGiveUpCount) {
|
||||||
|
s.show = true;
|
||||||
|
s.severity = NodeBannerSeverity::Error;
|
||||||
|
s.reason = NodeBannerReason::DaemonCrashed;
|
||||||
|
s.action = NodeBannerAction::RestartNode;
|
||||||
|
s.detail = !in.daemon_last_error.empty() ? in.daemon_last_error : in.connection_status;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
s.show = true;
|
||||||
|
s.severity = NodeBannerSeverity::Warning;
|
||||||
|
s.reason = NodeBannerReason::FullNodeOffline;
|
||||||
|
s.action = NodeBannerAction::Reconnect;
|
||||||
|
s.detail = in.connection_status;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dragonx::ui
|
||||||
@@ -32,19 +32,22 @@ void Notifications::render()
|
|||||||
return v >= 0 ? v : fb;
|
return v >= 0 ? v : fb;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Status bar geometry
|
// Status bar geometry. These are logical-px schema values; the icon/text drawn into the pill
|
||||||
float sbHeight = S.window("components.status-bar").height;
|
// are DPI-baked, so scale the box by dpiScale to match the (also DPI-scaled) rendered status bar
|
||||||
if (sbHeight <= 0.0f) sbHeight = 30.0f;
|
// and keep the icon/text inside the pill at HiDPI.
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
|
float sbHeight = S.window("components.status-bar").height * dp;
|
||||||
|
if (sbHeight <= 0.0f) sbHeight = 30.0f * dp;
|
||||||
|
|
||||||
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||||
float viewBottom = viewport->WorkPos.y + viewport->WorkSize.y;
|
float viewBottom = viewport->WorkPos.y + viewport->WorkSize.y;
|
||||||
float viewCenterX = viewport->WorkPos.x + viewport->WorkSize.x * 0.5f;
|
float viewCenterX = viewport->WorkPos.x + viewport->WorkSize.x * 0.5f;
|
||||||
|
|
||||||
// Toast pill sizing — fit inside status bar with margin
|
// Toast pill sizing — fit inside status bar with margin
|
||||||
float pillMarginY = nde("pill-margin-y", 3.0f);
|
float pillMarginY = nde("pill-margin-y", 3.0f) * dp;
|
||||||
float pillHeight = sbHeight - pillMarginY * 2.0f;
|
float pillHeight = sbHeight - pillMarginY * 2.0f;
|
||||||
float pillPadX = nde("padding-x", 12.0f);
|
float pillPadX = nde("padding-x", 12.0f) * dp;
|
||||||
float pillRounding = nde("pill-rounding", 12.0f);
|
float pillRounding = nde("pill-rounding", 12.0f) * dp;
|
||||||
|
|
||||||
// Get accent color based on type — resolved from theme palette
|
// Get accent color based on type — resolved from theme palette
|
||||||
ImVec4 accent_color, text_color;
|
ImVec4 accent_color, text_color;
|
||||||
@@ -89,7 +92,7 @@ void Notifications::render()
|
|||||||
ImFont* textFont = material::Type().caption();
|
ImFont* textFont = material::Type().caption();
|
||||||
ImFont* iconFont = material::Type().iconSmall();
|
ImFont* iconFont = material::Type().iconSmall();
|
||||||
float iconW = iconFont ? iconFont->CalcTextSizeA(iconFont->LegacySize, FLT_MAX, 0.0f, icon).x : 0.0f;
|
float iconW = iconFont ? iconFont->CalcTextSizeA(iconFont->LegacySize, FLT_MAX, 0.0f, icon).x : 0.0f;
|
||||||
float iconGap = 4.0f;
|
float iconGap = 4.0f * dp;
|
||||||
float msgW = textFont ? textFont->CalcTextSizeA(textFont->LegacySize, FLT_MAX, 0.0f, notif.message.c_str()).x : 100.0f;
|
float msgW = textFont ? textFont->CalcTextSizeA(textFont->LegacySize, FLT_MAX, 0.0f, notif.message.c_str()).x : 100.0f;
|
||||||
float pillWidth = pillPadX + iconW + iconGap + msgW + pillPadX;
|
float pillWidth = pillPadX + iconW + iconGap + msgW + pillPadX;
|
||||||
// Clamp to reasonable bounds
|
// Clamp to reasonable bounds
|
||||||
@@ -122,7 +125,7 @@ void Notifications::render()
|
|||||||
// Progress bar at bottom of pill (accent-colored), clipped to pill rounded
|
// Progress bar at bottom of pill (accent-colored), clipped to pill rounded
|
||||||
// corners. Draw a full-pill-size rounded rect and clip it to just the
|
// corners. Draw a full-pill-size rounded rect and clip it to just the
|
||||||
// bottom-left progress strip so both bottom corners are respected.
|
// bottom-left progress strip so both bottom corners are respected.
|
||||||
float progH = nde("progress-bar-height", 2.0f);
|
float progH = nde("progress-bar-height", 2.0f) * dp;
|
||||||
float progW = pillWidth * (1.0f - progress);
|
float progW = pillWidth * (1.0f - progress);
|
||||||
if (progW > 0.0f) {
|
if (progW > 0.0f) {
|
||||||
ImVec2 clipMin(pillX, pMax.y - progH);
|
ImVec2 clipMin(pillX, pMax.y - progH);
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <ctime>
|
||||||
#include "../util/logger.h"
|
#include "../util/logger.h"
|
||||||
#include "schema/ui_schema.h"
|
#include "schema/ui_schema.h"
|
||||||
|
|
||||||
@@ -22,6 +24,17 @@ enum class NotificationType {
|
|||||||
Error
|
Error
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// A retained alert for the persistent history panel. Unlike a live Notification (which fades and is
|
||||||
|
// erased within seconds), this keeps a wall-clock epoch so its age can be shown as "3m ago" long
|
||||||
|
// after the toast is gone. See App::renderAlertHistoryPanel.
|
||||||
|
struct AlertRecord {
|
||||||
|
std::string message;
|
||||||
|
NotificationType type;
|
||||||
|
std::int64_t epoch; // std::time(nullptr) at push — wall-clock, for relative-age display
|
||||||
|
std::function<void()> onClick; // optional: makes this bell-panel entry actionable
|
||||||
|
std::string actionHint; // optional: accent link label rendered for the action
|
||||||
|
};
|
||||||
|
|
||||||
struct Notification {
|
struct Notification {
|
||||||
std::string message;
|
std::string message;
|
||||||
NotificationType type;
|
NotificationType type;
|
||||||
@@ -82,9 +95,29 @@ public:
|
|||||||
push(message, NotificationType::Error, duration);
|
push(message, NotificationType::Error, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
void push(const std::string& message, NotificationType type, float duration = 5.0f) {
|
// An actionable alert: a normal toast PLUS a clickable entry in the bell/alert-history panel.
|
||||||
|
// onClick fires when the user clicks the accent `actionHint` link in that panel.
|
||||||
|
void action(const std::string& message, NotificationType type, std::function<void()> onClick,
|
||||||
|
const std::string& actionHint, float duration = -1.0f) {
|
||||||
|
if (duration < 0.0f) duration = schemaDuration("duration-warning", 3.5f);
|
||||||
|
push(message, type, duration, std::move(onClick), actionHint);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push(const std::string& message, NotificationType type, float duration = 5.0f,
|
||||||
|
std::function<void()> onClick = nullptr, const std::string& actionHint = "") {
|
||||||
notifications_.emplace_back(message, type, duration);
|
notifications_.emplace_back(message, type, duration);
|
||||||
|
|
||||||
|
// Retain a copy in the persistent history (the toast above will fade in seconds; this
|
||||||
|
// survives so the user can review what happened). Thread note: every push is on the UI
|
||||||
|
// thread (RPC results run as main-thread MainCb callbacks), so this container needs no lock,
|
||||||
|
// consistent with the rest of this class. Do NOT push from a raw worker thread.
|
||||||
|
history_.push_back(AlertRecord{message, type, static_cast<std::int64_t>(std::time(nullptr)),
|
||||||
|
std::move(onClick), actionHint});
|
||||||
|
++total_pushed_;
|
||||||
|
while (history_.size() > kMaxHistory) {
|
||||||
|
history_.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
// Log errors and warnings (debug-only output)
|
// Log errors and warnings (debug-only output)
|
||||||
if (type == NotificationType::Error) {
|
if (type == NotificationType::Error) {
|
||||||
DEBUG_LOGF("[ERROR] Notification: %s\n", message.c_str());
|
DEBUG_LOGF("[ERROR] Notification: %s\n", message.c_str());
|
||||||
@@ -127,6 +160,15 @@ public:
|
|||||||
max_notifications_ = max;
|
max_notifications_ = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Persistent alert history (for the status-bar bell panel) ──
|
||||||
|
/// Retained alerts, oldest first (capped at kMaxHistory; the toast deque is separate).
|
||||||
|
const std::deque<AlertRecord>& history() const { return history_; }
|
||||||
|
bool hasHistory() const { return !history_.empty(); }
|
||||||
|
void clearHistory() { history_.clear(); }
|
||||||
|
/// Monotonic count of every alert ever pushed this session — survives capping/clearing, so it is
|
||||||
|
/// the correct basis for an "unseen since last opened" count (deque size is not).
|
||||||
|
std::uint64_t totalPushed() const { return total_pushed_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Notifications() = default;
|
Notifications() = default;
|
||||||
~Notifications() = default;
|
~Notifications() = default;
|
||||||
@@ -137,6 +179,10 @@ private:
|
|||||||
size_t max_notifications_ = 5;
|
size_t max_notifications_ = 5;
|
||||||
std::function<void(const std::string&, bool)> console_callback_;
|
std::function<void(const std::string&, bool)> console_callback_;
|
||||||
|
|
||||||
|
std::deque<AlertRecord> history_;
|
||||||
|
std::uint64_t total_pushed_ = 0;
|
||||||
|
static constexpr size_t kMaxHistory = 100;
|
||||||
|
|
||||||
static float schemaDuration(const char* key, float fallback) {
|
static float schemaDuration(const char* key, float fallback) {
|
||||||
float v = schema::UI().drawElement("components.notifications", key).size;
|
float v = schema::UI().drawElement("components.notifications", key).size;
|
||||||
return v > 0.0f ? v : fallback;
|
return v > 0.0f ? v : fallback;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -149,6 +149,7 @@ struct SidebarStatus {
|
|||||||
int unconfirmedTxCount = 0; // badge on History
|
int unconfirmedTxCount = 0; // badge on History
|
||||||
bool miningActive = false; // green dot on Mining
|
bool miningActive = false; // green dot on Mining
|
||||||
int peerCount = 0; // badge on Peers
|
int peerCount = 0; // badge on Peers
|
||||||
|
int chatUnreadCount = 0; // badge on Chat (unread incoming messages)
|
||||||
// Exit
|
// Exit
|
||||||
bool exitClicked = false;
|
bool exitClicked = false;
|
||||||
// Branding logo (optional — loaded at startup)
|
// Branding logo (optional — loaded at startup)
|
||||||
@@ -218,7 +219,7 @@ inline void DrawGlassCutout(ImDrawList* dl, ImVec2 mn, ImVec2 mx,
|
|||||||
float lineW = s_cc.lineW;
|
float lineW = s_cc.lineW;
|
||||||
|
|
||||||
// --- Outer glow pass: wider, softer dark edge on top-left ---
|
// --- Outer glow pass: wider, softer dark edge on top-left ---
|
||||||
float glowExpand = s_cc.glowExpand;
|
float glowExpand = s_cc.glowExpand * Layout::dpiScale();
|
||||||
int glowA = (int)s_cc.glowAlpha;
|
int glowA = (int)s_cc.glowAlpha;
|
||||||
float glowLineW = s_cc.glowLineW;
|
float glowLineW = s_cc.glowLineW;
|
||||||
{
|
{
|
||||||
@@ -288,6 +289,7 @@ inline void DrawGlassBevelButton(ImDrawList* dl, ImVec2 mn, ImVec2 mx,
|
|||||||
// inner pass gives crisp bevel edge. All use AddRect with rounding so
|
// inner pass gives crisp bevel edge. All use AddRect with rounding so
|
||||||
// every layer follows the rounded corners perfectly — no clip rects needed.
|
// every layer follows the rounded corners perfectly — no clip rects needed.
|
||||||
{
|
{
|
||||||
|
const float dp = Layout::dpiScale();
|
||||||
float cx = (mn.x + mx.x) * 0.5f;
|
float cx = (mn.x + mx.x) * 0.5f;
|
||||||
float cy = (mn.y + mx.y) * 0.5f;
|
float cy = (mn.y + mx.y) * 0.5f;
|
||||||
|
|
||||||
@@ -303,7 +305,7 @@ inline void DrawGlassBevelButton(ImDrawList* dl, ImVec2 mn, ImVec2 mx,
|
|||||||
|
|
||||||
struct BevelPass { float expand; float lineW; float fadeStart; float fadeEnd; };
|
struct BevelPass { float expand; float lineW; float fadeStart; float fadeEnd; };
|
||||||
BevelPass passes[] = {
|
BevelPass passes[] = {
|
||||||
{ 0.5f, 0.75f, 0.30f, 0.55f }, // Outer glow (thin)
|
{ 0.5f * dp, 0.75f, 0.30f, 0.55f }, // Outer glow (thin)
|
||||||
{ 0.0f, 0.75f, 0.38f, 0.58f }, // Inner crisp bevel
|
{ 0.0f, 0.75f, 0.38f, 0.58f }, // Inner crisp bevel
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -386,7 +388,7 @@ inline void DrawGlassBevelButton(ImDrawList* dl, ImVec2 mn, ImVec2 mx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (depth > s_ic.threshold) {
|
if (depth > s_ic.threshold) {
|
||||||
float baseInset = s_ic.inset;
|
float baseInset = s_ic.inset * Layout::dpiScale();
|
||||||
int shadowMax = (int)(s_ic.maxAlpha * depth);
|
int shadowMax = (int)(s_ic.maxAlpha * depth);
|
||||||
float fadeRatio = s_ic.fadeRatio;
|
float fadeRatio = s_ic.fadeRatio;
|
||||||
float bW = mx.x - mn.x - baseInset * 2.0f;
|
float bW = mx.x - mn.x - baseInset * 2.0f;
|
||||||
@@ -486,7 +488,7 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
|
|||||||
float fixedH = stripH; // collapse strip
|
float fixedH = stripH; // collapse strip
|
||||||
for (int i = 0; i < (int)NavPage::Count_; ++i)
|
for (int i = 0; i < (int)NavPage::Count_; ++i)
|
||||||
if (IsNavPageVisible(kNavItems[i].page) && kNavItems[i].section_label && showLabels)
|
if (IsNavPageVisible(kNavItems[i].page) && kNavItems[i].section_label && showLabels)
|
||||||
fixedH += olFsz + 2.0f + sectionLabelPadBot; // section label + pad below
|
fixedH += olFsz + 2.0f * dp + sectionLabelPadBot; // section label + pad below
|
||||||
fixedH += bottomPadding + stripH; // exit area
|
fixedH += bottomPadding + stripH; // exit area
|
||||||
|
|
||||||
float baseFlexH = baseNavGap;
|
float baseFlexH = baseNavGap;
|
||||||
@@ -524,7 +526,7 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
|
|||||||
if (showLabels) {
|
if (showLabels) {
|
||||||
curY += sectionGap;
|
curY += sectionGap;
|
||||||
if (nSectionLabels < 4) sectionLabelY[nSectionLabels++] = curY;
|
if (nSectionLabels < 4) sectionLabelY[nSectionLabels++] = curY;
|
||||||
curY += olFsz + 2.0f + sectionLabelPadBot;
|
curY += olFsz + 2.0f * dp + sectionLabelPadBot;
|
||||||
} else {
|
} else {
|
||||||
curY += sectionGap * 0.4f;
|
curY += sectionGap * 0.4f;
|
||||||
if (nSeparators < 4) separatorY[nSeparators++] = curY;
|
if (nSeparators < 4) separatorY[nSeparators++] = curY;
|
||||||
@@ -537,11 +539,6 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
|
|||||||
float exitRelY = curY + bottomPadding;
|
float exitRelY = curY + bottomPadding;
|
||||||
float panelH = exitRelY + stripH;
|
float panelH = exitRelY + stripH;
|
||||||
|
|
||||||
// Vertical centering — offset so panel is centered in the child window
|
|
||||||
float centerOffset = std::max(glassMarginY, (contentHeight - panelH) * 0.5f);
|
|
||||||
if (centerOffset + panelH > contentHeight)
|
|
||||||
centerOffset = std::max(0.0f, contentHeight - panelH);
|
|
||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
// PASS 2: Render using computed positions
|
// PASS 2: Render using computed positions
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
@@ -551,6 +548,13 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
|
|||||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||||
ImVec2 wp = ImGui::GetWindowPos();
|
ImVec2 wp = ImGui::GetWindowPos();
|
||||||
|
|
||||||
|
// Vertical centering — center the panel within the child. app.cpp sizes the child (contentHeight)
|
||||||
|
// to the visible area (child top -> status-bar top) using window-local geometry, so this yields
|
||||||
|
// equal top/bottom gaps at any height on every platform, no viewport dependency.
|
||||||
|
float centerOffset = std::max(glassMarginY, (contentHeight - panelH) * 0.5f);
|
||||||
|
if (centerOffset + panelH > contentHeight)
|
||||||
|
centerOffset = std::max(0.0f, contentHeight - panelH);
|
||||||
|
|
||||||
float panelLeft = wp.x + glassMarginL;
|
float panelLeft = wp.x + glassMarginL;
|
||||||
float panelRight = wp.x + sidebarWidth - glassMarginR;
|
float panelRight = wp.x + sidebarWidth - glassMarginR;
|
||||||
float panelTopY = wp.y + centerOffset;
|
float panelTopY = wp.y + centerOffset;
|
||||||
@@ -650,7 +654,7 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
|
|||||||
fx.drawShimmer(dl, indMin, indMax, btnRnd);
|
fx.drawShimmer(dl, indMin, indMax, btnRnd);
|
||||||
fx.drawGradientBorderShift(dl, indMin, indMax, btnRnd);
|
fx.drawGradientBorderShift(dl, indMin, indMax, btnRnd);
|
||||||
}
|
}
|
||||||
DrawGlassCutout(dl, indMin, indMax, btnRnd, 1.5f);
|
DrawGlassCutout(dl, indMin, indMax, btnRnd, 1.5f * dp);
|
||||||
DrawGlassBevelButton(dl, indMin, indMax, btnRnd, btnDepth, 18);
|
DrawGlassBevelButton(dl, indMin, indMax, btnRnd, btnDepth, 18);
|
||||||
buttonRects.push_back({indMin, indMax, btnRnd});
|
buttonRects.push_back({indMin, indMax, btnRnd});
|
||||||
}
|
}
|
||||||
@@ -675,10 +679,31 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
|
|||||||
ImU32 textCol = selected ? Primary() : (pageNeedsUnlock ? OnSurfaceDisabled() : OnSurfaceMedium());
|
ImU32 textCol = selected ? Primary() : (pageNeedsUnlock ? OnSurfaceDisabled() : OnSurfaceMedium());
|
||||||
|
|
||||||
if (showLabels) {
|
if (showLabels) {
|
||||||
|
// The badge is a fixed top-right corner overlay, so it must NOT move
|
||||||
|
// the icon+label — otherwise the text jumps sideways the moment a live
|
||||||
|
// count toggles the badge on/off. Reserve clearance from whether the
|
||||||
|
// page CAN show a badge (constant per item), never from the current
|
||||||
|
// count, and keep the icon+label centered in the FULL button width so
|
||||||
|
// the text position and size stay identical with or without a badge.
|
||||||
|
bool itemBadgeCapable =
|
||||||
|
item.page == NavPage::History ||
|
||||||
|
item.page == NavPage::Mining ||
|
||||||
|
item.page == NavPage::Chat;
|
||||||
|
float badgeReserve = 0.0f;
|
||||||
|
if (itemBadgeCapable) {
|
||||||
|
bool dotOnlyReserve = (item.page == NavPage::Mining);
|
||||||
|
float badgeRReserve = dotOnlyReserve ? badgeRadiusDot : badgeRadiusNumber;
|
||||||
|
float badgeInsetXReserve = sde("badge-inset-x", 6.0f);
|
||||||
|
badgeReserve = badgeRReserve * 2.0f + badgeInsetXReserve;
|
||||||
|
}
|
||||||
|
|
||||||
ImFont* font = selected ? Type().subtitle2() : Type().body2();
|
ImFont* font = selected ? Type().subtitle2() : Type().body2();
|
||||||
float lblFsz = ScaledFontSize(font);
|
float lblFsz = ScaledFontSize(font);
|
||||||
float btnW = indMax.x - indMin.x;
|
float btnW = indMax.x - indMin.x;
|
||||||
float maxLabelW = btnW - iconS * 2.0f - iconLabelGap - Layout::spacingXs() * 2;
|
// Clearance is symmetric (2x) because the group stays centered in the
|
||||||
|
// full width: reserving on both sides keeps the label's right edge clear
|
||||||
|
// of the right-side corner badge without shifting the center off-axis.
|
||||||
|
float maxLabelW = btnW - iconS * 2.0f - iconLabelGap - Layout::spacingXs() * 2 - badgeReserve * 2.0f;
|
||||||
ImVec2 labelSz = font->CalcTextSizeA(lblFsz, 1000.0f, 0.0f, NavLabel(item));
|
ImVec2 labelSz = font->CalcTextSizeA(lblFsz, 1000.0f, 0.0f, NavLabel(item));
|
||||||
if (labelSz.x > maxLabelW && maxLabelW > 0) {
|
if (labelSz.x > maxLabelW && maxLabelW > 0) {
|
||||||
lblFsz *= maxLabelW / labelSz.x;
|
lblFsz *= maxLabelW / labelSz.x;
|
||||||
@@ -713,14 +738,16 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
|
|||||||
badgeCol = Warning(); badgeTextCol = OnWarning();
|
badgeCol = Warning(); badgeTextCol = OnWarning();
|
||||||
} else if (item.page == NavPage::Mining && status.miningActive) {
|
} else if (item.page == NavPage::Mining && status.miningActive) {
|
||||||
dotOnly = true; badgeCol = Success();
|
dotOnly = true; badgeCol = Success();
|
||||||
} else if (item.page == NavPage::Peers && status.peerCount > 0) {
|
} else if (item.page == NavPage::Chat && status.chatUnreadCount > 0) {
|
||||||
badgeCount = status.peerCount;
|
badgeCount = status.chatUnreadCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (badgeCount > 0 || dotOnly) {
|
if (badgeCount > 0 || dotOnly) {
|
||||||
float badgeR = dotOnly ? badgeRadiusDot : badgeRadiusNumber;
|
float badgeR = dotOnly ? badgeRadiusDot : badgeRadiusNumber;
|
||||||
float bx = indMax.x - badgeR - 6.0f;
|
float badgeInsetX = sde("badge-inset-x", 6.0f);
|
||||||
float by = indMin.y + badgeR + 5.0f;
|
float badgeInsetY = sde("badge-inset-y", 5.0f);
|
||||||
|
float bx = indMax.x - badgeR - badgeInsetX;
|
||||||
|
float by = indMin.y + badgeR + badgeInsetY;
|
||||||
dl->AddCircleFilled(ImVec2(bx, by), badgeR, badgeCol);
|
dl->AddCircleFilled(ImVec2(bx, by), badgeR, badgeCol);
|
||||||
if (!dotOnly && showLabels) {
|
if (!dotOnly && showLabels) {
|
||||||
char buf[16];
|
char buf[16];
|
||||||
|
|||||||
48
src/ui/staleness_badge.h
Normal file
48
src/ui/staleness_badge.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
// Refresh-staleness badge (finding W6-2). The wallet stamps WalletState::last_balance_update only on
|
||||||
|
// a *successful* balance fetch (see services/network_refresh_service.cpp), so a busy daemon that fails
|
||||||
|
// z_gettotalbalance without dropping the whole connection leaves the old balance on screen with a
|
||||||
|
// frozen timestamp — and the node-status banner (which only fires on a full disconnect) stays hidden.
|
||||||
|
// This badge is the surface that reflects that "connected but the number may be out of date" state.
|
||||||
|
//
|
||||||
|
// The decision is a pure function of (last-success timestamp, now, connected) so it is unit-testable;
|
||||||
|
// balance_tab.cpp draws the pill. Both use the same std::time(nullptr) wall-clock the refresh path
|
||||||
|
// stamps with, so age = now - last_update is consistent.
|
||||||
|
namespace dragonx::ui {
|
||||||
|
|
||||||
|
enum class StalenessSeverity {
|
||||||
|
Warning, // amber — noticeably behind
|
||||||
|
Error, // red — very stale, something is likely wrong
|
||||||
|
};
|
||||||
|
|
||||||
|
struct StalenessBadge {
|
||||||
|
bool show = false;
|
||||||
|
StalenessSeverity severity = StalenessSeverity::Warning;
|
||||||
|
std::int64_t seconds_old = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Balance refreshes every ~2s on the Overview profile (and ~10s while syncing), so tens of seconds
|
||||||
|
// with no successful update means refreshes are failing, not merely slow.
|
||||||
|
inline constexpr std::int64_t kStaleAfterSeconds = 45;
|
||||||
|
inline constexpr std::int64_t kVeryStaleAfterSeconds = 180;
|
||||||
|
|
||||||
|
inline StalenessBadge evaluateStalenessBadge(std::int64_t last_update, std::int64_t now, bool connected) {
|
||||||
|
StalenessBadge b;
|
||||||
|
// Offline is the node-status banner's job; don't double up. A zero stamp means "never updated
|
||||||
|
// this session" (fresh start) or "reset on disconnect" — nothing to be stale about yet.
|
||||||
|
if (!connected || last_update <= 0) return b;
|
||||||
|
|
||||||
|
std::int64_t age = now - last_update;
|
||||||
|
if (age < 0) age = 0; // clock skew guard
|
||||||
|
if (age < kStaleAfterSeconds) return b;
|
||||||
|
|
||||||
|
b.show = true;
|
||||||
|
b.seconds_old = age;
|
||||||
|
b.severity = (age >= kVeryStaleAfterSeconds) ? StalenessSeverity::Error : StalenessSeverity::Warning;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dragonx::ui
|
||||||
@@ -125,29 +125,26 @@ void RenderAboutDialog(App* app, bool* p_open)
|
|||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
ImGui::TextWrapped("%s", TR("about_license_text"));
|
ImGui::TextWrapped("%s", TR("about_license_text"));
|
||||||
|
|
||||||
ImGui::Spacing();
|
// Links — 3-button action row, centered via the shared footer helper (draws its own
|
||||||
ImGui::Separator();
|
// Spacing/Separator/Spacing above the row, replacing the hand-rolled divider block).
|
||||||
ImGui::Spacing();
|
const float linksTotalW = linkW * 3.0f + ImGui::GetStyle().ItemSpacing.x * 2.0f;
|
||||||
|
material::BeginOverlayDialogFooter(linksTotalW);
|
||||||
// Links
|
if (material::TactileButton(TR("about_website"), ImVec2(linkW, 0), S.resolveFont(linkBtn.font))) {
|
||||||
if (material::StyledButton(TR("about_website"), ImVec2(linkW, 0), S.resolveFont(linkBtn.font))) {
|
|
||||||
util::Platform::openUrl("https://dragonx.is");
|
util::Platform::openUrl("https://dragonx.is");
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (material::StyledButton(TR("about_github"), ImVec2(linkW, 0), S.resolveFont(linkBtn.font))) {
|
if (material::TactileButton(TR("about_github"), ImVec2(linkW, 0), S.resolveFont(linkBtn.font))) {
|
||||||
util::Platform::openUrl("https://git.dragonx.is/dragonx/ObsidianDragon");
|
util::Platform::openUrl("https://git.dragonx.is/dragonx/ObsidianDragon");
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (material::StyledButton(TR("about_block_explorer"), ImVec2(linkW, 0), S.resolveFont(linkBtn.font))) {
|
if (material::TactileButton(TR("about_block_explorer"), ImVec2(linkW, 0), S.resolveFont(linkBtn.font))) {
|
||||||
util::Platform::openUrl("https://explorer.dragonx.is");
|
util::Platform::openUrl("https://explorer.dragonx.is");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Spacing();
|
// Close button — lone dismiss action, centered via the shared footer helper (no extra
|
||||||
|
// divider above it, so it sits directly under the links row).
|
||||||
// Close button
|
material::BeginOverlayDialogFooter(closeW, false);
|
||||||
float button_width = closeW;
|
if (material::TactileButton(TR("close"), ImVec2(closeW, 0), S.resolveFont(closeBtn.font))) {
|
||||||
ImGui::SetCursorPosX((ImGui::GetWindowWidth() - button_width) * 0.5f);
|
|
||||||
if (material::StyledButton(TR("close"), ImVec2(button_width, 0), S.resolveFont(closeBtn.font))) {
|
|
||||||
*p_open = false;
|
*p_open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user