black formating
This commit is contained in:
+25
-25
@@ -29,6 +29,7 @@ class EclairError(Exception):
|
||||
class UnknownError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class EclairWallet(Wallet):
|
||||
def __init__(self):
|
||||
url = getenv("ECLAIR_URL")
|
||||
@@ -41,13 +42,10 @@ class EclairWallet(Wallet):
|
||||
auth = str(encodedAuth, "utf-8")
|
||||
self.auth = {"Authorization": f"Basic {auth}"}
|
||||
|
||||
|
||||
async def status(self) -> StatusResponse:
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = await client.post(
|
||||
f"{self.url}/usablebalances",
|
||||
headers=self.auth,
|
||||
timeout=40
|
||||
f"{self.url}/usablebalances", headers=self.auth, timeout=40
|
||||
)
|
||||
try:
|
||||
data = r.json()
|
||||
@@ -55,7 +53,7 @@ class EclairWallet(Wallet):
|
||||
return StatusResponse(
|
||||
f"Failed to connect to {self.url}, got: '{r.text[:200]}...'", 0
|
||||
)
|
||||
|
||||
|
||||
if r.is_error:
|
||||
return StatusResponse(data["error"], 0)
|
||||
|
||||
@@ -76,10 +74,7 @@ class EclairWallet(Wallet):
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = await client.post(
|
||||
f"{self.url}/createinvoice",
|
||||
headers=self.auth,
|
||||
data=data,
|
||||
timeout=40
|
||||
f"{self.url}/createinvoice", headers=self.auth, data=data, timeout=40
|
||||
)
|
||||
|
||||
if r.is_error:
|
||||
@@ -95,7 +90,6 @@ class EclairWallet(Wallet):
|
||||
data = r.json()
|
||||
return InvoiceResponse(True, data["paymentHash"], data["serialized"], None)
|
||||
|
||||
|
||||
async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse:
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = await client.post(
|
||||
@@ -113,10 +107,9 @@ class EclairWallet(Wallet):
|
||||
error_message = r.text
|
||||
pass
|
||||
return PaymentResponse(False, None, 0, None, error_message)
|
||||
|
||||
|
||||
data = r.json()
|
||||
|
||||
|
||||
checking_id = data["paymentHash"]
|
||||
preimage = data["paymentPreimage"]
|
||||
|
||||
@@ -135,22 +128,22 @@ class EclairWallet(Wallet):
|
||||
except:
|
||||
error_message = r.text
|
||||
pass
|
||||
return PaymentResponse(True, checking_id, 0, preimage, error_message) ## ?? is this ok ??
|
||||
return PaymentResponse(
|
||||
True, checking_id, 0, preimage, error_message
|
||||
) ## ?? is this ok ??
|
||||
|
||||
data = r.json()
|
||||
fees = [i["status"] for i in data]
|
||||
fee_msat = sum([i["feesPaid"] for i in fees])
|
||||
|
||||
return PaymentResponse(True, checking_id, fee_msat, preimage, None)
|
||||
|
||||
|
||||
return PaymentResponse(True, checking_id, fee_msat, preimage, None)
|
||||
|
||||
async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = await client.post(
|
||||
f"{self.url}/getreceivedinfo",
|
||||
headers=self.auth,
|
||||
data={"paymentHash": checking_id}
|
||||
data={"paymentHash": checking_id},
|
||||
)
|
||||
data = r.json()
|
||||
|
||||
@@ -160,31 +153,33 @@ class EclairWallet(Wallet):
|
||||
if data["status"]["type"] != "received":
|
||||
return PaymentStatus(False)
|
||||
|
||||
return PaymentStatus(True)
|
||||
return PaymentStatus(True)
|
||||
|
||||
async def get_payment_status(self, checking_id: str) -> PaymentStatus:
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = await client.post(
|
||||
url=f"{self.url}/getsentinfo",
|
||||
headers=self.auth,
|
||||
data={"paymentHash": checking_id}
|
||||
|
||||
data={"paymentHash": checking_id},
|
||||
)
|
||||
|
||||
data = r.json()[0]
|
||||
|
||||
if r.is_error:
|
||||
return PaymentStatus(None)
|
||||
|
||||
|
||||
if data["status"]["type"] != "sent":
|
||||
return PaymentStatus(False)
|
||||
|
||||
return PaymentStatus(True)
|
||||
|
||||
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
||||
|
||||
|
||||
try:
|
||||
async with connect(self.ws_url, extra_headers=[('Authorization', self.auth["Authorization"])]) as ws:
|
||||
async with connect(
|
||||
self.ws_url,
|
||||
extra_headers=[("Authorization", self.auth["Authorization"])],
|
||||
) as ws:
|
||||
while True:
|
||||
message = await ws.recv()
|
||||
message = json.loads(message)
|
||||
@@ -192,8 +187,13 @@ class EclairWallet(Wallet):
|
||||
if message and message["type"] == "payment-received":
|
||||
yield message["paymentHash"]
|
||||
|
||||
except (OSError, ConnectionClosedOK, ConnectionClosedError, ConnectionClosed) as ose:
|
||||
print('OSE', ose)
|
||||
except (
|
||||
OSError,
|
||||
ConnectionClosedOK,
|
||||
ConnectionClosedError,
|
||||
ConnectionClosed,
|
||||
) as ose:
|
||||
print("OSE", ose)
|
||||
pass
|
||||
|
||||
print("lost connection to eclair's websocket, retrying in 5 seconds")
|
||||
|
||||
Reference in New Issue
Block a user