{"version":3,"sources":["../../src/settlement-cache.ts"],"sourcesContent":["import { SETTLEMENT_TTL_MS } from \"./constants\";\n\n/**\n * In-memory cache for deduplicating concurrent settlement requests.\n *\n * A single instance should be shared across V1 and V2 facilitator scheme\n * instances so that a transaction submitted through one protocol version is\n * also blocked on the other.  Because Node.js is single-threaded, no lock\n * is required — the cache check + insert must simply occur before the first\n * `await` in the settle path.\n */\nexport class SettlementCache {\n  private readonly entries = new Map<string, number>();\n\n  /**\n   * Returns `true` if `key` is already pending settlement (duplicate),\n   * or `false` after recording it as newly pending.\n   *\n   * Callers should reject the settlement when this returns `true`.\n   *\n   * @param key - The unique identifier for the settlement (typically the transaction signature).\n   * @returns `true` if the key was already present (duplicate); `false` otherwise.\n   */\n  isDuplicate(key: string): boolean {\n    this.prune();\n    if (this.entries.has(key)) {\n      return true;\n    }\n    this.entries.set(key, Date.now());\n    return false;\n  }\n\n  /**\n   * Remove entries older than the settlement TTL.\n   */\n  private prune(): void {\n    const cutoff = Date.now() - SETTLEMENT_TTL_MS;\n    for (const [key, timestamp] of this.entries) {\n      if (timestamp < cutoff) {\n        this.entries.delete(key);\n      } else {\n        break;\n      }\n    }\n  }\n}\n"],"mappings":";;;;;AAWO,IAAM,kBAAN,MAAsB;AAAA,EAAtB;AACL,SAAiB,UAAU,oBAAI,IAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWnD,YAAY,KAAsB;AAChC,SAAK,MAAM;AACX,QAAI,KAAK,QAAQ,IAAI,GAAG,GAAG;AACzB,aAAO;AAAA,IACT;AACA,SAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AAChC,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKQ,QAAc;AACpB,UAAM,SAAS,KAAK,IAAI,IAAI;AAC5B,eAAW,CAAC,KAAK,SAAS,KAAK,KAAK,SAAS;AAC3C,UAAI,YAAY,QAAQ;AACtB,aAAK,QAAQ,OAAO,GAAG;AAAA,MACzB,OAAO;AACL;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}