From 970cc2cda22f5af59576dc3e2850e2635a835f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 22 Dec 2025 09:17:28 +0100 Subject: [PATCH] feat: add boltz client client (#20) * feat: add boltz-client to regtest --- .github/workflows/ci.yml | 4 +-- .gitignore | 6 +++++ README.md | 10 +++---- data/boltz-client/boltz.toml | 49 +++++++++++++++++++++++++++++++++++ data/boltz-nginx/default.conf | 49 +++++++++++++++++++++++++++++++++++ data/boltz/boltz.conf | 2 +- docker-compose.yml | 46 +++++++++++++++++++++++++++++--- docker-scripts.sh | 22 +++++++++++++++- tests => start-regtest | 0 9 files changed, 176 insertions(+), 12 deletions(-) create mode 100644 data/boltz-client/boltz.toml create mode 100644 data/boltz-nginx/default.conf rename tests => start-regtest (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f8be2e..f754cbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,5 +9,5 @@ jobs: run: | git clone https://github.com/lnbits/lnbits.git docker build -t lnbits/lnbits lnbits - chmod +x ./tests - ./tests + chmod +x ./start-regtest + ./start-regtest diff --git a/.gitignore b/.gitignore index c542600..e60bd79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,13 @@ data + !data/boltz data/boltz/* !data/boltz/boltz.conf + +!data/boltz-client +data/boltz-client/* +!data/boltz-client/boltz.toml + !data/electrs data/electrs/* !data/electrs/config.toml diff --git a/README.md b/README.md index 4ffa6df..2b68d3f 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ docker build -t lnbits/lnbits . mkdir docker git clone https://github.com/lnbits/legend-regtest-enviroment.git docker cd docker -chmod +x ./tests -./tests # start the regtest and also run tests +chmod +x ./start-regtest +./start-regtest # start the regtest and also run tests sudo chown -R $USER ./data # Give the data file permissions for user ``` @@ -52,10 +52,10 @@ make dev # testing ```sh -chmod +x ./tests -./tests +chmod +x ./start-regtest +./start-regtest # short answer :) -./tests && echo "PASSED" || echo "FAILED" > /dev/null +./start-regtest && echo "PASSED" || echo "FAILED" > /dev/null ``` usage of the `bitcoin-cli-sim`, `lightning-cli-sim` and `lncli-sim` aliases diff --git a/data/boltz-client/boltz.toml b/data/boltz-client/boltz.toml new file mode 100644 index 0000000..0045820 --- /dev/null +++ b/data/boltz-client/boltz.toml @@ -0,0 +1,49 @@ +standalone = true +network = "regtest" + +# Path the the log file +logfile = "" + +electrumUrl = "electrs:19001" +electrumLiquidUrl = "electrs-liquid:19002" + +[BOLTZ] +# By default the daemon automatically connects to the official Boltz instance for the network LND is on +# This value is used to override that +url = "http://boltz-nginx:9001" + +[DATABASE] +# Path to the SQLite database file +# path = "/home/michael/test.db" + +[RPC] +# Host of +host = "0.0.0.0" + +# Port of the gRPC interface +port = 9002 + +# Whether the REST proxy for the gRPC interface should be disabled +restDisabled = false + +# Host of the REST proxy +restHost = "0.0.0.0" + +# Port of the REST proxy +restPort = 9003 + +# Path to the TLS cert for the gRPC and REST interface +tlsCert = "" + +# Path to the TLS private key for the gRPC and REST interface +tlsKey = "" +noTls = true + +# Whether the macaroon authentication for the gRPC and REST interface should be disabled +noMacaroons = true + +# Path to the admin macaroon for the gRPC and REST interface +adminMacaroonPath = "" + +# Path to the read only macaroon for the gRPC and REST interface +readOnlyMacaroonPath = "" diff --git a/data/boltz-nginx/default.conf b/data/boltz-nginx/default.conf new file mode 100644 index 0000000..116fca2 --- /dev/null +++ b/data/boltz-nginx/default.conf @@ -0,0 +1,49 @@ +upstream boltz { + server boltz:9001; +} + +upstream boltzr { + server boltz:9005; +} + +upstream ws { + server boltz:9004; +} + +server { + listen 9001; + listen [::]:9001; + server_name localhost; + + add_header Access-Control-Allow-Origin "*" always; + add_header Access-Control-Allow-Methods 'GET, PATCH, DELETE, POST, OPTIONS' always; + add_header Access-Control-Allow-Headers "*" always; + + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + if ($request_method = OPTIONS) { + return 204; + } + + location /v2/ws { + proxy_pass http://ws/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + } + + location ~ ^/v2/(lightning|swap/rescue|swap/restore) { + proxy_pass http://boltzr; + } + + location /streamswapstatus { + proxy_pass http://boltzr; + } + + location / { + proxy_pass http://boltz; + } +} diff --git a/data/boltz/boltz.conf b/data/boltz/boltz.conf index 8293862..6a3ef7c 100644 --- a/data/boltz/boltz.conf +++ b/data/boltz/boltz.conf @@ -1,5 +1,5 @@ [api] -host = "boltz" +host = "0.0.0.0" port = 9_001 [grpc] diff --git a/docker-compose.yml b/docker-compose.yml index a8b1864..f328f1d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,7 +31,6 @@ services: image: boltz/boltz:latest ports: - 9000:9000 - - 9001:9001 entrypoint: "sh -c 'sleep 30; /boltz-backend/bin/boltzd'" volumes: - ./data/lnd-2:/data/lnd/ @@ -39,6 +38,42 @@ services: - elements-data:/root/.elements - bitcoin-data:/root/.bitcoin + boltz-client: + hostname: boltz-client + depends_on: + - boltz + restart: always + image: boltz/boltz-client:latest + ports: + - 9002:9002 + - 9003:9003 + expose: + - 9002 + healthcheck: + test: ['CMD', 'boltzcli', '--host', 'boltz-client', 'getinfo'] + interval: 5s + timeout: 3s + retries: 10 + start_period: 0s + volumes: + - elements-data:/root/.elements + - ./data/boltz-client:/root/.boltz + + boltz-backend-nginx: + hostname: boltz-nginx + restart: always + image: nginx:latest + ports: + - 9001:9001 + volumes: + - nginx-data:/etc/nginx/conf.d + healthcheck: + test: ['CMD-SHELL', 'curl http://localhost:9001/version'] + timeout: 1s + retries: 10 + interval: 1s + start_period: 0s + boltz-postgres: hostname: boltz-postgres restart: always @@ -53,8 +88,6 @@ services: - POSTGRES_DB=boltz - POSTGRES_USER=boltz - POSTGRES_PASSWORD=boltz - ports: - - 5432:5432 expose: - 5432 @@ -392,3 +425,10 @@ volumes: lnbits-data: bitcoin-data: elements-data: + nginx-data: + name: nginx-data + driver: local + driver_opts: + type: none + o: bind + device: ./data/boltz-nginx/ diff --git a/docker-scripts.sh b/docker-scripts.sh index c70f0bf..eca62fd 100644 --- a/docker-scripts.sh +++ b/docker-scripts.sh @@ -1,6 +1,10 @@ #!/bin/sh export COMPOSE_PROJECT_NAME=lnbits +boltzcli-sim() { + docker exec -it lnbits-boltz-client-1 boltzcli "$@" +} + bitcoin-cli-sim() { docker exec lnbits-bitcoind-1 bitcoin-cli -regtest "$@" } @@ -47,6 +51,14 @@ wait-for-eclair-channel() { done } +# args(i) +fund_boltz_client() { + # first address of seed: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about + address="el1qq2xvpcvfup5j8zscjq05u2wxxjcyewk7979f3mmz5l7uw5pqmx6xf5xy50hsn6vhkm5euwt72x878eq6zxx2z0z676mna6kdq" + echo "funding: $address on boltz-client" + elements-cli-sim -named sendtoaddress address=$address amount=30 fee_rate=100 > /dev/null +} + # args(i) fund_clightning_node() { @@ -98,7 +110,7 @@ lnbits-regtest-start-log(){ lnbits-regtest-stop(){ docker compose down --volumes # clean up lightning node data - sudo rm -rf ./data/clightning-1 ./data/clightning-2 ./data/clightning-3 ./data/lnd-1 ./data/lnd-2 ./data/lnd-3 ./data/lnd-4 ./data/boltz/boltz.db ./data/eclair/regtest + sudo rm -rf ./data/clightning-1 ./data/clightning-2 ./data/clightning-3 ./data/lnd-1 ./data/lnd-2 ./data/lnd-3 ./data/lnd-4 ./data/boltz/boltz.db ./data/eclair/regtest ./data/boltz-client/liquid-wallet ./data/boltz-client/bitcoin-wallet ./data/boltz-client/wallet ./data/boltz-client/boltz.db # recreate lightning node data folders preventing permission errors mkdir ./data/clightning-1 ./data/clightning-2 ./data/clightning-3 ./data/lnd-1 ./data/lnd-2 ./data/lnd-3 ./data/lnd-4 } @@ -108,6 +120,13 @@ lnbits-regtest-restart(){ lnbits-regtest-start } +boltz-client-init(){ + for i in 0 1 2; do + fund_boltz_client + done + elements-cli-sim -generate 3 > /dev/null +} + lnbits-bitcoin-init(){ echo "init_bitcoin_wallet..." bitcoin-cli-sim createwallet lnbits || bitcoin-cli-sim loadwallet lnbits @@ -133,6 +152,7 @@ lnbits-regtest-init(){ lnbits-elements-init lnbits-lightning-sync lnbits-lightning-init + boltz-client-init lnbits-init } diff --git a/tests b/start-regtest similarity index 100% rename from tests rename to start-regtest