mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
checkpoint: swap tokens into user controlled wallet
TODO: create the 7376 history kind, reemded marker, etc
This commit is contained in:
parent
df1a3fe842
commit
d61f0d1d4b
1 changed files with 34 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { CashuMint, CashuWallet } from '@cashu/cashu-ts';
|
import { CashuMint, CashuWallet, getEncodedToken, type Proof } from '@cashu/cashu-ts';
|
||||||
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
||||||
import { logi } from '@soapbox/logi';
|
import { logi } from '@soapbox/logi';
|
||||||
import { generateSecretKey, getPublicKey } from 'nostr-tools';
|
import { generateSecretKey, getPublicKey } from 'nostr-tools';
|
||||||
|
|
@ -548,7 +548,39 @@ export const swapNutzapsToWalletController: AppController = async (c) => {
|
||||||
|
|
||||||
const nutzaps = await store.query([nutzapsFilter], { signal });
|
const nutzaps = await store.query([nutzapsFilter], { signal });
|
||||||
|
|
||||||
// TODO: finally start doing the swap
|
const mintsToProofs: { [key: string]: Proof[] } = {};
|
||||||
|
nutzaps.forEach(async (event) => {
|
||||||
|
try {
|
||||||
|
const { mint, proofs }: { mint: string; proofs: Proof[] } = JSON.parse( // TODO: create a merge request in nostr tools or Nostrify to do this in a nice way?
|
||||||
|
await nip44.decrypt(pubkey, event.content),
|
||||||
|
);
|
||||||
|
if (typeof mint === 'string') {
|
||||||
|
mintsToProofs[mint] = [...(mintsToProofs[mint] || []), ...proofs];
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// do nothing, for now... (maybe print errors)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const mint of Object.keys(mintsToProofs)) {
|
||||||
|
const token = getEncodedToken({ mint, proofs: mintsToProofs[mint] }, { version: 3 });
|
||||||
|
|
||||||
|
const cashuWallet = new CashuWallet(new CashuMint(mint));
|
||||||
|
const receiveProofs = await cashuWallet.receive(token);
|
||||||
|
|
||||||
|
await createEvent({
|
||||||
|
kind: 7375,
|
||||||
|
content: await nip44.encrypt(
|
||||||
|
pubkey,
|
||||||
|
JSON.stringify({
|
||||||
|
mint,
|
||||||
|
proofs: receiveProofs,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}, c);
|
||||||
|
|
||||||
|
// TODO: create the 7376 history kind, reemded marker, etc
|
||||||
|
}
|
||||||
|
|
||||||
return c.json(201);
|
return c.json(201);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue