added migrate

This commit is contained in:
ben 2022-10-25 12:09:40 +01:00
parent 3552443f99
commit e88b18a417
7 changed files with 241 additions and 59 deletions

View File

@ -23,9 +23,22 @@ async def create_lnurldevice(
currency,
device,
profit,
amount
amount,
pin,
profit1,
amount1,
pin1,
profit2,
amount2,
pin2,
profit3,
amount3,
pin3,
profit4,
amount4,
pin4,
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
lnurldevice_id,
@ -36,6 +49,19 @@ async def create_lnurldevice(
data.device,
data.profit,
data.amount,
data.pin,
data.profit1,
data.amount1,
data.pin1,
data.profit2,
data.amount2,
data.pin2,
data.profit3,
data.amount3,
data.pin3,
data.profit4,
data.amount4,
data.pin4
),
)
return await get_lnurldevice(lnurldevice_id)

View File

@ -92,6 +92,8 @@ async def lnurl_v1_params(
p: str = Query(None),
atm: str = Query(None),
gpio: str = Query(None),
profit: str = Query(None),
amount: str = Query(None),
):
device = await get_lnurldevice(device_id)
if not device:
@ -106,14 +108,14 @@ async def lnurl_v1_params(
if device.device == "switch":
price_msat = (
await fiat_amount_as_satoshis(float(device.profit), device.currency)
await fiat_amount_as_satoshis(float(profit), device.currency)
if device.currency != "sat"
else amount_in_cent
) * 1000
lnurldevicepayment = await create_lnurldevicepayment(
deviceid=device.id,
payload="bla",
payload=amount,
sats=price_msat,
pin=gpio,
payhash="bla",
@ -237,7 +239,7 @@ async def lnurl_callback(
amount=lnurldevicepayment.sats / 1000,
memo=device.title + "-" + lnurldevicepayment.id,
unhashed_description=(await device.lnurlpay_metadata()).encode("utf-8"),
extra={"tag": "Switch", "pin": ,"id": paymentid, "time": device.amount},
extra={"tag": "Switch", "pin": lnurldevicepayment.pin,"amount": int(lnurldevicepayment.payload),"id": paymentid},
)
lnurldevicepayment = await update_lnurldevicepayment(
lnurldevicepayment_id=paymentid, payhash=payment_hash

View File

@ -93,23 +93,20 @@ async def m004_redux(db):
"""
Add 'meta' for storing various metadata about the wallet
"""
await db.execute(
"""
ALTER TABLE lnurldevice.lnurldevices ADD COLUMN (
amount1,
amount2,
amount3,
amount4,
time,
time1,
time2,
time3,
time4,
pin1,
pin2,
pin3,
pin4,
)
INT DEFAULT 0;
"""
)
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN pin INT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN profit1 FLOAT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN amount1 INT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN pin1 INT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN profit2 FLOAT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN amount2 INT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN pin2 INT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN profit3 FLOAT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN amount3 INT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN pin3 INT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN profit4 FLOAT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN amount4 INT DEFAULT 0")
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN pin4 INT DEFAULT 0")

View File

@ -18,20 +18,19 @@ class createLnurldevice(BaseModel):
device: str
profit: float
amount: int
amount1: int
amount2: int
amount3: int
amount4: int
pin: int
profit1: float
amount1: int
pin1: int
profit2: float
amount2: int
pin2: int
profit3: float
amount3: int
pin3: int
profit4: float
amount4: int
pin4: int
time: int
time1: int
time2: int
time3: int
time4: int
class lnurldevices(BaseModel):
@ -43,6 +42,19 @@ class lnurldevices(BaseModel):
device: str
profit: float
amount: int
pin: int
profit1: float
amount1: int
pin1: int
profit2: float
amount2: int
pin2: int
profit3: float
amount3: int
pin3: int
profit4: float
amount4: int
pin4: int
timestamp: str
def from_row(cls, row: Row) -> "lnurldevices":

View File

@ -36,5 +36,5 @@ async def on_invoice_paid(payment: Payment) -> None:
lnurldevicepayment = await update_lnurldevicepayment(
lnurldevicepayment_id=payment.extra.get("id"), payhash="used"
)
return await updater(lnurldevicepayment.deviceid, lnurldevicepayment.pin)
return await updater(lnurldevicepayment.deviceid, lnurldevicepayment.pin, lnurldevicepayment.amount)
return

View File

@ -230,27 +230,167 @@
label="Profit margin (% added to invoices/deducted from faucets)"
></q-input>
<div v-else>
<q-input
ref="setAmount"
filled
dense
v-model.trim="formDialoglnurldevice.data.profit"
class="q-pb-md"
:label="'Amount (' + formDialoglnurldevice.data.currency + ') *'"
:mask="'#.##'"
fill-mask="0"
reverse-fill-mask
:step="'0.01'"
value="0.00"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.amount"
type="number"
value="1000"
label="milesecs to turn Switch on for (1sec = 1000ms)"
></q-input>
<p>Switches</p>
<q-toggle v-model="switch1" color="primary" label="1"></q-toggle>
<q-toggle v-model="switch2" color="primary" label="2"></q-toggle>
<q-toggle v-model="switch3" color="primary" label="3"></q-toggle>
<q-toggle v-model="switch4" color="primary" label="4"></q-toggle>
<q-toggle v-model="switch5" color="primary" label="5"></q-toggle>
<div v-if="switch1">
<q-input
ref="setAmount"
filled
dense
v-model.trim="formDialoglnurldevice.data.profit"
class="q-pb-md"
:label="'Amount (' + formDialoglnurldevice.data.currency + ') *'"
:mask="'#.##'"
fill-mask="0"
reverse-fill-mask
:step="'0.01'"
value="0.00"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.amount"
type="number"
value="1000"
label="milesecs to turn Switch on for (1sec = 1000ms)"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.pin"
type="number"
label="GPIO to turn on"
></q-input>
</div>
<div v-if="switch2">
<q-input
ref="setAmount"
filled
dense
v-model.trim="formDialoglnurldevice.data.profit1"
class="q-pb-md"
:label="'Amount (' + formDialoglnurldevice.data.currency + ') *'"
:mask="'#.##'"
fill-mask="0"
reverse-fill-mask
:step="'0.01'"
value="0.00"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.amount1"
type="number"
value="1000"
label="milesecs to turn Switch on for (1sec = 1000ms)"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.pin1"
type="number"
label="GPIO to turn on"
></q-input>
</div>
<div v-if="switch3">
<q-input
ref="setAmount"
filled
dense
v-model.trim="formDialoglnurldevice.data.profit2"
class="q-pb-md"
:label="'Amount (' + formDialoglnurldevice.data.currency + ') *'"
:mask="'#.##'"
fill-mask="0"
reverse-fill-mask
:step="'0.01'"
value="0.00"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.amount2"
type="number"
value="1000"
label="milesecs to turn Switch on for (1sec = 1000ms)"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.pin2"
type="number"
label="GPIO to turn on"
></q-input>
</div>
<div v-if="switch4">
<q-input
ref="setAmount"
filled
dense
v-model.trim="formDialoglnurldevice.data.profit3"
class="q-pb-md"
:label="'Amount (' + formDialoglnurldevice.data.currency + ') *'"
:mask="'#.##'"
fill-mask="0"
reverse-fill-mask
:step="'0.01'"
value="0.00"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.amount3"
type="number"
value="1000"
label="milesecs to turn Switch on for (1sec = 1000ms)"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.pin3"
type="number"
label="GPIO to turn on"
></q-input>
</div>
<div v-if="switch4">
<q-input
ref="setAmount"
filled
dense
v-model.trim="formDialoglnurldevice.data.profit4"
class="q-pb-md"
:label="'Amount (' + formDialoglnurldevice.data.currency + ') *'"
:mask="'#.##'"
fill-mask="0"
reverse-fill-mask
:step="'0.01'"
value="0.00"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.amount4"
type="number"
value="1000"
label="milesecs to turn Switch on for (1sec = 1000ms)"
></q-input>
<q-input
filled
dense
v-model.trim="formDialoglnurldevice.data.pin4"
type="number"
label="GPIO to turn on"
></q-input>
</div>
</div>
<div class="row q-mt-lg">
@ -338,6 +478,11 @@
wslocation: window.location.hostname,
filter: '',
currency: 'USD',
switch1: false,
switch2: false,
switch3: false,
switch4: false,
switch5: false,
lnurldeviceLinks: [],
lnurldeviceLinksObj: [],
devices: [
@ -592,7 +737,7 @@
LNbits.utils.notifyApiError(error)
})
},
clearFormDialoglnurldevice() {
clearFormDialoglnurldevice () {
this.formDialoglnurldevice.data = {
lnurl_toggle: false,
show_message: false,

View File

@ -103,8 +103,8 @@ async def websocket_endpoint(websocket: WebSocket, lnurldevice_id: str):
manager.disconnect(websocket)
async def updater(lnurldevice_id, lnurldevice_pin):
async def updater(lnurldevice_id, lnurldevice_pin, lnurldevice_amount):
lnurldevice = await get_lnurldevice(lnurldevice_id)
if not lnurldevice:
return
return await manager.send_personal_message(f"pin:{lnurldevice.pin},amount:{lnurldevice.amount}", lnurldevice_id)
return await manager.send_personal_message(f"pin:{lnurldevice_pin},amount:{lnurldevice_amount}", lnurldevice_id)