mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-18 11:31:41 +02:00
async wrap
This commit is contained in:
@@ -8,6 +8,7 @@ import random
|
||||
from functools import partial, wraps
|
||||
from os import getenv
|
||||
from typing import AsyncGenerator, Optional
|
||||
import time
|
||||
|
||||
from .base import (
|
||||
InvoiceResponse,
|
||||
@@ -30,6 +31,10 @@ def async_wrap(func):
|
||||
return run
|
||||
|
||||
|
||||
def _pay_invoice(ln, bolt11):
|
||||
return ln.pay(bolt11)
|
||||
|
||||
|
||||
def _paid_invoices_stream(ln, last_pay_index):
|
||||
return ln.waitanyinvoice(last_pay_index)
|
||||
|
||||
@@ -99,7 +104,8 @@ class CLightningWallet(Wallet):
|
||||
|
||||
async def pay_invoice(self, bolt11: str) -> PaymentResponse:
|
||||
try:
|
||||
r = self.ln.pay(bolt11)
|
||||
wrapped = async_wrap(_pay_invoice)
|
||||
r = await wrapped(self.ln, bolt11)
|
||||
except RpcError as exc:
|
||||
return PaymentResponse(False, None, 0, None, str(exc))
|
||||
|
||||
@@ -133,4 +139,4 @@ class CLightningWallet(Wallet):
|
||||
wrapped = async_wrap(_paid_invoices_stream)
|
||||
paid = await wrapped(self.ln, self.last_pay_index)
|
||||
self.last_pay_index = paid["pay_index"]
|
||||
yield paid["label"]
|
||||
yield paid["label"]
|
Reference in New Issue
Block a user