initial crud, index form
This commit is contained in:
parent
3644e0e254
commit
577a3932f5
4 changed files with 83 additions and 5 deletions
|
|
@ -27,3 +27,5 @@ LNURL is a range of lightning-network standards that allow us to use lightning-n
|
||||||

|

|
||||||
|
|
||||||
3. Optional - add Lightning Address
|
3. Optional - add Lightning Address
|
||||||
|
- attach a username to your lnurlp to create a lightning address
|
||||||
|
- the LN address format will be username@lnbits-domain-name
|
||||||
|
|
|
||||||
62
crud.py
62
crud.py
|
|
@ -1,10 +1,12 @@
|
||||||
|
import re
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
|
|
||||||
from . import db
|
from . import db, maindb
|
||||||
from .models import CreatePayLinkData, PayLink
|
from .models import CreatePayLinkData, PayLink
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink:
|
async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink:
|
||||||
link_id = urlsafe_short_hash()[:6]
|
link_id = urlsafe_short_hash()[:6]
|
||||||
|
|
@ -26,9 +28,11 @@ async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink:
|
||||||
success_url,
|
success_url,
|
||||||
comment_chars,
|
comment_chars,
|
||||||
currency,
|
currency,
|
||||||
fiat_base_multiplier
|
fiat_base_multiplier,
|
||||||
|
username
|
||||||
|
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?, 0, 0, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, 0, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
link_id,
|
link_id,
|
||||||
|
|
@ -44,6 +48,7 @@ async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink:
|
||||||
data.comment_chars,
|
data.comment_chars,
|
||||||
data.currency,
|
data.currency,
|
||||||
data.fiat_base_multiplier,
|
data.fiat_base_multiplier,
|
||||||
|
data.username,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
assert result
|
assert result
|
||||||
|
|
@ -53,6 +58,57 @@ async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink:
|
||||||
return link
|
return link
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async def check_lnaddress_update(username: str, id: str) -> bool:
|
||||||
|
# check no duplicates for lnaddress when updating an username
|
||||||
|
row = await db.fetchall(
|
||||||
|
"SELECT username FROM lnurlp.pay_links WHERE username = ? AND id = ?",
|
||||||
|
(username, id),
|
||||||
|
)
|
||||||
|
logger.info("number of rows from username search")
|
||||||
|
logger.info(len(row))
|
||||||
|
if len(row) > 1:
|
||||||
|
assert False, "Lightning Address Already exists. Try a different One?"
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
async def check_lnaddress_exists(username: str) -> bool:
|
||||||
|
# check if lnaddress username exists in the database when creating a new entry
|
||||||
|
row = await db.fetchall(
|
||||||
|
"SELECT username FROM lnurlp.pay_links WHERE username = ?", (username,)
|
||||||
|
)
|
||||||
|
logger.info("number of rows from lnaddress search")
|
||||||
|
if row:
|
||||||
|
assert False, "Lighting Address Already exists. Try a different One?"
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
async def check_lnaddress_format(username: str) -> bool:
|
||||||
|
# check username complies with lnaddress specification
|
||||||
|
if not re.match("^[a-z0-9-_.]{3,15}$", username):
|
||||||
|
assert False, "Only letters a-z0-9-_. allowed, min 3 and max 15 characters!"
|
||||||
|
return
|
||||||
|
return True
|
||||||
|
|
||||||
|
async def get_wallet_key(wallet_id: str) -> str:
|
||||||
|
row = await maindb.fetchone("SELECT inkey FROM wallets WHERE id = ?", (wallet_id,))
|
||||||
|
if row is not None:
|
||||||
|
return row[0]
|
||||||
|
else:
|
||||||
|
assert False, "Cannot locate wallet invoice key"
|
||||||
|
return
|
||||||
|
|
||||||
|
async def get_address_data(username: str) -> Optional[PayLink]:
|
||||||
|
row = await db.fetchone(
|
||||||
|
"SELECT * FROM lnurl.pay_links WHERE username = ?", (username,)
|
||||||
|
)
|
||||||
|
return PayLink.from_row(row) if row else None
|
||||||
|
|
||||||
|
|
||||||
async def get_pay_link(link_id: str) -> Optional[PayLink]:
|
async def get_pay_link(link_id: str) -> Optional[PayLink]:
|
||||||
row = await db.fetchone("SELECT * FROM lnurlp.pay_links WHERE id = ?", (link_id,))
|
row = await db.fetchone("SELECT * FROM lnurlp.pay_links WHERE id = ?", (link_id,))
|
||||||
return PayLink.from_row(row) if row else None
|
return PayLink.from_row(row) if row else None
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ var locationPath = [
|
||||||
window.location.pathname
|
window.location.pathname
|
||||||
].join('')
|
].join('')
|
||||||
|
|
||||||
|
var domain = window.location.hostname
|
||||||
|
|
||||||
var mapPayLink = obj => {
|
var mapPayLink = obj => {
|
||||||
obj._data = _.clone(obj)
|
obj._data = _.clone(obj)
|
||||||
obj.date = Quasar.utils.date.formatDate(
|
obj.date = Quasar.utils.date.formatDate(
|
||||||
|
|
@ -26,6 +28,7 @@ new Vue({
|
||||||
mixins: [windowMixin],
|
mixins: [windowMixin],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
domain: domain,
|
||||||
currencies: [],
|
currencies: [],
|
||||||
fiatRates: {},
|
fiatRates: {},
|
||||||
checker: null,
|
checker: null,
|
||||||
|
|
@ -137,7 +140,8 @@ new Vue({
|
||||||
'success_text',
|
'success_text',
|
||||||
'success_url',
|
'success_url',
|
||||||
'comment_chars',
|
'comment_chars',
|
||||||
'currency'
|
'currency',
|
||||||
|
'username'
|
||||||
),
|
),
|
||||||
(value, key) =>
|
(value, key) =>
|
||||||
(key === 'webhook_url' ||
|
(key === 'webhook_url' ||
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
<q-tr :props="props">
|
<q-tr :props="props">
|
||||||
<q-th auto-width></q-th>
|
<q-th auto-width></q-th>
|
||||||
<q-th auto-width>Description</q-th>
|
<q-th auto-width>Description</q-th>
|
||||||
|
<q-th auto-width>Lightning Address</q-th>
|
||||||
<q-th auto-width>Amount</q-th>
|
<q-th auto-width>Amount</q-th>
|
||||||
<q-th auto-width>Currency</q-th>
|
<q-th auto-width>Currency</q-th>
|
||||||
<q-th auto-width></q-th>
|
<q-th auto-width></q-th>
|
||||||
|
|
@ -148,6 +149,21 @@
|
||||||
label="Wallet *"
|
label="Wallet *"
|
||||||
>
|
>
|
||||||
</q-select>
|
</q-select>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<q-input
|
||||||
|
filled
|
||||||
|
dense
|
||||||
|
v-model.trim="formDialog.data.lnaddress"
|
||||||
|
type="text"
|
||||||
|
label="Lightning Username"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div class="col" style="margin-top: 10px">
|
||||||
|
<span class="label"> @{% raw %} {{domain}} {% endraw %} </span>
|
||||||
|
</div>
|
||||||
|
</q-input>
|
||||||
|
</div>
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue