Commit graph

67 commits

Author SHA1 Message Date
fusion44
a921686b4a
fix(lightning): clear error for undecodable/wrong-network invoices
Decoding a malformed or wrong-network invoice (e.g. a regtest lnbcrt...
invoice on a mainnet node) made each backend fail with a cryptic,
leaked error: LND with the Go 'strconv.ParseUint: parsing "rt500":
invalid syntax' surfaced as a 500, and CLN with 'Invalid bolt11: ...'.

Add a shared helper raise_for_pay_req_decode_error() in lightning/utils
that recognizes the decode-failure signatures of both backends and
raises one clear 400 pointing at the likely cause (malformed or wrong
network). Wire LND (lnd_grpc), CLN gRPC and CLN JSON-RPC through it so
they behave identically; genuine backend errors still return 500.

Fixes #225

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 18:41:18 +02:00
fusion44
a98e9372b0
refactor(api): Event enum + broadcast_msg over WebSocket
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 18:41:18 +02:00
fusion44
8646d966dc
fix(lnd): return a retryable status while the RPC server starts up
While LND is up but its RPC server is 'in the process of starting up, but
not yet ready to accept calls', every LND method returned a bare 500 -
the caller (e.g. the WebUI polling list-all-tx) got a generic server
error with no useful signal.

_check_if_locked only mapped the 'wallet locked' case; generalize it to
_check_transient_ln_error and also map the startup message to
425 TOO_EARLY (matching how bitcoind warmup is reported), with a clear
'try again shortly' detail. This covers all LND methods that share the
same error-handling path.

Fixes #247

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 10:02:20 +02:00
fusion44
868457ffa5
fix(api): replace deprecated asyncio.get_event_loop()
get_event_loop() is deprecated on Python 3.11+ when there is no running
loop and is slated to change behaviour further.

- SSEManager.setup() ran at import time (app.api.utils) via
  get_event_loop(); this only worked because uvicorn imports the app
  inside its loop and would break when imported without a running loop
  (e.g. a Celery worker). Start the broadcast consumer lazily from
  within a running loop instead.
- everywhere else the pattern was get_event_loop().create_task(x)
  inside a coroutine; replace with asyncio.create_task(x).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 22:34:44 +02:00
fusion44
df62098cd1
refactor(lightning): migrate SendCoinsInput validator to Pydantic v2
Replace the deprecated Pydantic v1 @validator('amount', pre=True,
always=True) with a v2 @model_validator(mode='after'). The model
validator always runs and can see both amount and send_all, preserving
the cross-field rule (and the always=True semantics that reject the
empty/default case). Removes the last Pydantic v1 deprecation warning.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 22:22:05 +02:00
fusion44
d5a568da3e
fix(lightning): include payments in CLN list_all_tx
Two bugs in the CLN JSON-RPC list_all_tx:
- 'if pay is not Payment' compared each item to the Payment class rather
  than its type, so it was always true and every payment was skipped -
  payments never showed up in the transaction list.
- the successful_only filter appended the item inside the match branch
  and then again unconditionally, so it never filtered anything.

Use isinstance for the type check and skip non-matching items when
successful_only is set. Also guard the source lists against None so a
failed sub-query no longer crashes the loop.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 20:45:21 +02:00
fusion44
4355c8eabd
fix(lightning): prevent shell injection in CLN local calls
Two authenticated code paths interpolated user-controlled input into a
shell command:

- decode_pay_request passed the bolt11 string into _make_local_call,
  which ran it via create_subprocess_shell; a crafted /lightning/
  decode-pay-req request could execute arbitrary commands. Switch
  _make_local_call to create_subprocess_exec with a discrete argv list.
- blitz_cln_unlock interpolated the wallet password into a
  cl.hsmtool.sh invocation run through a shell, and logged it in the
  clear. shlex.quote the interpolated values and mark the call
  sensitive=True.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 19:58:41 +02:00
fusion44
e564d18d2b
chore: clean up imports; add better LND error logging 2026-02-03 11:05:19 +01:00
Justin Sharp
6b3acf0239 fix: handle missing fields in CLN invoice data gracefully
Fixes #129, #128, and addresses part of raspiblitz/raspiblitz#3182

BOLT12 offers, keysend payments, and certain CLN invoice types don't
always include all fields that the API expects, causing KeyError
exceptions that crash the web interface.

Changes:
- Modified Invoice.from_cln_json() to use .get() with safe defaults
  for all potentially missing fields (bolt11, amount_msat, payment_hash,
  description, label, status, etc.)
- Added fallback logic for amount_msat to use amount_received_msat
  when the primary field is missing
- Enhanced InvoiceState.from_cln_json() to handle unknown/missing
  statuses gracefully with logging instead of raising exceptions

This allows the web interface to display all CLN invoices including
BOLT12 payments from services like OCEAN mining pool, while preserving
all existing payment data for standard BOLT11 invoices.

Tested on RaspiBlitz v1.12.0 with Core Lightning and OCEAN mining
pool BOLT12 payouts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 10:00:05 +01:00
fusion44
2b98912796 feat: replace call_script func with better func
use exec_bash_command instead

refs #123
2025-05-06 09:16:46 +02:00
fusion44
751687e60b chore: run ruff format and isort 2025-05-06 09:16:46 +02:00
fusion44
8ee5a49892 feat: update get app status error handling code
refs #123
2025-05-06 09:16:46 +02:00
fusion44
25e4be8441 feat: make config loading more flexible
If the environment variable BAPI_ENV_PATH is set, the config system will
try to read configs from the given path instead of .env in pwd

If no file is found .env in pwd will be used as a fallback

Env variables will always override settings in .env files.
2025-03-23 17:43:39 +01:00
fusion44
149bd30b15
chore: update deps and flake file 2024-12-16 15:20:46 +01:00
Christoph Stenglein
cf4ab3963c remove ln_info_lite 2024-10-06 14:18:01 +02:00
fusion44
b08e53b599
fix(lnd): catch when pay requests can't be decoded
refs #247
2024-03-10 21:16:26 +01:00
fusion44
f1b657b9a1
chore: update LND gRPC files 2024-03-10 18:32:24 +01:00
fusion44
62d3f3da9b
fix: code changes for pydantic 2.4 2024-03-10 07:57:38 +01:00
fusion44
b7e9ae29fb
fix: adapt code to recent dependeny upgrades 2024-02-24 15:30:32 +01:00
pre-commit-ci[bot]
9bd14d161a
[pre-commit.ci] pre-commit autoupdate (#240)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 23.12.1 → 24.2.0](https://github.com/psf/black/compare/23.12.1...24.2.0)
- [github.com/astral-sh/ruff-pre-commit: v0.1.14 → v0.2.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.14...v0.2.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-02-18 12:11:15 +01:00
fusion44
adf472ac8b feat: implement Ruff as a linter; fix given errors 2023-06-25 07:17:00 +02:00
fusion44
8d93ce608f
fix: ln-info delivers wrong identity_uri #202 2023-05-20 14:13:24 +02:00
fusion44
9f8631c581
fix: send_coins crash when calling CLN RPC 2023-05-01 20:49:52 +02:00
fusion44
e290de8933
feat: proper error handling resolving peer aliases
Implementations sometimes don't find aliases in the gossip, even if
they are openeing a channel to the pubkey. In this case an empty
string will be returned and the problem logged in debug mode.

refs #199
2023-05-01 20:48:10 +02:00
fusion44
467d23a2c3
feat: improvements and fixes for send-coins
both:
feat: add send_all field to SendCoinsResponse

CLN_gRPC only:
feat: improve error handling
fix: return a status 412 when no funds are  available to send

CLN_gRPC only:
fix: send-coins sending incorrect amount
2023-05-01 13:28:58 +02:00
fusion44
02597754bf
docs: improve docs for send-coins 2023-04-23 18:34:27 +02:00
fusion44
71ad84e704
feat: improve logging and error handling 2023-04-21 22:58:29 +02:00
fusion44
fd4d70fa9a
fix: CLN gRPC logging import 2023-04-12 19:18:35 +02:00
fusion44
494c8c3477
feat: add the RaspiBlitz CLN specialization
RaspiBlitz has build an unlock feature on top of CLN
2023-04-09 18:38:51 +02:00
fusion44
909fac4702
fix: wrong wallet balance calculation (CLN j+gRPC)
Calculations didn't account for reserved utxo's and
where shown as available.
2023-04-09 18:21:20 +02:00
fusion44
57a3718a18
fix: CLN JRPC crash and initialization improvement
- fix: Crash in send-coins incorrectly assigning a value to a variable
- improvement: Robustness of the init code. Better detect a invalid
               RPC file path
2023-04-08 20:30:14 +02:00
fusion44
3826fd93a0
fix: a few smaller bugs
- CLN-JRPC: short_channel_id is not available while a channel is
  confirming => return an empty string
- CLN-GRPC: don't send all=False with the amount flag when opening a
  channel as it'll lead to an erro
- CLN-GRPC: don't utf8-decode the open-channel result
2023-04-07 20:59:44 +02:00
fusion44
eca87a5019
feat: improve logging for lnd and cln grpc 2023-04-03 20:17:48 +02:00
fusion44
06d6779eeb
feat: improve error handling in CLN gRPC 2023-04-03 19:15:55 +02:00
fusion44
b3262c5a38
fix: increase gRPC max receive message size
refs #125
2023-04-03 18:49:48 +02:00
fusion44
bcd1e782c3
fix: parsing errors 2023-04-02 20:27:05 +02:00
fusion44
b8810d2204
feat: bolt11 cache as a function in CLN JSON-RPC 2023-04-02 20:23:27 +02:00
fusion44
b4fe14de33
fix: open channel key error 2023-04-02 20:23:10 +02:00
fusion44
60bb7e519f
feat: check pay status before attempting payment
CLN returns no error when a payment was already completed before.
This commit adds a check to the payment status before attempting to
complete the payment. If the payment was already completed, the API
returns an exception.
2023-04-02 16:50:33 +02:00
fusion44
114b76c3d2
feat: implement close channel in CLN JSON-RPC 2023-04-02 14:48:35 +02:00
fusion44
d40790e5f4
fix: crashes in CLN JSON RPC implementation 2023-04-02 12:58:04 +02:00
fusion44
c73b8e9f15
feat: improve error detection in CLN JSON RPC 2023-04-02 12:57:27 +02:00
fusion44
eda5b3b17e
feat: implement listen forwards for CLN JSON RPC 2023-04-02 12:53:03 +02:00
fusion44
98b5912b23
feat: improve logging and error handling
* SSE client warmup data now logs errors properly
* apps module now logs errors properly
2023-04-02 11:09:43 +02:00
fusion44
572804033b
fix: increase buffer size for the socket reader 2023-03-30 19:41:32 +02:00
fusion44
507a32e372
feat: implement listen invoices in CLN JSON-RPC 2023-03-29 20:38:35 +02:00
fusion44
94179cc5da
feat: add CLN JSON-RPC implementation 2023-03-26 20:53:50 +02:00
fusion44
bb0dcd69d2
feat: update CLN_GRPC where gRPC are available
refs #99
2023-03-13 21:51:38 +01:00
fusion44
c03cd6c5d1
feat: further improvements to logging 2023-03-13 18:22:34 +01:00
fusion44
39e7281ccc
fix: p2sh-segwit address deprecation for CLN
Core Lightning deprecated p2sh-segwit addresses which caused a crash
when a newer CLN was used than the gRPC files allowed.

932ca9e91f
2023-03-12 08:38:48 +01:00