Files
nutshell/cashu/core/helpers.py
calle 89fb2787e6 Python/relative_import (#186)
* relative import all the things

* make format

* add __init__.py to cli/

* fix mypy errors

* get rid of more mypy

* mypy fix crud.py

* fix another mypy error
2023-05-01 22:39:23 +02:00

45 lines
1.1 KiB
Python

import asyncio
from functools import partial, wraps
from typing import List
from ..core.base import Proof
from ..core.settings import settings
def sum_proofs(proofs: List[Proof]):
return sum([p.amount for p in proofs])
def async_wrap(func):
@wraps(func)
async def run(*args, loop=None, executor=None, **kwargs):
if loop is None:
loop = asyncio.get_event_loop()
partial_func = partial(func, *args, **kwargs)
return await loop.run_in_executor(executor, partial_func)
return run
def async_unwrap(to_await):
async_response = []
async def run_and_capture_result():
r = await to_await
async_response.append(r)
loop = asyncio.get_event_loop()
coroutine = run_and_capture_result()
loop.run_until_complete(coroutine)
return async_response[0]
def fee_reserve(amount_msat: int, internal=False) -> int:
"""Function for calculating the Lightning fee reserve"""
if internal:
return 0
return max(
int(settings.lightning_reserve_fee_min),
int(amount_msat * settings.lightning_fee_percent / 100.0),
)