8000 feat: Add support for the new CLNRest as a funding source by Amperstrand · Pull Request #2778 · lnbits/lnbits · GitHub
[go: up one dir, main page]

Skip to content

feat: Add support for the new CLNRest as a funding source #2778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Jul 8, 2025

Conversation

Amperstrand
Copy link
Contributor
@Amperstrand Amperstrand commented Nov 19, 2024

#2232 never quite worked and was more of a POC.

Still a work in progress, but should just work.

To test it:

CLNREST_URL=https://127.0.0.1:3010
CLNREST_CA=/home/lightningd/.lightning/bitcoin/ca.pem
CLNREST_CERT=/home/lightningd/.lightning/bitcoin/server.pem

You can also use the contents of these files instead of the path to the file:
CLNREST_CA = cat ca.pem | awk '{printf "%s\\n", $0} END {printf "\n"}'
CLNREST_CERT =  cat server.pem | awk '{printf "%s\\n", $0} END {printf "\n"}'

CLNREST_READONLY_RUNE=lightning-cli createrune restrictions='[["method=listfunds", "method=listpays", "method=listinvoices", "method=getinfo", "method=summary", "method=waitanyinvoice"]]' | jq -r .rune
CLNREST_INVOICE_RUNE=lightning-cli createrune restrictions='[["method=invoice"], ["pnameamount_msat<1000001"], ["pnamelabel^LNbits"], ["rate=60"]]' | jq -r .rune

These will give LNbits permission to pay invoices:
#CLNREST_PAY_RUNE=lightning-cli createrune restrictions='[["method=pay"], ["pinvbolt11_amount<1001"],   ["pnamelabel^LNbits"], ["rate=1"]]' | jq -r .rune
#CLNREST_RENEPAY_RUNE=lightning-cli createrune restrictions='[["method=renepay"], ["pinvinvstring_amount<1001"], ["pnamelabel^LNbits"], ["rate=1"]]' | jq -r .rune

This is not really needed, but reduces start up time because it will otherwise ask for all invoices since the beginning of time from your core lightning node:
#CLNREST_LAST_PAY_INDEX='lightning-cli listinvoices | jq -r '.invoices | map(.created_index) | max'

# For core lightning v23.08, you had to provide the nodeid in order to call CLNRest, but this is no longer needed for more recent releases
#CLNREST_NODEID=lightning-cli getinfo | jq -r .id # only required for v23.08

@Schnema1
Copy link

Great work @Amperstrand and thank you for the support.

I did first tests with this pull request. Setup:
Testnode with separate users for each application. Bitcoin Core v28.rc2 and Core Lightning 24.08 (testnet3).

The setup of runes worked fine, although with slightly different commands.

Set up the .env file.
The runes have to be added like this: CLNREST_READONLY_RUNE=Bp4TZmzsTNnQzA.....
Attention: You cannot point to ca.pem and server.pem files within lightning user .lighting/testnet folder. Lnbits user has no right to read the certificates, and you get an error during start of lnbits.
Solution: You need to copy the two certificates into lnbits home and change the path in .env to the correct path. Similar as we had to do with access.macaroon file.

Improvement suggestion:
.env file: Instead of adding the content of a rune in the .env file, we could point to a rune file.

Open:
Testing the restriction of runes.
Code review, as I have no programming skills.

@dni dni changed the title Add support for the new CLNRest as a funding source feat: Add support for the new CLNRest as a funding source Dec 19, 2024
@dni dni self-requested a review July 2, 2025 07:56
@dni dni force-pushed the wallets/newCLNRest branch from 1b72153 to 3428546 Compare July 2, 2025 13:22
Copy link
codecov bot commented Jul 2, 2025

Codecov Report

Attention: Patch coverage is 15.50388% with 218 lines in your changes missing coverage. Please review.

Project coverage is 59.79%. Comparing base (264d1fa) to head (8c4f6b0).

Files with missing lines Patch % Lines
lnbits/wallets/clnrest.py 11.74% 218 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2778      +/-   ##
==========================================
- Coverage   60.56%   59.79%   -0.77%     
==========================================
  Files         111      112       +1     
  Lines       14587    14845     +258     
==========================================
+ Hits         8834     8876      +42     
- Misses       5753     5969     +216     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dni dni force-pushed the wallets/newCLNRest branch 2 times, most recently from ed8ac8f to e09ccbc Compare July 8, 2025 05:01
@dni dni marked this pull request as ready for review July 8, 2025 05:32
@motorina0 motorina0 force-pushed the wallets/newCLNRest branch from 345f67b to c83fb98 Compare July 8, 2025 08:25
@motorina0
Copy link
Collaborator

code review: Amperstrand#1

@motorina0 motorina0 force-pushed the wallets/newCLNRest branch from 8c4f6b0 to 7873231 Compare July 8, 2025 13:30
@dni dni merged commit cba8c02 into lnbits:dev Jul 8, 2025
dni added a commit that referenced this pull request Jul 15, 2025
Co-authored-by: Amperstrand <amperstrand@localhost>
Co-authored-by: dni ⚡ <office@dnilabs.com>
Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0