jmwallet.wallet.spend
jmwallet.wallet.spend
Reusable direct-send (non-CoinJoin) transaction building, signing, and broadcasting.
This module contains the core spending logic extracted from the CLI so that both
the CLI and the jmwalletd HTTP daemon can share it without duplication.
Attributes
DEFAULT_MAX_FEE_RATE_SAT_VB: float = 1000.0
module-attribute
DUST_THRESHOLD = 546
module-attribute
Classes
DirectSendResult
dataclass
Result returned by :func:direct_send.
Source code in jmwallet/src/jmwallet/wallet/spend.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
Attributes
change_amount: int
instance-attribute
fee: int
instance-attribute
fee_rate: float
instance-attribute
inputs: list[dict[str, object]] = field(default_factory=list)
class-attribute
instance-attribute
num_inputs: int
instance-attribute
num_outputs: int
instance-attribute
outputs: list[dict[str, object]] = field(default_factory=list)
class-attribute
instance-attribute
send_amount: int
instance-attribute
tx_hex: str
instance-attribute
txid: str
instance-attribute
ExcessiveFeeRateError
Bases: ValueError
Raised when a resolved fee rate exceeds the configured safety cap.
Subclasses :class:ValueError so existing except ValueError handlers
in the CLI and HTTP layers continue to behave correctly (refuse the
transaction with a user-visible error) without needing to know about the
new exception type.
Source code in jmwallet/src/jmwallet/wallet/spend.py
51 52 53 54 55 56 57 58 | |
Functions:
direct_send(*, wallet: WalletService, backend: BlockchainBackend, mixdepth: int, amount_sats: int, destination: str, fee_rate: float | None = None, fee_target_blocks: int = 6, tx_fee_factor: float = 0.0, max_fee_rate_sat_vb: float = DEFAULT_MAX_FEE_RATE_SAT_VB) -> DirectSendResult
async
Build, sign, and broadcast a direct (non-CoinJoin) transaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wallet
|
WalletService
|
An initialised and synced :class: |
required |
backend
|
BlockchainBackend
|
The blockchain backend for fee estimation and broadcasting. |
required |
mixdepth
|
int
|
The mixdepth (account) to spend from. |
required |
amount_sats
|
int
|
Amount in satoshis to send. |
required |
destination
|
str
|
Destination Bitcoin address (bech32 only). |
required |
fee_rate
|
float | None
|
Explicit fee rate in sat/vB. When None, the rate is estimated from the backend using fee_target_blocks. |
None
|
fee_target_blocks
|
int
|
Number of blocks for fee estimation (ignored when fee_rate is set). |
6
|
tx_fee_factor
|
float
|
Privacy randomization factor. The final rate is selected between the
resolved rate and that rate multiplied by |
0.0
|
max_fee_rate_sat_vb
|
float
|
Safety cap on the fee rate (sat/vB). The resolved rate (manual or
from backend estimation) is rejected with
:class: |
DEFAULT_MAX_FEE_RATE_SAT_VB
|
Returns:
| Type | Description |
|---|---|
DirectSendResult
|
|
Source code in jmwallet/src/jmwallet/wallet/spend.py
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 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
enforce_fee_rate_cap(fee_rate: float, max_fee_rate_sat_vb: float, *, source: str) -> None
Reject fee_rate if it exceeds the configured cap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fee_rate
|
float
|
The candidate fee rate in sat/vB. |
required |
max_fee_rate_sat_vb
|
float
|
The safety cap. Must be positive. |
required |
source
|
str
|
Human-readable description of where the rate came from
( |
required |
Raises:
| Type | Description |
|---|---|
ExcessiveFeeRateError
|
If |
Source code in jmwallet/src/jmwallet/wallet/spend.py
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 | |
estimate_fee(utxos: list[UTXOInfo], destination: str, fee_rate: float, *, has_change: bool) -> tuple[int, int]
Estimate the transaction fee and vsize.
P2WSH inputs (expired fidelity bonds being swept) are larger than P2WPKH inputs (their witness carries the timelock script), so size them as such or the resulting fee rate falls below the requested one (and potentially below the relay floor).
Returns (fee, vsize).
Source code in jmwallet/src/jmwallet/wallet/spend.py
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 | |
select_spendable_utxos(utxos: list[UTXOInfo], *, include_frozen: bool = False, include_fidelity_bonds: bool = False, locktime_cutoff: int | None = None) -> list[UTXOInfo]
Filter UTXOs to only those safe for auto-spending.
Frozen UTXOs and all fidelity bonds are excluded by default. Setting
include_fidelity_bonds admits only bonds whose locktime is strictly
below locktime_cutoff. The cutoff should be chain median-time-past for
transaction construction; it defaults to the host time for display-only
callers.
Source code in jmwallet/src/jmwallet/wallet/spend.py
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 | |