async wrap
This commit is contained in:
parent
e0bfb15e42
commit
860709f48c
1 changed files with 8 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ import random
|
||||||
from functools import partial, wraps
|
from functools import partial, wraps
|
||||||
from os import getenv
|
from os import getenv
|
||||||
from typing import AsyncGenerator, Optional
|
from typing import AsyncGenerator, Optional
|
||||||
|
import time
|
||||||
|
|
||||||
from .base import (
|
from .base import (
|
||||||
InvoiceResponse,
|
InvoiceResponse,
|
||||||
|
|
@ -30,6 +31,10 @@ def async_wrap(func):
|
||||||
return run
|
return run
|
||||||
|
|
||||||
|
|
||||||
|
def _pay_invoice(ln, bolt11):
|
||||||
|
return ln.pay(bolt11)
|
||||||
|
|
||||||
|
|
||||||
def _paid_invoices_stream(ln, last_pay_index):
|
def _paid_invoices_stream(ln, last_pay_index):
|
||||||
return ln.waitanyinvoice(last_pay_index)
|
return ln.waitanyinvoice(last_pay_index)
|
||||||
|
|
||||||
|
|
@ -99,7 +104,8 @@ class CLightningWallet(Wallet):
|
||||||
|
|
||||||
async def pay_invoice(self, bolt11: str) -> PaymentResponse:
|
async def pay_invoice(self, bolt11: str) -> PaymentResponse:
|
||||||
try:
|
try:
|
||||||
r = self.ln.pay(bolt11)
|
wrapped = async_wrap(_pay_invoice)
|
||||||
|
r = await wrapped(self.ln, bolt11)
|
||||||
except RpcError as exc:
|
except RpcError as exc:
|
||||||
return PaymentResponse(False, None, 0, None, str(exc))
|
return PaymentResponse(False, None, 0, None, str(exc))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue