From 0840ee184cd78ddd21263e48477e0d1d352b4b28 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 24 Dec 2022 15:43:48 +0100 Subject: [PATCH] fix typing --- cashu/wallet/wallet.py | 18 +++++++++--------- tests/test_wallet.py | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index 5d4e31a..1319448 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -5,7 +5,7 @@ import secrets as scrts import time import uuid from itertools import groupby -from typing import Dict, List +from typing import Dict, List, Optional import requests from loguru import logger @@ -55,7 +55,7 @@ from cashu.wallet.crud import ( class LedgerAPI: - keys: Dict[int, str] + keys: Dict[int, PublicKey] keyset: str tor: TorProxy db: Database @@ -133,7 +133,7 @@ class LedgerAPI: assert len(keyset.public_keys) > 0, "did not receive keys from mint." # check if current keyset is in db - keyset_local: WalletKeyset = await get_keyset(keyset.id, db=self.db) + keyset_local: Optional[WalletKeyset] = await get_keyset(keyset.id, db=self.db) if keyset_local is None: await store_keyset(keyset=keyset, db=self.db) @@ -257,7 +257,7 @@ class LedgerAPI: promises = [BlindedSignature(**p) for p in promises_list] return self._construct_proofs(promises, secrets, rs) - async def split(self, proofs, amount, scnd_secret: str = None): + async def split(self, proofs, amount, scnd_secret: Optional[str] = None): """Consume proofs and create new promises based on amount split. If scnd_secret is None, random secrets will be generated for the tokens to keep (frst_outputs) and the promises to send (scnd_outputs). @@ -424,7 +424,7 @@ class Wallet(LedgerAPI): await store_lightning_invoice(db=self.db, invoice=invoice) return invoice - async def mint(self, amount: int, payment_hash: str = None): + async def mint(self, amount: int, payment_hash: Optional[str] = None): split = amount_split(amount) proofs = await super().mint(split, payment_hash) if proofs == []: @@ -440,8 +440,8 @@ class Wallet(LedgerAPI): async def redeem( self, proofs: List[Proof], - scnd_script: str = None, - scnd_siganture: str = None, + scnd_script: Optional[str] = None, + scnd_siganture: Optional[str] = None, ): if scnd_script and scnd_siganture: logger.debug(f"Unlock script: {scnd_script}") @@ -454,7 +454,7 @@ class Wallet(LedgerAPI): self, proofs: List[Proof], amount: int, - scnd_secret: str = None, + scnd_secret: Optional[str] = None, ): assert len(proofs) > 0, ValueError("no proofs provided.") frst_proofs, scnd_proofs = await super().split(proofs, amount, scnd_secret) @@ -569,7 +569,7 @@ class Wallet(LedgerAPI): self, proofs: List[Proof], amount, - scnd_secret: str = None, + scnd_secret: Optional[str] = None, set_reserved: bool = False, ): """Like self.split but only considers non-reserved tokens.""" diff --git a/tests/test_wallet.py b/tests/test_wallet.py index f06e530..ab9330d 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -63,7 +63,7 @@ async def test_get_keysets(wallet1: Wallet): assert type(keyset) == dict assert type(keyset["keysets"]) == list assert len(keyset["keysets"]) > 0 - assert keyset["keysets"][0] == wallet1.keyset_id + assert keyset["keysets"][-1] == wallet1.keyset_id @pytest.mark.asyncio