diff options
Diffstat (limited to 'src/ark')
| -rw-r--r-- | src/ark/manager.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/ark/manager.js b/src/ark/manager.js index 703d341..d5ae2b0 100644 --- a/src/ark/manager.js +++ b/src/ark/manager.js @@ -171,6 +171,12 @@ export function pruneArkState(state, now = Date.now()) { return state; } +// How close to expiry the server-side backstop renewal is aimed: well inside +// the free fee bracket (under 96 blocks of life left on our ASPs), and far +// enough out — 36 blocks, six hourly rounds — for the round to run in time. +// Shared by the app (features/ark.js) and the worker tending a closed wallet. +export const backstopMargin = (network) => (network === 'regtest' ? 6 : 36); + export class ArkManager { constructor({ account, storage, arkUrl, esploraUrl, network = 'regtest', onUpdate, lnQuoteUrl, statusHint }) { this.account = account; // HDKey node; ark keys derived beneath it @@ -2419,6 +2425,14 @@ export class ArkManager { scheduledRefreshes() { return (this.state.scheduled || []).slice(); } + // Union of two devices' standing orders (the app's and the worker's, or + // two devices'), keyed by unlock hash; dead ones are dropped on the next + // _driveScheduled, so an order for a coin the other side spent is harmless. + static mergeScheduled(a = [], b = []) { + const seen = new Set(a.map((s) => s.unlockHash)); + return [...a, ...b.filter((s) => s.unlockHash && !seen.has(s.unlockHash))]; + } + // Keep every coin covered by a standing order, `marginBlocks` before its // expiry. Coins arrive, get spent, get renewed — each new one needs its own // backstop while it still has the lifetime to register one. Caller owns the |
