Where can I see payment details?
When you receive a payment in Lnbits, the transaction log will display only a resumed type of the transaction. Like this:
From df68400a2568fee7b9ece695c2eedea92d2d434d Mon Sep 17 00:00:00 2001
From: ben
Date: Wed, 18 Jan 2023 17:10:22 +0000
Subject: [PATCH 25/55] Added shipping zone
---
lnbits/extensions/market/README.md | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/lnbits/extensions/market/README.md b/lnbits/extensions/market/README.md
index 0dadf7a05..26b3d2299 100644
--- a/lnbits/extensions/market/README.md
+++ b/lnbits/extensions/market/README.md
@@ -99,6 +99,23 @@ ALL fields are optional apart from the `timestamp`. Data from newer events shoul
}
]
}
+ ],
+ "shipping_zones": [
+ {
+ "id": ,
+ "zone": ,
+ "price": ,
+ },
+ {
+ "id": ,
+ "zone": ,
+ "price": ,
+ },
+ {
+ "id": ,
+ "zone": ,
+ "price": ,
+ }
]
}
From 266471a5e35f6fbf53fe7edd51188e1e6ef20693 Mon Sep 17 00:00:00 2001
From: ben
Date: Wed, 18 Jan 2023 17:16:49 +0000
Subject: [PATCH 26/55] Added shipping
---
lnbits/extensions/market/README.md | 39 +++++++++++++++---------------
1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/lnbits/extensions/market/README.md b/lnbits/extensions/market/README.md
index 26b3d2299..0a21d36fc 100644
--- a/lnbits/extensions/market/README.md
+++ b/lnbits/extensions/market/README.md
@@ -51,14 +51,32 @@ ALL fields are optional apart from the `timestamp`. Data from newer events shoul
"name": ,
"description": ,
"timestamp": ,
+ "currency": ,
"action": ,
+ "shipping": [
+ {
+ "id": ,
+ "zones": ,
+ "price": ,
+ },
+ {
+ "id": ,
+ "zones": ,
+ "price": ,
+ },
+ {
+ "id": ,
+ "zones": ,
+ "price": ,
+ }
+ ],
"stalls": [
{
"id": ,
"name": ,
"description": ,
"categories": ,
- "currency": ,
+ "shipping": ,
"action": ,
"products": [
{
@@ -86,7 +104,7 @@ ALL fields are optional apart from the `timestamp`. Data from newer events shoul
"name": ,
"description": ,
"categories": ,
- "currency": ,
+ "shipping": ,
"action": ,
"products": [
{
@@ -99,23 +117,6 @@ ALL fields are optional apart from the `timestamp`. Data from newer events shoul
}
]
}
- ],
- "shipping_zones": [
- {
- "id": ,
- "zone": ,
- "price": ,
- },
- {
- "id": ,
- "zone": ,
- "price": ,
- },
- {
- "id": ,
- "zone": ,
- "price": ,
- }
]
}
From 71fc1b7146e10ffb98f7c9c6ea8e0aa58cba540f Mon Sep 17 00:00:00 2001
From: ben
Date: Wed, 18 Jan 2023 17:51:15 +0000
Subject: [PATCH 27/55] Added images
---
lnbits/extensions/market/README.md | 53 +++++++++++++++++++++++++++---
1 file changed, 48 insertions(+), 5 deletions(-)
diff --git a/lnbits/extensions/market/README.md b/lnbits/extensions/market/README.md
index 0a21d36fc..79675fd1a 100644
--- a/lnbits/extensions/market/README.md
+++ b/lnbits/extensions/market/README.md
@@ -35,9 +35,27 @@ The `merchant` admin software can be purely clientside, but for `convenience` an
NIP-01 https://github.com/nostr-protocol/nips/blob/master/01.md uses the basic NOSTR event type.
+```
+{
+ "id": <32-bytes sha256 of the the serialized event data>
+ "pubkey": <32-bytes hex-encoded public key of the event creator>,
+ "created_at": ,
+ "kind": ,
+ "tags": [
+ ["e", <32-bytes hex of the id of another event>, ],
+ ["p", <32-bytes hex of the key>, ],
+ ... // other kinds of tags may be included later
+ ],
+ "content": ,
+ "sig": <64-bytes signature of the sha256 hash of the serialized event data, which is the same as the "id" field>
+}
+```
+
The `merchant` event that publishes and updates product lists
-ALL fields are optional apart from the `timestamp`. Data from newer events should replace data from older events.
+The below json goes in `content` of NIP-01.
+
+Data from newer events should replace data from older events.
`action` types (used to indicate changes):
* `update` element has changed
@@ -50,7 +68,6 @@ ALL fields are optional apart from the `timestamp`. Data from newer events shoul
{
"name": ,
"description": ,
- "timestamp": ,
"currency": ,
"action": ,
"shipping": [
@@ -86,6 +103,12 @@ ALL fields are optional apart from the `timestamp`. Data from newer events shoul
"categories": ,
"amount": ,
"price": ,
+ "images": [
+ {
+ "name": ,
+ "link":
+ }
+ ],
"action": ,
},
{
@@ -95,6 +118,16 @@ ALL fields are optional apart from the `timestamp`. Data from newer events shoul
"categories": ,
"amount": ,
"price": ,
+ "images": [
+ {
+ "name": ,
+ "link":
+ },
+ {
+ "name": ,
+ "link":
+ }
+ ],
"action": ,
},
]
@@ -113,6 +146,12 @@ ALL fields are optional apart from the `timestamp`. Data from newer events shoul
"categories": ,
"amount": ,
"price": ,
+ "images": [
+ {
+ "name": ,
+ "link":
+ }
+ ],
"action": ,
}
]
@@ -126,9 +165,10 @@ ALL fields are optional apart from the `timestamp`. Data from newer events shoul
NIP-04 https://github.com/nostr-protocol/nips/blob/master/04.md, all checkout events are encrypted
+The below json goes in `content` of NIP-04.
+
### Step 1: `customer` order (event)
-ALL fields are optional apart from `timestamp`.
```
{
@@ -137,7 +177,6 @@ ALL fields are optional apart from `timestamp`.
"description": ,
"address": ,
"message": ,
- "timestamp": ,
"contact": [
"nostr": ,
"phone": ,
@@ -170,6 +209,8 @@ Merchant should verify the sum of product ids + timestamp.
Sent back from the merchant for payment. Any payment option is valid that the merchant can check.
+The below json goes in `content` of NIP-04.
+
`payment_options`/`type` include:
* `url` URL to a payment page, stripe, paypal, btcpayserver, etc
* `btc` onchain bitcoin address
@@ -180,7 +221,6 @@ Sent back from the merchant for payment. Any payment option is valid that the me
{
"id": ,
"message": ,
- "timestamp": ,
"payment_options": [
{
"type": ,
@@ -201,6 +241,9 @@ Sent back from the merchant for payment. Any payment option is valid that the me
### Step 3: `merchant` verify payment/shipped (event)
Once payment has been received and processed.
+
+The below json goes in `content` of NIP-04.
+
```
{
"id": ,
From bfc99937f602a773c7a0ebaa2c6a01f50aa60746 Mon Sep 17 00:00:00 2001
From: Arc <33088785+arcbtc@users.noreply.github.com>
Date: Wed, 18 Jan 2023 18:03:29 +0000
Subject: [PATCH 28/55] Update README.md
---
lnbits/extensions/market/README.md | 16 ----------------
1 file changed, 16 deletions(-)
diff --git a/lnbits/extensions/market/README.md b/lnbits/extensions/market/README.md
index 79675fd1a..b10e17baa 100644
--- a/lnbits/extensions/market/README.md
+++ b/lnbits/extensions/market/README.md
@@ -35,22 +35,6 @@ The `merchant` admin software can be purely clientside, but for `convenience` an
NIP-01 https://github.com/nostr-protocol/nips/blob/master/01.md uses the basic NOSTR event type.
-```
-{
- "id": <32-bytes sha256 of the the serialized event data>
- "pubkey": <32-bytes hex-encoded public key of the event creator>,
- "created_at": ,
- "kind": ,
- "tags": [
- ["e", <32-bytes hex of the id of another event>, ],
- ["p", <32-bytes hex of the key>, ],
- ... // other kinds of tags may be included later
- ],
- "content": ,
- "sig": <64-bytes signature of the sha256 hash of the serialized event data, which is the same as the "id" field>
-}
-```
-
The `merchant` event that publishes and updates product lists
The below json goes in `content` of NIP-01.
From 99d963c726ee288a88e33b33cc551574e5a3edea Mon Sep 17 00:00:00 2001
From: ben
Date: Wed, 18 Jan 2023 18:50:07 +0000
Subject: [PATCH 29/55] Added models and simple example
---
lnbits/extensions/market/README.md | 42 ++++-
lnbits/extensions/market/models.json | 227 +++++++++++++++++++++++++++
2 files changed, 267 insertions(+), 2 deletions(-)
create mode 100644 lnbits/extensions/market/models.json
diff --git a/lnbits/extensions/market/README.md b/lnbits/extensions/market/README.md
index b10e17baa..5b1c89eee 100644
--- a/lnbits/extensions/market/README.md
+++ b/lnbits/extensions/market/README.md
@@ -16,8 +16,8 @@ A `merchant` and `customer` both have a NOSTR key-pair that are used to sign not
* `merchant` - seller of products with NOSTR key-pair
* `customer` - buyer of products with NOSTR key-pair
* `product` - item for sale by the `merchant`
-* `stall` - list of products controlled by `merchant`
-* `marketplace` - clientside software for searching `stalls` an buying `products`
+* `stall` - list of products controlled by `merchant` (a `merchant` can have multiple stalls)
+* `marketplace` - clientside software for searching `stalls` and purchasing `products`
## Diagon Alley Clients
@@ -89,6 +89,7 @@ Data from newer events should replace data from older events.
"price": ,
"images": [
{
+ "id": ,
"name": ,
"link":
}
@@ -104,10 +105,12 @@ Data from newer events should replace data from older events.
"price": ,
"images": [
{
+ "id": ,
"name": ,
"link":
},
{
+ "id": ,
"name": ,
"link":
}
@@ -132,6 +135,7 @@ Data from newer events should replace data from older events.
"price": ,
"images": [
{
+ "id": ,
"name": ,
"link":
}
@@ -145,6 +149,33 @@ Data from newer events should replace data from older events.
```
+As all elements are optional, an `action` `update` to a `product` `image`, may look as simple as:
+
+```
+{
+ "stalls": [
+ {
+ "id": ,
+ "products": [
+ {
+ "id": ,
+ "images": [
+ {
+ "id": ,
+ "name": ,
+ "link":
+ }
+ ],
+ "action": ,
+ },
+ ]
+ }
+ ]
+}
+
+```
+
+
## Checkout events
NIP-04 https://github.com/nostr-protocol/nips/blob/master/04.md, all checkout events are encrypted
@@ -241,3 +272,10 @@ The below json goes in `content` of NIP-04.
## Customer support events
Customer support is handle over whatever communication method was specified. If communicationg via nostr, NIP-04 is used https://github.com/nostr-protocol/nips/blob/master/04.md.
+
+## Additional
+
+Standard data models can be found here here
+
+
+
diff --git a/lnbits/extensions/market/models.json b/lnbits/extensions/market/models.json
new file mode 100644
index 000000000..05bb4b11f
--- /dev/null
+++ b/lnbits/extensions/market/models.json
@@ -0,0 +1,227 @@
+{
+ "shipping_zones": [
+ "Free (digital)",
+ "Worldwide",
+ "Europe",
+ "Australia",
+ "Austria",
+ "Belgium",
+ "Brazil",
+ "Canada",
+ "Denmark",
+ "Finland",
+ "France",
+ "Germany",
+ "Greece",
+ "Hong Kong",
+ "Hungary",
+ "Ireland",
+ "Indonesia",
+ "Israel",
+ "Italy",
+ "Japan",
+ "Kazakhstan",
+ "Korea",
+ "Luxembourg",
+ "Malaysia",
+ "Mexico",
+ "Netherlands",
+ "New Zealand",
+ "Norway",
+ "Poland",
+ "Portugal",
+ "Russia",
+ "Saudi Arabia",
+ "Singapore",
+ "Spain",
+ "Sweden",
+ "Switzerland",
+ "Thailand",
+ "Turkey",
+ "Ukraine",
+ "United Kingdom**",
+ "United States***",
+ "Vietnam",
+ "China"
+ ],
+ "categories": [
+ "Fashion (clothing and accessories)",
+ "Health (and beauty)",
+ "Toys (and baby equipment)",
+ "Media (Books and CDs)",
+ "Groceries (Food and Drink)",
+ "Technology (Phones and Computers)",
+ "Home (furniture and accessories)",
+ "Gifts (flowers, cards, etc)",
+ "Adult",
+ "Other"
+ ],
+ "currency": {
+ "BTC": "Bitcoin",
+ "SAT": "Bitcoin satoshis",
+ "AED": "United Arab Emirates Dirham",
+ "AFN": "Afghan Afghani",
+ "ALL": "Albanian Lek",
+ "AMD": "Armenian Dram",
+ "ANG": "Netherlands Antillean Gulden",
+ "AOA": "Angolan Kwanza",
+ "ARS": "Argentine Peso",
+ "AUD": "Australian Dollar",
+ "AWG": "Aruban Florin",
+ "AZN": "Azerbaijani Manat",
+ "BAM": "Bosnia and Herzegovina Convertible Mark",
+ "BBD": "Barbadian Dollar",
+ "BDT": "Bangladeshi Taka",
+ "BGN": "Bulgarian Lev",
+ "BHD": "Bahraini Dinar",
+ "BIF": "Burundian Franc",
+ "BMD": "Bermudian Dollar",
+ "BND": "Brunei Dollar",
+ "BOB": "Bolivian Boliviano",
+ "BRL": "Brazilian Real",
+ "BSD": "Bahamian Dollar",
+ "BTN": "Bhutanese Ngultrum",
+ "BWP": "Botswana Pula",
+ "BYN": "Belarusian Ruble",
+ "BYR": "Belarusian Ruble",
+ "BZD": "Belize Dollar",
+ "CAD": "Canadian Dollar",
+ "CDF": "Congolese Franc",
+ "CHF": "Swiss Franc",
+ "CLF": "Unidad de Fomento",
+ "CLP": "Chilean Peso",
+ "CNH": "Chinese Renminbi Yuan Offshore",
+ "CNY": "Chinese Renminbi Yuan",
+ "COP": "Colombian Peso",
+ "CRC": "Costa Rican ColĆ³n",
+ "CUC": "Cuban Convertible Peso",
+ "CVE": "Cape Verdean Escudo",
+ "CZK": "Czech Koruna",
+ "DJF": "Djiboutian Franc",
+ "DKK": "Danish Krone",
+ "DOP": "Dominican Peso",
+ "DZD": "Algerian Dinar",
+ "EGP": "Egyptian Pound",
+ "ERN": "Eritrean Nakfa",
+ "ETB": "Ethiopian Birr",
+ "EUR": "Euro",
+ "FJD": "Fijian Dollar",
+ "FKP": "Falkland Pound",
+ "GBP": "British Pound",
+ "GEL": "Georgian Lari",
+ "GGP": "Guernsey Pound",
+ "GHS": "Ghanaian Cedi",
+ "GIP": "Gibraltar Pound",
+ "GMD": "Gambian Dalasi",
+ "GNF": "Guinean Franc",
+ "GTQ": "Guatemalan Quetzal",
+ "GYD": "Guyanese Dollar",
+ "HKD": "Hong Kong Dollar",
+ "HNL": "Honduran Lempira",
+ "HRK": "Croatian Kuna",
+ "HTG": "Haitian Gourde",
+ "HUF": "Hungarian Forint",
+ "IDR": "Indonesian Rupiah",
+ "ILS": "Israeli New Sheqel",
+ "IMP": "Isle of Man Pound",
+ "INR": "Indian Rupee",
+ "IQD": "Iraqi Dinar",
+ "ISK": "Icelandic KrĆ³na",
+ "JEP": "Jersey Pound",
+ "JMD": "Jamaican Dollar",
+ "JOD": "Jordanian Dinar",
+ "JPY": "Japanese Yen",
+ "KES": "Kenyan Shilling",
+ "KGS": "Kyrgyzstani Som",
+ "KHR": "Cambodian Riel",
+ "KMF": "Comorian Franc",
+ "KRW": "South Korean Won",
+ "KWD": "Kuwaiti Dinar",
+ "KYD": "Cayman Islands Dollar",
+ "KZT": "Kazakhstani Tenge",
+ "LAK": "Lao Kip",
+ "LBP": "Lebanese Pound",
+ "LKR": "Sri Lankan Rupee",
+ "LRD": "Liberian Dollar",
+ "LSL": "Lesotho Loti",
+ "LYD": "Libyan Dinar",
+ "MAD": "Moroccan Dirham",
+ "MDL": "Moldovan Leu",
+ "MGA": "Malagasy Ariary",
+ "MKD": "Macedonian Denar",
+ "MMK": "Myanmar Kyat",
+ "MNT": "Mongolian Tƶgrƶg",
+ "MOP": "Macanese Pataca",
+ "MRO": "Mauritanian Ouguiya",
+ "MUR": "Mauritian Rupee",
+ "MVR": "Maldivian Rufiyaa",
+ "MWK": "Malawian Kwacha",
+ "MXN": "Mexican Peso",
+ "MYR": "Malaysian Ringgit",
+ "MZN": "Mozambican Metical",
+ "NAD": "Namibian Dollar",
+ "NGN": "Nigerian Naira",
+ "NIO": "Nicaraguan CĆ³rdoba",
+ "NOK": "Norwegian Krone",
+ "NPR": "Nepalese Rupee",
+ "NZD": "New Zealand Dollar",
+ "OMR": "Omani Rial",
+ "PAB": "Panamanian Balboa",
+ "PEN": "Peruvian Sol",
+ "PGK": "Papua New Guinean Kina",
+ "PHP": "Philippine Peso",
+ "PKR": "Pakistani Rupee",
+ "PLN": "Polish ZÅoty",
+ "PYG": "Paraguayan GuaranĆ",
+ "QAR": "Qatari Riyal",
+ "RON": "Romanian Leu",
+ "RSD": "Serbian Dinar",
+ "RUB": "Russian Ruble",
+ "RWF": "Rwandan Franc",
+ "SAR": "Saudi Riyal",
+ "SBD": "Solomon Islands Dollar",
+ "SCR": "Seychellois Rupee",
+ "SEK": "Swedish Krona",
+ "SGD": "Singapore Dollar",
+ "SHP": "Saint Helenian Pound",
+ "SLL": "Sierra Leonean Leone",
+ "SOS": "Somali Shilling",
+ "SRD": "Surinamese Dollar",
+ "SSP": "South Sudanese Pound",
+ "STD": "SĆ£o TomĆ© and PrĆncipe Dobra",
+ "SVC": "Salvadoran ColĆ³n",
+ "SZL": "Swazi Lilangeni",
+ "THB": "Thai Baht",
+ "TJS": "Tajikistani Somoni",
+ "TMT": "Turkmenistani Manat",
+ "TND": "Tunisian Dinar",
+ "TOP": "Tongan PaŹ»anga",
+ "TRY": "Turkish Lira",
+ "TTD": "Trinidad and Tobago Dollar",
+ "TWD": "New Taiwan Dollar",
+ "TZS": "Tanzanian Shilling",
+ "UAH": "Ukrainian Hryvnia",
+ "UGX": "Ugandan Shilling",
+ "USD": "US Dollar",
+ "UYU": "Uruguayan Peso",
+ "UZS": "Uzbekistan Som",
+ "VEF": "Venezuelan BolĆvar",
+ "VES": "Venezuelan BolĆvar Soberano",
+ "VND": "Vietnamese Äį»ng",
+ "VUV": "Vanuatu Vatu",
+ "WST": "Samoan Tala",
+ "XAF": "Central African Cfa Franc",
+ "XAG": "Silver (Troy Ounce)",
+ "XAU": "Gold (Troy Ounce)",
+ "XCD": "East Caribbean Dollar",
+ "XDR": "Special Drawing Rights",
+ "XOF": "West African Cfa Franc",
+ "XPD": "Palladium",
+ "XPF": "Cfp Franc",
+ "XPT": "Platinum",
+ "YER": "Yemeni Rial",
+ "ZAR": "South African Rand",
+ "ZMW": "Zambian Kwacha",
+ "ZWL": "Zimbabwean Dollar"
+ }
+}
From a8b32194eb41a812d4abcbcf3d67e4f7cbf790f4 Mon Sep 17 00:00:00 2001
From: ben
Date: Wed, 18 Jan 2023 18:51:42 +0000
Subject: [PATCH 30/55] Reworded
---
lnbits/extensions/market/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lnbits/extensions/market/README.md b/lnbits/extensions/market/README.md
index 5b1c89eee..88e796fc8 100644
--- a/lnbits/extensions/market/README.md
+++ b/lnbits/extensions/market/README.md
@@ -149,7 +149,7 @@ Data from newer events should replace data from older events.
```
-As all elements are optional, an `action` `update` to a `product` `image`, may look as simple as:
+As all elements are optional, an `update` `action` to a `product` `image`, may look as simple as:
```
{
From d89a6a337a8e5f2956a347e4527f45698cdd2a7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?dni=20=E2=9A=A1?=
Date: Thu, 19 Jan 2023 10:30:47 +0100
Subject: [PATCH 31/55] boltz extension v2, recurring swaps (#981)
* add status to statusdialog
* first commits for boltz update
* formatting
* add latest boltz-clien package
* big refactor, depending on boltz_client package, clean up, mypy issues, not tested yet
* blacking, sorting and stuff
* remove unused req_wrap helper
* remove api docs from frontend
* bug: frontend boltz limits error
* clean up buttons
* update to boltz-client 0.0.8
* fix tests to poetry version 1.3.1
* update requirements
* formatting
* recurring swap works now, need more finetuning
* add exceptions for multiple auto swaps and swapping in with active auto swap
* black
* auto reverse swap actually works :)
* remove swap status dialogs
* update to boltz_client 0.0.9
* update to boltz-client 0.1.1, and fix startup
* update requirement.txt for boltz-client
* fixup columns in table, remove unused payment.extra, change deezy label
* remove balance check for auto swap out
* update boltzc-lient to 0.1.2, fix mypy issue inside boltz package
* nitpicks calle tasks.py
* calle nitpicks crud
* calle nitpicks crud
* refactor
* fix formatting
* circular import
* black :)
Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
---
lnbits/extensions/boltz/boltz.py | 421 ----------
lnbits/extensions/boltz/crud.py | 224 ++++--
lnbits/extensions/boltz/mempool.py | 93 ---
lnbits/extensions/boltz/migrations.py | 18 +
lnbits/extensions/boltz/models.py | 43 +-
lnbits/extensions/boltz/tasks.py | 268 ++++---
.../boltz/templates/boltz/_api_docs.html | 277 +------
.../boltz/_autoReverseSwapDialog.html | 83 ++
.../templates/boltz/_autoReverseSwapList.html | 54 ++
.../boltz/templates/boltz/_buttons.html | 35 +
.../templates/boltz/_checkSwapDialog.html | 113 +++
.../boltz/templates/boltz/_qrDialog.html | 31 +
.../boltz/_reverseSubmarineSwapDialog.html | 72 ++
.../boltz/_reverseSubmarineSwapList.html | 66 ++
.../boltz/templates/boltz/_statusDialog.html | 29 +
.../templates/boltz/_submarineSwapDialog.html | 58 ++
.../templates/boltz/_submarineSwapList.html | 78 ++
.../boltz/templates/boltz/index.html | 744 ++++--------------
lnbits/extensions/boltz/utils.py | 85 +-
lnbits/extensions/boltz/views.py | 6 +-
lnbits/extensions/boltz/views_api.py | 280 ++++---
.../deezy/templates/deezy/index.html | 2 +-
poetry.lock | 26 +-
pyproject.toml | 6 +-
requirements.txt | 1 +
tests/extensions/boltz/conftest.py | 15 +-
tests/extensions/boltz/test_api.py | 3 +-
tests/extensions/boltz/test_swap.py | 31 -
28 files changed, 1380 insertions(+), 1782 deletions(-)
delete mode 100644 lnbits/extensions/boltz/boltz.py
delete mode 100644 lnbits/extensions/boltz/mempool.py
create mode 100644 lnbits/extensions/boltz/templates/boltz/_autoReverseSwapDialog.html
create mode 100644 lnbits/extensions/boltz/templates/boltz/_autoReverseSwapList.html
create mode 100644 lnbits/extensions/boltz/templates/boltz/_buttons.html
create mode 100644 lnbits/extensions/boltz/templates/boltz/_checkSwapDialog.html
create mode 100644 lnbits/extensions/boltz/templates/boltz/_qrDialog.html
create mode 100644 lnbits/extensions/boltz/templates/boltz/_reverseSubmarineSwapDialog.html
create mode 100644 lnbits/extensions/boltz/templates/boltz/_reverseSubmarineSwapList.html
create mode 100644 lnbits/extensions/boltz/templates/boltz/_statusDialog.html
create mode 100644 lnbits/extensions/boltz/templates/boltz/_submarineSwapDialog.html
create mode 100644 lnbits/extensions/boltz/templates/boltz/_submarineSwapList.html
delete mode 100644 tests/extensions/boltz/test_swap.py
diff --git a/lnbits/extensions/boltz/boltz.py b/lnbits/extensions/boltz/boltz.py
deleted file mode 100644
index 31d927eac..000000000
--- a/lnbits/extensions/boltz/boltz.py
+++ /dev/null
@@ -1,421 +0,0 @@
-import asyncio
-import os
-from hashlib import sha256
-from typing import Awaitable, Union
-
-import httpx
-from embit import ec, script
-from embit.networks import NETWORKS
-from embit.transaction import SIGHASH, Transaction, TransactionInput, TransactionOutput
-from loguru import logger
-
-from lnbits.core.services import create_invoice, pay_invoice
-from lnbits.helpers import urlsafe_short_hash
-from lnbits.settings import settings
-
-from .crud import update_swap_status
-from .mempool import (
- get_fee_estimation,
- get_mempool_blockheight,
- get_mempool_fees,
- get_mempool_tx,
- get_mempool_tx_from_txs,
- send_onchain_tx,
- wait_for_websocket_message,
-)
-from .models import (
- CreateReverseSubmarineSwap,
- CreateSubmarineSwap,
- ReverseSubmarineSwap,
- SubmarineSwap,
- SwapStatus,
-)
-from .utils import check_balance, get_timestamp, req_wrap
-
-net = NETWORKS[settings.boltz_network]
-
-
-async def create_swap(data: CreateSubmarineSwap) -> SubmarineSwap:
- if not check_boltz_limits(data.amount):
- msg = f"Boltz - swap not in boltz limits"
- logger.warning(msg)
- raise Exception(msg)
-
- swap_id = urlsafe_short_hash()
- try:
- payment_hash, payment_request = await create_invoice(
- wallet_id=data.wallet,
- amount=data.amount,
- memo=f"swap of {data.amount} sats on boltz.exchange",
- extra={"tag": "boltz", "swap_id": swap_id},
- )
- except Exception as exc:
- msg = f"Boltz - create_invoice failed {str(exc)}"
- logger.error(msg)
- raise
-
- refund_privkey = ec.PrivateKey(os.urandom(32), True, net)
- refund_pubkey_hex = bytes.hex(refund_privkey.sec()).decode()
-
- res = req_wrap(
- "post",
- f"{settings.boltz_url}/createswap",
- json={
- "type": "submarine",
- "pairId": "BTC/BTC",
- "orderSide": "sell",
- "refundPublicKey": refund_pubkey_hex,
- "invoice": payment_request,
- "referralId": "lnbits",
- },
- headers={"Content-Type": "application/json"},
- )
- res = res.json()
- logger.info(
- f"Boltz - created normal swap, boltz_id: {res['id']}. wallet: {data.wallet}"
- )
- return SubmarineSwap(
- id=swap_id,
- time=get_timestamp(),
- wallet=data.wallet,
- amount=data.amount,
- payment_hash=payment_hash,
- refund_privkey=refund_privkey.wif(net),
- refund_address=data.refund_address,
- boltz_id=res["id"],
- status="pending",
- address=res["address"],
- expected_amount=res["expectedAmount"],
- timeout_block_height=res["timeoutBlockHeight"],
- bip21=res["bip21"],
- redeem_script=res["redeemScript"],
- )
-
-
-"""
-explanation taken from electrum
-send on Lightning, receive on-chain
-- User generates preimage, RHASH. Sends RHASH to server.
-- Server creates an LN invoice for RHASH.
-- User pays LN invoice - except server needs to hold the HTLC as preimage is unknown.
-- Server creates on-chain output locked to RHASH.
-- User spends on-chain output, revealing preimage.
-- Server fulfills HTLC using preimage.
-Note: expected_onchain_amount_sat is BEFORE deducting the on-chain claim tx fee.
-"""
-
-
-async def create_reverse_swap(
- data: CreateReverseSubmarineSwap,
-) -> [ReverseSubmarineSwap, asyncio.Task]:
- if not check_boltz_limits(data.amount):
- msg = f"Boltz - reverse swap not in boltz limits"
- logger.warning(msg)
- raise Exception(msg)
-
- swap_id = urlsafe_short_hash()
-
- if not await check_balance(data):
- logger.error(f"Boltz - reverse swap, insufficient balance.")
- return False
-
- claim_privkey = ec.PrivateKey(os.urandom(32), True, net)
- claim_pubkey_hex = bytes.hex(claim_privkey.sec()).decode()
- preimage = os.urandom(32)
- preimage_hash = sha256(preimage).hexdigest()
-
- res = req_wrap(
- "post",
- f"{settings.boltz_url}/createswap",
- json={
- "type": "reversesubmarine",
- "pairId": "BTC/BTC",
- "orderSide": "buy",
- "invoiceAmount": data.amount,
- "preimageHash": preimage_hash,
- "claimPublicKey": claim_pubkey_hex,
- "referralId": "lnbits",
- },
- headers={"Content-Type": "application/json"},
- )
- res = res.json()
-
- logger.info(
- f"Boltz - created reverse swap, boltz_id: {res['id']}. wallet: {data.wallet}"
- )
-
- swap = ReverseSubmarineSwap(
- id=swap_id,
- amount=data.amount,
- wallet=data.wallet,
- onchain_address=data.onchain_address,
- instant_settlement=data.instant_settlement,
- claim_privkey=claim_privkey.wif(net),
- preimage=preimage.hex(),
- status="pending",
- boltz_id=res["id"],
- timeout_block_height=res["timeoutBlockHeight"],
- lockup_address=res["lockupAddress"],
- onchain_amount=res["onchainAmount"],
- redeem_script=res["redeemScript"],
- invoice=res["invoice"],
- time=get_timestamp(),
- )
- logger.debug(f"Boltz - waiting for onchain tx, reverse swap_id: {swap.id}")
- task = create_task_log_exception(
- swap.id, wait_for_onchain_tx(swap, swap_websocket_callback_initial)
- )
- return swap, task
-
-
-def start_onchain_listener(swap: ReverseSubmarineSwap) -> asyncio.Task:
- return create_task_log_exception(
- swap.id, wait_for_onchain_tx(swap, swap_websocket_callback_restart)
- )
-
-
-async def start_confirmation_listener(
- swap: ReverseSubmarineSwap, mempool_lockup_tx
-) -> asyncio.Task:
- logger.debug(f"Boltz - reverse swap, waiting for confirmation...")
-
- tx, txid, *_ = mempool_lockup_tx
-
- confirmed = await wait_for_websocket_message({"track-tx": txid}, "txConfirmed")
- if confirmed:
- logger.debug(f"Boltz - reverse swap lockup transaction confirmed! claiming...")
- await create_claim_tx(swap, mempool_lockup_tx)
- else:
- logger.debug(f"Boltz - reverse swap lockup transaction still not confirmed.")
-
-
-def create_task_log_exception(swap_id: str, awaitable: Awaitable) -> asyncio.Task:
- async def _log_exception(awaitable):
- try:
- return await awaitable
- except Exception as e:
- logger.error(f"Boltz - reverse swap failed!: {swap_id} - {e}")
- await update_swap_status(swap_id, "failed")
-
- return asyncio.create_task(_log_exception(awaitable))
-
-
-async def swap_websocket_callback_initial(swap):
- wstask = asyncio.create_task(
- wait_for_websocket_message(
- {"track-address": swap.lockup_address}, "address-transactions"
- )
- )
- logger.debug(
- f"Boltz - created task, waiting on mempool websocket for address: {swap.lockup_address}"
- )
-
- # create_task is used because pay_invoice is stuck as long as boltz does not
- # see the onchain claim tx and it ends up in deadlock
- task: asyncio.Task = create_task_log_exception(
- swap.id,
- pay_invoice(
- wallet_id=swap.wallet,
- payment_request=swap.invoice,
- description=f"reverse swap for {swap.amount} sats on boltz.exchange",
- extra={"tag": "boltz", "swap_id": swap.id, "reverse": True},
- ),
- )
- logger.debug(f"Boltz - task pay_invoice created, reverse swap_id: {swap.id}")
-
- done, pending = await asyncio.wait(
- [task, wstask], return_when=asyncio.FIRST_COMPLETED
- )
- message = done.pop().result()
-
- # pay_invoice already failed, do not wait for onchain tx anymore
- if message is None:
- logger.debug(f"Boltz - pay_invoice already failed cancel websocket task.")
- wstask.cancel()
- raise
-
- return task, message
-
-
-async def swap_websocket_callback_restart(swap):
- logger.debug(f"Boltz - swap_websocket_callback_restart called...")
- message = await wait_for_websocket_message(
- {"track-address": swap.lockup_address}, "address-transactions"
- )
- return None, message
-
-
-async def wait_for_onchain_tx(swap: ReverseSubmarineSwap, callback):
- task, txs = await callback(swap)
- mempool_lockup_tx = get_mempool_tx_from_txs(txs, swap.lockup_address)
- if mempool_lockup_tx:
- tx, txid, *_ = mempool_lockup_tx
- if swap.instant_settlement or tx["status"]["confirmed"]:
- logger.debug(
- f"Boltz - reverse swap instant settlement, claiming immediatly..."
- )
- await create_claim_tx(swap, mempool_lockup_tx)
- else:
- await start_confirmation_listener(swap, mempool_lockup_tx)
- try:
- if task:
- await task
- except:
- logger.error(
- f"Boltz - could not await pay_invoice task, but sent onchain. should never happen!"
- )
- else:
- logger.error(f"Boltz - mempool lockup tx not found.")
-
-
-async def create_claim_tx(swap: ReverseSubmarineSwap, mempool_lockup_tx):
- tx = await create_onchain_tx(swap, mempool_lockup_tx)
- await send_onchain_tx(tx)
- logger.debug(f"Boltz - onchain tx sent, reverse swap completed")
- await update_swap_status(swap.id, "complete")
-
-
-async def create_refund_tx(swap: SubmarineSwap):
- mempool_lockup_tx = get_mempool_tx(swap.address)
- tx = await create_onchain_tx(swap, mempool_lockup_tx)
- await send_onchain_tx(tx)
-
-
-def check_block_height(block_height: int):
- current_block_height = get_mempool_blockheight()
- if current_block_height <= block_height:
- msg = f"refund not possible, timeout_block_height ({block_height}) is not yet exceeded ({current_block_height})"
- logger.debug(msg)
- raise Exception(msg)
-
-
-"""
-a submarine swap consists of 2 onchain tx's a lockup and a redeem tx.
-we create a tx to redeem the funds locked by the onchain lockup tx.
-claim tx for reverse swaps, refund tx for normal swaps they are the same
-onchain redeem tx, the difference between them is the private key, onchain_address,
-input sequence and input script_sig
-"""
-
-
-async def create_onchain_tx(
- swap: Union[ReverseSubmarineSwap, SubmarineSwap], mempool_lockup_tx
-) -> Transaction:
- is_refund_tx = type(swap) == SubmarineSwap
- if is_refund_tx:
- check_block_height(swap.timeout_block_height)
- privkey = ec.PrivateKey.from_wif(swap.refund_privkey)
- onchain_address = swap.refund_address
- preimage = b""
- sequence = 0xFFFFFFFE
- else:
- privkey = ec.PrivateKey.from_wif(swap.claim_privkey)
- preimage = bytes.fromhex(swap.preimage)
- onchain_address = swap.onchain_address
- sequence = 0xFFFFFFFF
-
- locktime = swap.timeout_block_height
- redeem_script = bytes.fromhex(swap.redeem_script)
-
- fees = get_fee_estimation()
-
- tx, txid, vout_cnt, vout_amount = mempool_lockup_tx
-
- script_pubkey = script.address_to_scriptpubkey(onchain_address)
-
- vin = [TransactionInput(bytes.fromhex(txid), vout_cnt, sequence=sequence)]
- vout = [TransactionOutput(vout_amount - fees, script_pubkey)]
- tx = Transaction(vin=vin, vout=vout)
-
- if is_refund_tx:
- tx.locktime = locktime
-
- # TODO: 2 rounds for fee calculation, look at vbytes after signing and do another TX
- s = script.Script(data=redeem_script)
- for i, inp in enumerate(vin):
- if is_refund_tx:
- rs = bytes([34]) + bytes([0]) + bytes([32]) + sha256(redeem_script).digest()
- tx.vin[i].script_sig = script.Script(data=rs)
- h = tx.sighash_segwit(i, s, vout_amount)
- sig = privkey.sign(h).serialize() + bytes([SIGHASH.ALL])
- witness_items = [sig, preimage, redeem_script]
- tx.vin[i].witness = script.Witness(items=witness_items)
-
- return tx
-
-
-def get_swap_status(swap: Union[SubmarineSwap, ReverseSubmarineSwap]) -> SwapStatus:
- swap_status = SwapStatus(
- wallet=swap.wallet,
- swap_id=swap.id,
- )
-
- try:
- boltz_request = get_boltz_status(swap.boltz_id)
- swap_status.boltz = boltz_request["status"]
- except httpx.HTTPStatusError as exc:
- json = exc.response.json()
- swap_status.boltz = json["error"]
- if "could not find" in swap_status.boltz:
- swap_status.exists = False
-
- if type(swap) == SubmarineSwap:
- swap_status.reverse = False
- swap_status.address = swap.address
- else:
- swap_status.reverse = True
- swap_status.address = swap.lockup_address
-
- swap_status.block_height = get_mempool_blockheight()
- swap_status.timeout_block_height = (
- f"{str(swap.timeout_block_height)} -> current: {str(swap_status.block_height)}"
- )
-
- if swap_status.block_height >= swap.timeout_block_height:
- swap_status.hit_timeout = True
-
- mempool_tx = get_mempool_tx(swap_status.address)
- swap_status.lockup = mempool_tx
- if mempool_tx == None:
- swap_status.has_lockup = False
- swap_status.confirmed = False
- swap_status.mempool = "transaction.unknown"
- swap_status.message = "lockup tx not in mempool"
- else:
- swap_status.has_lockup = True
- tx, *_ = mempool_tx
- if tx["status"]["confirmed"] == True:
- swap_status.mempool = "transaction.confirmed"
- swap_status.confirmed = True
- else:
- swap_status.confirmed = False
- swap_status.mempool = "transaction.unconfirmed"
-
- return swap_status
-
-
-def check_boltz_limits(amount):
- try:
- pairs = get_boltz_pairs()
- limits = pairs["pairs"]["BTC/BTC"]["limits"]
- return amount >= limits["minimal"] and amount <= limits["maximal"]
- except:
- return False
-
-
-def get_boltz_pairs():
- res = req_wrap(
- "get",
- f"{settings.boltz_url}/getpairs",
- headers={"Content-Type": "application/json"},
- )
- return res.json()
-
-
-def get_boltz_status(boltzid):
- res = req_wrap(
- "post",
- f"{settings.boltz_url}/swapstatus",
- json={"id": boltzid},
- )
- return res.json()
diff --git a/lnbits/extensions/boltz/crud.py b/lnbits/extensions/boltz/crud.py
index 1bb4286dc..621fd3656 100644
--- a/lnbits/extensions/boltz/crud.py
+++ b/lnbits/extensions/boltz/crud.py
@@ -1,20 +1,21 @@
-from http import HTTPStatus
+import time
from typing import List, Optional, Union
+from boltz_client.boltz import BoltzReverseSwapResponse, BoltzSwapResponse
from loguru import logger
-from starlette.exceptions import HTTPException
+
+from lnbits.helpers import urlsafe_short_hash
from . import db
from .models import (
+ AutoReverseSubmarineSwap,
+ CreateAutoReverseSubmarineSwap,
CreateReverseSubmarineSwap,
CreateSubmarineSwap,
ReverseSubmarineSwap,
SubmarineSwap,
)
-
-"""
-Submarine Swaps
-"""
+from .utils import create_boltz_client, execute_reverse_swap
async def get_submarine_swaps(wallet_ids: Union[str, List[str]]) -> List[SubmarineSwap]:
@@ -30,20 +31,6 @@ async def get_submarine_swaps(wallet_ids: Union[str, List[str]]) -> List[Submari
return [SubmarineSwap(**row) for row in rows]
-async def get_pending_submarine_swaps(
- wallet_ids: Union[str, List[str]]
-) -> List[SubmarineSwap]:
- if isinstance(wallet_ids, str):
- wallet_ids = [wallet_ids]
-
- q = ",".join(["?"] * len(wallet_ids))
- rows = await db.fetchall(
- f"SELECT * FROM boltz.submarineswap WHERE wallet IN ({q}) and status='pending' order by time DESC",
- (*wallet_ids,),
- )
- return [SubmarineSwap(**row) for row in rows]
-
-
async def get_all_pending_submarine_swaps() -> List[SubmarineSwap]:
rows = await db.fetchall(
f"SELECT * FROM boltz.submarineswap WHERE status='pending' order by time DESC",
@@ -51,14 +38,20 @@ async def get_all_pending_submarine_swaps() -> List[SubmarineSwap]:
return [SubmarineSwap(**row) for row in rows]
-async def get_submarine_swap(swap_id) -> SubmarineSwap:
+async def get_submarine_swap(swap_id) -> Optional[SubmarineSwap]:
row = await db.fetchone(
"SELECT * FROM boltz.submarineswap WHERE id = ?", (swap_id,)
)
return SubmarineSwap(**row) if row else None
-async def create_submarine_swap(swap: SubmarineSwap) -> Optional[SubmarineSwap]:
+async def create_submarine_swap(
+ data: CreateSubmarineSwap,
+ swap: BoltzSwapResponse,
+ swap_id: str,
+ refund_privkey_wif: str,
+ payment_hash: str,
+) -> Optional[SubmarineSwap]:
await db.execute(
"""
@@ -80,26 +73,22 @@ async def create_submarine_swap(swap: SubmarineSwap) -> Optional[SubmarineSwap]:
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
+ swap_id,
+ data.wallet,
+ payment_hash,
+ "pending",
swap.id,
- swap.wallet,
- swap.payment_hash,
- swap.status,
- swap.boltz_id,
- swap.refund_privkey,
- swap.refund_address,
- swap.expected_amount,
- swap.timeout_block_height,
+ refund_privkey_wif,
+ data.refund_address,
+ swap.expectedAmount,
+ swap.timeoutBlockHeight,
swap.address,
swap.bip21,
- swap.redeem_script,
- swap.amount,
+ swap.redeemScript,
+ data.amount,
),
)
- return await get_submarine_swap(swap.id)
-
-
-async def delete_submarine_swap(swap_id):
- await db.execute("DELETE FROM boltz.submarineswap WHERE id = ?", (swap_id,))
+ return await get_submarine_swap(swap_id)
async def get_reverse_submarine_swaps(
@@ -117,21 +106,6 @@ async def get_reverse_submarine_swaps(
return [ReverseSubmarineSwap(**row) for row in rows]
-async def get_pending_reverse_submarine_swaps(
- wallet_ids: Union[str, List[str]]
-) -> List[ReverseSubmarineSwap]:
- if isinstance(wallet_ids, str):
- wallet_ids = [wallet_ids]
-
- q = ",".join(["?"] * len(wallet_ids))
- rows = await db.fetchall(
- f"SELECT * FROM boltz.reverse_submarineswap WHERE wallet IN ({q}) and status='pending' order by time DESC",
- (*wallet_ids,),
- )
-
- return [ReverseSubmarineSwap(**row) for row in rows]
-
-
async def get_all_pending_reverse_submarine_swaps() -> List[ReverseSubmarineSwap]:
rows = await db.fetchall(
f"SELECT * FROM boltz.reverse_submarineswap WHERE status='pending' order by time DESC"
@@ -140,7 +114,7 @@ async def get_all_pending_reverse_submarine_swaps() -> List[ReverseSubmarineSwap
return [ReverseSubmarineSwap(**row) for row in rows]
-async def get_reverse_submarine_swap(swap_id) -> SubmarineSwap:
+async def get_reverse_submarine_swap(swap_id) -> Optional[ReverseSubmarineSwap]:
row = await db.fetchone(
"SELECT * FROM boltz.reverse_submarineswap WHERE id = ?", (swap_id,)
)
@@ -148,8 +122,31 @@ async def get_reverse_submarine_swap(swap_id) -> SubmarineSwap:
async def create_reverse_submarine_swap(
- swap: ReverseSubmarineSwap,
-) -> Optional[ReverseSubmarineSwap]:
+ data: CreateReverseSubmarineSwap,
+ claim_privkey_wif: str,
+ preimage_hex: str,
+ swap: BoltzReverseSwapResponse,
+) -> ReverseSubmarineSwap:
+
+ swap_id = urlsafe_short_hash()
+
+ reverse_swap = ReverseSubmarineSwap(
+ id=swap_id,
+ wallet=data.wallet,
+ status="pending",
+ boltz_id=swap.id,
+ instant_settlement=data.instant_settlement,
+ preimage=preimage_hex,
+ claim_privkey=claim_privkey_wif,
+ lockup_address=swap.lockupAddress,
+ invoice=swap.invoice,
+ onchain_amount=swap.onchainAmount,
+ onchain_address=data.onchain_address,
+ timeout_block_height=swap.timeoutBlockHeight,
+ redeem_script=swap.redeemScript,
+ amount=data.amount,
+ time=int(time.time()),
+ )
await db.execute(
"""
@@ -172,36 +169,93 @@ async def create_reverse_submarine_swap(
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
- swap.id,
+ reverse_swap.id,
+ reverse_swap.wallet,
+ reverse_swap.status,
+ reverse_swap.boltz_id,
+ reverse_swap.instant_settlement,
+ reverse_swap.preimage,
+ reverse_swap.claim_privkey,
+ reverse_swap.lockup_address,
+ reverse_swap.invoice,
+ reverse_swap.onchain_amount,
+ reverse_swap.onchain_address,
+ reverse_swap.timeout_block_height,
+ reverse_swap.redeem_script,
+ reverse_swap.amount,
+ ),
+ )
+ return reverse_swap
+
+
+async def get_auto_reverse_submarine_swaps(
+ wallet_ids: List[str],
+) -> List[AutoReverseSubmarineSwap]:
+ q = ",".join(["?"] * len(wallet_ids))
+ rows = await db.fetchall(
+ f"SELECT * FROM boltz.auto_reverse_submarineswap WHERE wallet IN ({q}) order by time DESC",
+ (*wallet_ids,),
+ )
+ return [AutoReverseSubmarineSwap(**row) for row in rows]
+
+
+async def get_auto_reverse_submarine_swap(
+ swap_id,
+) -> Optional[AutoReverseSubmarineSwap]:
+ row = await db.fetchone(
+ "SELECT * FROM boltz.auto_reverse_submarineswap WHERE id = ?", (swap_id,)
+ )
+ return AutoReverseSubmarineSwap(**row) if row else None
+
+
+async def get_auto_reverse_submarine_swap_by_wallet(
+ wallet_id,
+) -> Optional[AutoReverseSubmarineSwap]:
+ row = await db.fetchone(
+ "SELECT * FROM boltz.auto_reverse_submarineswap WHERE wallet = ?", (wallet_id,)
+ )
+ return AutoReverseSubmarineSwap(**row) if row else None
+
+
+async def create_auto_reverse_submarine_swap(
+ swap: CreateAutoReverseSubmarineSwap,
+) -> Optional[AutoReverseSubmarineSwap]:
+
+ swap_id = urlsafe_short_hash()
+ await db.execute(
+ """
+ INSERT INTO boltz.auto_reverse_submarineswap (
+ id,
+ wallet,
+ onchain_address,
+ instant_settlement,
+ balance,
+ amount
+ )
+ VALUES (?, ?, ?, ?, ?, ?)
+ """,
+ (
+ swap_id,
swap.wallet,
- swap.status,
- swap.boltz_id,
- swap.instant_settlement,
- swap.preimage,
- swap.claim_privkey,
- swap.lockup_address,
- swap.invoice,
- swap.onchain_amount,
swap.onchain_address,
- swap.timeout_block_height,
- swap.redeem_script,
+ swap.instant_settlement,
+ swap.balance,
swap.amount,
),
)
- return await get_reverse_submarine_swap(swap.id)
+ return await get_auto_reverse_submarine_swap(swap_id)
+
+
+async def delete_auto_reverse_submarine_swap(swap_id):
+ await db.execute(
+ "DELETE FROM boltz.auto_reverse_submarineswap WHERE id = ?", (swap_id,)
+ )
async def update_swap_status(swap_id: str, status: str):
- reverse = ""
swap = await get_submarine_swap(swap_id)
- if swap is None:
- swap = await get_reverse_submarine_swap(swap_id)
-
- if swap is None:
- return None
-
- if type(swap) == SubmarineSwap:
+ if swap:
await db.execute(
"UPDATE boltz.submarineswap SET status='"
+ status
@@ -209,17 +263,23 @@ async def update_swap_status(swap_id: str, status: str):
+ swap.id
+ "'"
)
- if type(swap) == ReverseSubmarineSwap:
- reverse = "reverse"
+ logger.info(
+ f"Boltz - swap status change: {status}. boltz_id: {swap.boltz_id}, wallet: {swap.wallet}"
+ )
+ return swap
+
+ reverse_swap = await get_reverse_submarine_swap(swap_id)
+ if reverse_swap:
await db.execute(
"UPDATE boltz.reverse_submarineswap SET status='"
+ status
+ "' WHERE id='"
- + swap.id
+ + reverse_swap.id
+ "'"
)
+ logger.info(
+ f"Boltz - reverse swap status change: {status}. boltz_id: {reverse_swap.boltz_id}, wallet: {reverse_swap.wallet}"
+ )
+ return reverse_swap
- message = f"Boltz - {reverse} swap status change: {status}. boltz_id: {swap.boltz_id}, wallet: {swap.wallet}"
- logger.info(message)
-
- return swap
+ return None
diff --git a/lnbits/extensions/boltz/mempool.py b/lnbits/extensions/boltz/mempool.py
deleted file mode 100644
index c7d572a91..000000000
--- a/lnbits/extensions/boltz/mempool.py
+++ /dev/null
@@ -1,93 +0,0 @@
-import asyncio
-import json
-
-import httpx
-import websockets
-from embit.transaction import Transaction
-from loguru import logger
-
-from lnbits.settings import settings
-
-from .utils import req_wrap
-
-websocket_url = f"{settings.boltz_mempool_space_url_ws}/api/v1/ws"
-
-
-async def wait_for_websocket_message(send, message_string):
- async for websocket in websockets.connect(websocket_url):
- try:
- await websocket.send(json.dumps({"action": "want", "data": ["blocks"]}))
- await websocket.send(json.dumps(send))
- async for raw in websocket:
- message = json.loads(raw)
- if message_string in message:
- return message.get(message_string)
- except websockets.ConnectionClosed:
- continue
-
-
-def get_mempool_tx(address):
- res = req_wrap(
- "get",
- f"{settings.boltz_mempool_space_url}/api/address/{address}/txs",
- headers={"Content-Type": "text/plain"},
- )
- txs = res.json()
- return get_mempool_tx_from_txs(txs, address)
-
-
-def get_mempool_tx_from_txs(txs, address):
- if len(txs) == 0:
- return None
- tx = txid = vout_cnt = vout_amount = None
- for a_tx in txs:
- for i, vout in enumerate(a_tx["vout"]):
- if vout["scriptpubkey_address"] == address:
- tx = a_tx
- txid = a_tx["txid"]
- vout_cnt = i
- vout_amount = vout["value"]
- # should never happen
- if tx == None:
- raise Exception("mempool tx not found")
- if txid == None:
- raise Exception("mempool txid not found")
- return tx, txid, vout_cnt, vout_amount
-
-
-def get_fee_estimation() -> int:
- # TODO: hardcoded maximum tx size, in the future we try to get the size of the tx via embit
- # we need a function like Transaction.vsize()
- tx_size_vbyte = 200
- mempool_fees = get_mempool_fees()
- return mempool_fees * tx_size_vbyte
-
-
-def get_mempool_fees() -> int:
- res = req_wrap(
- "get",
- f"{settings.boltz_mempool_space_url}/api/v1/fees/recommended",
- headers={"Content-Type": "text/plain"},
- )
- fees = res.json()
- return int(fees["economyFee"])
-
-
-def get_mempool_blockheight() -> int:
- res = req_wrap(
- "get",
- f"{settings.boltz_mempool_space_url}/api/blocks/tip/height",
- headers={"Content-Type": "text/plain"},
- )
- return int(res.text)
-
-
-async def send_onchain_tx(tx: Transaction):
- raw = bytes.hex(tx.serialize())
- logger.debug(f"Boltz - mempool sending onchain tx...")
- req_wrap(
- "post",
- f"{settings.boltz_mempool_space_url}/api/tx",
- headers={"Content-Type": "text/plain"},
- content=raw,
- )
diff --git a/lnbits/extensions/boltz/migrations.py b/lnbits/extensions/boltz/migrations.py
index 925322ecd..66648fccc 100644
--- a/lnbits/extensions/boltz/migrations.py
+++ b/lnbits/extensions/boltz/migrations.py
@@ -44,3 +44,21 @@ async def m001_initial(db):
);
"""
)
+
+
+async def m002_auto_swaps(db):
+ await db.execute(
+ """
+ CREATE TABLE boltz.auto_reverse_submarineswap (
+ id TEXT PRIMARY KEY,
+ wallet TEXT NOT NULL,
+ onchain_address TEXT NOT NULL,
+ amount INT NOT NULL,
+ balance INT NOT NULL,
+ instant_settlement BOOLEAN NOT NULL,
+ time TIMESTAMP NOT NULL DEFAULT """
+ + db.timestamp_now
+ + """
+ );
+ """
+ )
diff --git a/lnbits/extensions/boltz/models.py b/lnbits/extensions/boltz/models.py
index 4f4ec9e29..9500b678a 100644
--- a/lnbits/extensions/boltz/models.py
+++ b/lnbits/extensions/boltz/models.py
@@ -1,9 +1,5 @@
-import json
-from typing import Dict, List, Optional
-
-from fastapi.params import Query
-from pydantic.main import BaseModel
-from sqlalchemy.engine import base
+from fastapi import Query
+from pydantic import BaseModel
class SubmarineSwap(BaseModel):
@@ -51,25 +47,22 @@ class CreateReverseSubmarineSwap(BaseModel):
wallet: str = Query(...)
amount: int = Query(...)
instant_settlement: bool = Query(...)
- # validate on-address, bcrt1 for regtest addresses
- onchain_address: str = Query(
- ..., regex="^(bcrt1|bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$"
- )
+ onchain_address: str = Query(...)
-class SwapStatus(BaseModel):
- swap_id: str
+class AutoReverseSubmarineSwap(BaseModel):
+ id: str
wallet: str
- status: str = ""
- message: str = ""
- boltz: str = ""
- mempool: str = ""
- address: str = ""
- block_height: int = 0
- timeout_block_height: str = ""
- lockup: Optional[dict] = {}
- has_lockup: bool = False
- hit_timeout: bool = False
- confirmed: bool = True
- exists: bool = True
- reverse: bool = False
+ amount: int
+ balance: int
+ onchain_address: str
+ instant_settlement: bool
+ time: int
+
+
+class CreateAutoReverseSubmarineSwap(BaseModel):
+ wallet: str = Query(...)
+ amount: int = Query(...)
+ balance: int = Query(0)
+ instant_settlement: bool = Query(...)
+ onchain_address: str = Query(...)
diff --git a/lnbits/extensions/boltz/tasks.py b/lnbits/extensions/boltz/tasks.py
index d1ace04b8..ba394164b 100644
--- a/lnbits/extensions/boltz/tasks.py
+++ b/lnbits/extensions/boltz/tasks.py
@@ -1,129 +1,25 @@
import asyncio
-import httpx
+from boltz_client.boltz import BoltzNotFoundException, BoltzSwapStatusException
+from boltz_client.mempool import MempoolBlockHeightException
from loguru import logger
+from lnbits.core.crud import get_wallet
from lnbits.core.models import Payment
-from lnbits.core.services import check_transaction_status
+from lnbits.core.services import check_transaction_status, fee_reserve
from lnbits.helpers import get_current_extension_name
from lnbits.tasks import register_invoice_listener
-from .boltz import (
- create_claim_tx,
- create_refund_tx,
- get_swap_status,
- start_confirmation_listener,
- start_onchain_listener,
-)
from .crud import (
+ create_reverse_submarine_swap,
get_all_pending_reverse_submarine_swaps,
get_all_pending_submarine_swaps,
- get_reverse_submarine_swap,
+ get_auto_reverse_submarine_swap_by_wallet,
get_submarine_swap,
update_swap_status,
)
-
-"""
-testcases for boltz startup
-A. normal swaps
- 1. test: create -> kill -> start -> startup invoice listeners -> pay onchain funds -> should complete
- 2. test: create -> kill -> pay onchain funds -> start -> startup check -> should complete
- 3. test: create -> kill -> mine blocks and hit timeout -> start -> should go timeout/failed
- 4. test: create -> kill -> pay to less onchain funds -> mine blocks hit timeout -> start lnbits -> should be refunded
-
-B. reverse swaps
- 1. test: create instant -> kill -> boltz does lockup -> not confirmed -> start lnbits -> should claim/complete
- 2. test: create instant -> kill -> no lockup -> start lnbits -> should start onchain listener -> boltz does lockup -> should claim/complete (difficult to test)
- 3. test: create -> kill -> boltz does lockup -> not confirmed -> start lnbits -> should start tx listener -> after confirmation -> should claim/complete
- 4. test: create -> kill -> boltz does lockup -> confirmed -> start lnbits -> should claim/complete
- 5. test: create -> kill -> boltz does lockup -> hit timeout -> boltz refunds -> start -> should timeout
-"""
-
-
-async def check_for_pending_swaps():
- try:
- swaps = await get_all_pending_submarine_swaps()
- reverse_swaps = await get_all_pending_reverse_submarine_swaps()
- if len(swaps) > 0 or len(reverse_swaps) > 0:
- logger.debug(f"Boltz - startup swap check")
- except:
- # database is not created yet, do nothing
- return
-
- if len(swaps) > 0:
- logger.debug(f"Boltz - {len(swaps)} pending swaps")
- for swap in swaps:
- try:
- swap_status = get_swap_status(swap)
- # should only happen while development when regtest is reset
- if swap_status.exists is False:
- logger.debug(f"Boltz - swap: {swap.boltz_id} does not exist.")
- await update_swap_status(swap.id, "failed")
- continue
-
- payment_status = await check_transaction_status(
- swap.wallet, swap.payment_hash
- )
-
- if payment_status.paid:
- logger.debug(
- f"Boltz - swap: {swap.boltz_id} got paid while offline."
- )
- await update_swap_status(swap.id, "complete")
- else:
- if swap_status.hit_timeout:
- if not swap_status.has_lockup:
- logger.debug(
- f"Boltz - swap: {swap.id} hit timeout, but no lockup tx..."
- )
- await update_swap_status(swap.id, "timeout")
- else:
- logger.debug(f"Boltz - refunding swap: {swap.id}...")
- await create_refund_tx(swap)
- await update_swap_status(swap.id, "refunded")
-
- except Exception as exc:
- logger.error(f"Boltz - swap: {swap.id} - {str(exc)}")
-
- if len(reverse_swaps) > 0:
- logger.debug(f"Boltz - {len(reverse_swaps)} pending reverse swaps")
- for reverse_swap in reverse_swaps:
- try:
- swap_status = get_swap_status(reverse_swap)
-
- if swap_status.exists is False:
- logger.debug(
- f"Boltz - reverse_swap: {reverse_swap.boltz_id} does not exist."
- )
- await update_swap_status(reverse_swap.id, "failed")
- continue
-
- # if timeout hit, boltz would have already refunded
- if swap_status.hit_timeout:
- logger.debug(
- f"Boltz - reverse_swap: {reverse_swap.boltz_id} timeout."
- )
- await update_swap_status(reverse_swap.id, "timeout")
- continue
-
- if not swap_status.has_lockup:
- # start listener for onchain address
- logger.debug(
- f"Boltz - reverse_swap: {reverse_swap.boltz_id} restarted onchain address listener."
- )
- await start_onchain_listener(reverse_swap)
- continue
-
- if reverse_swap.instant_settlement or swap_status.confirmed:
- await create_claim_tx(reverse_swap, swap_status.lockup)
- else:
- logger.debug(
- f"Boltz - reverse_swap: {reverse_swap.boltz_id} restarted confirmation listener."
- )
- await start_confirmation_listener(reverse_swap, swap_status.lockup)
-
- except Exception as exc:
- logger.error(f"Boltz - reverse swap: {reverse_swap.id} - {str(exc)}")
+from .models import CreateReverseSubmarineSwap, ReverseSubmarineSwap, SubmarineSwap
+from .utils import create_boltz_client, execute_reverse_swap
async def wait_for_paid_invoices():
@@ -136,19 +32,149 @@ async def wait_for_paid_invoices():
async def on_invoice_paid(payment: Payment) -> None:
- if "boltz" != payment.extra.get("tag"):
+
+ await check_for_auto_swap(payment)
+
+ if payment.extra.get("tag") != "boltz":
# not a boltz invoice
return
await payment.set_pending(False)
- swap_id = payment.extra.get("swap_id")
- swap = await get_submarine_swap(swap_id)
- if not swap:
- logger.error(f"swap_id: {swap_id} not found.")
+ if payment.extra:
+ swap_id = payment.extra.get("swap_id")
+ if swap_id:
+ swap = await get_submarine_swap(swap_id)
+ if swap:
+ await update_swap_status(swap_id, "complete")
+
+
+async def check_for_auto_swap(payment: Payment) -> None:
+ auto_swap = await get_auto_reverse_submarine_swap_by_wallet(payment.wallet_id)
+ if auto_swap:
+ wallet = await get_wallet(payment.wallet_id)
+ if wallet:
+ reserve = fee_reserve(wallet.balance_msat) / 1000
+ balance = wallet.balance_msat / 1000
+ amount = balance - auto_swap.balance - reserve
+ if amount >= auto_swap.amount:
+
+ client = create_boltz_client()
+ claim_privkey_wif, preimage_hex, swap = client.create_reverse_swap(
+ amount=int(amount)
+ )
+ new_swap = await create_reverse_submarine_swap(
+ CreateReverseSubmarineSwap(
+ wallet=auto_swap.wallet,
+ amount=int(amount),
+ instant_settlement=auto_swap.instant_settlement,
+ onchain_address=auto_swap.onchain_address,
+ ),
+ claim_privkey_wif,
+ preimage_hex,
+ swap,
+ )
+ await execute_reverse_swap(client, new_swap)
+
+ logger.info(
+ f"Boltz: auto reverse swap created with amount: {amount}, boltz_id: {new_swap.boltz_id}"
+ )
+
+
+"""
+testcases for boltz startup
+A. normal swaps
+ 1. test: create -> kill -> start -> startup invoice listeners -> pay onchain funds -> should complete
+ 2. test: create -> kill -> pay onchain funds -> mine block -> start -> startup check -> should complete
+ 3. test: create -> kill -> mine blocks and hit timeout -> start -> should go timeout/failed
+ 4. test: create -> kill -> pay to less onchain funds -> mine blocks hit timeout -> start lnbits -> should be refunded
+
+B. reverse swaps
+ 1. test: create instant -> kill -> boltz does lockup -> not confirmed -> start lnbits -> should claim/complete
+ 2. test: create -> kill -> boltz does lockup -> not confirmed -> start lnbits -> mine blocks -> should claim/complete
+ 3. test: create -> kill -> boltz does lockup -> confirmed -> start lnbits -> should claim/complete
+"""
+
+
+async def check_for_pending_swaps():
+ try:
+ swaps = await get_all_pending_submarine_swaps()
+ reverse_swaps = await get_all_pending_reverse_submarine_swaps()
+ if len(swaps) > 0 or len(reverse_swaps) > 0:
+ logger.debug(f"Boltz - startup swap check")
+ except:
+ logger.error(
+ f"Boltz - startup swap check, database is not created yet, do nothing"
+ )
return
- logger.info(
- f"Boltz - lightning invoice is paid, normal swap completed. swap_id: {swap_id}"
- )
- await update_swap_status(swap_id, "complete")
+ client = create_boltz_client()
+
+ if len(swaps) > 0:
+ logger.debug(f"Boltz - {len(swaps)} pending swaps")
+ for swap in swaps:
+ await check_swap(swap, client)
+
+ if len(reverse_swaps) > 0:
+ logger.debug(f"Boltz - {len(reverse_swaps)} pending reverse swaps")
+ for reverse_swap in reverse_swaps:
+ await check_reverse_swap(reverse_swap, client)
+
+
+async def check_swap(swap: SubmarineSwap, client):
+ try:
+ payment_status = await check_transaction_status(swap.wallet, swap.payment_hash)
+ if payment_status.paid:
+ logger.debug(f"Boltz - swap: {swap.boltz_id} got paid while offline.")
+ await update_swap_status(swap.id, "complete")
+ else:
+ try:
+ _ = client.swap_status(swap.id)
+ except:
+ txs = client.mempool.get_txs_from_address(swap.address)
+ if len(txs) == 0:
+ await update_swap_status(swap.id, "timeout")
+ else:
+ await client.refund_swap(
+ privkey_wif=swap.refund_privkey,
+ lockup_address=swap.address,
+ receive_address=swap.refund_address,
+ redeem_script_hex=swap.redeem_script,
+ timeout_block_height=swap.timeout_block_height,
+ )
+ await update_swap_status(swap.id, "refunded")
+ except BoltzNotFoundException as exc:
+ logger.debug(f"Boltz - swap: {swap.boltz_id} does not exist.")
+ await update_swap_status(swap.id, "failed")
+ except MempoolBlockHeightException as exc:
+ logger.debug(
+ f"Boltz - tried to refund swap: {swap.id}, but has not reached the timeout."
+ )
+ except Exception as exc:
+ logger.error(f"Boltz - unhandled exception, swap: {swap.id} - {str(exc)}")
+
+
+async def check_reverse_swap(reverse_swap: ReverseSubmarineSwap, client):
+ try:
+ _ = client.swap_status(reverse_swap.boltz_id)
+ await client.claim_reverse_swap(
+ lockup_address=reverse_swap.lockup_address,
+ receive_address=reverse_swap.onchain_address,
+ privkey_wif=reverse_swap.claim_privkey,
+ preimage_hex=reverse_swap.preimage,
+ redeem_script_hex=reverse_swap.redeem_script,
+ zeroconf=reverse_swap.instant_settlement,
+ )
+ await update_swap_status(reverse_swap.id, "complete")
+
+ except BoltzSwapStatusException as exc:
+ logger.debug(f"Boltz - swap_status: {str(exc)}")
+ await update_swap_status(reverse_swap.id, "failed")
+ # should only happen while development when regtest is reset
+ except BoltzNotFoundException as exc:
+ logger.debug(f"Boltz - reverse swap: {reverse_swap.boltz_id} does not exist.")
+ await update_swap_status(reverse_swap.id, "failed")
+ except Exception as exc:
+ logger.error(
+ f"Boltz - unhandled exception, reverse swap: {reverse_swap.id} - {str(exc)}"
+ )
diff --git a/lnbits/extensions/boltz/templates/boltz/_api_docs.html b/lnbits/extensions/boltz/templates/boltz/_api_docs.html
index 704a8db56..bdcbc8ca2 100644
--- a/lnbits/extensions/boltz/templates/boltz/_api_docs.html
+++ b/lnbits/extensions/boltz/templates/boltz/_api_docs.html
@@ -1,242 +1,35 @@
-
-
-
-
-
-
- Boltz.exchange: Do onchain to offchain and vice-versa swaps
-
-
- Submarine and Reverse Submarine Swaps on LNbits via boltz.exchange
- API
-
-
- Link :
- https://boltz.exchange
-
-
-
- More details
-
-
- Created by,
- dni
-
-
-
-
-
-
-
-
- GET
- /boltz/api/v1/swap/reverse
-
- Returns 200 OK (application/json)
-
- JSON list of reverse submarine swaps
- Curl example
- curl -X GET {{ root_url }}/boltz/api/v1/swap/reverse -H "X-Api-Key:
- {{ user.wallets[0].adminkey }}"
-
-
-
-
-
-
-
- POST
- /boltz/api/v1/swap/reverse
- Body (application/json)
- {"wallet": <string>, "onchain_address": <string>,
- "amount": <integer>, "instant_settlement":
- <boolean>}
-
- Returns 200 OK (application/json)
-
- JSON create a reverse-submarine swaps
- Curl example
- curl -X POST {{ root_url }}/boltz/api/v1/swap/reverse -H "X-Api-Key:
- {{ user.wallets[0].adminkey }}"
-
-
-
-
-
-
-
- GET /boltz/api/v1/swap
-
- Returns 200 OK (application/json)
-
- JSON list of submarine swaps
- Curl example
- curl -X GET {{ root_url }}/boltz/api/v1/swap -H "X-Api-Key: {{
- user.wallets[0].adminkey }}"
-
-
-
-
-
-
-
- POST /boltz/api/v1/swap
- Body (application/json)
- {"wallet": <string>, "refund_address": <string>,
- "amount": <integer>}
-
- Returns 200 OK (application/json)
-
- JSON create a submarine swaps
- Curl example
- curl -X POST {{ root_url }}/boltz/api/v1/swap -H "X-Api-Key: {{
- user.wallets[0].adminkey }}"
-
-
-
-
-
-
-
- POST
- /boltz/api/v1/swap/refund/{swap_id}
-
- Returns 200 OK (application/json)
-
- JSON submarine swap
- Curl example
- curl -X GET {{ root_url }}/boltz/api/v1/swap/refund/{swap_id} -H
- "X-Api-Key: {{ user.wallets[0].adminkey }}"
-
-
-
-
-
-
-
- POST
- /boltz/api/v1/swap/status/{swap_id}
-
- Returns 200 OK (text/plain)
-
- swap status
- Curl example
- curl -X GET {{ root_url }}/boltz/api/v1/swap/status/{swap_id} -H
- "X-Api-Key: {{ user.wallets[0].adminkey }}"
-
-
-
-
-
-
-
- GET
- /boltz/api/v1/swap/check
-
- Returns 200 OK (application/json)
-
- JSON pending swaps
- Curl example
- curl -X GET {{ root_url }}/boltz/api/v1/swap/check -H "X-Api-Key: {{
- user.wallets[0].adminkey }}"
-
-
-
-
-
-
-
- GET
- /boltz/api/v1/swap/boltz
-
- Returns 200 OK (text/plain)
-
- JSON boltz config
- Curl example
- curl -X GET {{ root_url }}/boltz/api/v1/swap/boltz -H "X-Api-Key: {{
- user.wallets[0].inkey }}"
-
-
-
-
-
-
-
- GET
- /boltz/api/v1/swap/mempool
-
- Returns 200 OK (text/plain)
-
- mempool url
- Curl example
- curl -X GET {{ root_url }}/boltz/api/v1/swap/mempool -H "X-Api-Key:
- {{ user.wallets[0].inkey }}"
-
-
-
-
-
+
+
+
+
+
+ Boltz.exchange: Do onchain to offchain and vice-versa swaps
+
+
+ Submarine and Reverse Submarine Swaps on LNbits via boltz.exchange API
+
+
+ Link :
+ https://boltz.exchange
+
+
+
+ More details
+
+
+ Created by,
+ dni
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/_autoReverseSwapDialog.html b/lnbits/extensions/boltz/templates/boltz/_autoReverseSwapDialog.html
new file mode 100644
index 000000000..c9c682a8b
--- /dev/null
+++ b/lnbits/extensions/boltz/templates/boltz/_autoReverseSwapDialog.html
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+ mininum balance kept in wallet after a swap + the fee_reserve
+
+
+
+
+
+
+
+ Create Onchain TX when transaction is in mempool, but not
+ confirmed yet.
+
+
+
+
+
+
+
+
+ Cancel
+
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/_autoReverseSwapList.html b/lnbits/extensions/boltz/templates/boltz/_autoReverseSwapList.html
new file mode 100644
index 000000000..b297524f1
--- /dev/null
+++ b/lnbits/extensions/boltz/templates/boltz/_autoReverseSwapList.html
@@ -0,0 +1,54 @@
+
+
+
+
+
Auto Lightning -> Onchain
+
+
+ Export to CSV
+
+
+
+ {% raw %}
+
+
+
+
+ {{ col.label }}
+
+
+
+
+
+
+
+ delete the automatic reverse swap
+
+
+
+ {{ col.value }}
+
+
+
+ {% endraw %}
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/_buttons.html b/lnbits/extensions/boltz/templates/boltz/_buttons.html
new file mode 100644
index 000000000..3817b0766
--- /dev/null
+++ b/lnbits/extensions/boltz/templates/boltz/_buttons.html
@@ -0,0 +1,35 @@
+
+
+
+
+ Send onchain funds offchain (BTC -> LN)
+
+
+
+
+ Send offchain funds to onchain address (LN -> BTC)
+
+
+
+
+ Automatically send offchain funds to onchain address (LN -> BTC) with a
+ predefined threshold
+
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/_checkSwapDialog.html b/lnbits/extensions/boltz/templates/boltz/_checkSwapDialog.html
new file mode 100644
index 000000000..e59702d24
--- /dev/null
+++ b/lnbits/extensions/boltz/templates/boltz/_checkSwapDialog.html
@@ -0,0 +1,113 @@
+
+
+ pending swaps
+
+ {% raw %}
+
+
+
+
+ {{ col.label }}
+
+
+
+
+
+
+
+ refund swap
+
+
+ dowload refund file
+
+
+ open tx on mempool.space
+
+
+
+ {{ col.value }}
+
+
+
+ {% endraw %}
+
+ pending reverse swaps
+
+ {% raw %}
+
+
+
+
+ {{ col.label }}
+
+
+
+
+
+
+
+ open tx on mempool.space
+
+
+
+ {{ col.value }}
+
+
+
+ {% endraw %}
+
+
+ Close
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/_qrDialog.html b/lnbits/extensions/boltz/templates/boltz/_qrDialog.html
new file mode 100644
index 000000000..053ef65e7
--- /dev/null
+++ b/lnbits/extensions/boltz/templates/boltz/_qrDialog.html
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+ {% raw %}
+ Bitcoin On-Chain TX
+ Expected amount (sats): {{ qrCodeDialog.data.expected_amount }}
+
+ Expected amount (btc): {{ qrCodeDialog.data.expected_amount_btc }}
+
+ Onchain Address: {{ qrCodeDialog.data.address }}
+ {% endraw %}
+
+
+ Copy On-Chain Address
+ Close
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/_reverseSubmarineSwapDialog.html b/lnbits/extensions/boltz/templates/boltz/_reverseSubmarineSwapDialog.html
new file mode 100644
index 000000000..5b3cf861a
--- /dev/null
+++ b/lnbits/extensions/boltz/templates/boltz/_reverseSubmarineSwapDialog.html
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+ Create Onchain TX when transaction is in mempool, but not
+ confirmed yet.
+
+
+
+
+
+
+
+
+ Cancel
+
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/_reverseSubmarineSwapList.html b/lnbits/extensions/boltz/templates/boltz/_reverseSubmarineSwapList.html
new file mode 100644
index 000000000..fc9668d0d
--- /dev/null
+++ b/lnbits/extensions/boltz/templates/boltz/_reverseSubmarineSwapList.html
@@ -0,0 +1,66 @@
+
+
+
+
+
Lightning -> Onchain
+
+
+ Export to CSV
+
+
+
+ {% raw %}
+
+
+
+
+ {{ col.label }}
+
+
+
+
+
+
+
+ open swap status info
+
+
+ open tx on mempool.space
+
+
+
+ {{ col.value }}
+
+
+
+ {% endraw %}
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/_statusDialog.html b/lnbits/extensions/boltz/templates/boltz/_statusDialog.html
new file mode 100644
index 000000000..f6c14abc9
--- /dev/null
+++ b/lnbits/extensions/boltz/templates/boltz/_statusDialog.html
@@ -0,0 +1,29 @@
+
+
+
+ {% raw %}
+ Status: {{ statusDialog.data.status }}
+
+ {% endraw %}
+
+
+ Refund
+
+ Download refundfile
+ Close
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/_submarineSwapDialog.html b/lnbits/extensions/boltz/templates/boltz/_submarineSwapDialog.html
new file mode 100644
index 000000000..bf6aaa187
--- /dev/null
+++ b/lnbits/extensions/boltz/templates/boltz/_submarineSwapDialog.html
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+ Cancel
+
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/_submarineSwapList.html b/lnbits/extensions/boltz/templates/boltz/_submarineSwapList.html
new file mode 100644
index 000000000..b42e1dee9
--- /dev/null
+++ b/lnbits/extensions/boltz/templates/boltz/_submarineSwapList.html
@@ -0,0 +1,78 @@
+
+
+
+
+
Onchain -> Lightning
+
+
+ Export to CSV
+
+
+
+ {% raw %}
+
+
+
+
+ {{ col.label }}
+
+
+
+
+
+
+
+ open swap onchain details
+
+
+ open swap status info
+
+
+ open tx on mempool.space
+
+
+
+ {{ col.value }}
+
+
+
+ {% endraw %}
+
+
+
diff --git a/lnbits/extensions/boltz/templates/boltz/index.html b/lnbits/extensions/boltz/templates/boltz/index.html
index b7312de7a..308c3a46e 100644
--- a/lnbits/extensions/boltz/templates/boltz/index.html
+++ b/lnbits/extensions/boltz/templates/boltz/index.html
@@ -1,531 +1,19 @@
{% extends "base.html" %} {% from "macros.jinja" import window_vars with context
%} {% block page %}
-
-
-
-
-
- Send onchain funds offchain (BTC -> LN)
-
-
-
-
- Send offchain funds to onchain address (LN -> BTC)
-
-
-
-
- Check all pending swaps if they can be refunded.
-
-
-
-
-
-
-
-
-
Swaps (In)
-
-
- Export to CSV
-
-
-
- {% raw %}
-
-
-
-
- {{ col.label }}
-
-
-
-
-
-
-
- open swap onchain details
-
-
- open swap status info
-
-
- open tx on mempool.space
-
-
-
- {{ col.value }}
-
-
-
- {% endraw %}
-
-
-
-
-
-
-
-
Reverse Swaps (Out)
-
-
- Export to CSV
-
-
-
- {% raw %}
-
-
-
-
- {{ col.label }}
-
-
-
-
-
-
-
- open swap status info
-
-
- open tx on mempool.space
-
-
-
- {{ col.value }}
-
-
-
- {% endraw %}
-
-
-
+
+ {% include "boltz/_buttons.html" %} {% include
+ "boltz/_submarineSwapList.html" %} {% include
+ "boltz/_reverseSubmarineSwapList.html" %} {% include
+ "boltz/_autoReverseSwapList.html" %}
-
-
-
- {{SITE_TITLE}} Boltz extension
-
-
-
- {% include "boltz/_api_docs.html" %}
-
-
+
+ {% include "boltz/_api_docs.html" %}
-
-
-
-
-
-
-
-
-
-
-
- Cancel
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Create Onchain TX when transaction is in mempool, but not
- confirmed yet.
-
-
-
-
-
-
-
-
- Cancel
-
-
-
-
-
-
-
-
-
-
- {% raw %}
- Bitcoin On-Chain TX
- Expected amount (sats): {{ qrCodeDialog.data.expected_amount }}
-
- Expected amount (btc): {{ qrCodeDialog.data.expected_amount_btc
- }}
- Onchain Address: {{ qrCodeDialog.data.address }}
- {% endraw %}
-
-
- Copy On-Chain Address
- Close
-
-
-
-
-
-
- {% raw %}
- Wallet: {{ statusDialog.data.wallet }}
- Boltz Status: {{ statusDialog.data.boltz }}
- Mempool Status: {{ statusDialog.data.mempool }}
- Blockheight timeout: {{ statusDialog.data.timeout_block_height
- }}
- {% endraw %}
-
-
- Refund
-
- Download refundfile
- Close
-
-
-
-
-
- pending swaps
-
- {% raw %}
-
-
-
-
- {{ col.label }}
-
-
-
-
-
-
-
- refund swap
-
-
- dowload refund file
-
-
- open tx on mempool.space
-
-
-
- {{ col.value }}
-
-
-
- {% endraw %}
-
- pending reverse swaps
-
- {% raw %}
-
-
-
-
- {{ col.label }}
-
-
-
-
-
-
-
- open tx on mempool.space
-
-
-
- {{ col.value }}
-
-
-
- {% endraw %}
-
-
- Close
-
-
-
+ {% include "boltz/_submarineSwapDialog.html" %} {% include
+ "boltz/_reverseSubmarineSwapDialog.html" %} {% include
+ "boltz/_autoReverseSwapDialog.html" %} {% include "boltz/_qrDialog.html" %} {%
+ include "boltz/_statusDialog.html" %}
{% endblock %} {% block scripts %} {{ window_vars(user) }}
diff --git a/lnbits/extensions/boltz/utils.py b/lnbits/extensions/boltz/utils.py
index 4fb2edda2..7623fb6f6 100644
--- a/lnbits/extensions/boltz/utils.py
+++ b/lnbits/extensions/boltz/utils.py
@@ -1,10 +1,25 @@
+import asyncio
import calendar
import datetime
+from typing import Awaitable
-import httpx
-from loguru import logger
+from boltz_client.boltz import BoltzClient, BoltzConfig
-from lnbits.core.services import fee_reserve, get_wallet
+from lnbits.core.services import fee_reserve, get_wallet, pay_invoice
+from lnbits.settings import settings
+
+from .models import ReverseSubmarineSwap
+
+
+def create_boltz_client() -> BoltzClient:
+ config = BoltzConfig(
+ network=settings.boltz_network,
+ api_url=settings.boltz_url,
+ mempool_url=f"{settings.boltz_mempool_space_url}/api",
+ mempool_ws_url=f"{settings.boltz_mempool_space_url_ws}/api/v1/ws",
+ referral_id="lnbits",
+ )
+ return BoltzClient(config)
async def check_balance(data) -> bool:
@@ -23,22 +38,50 @@ def get_timestamp():
return calendar.timegm(date.utctimetuple())
-def req_wrap(funcname, *args, **kwargs):
- try:
+async def execute_reverse_swap(client, swap: ReverseSubmarineSwap):
+ # claim_task is watching onchain address for the lockup transaction to arrive / confirm
+ # and if the lockup is there, claim the onchain revealing preimage for hold invoice
+ claim_task = asyncio.create_task(
+ client.claim_reverse_swap(
+ privkey_wif=swap.claim_privkey,
+ preimage_hex=swap.preimage,
+ lockup_address=swap.lockup_address,
+ receive_address=swap.onchain_address,
+ redeem_script_hex=swap.redeem_script,
+ )
+ )
+ # pay_task is paying the hold invoice which gets held until you reveal your preimage when claiming your onchain funds
+ pay_task = pay_invoice_and_update_status(
+ swap.id,
+ claim_task,
+ pay_invoice(
+ wallet_id=swap.wallet,
+ payment_request=swap.invoice,
+ description=f"reverse swap for {swap.onchain_amount} sats on boltz.exchange",
+ extra={"tag": "boltz", "swap_id": swap.id, "reverse": True},
+ ),
+ )
+
+ # they need to run be concurrently, because else pay_task will lock the eventloop and claim_task will not be executed.
+ # the lockup transaction can only happen after you pay the invoice, which cannot be redeemed immediatly -> hold invoice
+ # after getting the lockup transaction, you can claim the onchain funds revealing the preimage for boltz to redeem the hold invoice
+ asyncio.gather(claim_task, pay_task)
+
+
+def pay_invoice_and_update_status(
+ swap_id: str, wstask: asyncio.Task, awaitable: Awaitable
+) -> asyncio.Task:
+ async def _pay_invoice(awaitable):
+ from .crud import update_swap_status
+
try:
- func = getattr(httpx, funcname)
- except AttributeError:
- logger.error('httpx function not found "%s"' % funcname)
- else:
- res = func(*args, timeout=30, **kwargs)
- res.raise_for_status()
- return res
- except httpx.RequestError as exc:
- msg = f"Unreachable: {exc.request.url!r}."
- logger.error(msg)
- raise
- except httpx.HTTPStatusError as exc:
- msg = f"HTTP Status Error: {exc.response.status_code} while requesting {exc.request.url!r}."
- logger.error(msg)
- logger.error(exc.response.json()["error"])
- raise
+ awaited = await awaitable
+ await update_swap_status(swap_id, "complete")
+ return awaited
+ except asyncio.exceptions.CancelledError:
+ """lnbits process was exited, do nothing and handle it in startup script"""
+ except:
+ wstask.cancel()
+ await update_swap_status(swap_id, "failed")
+
+ return asyncio.create_task(_pay_invoice(awaitable))
diff --git a/lnbits/extensions/boltz/views.py b/lnbits/extensions/boltz/views.py
index b6864113c..4b0e6d535 100644
--- a/lnbits/extensions/boltz/views.py
+++ b/lnbits/extensions/boltz/views.py
@@ -1,11 +1,10 @@
from urllib.parse import urlparse
-from fastapi import Request
-from fastapi.params import Depends
+from fastapi import Depends, Request
from fastapi.templating import Jinja2Templates
from starlette.responses import HTMLResponse
-from lnbits.core.models import Payment, User
+from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from . import boltz_ext, boltz_renderer
@@ -16,7 +15,6 @@ templates = Jinja2Templates(directory="templates")
@boltz_ext.get("/", response_class=HTMLResponse)
async def index(request: Request, user: User = Depends(check_user_exists)):
root_url = urlparse(str(request.url)).netloc
- wallet_ids = [wallet.id for wallet in user.wallets]
return boltz_renderer().TemplateResponse(
"boltz/index.html",
{"request": request, "user": user.dict(), "root_url": root_url},
diff --git a/lnbits/extensions/boltz/views_api.py b/lnbits/extensions/boltz/views_api.py
index 34f4033e8..ab32fac9a 100644
--- a/lnbits/extensions/boltz/views_api.py
+++ b/lnbits/extensions/boltz/views_api.py
@@ -1,34 +1,23 @@
-from datetime import datetime
from http import HTTPStatus
from typing import List
-import httpx
-from fastapi import status
-from fastapi.encoders import jsonable_encoder
-from fastapi.param_functions import Body
-from fastapi.params import Depends, Query
-from loguru import logger
-from pydantic import BaseModel
+from fastapi import Depends, Query, status
from starlette.exceptions import HTTPException
-from starlette.requests import Request
from lnbits.core.crud import get_user
+from lnbits.core.services import create_invoice
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
+from lnbits.helpers import urlsafe_short_hash
from lnbits.settings import settings
from . import boltz_ext
-from .boltz import (
- create_refund_tx,
- create_reverse_swap,
- create_swap,
- get_boltz_pairs,
- get_swap_status,
-)
from .crud import (
+ create_auto_reverse_submarine_swap,
create_reverse_submarine_swap,
create_submarine_swap,
- get_pending_reverse_submarine_swaps,
- get_pending_submarine_swaps,
+ delete_auto_reverse_submarine_swap,
+ get_auto_reverse_submarine_swap_by_wallet,
+ get_auto_reverse_submarine_swaps,
get_reverse_submarine_swap,
get_reverse_submarine_swaps,
get_submarine_swap,
@@ -36,12 +25,14 @@ from .crud import (
update_swap_status,
)
from .models import (
+ AutoReverseSubmarineSwap,
+ CreateAutoReverseSubmarineSwap,
CreateReverseSubmarineSwap,
CreateSubmarineSwap,
ReverseSubmarineSwap,
SubmarineSwap,
)
-from .utils import check_balance
+from .utils import check_balance, create_boltz_client, execute_reverse_swap
@boltz_ext.get(
@@ -76,17 +67,8 @@ async def api_submarineswap(
):
wallet_ids = [g.wallet.id]
if all_wallets:
- wallet_ids = (await get_user(g.wallet.user)).wallet_ids
-
- for swap in await get_pending_submarine_swaps(wallet_ids):
- swap_status = get_swap_status(swap)
- if swap_status.hit_timeout:
- if not swap_status.has_lockup:
- logger.warning(
- f"Boltz - swap: {swap.id} hit timeout, but no lockup tx..."
- )
- await update_swap_status(swap.id, "timeout")
-
+ user = await get_user(g.wallet.user)
+ wallet_ids = user.wallet_ids if user else []
return [swap.dict() for swap in await get_submarine_swaps(wallet_ids)]
@@ -109,35 +91,29 @@ async def api_submarineswap(
},
},
)
-async def api_submarineswap_refund(
- swap_id: str,
- g: WalletTypeInfo = Depends(require_admin_key),
-):
- if swap_id == None:
+async def api_submarineswap_refund(swap_id: str):
+ if not swap_id:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST, detail="swap_id missing"
)
-
swap = await get_submarine_swap(swap_id)
- if swap == None:
+ if not swap:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="swap does not exist."
)
-
if swap.status != "pending":
raise HTTPException(
status_code=HTTPStatus.METHOD_NOT_ALLOWED, detail="swap is not pending."
)
- try:
- await create_refund_tx(swap)
- except httpx.RequestError as exc:
- raise HTTPException(
- status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
- detail=f"Unreachable: {exc.request.url!r}.",
- )
- except Exception as exc:
- raise HTTPException(status_code=HTTPStatus.METHOD_NOT_ALLOWED, detail=str(exc))
+ client = create_boltz_client()
+ await client.refund_swap(
+ privkey_wif=swap.refund_privkey,
+ lockup_address=swap.address,
+ receive_address=swap.refund_address,
+ redeem_script_hex=swap.redeem_script,
+ timeout_block_height=swap.timeout_block_height,
+ )
await update_swap_status(swap.id, "refunded")
return swap
@@ -153,37 +129,43 @@ async def api_submarineswap_refund(
""",
response_description="create swap",
response_model=SubmarineSwap,
+ dependencies=[Depends(require_admin_key)],
responses={
- 405: {"description": "not allowed method, insufficient balance"},
+ 405: {
+ "description": "auto reverse swap is active, a swap would immediatly be swapped out again."
+ },
500: {"description": "boltz error"},
},
)
-async def api_submarineswap_create(
- data: CreateSubmarineSwap,
- wallet: WalletTypeInfo = Depends(require_admin_key),
-):
- try:
- swap_data = await create_swap(data)
- except httpx.RequestError as exc:
+async def api_submarineswap_create(data: CreateSubmarineSwap):
+
+ auto_swap = await get_auto_reverse_submarine_swap_by_wallet(data.wallet)
+ if auto_swap:
raise HTTPException(
- status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
- detail=f"Unreachable: {exc.request.url!r}.",
+ status_code=HTTPStatus.METHOD_NOT_ALLOWED,
+ detail="auto reverse swap is active, a swap would immediatly be swapped out again.",
)
- except Exception as exc:
- raise HTTPException(status_code=HTTPStatus.METHOD_NOT_ALLOWED, detail=str(exc))
- except httpx.HTTPStatusError as exc:
- raise HTTPException(
- status_code=exc.response.status_code, detail=exc.response.json()["error"]
- )
- swap = await create_submarine_swap(swap_data)
- return swap.dict()
+
+ client = create_boltz_client()
+ swap_id = urlsafe_short_hash()
+ payment_hash, payment_request = await create_invoice(
+ wallet_id=data.wallet,
+ amount=data.amount,
+ memo=f"swap of {data.amount} sats on boltz.exchange",
+ extra={"tag": "boltz", "swap_id": swap_id},
+ )
+ refund_privkey_wif, swap = client.create_swap(payment_request)
+ new_swap = await create_submarine_swap(
+ data, swap, swap_id, refund_privkey_wif, payment_hash
+ )
+ return new_swap.dict() if new_swap else None
# REVERSE SWAP
@boltz_ext.get(
"/api/v1/swap/reverse",
name=f"boltz.get /swap/reverse",
- summary="get a list of reverse swaps a swap",
+ summary="get a list of reverse swaps",
description="""
This endpoint gets a list of reverse swaps.
""",
@@ -192,13 +174,14 @@ async def api_submarineswap_create(
response_model=List[ReverseSubmarineSwap],
)
async def api_reverse_submarineswap(
- g: WalletTypeInfo = Depends(get_key_type), # type:ignore
+ g: WalletTypeInfo = Depends(get_key_type),
all_wallets: bool = Query(False),
):
wallet_ids = [g.wallet.id]
if all_wallets:
- wallet_ids = (await get_user(g.wallet.user)).wallet_ids
- return [swap.dict() for swap in await get_reverse_submarine_swaps(wallet_ids)]
+ user = await get_user(g.wallet.user)
+ wallet_ids = user.wallet_ids if user else []
+ return [swap for swap in await get_reverse_submarine_swaps(wallet_ids)]
@boltz_ext.post(
@@ -211,6 +194,7 @@ async def api_reverse_submarineswap(
""",
response_description="create reverse swap",
response_model=ReverseSubmarineSwap,
+ dependencies=[Depends(require_admin_key)],
responses={
405: {"description": "not allowed method, insufficient balance"},
500: {"description": "boltz error"},
@@ -218,30 +202,88 @@ async def api_reverse_submarineswap(
)
async def api_reverse_submarineswap_create(
data: CreateReverseSubmarineSwap,
- wallet: WalletTypeInfo = Depends(require_admin_key),
-):
+) -> ReverseSubmarineSwap:
if not await check_balance(data):
raise HTTPException(
status_code=HTTPStatus.METHOD_NOT_ALLOWED, detail="Insufficient balance."
)
+ client = create_boltz_client()
+ claim_privkey_wif, preimage_hex, swap = client.create_reverse_swap(
+ amount=data.amount
+ )
+ new_swap = await create_reverse_submarine_swap(
+ data, claim_privkey_wif, preimage_hex, swap
+ )
+ await execute_reverse_swap(client, new_swap)
+ return new_swap
- try:
- swap_data, task = await create_reverse_swap(data)
- except httpx.RequestError as exc:
- raise HTTPException(
- status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
- detail=f"Unreachable: {exc.request.url!r}.",
- )
- except httpx.HTTPStatusError as exc:
- raise HTTPException(
- status_code=exc.response.status_code, detail=exc.response.json()["error"]
- )
- except Exception as exc:
- raise HTTPException(status_code=HTTPStatus.METHOD_NOT_ALLOWED, detail=str(exc))
- swap = await create_reverse_submarine_swap(swap_data)
- return swap.dict()
+@boltz_ext.get(
+ "/api/v1/swap/reverse/auto",
+ name=f"boltz.get /swap/reverse/auto",
+ summary="get a list of auto reverse swaps",
+ description="""
+ This endpoint gets a list of auto reverse swaps.
+ """,
+ response_description="list of auto reverse swaps",
+ dependencies=[Depends(get_key_type)],
+ response_model=List[AutoReverseSubmarineSwap],
+)
+async def api_auto_reverse_submarineswap(
+ g: WalletTypeInfo = Depends(get_key_type),
+ all_wallets: bool = Query(False),
+):
+ wallet_ids = [g.wallet.id]
+ if all_wallets:
+ user = await get_user(g.wallet.user)
+ wallet_ids = user.wallet_ids if user else []
+ return [swap.dict() for swap in await get_auto_reverse_submarine_swaps(wallet_ids)]
+
+
+@boltz_ext.post(
+ "/api/v1/swap/reverse/auto",
+ status_code=status.HTTP_201_CREATED,
+ name=f"boltz.post /swap/reverse/auto",
+ summary="create a auto reverse submarine swap",
+ description="""
+ This endpoint creates a auto reverse submarine swap
+ """,
+ response_description="create auto reverse swap",
+ response_model=AutoReverseSubmarineSwap,
+ dependencies=[Depends(require_admin_key)],
+ responses={
+ 405: {
+ "description": "auto reverse swap is active, only 1 swap per wallet possible."
+ },
+ },
+)
+async def api_auto_reverse_submarineswap_create(data: CreateAutoReverseSubmarineSwap):
+
+ auto_swap = await get_auto_reverse_submarine_swap_by_wallet(data.wallet)
+ if auto_swap:
+ raise HTTPException(
+ status_code=HTTPStatus.METHOD_NOT_ALLOWED,
+ detail="auto reverse swap is active, only 1 swap per wallet possible.",
+ )
+
+ swap = await create_auto_reverse_submarine_swap(data)
+ return swap.dict() if swap else None
+
+
+@boltz_ext.delete(
+ "/api/v1/swap/reverse/auto/{swap_id}",
+ name=f"boltz.delete /swap/reverse/auto",
+ summary="delete a auto reverse submarine swap",
+ description="""
+ This endpoint deletes a auto reverse submarine swap
+ """,
+ response_description="delete auto reverse swap",
+ dependencies=[Depends(require_admin_key)],
+)
+async def api_auto_reverse_submarineswap_delete(swap_id: str):
+ await delete_auto_reverse_submarine_swap(swap_id)
+ return "OK"
@boltz_ext.post(
@@ -252,65 +294,22 @@ async def api_reverse_submarineswap_create(
This endpoint attempts to get the status of the swap.
""",
response_description="status of swap json",
+ dependencies=[Depends(require_admin_key)],
responses={
404: {"description": "when swap_id is not found"},
},
)
-async def api_swap_status(
- swap_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
-):
+async def api_swap_status(swap_id: str):
swap = await get_submarine_swap(swap_id) or await get_reverse_submarine_swap(
swap_id
)
- if swap == None:
+ if not swap:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="swap does not exist."
)
- try:
- status = get_swap_status(swap)
- except httpx.RequestError as exc:
- raise HTTPException(
- status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
- detail=f"Unreachable: {exc.request.url!r}.",
- )
- except Exception as exc:
- raise HTTPException(
- status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(exc)
- )
- return status
-
-@boltz_ext.post(
- "/api/v1/swap/check",
- name=f"boltz.swap_check",
- summary="list all pending swaps",
- description="""
- This endpoint gives you 2 lists of pending swaps and reverse swaps.
- """,
- response_description="list of pending swaps",
-)
-async def api_check_swaps(
- g: WalletTypeInfo = Depends(require_admin_key),
- all_wallets: bool = Query(False),
-):
- wallet_ids = [g.wallet.id]
- if all_wallets:
- wallet_ids = (await get_user(g.wallet.user)).wallet_ids
- status = []
- try:
- for swap in await get_pending_submarine_swaps(wallet_ids):
- status.append(get_swap_status(swap))
- for reverseswap in await get_pending_reverse_submarine_swaps(wallet_ids):
- status.append(get_swap_status(reverseswap))
- except httpx.RequestError as exc:
- raise HTTPException(
- status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
- detail=f"Unreachable: {exc.request.url!r}.",
- )
- except Exception as exc:
- raise HTTPException(
- status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(exc)
- )
+ client = create_boltz_client()
+ status = client.swap_status(swap.boltz_id)
return status
@@ -325,14 +324,5 @@ async def api_check_swaps(
response_model=dict,
)
async def api_boltz_config():
- try:
- res = get_boltz_pairs()
- except httpx.RequestError as exc:
- raise HTTPException(
- status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
- detail=f"Unreachable: {exc.request.url!r}.",
- )
- except Exception as e:
- raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
-
- return res["pairs"]["BTC/BTC"]
+ client = create_boltz_client()
+ return {"minimal": client.limit_minimal, "maximal": client.limit_maximal}
diff --git a/lnbits/extensions/deezy/templates/deezy/index.html b/lnbits/extensions/deezy/templates/deezy/index.html
index 858d32550..9d112ef13 100644
--- a/lnbits/extensions/deezy/templates/deezy/index.html
+++ b/lnbits/extensions/deezy/templates/deezy/index.html
@@ -224,7 +224,7 @@
- {{SITE_TITLE}} Boltz extension
+ {{SITE_TITLE}} Deezy extension
diff --git a/poetry.lock b/poetry.lock
index 5a99e198f..46dc503bf 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -175,6 +175,24 @@ d = ["aiohttp (>=3.7.4)"]
jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"]
uvloop = ["uvloop (>=0.15.2)"]
+[[package]]
+name = "boltz-client"
+version = "0.1.2"
+description = "python boltz client"
+category = "main"
+optional = false
+python-versions = ">=3.7,<4.0"
+files = [
+ {file = "boltz_client-0.1.2-py3-none-any.whl", hash = "sha256:2fb0814c7c3ea88d039e71088648df27db0c036b777b0618bd30638dd76ebe90"},
+ {file = "boltz_client-0.1.2.tar.gz", hash = "sha256:b360c0ff26f2dea62af6457de4d8c46e434cd24b607ed3aa71494409b57e082b"},
+]
+
+[package.dependencies]
+click = ">=8"
+embit = ">=0.4"
+httpx = ">=0.23"
+websockets = ">=10"
+
[[package]]
name = "cashu"
version = "0.8.2"
@@ -532,10 +550,10 @@ files = [
cffi = ">=1.12"
[package.extras]
-docs = ["sphinx (>=1.6.5,!=1.8.0,!=3.1.0,!=3.1.1)", "sphinx-rtd-theme"]
+docs = ["sphinx (>=1.6.5,!=1.8.0,!=3.1.0,!=3.1.1)", "sphinx_rtd_theme"]
docstest = ["pyenchant (>=1.6.11)", "sphinxcontrib-spelling (>=4.0.1)", "twine (>=1.12.0)"]
pep8test = ["black", "flake8", "flake8-import-order", "pep8-naming"]
-sdist = ["setuptools-rust (>=0.11.4)"]
+sdist = ["setuptools_rust (>=0.11.4)"]
ssh = ["bcrypt (>=3.1.5)"]
test = ["hypothesis (>=1.11.4,!=3.79.2)", "iso8601", "pretend", "pytest (>=6.2.0)", "pytest-cov", "pytest-subtests", "pytest-xdist", "pytz"]
@@ -1784,7 +1802,7 @@ mssql = ["pyodbc"]
mssql-pymssql = ["pymssql"]
mssql-pyodbc = ["pyodbc"]
mysql = ["mysqlclient"]
-oracle = ["cx-oracle"]
+oracle = ["cx_oracle"]
postgresql = ["psycopg2"]
postgresql-pg8000 = ["pg8000 (<1.16.6)"]
postgresql-psycopg2binary = ["psycopg2-binary"]
@@ -2094,4 +2112,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools"
[metadata]
lock-version = "2.0"
python-versions = "^3.10 | ^3.9 | ^3.8 | ^3.7"
-content-hash = "9daf94dd600a7e23dcefcc8752fae1694e0084e56553dc578a63272776a8fe53"
+content-hash = "b2d22a2a33b4c0a4491b5519b28772435c15747b407a150ffa591bcf6ccb56a6"
diff --git a/pyproject.toml b/pyproject.toml
index 68e06db5e..23fe0dae1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -62,7 +62,8 @@ protobuf = "^4.21.6"
Cerberus = "^1.3.4"
async-timeout = "^4.0.2"
pyln-client = "0.11.1"
-cashu = "0.8.2"
+cashu = "^0.8.2"
+boltz-client = "^0.1.2"
[tool.poetry.dev-dependencies]
@@ -88,8 +89,7 @@ profile = "black"
[tool.mypy]
files = "lnbits"
exclude = """(?x)(
- ^lnbits/extensions/boltz.
- | ^lnbits/wallets/lnd_grpc_files.
+ ^lnbits/wallets/lnd_grpc_files.
)"""
[[tool.mypy.overrides]]
diff --git a/requirements.txt b/requirements.txt
index c5332811a..1a0872db8 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -7,6 +7,7 @@ attrs==22.2.0 ; python_version >= "3.7" and python_version < "4.0"
base58==2.1.1 ; python_version >= "3.7" and python_version < "4.0"
bech32==1.2.0 ; python_version >= "3.7" and python_version < "4.0"
bitstring==3.1.9 ; python_version >= "3.7" and python_version < "4.0"
+boltz-client==0.1.2 ; python_version >= "3.7" and python_version < "4.0"
cashu==0.8.2 ; python_version >= "3.7" and python_version < "4.0"
cerberus==1.3.4 ; python_version >= "3.7" and python_version < "4.0"
certifi==2022.12.7 ; python_version >= "3.7" and python_version < "4.0"
diff --git a/tests/extensions/boltz/conftest.py b/tests/extensions/boltz/conftest.py
index b9ef78875..1eba452a9 100644
--- a/tests/extensions/boltz/conftest.py
+++ b/tests/extensions/boltz/conftest.py
@@ -1,17 +1,6 @@
-import asyncio
-import json
-import secrets
-
-import pytest
import pytest_asyncio
-from lnbits.core.crud import create_account, create_wallet, get_wallet
-from lnbits.extensions.boltz.boltz import create_reverse_swap, create_swap
-from lnbits.extensions.boltz.models import (
- CreateReverseSubmarineSwap,
- CreateSubmarineSwap,
-)
-from tests.mocks import WALLET
+from lnbits.extensions.boltz.models import CreateReverseSubmarineSwap
@pytest_asyncio.fixture(scope="session")
@@ -22,4 +11,4 @@ async def reverse_swap(from_wallet):
onchain_address="bcrt1q4vfyszl4p8cuvqh07fyhtxve5fxq8e2ux5gx43",
amount=20_000,
)
- return await create_reverse_swap(data)
+ return data
diff --git a/tests/extensions/boltz/test_api.py b/tests/extensions/boltz/test_api.py
index 0266f9400..057bdab5c 100644
--- a/tests/extensions/boltz/test_api.py
+++ b/tests/extensions/boltz/test_api.py
@@ -1,7 +1,6 @@
import pytest
-import pytest_asyncio
-from tests.helpers import is_fake, is_regtest
+from tests.helpers import is_fake
@pytest.mark.asyncio
diff --git a/tests/extensions/boltz/test_swap.py b/tests/extensions/boltz/test_swap.py
deleted file mode 100644
index ab5954acb..000000000
--- a/tests/extensions/boltz/test_swap.py
+++ /dev/null
@@ -1,31 +0,0 @@
-import asyncio
-
-import pytest
-import pytest_asyncio
-
-from lnbits.extensions.boltz.boltz import create_reverse_swap, create_swap
-from lnbits.extensions.boltz.crud import (
- create_reverse_submarine_swap,
- create_submarine_swap,
- get_reverse_submarine_swap,
- get_submarine_swap,
-)
-from tests.extensions.boltz.conftest import reverse_swap
-from tests.helpers import is_fake, is_regtest
-
-
-@pytest.mark.asyncio
-@pytest.mark.skipif(is_fake, reason="this test is only passes in regtest")
-async def test_create_reverse_swap(client, reverse_swap):
- swap, wait_for_onchain = reverse_swap
- assert swap.status == "pending"
- assert swap.id is not None
- assert swap.boltz_id is not None
- assert swap.claim_privkey is not None
- assert swap.onchain_address is not None
- assert swap.lockup_address is not None
- newswap = await create_reverse_submarine_swap(swap)
- await wait_for_onchain
- newswap = await get_reverse_submarine_swap(swap.id)
- assert newswap is not None
- assert newswap.status == "complete"
From dcf5f0adaa8eb3e77f0d63416e01b9028300c68b Mon Sep 17 00:00:00 2001
From: blackcoffeexbt <87530449+blackcoffeexbt@users.noreply.github.com>
Date: Thu, 19 Jan 2023 09:33:48 +0000
Subject: [PATCH 32/55] Gerty extension tweaks (#1360)
* Changes to font sizes on Gerty to improve appearance and readability on hardware
* Gerty URL checker removes https, http and trailing slash from display
* Gerty: Added modal with copy pasta for API URL
* Gerty: Removed toggleStates Vue watch to fix weird UI toggle behavour
* Gerty: Remove API link button from list of Gertys
* Gerty: Added block height option
* Gerty: Added api response when no page number is supplied in GET request
* Gerty: blacked
* Gerty: Ran prettier on templates
* Gerty: Added block height text and removed mini gerty option
* Gerty: Remove mini gerty font sizes
* Gerty: Moved URL formatting function. Set max URLs to check to 4
* Gerty: Removed unused async calls
* Gerty: Casing fix in "copy URL" > "Copy URL"
* Gerty: Removed dead code
* Gerty: Removed unused /pages/[id] def from views_api.py
* Gerty: Ran prettier and black
---
lnbits/extensions/gerty/helpers.py | 204 +++++++++---------
.../gerty/templates/gerty/index.html | 89 +++++---
2 files changed, 155 insertions(+), 138 deletions(-)
diff --git a/lnbits/extensions/gerty/helpers.py b/lnbits/extensions/gerty/helpers.py
index 3e48c5763..a3422b794 100644
--- a/lnbits/extensions/gerty/helpers.py
+++ b/lnbits/extensions/gerty/helpers.py
@@ -40,19 +40,6 @@ def get_text_item_dict(
elif font_size <= 40:
line_width = 25
- # Get font sizes for Gerty mini
- if gerty_type.lower() == "mini gerty":
- if font_size <= 12:
- font_size = 1
- if font_size <= 15:
- font_size = 1
- elif font_size <= 20:
- font_size = 2
- elif font_size <= 40:
- font_size = 2
- else:
- font_size = 5
-
# wrap the text
wrapper = textwrap.TextWrapper(width=line_width)
word_list = wrapper.wrap(text=text)
@@ -118,7 +105,7 @@ async def get_mining_dashboard(gerty):
text = []
text.append(
get_text_item_dict(
- text="Current mining hashrate", font_size=12, gerty_type=gerty.type
+ text="Current hashrate", font_size=12, gerty_type=gerty.type
)
)
text.append(
@@ -152,7 +139,7 @@ async def get_mining_dashboard(gerty):
)
)
text.append(
- get_text_item_dict(text=progress, font_size=60, gerty_type=gerty.type)
+ get_text_item_dict(text=progress, font_size=40, gerty_type=gerty.type)
)
areas.append(text)
@@ -190,7 +177,7 @@ async def get_mining_dashboard(gerty):
text="{0}{1}%".format(
"+" if difficultyChange > 0 else "", round(difficultyChange, 2)
),
- font_size=60,
+ font_size=40,
gerty_type=gerty.type,
)
)
@@ -315,7 +302,7 @@ def get_next_update_time(sleep_time_seconds: int = 0, utc_offset: int = 0):
local_refresh_time = next_refresh_time + timedelta(hours=utc_offset)
return "{0} {1}".format(
"I'll wake up at" if gerty_should_sleep(utc_offset) else "Next update at",
- local_refresh_time.strftime("%H:%M on %e %b %Y"),
+ local_refresh_time.strftime("%H:%M"),
)
@@ -459,7 +446,7 @@ async def get_screen_data(screen_num: int, screens_list: list, gerty):
response = await client.get(url)
text.append(
get_text_item_dict(
- text=url,
+ text=make_url_readable(url),
font_size=20,
gerty_type=gerty.type,
)
@@ -475,7 +462,7 @@ async def get_screen_data(screen_num: int, screens_list: list, gerty):
text = []
text.append(
get_text_item_dict(
- text=url,
+ text=make_url_readable(url),
font_size=20,
gerty_type=gerty.type,
)
@@ -496,6 +483,13 @@ async def get_screen_data(screen_num: int, screens_list: list, gerty):
areas.append(await get_onchain_stat(screen_slug, gerty))
elif screen_slug == "onchain_block_height":
text = []
+ text.append(
+ get_text_item_dict(
+ text="Block Height",
+ font_size=20,
+ gerty_type=gerty.type,
+ )
+ )
text.append(
get_text_item_dict(
text=format_number(await get_mempool_info("tip_height", gerty)),
@@ -697,123 +691,57 @@ async def get_onchain_stat(stat_slug: str, gerty):
or stat_slug == "onchain_difficulty_blocks_remaining"
or stat_slug == "onchain_difficulty_epoch_time_remaining"
):
- async with httpx.AsyncClient() as client:
- r = await get_mempool_info("difficulty_adjustment", gerty)
- if stat_slug == "onchain_difficulty_epoch_progress":
- stat = round(r["progressPercent"])
- text.append(
- get_text_item_dict(
- text="Progress through current difficulty epoch",
- font_size=15,
- gerty_type=gerty.type,
- )
- )
- text.append(
- get_text_item_dict(
- text="{0}%".format(stat), font_size=80, gerty_type=gerty.type
- )
- )
- elif stat_slug == "onchain_difficulty_retarget_date":
- stat = r["estimatedRetargetDate"]
- dt = datetime.fromtimestamp(stat / 1000).strftime("%e %b %Y at %H:%M")
- text.append(
- get_text_item_dict(
- text="Date of next difficulty adjustment",
- font_size=15,
- gerty_type=gerty.type,
- )
- )
- text.append(
- get_text_item_dict(text=dt, font_size=40, gerty_type=gerty.type)
- )
- elif stat_slug == "onchain_difficulty_blocks_remaining":
- stat = r["remainingBlocks"]
- text.append(
- get_text_item_dict(
- text="Blocks until next difficulty adjustment",
- font_size=15,
- gerty_type=gerty.type,
- )
- )
- text.append(
- get_text_item_dict(
- text="{0}".format(format_number(stat)),
- font_size=80,
- gerty_type=gerty.type,
- )
- )
- elif stat_slug == "onchain_difficulty_epoch_time_remaining":
- stat = r["remainingTime"]
- text.append(
- get_text_item_dict(
- text="Time until next difficulty adjustment",
- font_size=15,
- gerty_type=gerty.type,
- )
- )
- text.append(
- get_text_item_dict(
- text=get_time_remaining(stat / 1000, 4),
- font_size=20,
- gerty_type=gerty.type,
- )
- )
- return text
-
-
-async def get_onchain_dashboard(gerty):
- areas = []
- if isinstance(gerty.mempool_endpoint, str):
- async with httpx.AsyncClient() as client:
- r = await get_mempool_info("difficulty_adjustment", gerty)
- text = []
+ r = await get_mempool_info("difficulty_adjustment", gerty)
+ if stat_slug == "onchain_difficulty_epoch_progress":
stat = round(r["progressPercent"])
text.append(
get_text_item_dict(
- text="Progress through epoch", font_size=12, gerty_type=gerty.type
+ text="Progress through current difficulty epoch",
+ font_size=15,
+ gerty_type=gerty.type,
)
)
text.append(
get_text_item_dict(
- text="{0}%".format(stat), font_size=60, gerty_type=gerty.type
+ text="{0}%".format(stat), font_size=80, gerty_type=gerty.type
)
)
- areas.append(text)
-
- text = []
+ elif stat_slug == "onchain_difficulty_retarget_date":
stat = r["estimatedRetargetDate"]
dt = datetime.fromtimestamp(stat / 1000).strftime("%e %b %Y at %H:%M")
text.append(
get_text_item_dict(
- text="Date of next adjustment", font_size=12, gerty_type=gerty.type
+ text="Date of next difficulty adjustment",
+ font_size=15,
+ gerty_type=gerty.type,
)
)
text.append(
- get_text_item_dict(text=dt, font_size=20, gerty_type=gerty.type)
+ get_text_item_dict(text=dt, font_size=40, gerty_type=gerty.type)
)
- areas.append(text)
-
- text = []
+ elif stat_slug == "onchain_difficulty_blocks_remaining":
stat = r["remainingBlocks"]
text.append(
get_text_item_dict(
- text="Blocks until adjustment", font_size=12, gerty_type=gerty.type
+ text="Blocks until next difficulty adjustment",
+ font_size=15,
+ gerty_type=gerty.type,
)
)
text.append(
get_text_item_dict(
text="{0}".format(format_number(stat)),
- font_size=60,
+ font_size=80,
gerty_type=gerty.type,
)
)
- areas.append(text)
-
- text = []
+ elif stat_slug == "onchain_difficulty_epoch_time_remaining":
stat = r["remainingTime"]
text.append(
get_text_item_dict(
- text="Time until adjustment", font_size=12, gerty_type=gerty.type
+ text="Time until next difficulty adjustment",
+ font_size=15,
+ gerty_type=gerty.type,
)
)
text.append(
@@ -823,7 +751,67 @@ async def get_onchain_dashboard(gerty):
gerty_type=gerty.type,
)
)
- areas.append(text)
+ return text
+
+
+async def get_onchain_dashboard(gerty):
+ areas = []
+ if isinstance(gerty.mempool_endpoint, str):
+ text = []
+ stat = (format_number(await get_mempool_info("tip_height", gerty)),)
+ text.append(
+ get_text_item_dict(
+ text="Current block height", font_size=12, gerty_type=gerty.type
+ )
+ )
+ text.append(
+ get_text_item_dict(text=stat[0], font_size=40, gerty_type=gerty.type)
+ )
+ areas.append(text)
+
+ r = await get_mempool_info("difficulty_adjustment", gerty)
+ text = []
+ stat = round(r["progressPercent"])
+ text.append(
+ get_text_item_dict(
+ text="Progress through current epoch",
+ font_size=12,
+ gerty_type=gerty.type,
+ )
+ )
+ text.append(
+ get_text_item_dict(
+ text="{0}%".format(stat), font_size=40, gerty_type=gerty.type
+ )
+ )
+ areas.append(text)
+
+ text = []
+ stat = r["estimatedRetargetDate"]
+ dt = datetime.fromtimestamp(stat / 1000).strftime("%e %b %Y at %H:%M")
+ text.append(
+ get_text_item_dict(
+ text="Date of next adjustment", font_size=12, gerty_type=gerty.type
+ )
+ )
+ text.append(get_text_item_dict(text=dt, font_size=20, gerty_type=gerty.type))
+ areas.append(text)
+
+ text = []
+ stat = r["remainingBlocks"]
+ text.append(
+ get_text_item_dict(
+ text="Blocks until adjustment", font_size=12, gerty_type=gerty.type
+ )
+ )
+ text.append(
+ get_text_item_dict(
+ text="{0}".format(format_number(stat)),
+ font_size=40,
+ gerty_type=gerty.type,
+ )
+ )
+ areas.append(text)
return areas
@@ -944,3 +932,7 @@ async def get_mempool_stat(stat_slug: str, gerty):
)
)
return text
+
+
+def make_url_readable(url: str):
+ return url.replace("https://", "").replace("http://", "").strip("/")
diff --git a/lnbits/extensions/gerty/templates/gerty/index.html b/lnbits/extensions/gerty/templates/gerty/index.html
index 0c7155e0a..e9225bc20 100644
--- a/lnbits/extensions/gerty/templates/gerty/index.html
+++ b/lnbits/extensions/gerty/templates/gerty/index.html
@@ -59,17 +59,16 @@
>
Launch software Gerty
+
- View Gerty API
+ Gerty Settings
@@ -130,6 +129,35 @@
+
+
+ Gerty API URL
+
+ {% raw %}{{settingsDialog.apiUrl}}{% endraw %}
+ Click to Copy URL
+
+
+
+
+
+
+
+
+
@@ -157,6 +185,13 @@
val="xs"
label="Fiat to BTC price"
>
+
Hit enter to add values
@@ -300,7 +336,11 @@
)
obj.fsat = new Intl.NumberFormat(LOCALE).format(obj.amount)
obj.gerty = ['/gerty/', obj.id].join('')
- obj.gertyJson = ['/gerty/api/v1/gerty/pages/', obj.id, '/0'].join('')
+ obj.gertyJson = [
+ window.location.origin,
+ '/gerty/api/v1/gerty/pages/',
+ obj.id
+ ].join('')
return obj
}
@@ -514,6 +554,10 @@
rowsPerPage: 10
}
},
+ settingsDialog: {
+ show: false,
+ data: {}
+ },
formDialog: {
show: false,
data: {
@@ -610,6 +654,10 @@
})
})
},
+ openSettingsModal: function (apiUrl) {
+ this.settingsDialog.apiUrl = apiUrl
+ this.settingsDialog.show = true
+ },
updateformDialog: function (formId) {
var gerty = _.findWhere(this.gertys, {id: formId})
this.formDialog.data.id = gerty.id
@@ -762,29 +810,6 @@
this.formDialog.data.display_preferences.url_checker = false
}
}
- },
- toggleStates: {
- handler(toggleStatesValue) {
- // Switch all the toggles in each section to the relevant state
- for (const [toggleKey, toggleValue] of Object.entries(
- toggleStatesValue
- )) {
- if (this.oldToggleStates[toggleKey] !== toggleValue) {
- for (const [dpKey, dpValue] of Object.entries(
- this.formDialog.data.display_preferences
- )) {
- if (dpKey.indexOf(toggleKey) === 0) {
- this.formDialog.data.display_preferences[dpKey] = toggleValue
- }
- }
- }
- }
- // This is a weird hack we have to use to get VueJS to persist the previous toggle state between
- // watches. VueJS passes the old and new values by reference so when comparing objects they
- // will have the same values unless we do this
- this.oldToggleStates = JSON.parse(JSON.stringify(toggleStatesValue))
- },
- deep: true
}
}
})
From ffb5a91f6747c0150e0bafe9e322e6f20964fbd0 Mon Sep 17 00:00:00 2001
From: calle <93376500+callebtc@users.noreply.github.com>
Date: Fri, 20 Jan 2023 09:25:46 +0100
Subject: [PATCH 33/55] add robots.txt (#1383)
---
lnbits/core/views/generic.py | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lnbits/core/views/generic.py b/lnbits/core/views/generic.py
index ab19feb82..0177203b8 100644
--- a/lnbits/core/views/generic.py
+++ b/lnbits/core/views/generic.py
@@ -43,6 +43,15 @@ async def home(request: Request, lightning: str = ""):
)
+@core_html_routes.get("/robots.txt", response_class=HTMLResponse)
+async def robots():
+ data = """
+ User-agent: *
+ Disallow: /
+ """
+ return HTMLResponse(content=data, media_type="text/plain")
+
+
@core_html_routes.get(
"/extensions", name="core.extensions", response_class=HTMLResponse
)
From b13588dcef67c6bf10b87c1bb02b381081776a90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?dni=20=E2=9A=A1?=
Date: Mon, 23 Jan 2023 10:16:27 +0100
Subject: [PATCH 34/55] DOCS: improve boltz fee information (#1386)
* improve fee information an docs
* review @michael1011
Co-authored-by: ben
---
lnbits/extensions/boltz/README.md | 10 ++-
lnbits/extensions/boltz/crud.py | 1 -
.../boltz/templates/boltz/_api_docs.html | 76 ++++++++++++++++---
3 files changed, 73 insertions(+), 14 deletions(-)
diff --git a/lnbits/extensions/boltz/README.md b/lnbits/extensions/boltz/README.md
index 28289b73a..9ca38d491 100644
--- a/lnbits/extensions/boltz/README.md
+++ b/lnbits/extensions/boltz/README.md
@@ -5,11 +5,12 @@ move **IN** and **OUT** of the **lightning network** and remain in control of yo
* [Documentation](https://docs.boltz.exchange/en/latest/)
* [Discord](https://discord.gg/d6EK85KK)
* [Twitter](https://twitter.com/Boltzhq)
+* [FAQ](https://www.notion.so/Frequently-Asked-Questions-585328ae43944e2eba351050790d5eec) very cool!
# usage
This extension lets you create swaps, reverse swaps and in the case of failure refund your onchain funds.
-## create normal swap
+## create normal swap (Onchain -> Lightning)
1. click on "Swap (IN)" button to open following dialog, select a wallet, choose a proper amount in the min-max range and choose a onchain address to do your refund to if the swap fails after you already commited onchain funds.
---

@@ -22,14 +23,14 @@ This extension lets you create swaps, reverse swaps and in the case of failure r
if anything goes wrong when boltz is trying to pay your invoice, the swap will fail and you will need to refund your onchain funds after the timeout block height hit. (if boltz can pay the invoice, it wont be able to redeem your onchain funds either).
-## create reverse swap
+## create reverse swap (Lightning -> Onchain)
1. click on "Swap (OUT)" button to open following dialog, select a wallet, choose a proper amount in the min-max range and choose a onchain address to receive your funds to. Instant settlement: means that LNbits will create the onchain claim transaction if it sees the boltz lockup transaction in the mempool, but it is not confirmed yet. it is advised to leave this checked because it is faster and the longer is takes to settle, the higher the chances are that the lightning invoice expires and the swap fails.
---

---
if this swap fails, boltz is doing the onchain refunding, because they have to commit onchain funds.
-# refund locked onchain funds from a normal swap
+# refund locked onchain funds from a normal swap (Onchain -> Lightning)
if for some reason the normal swap fails and you already paid onchain, you can easily refund your btc.
this can happen if boltz is not able to pay your lightning invoice after you locked up your funds.
in case that happens, there is a info icon in the Swap (In) List which opens following dialog.
@@ -37,4 +38,5 @@ in case that happens, there is a info icon in the Swap (In) List which opens fol

----
if the timeout block height is exceeded you can either press refund and lnbits will do the refunding to the address you specified when creating the swap. Or download the refundfile so you can manually refund your onchain directly on the boltz.exchange website.
-if you think there is something wrong and/or you are unsure, you can ask for help either in LNbits telegram or in Boltz [Discord](https://discord.gg/d6EK85KK)
+if you think there is something wrong and/or you are unsure, you can ask for help either in LNbits telegram or in Boltz [Discord](https://discord.gg/d6EK85KK).
+In a recent update we made *automated check*, every 15 minutes, to check if LNbits can refund your failed swap.
diff --git a/lnbits/extensions/boltz/crud.py b/lnbits/extensions/boltz/crud.py
index 621fd3656..1c9eb700a 100644
--- a/lnbits/extensions/boltz/crud.py
+++ b/lnbits/extensions/boltz/crud.py
@@ -15,7 +15,6 @@ from .models import (
ReverseSubmarineSwap,
SubmarineSwap,
)
-from .utils import create_boltz_client, execute_reverse_swap
async def get_submarine_swaps(wallet_ids: Union[str, List[str]]) -> List[SubmarineSwap]:
diff --git a/lnbits/extensions/boltz/templates/boltz/_api_docs.html b/lnbits/extensions/boltz/templates/boltz/_api_docs.html
index bdcbc8ca2..f8474c576 100644
--- a/lnbits/extensions/boltz/templates/boltz/_api_docs.html
+++ b/lnbits/extensions/boltz/templates/boltz/_api_docs.html
@@ -6,30 +6,88 @@
style="padding: 5px 9px"
alt=""
/>
+ NON CUSTODIAL atomic swap service
- Boltz.exchange: Do onchain to offchain and vice-versa swaps
+ Providing trustless and account-free swap services since 2018. Move IN and
+ OUT of the lightning network and remain in control of your bitcoin, at all
+ time.
- Submarine and Reverse Submarine Swaps on LNbits via boltz.exchange API
-
-
- Link :
+ Link:
https://boltz.exchange
-
-
+
+ README:
More detailsread more
Created by,
+ >Extension created by,
dni
+
+
+
+ Fee Information
+
+
+ Every swap consists of 2 onchain transactions, lockup and claim / refund,
+ routing fees and a Boltz fee of 0.5%.
+
+
+
+
+ You want to swap out 100.000 sats, Lightning to Onchain:
+
+ - Onchain lockup tx fee: ~500 sats
+ - Onchain claim tx fee: 1000 sats (hardcoded)
+ - Routing fees (paid by you): unknown
+ - Boltz fees: 500 sats
+ - Fees total: 2000 sats + routing fees
+ - You receive: 98.000 sats
+
+
+ onchain_amount_received = amount - (amount * boltz_fee / 100) -
+ lockup_fee - claim_fee
+
+ 98.000 = 100.000 - 500 - 500 - 1000
+
+
+
+
+ You want to swap in 100.000 sats, Onchain to Lightning:
+
+ - Onchain lockup tx fee: whatever you choose when paying
+ - Onchain claim tx fee: ~500 sats
+ - Routing fees (paid by boltz): unknown
+ - Boltz fees: 500 sats (0.5%)
+ - Fees total: 1000 sats + lockup_fee
+ - You pay onchain: 101.000 sats + lockup_fee
+ - You receive lightning: 100.000 sats
+
+
+ onchain_payment + lockup_fee = amount + (amount * boltz_fee / 100) +
+ claim_fee + lockup_fee
+
+ 101.000 + lockup_fee = 100.000 + 500 + 500 + lockup_fee
+
+
+
From ca51b57355ba27aa4807be297461996dc168084a Mon Sep 17 00:00:00 2001
From: DarthCoin <56997124+Darth-Coin@users.noreply.github.com>
Date: Mon, 23 Jan 2023 10:16:54 +0100
Subject: [PATCH 35/55] Faq page (#1388)
* Cleanup formatting
Re-format text in markdown and cleanup extra code.
* small fixes
* Update faq.md
* Update faq.md
* Update faq.md
* small correction
corrected summary open
* correction sections
* add how to connect lndhub wallet
Add info about connecting Zeus and Bluewallet
* finishing 2 sections
add text to funding section and clearnet
* add text to swap and merchant
* group sections
re-organize sections of troubleshooting with did you know. Are practically the same
* small corrections
links corrections
* format sections
* fix link resources
* small corrections
* small corrections
* small correction
* Update faq.md
* Create faq.md
* Update faq.md
* Update faq.md
* Update faq.md
* Update faq.md
* small correction
Co-authored-by: arbadacarba <63317640+arbadacarbaYK@users.noreply.github.com>
---
docs/guide/faq.md | 431 +++++++++++++++++++++++++---------------------
1 file changed, 234 insertions(+), 197 deletions(-)
diff --git a/docs/guide/faq.md b/docs/guide/faq.md
index 8f9b74323..1ccf3e289 100644
--- a/docs/guide/faq.md
+++ b/docs/guide/faq.md
@@ -1,231 +1,268 @@
-------
+---
layout: default
title: FAQ
nav_order: 5
---
+# FAQ - Frequently Asked Questions
-FAQ - Frequently Asked Questions on LNbits
-==========================================
+## Install options
+LNbits is not a node management software but a ā”ļøLN only accounting system on top of a funding source.
-Install options
-
- LNbits is not a node management software but a lightning only accounting system on top of a funding source.
+Funding my LNbits wallet from my node it doesn't work.
+If you want to send sats from the same node that is the funding source of your LNbits, you will need to edit the lnd.conf file. The parameters to be included are:
+
+```
+allow-circular-route=1
+allow-self-payment=1
+```
+
+
-Funding my LNbits wallet from my node doesnt work.
-You will need to edit the lnd.conf file for this. The parameter to be included are allow-circular-route=1 respectively allow_self_payment=1.
-
-
-
-Funding source only available via tor (Umbrel, Citadel, ..)
-
-
+Funding source only available via tor (e.g. Umbrel)
+ If you want your setup to stay behind tor then only apps, pos and wallets that have tor activated can communicate with your wallets. Most likely you will have trouble when people try to redeem your voucher through onion or when importing your lnbits wallets into a wallet-app that doesnt support tor. If you plan to let LNbits wallets interact with plain internet shops and services you should consider setting up hybrid mode for your node.
+
Funding source is in a cloud
-
-
+ This means that you might not have access to some files which would allow certain administrative functions. E.g. on Voltage lnd.conf can not be edited. Payments from your node to LNbits wallets can therefore not be configurated in this case atm so you will need to take an extra wallet to send from funding source->wallet x->LNbits wallet (only) for the initial funding of the wallet.
+
LNbits via clearnet domain
-
+ Step by step guide how to convert your Tor only node into a clearnet node to make apps like LNbits accessible via https.
-Other funding sources (e.g bots)
-
+Which funding sources can I use for LNbits?
+ There are several ways to run a LNbits instance funded from different sources. It is importan to choose a source that has a good liquidity and good peers connected. If you use LNbits for public services your usersĀ“ payments can then flow happily in both directions. If you would like to fund your LNbits wallet via btc please see section Troubleshooting.
+ The LNbits manual shows you which sources can be used and how to configure each: CLN, LND, LNPay, Cliche, OpenNode as well as bots.
+
-
-
-Troubleshooting
-
+ - Configure allowed users & extensions in the .env file
+ - Configure allowed users & extensions via the Usermanager-Extension. You can find more info about the superuser and the admin extension here
+
+ Please note that all entries in the .env file will not be the taken into account once you activated the admin extension.
+
+
- Wallet-URL deleted, are funds safu ?
+## Troubleshooting
+
-
-
-
-
-
-
-Building hardware tools
-
- LNbits has all sorts of open APIs and tools to program and connect to a lot of different devices for several use-cases. Let us know what you did with it ! Come to the Makerbits Telegram Group if you are interested in building with LNbits or if you need help with a projekt - we got you!
-
-
- ATM - deposit and withdraw in your shop or at your meetup
-
-
-
-POS Terminal - an offline terminal for merchants
-
-
-
-Hardware Wallet- build your own, stack harder
-
-
-
-Bitcoin Switch - turn things on with bitcoin
-
-
-
-Vending machine (offline)
-
-
-
- Ressources
-
-
-
-
Use cases of LNbits
-
-Merchant
-
+ -
+
Wallet on demo server legend.lnbits
+ Always save a copy of your wallet-URL, Export2phone-QR or LNDhub for your own wallets in a safe place. LNbits CANNOT help you to recover them when lost.
+
+
+ -
+
Wallet on your own funding source/node
+ Always save a copy of your wallet-URL, Export2phone-QR or LNDhub for your own wallets in a safe place.
+ You can find all LNbits users and wallet-IDs in your LNbits user manager extension or in your sqlite database.
+ To edit or read the LNbits database, go to the LNbits /data folder and look for the file called sqlite.db.
+ You can open and edit it with excel or with a dedicated SQL-Editor like SQLite browser.
+
+
+
-Voucher
-
-
-
-
-NFC Cards, Badges, Rings etc.
-
- Printed voucher links or tippingcards
-To write cards you will need LNbits to be available in clearnet. Please consider running your own LNbits instance for this.
-
-LNURLw are strings that represent a faucet-link to a wallet. By scanning it, everyone will be able to withdraw sats from it. A LNURLw can be either a QR that leads to a static link or to one that responds with new invoices every time it is scanned (click "no assmilking"). You can create these QR by adding the LNURLw extension and generate the vouchertype you need.
- - Voucher can as well be printed directly from LNbits. After you created it, click the "eye" next to the link. By pressing the printer-button you print the plain QR but you could as well integrate it into a nice tippincard or voucher template by choosing "Advanced voucher" -> "Use custom voucher design". We collected some designs as well as templates to make your own ones under this LNbits voucher video-guide.. You will be able to create and print as much voucher as you like with it. Happy orangepilling!
- - Note that your LNbits needs to be reachable in clearnet to offer vouchers to others.
-
-
- Creating a NFC card for a wallet
- To write cards you will need LNbits to be available in clearnet. Please consider running your own LNbits instance for this.
- - On top to just printing voucher for your wallet you can also write these LNURLw to a simple NFC card fromon NTAG216 by not clicking the printer but the NFC symbol on android/chrome and tapping your card against the device. This will enable the cardholder to directly spend those sats at a tpos, pos or wallet-app another one uses that can handle lightning payments via NFC.
- - If you run an event and want to hand out bigger amounts of cards with simple voucher links on consider this NFC-brrr batch tool as well as using NTAG424 cards, so that your customers can rewrite them later with an own wallet and the boltcard service (see ff)
-- For bigger amounts the Boltcard-Extension should be used. It will generate a link that sends a new invoice every time it is used for payments and keeps track too if the allowed card-ID is redeeming funds. Hence the setup of Boltcards is a bit safer but it needs some additional tools. You can find further infos on creating or updating boltcards here.
-
-
-
- Ressources
-
-
-
-
-
-Developing for LNbits
-
-
-
-
-
-Did you know?
-
-Where can I see payment details?
-
-When you receive a payment in Lnbits, the transaction log will display only a resumed type of the transaction. Like this:
-
-
-
-As you can see on the left side, there's a little green arrow for receiveing or red arrow for sending.
-If you click on that arrow, will popup a screen with more details about the transaction, including the message and the name attached to the payment.
-
-
-If the sender's LN wallet support LUD-18 (nameDesc) will also insert an alias/pseudonym preceeding the comment. This is optional and only if the sender want to send that name. It can be any name and not related to real names.
-
-
-
-
-
-
-Can I receive a comment/message to my LNURL-p QR?
-
-When you create a LNURL-p, by default the comment box is not filled. That means comments are not allowed to be attached to payments.
-In order to allow comments, add the characters lenght of the box, from 1 to 250. Once you put a number there, the comment box will be displayed in the payment process. You can also edit a LNURL-p already created and add that number.
+Configure a comment that people see when paying to my LNURLp QR
+ When you create a LNURL-p, by default the comment box is not filled. That means comments are not allowed to be attached to payments.
+
In order to allow comments, add the characters lenght of the box, from 1 to 250. Once you put a number there,
+ the comment box will be displayed in the payment process. You can also edit a LNURL-p already created and add that number.

-
-Can i deposit onchain btc to LNbits ?
-There are multiple ways to exchange sats from onchain btc to LN btc (resp. to LNbits).
-A - Via a swap service like Boltz, FixedFloat, DiamondHands or ZigZag.
-This is useful if you provide only LNURL/LN invoices from your LNbits instance, but a payer only has onchain sats so
- they will have to the swap those sats first on their side.
-The procedure is simple: user sends onchain btc to the swap service and provides the LNURL / LN invoice from LNbits as destination of the swap.
-B - Using the Onchain LNbits extension
-Keep in mind that this is a separate wallet, not the LN btc one that is represented by LNbits as "your wallet" upon your LN funding source. This onchain wallet can be used also to swap LN btc to (e.g. your hardwarewallet) by using the LNbits Boltz or Deezy extension. If you run a webshop that is linked to your LNbits for LN payments, it is very handy to regularily drain all the sats from LN into onchain. This leads to more space in your LN channels to be able to receive new fresh sats.
-Procedure
-
-- Use Electrum or Sparrow wallet to create a new onchain wallet and save the backup seed in a safe place
-- Go to wallet information and copy the xpub
-- Go to LNbits - Onchain extension and create a new watch-only wallet with that xpub
-- Go to LNbits - Tipjar extension and create a new Tipjar. Select also the onchain option besides the LN wallet.
-- Optional - Go to LNbits - SatsPay extension and create a new charge for onchain btc. You can choose between onchain and LN or both. It will then create an invoice that can be shared.
-- Optional - If you use your LNbits linked to a Wordpress + Woocommerce page, once you create/link a watch-only wallet to your LN btc shop wallet, the customer will have both options to pay on the same screen.
+Can I deposit onchain BTC to LNbits ?
+ There are multiple ways to exchange sats from onchain btc to LN btc (resp. to LNbits).
+
+ -
+
A - Via an external swap service
+ If the user do not have full acceess of your LNbits, is just an external user, can use swap services like Boltz, FixedFloat, DiamondHands or ZigZag.
+ This is useful if you provide only LNURL/LN invoices from your LNbits instance, but a payer only has onchain sats so
+ they will have to the swap those sats first on their side.
+ The procedure is simple: user sends onchain btc to the swap service and provides the LNURL / LN invoice from LNbits as destination of the swap.
+
+
+ -
+
B - Using the Onchain LNbits extension
+ Keep in mind that this is a separate wallet, not the LN btc one that is represented by LNbits as "your wallet" upon your LN funding source.
+ This onchain wallet can be used also to swap LN btc to (e.g. your hardwarewallet) by using the LNbits Boltz or Deezy extension.
+ If you run a webshop that is linked to your LNbits for LN payments, it is very handy to regularily drain all the sats from LN into onchain.
+ This leads to more space in your LN channels to be able to receive new fresh sats.
+ Procedure:
+
+ - Use Electrum or Sparrow wallet to create a new onchain wallet and save the backup seed in a safe place
+ - Go to wallet information and copy the xpub
+ - Go to LNbits - Onchain extension and create a new watch-only wallet with that xpub
+ - Go to LNbits - Tipjar extension and create a new Tipjar. Select also the onchain option besides the LN wallet.
+ - Optional - Go to LNbits - SatsPay extension and create a new charge for onchain btc.
+ You can choose between onchain and LN or both. It will then create an invoice that can be shared.
+ - Optional - If you use your LNbits linked to a Wordpress + Woocommerce page, once you create/link a watch-only wallet to your LN btc shop wallet,
+ the customer will have both options to pay on the same screen.
+
+
+
+
+
+
+Where can I see payment details?
+ When you receive a payment in LNbits, the transaction log will display only a resumed type of the transaction.
+
+
+
+
In your transaction overview you will find a little green arrow for received and a red arrow for sended funds.
+
If you click on those arrows, a details popup shows attached messages as well as the senderĀ“s name if given.
+
+
+ Can I configure a name to the payments i make?
+ In LNbits this is currently not possible to do - but to receive. This is only possible if the sender's LN wallet supports LUD-18 (nameDesc) like e.g. Open Bitcion Wallet - OBW does. You will then see an alias/pseudonym in the details section of your LNbits transactions (click the arrows). Note that you can give any name there and it might not be related to the real senderĀ“s name(!) if your receive such.
+
+
+
+
+
+How can I use a LNbits lndhub account in other wallet apps?
+ Open your LNbits with the account / wallet you want to use, go to "manage extensions" and activate the LNDHUB extension.
+ Then open the LNDHUB extension, choose the wallet you want to use and scan the QR code you want to use: "admin" or "invoice only", depending on the security level you want for that wallet.
+ You can use Zeus or Bluewallet as wallet apps for a lndhub account.
+ Keep in mind: if your LNbits instance is Tor only, you must use also theose apps behind Tor and open the LNbits page through your Tor .onion address.
+
+
+## Building hardware tools
+ LNbits has all sorts of open APIs and tools to program and connect to a lot of different devices for a gazillion of use-cases. Let us know what you did with it ! Come to the Makerbits Telegram Group if you are interested in building or if you need help with a project - we got you!
+
+ATM - deposit and withdraw in your shop or at your meetup
+ This is a do-it-yourself project consisting of a mini-computer (Raspberry Pi Zero), a coin acceptor, a display, a 3D printed case, and a Bitcoin Lightning wallet as a funding source. It exchanges fiat coins for valuable Bitcoin Lightning ā” Satoshis. The user can pick up the Satoshis via QR code (LNURL-withdraw) on a mobile phone wallet. It works based on BTCPayer server, LNTXBOT is not longer an option. You can get the components as individual parts and build the case yourself e.g. from Fulmo who also made a guide on it. The shop offers payments in Bitcoin and Lightning ā”. The code can be found on the ATM github project page>.
+
+
+POS Terminal - an offline terminal for merchants
+ The LNpos is a self-sufficient point of sale terminal which allows offline onchain payments and an offline Lightning ATM for withdrawals. Free and open source software, free from intermediaries, with integrated battery, WLAN, DIY. You can get the 3D print as well as the whole kit from the LNbits shop from š Ressources. It allows
+
- LNPoS Online interactive Lightning payments
+ - LNURLPoS Offline Lightning Payments. Passive interaction, sharing a secret as evidence
+ - OnChain For onchain payments. Generates an address and displays a link for verification
+ - LNURLATM Offline Lightning Payouts. Generates LNURLw link to do withdrawals
+
+
+
+
+
+
+Hardware Wallet- build your own, stack harder
+The hardwarewallet is a very cheap solution for builders. The projectsĀ“ code and installation instructions for the LNbits hardware wallet can be found on github
+
+
+
+
+
+Bitcoin Switch - turn things on with bitcoin
+ Candy dispenser, vending machines (online), grabbing machines, jukeboxes, bandits and all sorts of other things have already been build with LNbitsĀ“ tools. Further info see š Ressources.
+
+
+
+
+
+Vending machine (offline)
+This code works similar to the LNpos. Note that the setup-video for the vending machine misses the new way of installing it via the new LNURLdevices extension. The vending machine project code resides on github.
+
+
+
+
+
+Resources - Building hardware tools
+
+
+
+
+## Use cases of LNbits
+Merchant
+ LNbits is a powerful solution for merchants, due to the easy setup with various extensions, that can be used for many scenarios.
+ Here is an overview of the LNbits tools available for a small restaurant as well as a hotel
+
+
+Swapping ā”ļøLN BTC to a BTC address
+ LNbits has two swap extensions integrated: Boltz and Deezy.
+ For a merchant that uses LNbits to receive BTC payments through LN, this is very handy to move the received sats from LN channels into onchain wallets. It not only helps you HODLing but is also freeing up "space in your channels" so you are ready to receive more sats.
+ Boltz has an option to setup an automated swap triggered by a certain amount received.
+
+
+Voucher
+ Printed voucher links or tippingcards
+ To generate voucher you will need LNbits to be available in clearnet. Please consider running your own LNbits instance for this.
+ LNURLw are strings that represent a faucet-link to a wallet. By scanning it, everyone will be able to withdraw sats from it. A LNURLw can be either a QR that leads to a static link or to one that responds with new invoices every time it is scanned (click "no assmilking"). You can create these QR by adding the LNURLw extension and generate the vouchertype you need.
+
+ - Voucher can as well be printed directly from LNbits. After you created it, click the "eye" next to the link. By pressing the printer-button you print the plain QR but you could as well integrate it into a nice tippincard or voucher template by choosing "Advanced voucher" -> "Use custom voucher design". We collected some designs as well as templates to make your own ones under this LNbits voucher video-guide.. You will be able to create and print as much voucher as you like with it. Happy orangepilling!
+ - Note that your LNbits needs to be reachable in clearnet to offer vouchers to others.
+
+NFC Cards, Badges, Rings etc.
+ Creating a NFC card for a wallet
+ To generate links for your cards you will need LNbits to be available in clearnet. Please consider running your own LNbits instance for this.
+
+ - On top to just printing voucher for your wallet you can also write these LNURLw to a simple NFC card fromon NTAG216 by not clicking the printer but the NFC symbol on android/chrome and tapping your card against the device. This will enable the cardholder to directly spend those sats at a tpos, pos or wallet-app another one uses that can handle lightning payments via NFC.
+ - If you run an event and want to hand out bigger amounts of cards with simple voucher links on consider this NFC-brrr batch tool as well as using NTAG424 cards, so that your customers can rewrite them later with an own wallet and the boltcard service (see ff)
+ - For bigger amounts the Boltcard-Extension should be used. It will generate a link that sends a new invoice every time it is used for payments and keeps track too if the allowed card-ID is redeeming funds. Hence the setup of Boltcards is a bit safer but it needs some additional tools. You can find further infos on creating or updating boltcards here.
+
+
Resources - NFC & LNbits
+
+
+
+
+
+
+
+
+## Developing for LNbits
+
+
From d30a6dc5c15fe62d417d1c9d571dcdcd79152b78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?dni=20=E2=9A=A1?=
Date: Mon, 23 Jan 2023 10:17:16 +0100
Subject: [PATCH 36/55] fix jukebox issues introduced from mypy pr (#1387)
* fix jukebox issues introduced from mypy pr
* fix no invoice
Co-authored-by: ben
---
lnbits/extensions/jukebox/crud.py | 4 ++--
lnbits/extensions/jukebox/models.py | 15 ++++++++-------
lnbits/extensions/jukebox/views.py | 2 ++
lnbits/extensions/jukebox/views_api.py | 8 ++++++++
4 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/lnbits/extensions/jukebox/crud.py b/lnbits/extensions/jukebox/crud.py
index 9d6548b6e..fe710f601 100644
--- a/lnbits/extensions/jukebox/crud.py
+++ b/lnbits/extensions/jukebox/crud.py
@@ -77,7 +77,7 @@ async def delete_jukebox(juke_id: str):
#####################################PAYMENTS
-async def create_jukebox_payment(data: CreateJukeboxPayment) -> JukeboxPayment:
+async def create_jukebox_payment(data: CreateJukeboxPayment) -> CreateJukeboxPayment:
await db.execute(
"""
INSERT INTO jukebox.jukebox_payment (payment_hash, juke_id, song_id, paid)
@@ -87,7 +87,7 @@ async def create_jukebox_payment(data: CreateJukeboxPayment) -> JukeboxPayment:
)
jukebox_payment = await get_jukebox_payment(data.payment_hash)
assert jukebox_payment, "Newly created Jukebox Payment couldn't be retrieved"
- return jukebox_payment
+ return data
async def update_jukebox_payment(
diff --git a/lnbits/extensions/jukebox/models.py b/lnbits/extensions/jukebox/models.py
index 70cf65230..507504f42 100644
--- a/lnbits/extensions/jukebox/models.py
+++ b/lnbits/extensions/jukebox/models.py
@@ -1,6 +1,7 @@
-from fastapi.param_functions import Query
+from typing import Optional
+
+from fastapi import Query
from pydantic import BaseModel
-from pydantic.main import BaseModel
class CreateJukeLinkData(BaseModel):
@@ -21,13 +22,13 @@ class Jukebox(BaseModel):
user: str
title: str
wallet: str
- inkey: str
+ inkey: Optional[str]
sp_user: str
sp_secret: str
- sp_access_token: str
- sp_refresh_token: str
- sp_device: str
- sp_playlists: str
+ sp_access_token: Optional[str]
+ sp_refresh_token: Optional[str]
+ sp_device: Optional[str]
+ sp_playlists: Optional[str]
price: int
profit: int
diff --git a/lnbits/extensions/jukebox/views.py b/lnbits/extensions/jukebox/views.py
index 2220da08a..e1c55449e 100644
--- a/lnbits/extensions/jukebox/views.py
+++ b/lnbits/extensions/jukebox/views.py
@@ -31,6 +31,8 @@ async def connect_to_jukebox(request: Request, juke_id):
)
devices = await api_get_jukebox_device_check(juke_id)
deviceConnected = False
+ assert jukebox.sp_device
+ assert jukebox.sp_playlists
for device in devices["devices"]:
if device["id"] == jukebox.sp_device.split("-")[1]:
deviceConnected = True
diff --git a/lnbits/extensions/jukebox/views_api.py b/lnbits/extensions/jukebox/views_api.py
index 1847ca50d..0cca8fc85 100644
--- a/lnbits/extensions/jukebox/views_api.py
+++ b/lnbits/extensions/jukebox/views_api.py
@@ -114,6 +114,7 @@ async def api_get_jukebox_song(
tracks = []
async with httpx.AsyncClient() as client:
try:
+ assert jukebox.sp_access_token
r = await client.get(
"https://api.spotify.com/v1/playlists/" + sp_playlist + "/tracks",
timeout=40,
@@ -194,6 +195,7 @@ async def api_get_jukebox_device_check(
if not jukebox:
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="No Jukeboxes")
async with httpx.AsyncClient() as client:
+ assert jukebox.sp_access_token
rDevice = await client.get(
"https://api.spotify.com/v1/me/player/devices",
timeout=40,
@@ -229,6 +231,7 @@ async def api_get_jukebox_invoice(juke_id, song_id):
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="No jukebox")
try:
+ assert jukebox.sp_device
devices = await api_get_jukebox_device_check(juke_id)
deviceConnected = False
for device in devices["devices"]:
@@ -291,6 +294,7 @@ async def api_get_jukebox_invoice_paid(
jukebox_payment = await get_jukebox_payment(pay_hash)
if jukebox_payment and jukebox_payment.paid:
async with httpx.AsyncClient() as client:
+ assert jukebox.sp_access_token
r = await client.get(
"https://api.spotify.com/v1/me/player/currently-playing?market=ES",
timeout=40,
@@ -308,6 +312,7 @@ async def api_get_jukebox_invoice_paid(
if r.status_code == 204 or isPlaying == False:
async with httpx.AsyncClient() as client:
uri = ["spotify:track:" + song_id]
+ assert jukebox.sp_device
r = await client.put(
"https://api.spotify.com/v1/me/player/play?device_id="
+ jukebox.sp_device.split("-")[1],
@@ -339,6 +344,8 @@ async def api_get_jukebox_invoice_paid(
)
elif r.status_code == 200:
async with httpx.AsyncClient() as client:
+ assert jukebox.sp_access_token
+ assert jukebox.sp_device
r = await client.post(
"https://api.spotify.com/v1/me/player/queue?uri=spotify%3Atrack%3A"
+ song_id
@@ -399,6 +406,7 @@ async def api_get_jukebox_currently(
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="No jukebox")
async with httpx.AsyncClient() as client:
try:
+ assert jukebox.sp_access_token
r = await client.get(
"https://api.spotify.com/v1/me/player/currently-playing?market=ES",
timeout=40,
From 9693e5932b2d3923878820bdea01df98ec23f29a Mon Sep 17 00:00:00 2001
From: Titusz
Date: Mon, 23 Jan 2023 10:27:19 +0100
Subject: [PATCH 37/55] Track fiat amount in TPoS invoices. (#1384)
---
lnbits/extensions/tpos/templates/tpos/tpos.html | 1 +
lnbits/extensions/tpos/views_api.py | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html
index bf97bf2b6..438fc22ea 100644
--- a/lnbits/extensions/tpos/templates/tpos/tpos.html
+++ b/lnbits/extensions/tpos/templates/tpos/tpos.html
@@ -500,6 +500,7 @@
.post('/tpos/api/v1/tposs/' + this.tposId + '/invoices', null, {
params: {
amount: this.sat,
+ memo: this.amountFormatted,
tipAmount: this.tipAmountSat
}
})
diff --git a/lnbits/extensions/tpos/views_api.py b/lnbits/extensions/tpos/views_api.py
index ada54b3f9..1be1428d9 100644
--- a/lnbits/extensions/tpos/views_api.py
+++ b/lnbits/extensions/tpos/views_api.py
@@ -58,7 +58,7 @@ async def api_tpos_delete(
@tpos_ext.post("/api/v1/tposs/{tpos_id}/invoices", status_code=HTTPStatus.CREATED)
async def api_tpos_create_invoice(
- tpos_id: str, amount: int = Query(..., ge=1), tipAmount: int = 0
+ tpos_id: str, amount: int = Query(..., ge=1), memo: str = "", tipAmount: int = 0
) -> dict:
tpos = await get_tpos(tpos_id)
@@ -75,7 +75,7 @@ async def api_tpos_create_invoice(
payment_hash, payment_request = await create_invoice(
wallet_id=tpos.wallet,
amount=amount,
- memo=f"{tpos.name}",
+ memo=f"{memo} to {tpos.name}" if memo else f"{tpos.name}",
extra={
"tag": "tpos",
"tipAmount": tipAmount,
From a0891886648c96fefb7e45327712b44da15fab24 Mon Sep 17 00:00:00 2001
From: Pavol Rusnak
Date: Mon, 23 Jan 2023 09:29:17 +0000
Subject: [PATCH 38/55] add pyright to the project (#1367)
* add pyright to project + bump prettier to latest
* reformat to match the latest prettier rules
---
Makefile | 3 ++
.../copilot/templates/copilot/compose.html | 5 +--
.../gerty/templates/gerty/gerty.html | 20 ++++------
.../gerty/templates/gerty/index.html | 4 +-
lnbits/extensions/jukebox/static/js/index.js | 3 +-
.../templates/lnurldevice/index.html | 11 +++---
.../market/templates/market/index.html | 5 +--
.../satspay/templates/satspay/index.html | 3 +-
.../extensions/smtp/templates/smtp/index.html | 11 +++---
.../templates/subdomains/index.html | 5 +--
.../components/wallet-list/wallet-list.js | 11 +++---
package-lock.json | 39 +++++++++++++++----
package.json | 3 +-
pyproject.toml | 8 ++++
14 files changed, 82 insertions(+), 49 deletions(-)
diff --git a/Makefile b/Makefile
index ebf2a8729..22d79f113 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,9 @@ check: mypy checkprettier checkisort checkblack
prettier: $(shell find lnbits -name "*.js" -o -name ".html")
./node_modules/.bin/prettier --write lnbits/static/js/*.js lnbits/core/static/js/*.js lnbits/extensions/*/templates/*/*.html ./lnbits/core/templates/core/*.html lnbits/templates/*.html lnbits/extensions/*/static/js/*.js lnbits/extensions/*/static/components/*/*.js lnbits/extensions/*/static/components/*/*.html
+pyright:
+ ./node_modules/.bin/pyright
+
black:
poetry run black .
diff --git a/lnbits/extensions/copilot/templates/copilot/compose.html b/lnbits/extensions/copilot/templates/copilot/compose.html
index 41745f0a4..2ec4c4f72 100644
--- a/lnbits/extensions/copilot/templates/copilot/compose.html
+++ b/lnbits/extensions/copilot/templates/copilot/compose.html
@@ -108,9 +108,8 @@
},
methods: {
showNotif: function (userMessage) {
- var colour = this.colours[
- Math.floor(Math.random() * this.colours.length)
- ]
+ var colour =
+ this.colours[Math.floor(Math.random() * this.colours.length)]
this.$q.notify({
color: colour,
icon: 'chat_bubble_outline',
diff --git a/lnbits/extensions/gerty/templates/gerty/gerty.html b/lnbits/extensions/gerty/templates/gerty/gerty.html
index 899942c1e..48122c998 100644
--- a/lnbits/extensions/gerty/templates/gerty/gerty.html
+++ b/lnbits/extensions/gerty/templates/gerty/gerty.html
@@ -224,21 +224,17 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %}
this.gertyname = this.gerty[i].settings.name
}
if (this.gerty[i].screen.group == 'fun_satoshi_quotes') {
- this.fun_satoshi_quotes['quote'] = this.gerty[
- i
- ].screen.areas[0][0].value
- this.fun_satoshi_quotes['date'] = this.gerty[
- i
- ].screen.areas[0][1].value
+ this.fun_satoshi_quotes['quote'] =
+ this.gerty[i].screen.areas[0][0].value
+ this.fun_satoshi_quotes['date'] =
+ this.gerty[i].screen.areas[0][1].value
this.gertyname = this.gerty[i].settings.name
}
if (this.gerty[i].screen.group == 'fun_exchange_market_rate') {
- this.fun_exchange_market_rate['unit'] = this.gerty[
- i
- ].screen.areas[0][0].value
- this.fun_exchange_market_rate['amount'] = this.gerty[
- i
- ].screen.areas[0][1].value
+ this.fun_exchange_market_rate['unit'] =
+ this.gerty[i].screen.areas[0][0].value
+ this.fun_exchange_market_rate['amount'] =
+ this.gerty[i].screen.areas[0][1].value
this.gertyname = this.gerty[i].settings.name
}
}
diff --git a/lnbits/extensions/gerty/templates/gerty/index.html b/lnbits/extensions/gerty/templates/gerty/index.html
index e9225bc20..b5eb42215 100644
--- a/lnbits/extensions/gerty/templates/gerty/index.html
+++ b/lnbits/extensions/gerty/templates/gerty/index.html
@@ -616,8 +616,8 @@
self.toggleStates.onchain
self.formDialog.data.display_preferences.onchain_difficulty_retarget_date =
self.toggleStates.onchain
- self.formDialog.data.display_preferences.onchain_difficulty_blocks_remaining = !self
- .toggleStates.onchain
+ self.formDialog.data.display_preferences.onchain_difficulty_blocks_remaining =
+ !self.toggleStates.onchain
self.formDialog.data.display_preferences.onchain_difficulty_epoch_time_remaining =
self.toggleStates.onchain
self.formDialog.data.display_preferences.onchain_block_height =
diff --git a/lnbits/extensions/jukebox/static/js/index.js b/lnbits/extensions/jukebox/static/js/index.js
index fe724450a..1241b80e0 100644
--- a/lnbits/extensions/jukebox/static/js/index.js
+++ b/lnbits/extensions/jukebox/static/js/index.js
@@ -255,7 +255,8 @@ new Vue({
},
createJukebox() {
self = this
- self.jukeboxDialog.data.sp_playlists = self.jukeboxDialog.data.sp_playlists.join()
+ self.jukeboxDialog.data.sp_playlists =
+ self.jukeboxDialog.data.sp_playlists.join()
self.updateDB()
self.jukeboxDialog.show = false
self.getJukeboxes()
diff --git a/lnbits/extensions/lnurldevice/templates/lnurldevice/index.html b/lnbits/extensions/lnurldevice/templates/lnurldevice/index.html
index 118183018..f308cc652 100644
--- a/lnbits/extensions/lnurldevice/templates/lnurldevice/index.html
+++ b/lnbits/extensions/lnurldevice/templates/lnurldevice/index.html
@@ -807,11 +807,12 @@
updatedData
)
.then(function (response) {
- self.lnurldeviceLinks = _.reject(self.lnurldeviceLinks, function (
- obj
- ) {
- return obj.id === updatedData.id
- })
+ self.lnurldeviceLinks = _.reject(
+ self.lnurldeviceLinks,
+ function (obj) {
+ return obj.id === updatedData.id
+ }
+ )
self.lnurldeviceLinks.push(maplnurldevice(response.data))
self.formDialoglnurldevice.show = false
self.clearFormDialoglnurldevice()
diff --git a/lnbits/extensions/market/templates/market/index.html b/lnbits/extensions/market/templates/market/index.html
index 77e3acced..0f8fa78bb 100644
--- a/lnbits/extensions/market/templates/market/index.html
+++ b/lnbits/extensions/market/templates/market/index.html
@@ -803,9 +803,8 @@
self.productDialog.data = _.clone(link._data)
if (self.productDialog.data.categories) {
- self.productDialog.data.categories = self.productDialog.data.categories.split(
- ','
- )
+ self.productDialog.data.categories =
+ self.productDialog.data.categories.split(',')
}
if (self.productDialog.data.image.startsWith('data:')) {
self.productDialog.url = false
diff --git a/lnbits/extensions/satspay/templates/satspay/index.html b/lnbits/extensions/satspay/templates/satspay/index.html
index 5a1c62f4d..74b3d2ccc 100644
--- a/lnbits/extensions/satspay/templates/satspay/index.html
+++ b/lnbits/extensions/satspay/templates/satspay/index.html
@@ -809,7 +809,8 @@
this.createTheme(wallet, data)
},
sendFormDataCharge: function () {
- this.formDialogCharge.data.custom_css = this.formDialogCharge.data.custom_css?.id
+ this.formDialogCharge.data.custom_css =
+ this.formDialogCharge.data.custom_css?.id
const data = this.formDialogCharge.data
const wallet = this.g.user.wallets[0].inkey
data.amount = parseInt(data.amount)
diff --git a/lnbits/extensions/smtp/templates/smtp/index.html b/lnbits/extensions/smtp/templates/smtp/index.html
index c64cdcfa2..4b00cd082 100644
--- a/lnbits/extensions/smtp/templates/smtp/index.html
+++ b/lnbits/extensions/smtp/templates/smtp/index.html
@@ -574,11 +574,12 @@
.inkey
)
.then(function (response) {
- self.emailaddresses = _.reject(self.emailaddresses, function (
- obj
- ) {
- return obj.id == emailaddressId
- })
+ self.emailaddresses = _.reject(
+ self.emailaddresses,
+ function (obj) {
+ return obj.id == emailaddressId
+ }
+ )
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
diff --git a/lnbits/extensions/subdomains/templates/subdomains/index.html b/lnbits/extensions/subdomains/templates/subdomains/index.html
index e8d8ec57d..a39773e71 100644
--- a/lnbits/extensions/subdomains/templates/subdomains/index.html
+++ b/lnbits/extensions/subdomains/templates/subdomains/index.html
@@ -484,9 +484,8 @@
var link = _.findWhere(this.domains, {id: formId})
console.log(link.id)
this.domainDialog.data = _.clone(link)
- this.domainDialog.data.allowed_record_types = link.allowed_record_types.split(
- ', '
- )
+ this.domainDialog.data.allowed_record_types =
+ link.allowed_record_types.split(', ')
this.domainDialog.show = true
},
updateDomain: function (wallet, data) {
diff --git a/lnbits/extensions/watchonly/static/components/wallet-list/wallet-list.js b/lnbits/extensions/watchonly/static/components/wallet-list/wallet-list.js
index 004f092ba..27d40ce97 100644
--- a/lnbits/extensions/watchonly/static/components/wallet-list/wallet-list.js
+++ b/lnbits/extensions/watchonly/static/components/wallet-list/wallet-list.js
@@ -174,11 +174,12 @@ async function walletList(path) {
'/watchonly/api/v1/wallet/' + walletAccountId,
this.adminkey
)
- this.walletAccounts = _.reject(this.walletAccounts, function (
- obj
- ) {
- return obj.id === walletAccountId
- })
+ this.walletAccounts = _.reject(
+ this.walletAccounts,
+ function (obj) {
+ return obj.id === walletAccountId
+ }
+ )
await this.refreshWalletAccounts()
} catch (error) {
this.$q.notify({
diff --git a/package-lock.json b/package-lock.json
index f2ff24bdd..37760cfc6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,31 +1,54 @@
{
- "name": "lnbits-legend",
+ "name": "lnbits",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"devDependencies": {
- "prettier": "2.1.1"
+ "prettier": "2.8.3",
+ "pyright": "1.1.289"
}
},
"node_modules/prettier": {
- "version": "2.1.1",
- "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.1.tgz",
- "integrity": "sha512-9bY+5ZWCfqj3ghYBLxApy2zf6m+NJo5GzmLTpr9FsApsfjriNnS2dahWReHMi7qNPhhHl9SYHJs2cHZLgexNIw==",
+ "version": "2.8.3",
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.3.tgz",
+ "integrity": "sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==",
"dev": true,
"bin": {
"prettier": "bin-prettier.js"
},
"engines": {
"node": ">=10.13.0"
+ },
+ "funding": {
+ "url": "https://github.com/prettier/prettier?sponsor=1"
+ }
+ },
+ "node_modules/pyright": {
+ "version": "1.1.289",
+ "resolved": "https://registry.npmjs.org/pyright/-/pyright-1.1.289.tgz",
+ "integrity": "sha512-fG3STxnwAt3i7bxbXUPJdYNFrcOWHLwCSEOySH2foUqtYdzWLcxDez0Kgl1X8LMQx0arMJ6HRkKghxfRD1/z6g==",
+ "dev": true,
+ "bin": {
+ "pyright": "index.js",
+ "pyright-langserver": "langserver.index.js"
+ },
+ "engines": {
+ "node": ">=12.0.0"
}
}
},
"dependencies": {
"prettier": {
- "version": "2.1.1",
- "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.1.tgz",
- "integrity": "sha512-9bY+5ZWCfqj3ghYBLxApy2zf6m+NJo5GzmLTpr9FsApsfjriNnS2dahWReHMi7qNPhhHl9SYHJs2cHZLgexNIw==",
+ "version": "2.8.3",
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.3.tgz",
+ "integrity": "sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==",
+ "dev": true
+ },
+ "pyright": {
+ "version": "1.1.289",
+ "resolved": "https://registry.npmjs.org/pyright/-/pyright-1.1.289.tgz",
+ "integrity": "sha512-fG3STxnwAt3i7bxbXUPJdYNFrcOWHLwCSEOySH2foUqtYdzWLcxDez0Kgl1X8LMQx0arMJ6HRkKghxfRD1/z6g==",
"dev": true
}
}
diff --git a/package.json b/package.json
index 19d34f128..de2a17915 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,6 @@
{
"devDependencies": {
- "prettier": "2.1.1"
+ "prettier": "2.8.3",
+ "pyright": "1.1.289"
}
}
diff --git a/pyproject.toml b/pyproject.toml
index 23fe0dae1..da873a125 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -86,6 +86,14 @@ lnbits = "lnbits.server:main"
[tool.isort]
profile = "black"
+[tool.pyright]
+include = [
+ "lnbits"
+]
+exclude = [
+ "lnbits/wallets/lnd_grpc_files",
+]
+
[tool.mypy]
files = "lnbits"
exclude = """(?x)(
From e106ec3e9cd6414ec25b27d156f41346824a96a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?dni=20=E2=9A=A1?=
Date: Mon, 23 Jan 2023 12:57:37 +0100
Subject: [PATCH 39/55] FIX: improve workflow stability (#1397)
* FIX: improve workflow stability
* just testing
* just testing, nr. 3
---
.github/workflows/formatting.yml | 4 +++-
.github/workflows/migrations.yml | 1 +
.github/workflows/mypy.yml | 1 +
.github/workflows/regtest.yml | 3 +++
.github/workflows/tests.yml | 2 ++
5 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml
index b6966bfa4..18445899c 100644
--- a/.github/workflows/formatting.yml
+++ b/.github/workflows/formatting.yml
@@ -24,7 +24,9 @@ jobs:
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install packages
- run: poetry install
+ run: |
+ poetry config virtualenvs.create false
+ poetry install
- name: Check black
run: make checkblack
- name: Check isort
diff --git a/.github/workflows/migrations.yml b/.github/workflows/migrations.yml
index 11429665e..6725d845c 100644
--- a/.github/workflows/migrations.yml
+++ b/.github/workflows/migrations.yml
@@ -36,6 +36,7 @@ jobs:
poetry-version: ${{ matrix.poetry-version }}
- name: Install dependencies
run: |
+ poetry config virtualenvs.create false
poetry install
sudo apt install unzip
- name: Run migrations
diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml
index 6868455e4..4c47fafc6 100644
--- a/.github/workflows/mypy.yml
+++ b/.github/workflows/mypy.yml
@@ -21,6 +21,7 @@ jobs:
poetry-version: ${{ matrix.poetry-version }}
- name: Install dependencies
run: |
+ poetry config virtualenvs.create false
poetry install
- name: Run tests
run: poetry run mypy
diff --git a/.github/workflows/regtest.yml b/.github/workflows/regtest.yml
index 99687032b..ecba4090b 100644
--- a/.github/workflows/regtest.yml
+++ b/.github/workflows/regtest.yml
@@ -29,6 +29,7 @@ jobs:
sudo chmod -R a+rwx .
- name: Install dependencies
run: |
+ poetry config virtualenvs.create false
poetry install
- name: Run tests
env:
@@ -72,6 +73,7 @@ jobs:
sudo chmod -R a+rwx .
- name: Install dependencies
run: |
+ poetry config virtualenvs.create false
poetry install
- name: Run tests
env:
@@ -116,6 +118,7 @@ jobs:
sudo chmod -R a+rwx .
- name: Install dependencies
run: |
+ poetry config virtualenvs.create false
poetry install
- name: Run tests
env:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 7409b03e5..dbbddf980 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -44,6 +44,7 @@ jobs:
poetry-version: ${{ matrix.poetry-version }}
- name: Install dependencies
run: |
+ poetry config virtualenvs.create false
poetry install
- name: Run tests
run: make test
@@ -80,6 +81,7 @@ jobs:
poetry-version: ${{ matrix.poetry-version }}
- name: Install dependencies
run: |
+ poetry config virtualenvs.create false
poetry install
- name: Run tests
env:
From 29761683877682efd3414581b3cdc4284f16f85c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?dni=20=E2=9A=A1?=
Date: Mon, 23 Jan 2023 14:23:30 +0100
Subject: [PATCH 40/55] FIX: prettier formatting (#1395)
* prettier
* depreceation warning, and reformatting with new prettier verison
---
.prettierrc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.prettierrc b/.prettierrc
index 224c6ee0f..725c3980a 100644
--- a/.prettierrc
+++ b/.prettierrc
@@ -7,6 +7,6 @@
"singleQuote": true,
"trailingComma": "none",
"useTabs": false,
- "jsxBracketSameLine": false,
+ "bracketSameLine": false,
"bracketSpacing": false
}
From 331c8e593beb0df00cead02f76af6cd2b27b7b7e Mon Sep 17 00:00:00 2001
From: Vlad Stan
Date: Mon, 23 Jan 2023 15:25:54 +0200
Subject: [PATCH 41/55] fix: ignore extra settings fields (#1398)
* fix: ignore extra settings fields
* fix: format
---
lnbits/settings.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lnbits/settings.py b/lnbits/settings.py
index 6ec4db0c7..8245a3d48 100644
--- a/lnbits/settings.py
+++ b/lnbits/settings.py
@@ -8,7 +8,7 @@ from typing import List, Optional
import httpx
from loguru import logger
-from pydantic import BaseSettings, Field, validator
+from pydantic import BaseSettings, Extra, Field, validator
def list_parse_fallback(v):
@@ -33,6 +33,7 @@ class LNbitsSettings(BaseSettings):
env_file_encoding = "utf-8"
case_sensitive = False
json_loads = list_parse_fallback
+ extra = Extra.ignore
class UsersSettings(LNbitsSettings):
From 165e5099c12fcbd8963f6cf4a9c9259164b722e5 Mon Sep 17 00:00:00 2001
From: ben
Date: Mon, 23 Jan 2023 19:57:49 +0000
Subject: [PATCH 42/55] trying to fix mypy
---
lnbits/core/models.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lnbits/core/models.py b/lnbits/core/models.py
index effd89dbe..d6f47ff5f 100644
--- a/lnbits/core/models.py
+++ b/lnbits/core/models.py
@@ -220,5 +220,5 @@ class TinyURL(BaseModel):
url: str
@classmethod
- def from_row(cls, row: Row) -> "TinyURL":
- return cls(**dict(row))
+ def from_row(cls, row: Row):
+ return cls(id=row["id"],url=row["url"])
From f3b1bca5b85843871495fe20a7d19ae78dee3fc6 Mon Sep 17 00:00:00 2001
From: ben
Date: Mon, 23 Jan 2023 20:25:47 +0000
Subject: [PATCH 43/55] format
---
lnbits/core/models.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lnbits/core/models.py b/lnbits/core/models.py
index d6f47ff5f..4b5094961 100644
--- a/lnbits/core/models.py
+++ b/lnbits/core/models.py
@@ -221,4 +221,4 @@ class TinyURL(BaseModel):
@classmethod
def from_row(cls, row: Row):
- return cls(id=row["id"],url=row["url"])
+ return cls(id=row["id"], url=row["url"])
From 39559cccb9f721609e61543fa437f86d682d87db Mon Sep 17 00:00:00 2001
From: ben
Date: Mon, 23 Jan 2023 21:15:43 +0000
Subject: [PATCH 44/55] Removes https in super user link
---
lnbits/core/services.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lnbits/core/services.py b/lnbits/core/services.py
index eefb2f990..72ee543c9 100644
--- a/lnbits/core/services.py
+++ b/lnbits/core/services.py
@@ -434,7 +434,7 @@ async def check_admin_settings():
http = "https" if settings.lnbits_force_https else "http"
admin_url = (
- f"{http}://{settings.host}:{settings.port}/wallet?usr={settings.super_user}"
+ f"http://{settings.host}:{settings.port}/wallet?usr={settings.super_user}"
)
logger.success(f"āļø Access super user account at: {admin_url}")
From 87ef8638b5f849e6ae804e0bc07c6785ff6d9f20 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?dni=20=E2=9A=A1?=
Date: Tue, 24 Jan 2023 11:40:17 +0100
Subject: [PATCH 45/55] fix annoying package-lock (#1405)
---
package-lock.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package-lock.json b/package-lock.json
index 37760cfc6..db16d6f3d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,5 +1,5 @@
{
- "name": "lnbits",
+ "name": "main",
"lockfileVersion": 2,
"requires": true,
"packages": {
From 3c61f61588c70a375f69b0764c32934d324a8c7c Mon Sep 17 00:00:00 2001
From: ben
Date: Tue, 24 Jan 2023 10:40:51 +0000
Subject: [PATCH 46/55] removed http var
---
lnbits/core/services.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/lnbits/core/services.py b/lnbits/core/services.py
index 72ee543c9..446645138 100644
--- a/lnbits/core/services.py
+++ b/lnbits/core/services.py
@@ -432,7 +432,6 @@ async def check_admin_settings():
for key, value in settings.dict(exclude_none=True).items():
logger.debug(f"{key}: {value}")
- http = "https" if settings.lnbits_force_https else "http"
admin_url = (
f"http://{settings.host}:{settings.port}/wallet?usr={settings.super_user}"
)
From 0d0817044c11ec5d9d5b1ed964866528bf4ae321 Mon Sep 17 00:00:00 2001
From: ben
Date: Tue, 24 Jan 2023 11:03:46 +0000
Subject: [PATCH 47/55] Pissy python and its tuples
---
lnbits/core/crud.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py
index df5345bbe..ca4c7ae92 100644
--- a/lnbits/core/crud.py
+++ b/lnbits/core/crud.py
@@ -640,7 +640,7 @@ async def get_tinyurl(
) -> Optional[TinyURL]:
row = await (conn or db).fetchone(
f"SELECT * FROM tiny_url WHERE id = ?",
- (tinyurl_id),
+ (tinyurl_id,),
)
return TinyURL.from_row(row) if row else None
@@ -650,6 +650,6 @@ async def get_tinyurl_by_url(
) -> Optional[TinyURL]:
row = await (conn or db).fetchone(
f"SELECT * FROM tiny_url WHERE url = ?",
- (url),
+ (url,),
)
return TinyURL.from_row(row) if row else None
From e53ccb04accc9d53f65e69468b9c84343c45e73c Mon Sep 17 00:00:00 2001
From: ben
Date: Tue, 24 Jan 2023 12:45:15 +0000
Subject: [PATCH 48/55] Added timestamp and endless
For future culling of links. If endless is not specified, then links older than x could be removed
---
lnbits/core/migrations.py | 6 ++++--
lnbits/core/models.py | 2 ++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/lnbits/core/migrations.py b/lnbits/core/migrations.py
index d7e0e186d..499adad6b 100644
--- a/lnbits/core/migrations.py
+++ b/lnbits/core/migrations.py
@@ -273,10 +273,12 @@ async def m008_create_admin_settings_table(db):
async def m009_create_tinyurl_table(db):
await db.execute(
- """
+ f"""
CREATE TABLE IF NOT EXISTS tiny_url (
id TEXT PRIMARY KEY,
- url TEXT
+ url TEXT,
+ endless BOOL NOT NULL DEFAULT false,
+ time TIMESTAMP NOT NULL DEFAULT {db.timestamp_now},
);
"""
)
diff --git a/lnbits/core/models.py b/lnbits/core/models.py
index 4b5094961..19e597769 100644
--- a/lnbits/core/models.py
+++ b/lnbits/core/models.py
@@ -218,6 +218,8 @@ class BalanceCheck(BaseModel):
class TinyURL(BaseModel):
id: str
url: str
+ endless: bool
+ time: float
@classmethod
def from_row(cls, row: Row):
From 274615f0b328ed8ddcc4c7af3d67164d4fd58101 Mon Sep 17 00:00:00 2001
From: ben
Date: Tue, 24 Jan 2023 13:27:30 +0000
Subject: [PATCH 49/55] Man, broken
---
lnbits/core/crud.py | 6 +++---
lnbits/core/migrations.py | 2 +-
lnbits/core/models.py | 2 +-
lnbits/core/views/api.py | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py
index ca4c7ae92..ebae6a81d 100644
--- a/lnbits/core/crud.py
+++ b/lnbits/core/crud.py
@@ -626,11 +626,11 @@ async def create_admin_settings(super_user: str, new_settings: dict):
# -------
-async def create_tinyurl(domain: str, conn: Optional[Connection] = None):
+async def create_tinyurl(domain: str, endless: bool, conn: Optional[Connection] = None):
tinyurl_id = uuid4().hex[:8]
await (conn or db).execute(
- f"INSERT INTO tiny_url (id, url) VALUES (?, ?)",
- (tinyurl_id, domain),
+ f"INSERT INTO tiny_url (id, url, endless) VALUES (?, ?, ?)",
+ (tinyurl_id, domain, endless,),
)
return await get_tinyurl(tinyurl_id)
diff --git a/lnbits/core/migrations.py b/lnbits/core/migrations.py
index 499adad6b..32764b395 100644
--- a/lnbits/core/migrations.py
+++ b/lnbits/core/migrations.py
@@ -278,7 +278,7 @@ async def m009_create_tinyurl_table(db):
id TEXT PRIMARY KEY,
url TEXT,
endless BOOL NOT NULL DEFAULT false,
- time TIMESTAMP NOT NULL DEFAULT {db.timestamp_now},
+ time TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}
);
"""
)
diff --git a/lnbits/core/models.py b/lnbits/core/models.py
index 19e597769..e8de4694b 100644
--- a/lnbits/core/models.py
+++ b/lnbits/core/models.py
@@ -223,4 +223,4 @@ class TinyURL(BaseModel):
@classmethod
def from_row(cls, row: Row):
- return cls(id=row["id"], url=row["url"])
+ return cls(dict(row))
diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py
index 1a166da07..b72cc244b 100644
--- a/lnbits/core/views/api.py
+++ b/lnbits/core/views/api.py
@@ -715,11 +715,11 @@ async def websocket_update_get(item_id: str, data: str):
@core_app.post("/api/v1/tinyurl")
-async def api_create_tinyurl(url: str):
+async def api_create_tinyurl(url: str, endless: Optional[bool] = False):
tinyurl = await get_tinyurl_by_url(url)
if tinyurl:
return tinyurl
- return await create_tinyurl(url)
+ return await create_tinyurl(url, endless)
@core_app.get("/api/v1/tinyurl/{tinyurl_id}")
From 5392b2cbfe42eed69fe300fde36bbfbca6443214 Mon Sep 17 00:00:00 2001
From: ben
Date: Tue, 24 Jan 2023 13:30:15 +0000
Subject: [PATCH 50/55] Fixed models
---
lnbits/core/models.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lnbits/core/models.py b/lnbits/core/models.py
index e8de4694b..a2d055681 100644
--- a/lnbits/core/models.py
+++ b/lnbits/core/models.py
@@ -223,4 +223,4 @@ class TinyURL(BaseModel):
@classmethod
def from_row(cls, row: Row):
- return cls(dict(row))
+ return cls(**dict(row))
From caadeb77e227aa5af4b361ac4e1cad39254e9ec1 Mon Sep 17 00:00:00 2001
From: ben
Date: Tue, 24 Jan 2023 13:32:21 +0000
Subject: [PATCH 51/55] format
---
lnbits/core/crud.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py
index ebae6a81d..5c1b3bc7f 100644
--- a/lnbits/core/crud.py
+++ b/lnbits/core/crud.py
@@ -630,7 +630,11 @@ async def create_tinyurl(domain: str, endless: bool, conn: Optional[Connection]
tinyurl_id = uuid4().hex[:8]
await (conn or db).execute(
f"INSERT INTO tiny_url (id, url, endless) VALUES (?, ?, ?)",
- (tinyurl_id, domain, endless,),
+ (
+ tinyurl_id,
+ domain,
+ endless,
+ ),
)
return await get_tinyurl(tinyurl_id)
From 6c9a52c6e1595c8f0c59cd2bf2db7602208a6aa0 Mon Sep 17 00:00:00 2001
From: ben
Date: Tue, 24 Jan 2023 13:48:04 +0000
Subject: [PATCH 52/55] mypy being thoroughly objectionable
---
lnbits/core/views/api.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py
index b72cc244b..105c240bd 100644
--- a/lnbits/core/views/api.py
+++ b/lnbits/core/views/api.py
@@ -715,7 +715,7 @@ async def websocket_update_get(item_id: str, data: str):
@core_app.post("/api/v1/tinyurl")
-async def api_create_tinyurl(url: str, endless: Optional[bool] = False):
+async def api_create_tinyurl(url: str, endless: bool = False):
tinyurl = await get_tinyurl_by_url(url)
if tinyurl:
return tinyurl
From 7322d27aa38cc310cf1f3d7a07f92b52a242ce88 Mon Sep 17 00:00:00 2001
From: ben
Date: Tue, 24 Jan 2023 20:27:20 +0000
Subject: [PATCH 53/55] changed to shortuuid as suggested by Vlad
---
lnbits/core/crud.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py
index 5c1b3bc7f..a4726d829 100644
--- a/lnbits/core/crud.py
+++ b/lnbits/core/crud.py
@@ -4,6 +4,8 @@ from typing import Any, Dict, List, Optional
from urllib.parse import urlparse
from uuid import uuid4
+import shortuuid
+
from lnbits import bolt11
from lnbits.db import COCKROACH, POSTGRES, Connection
from lnbits.settings import AdminSettings, EditableSettings, SuperSettings, settings
@@ -627,7 +629,7 @@ async def create_admin_settings(super_user: str, new_settings: dict):
async def create_tinyurl(domain: str, endless: bool, conn: Optional[Connection] = None):
- tinyurl_id = uuid4().hex[:8]
+ tinyurl_id = shortuuid.uuid()[:8]
await (conn or db).execute(
f"INSERT INTO tiny_url (id, url, endless) VALUES (?, ?, ?)",
(
From c0c4c8680888f51f4a7a27a1b5237ec880ff23df Mon Sep 17 00:00:00 2001
From: ben
Date: Tue, 24 Jan 2023 21:26:18 +0000
Subject: [PATCH 54/55] Added wallet authentication to creat, get and delete
tinyurls
---
lnbits/core/crud.py | 28 ++++++++-------
lnbits/core/migrations.py | 1 +
lnbits/core/models.py | 1 +
lnbits/core/views/api.py | 71 ++++++++++++++++++++++++++++++++-------
4 files changed, 76 insertions(+), 25 deletions(-)
diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py
index a4726d829..e5d4424fa 100644
--- a/lnbits/core/crud.py
+++ b/lnbits/core/crud.py
@@ -628,34 +628,38 @@ async def create_admin_settings(super_user: str, new_settings: dict):
# -------
-async def create_tinyurl(domain: str, endless: bool, conn: Optional[Connection] = None):
+async def create_tinyurl(domain: str, endless: bool, wallet: str):
tinyurl_id = shortuuid.uuid()[:8]
- await (conn or db).execute(
- f"INSERT INTO tiny_url (id, url, endless) VALUES (?, ?, ?)",
+ await db.execute(
+ f"INSERT INTO tiny_url (id, url, endless, wallet) VALUES (?, ?, ?, ?)",
(
tinyurl_id,
domain,
endless,
+ wallet,
),
)
return await get_tinyurl(tinyurl_id)
-async def get_tinyurl(
- tinyurl_id: str, conn: Optional[Connection] = None
-) -> Optional[TinyURL]:
- row = await (conn or db).fetchone(
+async def get_tinyurl(tinyurl_id: str) -> Optional[TinyURL]:
+ row = await db.fetchone(
f"SELECT * FROM tiny_url WHERE id = ?",
(tinyurl_id,),
)
return TinyURL.from_row(row) if row else None
-async def get_tinyurl_by_url(
- url: str, conn: Optional[Connection] = None
-) -> Optional[TinyURL]:
- row = await (conn or db).fetchone(
+async def get_tinyurl_by_url(url: str) -> List[TinyURL]:
+ rows = await db.fetchall(
f"SELECT * FROM tiny_url WHERE url = ?",
(url,),
)
- return TinyURL.from_row(row) if row else None
+ return [TinyURL.from_row(row) for row in rows]
+
+
+async def delete_tinyurl(tinyurl_id: str):
+ row = await db.execute(
+ f"DELETE FROM tiny_url WHERE id = ?",
+ (tinyurl_id,),
+ )
diff --git a/lnbits/core/migrations.py b/lnbits/core/migrations.py
index 32764b395..ccbd78717 100644
--- a/lnbits/core/migrations.py
+++ b/lnbits/core/migrations.py
@@ -278,6 +278,7 @@ async def m009_create_tinyurl_table(db):
id TEXT PRIMARY KEY,
url TEXT,
endless BOOL NOT NULL DEFAULT false,
+ wallet TEXT,
time TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}
);
"""
diff --git a/lnbits/core/models.py b/lnbits/core/models.py
index a2d055681..4def937e2 100644
--- a/lnbits/core/models.py
+++ b/lnbits/core/models.py
@@ -219,6 +219,7 @@ class TinyURL(BaseModel):
id: str
url: str
endless: bool
+ wallet: str
time: float
@classmethod
diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py
index 105c240bd..485592a76 100644
--- a/lnbits/core/views/api.py
+++ b/lnbits/core/views/api.py
@@ -48,6 +48,7 @@ from lnbits.utils.exchange_rates import (
from .. import core_app, db
from ..crud import (
create_tinyurl,
+ delete_tinyurl,
get_payments,
get_standalone_payment,
get_tinyurl,
@@ -715,23 +716,67 @@ async def websocket_update_get(item_id: str, data: str):
@core_app.post("/api/v1/tinyurl")
-async def api_create_tinyurl(url: str, endless: bool = False):
- tinyurl = await get_tinyurl_by_url(url)
- if tinyurl:
- return tinyurl
- return await create_tinyurl(url, endless)
+async def api_create_tinyurl(
+ url: str, endless: bool = False, wallet: WalletTypeInfo = Depends(get_key_type)
+):
+ tinyurls = await get_tinyurl_by_url(url)
+ try:
+ for tinyurl in tinyurls:
+ if tinyurl:
+ if tinyurl.wallet == wallet.wallet.inkey:
+ return tinyurl
+ return await create_tinyurl(url, endless, wallet.wallet.inkey)
+ except:
+ raise HTTPException(
+ status_code=HTTPStatus.BAD_REQUEST, detail="Unable to create tinyurl"
+ )
@core_app.get("/api/v1/tinyurl/{tinyurl_id}")
-async def api_get_tinyurl(tinyurl_id: str):
- return await get_tinyurl(tinyurl_id)
+async def api_get_tinyurl(
+ tinyurl_id: str, wallet: WalletTypeInfo = Depends(get_key_type)
+):
+ try:
+ tinyurl = await get_tinyurl(tinyurl_id)
+ if tinyurl.wallet == wallet.wallet.inkey:
+ return tinyurl
+ raise HTTPException(
+ status_code=HTTPStatus.FORBIDDEN, detail="Wrong key provided."
+ )
+ except:
+ raise HTTPException(
+ status_code=HTTPStatus.NOT_FOUND, detail="Unable to fetch tinyurl"
+ )
+
+
+@core_app.delete("/api/v1/tinyurl/{tinyurl_id}")
+async def api_delete_tinyurl(
+ tinyurl_id: str, wallet: WalletTypeInfo = Depends(get_key_type)
+):
+ try:
+ tinyurl = await get_tinyurl(tinyurl_id)
+ if tinyurl.wallet == wallet.wallet.inkey:
+ await delete_tinyurl(tinyurl_id)
+ return {"deleted": True}
+ raise HTTPException(
+ status_code=HTTPStatus.FORBIDDEN, detail="Wrong key provided."
+ )
+ except:
+ raise HTTPException(
+ status_code=HTTPStatus.BAD_REQUEST, detail="Unable to delete"
+ )
@core_app.get("/t/{tinyurl_id}")
async def api_tinyurl(tinyurl_id: str):
- tinyurl = await get_tinyurl(tinyurl_id)
- if tinyurl:
- response = RedirectResponse(url=tinyurl.url)
- return response
- else:
- return
+ try:
+ tinyurl = await get_tinyurl(tinyurl_id)
+ if tinyurl:
+ response = RedirectResponse(url=tinyurl.url)
+ return response
+ else:
+ return
+ except:
+ raise HTTPException(
+ status_code=HTTPStatus.NOT_FOUND, detail="unable to find tinyurl"
+ )
From dda1d9bb3a9d45a97d9487ebe3959c3b1c5289b4 Mon Sep 17 00:00:00 2001
From: ben
Date: Tue, 24 Jan 2023 21:29:52 +0000
Subject: [PATCH 55/55] mypy
---
lnbits/core/views/api.py | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py
index 485592a76..f614ba023 100644
--- a/lnbits/core/views/api.py
+++ b/lnbits/core/views/api.py
@@ -738,8 +738,9 @@ async def api_get_tinyurl(
):
try:
tinyurl = await get_tinyurl(tinyurl_id)
- if tinyurl.wallet == wallet.wallet.inkey:
- return tinyurl
+ if tinyurl:
+ if tinyurl.wallet == wallet.wallet.inkey:
+ return tinyurl
raise HTTPException(
status_code=HTTPStatus.FORBIDDEN, detail="Wrong key provided."
)
@@ -755,9 +756,10 @@ async def api_delete_tinyurl(
):
try:
tinyurl = await get_tinyurl(tinyurl_id)
- if tinyurl.wallet == wallet.wallet.inkey:
- await delete_tinyurl(tinyurl_id)
- return {"deleted": True}
+ if tinyurl:
+ if tinyurl.wallet == wallet.wallet.inkey:
+ await delete_tinyurl(tinyurl_id)
+ return {"deleted": True}
raise HTTPException(
status_code=HTTPStatus.FORBIDDEN, detail="Wrong key provided."
)