Skip to content

Commit

Permalink
make format
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Nov 24, 2023
1 parent e178290 commit 9aea4d7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
7 changes: 6 additions & 1 deletion cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ def __init__(
self.public_keys = public_keys
# overwrite id by deriving it from the public keys
self.id = derive_keyset_id(self.public_keys)
logger.trace(f"Derived keyset id {self.id} from public keys.")
if id and id != self.id:
logger.warning(
f"WARNING: Keyset id {self.id} does not match the given id {id}."
)

def serialize(self):
return json.dumps(
Expand All @@ -356,7 +361,7 @@ def serialize(self):

@classmethod
def from_row(cls, row: Row):
def deserialize(serialized: str):
def deserialize(serialized: str) -> Dict[int, PublicKey]:
return {
int(amount): PublicKey(bytes.fromhex(hex_key), raw=True)
for amount, hex_key in dict(json.loads(serialized)).items()
Expand Down
22 changes: 10 additions & 12 deletions cashu/nostr/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def __init__(self, private_key: str = "", relays: List[str] = [], connect=True):
def connect(self):
for relay in self.relays:
self.relay_manager.add_relay(relay)
self.relay_manager.open_connections(
{"cert_reqs": ssl.CERT_NONE}
) # NOTE: This disables ssl certificate verification
self.relay_manager.open_connections({
"cert_reqs": ssl.CERT_NONE
}) # NOTE: This disables ssl certificate verification

def close(self):
self.relay_manager.close_connections()
Expand Down Expand Up @@ -105,15 +105,13 @@ def dm(self, message: str, to_pubkey: PublicKey):
self.relay_manager.publish_event(dm)

def get_dm(self, sender_publickey: PublicKey, callback_func=None, filter_kwargs={}):
filters = Filters(
[
Filter(
kinds=[EventKind.ENCRYPTED_DIRECT_MESSAGE],
pubkey_refs=[sender_publickey.hex()],
**filter_kwargs,
)
]
)
filters = Filters([
Filter(
kinds=[EventKind.ENCRYPTED_DIRECT_MESSAGE],
pubkey_refs=[sender_publickey.hex()],
**filter_kwargs,
)
])
subscription_id = os.urandom(4).hex()
self.relay_manager.add_subscription(subscription_id, filters)

Expand Down
26 changes: 12 additions & 14 deletions cashu/nostr/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,18 @@ def verify(self) -> bool:
)

def to_message(self) -> str:
return json.dumps(
[
ClientMessageType.EVENT,
{
"id": self.id,
"pubkey": self.public_key,
"created_at": self.created_at,
"kind": self.kind,
"tags": self.tags,
"content": self.content,
"sig": self.signature,
},
]
)
return json.dumps([
ClientMessageType.EVENT,
{
"id": self.id,
"pubkey": self.public_key,
"created_at": self.created_at,
"kind": self.kind,
"tags": self.tags,
"content": self.content,
"sig": self.signature,
},
])


@dataclass
Expand Down
11 changes: 9 additions & 2 deletions tests/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from cashu.core.errors import CashuError, KeysetNotFoundError
from cashu.core.helpers import sum_proofs
from cashu.core.settings import settings
from cashu.wallet.crud import get_lightning_invoice, get_proofs
from cashu.wallet.crud import get_keyset, get_lightning_invoice, get_proofs
from cashu.wallet.wallet import Wallet
from cashu.wallet.wallet import Wallet as Wallet1
from cashu.wallet.wallet import Wallet as Wallet2
Expand Down Expand Up @@ -120,14 +120,21 @@ async def test_get_keyset_from_db(wallet1: Wallet):
# first load it from the mint
# await wallet1._load_mint_keys()
# NOTE: conftest already called wallet.load_mint() which got the keys from the mint
keyset1 = copy.copy(wallet1.keysets[wallet1.keyset_id])

# then load it from the db
keyset1 = copy.copy(wallet1.keysets[wallet1.keyset_id])
await wallet1._load_mint_keys()
keyset2 = copy.copy(wallet1.keysets[wallet1.keyset_id])

assert keyset1.public_keys == keyset2.public_keys
assert keyset1.id == keyset2.id

# load it directly from the db
keyset3 = await get_keyset(db=wallet1.db, id=keyset1.id)
assert keyset3
assert keyset1.public_keys == keyset3.public_keys
assert keyset1.id == keyset3.id


@pytest.mark.asyncio
async def test_get_info(wallet1: Wallet):
Expand Down

0 comments on commit 9aea4d7

Please sign in to comment.