diff options
Diffstat (limited to 'src/nwc-bg.js')
| -rw-r--r-- | src/nwc-bg.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/nwc-bg.js b/src/nwc-bg.js index 92786c0..3bdef08 100644 --- a/src/nwc-bg.js +++ b/src/nwc-bg.js @@ -88,6 +88,11 @@ export function buildBg({ ark, mgrState, keyFor, connections, offer, autowithdra const keys = {}; const idx = new Set((mgrState.vtxos || []).filter((v) => v.state !== 'spent').map((v) => v.keyIndex)); for (let i = 0; i < BG_KEY_LOOKAHEAD; i++) idx.add((mgrState.nextKeyIndex || 1) + i); + // A standing renewal order (and a renewal in flight) burned its output key + // when it was registered, below the counter by now: the worker needs that + // key to claim the renewed coin while the app is closed. + for (const e of mgrState.scheduled || []) if (e.outKeyIndex != null) idx.add(e.outKeyIndex); + for (const a of mgrState.actions || []) if (a.type === 'refresh' && a.step !== 'done' && a.outKeyIndex != null) idx.add(a.outKeyIndex); idx.add(0); // the receive-address key: mailbox/refund defaults land on it for (const i of idx) keys[String(i)] = keyFor(3, i); const keys5 = {}; @@ -107,9 +112,14 @@ export function buildBg({ ark, mgrState, keyFor, connections, offer, autowithdra // { on, threshold, keep, target: { kind, address, url?, spkHex? } } — the // destination is resolved by the app, so the worker never needs a relay autowithdraw: autowithdraw || null, + // The budget's spent counter rides along (stamped with its window) so the + // worker counts what the app spent; a revoked one rides along flagged, to + // be refused rather than ignored. connections: (connections || []).map((c) => ({ id: c.id, servicePk: c.servicePk, serviceSk: c.serviceSk, clientPk: c.clientPk, - maxSat: c.maxSat, dailySat: c.dailySat, + maxSat: c.maxSat, dailySat: c.dailySat, period: c.period || 'day', + spentDate: c.spentDate || null, spentToday: c.spentToday || 0, + revoked: !!c.revoked, })), }; } |
