-
Notifications
You must be signed in to change notification settings - Fork 19
fix(core): record melt quotes before settlement #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
34c16d3
eb8cd7c
4107cb5
26a9ddf
8ec4aa2
af82ae8
a6f1216
7445e8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@cashu/coco-core': patch | ||
| --- | ||
|
|
||
| Record pending melt quote observations before settling local melt operations, and use cached PAID | ||
| observations during recovery only when serialized settlement change is available. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,6 +155,15 @@ function getMeltQuoteChange(existing: MeltQuote | null, incoming: MeltQuote): bo | |
| ); | ||
| } | ||
|
|
||
| function shouldEnrichPaidMeltQuoteSettlement(existing: MeltQuote, incoming: MeltQuote): boolean { | ||
| return ( | ||
| existing.state === 'PAID' && | ||
| incoming.state === 'PAID' && | ||
| !Array.isArray(existing.change) && | ||
| Array.isArray(incoming.change) | ||
| ); | ||
| } | ||
|
|
||
| export interface QuoteLifecycleDeps { | ||
| mintHandlerProvider: MintHandlerProvider; | ||
| meltHandlerProvider: MeltHandlerProvider; | ||
|
|
@@ -718,6 +727,22 @@ export class QuoteLifecycle { | |
| ); | ||
|
|
||
| if (existing?.state === 'PAID') { | ||
| if (shouldEnrichPaidMeltQuoteSettlement(existing, canonicalQuote)) { | ||
| const persisted = await this.persistCanonicalMeltQuote({ | ||
| ...existing, | ||
| change: canonicalQuote.change, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an existing terminal Useful? React with 👍 / 👎. |
||
| lastObservedRemoteState: | ||
| canonicalQuote.lastObservedRemoteState ?? existing.lastObservedRemoteState, | ||
| lastObservedRemoteStateAt: | ||
| canonicalQuote.lastObservedRemoteStateAt ?? existing.lastObservedRemoteStateAt, | ||
| updatedAt: canonicalQuote.updatedAt, | ||
| } as MeltQuote); | ||
| return { | ||
| quote: persisted, | ||
| remoteQuoteChanged: true, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| quote: existing, | ||
| remoteQuoteChanged: false, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the cached PAID quote already has a serialized
changearray but still lacks the method-specific settlement field (payment_preimagefor BOLT oroutpointfor onchain), this branch treats it as complete and returns it without a remote refresh. The new cached-PAID fast path meansmergePaidMeltQuoteSettlementnever gets a chance to copy that metadata later, so the pending operation can be finalized permanently without the preimage/outpoint even though a full quote check would now provide it.Useful? React with 👍 / 👎.