From acdc0e688f15c9fc6fce47eeed60a417744e4c4f Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 10 Apr 2024 12:09:59 +0200 Subject: [PATCH] working --- cashu/core/base.py | 1 + cashu/mint/router_deprecated.py | 10 +++++++--- cashu/wallet/wallet_deprecated.py | 21 +++++++++++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/cashu/core/base.py b/cashu/core/base.py index 9de4b8a6..1e198306 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -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 diff --git a/cashu/mint/router_deprecated.py b/cashu/mint/router_deprecated.py index e9972b78..dde54056 100644 --- a/cashu/mint/router_deprecated.py +++ b/cashu/mint/router_deprecated.py @@ -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 @@ -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 = [] @@ -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) diff --git a/cashu/wallet/wallet_deprecated.py b/cashu/wallet/wallet_deprecated.py index db5e927a..080a9925 100644 --- a/cashu/wallet/wallet_deprecated.py +++ b/cashu/wallet/wallet_deprecated.py @@ -8,6 +8,7 @@ from ..core.base import ( BlindedMessage, + BlindedMessage_Deprecated, BlindedSignature, CheckFeesRequest_deprecated, CheckFeesResponse_deprecated, @@ -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""" @@ -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""" @@ -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]): @@ -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()