jmwalletd.state
jmwalletd.state
Daemon state management.
The DaemonState class is the single source of truth for the running
daemon. It holds the current wallet service, maker/taker state, auth
authority, config overrides, and WebSocket notification hub.
This is intentionally a plain class (not a Pydantic model) because it holds runtime objects like WalletService that are not serialisable.
Classes
CoinjoinState
Bases: IntEnum
Matches reference implementation's coinjoin state constants.
TUMBLER_RUNNING is a jm-ng extension used while a :mod:tumbler
plan is executing; it is distinct from TAKER_RUNNING so that direct
single-shot taker runs and tumbler runs can be mutually excluded from
one another without conflating the two.
Source code in jmwalletd/src/jmwalletd/state.py
25 26 27 28 29 30 31 32 33 34 35 36 37 | |
Attributes
MAKER_RUNNING = 1
class-attribute
instance-attribute
NOT_RUNNING = 2
class-attribute
instance-attribute
TAKER_RUNNING = 0
class-attribute
instance-attribute
TUMBLER_RUNNING = 3
class-attribute
instance-attribute
DaemonState
Mutable singleton holding all daemon runtime state.
This is created once at app startup and injected into route handlers via FastAPI dependency injection.
Source code in jmwalletd/src/jmwalletd/state.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
Attributes
coinjoin_state = CoinjoinState.NOT_RUNNING
instance-attribute
config_overrides: dict[str, dict[str, str]] = {}
instance-attribute
data_dir = data_dir or get_default_data_dir()
instance-attribute
maker_running: bool = False
instance-attribute
nickname: str | None = None
instance-attribute
offer_list: list[dict[str, str | int | float]] | None = None
instance-attribute
rescan_progress: float = 0.0
instance-attribute
rescanning: bool = False
instance-attribute
taker_running: bool = False
instance-attribute
token_authority = JMTokenAuthority()
instance-attribute
tumble_plan_wallet: str | None = None
instance-attribute
tumble_runner: Any = None
instance-attribute
tumble_task: asyncio.Task[Any] | None = None
instance-attribute
wallet_loaded: bool
property
Return True if a wallet is currently unlocked.
wallet_mnemonic: str = ''
instance-attribute
wallet_name: str = ''
instance-attribute
wallet_password: str = ''
instance-attribute
wallet_service: Any = None
instance-attribute
wallets_dir: Path
property
Return the directory where wallet files are stored.
Methods:
__init__(data_dir: Path | None = None) -> None
Source code in jmwalletd/src/jmwalletd/state.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
activate_coinjoin_state(state: CoinjoinState) -> None
Update the coinjoin state and notify WebSocket clients.
Source code in jmwalletd/src/jmwalletd/state.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
broadcast_ws(message: dict[str, Any]) -> None
Send a JSON message to all authenticated WebSocket clients.
Source code in jmwalletd/src/jmwalletd/state.py
263 264 265 266 267 268 269 270 271 272 273 274 | |
list_wallets() -> list[str]
List all .jmdat wallet files in the wallets directory.
Source code in jmwalletd/src/jmwalletd/state.py
153 154 155 156 | |
live_rescan_status() -> tuple[bool, float | None]
async
Return (rescanning, progress) with Bitcoin Core as source of truth.
The in-memory rescanning flag only tracks work started by this
daemon and can go stale (e.g. the HTTP call driving the rescan fails
while Core keeps scanning server-side, or the scan was triggered by
wallet creation/recovery or an external client). When the backend
exposes get_rescan_status (descriptor wallets), query Core's
getwalletinfo.scanning directly so both the flag and the progress
fraction reflect reality. Falls back to the in-memory flags for other
backends or on RPC errors.
Source code in jmwalletd/src/jmwalletd/state.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
lock_wallet() -> bool
async
Lock the current wallet, stopping any running maker/taker first.
Returns whether the wallet was already locked.
Source code in jmwalletd/src/jmwalletd/state.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
mark_tx_broadcast(txid: str) -> None
Record that a first-seen WebSocket notification was emitted for txid.
Lets the direct-send path and the background monitor cooperate so a transaction is announced at most once when it first appears.
Source code in jmwalletd/src/jmwalletd/state.py
276 277 278 279 280 281 282 283 | |
reconcile_stale_tumbler_plans() -> list[str]
Mark any on-disk tumbler plan left in a non-terminal state as FAILED.
A RUNNING or PENDING plan on disk at startup means the daemon
exited mid-run (crash, restart, lost power). The backend state (taker
session, directory connection, wallet sync cursor) is gone, so silently
resuming would risk double-spending. Instead, mark the plan FAILED with
a diagnostic so the UI can surface it; the user can then delete the
plan and build a new one.
Returns the list of wallet names whose plans were touched, for logging / metrics.
Source code in jmwalletd/src/jmwalletd/state.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
register_ws_client() -> asyncio.Queue[str]
Register a new WebSocket client and return its message queue.
Source code in jmwalletd/src/jmwalletd/state.py
358 359 360 361 362 363 | |
start_tx_monitor(*, baseline_existing: bool = True) -> None
Start the background transaction monitor for the loaded wallet.
Idempotent (a running monitor is left in place). Does nothing when no wallet is loaded or the backend cannot enumerate transactions (e.g. a light client without that capability), in which case WebSocket tx notifications are limited to the inline direct-send broadcast.
Source code in jmwalletd/src/jmwalletd/state.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
unregister_ws_client(q: asyncio.Queue[str]) -> None
Unregister a WebSocket client.
Source code in jmwalletd/src/jmwalletd/state.py
365 366 367 368 | |
wait_tx_monitor_ready(timeout: float = 30.0) -> bool
async
Wait briefly for the monitor's silent history baseline.
Lifecycle endpoints call this before returning so activity initiated by
the client cannot land in the baseline window. A backend outage is
bounded by timeout and reported to the caller as not ready.
Source code in jmwalletd/src/jmwalletd/state.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |