@secondlayer/shared 16.0.0 → 17.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/archive/range-digest.d.ts +0 -36
- package/dist/src/archive/semantic-digest-builder.d.ts +0 -36
- package/dist/src/classify/index.js +1 -4
- package/dist/src/classify/index.js.map +3 -3
- package/dist/src/coverage/index.d.ts +0 -36
- package/dist/src/crypto/secondlayer-webhook.js +1 -4
- package/dist/src/crypto/secondlayer-webhook.js.map +3 -3
- package/dist/src/db/index.d.ts +1 -151
- package/dist/src/db/index.js +1 -70
- package/dist/src/db/index.js.map +6 -6
- package/dist/src/db/queries/chain-reorgs.d.ts +0 -36
- package/dist/src/db/queries/chain-reorgs.js +1 -70
- package/dist/src/db/queries/chain-reorgs.js.map +6 -6
- package/dist/src/db/queries/contracts.d.ts +0 -36
- package/dist/src/db/queries/contracts.js.map +2 -2
- package/dist/src/db/queries/instance.d.ts +0 -36
- package/dist/src/db/queries/instance.js +1 -4
- package/dist/src/db/queries/instance.js.map +3 -3
- package/dist/src/db/queries/integrity.d.ts +0 -36
- package/dist/src/db/queries/integrity.js +1 -4
- package/dist/src/db/queries/integrity.js.map +3 -3
- package/dist/src/db/queries/subgraph-gaps.d.ts +0 -36
- package/dist/src/db/queries/subgraph-operations.d.ts +0 -36
- package/dist/src/db/queries/subgraphs.d.ts +0 -36
- package/dist/src/db/queries/sync-scope.d.ts +0 -36
- package/dist/src/db/queries/webhook-replays.d.ts +0 -36
- package/dist/src/db/queries/webhooks.d.ts +0 -36
- package/dist/src/db/schema.d.ts +1 -37
- package/dist/src/db/schema.js.map +2 -2
- package/dist/src/email/index.js +1 -4
- package/dist/src/email/index.js.map +3 -3
- package/dist/src/env.d.ts +2 -8
- package/dist/src/env.js +1 -5
- package/dist/src/env.js.map +3 -3
- package/dist/src/index.d.ts +19 -158
- package/dist/src/index.js +51 -77
- package/dist/src/index.js.map +10 -8
- package/dist/src/insights/index.d.ts +0 -36
- package/dist/src/insights/index.js +1 -4
- package/dist/src/insights/index.js.map +3 -3
- package/dist/src/leader.js +1 -70
- package/dist/src/leader.js.map +6 -6
- package/dist/src/logger.js +1 -4
- package/dist/src/logger.js.map +3 -3
- package/dist/src/node/local-client.d.ts +0 -36
- package/dist/src/node/tx-summary.d.ts +7 -1
- package/dist/src/node/tx-summary.js +17 -5
- package/dist/src/node/tx-summary.js.map +4 -4
- package/dist/src/queue/listener.js +1 -70
- package/dist/src/queue/listener.js.map +6 -6
- package/dist/src/runtime/index.js +1 -2
- package/dist/src/runtime/index.js.map +3 -3
- package/dist/src/schemas/index.js +28 -7
- package/dist/src/schemas/index.js.map +5 -4
- package/dist/src/schemas/webhooks.js +28 -7
- package/dist/src/schemas/webhooks.js.map +5 -4
- package/dist/src/streams-rows/index.d.ts +35 -12
- package/dist/src/streams-rows/index.js +25 -21
- package/dist/src/streams-rows/index.js.map +5 -5
- package/migrations/0206_drop_pox4_calls.ts +32 -0
- package/migrations/0207_bns_buy_listing_price.ts +39 -0
- package/migrations/0208_pox5_calculate_rewards_cycle.ts +31 -0
- package/migrations/0209_chain_reorgs_index_block_hash.ts +51 -0
- package/migrations/0210_mempool_evict_superseded_nonces.ts +71 -0
- package/package.json +1 -1
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { cvToValue, deserializeCV } from \"@secondlayer/stacks/clarity\";\n\n/** Make a cvToValue result JSON-serializable: Clarity (u)ints decode to bigint,\n * which JSON.stringify can't handle — convert recursively to strings. */\nexport function toJsonSafe(value: unknown): unknown {\n\tif (typeof value === \"bigint\") return value.toString();\n\tif (Array.isArray(value)) return value.map(toJsonSafe);\n\tif (value && typeof value === \"object\") {\n\t\tconst out: Record<string, unknown> = {};\n\t\tfor (const [key, val] of Object.entries(value)) {\n\t\t\tout[key] = toJsonSafe(val);\n\t\t}\n\t\treturn out;\n\t}\n\treturn value;\n}\n\n/** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,\n * buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */\nexport function decodeClarityValue(hex: string): unknown {\n\ttry {\n\t\tconst clean = hex.startsWith(\"0x\") ? hex.slice(2) : hex;\n\t\treturn toJsonSafe(cvToValue(deserializeCV(clean)));\n\t} catch {\n\t\treturn hex;\n\t}\n}\n",
|
|
6
6
|
"// The decoded event-type vocabulary — canonical home is now\n// `@secondlayer/stacks/filters` (the LEAF of the dependency graph: shared\n// depends on stacks, never the reverse, so no package can drift a private\n// copy upward). Re-exported here so every existing `@secondlayer/shared`\n// import keeps working unchanged.\nimport {\n\tDECODED_EVENT_TYPES,\n\ttype VM_NODE_TO_STORED_TYPE,\n} from \"@secondlayer/stacks/filters\";\nimport type { DecodedEventType } from \"@secondlayer/stacks/filters\";\n\nexport {\n\tDECODED_EVENT_TYPES,\n\tVM_EVENT_TYPES,\n\tVM_NODE_TO_STORED_TYPE,\n\ttype DecodedEventType,\n\ttype VmEventType,\n\ttype VmNodeEventType,\n} from \"@secondlayer/stacks/filters\";\n\ntype VmStoredToNode = {\n\t[K in keyof typeof VM_NODE_TO_STORED_TYPE as (typeof VM_NODE_TO_STORED_TYPE)[K]]: K;\n};\n\n/** Inverse of {@link VM_NODE_TO_STORED_TYPE}. Replay reconstruction emits the\n * node-shaped `/new_block.vm_events` body, so ingest can re-parse it. */\nexport const VM_STORED_TO_NODE_TYPE: VmStoredToNode = {\n\tnested_contract_call: \"contract_call_event\",\n\tvar_set: \"var_set_event\",\n\tmap_set: \"map_set_event\",\n\tmap_insert: \"map_insert_event\",\n\tmap_delete: \"map_delete_event\",\n};\n\n/** Alias kept for the Streams surface (identical to {@link DECODED_EVENT_TYPES}).\n * Explicit type annotation required — isolatedDeclarations emits `unknown` for\n * a bare const-to-const alias. */\nexport const STREAMS_EVENT_TYPES: typeof DECODED_EVENT_TYPES =\n\tDECODED_EVENT_TYPES;\nexport type StreamsEventType = DecodedEventType;\n\n/**\n * Wire vocabulary for `chain=bitcoin` Streams events (plan 059) — Runes\n * activity, mirroring the Stacks `ft_*` family. Same four kinds as 058's\n * `RuneEventKind` (`packages/api/src/index/runes.ts`), duplicated here as the\n * canonical shared const rather than imported from the api package (shared\n * never depends on api); the DB `kind` column (`etch|mint|transfer|burn`) is\n * mapped at the edge in both readers.\n */\nexport const RUNE_EVENT_TYPES = [\n\t\"rune_etch\",\n\t\"rune_mint\",\n\t\"rune_transfer\",\n\t\"rune_burn\",\n] as const;\nexport type RuneEventType = (typeof RUNE_EVENT_TYPES)[number];\n",
|
|
7
|
-
"import type { StreamsEvent } from \"./events.ts\";\n\n/** Superset of the columns the decoded_events table holds. Every decoded\n * event's `decoded_payload` is assignable to this, so the indexer's writer\n * can map columns generically instead of per-event-type. */\nexport type DecodedEventColumns = {\n\tcontract_id?: string | null;\n\tasset_identifier?: string | null;\n\tsender?: string | null;\n\trecipient?: string | null;\n\tamount?: string | null;\n\tvalue?: string | null;\n\tmemo?: string | null;\n\t/** JSONB overflow for non-flat types (e.g. print's decoded value). */\n\tpayload?: unknown;\n};\n\nexport function requireString(\n\tpayload: Record<string, unknown>,\n\tfield: string,\n\teventType: string,\n): string {\n\tconst value = payload[field];\n\tif (typeof value !== \"string\" || value.length === 0) {\n\t\tthrow new Error(`${eventType} payload missing ${field}`);\n\t}\n\treturn value;\n}\n\nexport function optionalString(value: unknown): string | null {\n\treturn typeof value === \"string\" && value.length > 0 ? value : null;\n}\n\nexport function requireAmountField(\n\tpayload: Record<string, unknown>,\n\tfield: string,\n\teventType: string,\n): string {\n\tconst amount = requireString(payload, field, eventType);\n\tif (!/^(0|[1-9]\\d*)$/.test(amount)) {\n\t\tthrow new Error(`${eventType} payload has malformed ${field}`);\n\t}\n\treturn amount;\n}\n\nexport function requireAmount(\n\tpayload: Record<string, unknown>,\n\teventType: string,\n): string {\n\treturn requireAmountField(payload, \"amount\", eventType);\n}\n\nexport function parseAssetIdentifier(\n\tassetIdentifier: string,\n\teventType: string,\n): { contract_id: string; token_name: string | null } {\n\tconst [contractId, tokenName] = assetIdentifier.split(\"::\");\n\tif (!contractId) {\n\t\tthrow new Error(`${eventType} payload has malformed asset_identifier`);\n\t}\n\treturn {\n\t\tcontract_id: contractId,\n\t\ttoken_name: tokenName && tokenName.length > 0 ? tokenName : null,\n\t};\n}\n\n/**
|
|
7
|
+
"import type { StreamsEvent } from \"./events.ts\";\n\n/** Superset of the columns the decoded_events table holds. Every decoded\n * event's `decoded_payload` is assignable to this, so the indexer's writer\n * can map columns generically instead of per-event-type. */\nexport type DecodedEventColumns = {\n\tcontract_id?: string | null;\n\tasset_identifier?: string | null;\n\tsender?: string | null;\n\trecipient?: string | null;\n\tamount?: string | null;\n\tvalue?: string | null;\n\tmemo?: string | null;\n\t/** JSONB overflow for non-flat types (e.g. print's decoded value). */\n\tpayload?: unknown;\n};\n\nexport function requireString(\n\tpayload: Record<string, unknown>,\n\tfield: string,\n\teventType: string,\n): string {\n\tconst value = payload[field];\n\tif (typeof value !== \"string\" || value.length === 0) {\n\t\tthrow new Error(`${eventType} payload missing ${field}`);\n\t}\n\treturn value;\n}\n\nexport function optionalString(value: unknown): string | null {\n\treturn typeof value === \"string\" && value.length > 0 ? value : null;\n}\n\nexport function requireAmountField(\n\tpayload: Record<string, unknown>,\n\tfield: string,\n\teventType: string,\n): string {\n\tconst amount = requireString(payload, field, eventType);\n\tif (!/^(0|[1-9]\\d*)$/.test(amount)) {\n\t\tthrow new Error(`${eventType} payload has malformed ${field}`);\n\t}\n\treturn amount;\n}\n\nexport function requireAmount(\n\tpayload: Record<string, unknown>,\n\teventType: string,\n): string {\n\treturn requireAmountField(payload, \"amount\", eventType);\n}\n\nexport function parseAssetIdentifier(\n\tassetIdentifier: string,\n\teventType: string,\n): { contract_id: string; token_name: string | null } {\n\tconst [contractId, tokenName] = assetIdentifier.split(\"::\");\n\tif (!contractId) {\n\t\tthrow new Error(`${eventType} payload has malformed asset_identifier`);\n\t}\n\treturn {\n\t\tcontract_id: contractId,\n\t\ttoken_name: tokenName && tokenName.length > 0 ? tokenName : null,\n\t};\n}\n\nconst HEX_BODY = /^[0-9a-fA-F]*$/;\n\n/** The canonical `0x` hex of a payload's Clarity value, from whichever field\n * the row's ingestion era wrote: `raw_value` (from ~7.46M), a `0x` string at\n * `value` (before that), or a typed `{ hex }` object. Null when none is hex. */\nexport function clarityHexOf(payload: Record<string, unknown>): string | null {\n\tconst rawValue = payload.raw_value;\n\tif (typeof rawValue === \"string\") return rawValue;\n\tconst value = payload.value;\n\tif (typeof value === \"string\" && value.startsWith(\"0x\")) return value;\n\tif (\n\t\tvalue &&\n\t\ttypeof value === \"object\" &&\n\t\ttypeof (value as { hex?: unknown }).hex === \"string\"\n\t) {\n\t\treturn (value as { hex: string }).hex;\n\t}\n\treturn null;\n}\n\n/** NFT token id as canonical `0x` hex; throws when missing or malformed. */\nexport function requireHexValue(\n\tpayload: Record<string, unknown>,\n\teventType: string,\n): string {\n\tconst hex =\n\t\tclarityHexOf(payload) ??\n\t\t(typeof payload.value === \"string\" ? payload.value : null);\n\tif (!hex) {\n\t\tthrow new Error(`${eventType} payload missing value`);\n\t}\n\tif (!/^0x[0-9a-fA-F]*$/.test(hex)) {\n\t\tthrow new Error(`${eventType} payload has malformed value`);\n\t}\n\treturn hex;\n}\n\n/**\n * A transfer memo as `0x` hex, or null when the transfer carried none.\n *\n * Stored memos come in three spellings depending on ingestion era: `0x…`\n * (before ~7.4M), bare hex (after), and missing or `\"\"` for transfers made\n * without a memo. Non-hex strings pass through untouched.\n */\nexport function normalizeMemoHex(memo: unknown): string | null {\n\tif (typeof memo !== \"string\") return null;\n\tconst body = memo.startsWith(\"0x\") ? memo.slice(2) : memo;\n\tif (body.length === 0) return null;\n\treturn HEX_BODY.test(body) ? `0x${body}` : memo;\n}\n\n/** Common envelope fields shared by every decoded event, lifted off the\n * source StreamsEvent. The decoder supplies event_type + decoded_payload. */\nexport function decodedRow<T extends string, P>(\n\tevent: StreamsEvent,\n\teventType: T,\n\tdecoded_payload: P,\n): {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: T;\n\tdecoded_payload: P;\n\tsource_cursor: string;\n} {\n\treturn {\n\t\tcursor: event.cursor,\n\t\tblock_height: event.block_height,\n\t\ttx_id: event.tx_id,\n\t\ttx_index: event.tx_index,\n\t\tevent_index: event.event_index,\n\t\tevent_type: eventType,\n\t\tdecoded_payload,\n\t\tsource_cursor: event.cursor,\n\t};\n}\n",
|
|
8
8
|
"import {\n\tdecodedRow,\n\tparseAssetIdentifier,\n\trequireAmount,\n\trequireString,\n} from \"./_payload.ts\";\nimport type { StreamsEvent } from \"./events.ts\";\n\nexport type { FtTransferPayload } from \"./events.ts\";\n\nexport type FtTransferEvent = Extract<\n\tStreamsEvent,\n\t{ event_type: \"ft_transfer\" }\n>;\n\nexport type DecodedFtTransferPayload = {\n\tasset_identifier: string;\n\tcontract_id: string;\n\ttoken_name: string | null;\n\tsender: string;\n\trecipient: string;\n\tamount: string;\n};\n\nexport type DecodedFtTransfer = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"ft_transfer\";\n\tdecoded_payload: DecodedFtTransferPayload;\n\tsource_cursor: string;\n};\n\nexport function isFtTransfer(event: StreamsEvent): event is FtTransferEvent {\n\treturn event.event_type === \"ft_transfer\";\n}\n\nexport function decodeFtTransfer(event: StreamsEvent): DecodedFtTransfer {\n\tif (!isFtTransfer(event)) {\n\t\tthrow new Error(`Expected ft_transfer event, got ${event.event_type}`);\n\t}\n\n\tconst payload = event.payload;\n\tconst assetIdentifier = requireString(\n\t\tpayload,\n\t\t\"asset_identifier\",\n\t\t\"ft_transfer\",\n\t);\n\tconst sender = requireString(payload, \"sender\", \"ft_transfer\");\n\tconst recipient = requireString(payload, \"recipient\", \"ft_transfer\");\n\tconst amount = requireAmount(payload, \"ft_transfer\");\n\tconst { contract_id, token_name } = parseAssetIdentifier(\n\t\tassetIdentifier,\n\t\t\"ft_transfer\",\n\t);\n\n\treturn decodedRow(event, \"ft_transfer\", {\n\t\tasset_identifier: assetIdentifier,\n\t\tcontract_id: event.contract_id ?? contract_id,\n\t\ttoken_name,\n\t\tsender,\n\t\trecipient,\n\t\tamount,\n\t});\n}\n",
|
|
9
9
|
"import {\n\tdecodedRow,\n\tparseAssetIdentifier,\n\trequireHexValue,\n\trequireString,\n} from \"./_payload.ts\";\nimport type { StreamsEvent } from \"./events.ts\";\n\nexport type { NftTransferPayload } from \"./events.ts\";\n\nexport type NftTransferEvent = Extract<\n\tStreamsEvent,\n\t{ event_type: \"nft_transfer\" }\n>;\n\nexport type DecodedNftTransferPayload = {\n\tasset_identifier: string;\n\tcontract_id: string;\n\ttoken_name: string | null;\n\tsender: string;\n\trecipient: string;\n\tvalue: string;\n};\n\nexport type DecodedNftTransfer = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"nft_transfer\";\n\tdecoded_payload: DecodedNftTransferPayload;\n\tsource_cursor: string;\n};\n\nexport function isNftTransfer(event: StreamsEvent): event is NftTransferEvent {\n\treturn event.event_type === \"nft_transfer\";\n}\n\nexport function decodeNftTransfer(event: StreamsEvent): DecodedNftTransfer {\n\tif (!isNftTransfer(event)) {\n\t\tthrow new Error(`Expected nft_transfer event, got ${event.event_type}`);\n\t}\n\n\tconst payload = event.payload;\n\tconst assetIdentifier = requireString(\n\t\tpayload,\n\t\t\"asset_identifier\",\n\t\t\"nft_transfer\",\n\t);\n\tconst sender = requireString(payload, \"sender\", \"nft_transfer\");\n\tconst recipient = requireString(payload, \"recipient\", \"nft_transfer\");\n\tconst value = requireHexValue(payload, \"nft_transfer\");\n\tconst { contract_id, token_name } = parseAssetIdentifier(\n\t\tassetIdentifier,\n\t\t\"nft_transfer\",\n\t);\n\n\treturn decodedRow(event, \"nft_transfer\", {\n\t\tasset_identifier: assetIdentifier,\n\t\tcontract_id: event.contract_id ?? contract_id,\n\t\ttoken_name,\n\t\tsender,\n\t\trecipient,\n\t\tvalue,\n\t});\n}\n",
|
|
10
|
-
"import { decodedRow, optionalString } from \"./_payload.ts\";\nimport { decodeClarityValue, toJsonSafe } from \"./clarity.ts\";\nimport type { StreamsEvent } from \"./events.ts\";\n\n/** Decoded form of a Clarity `print` event:\n * - `topic`: the print topic, when the contract emits a `{ topic, ... }` tuple\n * - `value`: the Clarity value decoded to JSON (uints as strings, buffers as\n * `0x…` hex, tuples as objects)\n * - `raw_value`: the canonical serialized hex, for byte-exact consumers */\nexport type DecodedPrintValue = {\n\ttopic: string | null;\n\tvalue: unknown;\n\traw_value: string | null;\n};\n\nexport type DecodedPrintPayload = {\n\tcontract_id: string | null;\n\tpayload: DecodedPrintValue;\n};\n\nexport type DecodedPrint = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"print\";\n\tdecoded_payload: DecodedPrintPayload;\n\tsource_cursor: string;\n};\n\
|
|
11
|
-
"import {\n\tdecodedRow,\n\toptionalString,\n\trequireAmount,\n\trequireAmountField,\n\trequireString,\n} from \"./_payload.ts\";\nimport type { StreamsEvent } from \"./events.ts\";\n\nexport type DecodedStxTransferPayload = {\n\tsender: string;\n\trecipient: string;\n\tamount: string;\n\tmemo: string | null;\n};\n\nexport type DecodedStxTransfer = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"stx_transfer\";\n\tdecoded_payload: DecodedStxTransferPayload;\n\tsource_cursor: string;\n};\n\nexport type DecodedStxMintPayload = {\n\trecipient: string;\n\tamount: string;\n};\n\nexport type DecodedStxMint = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"stx_mint\";\n\tdecoded_payload: DecodedStxMintPayload;\n\tsource_cursor: string;\n};\n\nexport type DecodedStxBurnPayload = {\n\tsender: string;\n\tamount: string;\n};\n\nexport type DecodedStxBurn = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"stx_burn\";\n\tdecoded_payload: DecodedStxBurnPayload;\n\tsource_cursor: string;\n};\n\nexport function isStxTransfer(\n\tevent: StreamsEvent,\n): event is StreamsEvent & { event_type: \"stx_transfer\" } {\n\treturn event.event_type === \"stx_transfer\";\n}\n\nexport function decodeStxTransfer(event: StreamsEvent): DecodedStxTransfer {\n\tif (!isStxTransfer(event)) {\n\t\tthrow new Error(`Expected stx_transfer event, got ${event.event_type}`);\n\t}\n\tconst payload = event.payload;\n\treturn decodedRow(event, \"stx_transfer\", {\n\t\tsender: requireString(payload, \"sender\", \"stx_transfer\"),\n\t\trecipient: requireString(payload, \"recipient\", \"stx_transfer\"),\n\t\tamount: requireAmount(payload, \"stx_transfer\"),\n\t\tmemo:
|
|
10
|
+
"import { clarityHexOf, decodedRow, optionalString } from \"./_payload.ts\";\nimport { decodeClarityValue, toJsonSafe } from \"./clarity.ts\";\nimport type { StreamsEvent } from \"./events.ts\";\n\n/** Decoded form of a Clarity `print` event:\n * - `topic`: the print topic, when the contract emits a `{ topic, ... }` tuple\n * - `value`: the Clarity value decoded to JSON (uints as strings, buffers as\n * `0x…` hex, tuples as objects)\n * - `raw_value`: the canonical serialized hex, for byte-exact consumers */\nexport type DecodedPrintValue = {\n\ttopic: string | null;\n\tvalue: unknown;\n\traw_value: string | null;\n};\n\nexport type DecodedPrintPayload = {\n\tcontract_id: string | null;\n\tpayload: DecodedPrintValue;\n};\n\nexport type DecodedPrint = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"print\";\n\tdecoded_payload: DecodedPrintPayload;\n\tsource_cursor: string;\n};\n\nexport function isPrint(\n\tevent: StreamsEvent,\n): event is StreamsEvent & { event_type: \"print\" } {\n\treturn event.event_type === \"print\";\n}\n\nexport function decodePrint(event: StreamsEvent): DecodedPrint {\n\tif (!isPrint(event)) {\n\t\tthrow new Error(`Expected print event, got ${event.event_type}`);\n\t}\n\tconst payload = event.payload;\n\tconst topic = optionalString(payload.topic);\n\tconst rawValue = clarityHexOf(payload);\n\n\tconst value = rawValue\n\t\t? decodeClarityValue(rawValue)\n\t\t: toJsonSafe(payload.value ?? null);\n\n\treturn decodedRow(event, \"print\", {\n\t\tcontract_id: event.contract_id ?? optionalString(payload.contract_id),\n\t\tpayload: { topic, value, raw_value: rawValue },\n\t});\n}\n",
|
|
11
|
+
"import {\n\tdecodedRow,\n\tnormalizeMemoHex,\n\toptionalString,\n\trequireAmount,\n\trequireAmountField,\n\trequireString,\n} from \"./_payload.ts\";\nimport type { StreamsEvent } from \"./events.ts\";\n\nexport type DecodedStxTransferPayload = {\n\tsender: string;\n\trecipient: string;\n\tamount: string;\n\tmemo: string | null;\n};\n\nexport type DecodedStxTransfer = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"stx_transfer\";\n\tdecoded_payload: DecodedStxTransferPayload;\n\tsource_cursor: string;\n};\n\nexport type DecodedStxMintPayload = {\n\trecipient: string;\n\tamount: string;\n};\n\nexport type DecodedStxMint = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"stx_mint\";\n\tdecoded_payload: DecodedStxMintPayload;\n\tsource_cursor: string;\n};\n\nexport type DecodedStxBurnPayload = {\n\tsender: string;\n\tamount: string;\n};\n\nexport type DecodedStxBurn = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"stx_burn\";\n\tdecoded_payload: DecodedStxBurnPayload;\n\tsource_cursor: string;\n};\n\nexport function isStxTransfer(\n\tevent: StreamsEvent,\n): event is StreamsEvent & { event_type: \"stx_transfer\" } {\n\treturn event.event_type === \"stx_transfer\";\n}\n\nexport function decodeStxTransfer(event: StreamsEvent): DecodedStxTransfer {\n\tif (!isStxTransfer(event)) {\n\t\tthrow new Error(`Expected stx_transfer event, got ${event.event_type}`);\n\t}\n\tconst payload = event.payload;\n\treturn decodedRow(event, \"stx_transfer\", {\n\t\tsender: requireString(payload, \"sender\", \"stx_transfer\"),\n\t\trecipient: requireString(payload, \"recipient\", \"stx_transfer\"),\n\t\tamount: requireAmount(payload, \"stx_transfer\"),\n\t\tmemo: normalizeMemoHex(payload.memo),\n\t});\n}\n\nexport function isStxMint(\n\tevent: StreamsEvent,\n): event is StreamsEvent & { event_type: \"stx_mint\" } {\n\treturn event.event_type === \"stx_mint\";\n}\n\nexport function decodeStxMint(event: StreamsEvent): DecodedStxMint {\n\tif (!isStxMint(event)) {\n\t\tthrow new Error(`Expected stx_mint event, got ${event.event_type}`);\n\t}\n\tconst payload = event.payload;\n\treturn decodedRow(event, \"stx_mint\", {\n\t\trecipient: requireString(payload, \"recipient\", \"stx_mint\"),\n\t\tamount: requireAmount(payload, \"stx_mint\"),\n\t});\n}\n\nexport function isStxBurn(\n\tevent: StreamsEvent,\n): event is StreamsEvent & { event_type: \"stx_burn\" } {\n\treturn event.event_type === \"stx_burn\";\n}\n\nexport function decodeStxBurn(event: StreamsEvent): DecodedStxBurn {\n\tif (!isStxBurn(event)) {\n\t\tthrow new Error(`Expected stx_burn event, got ${event.event_type}`);\n\t}\n\tconst payload = event.payload;\n\treturn decodedRow(event, \"stx_burn\", {\n\t\tsender: requireString(payload, \"sender\", \"stx_burn\"),\n\t\tamount: requireAmount(payload, \"stx_burn\"),\n\t});\n}\n\nexport type DecodedStxLockPayload = {\n\t// The locked principal maps to `sender` and the locked uSTX to `amount` so\n\t// stx_lock is filterable like the other STX types; the lock-specific\n\t// unlock_height rides in the jsonb `payload` overflow.\n\tsender: string;\n\tamount: string;\n\tpayload: { unlock_height: string | null };\n};\n\nexport type DecodedStxLock = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"stx_lock\";\n\tdecoded_payload: DecodedStxLockPayload;\n\tsource_cursor: string;\n};\n\nexport function isStxLock(\n\tevent: StreamsEvent,\n): event is StreamsEvent & { event_type: \"stx_lock\" } {\n\treturn event.event_type === \"stx_lock\";\n}\n\nexport function decodeStxLock(event: StreamsEvent): DecodedStxLock {\n\tif (!isStxLock(event)) {\n\t\tthrow new Error(`Expected stx_lock event, got ${event.event_type}`);\n\t}\n\tconst payload = event.payload;\n\treturn decodedRow(event, \"stx_lock\", {\n\t\tsender: requireString(payload, \"locked_address\", \"stx_lock\"),\n\t\tamount: requireAmountField(payload, \"locked_amount\", \"stx_lock\"),\n\t\tpayload: { unlock_height: optionalString(payload.unlock_height) },\n\t});\n}\n",
|
|
12
12
|
"import {\n\tdecodedRow,\n\tparseAssetIdentifier,\n\trequireAmount,\n\trequireHexValue,\n\trequireString,\n} from \"./_payload.ts\";\nimport type { StreamsEvent } from \"./events.ts\";\n\nexport type DecodedFtMintPayload = {\n\tasset_identifier: string;\n\tcontract_id: string;\n\ttoken_name: string | null;\n\trecipient: string;\n\tamount: string;\n};\n\nexport type DecodedFtMint = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"ft_mint\";\n\tdecoded_payload: DecodedFtMintPayload;\n\tsource_cursor: string;\n};\n\nexport type DecodedFtBurnPayload = {\n\tasset_identifier: string;\n\tcontract_id: string;\n\ttoken_name: string | null;\n\tsender: string;\n\tamount: string;\n};\n\nexport type DecodedFtBurn = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"ft_burn\";\n\tdecoded_payload: DecodedFtBurnPayload;\n\tsource_cursor: string;\n};\n\nexport type DecodedNftMintPayload = {\n\tasset_identifier: string;\n\tcontract_id: string;\n\ttoken_name: string | null;\n\trecipient: string;\n\tvalue: string;\n};\n\nexport type DecodedNftMint = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"nft_mint\";\n\tdecoded_payload: DecodedNftMintPayload;\n\tsource_cursor: string;\n};\n\nexport type DecodedNftBurnPayload = {\n\tasset_identifier: string;\n\tcontract_id: string;\n\ttoken_name: string | null;\n\tsender: string;\n\tvalue: string;\n};\n\nexport type DecodedNftBurn = {\n\tcursor: string;\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index: number;\n\tevent_index: number;\n\tevent_type: \"nft_burn\";\n\tdecoded_payload: DecodedNftBurnPayload;\n\tsource_cursor: string;\n};\n\nfunction assetFields(event: StreamsEvent, eventType: string) {\n\tconst assetIdentifier = requireString(\n\t\tevent.payload,\n\t\t\"asset_identifier\",\n\t\teventType,\n\t);\n\tconst { contract_id, token_name } = parseAssetIdentifier(\n\t\tassetIdentifier,\n\t\teventType,\n\t);\n\treturn {\n\t\tasset_identifier: assetIdentifier,\n\t\tcontract_id: event.contract_id ?? contract_id,\n\t\ttoken_name,\n\t};\n}\n\nexport function isFtMint(\n\tevent: StreamsEvent,\n): event is StreamsEvent & { event_type: \"ft_mint\" } {\n\treturn event.event_type === \"ft_mint\";\n}\n\nexport function decodeFtMint(event: StreamsEvent): DecodedFtMint {\n\tif (!isFtMint(event)) {\n\t\tthrow new Error(`Expected ft_mint event, got ${event.event_type}`);\n\t}\n\treturn decodedRow(event, \"ft_mint\", {\n\t\t...assetFields(event, \"ft_mint\"),\n\t\trecipient: requireString(event.payload, \"recipient\", \"ft_mint\"),\n\t\tamount: requireAmount(event.payload, \"ft_mint\"),\n\t});\n}\n\nexport function isFtBurn(\n\tevent: StreamsEvent,\n): event is StreamsEvent & { event_type: \"ft_burn\" } {\n\treturn event.event_type === \"ft_burn\";\n}\n\nexport function decodeFtBurn(event: StreamsEvent): DecodedFtBurn {\n\tif (!isFtBurn(event)) {\n\t\tthrow new Error(`Expected ft_burn event, got ${event.event_type}`);\n\t}\n\treturn decodedRow(event, \"ft_burn\", {\n\t\t...assetFields(event, \"ft_burn\"),\n\t\tsender: requireString(event.payload, \"sender\", \"ft_burn\"),\n\t\tamount: requireAmount(event.payload, \"ft_burn\"),\n\t});\n}\n\nexport function isNftMint(\n\tevent: StreamsEvent,\n): event is StreamsEvent & { event_type: \"nft_mint\" } {\n\treturn event.event_type === \"nft_mint\";\n}\n\nexport function decodeNftMint(event: StreamsEvent): DecodedNftMint {\n\tif (!isNftMint(event)) {\n\t\tthrow new Error(`Expected nft_mint event, got ${event.event_type}`);\n\t}\n\treturn decodedRow(event, \"nft_mint\", {\n\t\t...assetFields(event, \"nft_mint\"),\n\t\trecipient: requireString(event.payload, \"recipient\", \"nft_mint\"),\n\t\tvalue: requireHexValue(event.payload, \"nft_mint\"),\n\t});\n}\n\nexport function isNftBurn(\n\tevent: StreamsEvent,\n): event is StreamsEvent & { event_type: \"nft_burn\" } {\n\treturn event.event_type === \"nft_burn\";\n}\n\nexport function decodeNftBurn(event: StreamsEvent): DecodedNftBurn {\n\tif (!isNftBurn(event)) {\n\t\tthrow new Error(`Expected nft_burn event, got ${event.event_type}`);\n\t}\n\treturn decodedRow(event, \"nft_burn\", {\n\t\t...assetFields(event, \"nft_burn\"),\n\t\tsender: requireString(event.payload, \"sender\", \"nft_burn\"),\n\t\tvalue: requireHexValue(event.payload, \"nft_burn\"),\n\t});\n}\n"
|
|
13
13
|
],
|
|
14
|
-
"mappings": ";AAAA;AAIO,SAAS,UAAU,CAAC,OAAyB;AAAA,EACnD,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO,MAAM,SAAS;AAAA,EACrD,IAAI,MAAM,QAAQ,KAAK;AAAA,IAAG,OAAO,MAAM,IAAI,UAAU;AAAA,EACrD,IAAI,SAAS,OAAO,UAAU,UAAU;AAAA,IACvC,MAAM,MAA+B,CAAC;AAAA,IACtC,YAAY,KAAK,QAAQ,OAAO,QAAQ,KAAK,GAAG;AAAA,MAC/C,IAAI,OAAO,WAAW,GAA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@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
import { onChainPlane } from "../src/db/migration-role.ts";
|
|
3
|
+
|
|
4
|
+
// The dedicated pox-4 decoder and `/v1/index/stacking` are gone: pox-4 is a
|
|
5
|
+
// retired contract (the chain runs pox-5), and its history stays readable
|
|
6
|
+
// through the generic layers (contract-calls, Streams). Drop the decoded table
|
|
7
|
+
// and the decoder's checkpoint row. Chain-plane only; each step is skipped
|
|
8
|
+
// when its table is absent.
|
|
9
|
+
async function tableExists(db: Kysely<unknown>, table: string) {
|
|
10
|
+
const { rows } = await sql<{ exists: boolean }>`
|
|
11
|
+
SELECT to_regclass(${`public.${table}`}) IS NOT NULL AS exists
|
|
12
|
+
`.execute(db);
|
|
13
|
+
return rows[0]?.exists === true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
17
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
18
|
+
await onChainPlane(async () => {
|
|
19
|
+
if (await tableExists(db, "pox4_calls")) {
|
|
20
|
+
await sql`DROP TABLE IF EXISTS pox4_calls`.execute(db);
|
|
21
|
+
}
|
|
22
|
+
if (await tableExists(db, "decoder_checkpoints")) {
|
|
23
|
+
await sql`DELETE FROM decoder_checkpoints WHERE decoder_name = 'decode.pox4.v1'`.execute(
|
|
24
|
+
db,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// No-op: nothing reads pox4_calls any more. Its rows are rebuildable from
|
|
31
|
+
// Streams (`contract_id=SP000000000000000000002Q6VF78.pox-4`) if ever needed.
|
|
32
|
+
export async function down(_db: Kysely<unknown>): Promise<void> {}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
import { onChainPlane } from "../src/db/migration-role.ts";
|
|
3
|
+
|
|
4
|
+
// BNS-V2 `buy-in-ustx` prints only `{a, id}`, so buys had no price. A buy needs
|
|
5
|
+
// a `market` entry, which only `list-in-ustx` sets, so the price and commission
|
|
6
|
+
// are on the latest listing for that id before the buy; the decoder now copies
|
|
7
|
+
// them on write. Fill stored buys the same way (133 rows at writing; buys whose
|
|
8
|
+
// listing predates the table stay null). Skipped when the table is absent.
|
|
9
|
+
async function tableExists(db: Kysely<unknown>, table: string) {
|
|
10
|
+
const { rows } = await sql<{ exists: boolean }>`
|
|
11
|
+
SELECT to_regclass(${`public.${table}`}) IS NOT NULL AS exists
|
|
12
|
+
`.execute(db);
|
|
13
|
+
return rows[0]?.exists === true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
17
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
18
|
+
await onChainPlane(async () => {
|
|
19
|
+
if (!(await tableExists(db, "bns_marketplace_events"))) return;
|
|
20
|
+
await sql`
|
|
21
|
+
UPDATE bns_marketplace_events b
|
|
22
|
+
SET (price_ustx, commission) = (
|
|
23
|
+
SELECT l.price_ustx, l.commission
|
|
24
|
+
FROM bns_marketplace_events l
|
|
25
|
+
WHERE l.bns_id = b.bns_id
|
|
26
|
+
AND l.action = 'list-in-ustx'
|
|
27
|
+
AND l.canonical
|
|
28
|
+
AND (l.block_height, l.event_index) < (b.block_height, b.event_index)
|
|
29
|
+
ORDER BY l.block_height DESC, l.event_index DESC
|
|
30
|
+
LIMIT 1
|
|
31
|
+
)
|
|
32
|
+
WHERE b.action = 'buy-in-ustx'
|
|
33
|
+
AND b.price_ustx IS NULL
|
|
34
|
+
`.execute(db);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Data fill only: the decoder writes the same values, nothing to undo.
|
|
39
|
+
export async function down(): Promise<void> {}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
import { onChainPlane } from "../src/db/migration-role.ts";
|
|
3
|
+
|
|
4
|
+
// `calculate-rewards` prints its reward cycle as `stx-cycle`, but the decoder
|
|
5
|
+
// left `reward_cycle` null, so `?reward_cycle=` never found those rows. The
|
|
6
|
+
// decoder now promotes it; fill history from the stored `data` (a few dozen
|
|
7
|
+
// rows). Skipped when the table is absent.
|
|
8
|
+
async function tableExists(db: Kysely<unknown>, table: string) {
|
|
9
|
+
const { rows } = await sql<{ exists: boolean }>`
|
|
10
|
+
SELECT to_regclass(${`public.${table}`}) IS NOT NULL AS exists
|
|
11
|
+
`.execute(db);
|
|
12
|
+
return rows[0]?.exists === true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
16
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
17
|
+
await onChainPlane(async () => {
|
|
18
|
+
if (!(await tableExists(db, "pox5_events"))) return;
|
|
19
|
+
await sql`
|
|
20
|
+
UPDATE pox5_events
|
|
21
|
+
SET reward_cycle = (data->>'stx-cycle')::integer
|
|
22
|
+
WHERE topic = 'calculate-rewards'
|
|
23
|
+
AND reward_cycle IS NULL
|
|
24
|
+
AND data->>'stx-cycle' ~ '^[0-9]{1,9}$'
|
|
25
|
+
`.execute(db);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function down(): Promise<void> {
|
|
30
|
+
// Data-only fill of values the decoder now writes; nothing to undo.
|
|
31
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
import { onChainPlane } from "../src/db/migration-role.ts";
|
|
3
|
+
|
|
4
|
+
// `chain_reorgs.old_index_block_hash` / `new_index_block_hash` held the Stacks
|
|
5
|
+
// block hash (`blocks.hash`), not the index block hash they promise: every row
|
|
6
|
+
// written before this migration did. Rewrite each side to the index hash of the
|
|
7
|
+
// block it names: from `blocks` when that block still holds the fork height,
|
|
8
|
+
// else from a staged `pending_fork_blocks` payload. A side neither holds goes
|
|
9
|
+
// null (unknown) rather than keep a hash of the wrong kind. A side that already
|
|
10
|
+
// names an index hash at its height (written by the fixed indexer) is left
|
|
11
|
+
// alone. Skipped when a table is absent.
|
|
12
|
+
async function tableExists(db: Kysely<unknown>, table: string) {
|
|
13
|
+
const { rows } = await sql<{ exists: boolean }>`
|
|
14
|
+
SELECT to_regclass(${table}) IS NOT NULL AS exists
|
|
15
|
+
`.execute(db);
|
|
16
|
+
return rows[0]?.exists === true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
20
|
+
await onChainPlane(async () => {
|
|
21
|
+
for (const table of ["chain_reorgs", "blocks", "pending_fork_blocks"]) {
|
|
22
|
+
if (!(await tableExists(db, table))) return;
|
|
23
|
+
}
|
|
24
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
25
|
+
for (const side of ["old", "new"] as const) {
|
|
26
|
+
const column = sql.ref(`${side}_index_block_hash`);
|
|
27
|
+
const named = sql.ref(`r.${side}_index_block_hash`);
|
|
28
|
+
await sql`
|
|
29
|
+
UPDATE chain_reorgs r
|
|
30
|
+
SET ${column} = COALESCE(
|
|
31
|
+
(SELECT b.index_block_hash FROM blocks b
|
|
32
|
+
WHERE b.height = r.fork_point_height AND b.hash = ${named}),
|
|
33
|
+
(SELECT NULLIF(p.payload->>'index_block_hash', '')
|
|
34
|
+
FROM pending_fork_blocks p
|
|
35
|
+
WHERE p.height = r.fork_point_height AND p.block_hash = ${named}
|
|
36
|
+
LIMIT 1))
|
|
37
|
+
WHERE ${named} IS NOT NULL
|
|
38
|
+
AND NOT EXISTS (SELECT 1 FROM blocks b
|
|
39
|
+
WHERE b.height = r.fork_point_height
|
|
40
|
+
AND b.index_block_hash = ${named})
|
|
41
|
+
AND NOT EXISTS (SELECT 1 FROM pending_fork_blocks p
|
|
42
|
+
WHERE p.height = r.fork_point_height
|
|
43
|
+
AND p.payload->>'index_block_hash' = ${named})
|
|
44
|
+
`.execute(db);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function down(): Promise<void> {
|
|
50
|
+
// Data repair: the block hashes it replaced were wrong, nothing to restore.
|
|
51
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type Kysely, type RawBuilder, sql } from "kysely";
|
|
2
|
+
import { onChainPlane } from "../src/db/migration-role.ts";
|
|
3
|
+
|
|
4
|
+
// Block ingest now evicts a pending tx once a confirmed tx from its sender
|
|
5
|
+
// spends its nonce. Rows already in `mempool_transactions` predate that and
|
|
6
|
+
// most can never confirm (prod: 173 of 207), so clear them once: a pending tx
|
|
7
|
+
// whose origin nonce is at or below a nonce its sender confirmed is dead.
|
|
8
|
+
//
|
|
9
|
+
// The node admitted each pending tx with a live nonce, so the tx that spent it
|
|
10
|
+
// landed after the oldest receipt: only blocks since then are scanned (an hour
|
|
11
|
+
// of slack, within the last 100k heights), never a sender's whole history.
|
|
12
|
+
// Skipped when a table is absent.
|
|
13
|
+
async function tableExists(db: Kysely<unknown>, table: string) {
|
|
14
|
+
const { rows } = await sql<{ exists: boolean }>`
|
|
15
|
+
SELECT to_regclass(${table}) IS NOT NULL AS exists
|
|
16
|
+
`.execute(db);
|
|
17
|
+
return rows[0]?.exists === true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// SIP-005: the origin nonce is the 8 bytes after version(1) chain_id(4)
|
|
21
|
+
// auth_type(1) hash_mode(1) signer(20), for standard (0x04) and sponsored
|
|
22
|
+
// (0x05) auth alike. Same layout `rawTxNonce` reads.
|
|
23
|
+
function hexOf(column: RawBuilder<unknown>) {
|
|
24
|
+
return sql`regexp_replace(${column}, '^0x', '')`;
|
|
25
|
+
}
|
|
26
|
+
function hasNonce(column: RawBuilder<unknown>) {
|
|
27
|
+
return sql`(substr(${hexOf(column)}, 11, 2) IN ('04', '05')
|
|
28
|
+
AND substr(${hexOf(column)}, 55, 16) ~ '^[0-9a-fA-F]{16}$')`;
|
|
29
|
+
}
|
|
30
|
+
function nonceOf(column: RawBuilder<unknown>) {
|
|
31
|
+
return sql`('x' || substr(${hexOf(column)}, 55, 16))::bit(64)::bigint`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
35
|
+
await onChainPlane(async () => {
|
|
36
|
+
for (const table of ["mempool_transactions", "transactions", "blocks"]) {
|
|
37
|
+
if (!(await tableExists(db, table))) return;
|
|
38
|
+
}
|
|
39
|
+
const { rows } = await sql<{ floor: string | number | null }>`
|
|
40
|
+
SELECT min(height) AS floor
|
|
41
|
+
FROM blocks
|
|
42
|
+
WHERE height > (SELECT max(height) - 100000 FROM blocks)
|
|
43
|
+
AND timestamp >= (
|
|
44
|
+
SELECT extract(epoch FROM min(received_at) - interval '1 hour')
|
|
45
|
+
FROM mempool_transactions)
|
|
46
|
+
`.execute(db);
|
|
47
|
+
if (rows[0]?.floor == null) return;
|
|
48
|
+
const floor = Number(rows[0].floor);
|
|
49
|
+
const pending = sql.ref("m.raw_tx");
|
|
50
|
+
const confirmed = sql.ref("t.raw_tx");
|
|
51
|
+
await sql`
|
|
52
|
+
DELETE FROM mempool_transactions m
|
|
53
|
+
USING (
|
|
54
|
+
SELECT t.sender, max(${nonceOf(confirmed)}) AS spent
|
|
55
|
+
FROM transactions t
|
|
56
|
+
JOIN blocks b ON b.height = t.block_height AND b.canonical
|
|
57
|
+
WHERE t.block_height >= ${floor}
|
|
58
|
+
AND t.sender IN (SELECT sender FROM mempool_transactions)
|
|
59
|
+
AND ${hasNonce(confirmed)}
|
|
60
|
+
GROUP BY t.sender
|
|
61
|
+
) c
|
|
62
|
+
WHERE m.sender = c.sender
|
|
63
|
+
AND ${hasNonce(pending)}
|
|
64
|
+
AND ${nonceOf(pending)} <= c.spent
|
|
65
|
+
`.execute(db);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function down(): Promise<void> {
|
|
70
|
+
// Data cleanup: the evicted txs could never confirm, nothing to restore.
|
|
71
|
+
}
|