mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
feat: implement GET '/api/v1/ditto/cashu/quote/:quote_id' (not tested)
This commit is contained in:
parent
8cba937962
commit
b9d813804e
1 changed files with 25 additions and 1 deletions
|
|
@ -10,7 +10,7 @@ import { requireNip44Signer } from '@/middleware/requireSigner.ts';
|
||||||
import { requireStore } from '@/middleware/storeMiddleware.ts';
|
import { requireStore } from '@/middleware/storeMiddleware.ts';
|
||||||
import { walletSchema } from '@/schema.ts';
|
import { walletSchema } from '@/schema.ts';
|
||||||
import { swapNutzapsMiddleware } from '@/middleware/swapNutzapsMiddleware.ts';
|
import { swapNutzapsMiddleware } from '@/middleware/swapNutzapsMiddleware.ts';
|
||||||
import { isNostrId } from '@/utils.ts';
|
import { isNostrId, nostrNow } from '@/utils.ts';
|
||||||
import { logi } from '@soapbox/logi';
|
import { logi } from '@soapbox/logi';
|
||||||
import { errorJson } from '@/utils/log.ts';
|
import { errorJson } from '@/utils/log.ts';
|
||||||
|
|
||||||
|
|
@ -82,6 +82,30 @@ app.post('/quote', requireNip44Signer, async (c) => {
|
||||||
* https://github.com/cashubtc/nuts/blob/main/04.md#check-mint-quote-state
|
* https://github.com/cashubtc/nuts/blob/main/04.md#check-mint-quote-state
|
||||||
*/
|
*/
|
||||||
app.get('/quote/:quote_id', requireNip44Signer, async (c) => {
|
app.get('/quote/:quote_id', requireNip44Signer, async (c) => {
|
||||||
|
const signer = c.var.signer;
|
||||||
|
const { signal } = c.req.raw;
|
||||||
|
const store = c.get('store');
|
||||||
|
const pubkey = await signer.getPublicKey();
|
||||||
|
const quote_id = c.req.param('quote_id');
|
||||||
|
|
||||||
|
const events = await store.query([{ kinds: [7374], authors: [pubkey] }], { signal });
|
||||||
|
for (const event of events) {
|
||||||
|
const decryptedQuoteId = await signer.nip44.decrypt(pubkey, event.content);
|
||||||
|
const mintUrl = event.tags.find(([name]) => name === 'mint')?.[1];
|
||||||
|
const expiration = Number(event.tags.find(([name]) => name === 'expiration')?.[1]);
|
||||||
|
const now = nostrNow();
|
||||||
|
|
||||||
|
if (mintUrl && (expiration > now) && (quote_id === decryptedQuoteId)) {
|
||||||
|
const mint = new CashuMint(mintUrl);
|
||||||
|
const wallet = new CashuWallet(mint);
|
||||||
|
await wallet.loadMint();
|
||||||
|
|
||||||
|
const mintQuote = await wallet.checkMintQuote(quote_id);
|
||||||
|
return c.json(mintQuote, 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({ error: 'Quote not found' }, 404);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue