Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wallet] no async for deserialization functions #255

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions cashu/wallet/api/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async def receive_command(
):
initial_balance = wallet.available_balance
if token:
tokenObj: TokenV3 = await deserialize_token_from_string(token)
tokenObj: TokenV3 = deserialize_token_from_string(token)
await verify_mints(wallet, tokenObj)
balance = await receive(wallet, tokenObj, lock)
elif nostr:
Expand All @@ -191,7 +191,7 @@ async def receive_command(
for _, value in groupby(reserved_proofs, key=itemgetter("send_id")): # type: ignore
proofs = list(value)
token = await wallet.serialize_proofs(proofs)
tokenObj = await deserialize_token_from_string(token)
tokenObj = deserialize_token_from_string(token)
await verify_mints(wallet, tokenObj)
balance = await receive(wallet, tokenObj, lock)
else:
Expand Down Expand Up @@ -268,7 +268,7 @@ async def pending(
):
grouped_proofs = list(value)
token = await wallet.serialize_proofs(grouped_proofs)
tokenObj = await deserialize_token_from_string(token)
tokenObj = deserialize_token_from_string(token)
mint = [t.mint for t in tokenObj.token][0]
reserved_date = datetime.utcfromtimestamp(
int(grouped_proofs[0].time_reserved)
Expand Down
4 changes: 2 additions & 2 deletions cashu/wallet/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ async def receive_cli(
wallet.status()

if token:
tokenObj = await deserialize_token_from_string(token)
tokenObj = deserialize_token_from_string(token)
# verify that we trust all mints in these tokens
# ask the user if they want to trust the new mints
for mint_url in set([t.mint for t in tokenObj.token if t.mint]):
Expand Down Expand Up @@ -450,7 +450,7 @@ async def pending(ctx: Context, legacy, number: int, offset: int):
):
grouped_proofs = list(value)
token = await wallet.serialize_proofs(grouped_proofs)
tokenObj = await deserialize_token_from_string(token)
tokenObj = deserialize_token_from_string(token)
mint = [t.mint for t in tokenObj.token][0]
# token_hidden_secret = await wallet.serialize_proofs(grouped_proofs)
reserved_date = datetime.utcfromtimestamp(
Expand Down
10 changes: 5 additions & 5 deletions cashu/wallet/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def redeem_TokenV3_multimint(
print(f"Received {sum_proofs(redeem_proofs)} sats")


async def serialize_TokenV2_to_TokenV3(tokenv2: TokenV2):
def serialize_TokenV2_to_TokenV3(tokenv2: TokenV2):
"""Helper function to receive legacy TokenV2 tokens.
Takes a list of proofs and constructs a *serialized* TokenV3 to be received through
the ordinary path.
Expand All @@ -64,7 +64,7 @@ async def serialize_TokenV2_to_TokenV3(tokenv2: TokenV2):
return token_serialized


async def serialize_TokenV1_to_TokenV3(tokenv1: TokenV1):
def serialize_TokenV1_to_TokenV3(tokenv1: TokenV1):
"""Helper function to receive legacy TokenV1 tokens.
Takes a list of proofs and constructs a *serialized* TokenV3 to be received through
the ordinary path.
Expand All @@ -77,7 +77,7 @@ async def serialize_TokenV1_to_TokenV3(tokenv1: TokenV1):
return token_serialized


async def deserialize_token_from_string(token: str) -> TokenV3:
def deserialize_token_from_string(token: str) -> TokenV3:
# deserialize token

# ----- backwards compatibility -----
Expand All @@ -86,15 +86,15 @@ async def deserialize_token_from_string(token: str) -> TokenV3:
if token.startswith("eyJwcm9"):
try:
tokenv2 = TokenV2.parse_obj(json.loads(base64.urlsafe_b64decode(token)))
token = await serialize_TokenV2_to_TokenV3(tokenv2)
token = serialize_TokenV2_to_TokenV3(tokenv2)
except:
pass

# V1Tokens (<0.7) (W3siaWQ...)
if token.startswith("W3siaWQ"):
try:
tokenv1 = TokenV1.parse_obj(json.loads(base64.urlsafe_b64decode(token)))
token = await serialize_TokenV1_to_TokenV3(tokenv1)
token = serialize_TokenV1_to_TokenV3(tokenv1)
except:
pass

Expand Down