Skip to content

Commit

Permalink
add hints and remove logs
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Oct 6, 2023
1 parent 9b79746 commit b1cbb50
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
34 changes: 22 additions & 12 deletions cashu/mint/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,47 @@ async def get_keyset(self, *args, **kwags):
pass

@abstractmethod
async def get_lightning_invoice(self, *args, **kwags):
async def get_lightning_invoice(self, *args, **kwags) -> Optional[Invoice]:
pass

async def get_secrets_used(self, *args, **kwags):
@abstractmethod
async def get_secrets_used(self, *args, **kwags) -> List[str]:
pass

async def invalidate_proof(self, *args, **kwags):
@abstractmethod
async def invalidate_proof(self, *args, **kwags) -> None:
pass

async def get_proofs_pending(self, *args, **kwags):
@abstractmethod
async def get_proofs_pending(self, *args, **kwags) -> List[Proof]:
pass

async def set_proof_pending(self, *args, **kwags):
@abstractmethod
async def set_proof_pending(self, *args, **kwags) -> None:
pass

async def unset_proof_pending(self, *args, **kwags):
@abstractmethod
async def unset_proof_pending(self, *args, **kwags) -> None:
pass

async def store_keyset(self, *args, **kwags):
@abstractmethod
async def store_keyset(self, *args, **kwags) -> None:
pass

async def store_lightning_invoice(self, *args, **kwags):
@abstractmethod
async def store_lightning_invoice(self, *args, **kwags) -> None:
pass

async def store_promise(self, *args, **kwags):
@abstractmethod
async def store_promise(self, *args, **kwags) -> None:
pass

async def get_promise(self, *args, **kwags):
@abstractmethod
async def get_promise(self, *args, **kwags) -> Optional[BlindedSignature]:
pass

async def update_lightning_invoice(self, *args, **kwags):
@abstractmethod
async def update_lightning_invoice(self, *args, **kwags) -> None:
pass


Expand All @@ -63,7 +73,7 @@ async def store_promise(
e: str = "",
s: str = "",
conn: Optional[Connection] = None,
):
) -> None:
await (conn or db).execute(
f"""
INSERT INTO {table_with_schema(db, 'promises')}
Expand Down
15 changes: 8 additions & 7 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(
self.derivation_path = derivation_path

self.db = db
self.crud = crud
self.crud = crud()
self.lightning = lightning
self.pubkey = derive_pubkey(self.master_key)
self.keysets = MintKeysets([])
Expand Down Expand Up @@ -385,14 +385,15 @@ async def request_mint(self, amount: int) -> Tuple[str, str]:

async def mint(
self,
B_s: List[BlindedMessage],
*,
outputs: List[BlindedMessage],
id: Optional[str] = None,
keyset: Optional[MintKeyset] = None,
) -> List[BlindedSignature]:
"""Mints a promise for coins for B_.
"""Mints new coins if payment `id` was successful. Ingest blind messages `outputs` and returns blind signatures `promises`.
Args:
B_s (List[BlindedMessage]): Outputs (blinded messages) to sign.
outputs (List[BlindedMessage]): Outputs (blinded messages) to sign.
id (Optional[str], optional): Id of (paid) Lightning invoice. Defaults to None.
keyset (Optional[MintKeyset], optional): Keyset to use. If not provided, uses active keyset. Defaults to None.
Expand All @@ -406,7 +407,7 @@ async def mint(
List[BlindedSignature]: Signatures on the outputs.
"""
logger.trace("called mint")
amount_outputs = sum([b.amount for b in B_s])
amount_outputs = sum([b.amount for b in outputs])

if settings.lightning:
if not id:
Expand All @@ -425,9 +426,9 @@ async def mint(
)
del self.locks[id]

self._verify_outputs(B_s)
self._verify_outputs(outputs)

promises = await self._generate_promises(B_s, keyset)
promises = await self._generate_promises(outputs, keyset)
logger.trace("generated promises")
return promises

Expand Down
2 changes: 1 addition & 1 deletion cashu/mint/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async def mint(
"""
logger.trace(f"> POST /mint: {payload}")

promises = await ledger.mint(payload.outputs, id=payload.id)
promises = await ledger.mint(outputs=payload.outputs, id=payload.id)
blinded_signatures = PostMintResponse(promises=promises)
logger.trace(f"< POST /mint: {blinded_signatures}")
return blinded_signatures
Expand Down
2 changes: 1 addition & 1 deletion cashu/wallet/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def redeem_TokenV3_multimint(wallet: Wallet, token: TokenV3):
t.mint, os.path.join(settings.cashu_dir, wallet.name)
)
keysets = mint_wallet._get_proofs_keysets(t.proofs)
logger.debug(f"Keysets in tokens: {keysets}")
logger.trace(f"Keysets in tokens: {keysets}")
# loop over all keysets
for keyset in set(keysets):
await mint_wallet.load_mint()
Expand Down
4 changes: 2 additions & 2 deletions cashu/wallet/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ async def _init_private_key(self, from_mnemonic: Optional[str] = None) -> None:
self.seed = mnemo.to_seed(mnemonic_str)
self.mnemonic = mnemonic_str

logger.debug(f"Using seed: {self.seed.hex()}")
logger.debug(f"Using mnemonic: {mnemonic_str}")
# logger.debug(f"Using seed: {self.seed.hex()}")
# logger.debug(f"Using mnemonic: {mnemonic_str}")

# if no mnemonic was in the database, store the new one
if ret_db is None:
Expand Down

0 comments on commit b1cbb50

Please sign in to comment.