From 6c59ed748bf9d36b3d1a8aa830e806c654fa12aa Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 2 Nov 2024 16:02:03 +0100 Subject: [PATCH] state check compat with 0.15.0 --- cashu/wallet/v1_api.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/cashu/wallet/v1_api.py b/cashu/wallet/v1_api.py index ba4d9c06..26bff616 100644 --- a/cashu/wallet/v1_api.py +++ b/cashu/wallet/v1_api.py @@ -573,9 +573,28 @@ async def check_proof_state(self, proofs: List[Proof]) -> PostCheckStateResponse states.append(ProofState(Y=p.Y, state=ProofSpentState.pending)) else: states.append(ProofState(Y=p.Y, state=ProofSpentState.spent)) - ret = PostCheckStateResponse(states=states) - return ret + return PostCheckStateResponse(states=states) # END backwards compatibility < 0.15.0 + + # BEGIN backwards compatibility < 0.16.0 + # payload has "secrets" instead of "Ys" + if resp.status_code == 422: + logger.warning( + "Received HTTP Error 422. Attempting state check with < 0.16.0 compatibility." + ) + payload_secrets = {"secrets": [p.secret for p in proofs]} + resp_secrets = await self.httpx.post( + join(self.url, "/v1/checkstate"), + json=payload_secrets, + ) + self.raise_on_error(resp_secrets) + states = [ + ProofState(Y=p.Y, state=ProofSpentState(s["state"])) + for p, s in zip(proofs, resp_secrets.json()["states"]) + ] + return PostCheckStateResponse(states=states) + # END backwards compatibility < 0.16.0 + self.raise_on_error_request(resp) return PostCheckStateResponse.parse_obj(resp.json())