Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dlc
Browse files Browse the repository at this point in the history
  • Loading branch information
lollerfirst committed Jul 29, 2024
2 parents ffa6858 + e14dc6d commit 30ebc3f
Show file tree
Hide file tree
Showing 25 changed files with 25,319 additions and 208 deletions.
24 changes: 19 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,31 @@ MINT_DATABASE=data/mint
# MINT_DATABASE=postgres://cashu:cashu@localhost:5432/cashu

# Funding source backends
# Supported: FakeWallet, LndRestWallet, CLNRestWallet, BlinkWallet, LNbitsWallet, StrikeWallet, CoreLightningRestWallet (deprecated)
# Set one funding source backend for each unit
# Supported: FakeWallet, LndRestWallet, LndRPCWallet, CLNRestWallet, BlinkWallet, LNbitsWallet, StrikeWallet, CoreLightningRestWallet (deprecated)

MINT_BACKEND_BOLT11_SAT=FakeWallet
# Only works if a usd derivation path is set
# MINT_BACKEND_BOLT11_SAT=FakeWallet
# MINT_BACKEND_BOLT11_USD=FakeWallet
# MINT_BACKEND_BOLT11_EUR=FakeWallet

# for use with LNbitsWallet
MINT_LNBITS_ENDPOINT=https://legend.lnbits.com
MINT_LNBITS_KEY=yourkeyasdasdasd
# Funding source settings

# Use with LndRPCWallet
MINT_LND_RPC_ENDPOINT=localhost:10009
MINT_LND_RPC_CERT="/path/to/tls.cert"
MINT_LND_RPC_MACAROON="/path/to/admin.macaroon"

# Use with LndRestWallet
MINT_LND_REST_ENDPOINT=https://127.0.0.1:8086
MINT_LND_REST_CERT="/home/lnd/.lnd/tls.cert"
MINT_LND_REST_MACAROON="/home/lnd/.lnd/data/chain/bitcoin/regtest/admin.macaroon"
MINT_LND_REST_CERT_VERIFY=True

# Use with LND
# This setting enables MPP support for Partial multi-path payments (NUT-15)
MINT_LND_ENABLE_MPP=TRUE

# Use with CLNRestWallet
MINT_CLNREST_URL=https://localhost:3010
MINT_CLNREST_CERT="./clightning-2/regtest/ca.pem"
Expand All @@ -86,6 +96,10 @@ MINT_CORELIGHTNING_REST_URL=https://localhost:3001
MINT_CORELIGHTNING_REST_MACAROON="./clightning-rest/access.macaroon"
MINT_CORELIGHTNING_REST_CERT="./clightning-2-rest/certificate.pem"

# Use with LNbitsWallet
MINT_LNBITS_ENDPOINT=https://legend.lnbits.com
MINT_LNBITS_KEY=yourkeyasdasdasd

# Use with BlinkWallet
MINT_BLINK_KEY=blink_abcdefgh

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
python-version: ["3.10"]
poetry-version: ["1.7.1"]
backend-wallet-class:
["LndRestWallet", "CLNRestWallet", "CoreLightningRestWallet", "LNbitsWallet"]
["LndRPCWallet", "LndRestWallet", "CLNRestWallet", "CoreLightningRestWallet", "LNbitsWallet"]
mint-database: ["./test_data/test_mint", "postgres://cashu:cashu@localhost:5432/cashu"]
# mint-database: ["./test_data/test_mint"]
with:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/regtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ jobs:
MINT_TEST_DATABASE: ${{ inputs.mint-database }}
TOR: false
MINT_BACKEND_BOLT11_SAT: ${{ inputs.backend-wallet-class }}
# LNbits wallet
MINT_LNBITS_ENDPOINT: http://localhost:5001
MINT_LNBITS_KEY: d08a3313322a4514af75d488bcc27eee
# LndRestWallet
MINT_LND_REST_ENDPOINT: https://localhost:8081/
MINT_LND_REST_CERT: ./regtest/data/lnd-3/tls.cert
MINT_LND_REST_MACAROON: ./regtest/data/lnd-3/data/chain/bitcoin/regtest/admin.macaroon
# LndRPCWallet
MINT_LND_RPC_ENDPOINT: localhost:10009
MINT_LND_RPC_CERT: ./regtest/data/lnd-3/tls.cert
MINT_LND_RPC_MACAROON: ./regtest/data/lnd-3/data/chain/bitcoin/regtest/admin.macaroon

MINT_LND_ENABLE_MPP: true
# LND_GRPC_ENDPOINT: localhost
# LND_GRPC_PORT: 10009
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Cashu is a free and open-source [Ecash protocol](https://github.com/cashubtc/nut
## The Cashu protocol
Different Cashu clients and mints use the same protocol to achieve interoperability. See the [documentation page](https://docs.cashu.space/) for more information on other projects. If you are interested in developing on your own Cashu project, please refer to the protocol specs [protocol specs](https://github.com/cashubtc/nuts).

## Easy Install
## Easy Install: Nutshell wallet

The easiest way to use Cashu is to install the package it via pip:
```bash
Expand All @@ -51,6 +51,18 @@ If you have problems running the command above on Ubuntu, run `sudo apt install

You can skip the entire next section about Poetry and jump right to [Using Cashu](#using-cashu).

## Easy Install: Nutshell mint

The easiest way to get a mint running is through Docker.

You can build the image yourself by running the following command. Make sure to adjust the environment variables in `docker-compose.yaml`.

```bash
docker compose up mint
```

Alternatively, you can use the pre-built Docker images, see [Running a mint](#docker).

## Manual install: Poetry
These steps help you install Python via pyenv and Poetry. If you already have Poetry running on your computer, you can skip this step and jump right to [Install Cashu](#poetry-install-cashu).

Expand Down
4 changes: 4 additions & 0 deletions cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,8 @@ def serialize(self, include_dleq=False) -> str:
self.serialize_to_dict(include_dleq), separators=(",", ":")
).encode()
).decode()
# remove padding
tokenv3_serialized = tokenv3_serialized.rstrip("=")
return tokenv3_serialized

@classmethod
Expand Down Expand Up @@ -1149,6 +1151,8 @@ def serialize(self, include_dleq=False) -> str:
tokenv4_serialized += base64.urlsafe_b64encode(
cbor2.dumps(self.serialize_to_dict(include_dleq))
).decode()
# remove padding
tokenv4_serialized = tokenv4_serialized.rstrip("=")
return tokenv4_serialized

@classmethod
Expand Down
5 changes: 5 additions & 0 deletions cashu/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ class LndRestFundingSource(MintSettings):
mint_lnd_rest_invoice_macaroon: Optional[str] = Field(default=None)
mint_lnd_enable_mpp: bool = Field(default=False)

class LndRPCFundingSource(MintSettings):
mint_lnd_rpc_endpoint: Optional[str] = Field(default=None)
mint_lnd_rpc_cert: Optional[str] = Field(default=None)
mint_lnd_rpc_macaroon: Optional[str] = Field(default=None)

class CLNRestFundingSource(MintSettings):
mint_clnrest_url: Optional[str] = Field(default=None)
Expand All @@ -217,6 +221,7 @@ class CoreLightningRestFundingSource(MintSettings):

class Settings(
EnvSettings,
LndRPCFundingSource,
LndRestFundingSource,
CoreLightningRestFundingSource,
CLNRestFundingSource,
Expand Down
1 change: 1 addition & 0 deletions cashu/lightning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .corelightningrest import CoreLightningRestWallet # noqa: F401
from .fake import FakeWallet # noqa: F401
from .lnbits import LNbitsWallet # noqa: F401
from .lnd_grpc.lnd_grpc import LndRPCWallet # noqa: F401
from .lndrest import LndRestWallet # noqa: F401
from .strike import StrikeWallet # noqa: F401

Expand Down
41 changes: 40 additions & 1 deletion cashu/lightning/lnbits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# type: ignore
import asyncio
import json
from typing import AsyncGenerator, Optional

import httpx
Expand All @@ -25,6 +27,7 @@ class LNbitsWallet(LightningBackend):

supported_units = set([Unit.sat])
unit = Unit.sat
supports_incoming_payment_stream: bool = True

def __init__(self, unit: Unit = Unit.sat, **kwargs):
self.assert_unit_supported(unit)
Expand Down Expand Up @@ -184,4 +187,40 @@ async def get_payment_quote(
)

async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
raise NotImplementedError("paid_invoices_stream not implemented")
url = f"{self.endpoint}/api/v1/payments/sse"

try:
sse_headers = self.client.headers.copy()
sse_headers.update(
{
"accept": "text/event-stream",
"cache-control": "no-cache",
"connection": "keep-alive",
}
)
async with self.client.stream(
"GET",
url,
content="text/event-stream",
timeout=None,
headers=sse_headers,
) as r:
sse_trigger = False
async for line in r.aiter_lines():
# The data we want to listen to is of this shape:
# event: payment-received
# data: {.., "payment_hash" : "asd"}
if line.startswith("event: payment-received"):
sse_trigger = True
continue
elif sse_trigger and line.startswith("data:"):
data = json.loads(line[len("data:") :])
sse_trigger = False
yield data["payment_hash"]
else:
sse_trigger = False

except (OSError, httpx.ReadError, httpx.ConnectError, httpx.ReadTimeout):
pass

await asyncio.sleep(1)
Loading

0 comments on commit 30ebc3f

Please sign in to comment.