mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 10:34:20 +01:00
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
This commit is contained in:
@@ -5,8 +5,8 @@ from typing import Any, Dict, List, Optional, TypedDict, Union
|
|||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from cashu.core.crypto import derive_keys, derive_keyset_id, derive_pubkeys
|
from ..core.crypto import derive_keys, derive_keyset_id, derive_pubkeys
|
||||||
from cashu.core.secp import PrivateKey, PublicKey
|
from ..core.secp import PrivateKey, PublicKey
|
||||||
|
|
||||||
# ------- PROOFS -------
|
# ------- PROOFS -------
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import base64
|
|||||||
import hashlib
|
import hashlib
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from cashu.core.secp import PrivateKey, PublicKey
|
from ..core.secp import PrivateKey, PublicKey
|
||||||
from cashu.core.settings import settings
|
from ..core.settings import settings
|
||||||
|
|
||||||
# entropy = bytes([random.getrandbits(8) for i in range(16)])
|
# entropy = bytes([random.getrandbits(8) for i in range(16)])
|
||||||
# mnemonic = bip39.mnemonic_from_bytes(entropy)
|
# mnemonic = bip39.mnemonic_from_bytes(entropy)
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import asyncio
|
|||||||
from functools import partial, wraps
|
from functools import partial, wraps
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from cashu.core.base import Proof
|
from ..core.base import Proof
|
||||||
from cashu.core.settings import settings
|
from ..core.settings import settings
|
||||||
|
|
||||||
|
|
||||||
def sum_proofs(proofs: List[Proof]):
|
def sum_proofs(proofs: List[Proof]):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from cashu.core.db import COCKROACH, POSTGRES, SQLITE, Database
|
from ..core.db import COCKROACH, POSTGRES, SQLITE, Database
|
||||||
|
|
||||||
|
|
||||||
def table_with_schema(db, table: str):
|
def table_with_schema(db, table: str):
|
||||||
@@ -35,6 +35,7 @@ async def migrate_databases(db: Database, migrations_module):
|
|||||||
await set_migration_version(conn, db_name, version)
|
await set_migration_version(conn, db_name, version)
|
||||||
|
|
||||||
async with db.connect() as conn:
|
async with db.connect() as conn:
|
||||||
|
exists = None
|
||||||
if conn.type == SQLITE:
|
if conn.type == SQLITE:
|
||||||
exists = await conn.fetchone(
|
exists = await conn.fetchone(
|
||||||
f"SELECT * FROM sqlite_master WHERE type='table' AND name='{table_with_schema(db, 'dbversions')}'"
|
f"SELECT * FROM sqlite_master WHERE type='table' AND name='{table_with_schema(db, 'dbversions')}'"
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import random
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import AsyncGenerator, Dict, Optional, Set
|
from typing import AsyncGenerator, Dict, Optional, Set
|
||||||
|
|
||||||
from cashu.core.bolt11 import Invoice, decode, encode
|
from ..core.bolt11 import Invoice, decode, encode
|
||||||
|
|
||||||
from .base import (
|
from .base import (
|
||||||
InvoiceResponse,
|
InvoiceResponse,
|
||||||
PaymentResponse,
|
PaymentResponse,
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ from typing import Dict, Optional
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from cashu.core.settings import settings
|
from ..core.settings import settings
|
||||||
|
|
||||||
from .base import (
|
from .base import (
|
||||||
InvoiceResponse,
|
InvoiceResponse,
|
||||||
PaymentResponse,
|
PaymentResponse,
|
||||||
@@ -110,7 +109,6 @@ class LNbitsWallet(Wallet):
|
|||||||
|
|
||||||
async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
||||||
try:
|
try:
|
||||||
|
|
||||||
r = self.s.get(
|
r = self.s.get(
|
||||||
url=f"{self.endpoint}/api/v1/payments/{checking_id}",
|
url=f"{self.endpoint}/api/v1/payments/{checking_id}",
|
||||||
headers=self.key,
|
headers=self.key,
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ from starlette.middleware import Middleware
|
|||||||
from starlette.middleware.base import BaseHTTPMiddleware
|
from starlette.middleware.base import BaseHTTPMiddleware
|
||||||
from starlette.middleware.cors import CORSMiddleware
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
from cashu.core.settings import settings
|
from ..core.settings import settings
|
||||||
|
|
||||||
from .router import router
|
from .router import router
|
||||||
from .startup import start_mint_init
|
from .startup import start_mint_init
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import time
|
import time
|
||||||
from typing import Any, List, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from cashu.core.base import Invoice, MintKeyset, Proof
|
from ..core.base import Invoice, MintKeyset, Proof
|
||||||
from cashu.core.db import Connection, Database
|
from ..core.db import Connection, Database
|
||||||
from cashu.core.migrations import table_with_schema
|
from ..core.migrations import table_with_schema
|
||||||
|
|
||||||
|
|
||||||
class LedgerCrud:
|
class LedgerCrud:
|
||||||
@@ -14,48 +14,37 @@ class LedgerCrud:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
async def get_keyset(*args, **kwags):
|
async def get_keyset(*args, **kwags):
|
||||||
|
return await get_keyset(*args, **kwags) # type: ignore
|
||||||
return await get_keyset(*args, **kwags)
|
|
||||||
|
|
||||||
async def get_lightning_invoice(*args, **kwags):
|
async def get_lightning_invoice(*args, **kwags):
|
||||||
|
return await get_lightning_invoice(*args, **kwags) # type: ignore
|
||||||
return await get_lightning_invoice(*args, **kwags)
|
|
||||||
|
|
||||||
async def get_proofs_used(*args, **kwags):
|
async def get_proofs_used(*args, **kwags):
|
||||||
|
return await get_proofs_used(*args, **kwags) # type: ignore
|
||||||
return await get_proofs_used(*args, **kwags)
|
|
||||||
|
|
||||||
async def invalidate_proof(*args, **kwags):
|
async def invalidate_proof(*args, **kwags):
|
||||||
|
return await invalidate_proof(*args, **kwags) # type: ignore
|
||||||
return await invalidate_proof(*args, **kwags)
|
|
||||||
|
|
||||||
async def get_proofs_pending(*args, **kwags):
|
async def get_proofs_pending(*args, **kwags):
|
||||||
|
return await get_proofs_pending(*args, **kwags) # type: ignore
|
||||||
return await get_proofs_pending(*args, **kwags)
|
|
||||||
|
|
||||||
async def set_proof_pending(*args, **kwags):
|
async def set_proof_pending(*args, **kwags):
|
||||||
|
return await set_proof_pending(*args, **kwags) # type: ignore
|
||||||
return await set_proof_pending(*args, **kwags)
|
|
||||||
|
|
||||||
async def unset_proof_pending(*args, **kwags):
|
async def unset_proof_pending(*args, **kwags):
|
||||||
|
return await unset_proof_pending(*args, **kwags) # type: ignore
|
||||||
return await unset_proof_pending(*args, **kwags)
|
|
||||||
|
|
||||||
async def store_keyset(*args, **kwags):
|
async def store_keyset(*args, **kwags):
|
||||||
|
return await store_keyset(*args, **kwags) # type: ignore
|
||||||
return await store_keyset(*args, **kwags)
|
|
||||||
|
|
||||||
async def store_lightning_invoice(*args, **kwags):
|
async def store_lightning_invoice(*args, **kwags):
|
||||||
|
return await store_lightning_invoice(*args, **kwags) # type: ignore
|
||||||
return await store_lightning_invoice(*args, **kwags)
|
|
||||||
|
|
||||||
async def store_promise(*args, **kwags):
|
async def store_promise(*args, **kwags):
|
||||||
|
return await store_promise(*args, **kwags) # type: ignore
|
||||||
return await store_promise(*args, **kwags)
|
|
||||||
|
|
||||||
async def update_lightning_invoice(*args, **kwags):
|
async def update_lightning_invoice(*args, **kwags):
|
||||||
|
return await update_lightning_invoice(*args, **kwags) # type: ignore
|
||||||
return await update_lightning_invoice(*args, **kwags)
|
|
||||||
|
|
||||||
|
|
||||||
async def store_promise(
|
async def store_promise(
|
||||||
@@ -65,7 +54,6 @@ async def store_promise(
|
|||||||
C_: str,
|
C_: str,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO {table_with_schema(db, 'promises')}
|
INSERT INTO {table_with_schema(db, 'promises')}
|
||||||
@@ -84,7 +72,6 @@ async def get_proofs_used(
|
|||||||
db: Database,
|
db: Database,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
rows = await (conn or db).fetchall(
|
rows = await (conn or db).fetchall(
|
||||||
f"""
|
f"""
|
||||||
SELECT secret from {table_with_schema(db, 'proofs_used')}
|
SELECT secret from {table_with_schema(db, 'proofs_used')}
|
||||||
@@ -98,7 +85,6 @@ async def invalidate_proof(
|
|||||||
proof: Proof,
|
proof: Proof,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
# we add the proof and secret to the used list
|
# we add the proof and secret to the used list
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
f"""
|
f"""
|
||||||
@@ -118,7 +104,6 @@ async def get_proofs_pending(
|
|||||||
db: Database,
|
db: Database,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
rows = await (conn or db).fetchall(
|
rows = await (conn or db).fetchall(
|
||||||
f"""
|
f"""
|
||||||
SELECT * from {table_with_schema(db, 'proofs_pending')}
|
SELECT * from {table_with_schema(db, 'proofs_pending')}
|
||||||
@@ -132,7 +117,6 @@ async def set_proof_pending(
|
|||||||
proof: Proof,
|
proof: Proof,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
# we add the proof and secret to the used list
|
# we add the proof and secret to the used list
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
f"""
|
f"""
|
||||||
@@ -153,7 +137,6 @@ async def unset_proof_pending(
|
|||||||
db: Database,
|
db: Database,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
f"""
|
f"""
|
||||||
DELETE FROM {table_with_schema(db, 'proofs_pending')}
|
DELETE FROM {table_with_schema(db, 'proofs_pending')}
|
||||||
@@ -168,7 +151,6 @@ async def store_lightning_invoice(
|
|||||||
invoice: Invoice,
|
invoice: Invoice,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO {table_with_schema(db, 'invoices')}
|
INSERT INTO {table_with_schema(db, 'invoices')}
|
||||||
@@ -189,7 +171,6 @@ async def get_lightning_invoice(
|
|||||||
hash: str,
|
hash: str,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
row = await (conn or db).fetchone(
|
row = await (conn or db).fetchone(
|
||||||
f"""
|
f"""
|
||||||
SELECT * from {table_with_schema(db, 'invoices')}
|
SELECT * from {table_with_schema(db, 'invoices')}
|
||||||
@@ -220,7 +201,6 @@ async def store_keyset(
|
|||||||
keyset: MintKeyset,
|
keyset: MintKeyset,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
await (conn or db).execute( # type: ignore
|
await (conn or db).execute( # type: ignore
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO {table_with_schema(db, 'keysets')}
|
INSERT INTO {table_with_schema(db, 'keysets')}
|
||||||
@@ -241,7 +221,7 @@ async def store_keyset(
|
|||||||
|
|
||||||
async def get_keyset(
|
async def get_keyset(
|
||||||
db: Database,
|
db: Database,
|
||||||
id: str = None,
|
id: str = "",
|
||||||
derivation_path: str = "",
|
derivation_path: str = "",
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ from typing import Dict, List, Literal, Optional, Set, Union
|
|||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
import cashu.core.b_dhke as b_dhke
|
from ..core import b_dhke as b_dhke
|
||||||
import cashu.core.bolt11 as bolt11
|
from ..core import bolt11 as bolt11
|
||||||
import cashu.core.legacy as legacy
|
from ..core import legacy as legacy
|
||||||
from cashu.core.base import (
|
from ..core.base import (
|
||||||
BlindedMessage,
|
BlindedMessage,
|
||||||
BlindedSignature,
|
BlindedSignature,
|
||||||
Invoice,
|
Invoice,
|
||||||
@@ -14,15 +14,15 @@ from cashu.core.base import (
|
|||||||
MintKeysets,
|
MintKeysets,
|
||||||
Proof,
|
Proof,
|
||||||
)
|
)
|
||||||
from cashu.core.crypto import derive_pubkey
|
from ..core.crypto import derive_pubkey
|
||||||
from cashu.core.db import Database
|
from ..core.db import Database
|
||||||
from cashu.core.helpers import fee_reserve, sum_proofs
|
from ..core.helpers import fee_reserve, sum_proofs
|
||||||
from cashu.core.script import verify_script
|
from ..core.script import verify_script
|
||||||
from cashu.core.secp import PublicKey
|
from ..core.secp import PublicKey
|
||||||
from cashu.core.settings import settings
|
from ..core.settings import settings
|
||||||
from cashu.core.split import amount_split
|
from ..core.split import amount_split
|
||||||
from cashu.lightning.base import Wallet
|
from ..lightning.base import Wallet
|
||||||
from cashu.mint.crud import LedgerCrud
|
from ..mint.crud import LedgerCrud
|
||||||
|
|
||||||
|
|
||||||
class Ledger:
|
class Ledger:
|
||||||
@@ -449,6 +449,7 @@ class Ledger:
|
|||||||
invoice_amount: int,
|
invoice_amount: int,
|
||||||
ln_fee_msat: int,
|
ln_fee_msat: int,
|
||||||
outputs: List[BlindedMessage],
|
outputs: List[BlindedMessage],
|
||||||
|
keyset: Optional[MintKeyset] = None,
|
||||||
):
|
):
|
||||||
"""Generates a set of new promises (blinded signatures) from a set of blank outputs
|
"""Generates a set of new promises (blinded signatures) from a set of blank outputs
|
||||||
(outputs with no or ignored amount) by looking at the difference between the Lightning
|
(outputs with no or ignored amount) by looking at the difference between the Lightning
|
||||||
@@ -497,7 +498,7 @@ class Ledger:
|
|||||||
outputs[i].amount = return_amounts_sorted[i]
|
outputs[i].amount = return_amounts_sorted[i]
|
||||||
if not self._verify_no_duplicate_outputs(outputs):
|
if not self._verify_no_duplicate_outputs(outputs):
|
||||||
raise Exception("duplicate promises.")
|
raise Exception("duplicate promises.")
|
||||||
return_promises = await self._generate_promises(outputs)
|
return_promises = await self._generate_promises(outputs, keyset)
|
||||||
return return_promises
|
return return_promises
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import click
|
|||||||
import uvicorn
|
import uvicorn
|
||||||
from click import Context
|
from click import Context
|
||||||
|
|
||||||
from cashu.core.settings import settings
|
from ..core.settings import settings
|
||||||
|
|
||||||
|
|
||||||
@click.command(
|
@click.command(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from cashu.core.db import Database
|
from ..core.db import Database
|
||||||
from cashu.core.migrations import table_with_schema
|
from ..core.migrations import table_with_schema
|
||||||
|
|
||||||
|
|
||||||
async def m000_create_migrations_table(db):
|
async def m000_create_migrations_table(db):
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from typing import Dict, List, Union
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
from secp256k1 import PublicKey
|
from secp256k1 import PublicKey
|
||||||
|
|
||||||
from cashu.core.base import (
|
from ..core.base import (
|
||||||
BlindedMessage,
|
BlindedMessage,
|
||||||
BlindedSignature,
|
BlindedSignature,
|
||||||
CheckFeesRequest,
|
CheckFeesRequest,
|
||||||
@@ -21,9 +21,9 @@ from cashu.core.base import (
|
|||||||
PostSplitRequest,
|
PostSplitRequest,
|
||||||
PostSplitResponse,
|
PostSplitResponse,
|
||||||
)
|
)
|
||||||
from cashu.core.errors import CashuError
|
from ..core.errors import CashuError
|
||||||
from cashu.core.settings import settings
|
from ..core.settings import settings
|
||||||
from cashu.mint.startup import ledger
|
from ..mint.startup import ledger
|
||||||
|
|
||||||
router: APIRouter = APIRouter()
|
router: APIRouter = APIRouter()
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import importlib
|
|||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from cashu.core.db import Database
|
from ..core.db import Database
|
||||||
from cashu.core.migrations import migrate_databases
|
from ..core.migrations import migrate_databases
|
||||||
from cashu.core.settings import settings
|
from ..core.settings import settings
|
||||||
from cashu.lightning.fake import FakeWallet # type: ignore
|
from ..lightning.fake import FakeWallet # type: ignore
|
||||||
from cashu.lightning.lnbits import LNbitsWallet # type: ignore
|
from ..lightning.lnbits import LNbitsWallet # type: ignore
|
||||||
from cashu.mint import migrations
|
from ..mint import migrations
|
||||||
from cashu.mint.ledger import Ledger
|
from ..mint.ledger import Ledger
|
||||||
|
|
||||||
logger.debug("Enviroment Settings:")
|
logger.debug("Enviroment Settings:")
|
||||||
for key, value in settings.dict().items():
|
for key, value in settings.dict().items():
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ sys.tracebacklimit = None # type: ignore
|
|||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from cashu.core.settings import settings
|
from ..core.settings import settings
|
||||||
|
|
||||||
# configure logger
|
# configure logger
|
||||||
logger.remove()
|
logger.remove()
|
||||||
|
|||||||
0
cashu/wallet/cli/__init__.py
Normal file
0
cashu/wallet/cli/__init__.py
Normal file
@@ -18,21 +18,20 @@ import click
|
|||||||
from click import Context
|
from click import Context
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from cashu.core.base import Proof, TokenV1, TokenV2, TokenV3
|
from ...core.base import Proof, TokenV1, TokenV2, TokenV3
|
||||||
from cashu.core.helpers import sum_proofs
|
from ...core.helpers import sum_proofs
|
||||||
from cashu.core.migrations import migrate_databases
|
from ...core.migrations import migrate_databases
|
||||||
from cashu.core.settings import settings
|
from ...core.settings import settings
|
||||||
from cashu.nostr.nostr.client.client import NostrClient
|
from ...nostr.nostr.client.client import NostrClient
|
||||||
from cashu.tor.tor import TorProxy
|
from ...tor.tor import TorProxy
|
||||||
from cashu.wallet import migrations
|
from ...wallet import migrations
|
||||||
from cashu.wallet.crud import (
|
from ...wallet.crud import (
|
||||||
get_keyset,
|
get_keyset,
|
||||||
get_lightning_invoices,
|
get_lightning_invoices,
|
||||||
get_reserved_proofs,
|
get_reserved_proofs,
|
||||||
get_unused_locks,
|
get_unused_locks,
|
||||||
)
|
)
|
||||||
from cashu.wallet.wallet import Wallet as Wallet
|
from ...wallet.wallet import Wallet as Wallet
|
||||||
|
|
||||||
from .cli_helpers import (
|
from .cli_helpers import (
|
||||||
get_mint_wallet,
|
get_mint_wallet,
|
||||||
print_mint_balances,
|
print_mint_balances,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import click
|
|||||||
from click import Context
|
from click import Context
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from cashu.core.base import (
|
from ...core.base import (
|
||||||
Proof,
|
Proof,
|
||||||
TokenV1,
|
TokenV1,
|
||||||
TokenV2,
|
TokenV2,
|
||||||
@@ -15,10 +15,10 @@ from cashu.core.base import (
|
|||||||
TokenV3Token,
|
TokenV3Token,
|
||||||
WalletKeyset,
|
WalletKeyset,
|
||||||
)
|
)
|
||||||
from cashu.core.helpers import sum_proofs
|
from ...core.helpers import sum_proofs
|
||||||
from cashu.core.settings import settings
|
from ...core.settings import settings
|
||||||
from cashu.wallet.crud import get_keyset
|
from ...wallet.crud import get_keyset
|
||||||
from cashu.wallet.wallet import Wallet as Wallet
|
from ...wallet.wallet import Wallet as Wallet
|
||||||
|
|
||||||
|
|
||||||
async def verify_mint(mint_wallet: Wallet, url: str):
|
async def verify_mint(mint_wallet: Wallet, url: str):
|
||||||
|
|||||||
@@ -6,16 +6,13 @@ import click
|
|||||||
from click import Context
|
from click import Context
|
||||||
from requests.exceptions import ConnectionError
|
from requests.exceptions import ConnectionError
|
||||||
|
|
||||||
from cashu.core.settings import settings
|
from ...core.settings import settings
|
||||||
from cashu.nostr.nostr.client.client import NostrClient
|
from ...nostr.nostr.client.client import NostrClient
|
||||||
from cashu.nostr.nostr.event import Event
|
from ...nostr.nostr.event import Event
|
||||||
from cashu.nostr.nostr.key import PublicKey
|
from ...nostr.nostr.key import PublicKey
|
||||||
from cashu.wallet.cli.cli_helpers import get_mint_wallet
|
from ..crud import get_nostr_last_check_timestamp, set_nostr_last_check_timestamp
|
||||||
from cashu.wallet.crud import (
|
from ..wallet import Wallet
|
||||||
get_nostr_last_check_timestamp,
|
from .cli_helpers import get_mint_wallet
|
||||||
set_nostr_last_check_timestamp,
|
|
||||||
)
|
|
||||||
from cashu.wallet.wallet import Wallet
|
|
||||||
|
|
||||||
|
|
||||||
async def nip5_to_pubkey(wallet: Wallet, address: str):
|
async def nip5_to_pubkey(wallet: Wallet, address: str):
|
||||||
@@ -113,7 +110,7 @@ async def receive_nostr(ctx: Context, verbose: bool):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
# call the receive method
|
# call the receive method
|
||||||
from cashu.wallet.cli.cli import receive
|
from ...wallet.cli.cli import receive
|
||||||
|
|
||||||
asyncio.run(receive(ctx, decrypted_content, ""))
|
asyncio.run(receive(ctx, decrypted_content, ""))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import time
|
import time
|
||||||
from typing import Any, List, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from cashu.core.base import Invoice, KeyBase, P2SHScript, Proof, WalletKeyset
|
from ..core.base import Invoice, KeyBase, P2SHScript, Proof, WalletKeyset
|
||||||
from cashu.core.db import Connection, Database
|
from ..core.db import Connection, Database
|
||||||
|
|
||||||
|
|
||||||
async def store_proof(
|
async def store_proof(
|
||||||
@@ -10,7 +10,6 @@ async def store_proof(
|
|||||||
db: Database,
|
db: Database,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO proofs
|
INSERT INTO proofs
|
||||||
@@ -25,7 +24,6 @@ async def get_proofs(
|
|||||||
db: Database,
|
db: Database,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
rows = await (conn or db).fetchall(
|
rows = await (conn or db).fetchall(
|
||||||
"""
|
"""
|
||||||
SELECT * from proofs
|
SELECT * from proofs
|
||||||
@@ -38,7 +36,6 @@ async def get_reserved_proofs(
|
|||||||
db: Database,
|
db: Database,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
rows = await (conn or db).fetchall(
|
rows = await (conn or db).fetchall(
|
||||||
"""
|
"""
|
||||||
SELECT * from proofs
|
SELECT * from proofs
|
||||||
@@ -53,7 +50,6 @@ async def invalidate_proof(
|
|||||||
db: Database,
|
db: Database,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
f"""
|
f"""
|
||||||
DELETE FROM proofs
|
DELETE FROM proofs
|
||||||
@@ -75,8 +71,8 @@ async def invalidate_proof(
|
|||||||
async def update_proof_reserved(
|
async def update_proof_reserved(
|
||||||
proof: Proof,
|
proof: Proof,
|
||||||
reserved: bool,
|
reserved: bool,
|
||||||
send_id: str = None,
|
send_id: str = "",
|
||||||
db: Database = None,
|
db: Optional[Database] = None,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
clauses = []
|
clauses = []
|
||||||
@@ -104,7 +100,6 @@ async def secret_used(
|
|||||||
db: Database,
|
db: Database,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
rows = await (conn or db).fetchone(
|
rows = await (conn or db).fetchone(
|
||||||
"""
|
"""
|
||||||
SELECT * from proofs
|
SELECT * from proofs
|
||||||
@@ -120,7 +115,6 @@ async def store_p2sh(
|
|||||||
db: Database,
|
db: Database,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO p2sh
|
INSERT INTO p2sh
|
||||||
@@ -137,11 +131,10 @@ async def store_p2sh(
|
|||||||
|
|
||||||
|
|
||||||
async def get_unused_locks(
|
async def get_unused_locks(
|
||||||
address: str = None,
|
address: str = "",
|
||||||
db: Database = None,
|
db: Optional[Database] = None,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
clause: List[str] = []
|
clause: List[str] = []
|
||||||
args: List[str] = []
|
args: List[str] = []
|
||||||
|
|
||||||
@@ -168,7 +161,7 @@ async def get_unused_locks(
|
|||||||
async def update_p2sh_used(
|
async def update_p2sh_used(
|
||||||
p2sh: P2SHScript,
|
p2sh: P2SHScript,
|
||||||
used: bool,
|
used: bool,
|
||||||
db: Database = None,
|
db: Optional[Database] = None,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
clauses = []
|
clauses = []
|
||||||
@@ -184,11 +177,10 @@ async def update_p2sh_used(
|
|||||||
|
|
||||||
async def store_keyset(
|
async def store_keyset(
|
||||||
keyset: WalletKeyset,
|
keyset: WalletKeyset,
|
||||||
mint_url: str = None,
|
mint_url: str = "",
|
||||||
db: Database = None,
|
db: Optional[Database] = None,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
await (conn or db).execute( # type: ignore
|
await (conn or db).execute( # type: ignore
|
||||||
"""
|
"""
|
||||||
INSERT INTO keysets
|
INSERT INTO keysets
|
||||||
@@ -209,7 +201,7 @@ async def store_keyset(
|
|||||||
async def get_keyset(
|
async def get_keyset(
|
||||||
id: str = "",
|
id: str = "",
|
||||||
mint_url: str = "",
|
mint_url: str = "",
|
||||||
db: Database = None,
|
db: Optional[Database] = None,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
clauses = []
|
clauses = []
|
||||||
@@ -241,7 +233,6 @@ async def store_lightning_invoice(
|
|||||||
invoice: Invoice,
|
invoice: Invoice,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO invoices
|
INSERT INTO invoices
|
||||||
@@ -262,7 +253,7 @@ async def store_lightning_invoice(
|
|||||||
|
|
||||||
async def get_lightning_invoice(
|
async def get_lightning_invoice(
|
||||||
db: Database,
|
db: Database,
|
||||||
hash: str = None,
|
hash: str = "",
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
clauses = []
|
clauses = []
|
||||||
@@ -287,7 +278,7 @@ async def get_lightning_invoice(
|
|||||||
|
|
||||||
async def get_lightning_invoices(
|
async def get_lightning_invoices(
|
||||||
db: Database,
|
db: Database,
|
||||||
paid: bool = None,
|
paid: Optional[bool] = None,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
clauses: List[Any] = []
|
clauses: List[Any] = []
|
||||||
@@ -315,7 +306,7 @@ async def update_lightning_invoice(
|
|||||||
db: Database,
|
db: Database,
|
||||||
hash: str,
|
hash: str,
|
||||||
paid: bool,
|
paid: bool,
|
||||||
time_paid: int = None,
|
time_paid: Optional[int] = None,
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
):
|
):
|
||||||
clauses = []
|
clauses = []
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from cashu.core.db import Database
|
from ..core.db import Database
|
||||||
|
|
||||||
|
|
||||||
async def m000_create_migrations_table(db):
|
async def m000_create_migrations_table(db):
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ from typing import Dict, List, Optional
|
|||||||
import requests
|
import requests
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
import cashu.core.b_dhke as b_dhke
|
from ..core import b_dhke as b_dhke
|
||||||
import cashu.core.bolt11 as bolt11
|
from ..core import bolt11 as bolt11
|
||||||
from cashu.core.base import (
|
from ..core.base import (
|
||||||
BlindedMessage,
|
BlindedMessage,
|
||||||
BlindedSignature,
|
BlindedSignature,
|
||||||
CheckFeesRequest,
|
CheckFeesRequest,
|
||||||
@@ -35,20 +35,20 @@ from cashu.core.base import (
|
|||||||
TokenV3Token,
|
TokenV3Token,
|
||||||
WalletKeyset,
|
WalletKeyset,
|
||||||
)
|
)
|
||||||
from cashu.core.bolt11 import Invoice as InvoiceBolt11
|
from ..core.bolt11 import Invoice as InvoiceBolt11
|
||||||
from cashu.core.db import Database
|
from ..core.db import Database
|
||||||
from cashu.core.helpers import sum_proofs
|
from ..core.helpers import sum_proofs
|
||||||
from cashu.core.script import (
|
from ..core.script import (
|
||||||
step0_carol_checksig_redeemscrip,
|
step0_carol_checksig_redeemscrip,
|
||||||
step0_carol_privkey,
|
step0_carol_privkey,
|
||||||
step1_carol_create_p2sh_address,
|
step1_carol_create_p2sh_address,
|
||||||
step2_carol_sign_tx,
|
step2_carol_sign_tx,
|
||||||
)
|
)
|
||||||
from cashu.core.secp import PrivateKey, PublicKey
|
from ..core.secp import PrivateKey, PublicKey
|
||||||
from cashu.core.settings import settings
|
from ..core.settings import settings
|
||||||
from cashu.core.split import amount_split
|
from ..core.split import amount_split
|
||||||
from cashu.tor.tor import TorProxy
|
from ..tor.tor import TorProxy
|
||||||
from cashu.wallet.crud import (
|
from ..wallet.crud import (
|
||||||
get_keyset,
|
get_keyset,
|
||||||
get_proofs,
|
get_proofs,
|
||||||
invalidate_proof,
|
invalidate_proof,
|
||||||
|
|||||||
Reference in New Issue
Block a user