Skip to content

Commit

Permalink
LightningWallet -> LightningBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Nov 21, 2023
1 parent 48c15a7 commit 6d4e9ff
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 218 deletions.
6 changes: 1 addition & 5 deletions cashu/lightning/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from pydantic import BaseModel

from ..core.base import Method, Unit


class StatusResponse(BaseModel):
error_message: Optional[str]
Expand Down Expand Up @@ -61,9 +59,7 @@ def __str__(self) -> str:
return "unknown (should never happen)"


class LightningWallet(ABC):
unit: Unit
method: Method
class LightningBackend(ABC):

@abstractmethod
def status(self) -> Coroutine[None, None, StatusResponse]:
Expand Down
4 changes: 2 additions & 2 deletions cashu/lightning/corelightningrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..core.settings import settings
from .base import (
InvoiceResponse,
LightningWallet,
LightningBackend,
PaymentQuoteResponse,
PaymentResponse,
PaymentStatus,
Expand All @@ -25,7 +25,7 @@
from .macaroon import load_macaroon


class CoreLightningRestWallet(LightningWallet):
class CoreLightningRestWallet(LightningBackend):
def __init__(self):
macaroon = settings.mint_corelightning_rest_macaroon
assert macaroon, "missing cln-rest macaroon"
Expand Down
8 changes: 2 additions & 6 deletions cashu/lightning/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,21 @@
encode,
)

from ..core.base import Method, Unit
from ..core.helpers import fee_reserve
from ..core.settings import settings
from .base import (
InvoiceResponse,
LightningWallet,
LightningBackend,
PaymentQuoteResponse,
PaymentResponse,
PaymentStatus,
StatusResponse,
)


class FakeWallet(LightningWallet):
class FakeWallet(LightningBackend):
"""https://github.com/lnbits/lnbits"""

method = Method.bolt11
unit = Unit.sat

queue: asyncio.Queue[Bolt11] = asyncio.Queue(0)
payment_secrets: Dict[str, str] = dict()
paid_invoices: Set[str] = set()
Expand Down
4 changes: 2 additions & 2 deletions cashu/lightning/lnbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
from ..core.settings import settings
from .base import (
InvoiceResponse,
LightningWallet,
LightningBackend,
PaymentQuoteResponse,
PaymentResponse,
PaymentStatus,
StatusResponse,
)


class LNbitsWallet(LightningWallet):
class LNbitsWallet(LightningBackend):
"""https://github.com/lnbits/lnbits"""

def __init__(self):
Expand Down
4 changes: 2 additions & 2 deletions cashu/lightning/lndrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..core.settings import settings
from .base import (
InvoiceResponse,
LightningWallet,
LightningBackend,
PaymentQuoteResponse,
PaymentResponse,
PaymentStatus,
Expand All @@ -24,7 +24,7 @@
from .macaroon import load_macaroon


class LndRestWallet(LightningWallet):
class LndRestWallet(LightningBackend):
"""https://api.lightning.community/rest/index.html#lnd-rest-api-reference"""

def __init__(self):
Expand Down
4 changes: 2 additions & 2 deletions cashu/lightning/strike.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
from ..core.settings import settings
from .base import (
InvoiceResponse,
LightningWallet,
LightningBackend,
PaymentQuoteResponse,
PaymentResponse,
PaymentStatus,
StatusResponse,
)


class StrikeUSDWallet(LightningWallet):
class StrikeUSDWallet(LightningBackend):
"""https://github.com/lnbits/lnbits"""

method = Method.bolt11
Expand Down
33 changes: 3 additions & 30 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from ..core.split import amount_split
from ..lightning.base import (
InvoiceResponse,
LightningWallet,
LightningBackend,
PaymentQuoteResponse,
PaymentStatus,
)
Expand All @@ -46,7 +46,7 @@


class Ledger(LedgerVerification, LedgerSpendingConditions):
backends: Mapping[Method, Mapping[Unit, LightningWallet]] = {}
backends: Mapping[Method, Mapping[Unit, LightningBackend]] = {}
locks: Dict[str, asyncio.Lock] = {} # holds multiprocessing locks
proofs_pending_lock: asyncio.Lock = (
asyncio.Lock()
Expand All @@ -57,7 +57,7 @@ def __init__(
self,
db: Database,
seed: str,
backends: Mapping[Method, Mapping[Unit, LightningWallet]],
backends: Mapping[Method, Mapping[Unit, LightningBackend]],
derivation_path="",
crud=LedgerCrudSqlite(),
):
Expand Down Expand Up @@ -430,33 +430,6 @@ async def melt_quote(
unit
].get_payment_quote(melt_quote.request)

if unit == Unit.msat:
payment_quote.amount = payment_quote.amount * 1000
payment_quote.fee = payment_quote.fee * 1000

# amount = invoice_amount_sat
# checking_id = invoice_obj.payment_hash

# if unit == Unit.sat:
# # Lightning
# fee_reserve_sat = await self._get_lightning_fees(melt_quote.request)
# amount = invoice_amount_sat
# checking_id = invoice_obj.payment_hash
# elif unit == Unit.usd:
# fee_reserve_sat = 0
# amount = int(invoice_amount_sat / 3400)
# checking_id = invoice_obj.payment_hash
# elif unit == Unit.cheese:
# fee_reserve_sat = 2
# amount = int(invoice_amount_sat / 2)
# checking_id = invoice_obj.payment_hash
# elif unit == Unit.msat:
# fee_reserve_sat = 0
# amount = invoice_amount_sat * 1000
# checking_id = invoice_obj.payment_hash
# else:
# raise NotAllowedError(f"Melt quote: {melt_quote.unit} unit not supported.")

# NOTE: We do not store the fee reserve in the database.
quote = MeltQuote(
quote=random_hash(),
Expand Down
167 changes: 0 additions & 167 deletions cashu/mint/lightning.py

This file was deleted.

4 changes: 2 additions & 2 deletions cashu/mint/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ..core.base import MintKeyset, Unit
from ..core.db import Database
from ..lightning.base import LightningWallet
from ..lightning.base import LightningBackend
from ..mint.crud import LedgerCrud


Expand All @@ -12,7 +12,7 @@ class SupportsKeysets(Protocol):


class SupportLightning(Protocol):
lightning: Dict[Unit, LightningWallet]
lightning: Dict[Unit, LightningBackend]


class SupportsDb(Protocol):
Expand Down

0 comments on commit 6d4e9ff

Please sign in to comment.