Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Apr 10, 2024
1 parent 1355eef commit acdc0e6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class BlindedMessage_Deprecated(BaseModel):
# Same as BlindedMessage, but without the id field
amount: int
B_: str # Hex-encoded blinded message
id: Optional[str] = None
witness: Union[str, None] = None # witnesses (used for P2PK with SIG_ALL)

@property
Expand Down
10 changes: 7 additions & 3 deletions cashu/mint/router_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ async def mint_deprecated(
# use the deprecated version of the current keyset
assert ledger.keyset.duplicate_keyset_id
outputs: list[BlindedMessage] = [
BlindedMessage(id=ledger.keyset.duplicate_keyset_id, **o.dict())
BlindedMessage(
id=o.id or ledger.keyset.duplicate_keyset_id, **o.dict(exclude={"id"})
)
for o in payload.outputs
]
# END BACKWARDS COMPATIBILITY < 0.15
Expand Down Expand Up @@ -225,7 +227,8 @@ async def melt_deprecated(
# BEGIN BACKWARDS COMPATIBILITY < 0.14: add "id" to outputs
if payload.outputs:
outputs: list[BlindedMessage] = [
BlindedMessage(id=ledger.keyset.id, **o.dict()) for o in payload.outputs
BlindedMessage(id=o.id or ledger.keyset.id, **o.dict(exclude={"id"}))
for o in payload.outputs
]
else:
outputs = []
Expand Down Expand Up @@ -296,7 +299,8 @@ async def split_deprecated(
assert payload.outputs, Exception("no outputs provided.")
# BEGIN BACKWARDS COMPATIBILITY < 0.14: add "id" to outputs
outputs: list[BlindedMessage] = [
BlindedMessage(id=ledger.keyset.id, **o.dict()) for o in payload.outputs
BlindedMessage(id=o.id or ledger.keyset.id, **o.dict(exclude={"id"}))
for o in payload.outputs
]
# END BACKWARDS COMPATIBILITY < 0.14
promises = await ledger.split(proofs=payload.proofs, outputs=outputs)
Expand Down
21 changes: 17 additions & 4 deletions cashu/wallet/wallet_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ..core.base import (
BlindedMessage,
BlindedMessage_Deprecated,
BlindedSignature,
CheckFeesRequest_deprecated,
CheckFeesResponse_deprecated,
Expand Down Expand Up @@ -271,7 +272,8 @@ async def mint_deprecated(
Raises:
Exception: If the minting fails
"""
outputs_payload = PostMintRequest_deprecated(outputs=outputs)
outputs_deprecated = [BlindedMessage_Deprecated(**o.dict()) for o in outputs]
outputs_payload = PostMintRequest_deprecated(outputs=outputs_deprecated)

def _mintrequest_include_fields(outputs: List[BlindedMessage]):
"""strips away fields from the model that aren't necessary for the /mint"""
Expand Down Expand Up @@ -307,7 +309,14 @@ async def pay_lightning_deprecated(
Accepts proofs and a lightning invoice to pay in exchange.
"""
logger.warning("Using deprecated API call: POST /melt")
payload = PostMeltRequest_deprecated(proofs=proofs, pr=invoice, outputs=outputs)
outputs_deprecated = (
[BlindedMessage_Deprecated(**o.dict()) for o in outputs]
if outputs
else None
)
payload = PostMeltRequest_deprecated(
proofs=proofs, pr=invoice, outputs=outputs_deprecated
)

def _meltrequest_include_fields(proofs: List[Proof]):
"""strips away fields from the model that aren't necessary for the /melt"""
Expand Down Expand Up @@ -336,7 +345,10 @@ async def split_deprecated(
) -> List[BlindedSignature]:
"""Consume proofs and create new promises based on amount split."""
logger.warning("Using deprecated API call: Calling split. POST /split")
split_payload = PostSplitRequest_Deprecated(proofs=proofs, outputs=outputs)
outputs_deprecated = [BlindedMessage_Deprecated(**o.dict()) for o in outputs]
split_payload = PostSplitRequest_Deprecated(
proofs=proofs, outputs=outputs_deprecated
)

# construct payload
def _splitrequest_include_fields(proofs: List[Proof]):
Expand Down Expand Up @@ -403,7 +415,8 @@ async def restore_promises_deprecated(
Asks the mint to restore promises corresponding to outputs.
"""
logger.warning("Using deprecated API call: POST /restore")
payload = PostMintRequest_deprecated(outputs=outputs)
outputs_deprecated = [BlindedMessage_Deprecated(**o.dict()) for o in outputs]
payload = PostMintRequest_deprecated(outputs=outputs_deprecated)
resp = await self.httpx.post(join(self.url, "/restore"), json=payload.dict())
self.raise_on_error(resp)
response_dict = resp.json()
Expand Down

0 comments on commit acdc0e6

Please sign in to comment.