mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-26 08:41:04 +02:00
Removed id, using param instead
This commit is contained in:
parent
4aeb7683e5
commit
a220acb583
@ -166,7 +166,7 @@ def lnencode(addr, privkey):
|
|||||||
if addr.amount:
|
if addr.amount:
|
||||||
amount = Decimal(str(addr.amount))
|
amount = Decimal(str(addr.amount))
|
||||||
# We can only send down to millisatoshi.
|
# We can only send down to millisatoshi.
|
||||||
if amount * 10**12 % 10:
|
if amount * 10 ** 12 % 10:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Cannot encode {}: too many decimal places".format(addr.amount)
|
"Cannot encode {}: too many decimal places".format(addr.amount)
|
||||||
)
|
)
|
||||||
@ -271,7 +271,7 @@ class LnAddr(object):
|
|||||||
def shorten_amount(amount):
|
def shorten_amount(amount):
|
||||||
"""Given an amount in bitcoin, shorten it"""
|
"""Given an amount in bitcoin, shorten it"""
|
||||||
# Convert to pico initially
|
# Convert to pico initially
|
||||||
amount = int(amount * 10**12)
|
amount = int(amount * 10 ** 12)
|
||||||
units = ["p", "n", "u", "m", ""]
|
units = ["p", "n", "u", "m", ""]
|
||||||
for unit in units:
|
for unit in units:
|
||||||
if amount % 1000 == 0:
|
if amount % 1000 == 0:
|
||||||
@ -290,7 +290,7 @@ def _unshorten_amount(amount: str) -> int:
|
|||||||
# * `u` (micro): multiply by 0.000001
|
# * `u` (micro): multiply by 0.000001
|
||||||
# * `n` (nano): multiply by 0.000000001
|
# * `n` (nano): multiply by 0.000000001
|
||||||
# * `p` (pico): multiply by 0.000000000001
|
# * `p` (pico): multiply by 0.000000000001
|
||||||
units = {"p": 10**12, "n": 10**9, "u": 10**6, "m": 10**3}
|
units = {"p": 10 ** 12, "n": 10 ** 9, "u": 10 ** 6, "m": 10 ** 3}
|
||||||
unit = str(amount)[-1]
|
unit = str(amount)[-1]
|
||||||
|
|
||||||
# BOLT #11:
|
# BOLT #11:
|
||||||
|
@ -329,12 +329,12 @@ async def perform_lnurlauth(
|
|||||||
sign_len = 6 + r_len + s_len
|
sign_len = 6 + r_len + s_len
|
||||||
|
|
||||||
signature = BytesIO()
|
signature = BytesIO()
|
||||||
signature.write(0x30.to_bytes(1, "big", signed=False))
|
signature.write(0x30 .to_bytes(1, "big", signed=False))
|
||||||
signature.write((sign_len - 2).to_bytes(1, "big", signed=False))
|
signature.write((sign_len - 2).to_bytes(1, "big", signed=False))
|
||||||
signature.write(0x02.to_bytes(1, "big", signed=False))
|
signature.write(0x02 .to_bytes(1, "big", signed=False))
|
||||||
signature.write(r_len.to_bytes(1, "big", signed=False))
|
signature.write(r_len.to_bytes(1, "big", signed=False))
|
||||||
signature.write(r)
|
signature.write(r)
|
||||||
signature.write(0x02.to_bytes(1, "big", signed=False))
|
signature.write(0x02 .to_bytes(1, "big", signed=False))
|
||||||
signature.write(s_len.to_bytes(1, "big", signed=False))
|
signature.write(s_len.to_bytes(1, "big", signed=False))
|
||||||
signature.write(s)
|
signature.write(s)
|
||||||
|
|
||||||
@ -388,9 +388,9 @@ class WebsocketConnectionManager:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.active_connections: List[WebSocket] = []
|
self.active_connections: List[WebSocket] = []
|
||||||
|
|
||||||
async def connect(self, websocket: WebSocket, item_id: str):
|
async def connect(self, websocket: WebSocket):
|
||||||
await websocket.accept()
|
await websocket.accept()
|
||||||
websocket.id = item_id
|
logger.debug(websocket)
|
||||||
self.active_connections.append(websocket)
|
self.active_connections.append(websocket)
|
||||||
|
|
||||||
def disconnect(self, websocket: WebSocket):
|
def disconnect(self, websocket: WebSocket):
|
||||||
@ -398,7 +398,7 @@ class WebsocketConnectionManager:
|
|||||||
|
|
||||||
async def send_data(self, message: str, item_id: str):
|
async def send_data(self, message: str, item_id: str):
|
||||||
for connection in self.active_connections:
|
for connection in self.active_connections:
|
||||||
if connection.id == item_id:
|
if connection.path_params["item_id"] == item_id:
|
||||||
await connection.send_text(message)
|
await connection.send_text(message)
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,9 +9,18 @@ from io import BytesIO
|
|||||||
from typing import Dict, List, Optional, Tuple, Union
|
from typing import Dict, List, Optional, Tuple, Union
|
||||||
from urllib.parse import ParseResult, parse_qs, urlencode, urlparse, urlunparse
|
from urllib.parse import ParseResult, parse_qs, urlencode, urlparse, urlunparse
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
import httpx
|
import httpx
|
||||||
import pyqrcode
|
import pyqrcode
|
||||||
from fastapi import Depends, Header, Query, Response, Request, WebSocket, WebSocketDisconnect
|
from fastapi import (
|
||||||
|
Depends,
|
||||||
|
Header,
|
||||||
|
Query,
|
||||||
|
Request,
|
||||||
|
Response,
|
||||||
|
WebSocket,
|
||||||
|
WebSocketDisconnect,
|
||||||
|
)
|
||||||
from fastapi.exceptions import HTTPException
|
from fastapi.exceptions import HTTPException
|
||||||
from fastapi.params import Body
|
from fastapi.params import Body
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
@ -20,7 +29,6 @@ from pydantic.fields import Field
|
|||||||
from sse_starlette.sse import EventSourceResponse, ServerSentEvent
|
from sse_starlette.sse import EventSourceResponse, ServerSentEvent
|
||||||
from starlette.responses import HTMLResponse, StreamingResponse
|
from starlette.responses import HTMLResponse, StreamingResponse
|
||||||
|
|
||||||
import async_timeout
|
|
||||||
from lnbits import bolt11, lnurl
|
from lnbits import bolt11, lnurl
|
||||||
from lnbits.core.models import Payment, Wallet
|
from lnbits.core.models import Payment, Wallet
|
||||||
from lnbits.decorators import (
|
from lnbits.decorators import (
|
||||||
@ -706,7 +714,7 @@ async def api_auditor(wallet: WalletTypeInfo = Depends(get_key_type)):
|
|||||||
|
|
||||||
@core_app.websocket("/api/v1/ws/{item_id}")
|
@core_app.websocket("/api/v1/ws/{item_id}")
|
||||||
async def websocket_connect(websocket: WebSocket, item_id: str):
|
async def websocket_connect(websocket: WebSocket, item_id: str):
|
||||||
await websocketManager.connect(websocket, item_id)
|
await websocketManager.connect(websocket)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
data = await websocket.receive_text()
|
data = await websocket.receive_text()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user