Add get quote API to wallet + check proof states in batches (#637)

* add get quote api to wallet

* wrong string

* test before pushing

* fix tests for deprecated api only

* sigh
This commit is contained in:
callebtc
2024-10-08 18:12:10 +02:00
committed by GitHub
parent cd39e18916
commit 4490cc6fce
6 changed files with 102 additions and 22 deletions

View File

@@ -170,7 +170,7 @@ class LedgerAPI(LedgerAPIDeprecated):
keys_dict: dict = resp.json()
assert len(keys_dict), Exception("did not receive any keys")
keys = KeysResponse.parse_obj(keys_dict)
keysets_str = ' '.join([f"{k.id} ({k.unit})" for k in keys.keysets])
keysets_str = " ".join([f"{k.id} ({k.unit})" for k in keys.keysets])
logger.debug(f"Received {len(keys.keysets)} keysets from mint: {keysets_str}.")
ret = [
WalletKeyset(
@@ -312,6 +312,24 @@ class LedgerAPI(LedgerAPIDeprecated):
return_dict = resp.json()
return PostMintQuoteResponse.parse_obj(return_dict)
@async_set_httpx_client
@async_ensure_mint_loaded
async def get_mint_quote(self, quote: str) -> PostMintQuoteResponse:
"""Returns an existing mint quote from the server.
Args:
quote (str): Quote ID
Returns:
PostMintQuoteResponse: Mint Quote Response
"""
resp = await self.httpx.get(
join(self.url, f"/v1/mint/quote/bolt11/{quote}"),
)
self.raise_on_error_request(resp)
return_dict = resp.json()
return PostMintQuoteResponse.parse_obj(return_dict)
@async_set_httpx_client
@async_ensure_mint_loaded
async def mint(
@@ -400,6 +418,24 @@ class LedgerAPI(LedgerAPIDeprecated):
return_dict = resp.json()
return PostMeltQuoteResponse.parse_obj(return_dict)
@async_set_httpx_client
@async_ensure_mint_loaded
async def get_melt_quote(self, quote: str) -> PostMeltQuoteResponse:
"""Returns an existing melt quote from the server.
Args:
quote (str): Quote ID
Returns:
PostMeltQuoteResponse: Melt Quote Response
"""
resp = await self.httpx.get(
join(self.url, f"/v1/melt/quote/bolt11/{quote}"),
)
self.raise_on_error_request(resp)
return_dict = resp.json()
return PostMeltQuoteResponse.parse_obj(return_dict)
@async_set_httpx_client
@async_ensure_mint_loaded
async def melt(