ponder 0.9.3 → 0.9.4-debug.1
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/bin/ponder.js +588 -2207
- package/dist/bin/ponder.js.map +1 -1
- package/dist/chunk-6AOFLZJ4.js +1692 -0
- package/dist/chunk-6AOFLZJ4.js.map +1 -0
- package/dist/chunk-DZFRP3KH.js +70 -0
- package/dist/chunk-DZFRP3KH.js.map +1 -0
- package/dist/{chunk-LHCA5XFV.js → chunk-MJKRYIBO.js} +2 -69
- package/dist/chunk-MJKRYIBO.js.map +1 -0
- package/dist/db-in86nyw7.d.ts +625 -0
- package/dist/experimental_unsafe_stores.d.ts +375 -0
- package/dist/experimental_unsafe_stores.js +11 -0
- package/dist/experimental_unsafe_stores.js.map +1 -0
- package/dist/index.d.ts +12 -427
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
- package/src/build/configAndIndexingFunctions.ts +547 -512
- package/src/build/index.ts +2 -0
- package/src/config/index.ts +4 -4
- package/src/experimental_unsafe_stores.ts +4 -0
- package/dist/chunk-LHCA5XFV.js.map +0 -1
package/dist/bin/ponder.js
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
createQueue,
|
|
4
|
-
dedupe,
|
|
5
3
|
getMetadataStore,
|
|
6
4
|
never,
|
|
7
|
-
promiseWithResolvers,
|
|
8
5
|
serialize
|
|
9
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-DZFRP3KH.js";
|
|
10
7
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
BuildError,
|
|
9
|
+
NonRetryableError,
|
|
10
|
+
ShutdownError,
|
|
11
|
+
createHistoricalIndexingStore,
|
|
12
|
+
createRealtimeIndexingStore,
|
|
13
|
+
getColumnCasing,
|
|
14
|
+
getPrimaryKeyColumns,
|
|
15
|
+
getSql,
|
|
16
|
+
getTableNames,
|
|
17
|
+
prettyPrint
|
|
18
|
+
} from "../chunk-6AOFLZJ4.js";
|
|
19
|
+
import {
|
|
20
|
+
createQueue,
|
|
21
|
+
dedupe,
|
|
22
|
+
promiseWithResolvers
|
|
23
|
+
} from "../chunk-MJKRYIBO.js";
|
|
24
|
+
import "../chunk-K2TLRLX3.js";
|
|
13
25
|
|
|
14
26
|
// src/bin/ponder.ts
|
|
15
27
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
@@ -677,106 +689,6 @@ function hrTimeToMs(diff) {
|
|
|
677
689
|
// src/internal/telemetry.ts
|
|
678
690
|
import Conf from "conf";
|
|
679
691
|
import { detect, getNpmVersion } from "detect-package-manager";
|
|
680
|
-
|
|
681
|
-
// src/internal/errors.ts
|
|
682
|
-
var BaseError = class _BaseError extends Error {
|
|
683
|
-
name = "BaseError";
|
|
684
|
-
meta = [];
|
|
685
|
-
constructor(message) {
|
|
686
|
-
super(message);
|
|
687
|
-
Object.setPrototypeOf(this, _BaseError.prototype);
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
function getBaseError(err) {
|
|
691
|
-
if (err instanceof BaseError)
|
|
692
|
-
return err;
|
|
693
|
-
if (err instanceof Error)
|
|
694
|
-
return new BaseError(err.message);
|
|
695
|
-
if (typeof err?.message === "string")
|
|
696
|
-
return new BaseError(err.message);
|
|
697
|
-
if (typeof err === "string")
|
|
698
|
-
return new BaseError(err);
|
|
699
|
-
return new BaseError("unknown error");
|
|
700
|
-
}
|
|
701
|
-
var BuildError = class _BuildError extends BaseError {
|
|
702
|
-
name = "BuildError";
|
|
703
|
-
constructor(message) {
|
|
704
|
-
super(message);
|
|
705
|
-
Object.setPrototypeOf(this, _BuildError.prototype);
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
var NonRetryableError = class _NonRetryableError extends BaseError {
|
|
709
|
-
name = "NonRetryableError";
|
|
710
|
-
constructor(message) {
|
|
711
|
-
super(message);
|
|
712
|
-
Object.setPrototypeOf(this, _NonRetryableError.prototype);
|
|
713
|
-
}
|
|
714
|
-
};
|
|
715
|
-
var UniqueConstraintError = class _UniqueConstraintError extends NonRetryableError {
|
|
716
|
-
name = "UniqueConstraintError";
|
|
717
|
-
constructor(message) {
|
|
718
|
-
super(message);
|
|
719
|
-
Object.setPrototypeOf(this, _UniqueConstraintError.prototype);
|
|
720
|
-
}
|
|
721
|
-
};
|
|
722
|
-
var NotNullConstraintError = class _NotNullConstraintError extends NonRetryableError {
|
|
723
|
-
name = "NotNullConstraintError";
|
|
724
|
-
constructor(message) {
|
|
725
|
-
super(message);
|
|
726
|
-
Object.setPrototypeOf(this, _NotNullConstraintError.prototype);
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
var RecordNotFoundError = class _RecordNotFoundError extends NonRetryableError {
|
|
730
|
-
name = "RecordNotFoundError";
|
|
731
|
-
constructor(message) {
|
|
732
|
-
super(message);
|
|
733
|
-
Object.setPrototypeOf(this, _RecordNotFoundError.prototype);
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
var CheckConstraintError = class _CheckConstraintError extends NonRetryableError {
|
|
737
|
-
name = "CheckConstraintError";
|
|
738
|
-
constructor(message) {
|
|
739
|
-
super(message);
|
|
740
|
-
Object.setPrototypeOf(this, _CheckConstraintError.prototype);
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
var InvalidStoreMethodError = class _InvalidStoreMethodError extends NonRetryableError {
|
|
744
|
-
name = "InvalidStoreMethodError";
|
|
745
|
-
constructor(message) {
|
|
746
|
-
super(message);
|
|
747
|
-
Object.setPrototypeOf(this, _InvalidStoreMethodError.prototype);
|
|
748
|
-
}
|
|
749
|
-
};
|
|
750
|
-
var UndefinedTableError = class _UndefinedTableError extends NonRetryableError {
|
|
751
|
-
name = "UndefinedTableError";
|
|
752
|
-
constructor(message) {
|
|
753
|
-
super(message);
|
|
754
|
-
Object.setPrototypeOf(this, _UndefinedTableError.prototype);
|
|
755
|
-
}
|
|
756
|
-
};
|
|
757
|
-
var BigIntSerializationError = class _BigIntSerializationError extends NonRetryableError {
|
|
758
|
-
name = "BigIntSerializationError";
|
|
759
|
-
constructor(message) {
|
|
760
|
-
super(message);
|
|
761
|
-
Object.setPrototypeOf(this, _BigIntSerializationError.prototype);
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
var FlushError = class _FlushError extends NonRetryableError {
|
|
765
|
-
name = "FlushError";
|
|
766
|
-
constructor(message) {
|
|
767
|
-
super(message);
|
|
768
|
-
Object.setPrototypeOf(this, _FlushError.prototype);
|
|
769
|
-
}
|
|
770
|
-
};
|
|
771
|
-
var ShutdownError = class _ShutdownError extends NonRetryableError {
|
|
772
|
-
name = "ShutdownError";
|
|
773
|
-
constructor(message) {
|
|
774
|
-
super(message);
|
|
775
|
-
Object.setPrototypeOf(this, _ShutdownError.prototype);
|
|
776
|
-
}
|
|
777
|
-
};
|
|
778
|
-
|
|
779
|
-
// src/internal/telemetry.ts
|
|
780
692
|
var HEARTBEAT_INTERVAL_MS = 6e4;
|
|
781
693
|
function createTelemetry({
|
|
782
694
|
options,
|
|
@@ -1655,6 +1567,9 @@ var shouldGetTransactionReceipt = (filter) => {
|
|
|
1655
1567
|
return false;
|
|
1656
1568
|
};
|
|
1657
1569
|
|
|
1570
|
+
// src/build/configAndIndexingFunctions.ts
|
|
1571
|
+
import { BlockNotFoundError, hexToNumber as hexToNumber2 } from "viem";
|
|
1572
|
+
|
|
1658
1573
|
// src/utils/offset.ts
|
|
1659
1574
|
import { InvalidAbiDecodingTypeError } from "viem";
|
|
1660
1575
|
function getBytesConsumedByParam(param) {
|
|
@@ -1785,6 +1700,37 @@ async function buildConfigAndIndexingFunctions({
|
|
|
1785
1700
|
rawIndexingFunctions
|
|
1786
1701
|
}) {
|
|
1787
1702
|
const logs = [];
|
|
1703
|
+
const perNetworkLatestBlockNumber = /* @__PURE__ */ new Map();
|
|
1704
|
+
const resolveBlockNumber = async (blockNumberOrTag, network) => {
|
|
1705
|
+
if (blockNumberOrTag === void 0) {
|
|
1706
|
+
return void 0;
|
|
1707
|
+
}
|
|
1708
|
+
if (Number.isNaN(blockNumberOrTag)) {
|
|
1709
|
+
return void 0;
|
|
1710
|
+
}
|
|
1711
|
+
if (blockNumberOrTag === "latest") {
|
|
1712
|
+
if (perNetworkLatestBlockNumber.has(network.name)) {
|
|
1713
|
+
return perNetworkLatestBlockNumber.get(network.name);
|
|
1714
|
+
} else {
|
|
1715
|
+
const blockPromise = network.transport.request({
|
|
1716
|
+
method: "eth_getBlockByNumber",
|
|
1717
|
+
params: ["latest", false]
|
|
1718
|
+
}).then((block) => {
|
|
1719
|
+
if (!block)
|
|
1720
|
+
throw new BlockNotFoundError({ blockNumber: "latest" });
|
|
1721
|
+
return hexToNumber2(block.number);
|
|
1722
|
+
}).catch((e) => {
|
|
1723
|
+
throw new Error(
|
|
1724
|
+
`Unable to fetch "latest" block for network '${network.name}':
|
|
1725
|
+
${e.message}`
|
|
1726
|
+
);
|
|
1727
|
+
});
|
|
1728
|
+
perNetworkLatestBlockNumber.set(network.name, blockPromise);
|
|
1729
|
+
return blockPromise;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
return blockNumberOrTag;
|
|
1733
|
+
};
|
|
1788
1734
|
const networks = await Promise.all(
|
|
1789
1735
|
Object.entries(config.networks).map(async ([networkName, network]) => {
|
|
1790
1736
|
const { chainId, transport } = network;
|
|
@@ -1893,450 +1839,458 @@ async function buildConfigAndIndexingFunctions({
|
|
|
1893
1839
|
`Validation failed: Network for '${source.name}' is null or undefined. Expected one of [${networks.map((n) => `'${n.name}'`).join(", ")}].`
|
|
1894
1840
|
);
|
|
1895
1841
|
}
|
|
1896
|
-
const startBlockMaybeNan = source.startBlock;
|
|
1897
|
-
const startBlock = Number.isNaN(startBlockMaybeNan) ? void 0 : startBlockMaybeNan;
|
|
1898
|
-
const endBlockMaybeNan = source.endBlock;
|
|
1899
|
-
const endBlock = Number.isNaN(endBlockMaybeNan) ? void 0 : endBlockMaybeNan;
|
|
1900
|
-
if (startBlock !== void 0 && endBlock !== void 0 && endBlock < startBlock) {
|
|
1901
|
-
throw new Error(
|
|
1902
|
-
`Validation failed: Start block for '${source.name}' is after end block (${startBlock} > ${endBlock}).`
|
|
1903
|
-
);
|
|
1904
|
-
}
|
|
1905
1842
|
const network = networks.find((n) => n.name === source.network);
|
|
1906
1843
|
if (!network) {
|
|
1907
1844
|
throw new Error(
|
|
1908
1845
|
`Validation failed: Invalid network for '${source.name}'. Got '${source.network}', expected one of [${networks.map((n) => `'${n.name}'`).join(", ")}].`
|
|
1909
1846
|
);
|
|
1910
1847
|
}
|
|
1848
|
+
const startBlock = await resolveBlockNumber(source.startBlock, network);
|
|
1849
|
+
const endBlock = await resolveBlockNumber(source.endBlock, network);
|
|
1850
|
+
if (startBlock !== void 0 && endBlock !== void 0 && endBlock < startBlock) {
|
|
1851
|
+
throw new Error(
|
|
1852
|
+
`Validation failed: Start block for '${source.name}' is after end block (${startBlock} > ${endBlock}).`
|
|
1853
|
+
);
|
|
1854
|
+
}
|
|
1911
1855
|
}
|
|
1912
|
-
const contractSources =
|
|
1913
|
-
config.contracts ?? {}
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1856
|
+
const contractSources = (await Promise.all(
|
|
1857
|
+
flattenSources(config.contracts ?? {}).map(
|
|
1858
|
+
async (source) => {
|
|
1859
|
+
const network = networks.find((n) => n.name === source.network);
|
|
1860
|
+
const registeredLogEvents = [];
|
|
1861
|
+
const registeredCallTraceEvents = [];
|
|
1862
|
+
for (const eventName of Object.keys(indexingFunctions)) {
|
|
1863
|
+
if (eventName.includes(":")) {
|
|
1864
|
+
const [logContractName, logEventName] = eventName.split(":");
|
|
1865
|
+
if (logContractName === source.name && logEventName !== "setup") {
|
|
1866
|
+
registeredLogEvents.push(logEventName);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
if (eventName.includes(".")) {
|
|
1870
|
+
const [functionContractName, functionName] = eventName.split(
|
|
1871
|
+
"."
|
|
1872
|
+
);
|
|
1873
|
+
if (functionContractName === source.name) {
|
|
1874
|
+
registeredCallTraceEvents.push(functionName);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1923
1877
|
}
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
const
|
|
1927
|
-
|
|
1928
|
-
|
|
1878
|
+
const abiEvents = buildAbiEvents({ abi: source.abi });
|
|
1879
|
+
const abiFunctions = buildAbiFunctions({ abi: source.abi });
|
|
1880
|
+
const registeredEventSelectors = [];
|
|
1881
|
+
for (const logEvent of registeredLogEvents) {
|
|
1882
|
+
const abiEvent = abiEvents.bySafeName[logEvent];
|
|
1883
|
+
if (abiEvent === void 0) {
|
|
1884
|
+
throw new Error(
|
|
1885
|
+
`Validation failed: Event name for event '${logEvent}' not found in the contract ABI. Got '${logEvent}', expected one of [${Object.keys(
|
|
1886
|
+
abiEvents.bySafeName
|
|
1887
|
+
).map((eventName) => `'${eventName}'`).join(", ")}].`
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1890
|
+
registeredEventSelectors.push(abiEvent.selector);
|
|
1929
1891
|
}
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
for (const filter of eventFilters) {
|
|
1962
|
-
const abiEvent = abiEvents.bySafeName[filter.event];
|
|
1963
|
-
if (!abiEvent) {
|
|
1964
|
-
throw new Error(
|
|
1965
|
-
`Validation failed: Invalid filter for contract '${source.name}'. Got event name '${filter.event}', expected one of [${Object.keys(
|
|
1966
|
-
abiEvents.bySafeName
|
|
1967
|
-
).map((n) => `'${n}'`).join(", ")}].`
|
|
1892
|
+
const registeredFunctionSelectors = [];
|
|
1893
|
+
for (const _function of registeredCallTraceEvents) {
|
|
1894
|
+
const abiFunction = abiFunctions.bySafeName[_function];
|
|
1895
|
+
if (abiFunction === void 0) {
|
|
1896
|
+
throw new Error(
|
|
1897
|
+
`Validation failed: Function name for function '${_function}' not found in the contract ABI. Got '${_function}', expected one of [${Object.keys(
|
|
1898
|
+
abiFunctions.bySafeName
|
|
1899
|
+
).map((eventName) => `'${eventName}'`).join(", ")}].`
|
|
1900
|
+
);
|
|
1901
|
+
}
|
|
1902
|
+
registeredFunctionSelectors.push(abiFunction.selector);
|
|
1903
|
+
}
|
|
1904
|
+
const topicsArray = [];
|
|
1905
|
+
if (source.filter !== void 0) {
|
|
1906
|
+
const eventFilters = Array.isArray(source.filter) ? source.filter : [source.filter];
|
|
1907
|
+
for (const filter of eventFilters) {
|
|
1908
|
+
const abiEvent = abiEvents.bySafeName[filter.event];
|
|
1909
|
+
if (!abiEvent) {
|
|
1910
|
+
throw new Error(
|
|
1911
|
+
`Validation failed: Invalid filter for contract '${source.name}'. Got event name '${filter.event}', expected one of [${Object.keys(
|
|
1912
|
+
abiEvents.bySafeName
|
|
1913
|
+
).map((n) => `'${n}'`).join(", ")}].`
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
topicsArray.push(...buildTopics(source.abi, eventFilters));
|
|
1918
|
+
const filteredEventSelectors = topicsArray.map(
|
|
1919
|
+
(t) => t.topic0
|
|
1920
|
+
);
|
|
1921
|
+
const excludedRegisteredEventSelectors = registeredEventSelectors.filter(
|
|
1922
|
+
(s) => filteredEventSelectors.includes(s) === false
|
|
1968
1923
|
);
|
|
1924
|
+
for (const selector of filteredEventSelectors) {
|
|
1925
|
+
if (registeredEventSelectors.includes(selector) === false) {
|
|
1926
|
+
throw new Error(
|
|
1927
|
+
`Validation failed: Event selector '${abiEvents.bySelector[selector]?.safeName}' is used in a filter but does not have a corresponding indexing function.`
|
|
1928
|
+
);
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
if (excludedRegisteredEventSelectors.length > 0) {
|
|
1932
|
+
topicsArray.push({
|
|
1933
|
+
topic0: excludedRegisteredEventSelectors,
|
|
1934
|
+
topic1: null,
|
|
1935
|
+
topic2: null,
|
|
1936
|
+
topic3: null
|
|
1937
|
+
});
|
|
1938
|
+
}
|
|
1939
|
+
} else {
|
|
1940
|
+
topicsArray.push({
|
|
1941
|
+
topic0: registeredEventSelectors,
|
|
1942
|
+
topic1: null,
|
|
1943
|
+
topic2: null,
|
|
1944
|
+
topic3: null
|
|
1945
|
+
});
|
|
1969
1946
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1947
|
+
const fromBlock = await resolveBlockNumber(
|
|
1948
|
+
source.startBlock,
|
|
1949
|
+
network
|
|
1950
|
+
);
|
|
1951
|
+
const toBlock = await resolveBlockNumber(source.endBlock, network);
|
|
1952
|
+
const contractMetadata = {
|
|
1953
|
+
type: "contract",
|
|
1954
|
+
abi: source.abi,
|
|
1955
|
+
abiEvents,
|
|
1956
|
+
abiFunctions,
|
|
1957
|
+
name: source.name,
|
|
1958
|
+
network
|
|
1959
|
+
};
|
|
1960
|
+
const resolvedAddress = source?.address;
|
|
1961
|
+
if (typeof resolvedAddress === "object" && !Array.isArray(resolvedAddress)) {
|
|
1962
|
+
const logFactory = buildLogFactory({
|
|
1963
|
+
chainId: network.chainId,
|
|
1964
|
+
...resolvedAddress
|
|
1965
|
+
});
|
|
1966
|
+
const logSources2 = topicsArray.map(
|
|
1967
|
+
(topics) => ({
|
|
1968
|
+
...contractMetadata,
|
|
1969
|
+
filter: {
|
|
1970
|
+
type: "log",
|
|
1971
|
+
chainId: network.chainId,
|
|
1972
|
+
address: logFactory,
|
|
1973
|
+
topic0: topics.topic0,
|
|
1974
|
+
topic1: topics.topic1,
|
|
1975
|
+
topic2: topics.topic2,
|
|
1976
|
+
topic3: topics.topic3,
|
|
1977
|
+
fromBlock,
|
|
1978
|
+
toBlock,
|
|
1979
|
+
include: defaultLogFilterInclude.concat(
|
|
1980
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
1981
|
+
)
|
|
1982
|
+
}
|
|
1983
|
+
})
|
|
1982
1984
|
);
|
|
1985
|
+
if (source.includeCallTraces) {
|
|
1986
|
+
return [
|
|
1987
|
+
...logSources2,
|
|
1988
|
+
{
|
|
1989
|
+
...contractMetadata,
|
|
1990
|
+
filter: {
|
|
1991
|
+
type: "trace",
|
|
1992
|
+
chainId: network.chainId,
|
|
1993
|
+
fromAddress: void 0,
|
|
1994
|
+
toAddress: logFactory,
|
|
1995
|
+
callType: "CALL",
|
|
1996
|
+
functionSelector: registeredFunctionSelectors,
|
|
1997
|
+
includeReverted: false,
|
|
1998
|
+
fromBlock,
|
|
1999
|
+
toBlock,
|
|
2000
|
+
include: defaultTraceFilterInclude.concat(
|
|
2001
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2002
|
+
)
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
];
|
|
2006
|
+
}
|
|
2007
|
+
return logSources2;
|
|
2008
|
+
} else if (resolvedAddress !== void 0) {
|
|
2009
|
+
for (const address of Array.isArray(resolvedAddress) ? resolvedAddress : [resolvedAddress]) {
|
|
2010
|
+
if (!address.startsWith("0x"))
|
|
2011
|
+
throw new Error(
|
|
2012
|
+
`Validation failed: Invalid prefix for address '${address}'. Got '${address.slice(
|
|
2013
|
+
0,
|
|
2014
|
+
2
|
|
2015
|
+
)}', expected '0x'.`
|
|
2016
|
+
);
|
|
2017
|
+
if (address.length !== 42)
|
|
2018
|
+
throw new Error(
|
|
2019
|
+
`Validation failed: Invalid length for address '${address}'. Got ${address.length}, expected 42 characters.`
|
|
2020
|
+
);
|
|
2021
|
+
}
|
|
1983
2022
|
}
|
|
2023
|
+
const validatedAddress = Array.isArray(resolvedAddress) ? dedupe(resolvedAddress).map((r) => toLowerCase(r)) : resolvedAddress !== void 0 ? toLowerCase(resolvedAddress) : void 0;
|
|
2024
|
+
const logSources = topicsArray.map(
|
|
2025
|
+
(topics) => ({
|
|
2026
|
+
...contractMetadata,
|
|
2027
|
+
filter: {
|
|
2028
|
+
type: "log",
|
|
2029
|
+
chainId: network.chainId,
|
|
2030
|
+
address: validatedAddress,
|
|
2031
|
+
topic0: topics.topic0,
|
|
2032
|
+
topic1: topics.topic1,
|
|
2033
|
+
topic2: topics.topic2,
|
|
2034
|
+
topic3: topics.topic3,
|
|
2035
|
+
fromBlock,
|
|
2036
|
+
toBlock,
|
|
2037
|
+
include: defaultLogFilterInclude.concat(
|
|
2038
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2039
|
+
)
|
|
2040
|
+
}
|
|
2041
|
+
})
|
|
2042
|
+
);
|
|
2043
|
+
if (source.includeCallTraces) {
|
|
2044
|
+
return [
|
|
2045
|
+
...logSources,
|
|
2046
|
+
{
|
|
2047
|
+
...contractMetadata,
|
|
2048
|
+
filter: {
|
|
2049
|
+
type: "trace",
|
|
2050
|
+
chainId: network.chainId,
|
|
2051
|
+
fromAddress: void 0,
|
|
2052
|
+
toAddress: Array.isArray(validatedAddress) ? validatedAddress : validatedAddress === void 0 ? void 0 : [validatedAddress],
|
|
2053
|
+
callType: "CALL",
|
|
2054
|
+
functionSelector: registeredFunctionSelectors,
|
|
2055
|
+
includeReverted: false,
|
|
2056
|
+
fromBlock,
|
|
2057
|
+
toBlock,
|
|
2058
|
+
include: defaultTraceFilterInclude.concat(
|
|
2059
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2060
|
+
)
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
];
|
|
2064
|
+
} else
|
|
2065
|
+
return logSources;
|
|
1984
2066
|
}
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
} else {
|
|
1994
|
-
topicsArray.push({
|
|
1995
|
-
topic0: registeredEventSelectors,
|
|
1996
|
-
topic1: null,
|
|
1997
|
-
topic2: null,
|
|
1998
|
-
topic3: null
|
|
2067
|
+
)
|
|
2068
|
+
)).flat().filter((source) => {
|
|
2069
|
+
const hasNoRegisteredIndexingFunctions = source.filter.type === "trace" ? Array.isArray(source.filter.functionSelector) && source.filter.functionSelector.length === 0 : Array.isArray(source.filter.topic0) && source.filter.topic0?.length === 0;
|
|
2070
|
+
if (hasNoRegisteredIndexingFunctions) {
|
|
2071
|
+
logs.push({
|
|
2072
|
+
level: "debug",
|
|
2073
|
+
msg: `No indexing functions were registered for '${source.name}' ${source.filter.type === "trace" ? "traces" : "logs"}`
|
|
1999
2074
|
});
|
|
2000
2075
|
}
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
(topics) => ({
|
|
2021
|
-
...contractMetadata,
|
|
2022
|
-
filter: {
|
|
2023
|
-
type: "log",
|
|
2076
|
+
return hasNoRegisteredIndexingFunctions === false;
|
|
2077
|
+
});
|
|
2078
|
+
const accountSources = (await Promise.all(
|
|
2079
|
+
flattenSources(config.accounts ?? {}).map(
|
|
2080
|
+
async (source) => {
|
|
2081
|
+
const network = networks.find((n) => n.name === source.network);
|
|
2082
|
+
const fromBlock = await resolveBlockNumber(
|
|
2083
|
+
source.startBlock,
|
|
2084
|
+
network
|
|
2085
|
+
);
|
|
2086
|
+
const toBlock = await resolveBlockNumber(source.endBlock, network);
|
|
2087
|
+
const resolvedAddress = source?.address;
|
|
2088
|
+
if (resolvedAddress === void 0) {
|
|
2089
|
+
throw new Error(
|
|
2090
|
+
`Validation failed: Account '${source.name}' must specify an 'address'.`
|
|
2091
|
+
);
|
|
2092
|
+
}
|
|
2093
|
+
if (typeof resolvedAddress === "object" && !Array.isArray(resolvedAddress)) {
|
|
2094
|
+
const logFactory = buildLogFactory({
|
|
2024
2095
|
chainId: network.chainId,
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2096
|
+
...resolvedAddress
|
|
2097
|
+
});
|
|
2098
|
+
return [
|
|
2099
|
+
{
|
|
2100
|
+
type: "account",
|
|
2101
|
+
name: source.name,
|
|
2102
|
+
network,
|
|
2103
|
+
filter: {
|
|
2104
|
+
type: "transaction",
|
|
2105
|
+
chainId: network.chainId,
|
|
2106
|
+
fromAddress: void 0,
|
|
2107
|
+
toAddress: logFactory,
|
|
2108
|
+
includeReverted: false,
|
|
2109
|
+
fromBlock,
|
|
2110
|
+
toBlock,
|
|
2111
|
+
include: defaultTransactionFilterInclude
|
|
2112
|
+
}
|
|
2113
|
+
},
|
|
2114
|
+
{
|
|
2115
|
+
type: "account",
|
|
2116
|
+
name: source.name,
|
|
2117
|
+
network,
|
|
2118
|
+
filter: {
|
|
2119
|
+
type: "transaction",
|
|
2120
|
+
chainId: network.chainId,
|
|
2121
|
+
fromAddress: logFactory,
|
|
2122
|
+
toAddress: void 0,
|
|
2123
|
+
includeReverted: false,
|
|
2124
|
+
fromBlock,
|
|
2125
|
+
toBlock,
|
|
2126
|
+
include: defaultTransactionFilterInclude
|
|
2127
|
+
}
|
|
2128
|
+
},
|
|
2129
|
+
{
|
|
2130
|
+
type: "account",
|
|
2131
|
+
name: source.name,
|
|
2132
|
+
network,
|
|
2133
|
+
filter: {
|
|
2134
|
+
type: "transfer",
|
|
2135
|
+
chainId: network.chainId,
|
|
2136
|
+
fromAddress: void 0,
|
|
2137
|
+
toAddress: logFactory,
|
|
2138
|
+
includeReverted: false,
|
|
2139
|
+
fromBlock,
|
|
2140
|
+
toBlock,
|
|
2141
|
+
include: defaultTransferFilterInclude.concat(
|
|
2142
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2143
|
+
)
|
|
2144
|
+
}
|
|
2145
|
+
},
|
|
2146
|
+
{
|
|
2147
|
+
type: "account",
|
|
2148
|
+
name: source.name,
|
|
2149
|
+
network,
|
|
2150
|
+
filter: {
|
|
2151
|
+
type: "transfer",
|
|
2152
|
+
chainId: network.chainId,
|
|
2153
|
+
fromAddress: logFactory,
|
|
2154
|
+
toAddress: void 0,
|
|
2155
|
+
includeReverted: false,
|
|
2156
|
+
fromBlock,
|
|
2157
|
+
toBlock,
|
|
2158
|
+
include: defaultTransferFilterInclude.concat(
|
|
2159
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2160
|
+
)
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
];
|
|
2164
|
+
}
|
|
2165
|
+
for (const address of Array.isArray(resolvedAddress) ? resolvedAddress : [resolvedAddress]) {
|
|
2166
|
+
if (!address.startsWith("0x"))
|
|
2167
|
+
throw new Error(
|
|
2168
|
+
`Validation failed: Invalid prefix for address '${address}'. Got '${address.slice(
|
|
2169
|
+
0,
|
|
2170
|
+
2
|
|
2171
|
+
)}', expected '0x'.`
|
|
2172
|
+
);
|
|
2173
|
+
if (address.length !== 42)
|
|
2174
|
+
throw new Error(
|
|
2175
|
+
`Validation failed: Invalid length for address '${address}'. Got ${address.length}, expected 42 characters.`
|
|
2176
|
+
);
|
|
2177
|
+
}
|
|
2178
|
+
const validatedAddress = Array.isArray(resolvedAddress) ? dedupe(resolvedAddress).map((r) => toLowerCase(r)) : resolvedAddress !== void 0 ? toLowerCase(resolvedAddress) : void 0;
|
|
2039
2179
|
return [
|
|
2040
|
-
...logSources2,
|
|
2041
2180
|
{
|
|
2042
|
-
|
|
2181
|
+
type: "account",
|
|
2182
|
+
name: source.name,
|
|
2183
|
+
network,
|
|
2184
|
+
filter: {
|
|
2185
|
+
type: "transaction",
|
|
2186
|
+
chainId: network.chainId,
|
|
2187
|
+
fromAddress: void 0,
|
|
2188
|
+
toAddress: validatedAddress,
|
|
2189
|
+
includeReverted: false,
|
|
2190
|
+
fromBlock,
|
|
2191
|
+
toBlock,
|
|
2192
|
+
include: defaultTransactionFilterInclude
|
|
2193
|
+
}
|
|
2194
|
+
},
|
|
2195
|
+
{
|
|
2196
|
+
type: "account",
|
|
2197
|
+
name: source.name,
|
|
2198
|
+
network,
|
|
2199
|
+
filter: {
|
|
2200
|
+
type: "transaction",
|
|
2201
|
+
chainId: network.chainId,
|
|
2202
|
+
fromAddress: validatedAddress,
|
|
2203
|
+
toAddress: void 0,
|
|
2204
|
+
includeReverted: false,
|
|
2205
|
+
fromBlock,
|
|
2206
|
+
toBlock,
|
|
2207
|
+
include: defaultTransactionFilterInclude
|
|
2208
|
+
}
|
|
2209
|
+
},
|
|
2210
|
+
{
|
|
2211
|
+
type: "account",
|
|
2212
|
+
name: source.name,
|
|
2213
|
+
network,
|
|
2043
2214
|
filter: {
|
|
2044
|
-
type: "
|
|
2215
|
+
type: "transfer",
|
|
2045
2216
|
chainId: network.chainId,
|
|
2046
2217
|
fromAddress: void 0,
|
|
2047
|
-
toAddress:
|
|
2048
|
-
|
|
2049
|
-
|
|
2218
|
+
toAddress: validatedAddress,
|
|
2219
|
+
includeReverted: false,
|
|
2220
|
+
fromBlock,
|
|
2221
|
+
toBlock,
|
|
2222
|
+
include: defaultTransferFilterInclude.concat(
|
|
2223
|
+
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2224
|
+
)
|
|
2225
|
+
}
|
|
2226
|
+
},
|
|
2227
|
+
{
|
|
2228
|
+
type: "account",
|
|
2229
|
+
name: source.name,
|
|
2230
|
+
network,
|
|
2231
|
+
filter: {
|
|
2232
|
+
type: "transfer",
|
|
2233
|
+
chainId: network.chainId,
|
|
2234
|
+
fromAddress: validatedAddress,
|
|
2235
|
+
toAddress: void 0,
|
|
2050
2236
|
includeReverted: false,
|
|
2051
2237
|
fromBlock,
|
|
2052
2238
|
toBlock,
|
|
2053
|
-
include:
|
|
2239
|
+
include: defaultTransferFilterInclude.concat(
|
|
2054
2240
|
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2055
2241
|
)
|
|
2056
2242
|
}
|
|
2057
2243
|
}
|
|
2058
2244
|
];
|
|
2059
2245
|
}
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
);
|
|
2070
|
-
if (address.length !== 42)
|
|
2071
|
-
throw new Error(
|
|
2072
|
-
`Validation failed: Invalid length for address '${address}'. Got ${address.length}, expected 42 characters.`
|
|
2073
|
-
);
|
|
2074
|
-
}
|
|
2246
|
+
)
|
|
2247
|
+
)).flat().filter((source) => {
|
|
2248
|
+
const eventName = source.filter.type === "transaction" ? source.filter.fromAddress === void 0 ? `${source.name}:transaction:to` : `${source.name}:transaction:from` : source.filter.fromAddress === void 0 ? `${source.name}:transfer:to` : `${source.name}:transfer:from`;
|
|
2249
|
+
const hasRegisteredIndexingFunction = indexingFunctions[eventName] !== void 0;
|
|
2250
|
+
if (!hasRegisteredIndexingFunction) {
|
|
2251
|
+
logs.push({
|
|
2252
|
+
level: "debug",
|
|
2253
|
+
msg: `No indexing functions were registered for '${eventName}'`
|
|
2254
|
+
});
|
|
2075
2255
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2256
|
+
return hasRegisteredIndexingFunction;
|
|
2257
|
+
});
|
|
2258
|
+
const blockSources = (await Promise.all(
|
|
2259
|
+
flattenSources(config.blocks ?? {}).map(async (source) => {
|
|
2260
|
+
const network = networks.find((n) => n.name === source.network);
|
|
2261
|
+
const intervalMaybeNan = source.interval ?? 1;
|
|
2262
|
+
const interval = Number.isNaN(intervalMaybeNan) ? 0 : intervalMaybeNan;
|
|
2263
|
+
if (!Number.isInteger(interval) || interval === 0) {
|
|
2264
|
+
throw new Error(
|
|
2265
|
+
`Validation failed: Invalid interval for block source '${source.name}'. Got ${interval}, expected a non-zero integer.`
|
|
2266
|
+
);
|
|
2267
|
+
}
|
|
2268
|
+
const fromBlock = await resolveBlockNumber(source.startBlock, network);
|
|
2269
|
+
const toBlock = await resolveBlockNumber(source.endBlock, network);
|
|
2270
|
+
return {
|
|
2271
|
+
type: "block",
|
|
2272
|
+
name: source.name,
|
|
2273
|
+
network,
|
|
2080
2274
|
filter: {
|
|
2081
|
-
type: "
|
|
2275
|
+
type: "block",
|
|
2082
2276
|
chainId: network.chainId,
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
topic1: topics.topic1,
|
|
2086
|
-
topic2: topics.topic2,
|
|
2087
|
-
topic3: topics.topic3,
|
|
2277
|
+
interval,
|
|
2278
|
+
offset: (fromBlock ?? 0) % interval,
|
|
2088
2279
|
fromBlock,
|
|
2089
2280
|
toBlock,
|
|
2090
|
-
include:
|
|
2091
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2092
|
-
)
|
|
2093
|
-
}
|
|
2094
|
-
})
|
|
2095
|
-
);
|
|
2096
|
-
if (source.includeCallTraces) {
|
|
2097
|
-
return [
|
|
2098
|
-
...logSources,
|
|
2099
|
-
{
|
|
2100
|
-
...contractMetadata,
|
|
2101
|
-
filter: {
|
|
2102
|
-
type: "trace",
|
|
2103
|
-
chainId: network.chainId,
|
|
2104
|
-
fromAddress: void 0,
|
|
2105
|
-
toAddress: Array.isArray(validatedAddress) ? validatedAddress : validatedAddress === void 0 ? void 0 : [validatedAddress],
|
|
2106
|
-
callType: "CALL",
|
|
2107
|
-
functionSelector: registeredFunctionSelectors,
|
|
2108
|
-
includeReverted: false,
|
|
2109
|
-
fromBlock,
|
|
2110
|
-
toBlock,
|
|
2111
|
-
include: defaultTraceFilterInclude.concat(
|
|
2112
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2113
|
-
)
|
|
2114
|
-
}
|
|
2281
|
+
include: defaultBlockFilterInclude
|
|
2115
2282
|
}
|
|
2116
|
-
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
if (hasNoRegisteredIndexingFunctions) {
|
|
2283
|
+
};
|
|
2284
|
+
})
|
|
2285
|
+
)).flat().filter((blockSource) => {
|
|
2286
|
+
const hasRegisteredIndexingFunction = indexingFunctions[`${blockSource.name}:block`] !== void 0;
|
|
2287
|
+
if (!hasRegisteredIndexingFunction) {
|
|
2122
2288
|
logs.push({
|
|
2123
2289
|
level: "debug",
|
|
2124
|
-
msg: `No indexing functions were registered for '${
|
|
2290
|
+
msg: `No indexing functions were registered for '${blockSource.name}' blocks`
|
|
2125
2291
|
});
|
|
2126
2292
|
}
|
|
2127
|
-
return
|
|
2128
|
-
});
|
|
2129
|
-
const accountSources = flattenSources(config.accounts ?? {}).flatMap((source) => {
|
|
2130
|
-
const network = networks.find((n) => n.name === source.network);
|
|
2131
|
-
const startBlockMaybeNan = source.startBlock;
|
|
2132
|
-
const fromBlock = Number.isNaN(startBlockMaybeNan) ? void 0 : startBlockMaybeNan;
|
|
2133
|
-
const endBlockMaybeNan = source.endBlock;
|
|
2134
|
-
const toBlock = Number.isNaN(endBlockMaybeNan) ? void 0 : endBlockMaybeNan;
|
|
2135
|
-
const resolvedAddress = source?.address;
|
|
2136
|
-
if (resolvedAddress === void 0) {
|
|
2137
|
-
throw new Error(
|
|
2138
|
-
`Validation failed: Account '${source.name}' must specify an 'address'.`
|
|
2139
|
-
);
|
|
2140
|
-
}
|
|
2141
|
-
if (typeof resolvedAddress === "object" && !Array.isArray(resolvedAddress)) {
|
|
2142
|
-
const logFactory = buildLogFactory({
|
|
2143
|
-
chainId: network.chainId,
|
|
2144
|
-
...resolvedAddress
|
|
2145
|
-
});
|
|
2146
|
-
return [
|
|
2147
|
-
{
|
|
2148
|
-
type: "account",
|
|
2149
|
-
name: source.name,
|
|
2150
|
-
network,
|
|
2151
|
-
filter: {
|
|
2152
|
-
type: "transaction",
|
|
2153
|
-
chainId: network.chainId,
|
|
2154
|
-
fromAddress: void 0,
|
|
2155
|
-
toAddress: logFactory,
|
|
2156
|
-
includeReverted: false,
|
|
2157
|
-
fromBlock,
|
|
2158
|
-
toBlock,
|
|
2159
|
-
include: defaultTransactionFilterInclude
|
|
2160
|
-
}
|
|
2161
|
-
},
|
|
2162
|
-
{
|
|
2163
|
-
type: "account",
|
|
2164
|
-
name: source.name,
|
|
2165
|
-
network,
|
|
2166
|
-
filter: {
|
|
2167
|
-
type: "transaction",
|
|
2168
|
-
chainId: network.chainId,
|
|
2169
|
-
fromAddress: logFactory,
|
|
2170
|
-
toAddress: void 0,
|
|
2171
|
-
includeReverted: false,
|
|
2172
|
-
fromBlock,
|
|
2173
|
-
toBlock,
|
|
2174
|
-
include: defaultTransactionFilterInclude
|
|
2175
|
-
}
|
|
2176
|
-
},
|
|
2177
|
-
{
|
|
2178
|
-
type: "account",
|
|
2179
|
-
name: source.name,
|
|
2180
|
-
network,
|
|
2181
|
-
filter: {
|
|
2182
|
-
type: "transfer",
|
|
2183
|
-
chainId: network.chainId,
|
|
2184
|
-
fromAddress: void 0,
|
|
2185
|
-
toAddress: logFactory,
|
|
2186
|
-
includeReverted: false,
|
|
2187
|
-
fromBlock,
|
|
2188
|
-
toBlock,
|
|
2189
|
-
include: defaultTransferFilterInclude.concat(
|
|
2190
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2191
|
-
)
|
|
2192
|
-
}
|
|
2193
|
-
},
|
|
2194
|
-
{
|
|
2195
|
-
type: "account",
|
|
2196
|
-
name: source.name,
|
|
2197
|
-
network,
|
|
2198
|
-
filter: {
|
|
2199
|
-
type: "transfer",
|
|
2200
|
-
chainId: network.chainId,
|
|
2201
|
-
fromAddress: logFactory,
|
|
2202
|
-
toAddress: void 0,
|
|
2203
|
-
includeReverted: false,
|
|
2204
|
-
fromBlock,
|
|
2205
|
-
toBlock,
|
|
2206
|
-
include: defaultTransferFilterInclude.concat(
|
|
2207
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2208
|
-
)
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
];
|
|
2212
|
-
}
|
|
2213
|
-
for (const address of Array.isArray(resolvedAddress) ? resolvedAddress : [resolvedAddress]) {
|
|
2214
|
-
if (!address.startsWith("0x"))
|
|
2215
|
-
throw new Error(
|
|
2216
|
-
`Validation failed: Invalid prefix for address '${address}'. Got '${address.slice(
|
|
2217
|
-
0,
|
|
2218
|
-
2
|
|
2219
|
-
)}', expected '0x'.`
|
|
2220
|
-
);
|
|
2221
|
-
if (address.length !== 42)
|
|
2222
|
-
throw new Error(
|
|
2223
|
-
`Validation failed: Invalid length for address '${address}'. Got ${address.length}, expected 42 characters.`
|
|
2224
|
-
);
|
|
2225
|
-
}
|
|
2226
|
-
const validatedAddress = Array.isArray(resolvedAddress) ? dedupe(resolvedAddress).map((r) => toLowerCase(r)) : resolvedAddress !== void 0 ? toLowerCase(resolvedAddress) : void 0;
|
|
2227
|
-
return [
|
|
2228
|
-
{
|
|
2229
|
-
type: "account",
|
|
2230
|
-
name: source.name,
|
|
2231
|
-
network,
|
|
2232
|
-
filter: {
|
|
2233
|
-
type: "transaction",
|
|
2234
|
-
chainId: network.chainId,
|
|
2235
|
-
fromAddress: void 0,
|
|
2236
|
-
toAddress: validatedAddress,
|
|
2237
|
-
includeReverted: false,
|
|
2238
|
-
fromBlock,
|
|
2239
|
-
toBlock,
|
|
2240
|
-
include: defaultTransactionFilterInclude
|
|
2241
|
-
}
|
|
2242
|
-
},
|
|
2243
|
-
{
|
|
2244
|
-
type: "account",
|
|
2245
|
-
name: source.name,
|
|
2246
|
-
network,
|
|
2247
|
-
filter: {
|
|
2248
|
-
type: "transaction",
|
|
2249
|
-
chainId: network.chainId,
|
|
2250
|
-
fromAddress: validatedAddress,
|
|
2251
|
-
toAddress: void 0,
|
|
2252
|
-
includeReverted: false,
|
|
2253
|
-
fromBlock,
|
|
2254
|
-
toBlock,
|
|
2255
|
-
include: defaultTransactionFilterInclude
|
|
2256
|
-
}
|
|
2257
|
-
},
|
|
2258
|
-
{
|
|
2259
|
-
type: "account",
|
|
2260
|
-
name: source.name,
|
|
2261
|
-
network,
|
|
2262
|
-
filter: {
|
|
2263
|
-
type: "transfer",
|
|
2264
|
-
chainId: network.chainId,
|
|
2265
|
-
fromAddress: void 0,
|
|
2266
|
-
toAddress: validatedAddress,
|
|
2267
|
-
includeReverted: false,
|
|
2268
|
-
fromBlock,
|
|
2269
|
-
toBlock,
|
|
2270
|
-
include: defaultTransferFilterInclude.concat(
|
|
2271
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2272
|
-
)
|
|
2273
|
-
}
|
|
2274
|
-
},
|
|
2275
|
-
{
|
|
2276
|
-
type: "account",
|
|
2277
|
-
name: source.name,
|
|
2278
|
-
network,
|
|
2279
|
-
filter: {
|
|
2280
|
-
type: "transfer",
|
|
2281
|
-
chainId: network.chainId,
|
|
2282
|
-
fromAddress: validatedAddress,
|
|
2283
|
-
toAddress: void 0,
|
|
2284
|
-
includeReverted: false,
|
|
2285
|
-
fromBlock,
|
|
2286
|
-
toBlock,
|
|
2287
|
-
include: defaultTransferFilterInclude.concat(
|
|
2288
|
-
source.includeTransactionReceipts ? defaultTransactionReceiptInclude : []
|
|
2289
|
-
)
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2292
|
-
];
|
|
2293
|
-
}).filter((source) => {
|
|
2294
|
-
const eventName = source.filter.type === "transaction" ? source.filter.fromAddress === void 0 ? `${source.name}:transaction:to` : `${source.name}:transaction:from` : source.filter.fromAddress === void 0 ? `${source.name}:transfer:to` : `${source.name}:transfer:from`;
|
|
2295
|
-
const hasRegisteredIndexingFunction = indexingFunctions[eventName] !== void 0;
|
|
2296
|
-
if (!hasRegisteredIndexingFunction) {
|
|
2297
|
-
logs.push({
|
|
2298
|
-
level: "debug",
|
|
2299
|
-
msg: `No indexing functions were registered for '${eventName}'`
|
|
2300
|
-
});
|
|
2301
|
-
}
|
|
2302
|
-
return hasRegisteredIndexingFunction;
|
|
2303
|
-
});
|
|
2304
|
-
const blockSources = flattenSources(config.blocks ?? {}).map((source) => {
|
|
2305
|
-
const network = networks.find((n) => n.name === source.network);
|
|
2306
|
-
const intervalMaybeNan = source.interval ?? 1;
|
|
2307
|
-
const interval = Number.isNaN(intervalMaybeNan) ? 0 : intervalMaybeNan;
|
|
2308
|
-
if (!Number.isInteger(interval) || interval === 0) {
|
|
2309
|
-
throw new Error(
|
|
2310
|
-
`Validation failed: Invalid interval for block source '${source.name}'. Got ${interval}, expected a non-zero integer.`
|
|
2311
|
-
);
|
|
2312
|
-
}
|
|
2313
|
-
const startBlockMaybeNan = source.startBlock;
|
|
2314
|
-
const fromBlock = Number.isNaN(startBlockMaybeNan) ? void 0 : startBlockMaybeNan;
|
|
2315
|
-
const endBlockMaybeNan = source.endBlock;
|
|
2316
|
-
const toBlock = Number.isNaN(endBlockMaybeNan) ? void 0 : endBlockMaybeNan;
|
|
2317
|
-
return {
|
|
2318
|
-
type: "block",
|
|
2319
|
-
name: source.name,
|
|
2320
|
-
network,
|
|
2321
|
-
filter: {
|
|
2322
|
-
type: "block",
|
|
2323
|
-
chainId: network.chainId,
|
|
2324
|
-
interval,
|
|
2325
|
-
offset: (fromBlock ?? 0) % interval,
|
|
2326
|
-
fromBlock,
|
|
2327
|
-
toBlock,
|
|
2328
|
-
include: defaultBlockFilterInclude
|
|
2329
|
-
}
|
|
2330
|
-
};
|
|
2331
|
-
}).filter((blockSource) => {
|
|
2332
|
-
const hasRegisteredIndexingFunction = indexingFunctions[`${blockSource.name}:block`] !== void 0;
|
|
2333
|
-
if (!hasRegisteredIndexingFunction) {
|
|
2334
|
-
logs.push({
|
|
2335
|
-
level: "debug",
|
|
2336
|
-
msg: `No indexing functions were registered for '${blockSource.name}' blocks`
|
|
2337
|
-
});
|
|
2338
|
-
}
|
|
2339
|
-
return hasRegisteredIndexingFunction;
|
|
2293
|
+
return hasRegisteredIndexingFunction;
|
|
2340
2294
|
});
|
|
2341
2295
|
const sources = [...contractSources, ...accountSources, ...blockSources];
|
|
2342
2296
|
const networksWithSources = networks.filter((network) => {
|
|
@@ -2530,617 +2484,22 @@ function safeBuildPre({
|
|
|
2530
2484
|
}
|
|
2531
2485
|
}
|
|
2532
2486
|
|
|
2533
|
-
// src/drizzle/kit/index.ts
|
|
2534
|
-
import { SQL, is } from "drizzle-orm";
|
|
2535
|
-
import { CasingCache, toCamelCase, toSnakeCase } from "drizzle-orm/casing";
|
|
2536
|
-
import {
|
|
2537
|
-
PgDialect,
|
|
2538
|
-
PgEnumColumn,
|
|
2539
|
-
PgMaterializedView,
|
|
2540
|
-
PgSchema,
|
|
2541
|
-
PgTable,
|
|
2542
|
-
PgView,
|
|
2543
|
-
getTableConfig,
|
|
2544
|
-
integer,
|
|
2545
|
-
isPgEnum,
|
|
2546
|
-
isPgSequence,
|
|
2547
|
-
pgTable,
|
|
2548
|
-
serial,
|
|
2549
|
-
varchar
|
|
2550
|
-
} from "drizzle-orm/pg-core";
|
|
2551
|
-
var sqlToReorgTableName = (tableName) => `_reorg__${tableName}`;
|
|
2552
|
-
var getSql = (schema) => {
|
|
2553
|
-
const { tables, enums, schemas } = prepareFromExports(schema);
|
|
2554
|
-
const json = generatePgSnapshot(tables, enums, schemas, "snake_case");
|
|
2555
|
-
const squashed = squashPgScheme(json);
|
|
2556
|
-
const jsonCreateIndexesForCreatedTables = Object.values(
|
|
2557
|
-
squashed.tables
|
|
2558
|
-
).flatMap((it) => {
|
|
2559
|
-
return preparePgCreateIndexesJson(it.name, it.schema, it.indexes);
|
|
2560
|
-
});
|
|
2561
|
-
const jsonCreateEnums = Object.values(squashed.enums).map((it) => {
|
|
2562
|
-
return prepareCreateEnumJson(it.name, it.schema, it.values);
|
|
2563
|
-
}) ?? [];
|
|
2564
|
-
const jsonCreateTables = Object.values(squashed.tables).map((it) => {
|
|
2565
|
-
return preparePgCreateTableJson(it, json);
|
|
2566
|
-
});
|
|
2567
|
-
const fromJson = (statements) => statements.flatMap((statement) => {
|
|
2568
|
-
const filtered = convertors.filter((it) => {
|
|
2569
|
-
return it.can(statement, "postgresql");
|
|
2570
|
-
});
|
|
2571
|
-
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
|
2572
|
-
if (!convertor) {
|
|
2573
|
-
return "";
|
|
2574
|
-
}
|
|
2575
|
-
return convertor.convert(statement);
|
|
2576
|
-
}).filter((it) => it !== "");
|
|
2577
|
-
const combinedTables = jsonCreateTables.flatMap((statement) => [
|
|
2578
|
-
statement,
|
|
2579
|
-
createReorgTableStatement(statement)
|
|
2580
|
-
]);
|
|
2581
|
-
return {
|
|
2582
|
-
tables: {
|
|
2583
|
-
sql: fromJson(combinedTables),
|
|
2584
|
-
json: combinedTables
|
|
2585
|
-
},
|
|
2586
|
-
enums: { sql: fromJson(jsonCreateEnums), json: jsonCreateEnums },
|
|
2587
|
-
indexes: {
|
|
2588
|
-
sql: fromJson(jsonCreateIndexesForCreatedTables),
|
|
2589
|
-
json: jsonCreateIndexesForCreatedTables
|
|
2590
|
-
}
|
|
2591
|
-
};
|
|
2592
|
-
};
|
|
2593
|
-
var createReorgTableStatement = (statement) => {
|
|
2594
|
-
const reorgStatement = structuredClone(statement);
|
|
2595
|
-
reorgStatement.compositePkName = void 0;
|
|
2596
|
-
reorgStatement.compositePKs = [];
|
|
2597
|
-
for (const column of reorgStatement.columns) {
|
|
2598
|
-
column.primaryKey = false;
|
|
2599
|
-
}
|
|
2600
|
-
const reorgColumns = Object.values(
|
|
2601
|
-
squashPgScheme(
|
|
2602
|
-
generatePgSnapshot(
|
|
2603
|
-
[
|
|
2604
|
-
pgTable("", {
|
|
2605
|
-
operation_id: serial().notNull().primaryKey(),
|
|
2606
|
-
operation: integer().notNull(),
|
|
2607
|
-
checkpoint: varchar({
|
|
2608
|
-
length: 75
|
|
2609
|
-
}).notNull()
|
|
2610
|
-
})
|
|
2611
|
-
],
|
|
2612
|
-
[],
|
|
2613
|
-
[],
|
|
2614
|
-
"snake_case"
|
|
2615
|
-
)
|
|
2616
|
-
).tables
|
|
2617
|
-
//@ts-ignore
|
|
2618
|
-
)[0].columns;
|
|
2619
|
-
reorgStatement.columns.push(...Object.values(reorgColumns));
|
|
2620
|
-
reorgStatement.tableName = sqlToReorgTableName(reorgStatement.tableName);
|
|
2621
|
-
return reorgStatement;
|
|
2622
|
-
};
|
|
2623
|
-
var PgSquasher = {
|
|
2624
|
-
squashIdx: (idx) => {
|
|
2625
|
-
return `${idx.name};${idx.columns.map(
|
|
2626
|
-
(c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass && ""}`
|
|
2627
|
-
).join(
|
|
2628
|
-
",,"
|
|
2629
|
-
)};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
|
|
2630
|
-
},
|
|
2631
|
-
unsquashIdx: (input) => {
|
|
2632
|
-
const [
|
|
2633
|
-
name,
|
|
2634
|
-
columnsString,
|
|
2635
|
-
isUnique,
|
|
2636
|
-
concurrently,
|
|
2637
|
-
method,
|
|
2638
|
-
where,
|
|
2639
|
-
idxWith
|
|
2640
|
-
] = input.split(";");
|
|
2641
|
-
const columnString = columnsString.split(",,");
|
|
2642
|
-
const columns = [];
|
|
2643
|
-
for (const column of columnString) {
|
|
2644
|
-
const [expression, isExpression, asc, nulls, opclass] = column.split("--");
|
|
2645
|
-
columns.push({
|
|
2646
|
-
nulls,
|
|
2647
|
-
isExpression: isExpression === "true",
|
|
2648
|
-
asc: asc === "true",
|
|
2649
|
-
expression,
|
|
2650
|
-
opclass: opclass === "undefined" ? void 0 : opclass
|
|
2651
|
-
});
|
|
2652
|
-
}
|
|
2653
|
-
return {
|
|
2654
|
-
name,
|
|
2655
|
-
columns,
|
|
2656
|
-
isUnique: isUnique === "true",
|
|
2657
|
-
concurrently: concurrently === "true",
|
|
2658
|
-
method,
|
|
2659
|
-
where: where === "undefined" ? void 0 : where,
|
|
2660
|
-
with: !idxWith || idxWith === "undefined" ? void 0 : JSON.parse(idxWith)
|
|
2661
|
-
};
|
|
2662
|
-
},
|
|
2663
|
-
squashPK: (pk) => {
|
|
2664
|
-
return `${pk.columns.join(",")};${pk.name}`;
|
|
2665
|
-
},
|
|
2666
|
-
unsquashPK: (pk) => {
|
|
2667
|
-
const splitted = pk.split(";");
|
|
2668
|
-
return { name: splitted[1], columns: splitted[0].split(",") };
|
|
2669
|
-
}
|
|
2670
|
-
};
|
|
2671
|
-
var parseType = (schemaPrefix, type) => {
|
|
2672
|
-
const pgNativeTypes = [
|
|
2673
|
-
"uuid",
|
|
2674
|
-
"smallint",
|
|
2675
|
-
"integer",
|
|
2676
|
-
"bigint",
|
|
2677
|
-
"boolean",
|
|
2678
|
-
"text",
|
|
2679
|
-
"varchar",
|
|
2680
|
-
"serial",
|
|
2681
|
-
"bigserial",
|
|
2682
|
-
"decimal",
|
|
2683
|
-
"numeric",
|
|
2684
|
-
"real",
|
|
2685
|
-
"json",
|
|
2686
|
-
"jsonb",
|
|
2687
|
-
"time",
|
|
2688
|
-
"time with time zone",
|
|
2689
|
-
"time without time zone",
|
|
2690
|
-
"time",
|
|
2691
|
-
"timestamp",
|
|
2692
|
-
"timestamp with time zone",
|
|
2693
|
-
"timestamp without time zone",
|
|
2694
|
-
"date",
|
|
2695
|
-
"interval",
|
|
2696
|
-
"bigint",
|
|
2697
|
-
"bigserial",
|
|
2698
|
-
"double precision",
|
|
2699
|
-
"interval year",
|
|
2700
|
-
"interval month",
|
|
2701
|
-
"interval day",
|
|
2702
|
-
"interval hour",
|
|
2703
|
-
"interval minute",
|
|
2704
|
-
"interval second",
|
|
2705
|
-
"interval year to month",
|
|
2706
|
-
"interval day to hour",
|
|
2707
|
-
"interval day to minute",
|
|
2708
|
-
"interval day to second",
|
|
2709
|
-
"interval hour to minute",
|
|
2710
|
-
"interval hour to second",
|
|
2711
|
-
"interval minute to second"
|
|
2712
|
-
];
|
|
2713
|
-
const arrayDefinitionRegex = /\[\d*(?:\[\d*\])*\]/g;
|
|
2714
|
-
const arrayDefinition = (type.match(arrayDefinitionRegex) ?? []).join("");
|
|
2715
|
-
const withoutArrayDefinition = type.replace(arrayDefinitionRegex, "");
|
|
2716
|
-
return pgNativeTypes.some((it) => type.startsWith(it)) ? `${withoutArrayDefinition}${arrayDefinition}` : `${schemaPrefix}"${withoutArrayDefinition}"${arrayDefinition}`;
|
|
2717
|
-
};
|
|
2718
|
-
var Convertor = class {
|
|
2719
|
-
};
|
|
2720
|
-
var PgCreateTableConvertor = class extends Convertor {
|
|
2721
|
-
can(statement, dialect) {
|
|
2722
|
-
return statement.type === "create_table" && dialect === "postgresql";
|
|
2723
|
-
}
|
|
2724
|
-
convert(st) {
|
|
2725
|
-
const { tableName, schema, columns, compositePKs } = st;
|
|
2726
|
-
let statement = "";
|
|
2727
|
-
const name = schema ? `"${schema}"."${tableName}"` : `"${tableName}"`;
|
|
2728
|
-
statement += `CREATE TABLE ${name} (
|
|
2729
|
-
`;
|
|
2730
|
-
for (let i = 0; i < columns.length; i++) {
|
|
2731
|
-
const column = columns[i];
|
|
2732
|
-
const primaryKeyStatement = column.primaryKey ? " PRIMARY KEY" : "";
|
|
2733
|
-
const notNullStatement = column.notNull && !column.identity ? " NOT NULL" : "";
|
|
2734
|
-
const defaultStatement = column.default !== void 0 ? ` DEFAULT ${column.default}` : "";
|
|
2735
|
-
const schemaPrefix = column.typeSchema && column.typeSchema !== "public" ? `"${column.typeSchema}".` : "";
|
|
2736
|
-
const type = parseType(schemaPrefix, column.type);
|
|
2737
|
-
statement += ` "${column.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}`;
|
|
2738
|
-
statement += i === columns.length - 1 ? "" : ",\n";
|
|
2739
|
-
}
|
|
2740
|
-
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
2741
|
-
statement += ",\n";
|
|
2742
|
-
const compositePK = PgSquasher.unsquashPK(compositePKs[0]);
|
|
2743
|
-
statement += ` CONSTRAINT "${st.compositePkName}" PRIMARY KEY("${compositePK.columns.join(`","`)}")`;
|
|
2744
|
-
}
|
|
2745
|
-
statement += "\n);";
|
|
2746
|
-
statement += "\n";
|
|
2747
|
-
return statement;
|
|
2748
|
-
}
|
|
2749
|
-
};
|
|
2750
|
-
var CreateTypeEnumConvertor = class extends Convertor {
|
|
2751
|
-
can(statement) {
|
|
2752
|
-
return statement.type === "create_type_enum";
|
|
2753
|
-
}
|
|
2754
|
-
convert(st) {
|
|
2755
|
-
const { name, values, schema } = st;
|
|
2756
|
-
const enumNameWithSchema = schema ? `"${schema}"."${name}"` : `"${name}"`;
|
|
2757
|
-
let valuesStatement = "(";
|
|
2758
|
-
valuesStatement += values.map((it) => `'${it}'`).join(", ");
|
|
2759
|
-
valuesStatement += ")";
|
|
2760
|
-
const statement = `CREATE TYPE ${enumNameWithSchema} AS ENUM${valuesStatement};`;
|
|
2761
|
-
return statement;
|
|
2762
|
-
}
|
|
2763
|
-
};
|
|
2764
|
-
var CreatePgIndexConvertor = class extends Convertor {
|
|
2765
|
-
can(statement, dialect) {
|
|
2766
|
-
return statement.type === "create_index_pg" && dialect === "postgresql";
|
|
2767
|
-
}
|
|
2768
|
-
convert(statement) {
|
|
2769
|
-
const {
|
|
2770
|
-
name,
|
|
2771
|
-
columns,
|
|
2772
|
-
isUnique,
|
|
2773
|
-
concurrently,
|
|
2774
|
-
with: withMap,
|
|
2775
|
-
method,
|
|
2776
|
-
where
|
|
2777
|
-
} = statement.data;
|
|
2778
|
-
const indexPart = isUnique ? "UNIQUE INDEX" : "INDEX";
|
|
2779
|
-
const value = columns.map(
|
|
2780
|
-
(it) => `${it.isExpression ? it.expression : `"${it.expression}"`}${it.opclass ? ` ${it.opclass}` : it.asc ? "" : " DESC"}${it.asc && it.nulls && it.nulls === "last" || it.opclass ? "" : ` NULLS ${it.nulls.toUpperCase()}`}`
|
|
2781
|
-
).join(",");
|
|
2782
|
-
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
2783
|
-
function reverseLogic(mappedWith) {
|
|
2784
|
-
let reversedString = "";
|
|
2785
|
-
for (const key in mappedWith) {
|
|
2786
|
-
if (mappedWith.hasOwnProperty(key)) {
|
|
2787
|
-
reversedString += `${key}=${mappedWith[key]},`;
|
|
2788
|
-
}
|
|
2789
|
-
}
|
|
2790
|
-
reversedString = reversedString.slice(0, -1);
|
|
2791
|
-
return reversedString;
|
|
2792
|
-
}
|
|
2793
|
-
return `CREATE ${indexPart}${concurrently ? " CONCURRENTLY" : ""} IF NOT EXISTS "${name}" ON ${tableNameWithSchema} USING ${method} (${value})${Object.keys(withMap).length !== 0 ? ` WITH (${reverseLogic(withMap)})` : ""}${where ? ` WHERE ${where}` : ""};`;
|
|
2794
|
-
}
|
|
2795
|
-
};
|
|
2796
|
-
var PgCreateSchemaConvertor = class extends Convertor {
|
|
2797
|
-
can(statement, dialect) {
|
|
2798
|
-
return statement.type === "create_schema" && dialect === "postgresql";
|
|
2799
|
-
}
|
|
2800
|
-
convert(statement) {
|
|
2801
|
-
const { name } = statement;
|
|
2802
|
-
return `CREATE SCHEMA IF NOT EXISTS"${name}";
|
|
2803
|
-
`;
|
|
2804
|
-
}
|
|
2805
|
-
};
|
|
2806
|
-
var convertors = [];
|
|
2807
|
-
convertors.push(new PgCreateTableConvertor());
|
|
2808
|
-
convertors.push(new CreateTypeEnumConvertor());
|
|
2809
|
-
convertors.push(new CreatePgIndexConvertor());
|
|
2810
|
-
convertors.push(new PgCreateSchemaConvertor());
|
|
2811
|
-
var preparePgCreateTableJson = (table, json) => {
|
|
2812
|
-
const { name, schema, columns, compositePrimaryKeys } = table;
|
|
2813
|
-
const tableKey = `${schema || "public"}.${name}`;
|
|
2814
|
-
const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json.tables[tableKey].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
|
|
2815
|
-
return {
|
|
2816
|
-
type: "create_table",
|
|
2817
|
-
tableName: name,
|
|
2818
|
-
schema,
|
|
2819
|
-
columns: Object.values(columns),
|
|
2820
|
-
compositePKs: Object.values(compositePrimaryKeys),
|
|
2821
|
-
compositePkName
|
|
2822
|
-
};
|
|
2823
|
-
};
|
|
2824
|
-
var preparePgCreateIndexesJson = (tableName, schema, indexes) => {
|
|
2825
|
-
return Object.values(indexes).map((indexData) => {
|
|
2826
|
-
return {
|
|
2827
|
-
type: "create_index_pg",
|
|
2828
|
-
tableName,
|
|
2829
|
-
data: PgSquasher.unsquashIdx(indexData),
|
|
2830
|
-
schema
|
|
2831
|
-
};
|
|
2832
|
-
});
|
|
2833
|
-
};
|
|
2834
|
-
var prepareCreateEnumJson = (name, schema, values) => {
|
|
2835
|
-
return {
|
|
2836
|
-
type: "create_type_enum",
|
|
2837
|
-
name,
|
|
2838
|
-
schema,
|
|
2839
|
-
values
|
|
2840
|
-
};
|
|
2841
|
-
};
|
|
2842
|
-
var prepareFromExports = (exports) => {
|
|
2843
|
-
const tables = [];
|
|
2844
|
-
const enums = [];
|
|
2845
|
-
const schemas = [];
|
|
2846
|
-
const sequences = [];
|
|
2847
|
-
const views = [];
|
|
2848
|
-
const matViews = [];
|
|
2849
|
-
const i0values = Object.values(exports);
|
|
2850
|
-
i0values.forEach((t) => {
|
|
2851
|
-
if (isPgEnum(t)) {
|
|
2852
|
-
enums.push(t);
|
|
2853
|
-
return;
|
|
2854
|
-
}
|
|
2855
|
-
if (is(t, PgTable)) {
|
|
2856
|
-
tables.push(t);
|
|
2857
|
-
}
|
|
2858
|
-
if (is(t, PgSchema)) {
|
|
2859
|
-
schemas.push(t);
|
|
2860
|
-
}
|
|
2861
|
-
if (is(t, PgView)) {
|
|
2862
|
-
views.push(t);
|
|
2863
|
-
}
|
|
2864
|
-
if (is(t, PgMaterializedView)) {
|
|
2865
|
-
matViews.push(t);
|
|
2866
|
-
}
|
|
2867
|
-
if (isPgSequence(t)) {
|
|
2868
|
-
sequences.push(t);
|
|
2869
|
-
}
|
|
2870
|
-
});
|
|
2871
|
-
return { tables, enums, schemas, sequences, views, matViews };
|
|
2872
|
-
};
|
|
2873
|
-
function getColumnCasing(column, casing) {
|
|
2874
|
-
if (!column.name)
|
|
2875
|
-
return "";
|
|
2876
|
-
return !column.keyAsName || casing === void 0 ? column.name : casing === "camelCase" ? toCamelCase(column.name) : toSnakeCase(column.name);
|
|
2877
|
-
}
|
|
2878
|
-
var sqlToStr = (sql5, casing) => {
|
|
2879
|
-
return sql5.toQuery({
|
|
2880
|
-
escapeName: () => {
|
|
2881
|
-
throw new Error("we don't support params for `sql` default values");
|
|
2882
|
-
},
|
|
2883
|
-
escapeParam: () => {
|
|
2884
|
-
throw new Error("we don't support params for `sql` default values");
|
|
2885
|
-
},
|
|
2886
|
-
escapeString: () => {
|
|
2887
|
-
throw new Error("we don't support params for `sql` default values");
|
|
2888
|
-
},
|
|
2889
|
-
casing: new CasingCache(casing)
|
|
2890
|
-
}).sql;
|
|
2891
|
-
};
|
|
2892
|
-
function isPgArrayType(sqlType) {
|
|
2893
|
-
return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
|
|
2894
|
-
}
|
|
2895
|
-
function buildArrayString(array, sqlType) {
|
|
2896
|
-
sqlType = sqlType.split("[")[0];
|
|
2897
|
-
const values = array.map((value) => {
|
|
2898
|
-
if (typeof value === "number" || typeof value === "bigint") {
|
|
2899
|
-
return value.toString();
|
|
2900
|
-
} else if (typeof value === "boolean") {
|
|
2901
|
-
return value ? "true" : "false";
|
|
2902
|
-
} else if (Array.isArray(value)) {
|
|
2903
|
-
return buildArrayString(value, sqlType);
|
|
2904
|
-
} else if (value instanceof Date) {
|
|
2905
|
-
if (sqlType === "date") {
|
|
2906
|
-
return `"${value.toISOString().split("T")[0]}"`;
|
|
2907
|
-
} else if (sqlType === "timestamp") {
|
|
2908
|
-
return `"${value.toISOString().replace("T", " ").slice(0, 23)}"`;
|
|
2909
|
-
} else {
|
|
2910
|
-
return `"${value.toISOString()}"`;
|
|
2911
|
-
}
|
|
2912
|
-
} else if (typeof value === "object") {
|
|
2913
|
-
return `"${JSON.stringify(value).replaceAll('"', '\\"')}"`;
|
|
2914
|
-
}
|
|
2915
|
-
return `"${value}"`;
|
|
2916
|
-
}).join(",");
|
|
2917
|
-
return `{${values}}`;
|
|
2918
|
-
}
|
|
2919
|
-
var indexName = (tableName, columns) => {
|
|
2920
|
-
return `${tableName}_${columns.join("_")}_index`;
|
|
2921
|
-
};
|
|
2922
|
-
var generatePgSnapshot = (tables, enums, schemas, casing) => {
|
|
2923
|
-
const dialect = new PgDialect({ casing });
|
|
2924
|
-
const result = {};
|
|
2925
|
-
const indexesInSchema = {};
|
|
2926
|
-
for (const table of tables) {
|
|
2927
|
-
const {
|
|
2928
|
-
name: tableName,
|
|
2929
|
-
columns,
|
|
2930
|
-
indexes,
|
|
2931
|
-
schema,
|
|
2932
|
-
primaryKeys
|
|
2933
|
-
} = getTableConfig(table);
|
|
2934
|
-
const columnsObject = {};
|
|
2935
|
-
const indexesObject = {};
|
|
2936
|
-
const primaryKeysObject = {};
|
|
2937
|
-
columns.forEach((column) => {
|
|
2938
|
-
const name = getColumnCasing(column, casing);
|
|
2939
|
-
const notNull = column.notNull;
|
|
2940
|
-
const primaryKey = column.primary;
|
|
2941
|
-
const sqlTypeLowered = column.getSQLType().toLowerCase();
|
|
2942
|
-
const typeSchema = is(column, PgEnumColumn) ? column.enum.schema || "public" : void 0;
|
|
2943
|
-
const columnToSet = {
|
|
2944
|
-
name,
|
|
2945
|
-
type: column.getSQLType(),
|
|
2946
|
-
typeSchema,
|
|
2947
|
-
primaryKey,
|
|
2948
|
-
notNull
|
|
2949
|
-
};
|
|
2950
|
-
if (column.default !== void 0) {
|
|
2951
|
-
if (is(column.default, SQL)) {
|
|
2952
|
-
columnToSet.default = sqlToStr(column.default, casing);
|
|
2953
|
-
} else {
|
|
2954
|
-
if (typeof column.default === "string") {
|
|
2955
|
-
columnToSet.default = `'${column.default}'`;
|
|
2956
|
-
} else {
|
|
2957
|
-
if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
|
|
2958
|
-
columnToSet.default = `'${JSON.stringify(column.default)}'::${sqlTypeLowered}`;
|
|
2959
|
-
} else if (column.default instanceof Date) {
|
|
2960
|
-
if (sqlTypeLowered === "date") {
|
|
2961
|
-
columnToSet.default = `'${column.default.toISOString().split("T")[0]}'`;
|
|
2962
|
-
} else if (sqlTypeLowered === "timestamp") {
|
|
2963
|
-
columnToSet.default = `'${column.default.toISOString().replace("T", " ").slice(0, 23)}'`;
|
|
2964
|
-
} else {
|
|
2965
|
-
columnToSet.default = `'${column.default.toISOString()}'`;
|
|
2966
|
-
}
|
|
2967
|
-
} else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column.default)) {
|
|
2968
|
-
columnToSet.default = `'${buildArrayString(column.default, sqlTypeLowered)}'`;
|
|
2969
|
-
} else {
|
|
2970
|
-
columnToSet.default = column.default;
|
|
2971
|
-
}
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
2974
|
-
}
|
|
2975
|
-
columnsObject[name] = columnToSet;
|
|
2976
|
-
});
|
|
2977
|
-
primaryKeys.map((pk) => {
|
|
2978
|
-
const originalColumnNames = pk.columns.map((c) => c.name);
|
|
2979
|
-
const columnNames = pk.columns.map((c) => getColumnCasing(c, casing));
|
|
2980
|
-
let name = pk.getName();
|
|
2981
|
-
if (casing !== void 0) {
|
|
2982
|
-
for (let i = 0; i < originalColumnNames.length; i++) {
|
|
2983
|
-
name = name.replace(originalColumnNames[i], columnNames[i]);
|
|
2984
|
-
}
|
|
2985
|
-
}
|
|
2986
|
-
primaryKeysObject[name] = {
|
|
2987
|
-
name,
|
|
2988
|
-
columns: columnNames
|
|
2989
|
-
};
|
|
2990
|
-
});
|
|
2991
|
-
indexes.forEach((value) => {
|
|
2992
|
-
const columns2 = value.config.columns;
|
|
2993
|
-
const indexColumnNames = [];
|
|
2994
|
-
columns2.forEach((it) => {
|
|
2995
|
-
const name2 = getColumnCasing(it, casing);
|
|
2996
|
-
indexColumnNames.push(name2);
|
|
2997
|
-
});
|
|
2998
|
-
const name = value.config.name ? value.config.name : indexName(tableName, indexColumnNames);
|
|
2999
|
-
const indexColumns = columns2.map(
|
|
3000
|
-
(it) => {
|
|
3001
|
-
if (is(it, SQL)) {
|
|
3002
|
-
return {
|
|
3003
|
-
expression: dialect.sqlToQuery(it, "indexes").sql,
|
|
3004
|
-
asc: true,
|
|
3005
|
-
isExpression: true,
|
|
3006
|
-
nulls: "last"
|
|
3007
|
-
};
|
|
3008
|
-
} else {
|
|
3009
|
-
it = it;
|
|
3010
|
-
return {
|
|
3011
|
-
expression: getColumnCasing(it, casing),
|
|
3012
|
-
isExpression: false,
|
|
3013
|
-
// @ts-ignore
|
|
3014
|
-
asc: it.indexConfig?.order === "asc",
|
|
3015
|
-
// @ts-ignore
|
|
3016
|
-
nulls: it.indexConfig?.nulls ? (
|
|
3017
|
-
// @ts-ignore
|
|
3018
|
-
it.indexConfig?.nulls
|
|
3019
|
-
) : (
|
|
3020
|
-
// @ts-ignore
|
|
3021
|
-
it.indexConfig?.order === "desc" ? "first" : "last"
|
|
3022
|
-
),
|
|
3023
|
-
// @ts-ignore
|
|
3024
|
-
opclass: it.indexConfig?.opClass
|
|
3025
|
-
};
|
|
3026
|
-
}
|
|
3027
|
-
}
|
|
3028
|
-
);
|
|
3029
|
-
if (typeof indexesInSchema[schema ?? "public"] !== "undefined") {
|
|
3030
|
-
indexesInSchema[schema ?? "public"].push(name);
|
|
3031
|
-
} else {
|
|
3032
|
-
indexesInSchema[schema ?? "public"] = [name];
|
|
3033
|
-
}
|
|
3034
|
-
indexesObject[name] = {
|
|
3035
|
-
name,
|
|
3036
|
-
columns: indexColumns,
|
|
3037
|
-
isUnique: value.config.unique ?? false,
|
|
3038
|
-
where: value.config.where ? dialect.sqlToQuery(value.config.where).sql : void 0,
|
|
3039
|
-
concurrently: value.config.concurrently ?? false,
|
|
3040
|
-
method: value.config.method ?? "btree",
|
|
3041
|
-
with: value.config.with ?? {}
|
|
3042
|
-
};
|
|
3043
|
-
});
|
|
3044
|
-
const tableKey = `${schema ?? "public"}.${tableName}`;
|
|
3045
|
-
result[tableKey] = {
|
|
3046
|
-
name: tableName,
|
|
3047
|
-
schema: schema ?? "",
|
|
3048
|
-
columns: columnsObject,
|
|
3049
|
-
indexes: indexesObject,
|
|
3050
|
-
compositePrimaryKeys: primaryKeysObject
|
|
3051
|
-
};
|
|
3052
|
-
}
|
|
3053
|
-
const enumsToReturn = enums.reduce((map, obj) => {
|
|
3054
|
-
const enumSchema = obj.schema || "public";
|
|
3055
|
-
const key = `${enumSchema}.${obj.enumName}`;
|
|
3056
|
-
map[key] = {
|
|
3057
|
-
name: obj.enumName,
|
|
3058
|
-
schema: enumSchema,
|
|
3059
|
-
values: obj.enumValues
|
|
3060
|
-
};
|
|
3061
|
-
return map;
|
|
3062
|
-
}, {});
|
|
3063
|
-
const schemasObject = Object.fromEntries(
|
|
3064
|
-
schemas.filter((it) => {
|
|
3065
|
-
return it.schemaName !== "public";
|
|
3066
|
-
}).map((it) => [it.schemaName, it.schemaName])
|
|
3067
|
-
);
|
|
3068
|
-
return {
|
|
3069
|
-
version: "7",
|
|
3070
|
-
dialect: "postgresql",
|
|
3071
|
-
tables: result,
|
|
3072
|
-
enums: enumsToReturn,
|
|
3073
|
-
schemas: schemasObject
|
|
3074
|
-
};
|
|
3075
|
-
};
|
|
3076
|
-
var mapValues = (obj, map) => {
|
|
3077
|
-
const result = Object.keys(obj).reduce(
|
|
3078
|
-
(result2, key) => {
|
|
3079
|
-
result2[key] = map(obj[key]);
|
|
3080
|
-
return result2;
|
|
3081
|
-
},
|
|
3082
|
-
{}
|
|
3083
|
-
);
|
|
3084
|
-
return result;
|
|
3085
|
-
};
|
|
3086
|
-
var squashPgScheme = (json) => {
|
|
3087
|
-
const mappedTables = Object.fromEntries(
|
|
3088
|
-
Object.entries(json.tables).map((it) => {
|
|
3089
|
-
const squashedIndexes = mapValues(it[1].indexes, (index) => {
|
|
3090
|
-
return PgSquasher.squashIdx(index);
|
|
3091
|
-
});
|
|
3092
|
-
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
|
3093
|
-
return PgSquasher.squashPK(pk);
|
|
3094
|
-
});
|
|
3095
|
-
const mappedColumns = Object.fromEntries(
|
|
3096
|
-
Object.entries(it[1].columns).map((it2) => {
|
|
3097
|
-
return [
|
|
3098
|
-
it2[0],
|
|
3099
|
-
{
|
|
3100
|
-
...it2[1],
|
|
3101
|
-
identity: void 0
|
|
3102
|
-
}
|
|
3103
|
-
];
|
|
3104
|
-
})
|
|
3105
|
-
);
|
|
3106
|
-
return [
|
|
3107
|
-
it[0],
|
|
3108
|
-
{
|
|
3109
|
-
name: it[1].name,
|
|
3110
|
-
schema: it[1].schema,
|
|
3111
|
-
columns: mappedColumns,
|
|
3112
|
-
indexes: squashedIndexes,
|
|
3113
|
-
compositePrimaryKeys: squashedPKs
|
|
3114
|
-
}
|
|
3115
|
-
];
|
|
3116
|
-
})
|
|
3117
|
-
);
|
|
3118
|
-
return {
|
|
3119
|
-
version: "7",
|
|
3120
|
-
dialect: json.dialect,
|
|
3121
|
-
tables: mappedTables,
|
|
3122
|
-
enums: json.enums,
|
|
3123
|
-
schemas: json.schemas,
|
|
3124
|
-
views: json.views
|
|
3125
|
-
};
|
|
3126
|
-
};
|
|
3127
|
-
|
|
3128
2487
|
// src/build/schema.ts
|
|
3129
|
-
import { SQL
|
|
2488
|
+
import { SQL, getTableColumns, is } from "drizzle-orm";
|
|
3130
2489
|
import {
|
|
3131
2490
|
PgBigSerial53,
|
|
3132
2491
|
PgBigSerial64,
|
|
3133
2492
|
PgSequence,
|
|
3134
2493
|
PgSerial,
|
|
3135
2494
|
PgSmallSerial,
|
|
3136
|
-
PgTable
|
|
3137
|
-
PgView
|
|
3138
|
-
getTableConfig
|
|
2495
|
+
PgTable,
|
|
2496
|
+
PgView,
|
|
2497
|
+
getTableConfig
|
|
3139
2498
|
} from "drizzle-orm/pg-core";
|
|
3140
2499
|
var buildSchema = ({ schema }) => {
|
|
3141
2500
|
const statements = getSql(schema);
|
|
3142
2501
|
for (const [name, s] of Object.entries(schema)) {
|
|
3143
|
-
if (
|
|
2502
|
+
if (is(s, PgTable)) {
|
|
3144
2503
|
let hasPrimaryKey = false;
|
|
3145
2504
|
for (const [columnName, column] of Object.entries(getTableColumns(s))) {
|
|
3146
2505
|
if (column.primary) {
|
|
@@ -3173,60 +2532,60 @@ var buildSchema = ({ schema }) => {
|
|
|
3173
2532
|
);
|
|
3174
2533
|
}
|
|
3175
2534
|
if (column.hasDefault) {
|
|
3176
|
-
if (column.default && column.default instanceof
|
|
2535
|
+
if (column.default && column.default instanceof SQL) {
|
|
3177
2536
|
throw new Error(
|
|
3178
2537
|
`Schema validation failed: '${name}.${columnName}' is a default column and default columns with raw sql are unsupported.`
|
|
3179
2538
|
);
|
|
3180
2539
|
}
|
|
3181
|
-
if (column.defaultFn && column.defaultFn() instanceof
|
|
2540
|
+
if (column.defaultFn && column.defaultFn() instanceof SQL) {
|
|
3182
2541
|
throw new Error(
|
|
3183
2542
|
`Schema validation failed: '${name}.${columnName}' is a default column and default columns with raw sql are unsupported.`
|
|
3184
2543
|
);
|
|
3185
2544
|
}
|
|
3186
|
-
if (column.onUpdateFn && column.onUpdateFn() instanceof
|
|
2545
|
+
if (column.onUpdateFn && column.onUpdateFn() instanceof SQL) {
|
|
3187
2546
|
throw new Error(
|
|
3188
2547
|
`Schema validation failed: '${name}.${columnName}' is a default column and default columns with raw sql are unsupported.`
|
|
3189
2548
|
);
|
|
3190
2549
|
}
|
|
3191
2550
|
}
|
|
3192
2551
|
}
|
|
3193
|
-
if (
|
|
2552
|
+
if (getTableConfig(s).primaryKeys.length > 1) {
|
|
3194
2553
|
throw new Error(
|
|
3195
2554
|
`Schema validation failed: '${name}' has multiple primary keys.`
|
|
3196
2555
|
);
|
|
3197
2556
|
}
|
|
3198
|
-
if (
|
|
2557
|
+
if (getTableConfig(s).primaryKeys.length === 1 && hasPrimaryKey) {
|
|
3199
2558
|
throw new Error(
|
|
3200
2559
|
`Schema validation failed: '${name}' has multiple primary keys.`
|
|
3201
2560
|
);
|
|
3202
2561
|
}
|
|
3203
|
-
if (
|
|
2562
|
+
if (getTableConfig(s).primaryKeys.length === 0 && hasPrimaryKey === false) {
|
|
3204
2563
|
throw new Error(
|
|
3205
2564
|
`Schema validation failed: '${name}' has no primary key. Declare one with ".primaryKey()".`
|
|
3206
2565
|
);
|
|
3207
2566
|
}
|
|
3208
|
-
if (
|
|
2567
|
+
if (getTableConfig(s).foreignKeys.length > 0) {
|
|
3209
2568
|
throw new Error(
|
|
3210
2569
|
`Schema validation failed: '${name}' has a foreign key constraint and foreign key constraints are unsupported.`
|
|
3211
2570
|
);
|
|
3212
2571
|
}
|
|
3213
|
-
if (
|
|
2572
|
+
if (getTableConfig(s).checks.length > 0) {
|
|
3214
2573
|
throw new Error(
|
|
3215
2574
|
`Schema validation failed: '${name}' has a check constraint and check constraints are unsupported.`
|
|
3216
2575
|
);
|
|
3217
2576
|
}
|
|
3218
|
-
if (
|
|
2577
|
+
if (getTableConfig(s).uniqueConstraints.length > 0) {
|
|
3219
2578
|
throw new Error(
|
|
3220
2579
|
`Schema validation failed: '${name}' has a unique constraint and unique constraints are unsupported.`
|
|
3221
2580
|
);
|
|
3222
2581
|
}
|
|
3223
2582
|
}
|
|
3224
|
-
if (
|
|
2583
|
+
if (is(s, PgSequence)) {
|
|
3225
2584
|
throw new Error(
|
|
3226
2585
|
`Schema validation failed: '${name}' is a sequence and sequences are unsupported.`
|
|
3227
2586
|
);
|
|
3228
2587
|
}
|
|
3229
|
-
if (
|
|
2588
|
+
if (is(s, PgView)) {
|
|
3230
2589
|
throw new Error(
|
|
3231
2590
|
`Schema validation failed: '${name}' is a view and views are unsupported.`
|
|
3232
2591
|
);
|
|
@@ -3495,6 +2854,7 @@ var createBuild = async ({
|
|
|
3495
2854
|
async executeApi({ indexingBuild, database }) {
|
|
3496
2855
|
globalThis.PONDER_INDEXING_BUILD = indexingBuild;
|
|
3497
2856
|
globalThis.PONDER_DATABASE = database;
|
|
2857
|
+
globalThis.COMMON = common;
|
|
3498
2858
|
if (!fs.existsSync(common.options.apiFile)) {
|
|
3499
2859
|
const error = new BuildError(
|
|
3500
2860
|
`API function file not found. Create a file at ${common.options.apiFile}. Read more: https://ponder-docs-git-v09-ponder-sh.vercel.app/docs/query/api-functions`
|
|
@@ -3737,49 +3097,6 @@ var createBuild = async ({
|
|
|
3737
3097
|
// src/database/index.ts
|
|
3738
3098
|
import { randomUUID } from "node:crypto";
|
|
3739
3099
|
|
|
3740
|
-
// src/drizzle/index.ts
|
|
3741
|
-
import { getTableColumns as getTableColumns2, getTableName, is as is3 } from "drizzle-orm";
|
|
3742
|
-
import { PgTable as PgTable3, getTableConfig as getTableConfig3 } from "drizzle-orm/pg-core";
|
|
3743
|
-
var getTableNames = (schema) => {
|
|
3744
|
-
const tableNames = Object.entries(schema).filter(([, table]) => is3(table, PgTable3)).map(([js, table]) => {
|
|
3745
|
-
const sql5 = getTableName(table);
|
|
3746
|
-
return {
|
|
3747
|
-
sql: sql5,
|
|
3748
|
-
reorg: sqlToReorgTableName(sql5),
|
|
3749
|
-
trigger: sqlToReorgTableName(sql5),
|
|
3750
|
-
triggerFn: `operation_reorg__${sql5}()`,
|
|
3751
|
-
js
|
|
3752
|
-
};
|
|
3753
|
-
});
|
|
3754
|
-
return tableNames;
|
|
3755
|
-
};
|
|
3756
|
-
var getPrimaryKeyColumns = (table) => {
|
|
3757
|
-
const primaryKeys = getTableConfig3(table).primaryKeys;
|
|
3758
|
-
const findJsName = (column) => {
|
|
3759
|
-
const name = column.name;
|
|
3760
|
-
for (const [js, column2] of Object.entries(getTableColumns2(table))) {
|
|
3761
|
-
if (column2.name === name)
|
|
3762
|
-
return js;
|
|
3763
|
-
}
|
|
3764
|
-
throw "unreachable";
|
|
3765
|
-
};
|
|
3766
|
-
if (primaryKeys.length > 0) {
|
|
3767
|
-
return primaryKeys[0].columns.map((column) => ({
|
|
3768
|
-
sql: getColumnCasing(column, "snake_case"),
|
|
3769
|
-
js: findJsName(column)
|
|
3770
|
-
}));
|
|
3771
|
-
}
|
|
3772
|
-
const pkColumn = Object.values(getTableColumns2(table)).find(
|
|
3773
|
-
(c) => c.primary
|
|
3774
|
-
);
|
|
3775
|
-
return [
|
|
3776
|
-
{
|
|
3777
|
-
sql: getColumnCasing(pkColumn, "snake_case"),
|
|
3778
|
-
js: findJsName(pkColumn)
|
|
3779
|
-
}
|
|
3780
|
-
];
|
|
3781
|
-
};
|
|
3782
|
-
|
|
3783
3100
|
// src/sync-store/migrations.ts
|
|
3784
3101
|
import { sql } from "kysely";
|
|
3785
3102
|
var migrations = {
|
|
@@ -4490,27 +3807,6 @@ var formatPercentage = (cacheRate) => {
|
|
|
4490
3807
|
|
|
4491
3808
|
// src/utils/pg.ts
|
|
4492
3809
|
import pg from "pg";
|
|
4493
|
-
|
|
4494
|
-
// src/utils/print.ts
|
|
4495
|
-
function prettyPrint(args) {
|
|
4496
|
-
if (args === void 0)
|
|
4497
|
-
return "(undefined)";
|
|
4498
|
-
const entries = Object.entries(args).map(([key, value]) => {
|
|
4499
|
-
if (value === void 0)
|
|
4500
|
-
return null;
|
|
4501
|
-
const trimmedValue = typeof value === "string" && value.length > 80 ? value.slice(0, 80).concat("...") : value;
|
|
4502
|
-
return [key, trimmedValue];
|
|
4503
|
-
}).filter(Boolean);
|
|
4504
|
-
if (entries.length === 0)
|
|
4505
|
-
return " (empty object)";
|
|
4506
|
-
const maxLength = entries.reduce(
|
|
4507
|
-
(acc, [key]) => Math.max(acc, key.length),
|
|
4508
|
-
0
|
|
4509
|
-
);
|
|
4510
|
-
return entries.map(([key, value]) => ` ${`${key}`.padEnd(maxLength + 1)} ${value}`).join("\n");
|
|
4511
|
-
}
|
|
4512
|
-
|
|
4513
|
-
// src/utils/pg.ts
|
|
4514
3810
|
var bigIntArrayParser = pg.types.getTypeParser(1016);
|
|
4515
3811
|
pg.types.setTypeParser(1231, bigIntArrayParser);
|
|
4516
3812
|
var originalClientQuery = pg.Client.prototype.query;
|
|
@@ -4706,7 +4002,7 @@ async function wait(milliseconds) {
|
|
|
4706
4002
|
}
|
|
4707
4003
|
|
|
4708
4004
|
// src/database/index.ts
|
|
4709
|
-
import { getTableColumns as
|
|
4005
|
+
import { getTableColumns as getTableColumns2 } from "drizzle-orm";
|
|
4710
4006
|
import { drizzle as drizzleNodePg } from "drizzle-orm/node-postgres";
|
|
4711
4007
|
import { drizzle as drizzlePglite } from "drizzle-orm/pglite";
|
|
4712
4008
|
import {
|
|
@@ -4942,8 +4238,8 @@ var createDatabase = async ({
|
|
|
4942
4238
|
for (const log of reversed) {
|
|
4943
4239
|
if (log.operation === 0) {
|
|
4944
4240
|
await tx.deleteFrom(tableName.sql).$call((qb2) => {
|
|
4945
|
-
for (const { sql:
|
|
4946
|
-
qb2 = qb2.where(
|
|
4241
|
+
for (const { sql: sql4 } of primaryKeyColumns) {
|
|
4242
|
+
qb2 = qb2.where(sql4, "=", log[sql4]);
|
|
4947
4243
|
}
|
|
4948
4244
|
return qb2;
|
|
4949
4245
|
}).execute();
|
|
@@ -4952,8 +4248,8 @@ var createDatabase = async ({
|
|
|
4952
4248
|
log.checkpoint = void 0;
|
|
4953
4249
|
log.operation = void 0;
|
|
4954
4250
|
await tx.updateTable(tableName.sql).set(log).$call((qb2) => {
|
|
4955
|
-
for (const { sql:
|
|
4956
|
-
qb2 = qb2.where(
|
|
4251
|
+
for (const { sql: sql4 } of primaryKeyColumns) {
|
|
4252
|
+
qb2 = qb2.where(sql4, "=", log[sql4]);
|
|
4957
4253
|
}
|
|
4958
4254
|
return qb2;
|
|
4959
4255
|
}).execute();
|
|
@@ -4962,7 +4258,7 @@ var createDatabase = async ({
|
|
|
4962
4258
|
log.checkpoint = void 0;
|
|
4963
4259
|
log.operation = void 0;
|
|
4964
4260
|
await tx.insertInto(tableName.sql).values(log).onConflict(
|
|
4965
|
-
(oc) => oc.columns(primaryKeyColumns.map(({ sql:
|
|
4261
|
+
(oc) => oc.columns(primaryKeyColumns.map(({ sql: sql4 }) => sql4)).doNothing()
|
|
4966
4262
|
).execute();
|
|
4967
4263
|
}
|
|
4968
4264
|
}
|
|
@@ -5217,7 +4513,7 @@ var createDatabase = async ({
|
|
|
5217
4513
|
if (createdTables) {
|
|
5218
4514
|
common.logger.info({
|
|
5219
4515
|
service: "database",
|
|
5220
|
-
msg: `Created tables [${getTableNames(schemaBuild.schema).map(({ sql:
|
|
4516
|
+
msg: `Created tables [${getTableNames(schemaBuild.schema).map(({ sql: sql4 }) => sql4).join(", ")}]`
|
|
5221
4517
|
});
|
|
5222
4518
|
const newApp = {
|
|
5223
4519
|
is_locked: 1,
|
|
@@ -5226,7 +4522,7 @@ var createDatabase = async ({
|
|
|
5226
4522
|
build_id: buildId,
|
|
5227
4523
|
checkpoint: ZERO_CHECKPOINT_STRING,
|
|
5228
4524
|
table_names: getTableNames(schemaBuild.schema).map(
|
|
5229
|
-
({ sql:
|
|
4525
|
+
({ sql: sql4 }) => sql4
|
|
5230
4526
|
),
|
|
5231
4527
|
version: VERSION
|
|
5232
4528
|
};
|
|
@@ -5347,7 +4643,7 @@ var createDatabase = async ({
|
|
|
5347
4643
|
{ method: "createTriggers", includeTraceLogs: true },
|
|
5348
4644
|
async () => {
|
|
5349
4645
|
for (const tableName of getTableNames(schemaBuild.schema)) {
|
|
5350
|
-
const columns =
|
|
4646
|
+
const columns = getTableColumns2(
|
|
5351
4647
|
schemaBuild.schema[tableName.js]
|
|
5352
4648
|
);
|
|
5353
4649
|
const columnNames = Object.values(columns).map(
|
|
@@ -5647,921 +4943,6 @@ var mergeResults = (results) => {
|
|
|
5647
4943
|
return { status: "success", result: results.map((result) => result.result) };
|
|
5648
4944
|
};
|
|
5649
4945
|
|
|
5650
|
-
// src/indexing-store/historical.ts
|
|
5651
|
-
import {
|
|
5652
|
-
and,
|
|
5653
|
-
eq,
|
|
5654
|
-
getTableColumns as getTableColumns4,
|
|
5655
|
-
getTableName as getTableName2,
|
|
5656
|
-
sql as sql3
|
|
5657
|
-
} from "drizzle-orm";
|
|
5658
|
-
import { getTableConfig as getTableConfig4 } from "drizzle-orm/pg-core";
|
|
5659
|
-
import { drizzle } from "drizzle-orm/pg-proxy";
|
|
5660
|
-
|
|
5661
|
-
// src/indexing-store/index.ts
|
|
5662
|
-
var parseSqlError = (e) => {
|
|
5663
|
-
let error = getBaseError(e);
|
|
5664
|
-
if (error?.message?.includes("violates not-null constraint")) {
|
|
5665
|
-
error = new NotNullConstraintError(error.message);
|
|
5666
|
-
} else if (error?.message?.includes("violates unique constraint")) {
|
|
5667
|
-
error = new UniqueConstraintError(error.message);
|
|
5668
|
-
} else if (error?.message.includes("violates check constraint")) {
|
|
5669
|
-
error = new CheckConstraintError(error.message);
|
|
5670
|
-
} else if (error?.message?.includes("Do not know how to serialize a BigInt")) {
|
|
5671
|
-
error = new BigIntSerializationError(error.message);
|
|
5672
|
-
error.meta.push(
|
|
5673
|
-
"Hint:\n The JSON column type does not support BigInt values. Use the replaceBigInts() helper function before inserting into the database. Docs: https://ponder.sh/docs/utilities/replace-bigints"
|
|
5674
|
-
);
|
|
5675
|
-
}
|
|
5676
|
-
return error;
|
|
5677
|
-
};
|
|
5678
|
-
|
|
5679
|
-
// src/indexing-store/historical.ts
|
|
5680
|
-
var checkOnchainTable = (table, method) => {
|
|
5681
|
-
if (table === void 0)
|
|
5682
|
-
throw new UndefinedTableError(
|
|
5683
|
-
`Table object passed to db.${method}() is undefined`
|
|
5684
|
-
);
|
|
5685
|
-
if (onchain in table)
|
|
5686
|
-
return;
|
|
5687
|
-
throw new InvalidStoreMethodError(
|
|
5688
|
-
method === "find" ? `db.find() can only be used with onchain tables, and '${getTableConfig4(table).name}' is an offchain table.` : `Indexing functions can only write to onchain tables, and '${getTableConfig4(table).name}' is an offchain table.`
|
|
5689
|
-
);
|
|
5690
|
-
};
|
|
5691
|
-
var hasEmptyValue = (column) => {
|
|
5692
|
-
return column.hasDefault;
|
|
5693
|
-
};
|
|
5694
|
-
var getEmptyValue = (column, type) => {
|
|
5695
|
-
if (type === 1 /* UPDATE */ && column.onUpdateFn) {
|
|
5696
|
-
return column.onUpdateFn();
|
|
5697
|
-
}
|
|
5698
|
-
if (column.default !== void 0)
|
|
5699
|
-
return column.default;
|
|
5700
|
-
if (column.defaultFn !== void 0)
|
|
5701
|
-
return column.defaultFn();
|
|
5702
|
-
if (column.onUpdateFn !== void 0)
|
|
5703
|
-
return column.onUpdateFn();
|
|
5704
|
-
return void 0;
|
|
5705
|
-
};
|
|
5706
|
-
var normalizeColumn = (column, value, type) => {
|
|
5707
|
-
if (value === void 0) {
|
|
5708
|
-
if (hasEmptyValue(column))
|
|
5709
|
-
return getEmptyValue(column, type);
|
|
5710
|
-
return null;
|
|
5711
|
-
}
|
|
5712
|
-
if (column.mapToDriverValue === void 0)
|
|
5713
|
-
return value;
|
|
5714
|
-
try {
|
|
5715
|
-
return column.mapFromDriverValue(column.mapToDriverValue(value));
|
|
5716
|
-
} catch (e) {
|
|
5717
|
-
if (e?.message?.includes("Do not know how to serialize a BigInt")) {
|
|
5718
|
-
const error = new BigIntSerializationError(e.message);
|
|
5719
|
-
error.meta.push(
|
|
5720
|
-
"Hint:\n The JSON column type does not support BigInt values. Use the replaceBigInts() helper function before inserting into the database. Docs: https://ponder.sh/docs/utilities/replace-bigints"
|
|
5721
|
-
);
|
|
5722
|
-
throw error;
|
|
5723
|
-
}
|
|
5724
|
-
}
|
|
5725
|
-
};
|
|
5726
|
-
var createHistoricalIndexingStore = ({
|
|
5727
|
-
common,
|
|
5728
|
-
schemaBuild: { schema },
|
|
5729
|
-
database,
|
|
5730
|
-
isDatabaseEmpty
|
|
5731
|
-
}) => {
|
|
5732
|
-
const queue = createQueue({
|
|
5733
|
-
browser: false,
|
|
5734
|
-
initialStart: true,
|
|
5735
|
-
concurrency: 1,
|
|
5736
|
-
worker: (fn) => {
|
|
5737
|
-
return fn();
|
|
5738
|
-
}
|
|
5739
|
-
});
|
|
5740
|
-
const primaryKeysCache = /* @__PURE__ */ new Map();
|
|
5741
|
-
const cache = /* @__PURE__ */ new Map();
|
|
5742
|
-
for (const tableName of getTableNames(schema)) {
|
|
5743
|
-
primaryKeysCache.set(
|
|
5744
|
-
schema[tableName.js],
|
|
5745
|
-
getPrimaryKeyColumns(schema[tableName.js])
|
|
5746
|
-
);
|
|
5747
|
-
cache.set(schema[tableName.js], /* @__PURE__ */ new Map());
|
|
5748
|
-
}
|
|
5749
|
-
const getCacheKey = (table, row) => {
|
|
5750
|
-
const primaryKeys = primaryKeysCache.get(table);
|
|
5751
|
-
return primaryKeys.map((pk) => normalizeColumn(table[pk.js], row[pk.js])).join("_");
|
|
5752
|
-
};
|
|
5753
|
-
const getCacheEntry = (table, row) => {
|
|
5754
|
-
return cache.get(table).get(getCacheKey(table, row));
|
|
5755
|
-
};
|
|
5756
|
-
const setCacheEntry = (table, userRow, entryType, existingRow) => {
|
|
5757
|
-
let row = structuredClone(userRow);
|
|
5758
|
-
if (existingRow) {
|
|
5759
|
-
for (const [key, value] of Object.entries(row)) {
|
|
5760
|
-
existingRow[key] = value;
|
|
5761
|
-
}
|
|
5762
|
-
existingRow = normalizeRow(table, existingRow, entryType);
|
|
5763
|
-
const bytes = getBytes(existingRow);
|
|
5764
|
-
cacheBytes += bytes;
|
|
5765
|
-
cache.get(table).set(getCacheKey(table, existingRow), {
|
|
5766
|
-
type: entryType,
|
|
5767
|
-
row: existingRow,
|
|
5768
|
-
operationIndex: totalCacheOps++,
|
|
5769
|
-
bytes
|
|
5770
|
-
});
|
|
5771
|
-
return structuredClone(existingRow);
|
|
5772
|
-
} else {
|
|
5773
|
-
row = normalizeRow(table, row, entryType);
|
|
5774
|
-
const bytes = getBytes(row);
|
|
5775
|
-
cacheBytes += bytes;
|
|
5776
|
-
cache.get(table).set(getCacheKey(table, row), {
|
|
5777
|
-
type: entryType,
|
|
5778
|
-
bytes,
|
|
5779
|
-
operationIndex: totalCacheOps++,
|
|
5780
|
-
row
|
|
5781
|
-
});
|
|
5782
|
-
return structuredClone(row);
|
|
5783
|
-
}
|
|
5784
|
-
};
|
|
5785
|
-
const deleteCacheEntry = (table, row) => {
|
|
5786
|
-
const entry = getCacheEntry(table, row);
|
|
5787
|
-
if (entry) {
|
|
5788
|
-
cacheBytes -= entry.bytes;
|
|
5789
|
-
}
|
|
5790
|
-
return cache.get(table).delete(getCacheKey(table, row));
|
|
5791
|
-
};
|
|
5792
|
-
const normalizeRow = (table, row, type) => {
|
|
5793
|
-
for (const [columnName, column] of Object.entries(getTableColumns4(table))) {
|
|
5794
|
-
if (type === 0 /* INSERT */ && (row[columnName] === void 0 || row[columnName] === null) && column.notNull && hasEmptyValue(column) === false) {
|
|
5795
|
-
const error = new NotNullConstraintError(
|
|
5796
|
-
`Column '${getTableName2(table)}.${columnName}' violates not-null constraint.`
|
|
5797
|
-
);
|
|
5798
|
-
error.meta.push(
|
|
5799
|
-
`db.${type === 0 /* INSERT */ ? "insert" : "update"} arguments:
|
|
5800
|
-
${prettyPrint(row)}`
|
|
5801
|
-
);
|
|
5802
|
-
throw error;
|
|
5803
|
-
}
|
|
5804
|
-
row[columnName] = normalizeColumn(column, row[columnName], type);
|
|
5805
|
-
}
|
|
5806
|
-
return row;
|
|
5807
|
-
};
|
|
5808
|
-
const getBytes = (value) => {
|
|
5809
|
-
let size = 13;
|
|
5810
|
-
if (typeof value === "number") {
|
|
5811
|
-
size += 8;
|
|
5812
|
-
} else if (typeof value === "string") {
|
|
5813
|
-
size += 2 * value.length;
|
|
5814
|
-
} else if (typeof value === "boolean") {
|
|
5815
|
-
size += 4;
|
|
5816
|
-
} else if (typeof value === "bigint") {
|
|
5817
|
-
size += 48;
|
|
5818
|
-
} else if (value === null || value === void 0) {
|
|
5819
|
-
size += 8;
|
|
5820
|
-
} else if (Array.isArray(value)) {
|
|
5821
|
-
for (const e of value) {
|
|
5822
|
-
size += getBytes(e);
|
|
5823
|
-
}
|
|
5824
|
-
} else {
|
|
5825
|
-
for (const col of Object.values(value)) {
|
|
5826
|
-
size += getBytes(col);
|
|
5827
|
-
}
|
|
5828
|
-
}
|
|
5829
|
-
return size;
|
|
5830
|
-
};
|
|
5831
|
-
let cacheBytes = 0;
|
|
5832
|
-
let totalCacheOps = 0;
|
|
5833
|
-
const maxBytes = common.options.indexingCacheMaxBytes;
|
|
5834
|
-
common.logger.debug({
|
|
5835
|
-
service: "indexing",
|
|
5836
|
-
msg: `Using a ${Math.round(maxBytes / (1024 * 1024))} MB indexing cache`
|
|
5837
|
-
});
|
|
5838
|
-
const getWhereCondition = (table, key) => {
|
|
5839
|
-
primaryKeysCache.get(table);
|
|
5840
|
-
const conditions = [];
|
|
5841
|
-
for (const { js } of primaryKeysCache.get(table)) {
|
|
5842
|
-
conditions.push(eq(table[js], key[js]));
|
|
5843
|
-
}
|
|
5844
|
-
return and(...conditions);
|
|
5845
|
-
};
|
|
5846
|
-
const find = (table, key) => {
|
|
5847
|
-
return database.qb.drizzle.select().from(table).where(getWhereCondition(table, key)).then((res) => res.length === 0 ? null : res[0]);
|
|
5848
|
-
};
|
|
5849
|
-
const indexingStore = {
|
|
5850
|
-
// @ts-ignore
|
|
5851
|
-
find: (table, key) => queue.add(
|
|
5852
|
-
() => database.wrap(
|
|
5853
|
-
{ method: `${getTableName2(table) ?? "unknown"}.find()` },
|
|
5854
|
-
async () => {
|
|
5855
|
-
checkOnchainTable(table, "find");
|
|
5856
|
-
const entry = getCacheEntry(table, key);
|
|
5857
|
-
if (entry) {
|
|
5858
|
-
getCacheEntry(table, key).operationIndex = totalCacheOps++;
|
|
5859
|
-
return entry.row;
|
|
5860
|
-
} else {
|
|
5861
|
-
if (isDatabaseEmpty)
|
|
5862
|
-
return null;
|
|
5863
|
-
const row = await find(table, key);
|
|
5864
|
-
const bytes = getBytes(row);
|
|
5865
|
-
cacheBytes += bytes;
|
|
5866
|
-
cache.get(table).set(getCacheKey(table, key), {
|
|
5867
|
-
type: 2 /* FIND */,
|
|
5868
|
-
bytes,
|
|
5869
|
-
operationIndex: totalCacheOps++,
|
|
5870
|
-
row
|
|
5871
|
-
});
|
|
5872
|
-
return find(table, key);
|
|
5873
|
-
}
|
|
5874
|
-
}
|
|
5875
|
-
)
|
|
5876
|
-
),
|
|
5877
|
-
// @ts-ignore
|
|
5878
|
-
insert(table) {
|
|
5879
|
-
return {
|
|
5880
|
-
values: (values) => {
|
|
5881
|
-
const inner = {
|
|
5882
|
-
onConflictDoNothing: () => queue.add(
|
|
5883
|
-
() => database.wrap(
|
|
5884
|
-
{
|
|
5885
|
-
method: `${getTableName2(table) ?? "unknown"}.insert()`
|
|
5886
|
-
},
|
|
5887
|
-
async () => {
|
|
5888
|
-
checkOnchainTable(table, "insert");
|
|
5889
|
-
if (Array.isArray(values)) {
|
|
5890
|
-
const rows = [];
|
|
5891
|
-
for (const value of values) {
|
|
5892
|
-
const entry = getCacheEntry(table, value);
|
|
5893
|
-
let row;
|
|
5894
|
-
if (entry?.row) {
|
|
5895
|
-
row = entry.row;
|
|
5896
|
-
} else {
|
|
5897
|
-
if (isDatabaseEmpty)
|
|
5898
|
-
row = null;
|
|
5899
|
-
else
|
|
5900
|
-
row = await find(table, value);
|
|
5901
|
-
}
|
|
5902
|
-
if (row === null) {
|
|
5903
|
-
rows.push(
|
|
5904
|
-
setCacheEntry(table, value, 0 /* INSERT */)
|
|
5905
|
-
);
|
|
5906
|
-
} else {
|
|
5907
|
-
rows.push(null);
|
|
5908
|
-
}
|
|
5909
|
-
}
|
|
5910
|
-
return rows;
|
|
5911
|
-
} else {
|
|
5912
|
-
const entry = getCacheEntry(table, values);
|
|
5913
|
-
let row;
|
|
5914
|
-
if (entry?.row) {
|
|
5915
|
-
row = entry.row;
|
|
5916
|
-
} else {
|
|
5917
|
-
if (isDatabaseEmpty)
|
|
5918
|
-
row = null;
|
|
5919
|
-
else
|
|
5920
|
-
row = await find(table, values);
|
|
5921
|
-
}
|
|
5922
|
-
if (row === null) {
|
|
5923
|
-
return setCacheEntry(table, values, 0 /* INSERT */);
|
|
5924
|
-
}
|
|
5925
|
-
return null;
|
|
5926
|
-
}
|
|
5927
|
-
}
|
|
5928
|
-
)
|
|
5929
|
-
),
|
|
5930
|
-
onConflictDoUpdate: (valuesU) => queue.add(
|
|
5931
|
-
() => database.wrap(
|
|
5932
|
-
{
|
|
5933
|
-
method: `${getTableName2(table) ?? "unknown"}.insert()`
|
|
5934
|
-
},
|
|
5935
|
-
async () => {
|
|
5936
|
-
checkOnchainTable(table, "insert");
|
|
5937
|
-
if (Array.isArray(values)) {
|
|
5938
|
-
const rows = [];
|
|
5939
|
-
for (const value of values) {
|
|
5940
|
-
const entry = getCacheEntry(table, value);
|
|
5941
|
-
deleteCacheEntry(table, value);
|
|
5942
|
-
let row;
|
|
5943
|
-
if (entry?.row) {
|
|
5944
|
-
row = entry.row;
|
|
5945
|
-
} else {
|
|
5946
|
-
if (isDatabaseEmpty)
|
|
5947
|
-
row = null;
|
|
5948
|
-
else
|
|
5949
|
-
row = await find(table, value);
|
|
5950
|
-
}
|
|
5951
|
-
if (row === null) {
|
|
5952
|
-
rows.push(
|
|
5953
|
-
setCacheEntry(table, value, 0 /* INSERT */)
|
|
5954
|
-
);
|
|
5955
|
-
} else {
|
|
5956
|
-
if (typeof valuesU === "function") {
|
|
5957
|
-
rows.push(
|
|
5958
|
-
setCacheEntry(
|
|
5959
|
-
table,
|
|
5960
|
-
valuesU(row),
|
|
5961
|
-
entry?.type === 0 /* INSERT */ ? 0 /* INSERT */ : 1 /* UPDATE */,
|
|
5962
|
-
row
|
|
5963
|
-
)
|
|
5964
|
-
);
|
|
5965
|
-
} else {
|
|
5966
|
-
rows.push(
|
|
5967
|
-
setCacheEntry(
|
|
5968
|
-
table,
|
|
5969
|
-
valuesU,
|
|
5970
|
-
entry?.type === 0 /* INSERT */ ? 0 /* INSERT */ : 1 /* UPDATE */,
|
|
5971
|
-
row
|
|
5972
|
-
)
|
|
5973
|
-
);
|
|
5974
|
-
}
|
|
5975
|
-
}
|
|
5976
|
-
}
|
|
5977
|
-
return rows;
|
|
5978
|
-
} else {
|
|
5979
|
-
const entry = getCacheEntry(table, values);
|
|
5980
|
-
deleteCacheEntry(table, values);
|
|
5981
|
-
let row;
|
|
5982
|
-
if (entry?.row) {
|
|
5983
|
-
row = entry.row;
|
|
5984
|
-
} else {
|
|
5985
|
-
if (isDatabaseEmpty)
|
|
5986
|
-
row = null;
|
|
5987
|
-
else
|
|
5988
|
-
row = await find(table, values);
|
|
5989
|
-
}
|
|
5990
|
-
if (row === null) {
|
|
5991
|
-
return setCacheEntry(table, values, 0 /* INSERT */);
|
|
5992
|
-
} else {
|
|
5993
|
-
if (typeof valuesU === "function") {
|
|
5994
|
-
return setCacheEntry(
|
|
5995
|
-
table,
|
|
5996
|
-
valuesU(row),
|
|
5997
|
-
entry?.type === 0 /* INSERT */ ? 0 /* INSERT */ : 1 /* UPDATE */,
|
|
5998
|
-
row
|
|
5999
|
-
);
|
|
6000
|
-
} else {
|
|
6001
|
-
return setCacheEntry(
|
|
6002
|
-
table,
|
|
6003
|
-
valuesU,
|
|
6004
|
-
entry?.type === 0 /* INSERT */ ? 0 /* INSERT */ : 1 /* UPDATE */,
|
|
6005
|
-
row
|
|
6006
|
-
);
|
|
6007
|
-
}
|
|
6008
|
-
}
|
|
6009
|
-
}
|
|
6010
|
-
}
|
|
6011
|
-
)
|
|
6012
|
-
),
|
|
6013
|
-
// biome-ignore lint/suspicious/noThenProperty: <explanation>
|
|
6014
|
-
then: (onFulfilled, onRejected) => queue.add(
|
|
6015
|
-
() => database.wrap(
|
|
6016
|
-
{
|
|
6017
|
-
method: `${getTableName2(table) ?? "unknown"}.insert()`
|
|
6018
|
-
},
|
|
6019
|
-
async () => {
|
|
6020
|
-
checkOnchainTable(table, "insert");
|
|
6021
|
-
if (Array.isArray(values)) {
|
|
6022
|
-
const rows = [];
|
|
6023
|
-
for (const value of values) {
|
|
6024
|
-
if (getCacheEntry(table, value)?.row) {
|
|
6025
|
-
const error = new UniqueConstraintError(
|
|
6026
|
-
`Unique constraint failed for '${getTableName2(table)}'.`
|
|
6027
|
-
);
|
|
6028
|
-
error.meta.push(
|
|
6029
|
-
`db.insert arguments:
|
|
6030
|
-
${prettyPrint(value)}`
|
|
6031
|
-
);
|
|
6032
|
-
throw error;
|
|
6033
|
-
} else if (isDatabaseEmpty === false) {
|
|
6034
|
-
const findResult = await find(table, value);
|
|
6035
|
-
if (findResult) {
|
|
6036
|
-
const error = new UniqueConstraintError(
|
|
6037
|
-
`Unique constraint failed for '${getTableName2(table)}'.`
|
|
6038
|
-
);
|
|
6039
|
-
error.meta.push(
|
|
6040
|
-
`db.insert arguments:
|
|
6041
|
-
${prettyPrint(value)}`
|
|
6042
|
-
);
|
|
6043
|
-
throw error;
|
|
6044
|
-
}
|
|
6045
|
-
}
|
|
6046
|
-
rows.push(
|
|
6047
|
-
setCacheEntry(table, value, 0 /* INSERT */)
|
|
6048
|
-
);
|
|
6049
|
-
}
|
|
6050
|
-
return rows;
|
|
6051
|
-
} else {
|
|
6052
|
-
if (getCacheEntry(table, values)?.row) {
|
|
6053
|
-
const error = new UniqueConstraintError(
|
|
6054
|
-
`Unique constraint failed for '${getTableName2(table)}'.`
|
|
6055
|
-
);
|
|
6056
|
-
error.meta.push(
|
|
6057
|
-
`db.insert arguments:
|
|
6058
|
-
${prettyPrint(values)}`
|
|
6059
|
-
);
|
|
6060
|
-
throw error;
|
|
6061
|
-
} else if (isDatabaseEmpty === false) {
|
|
6062
|
-
const findResult = await find(table, values);
|
|
6063
|
-
if (findResult) {
|
|
6064
|
-
const error = new UniqueConstraintError(
|
|
6065
|
-
`Unique constraint failed for '${getTableName2(table)}'.`
|
|
6066
|
-
);
|
|
6067
|
-
error.meta.push(
|
|
6068
|
-
`db.insert arguments:
|
|
6069
|
-
${prettyPrint(values)}`
|
|
6070
|
-
);
|
|
6071
|
-
throw error;
|
|
6072
|
-
}
|
|
6073
|
-
}
|
|
6074
|
-
return setCacheEntry(table, values, 0 /* INSERT */);
|
|
6075
|
-
}
|
|
6076
|
-
}
|
|
6077
|
-
)
|
|
6078
|
-
).then(onFulfilled, onRejected),
|
|
6079
|
-
catch: (onRejected) => inner.then(void 0, onRejected),
|
|
6080
|
-
finally: (onFinally) => inner.then(
|
|
6081
|
-
(value) => {
|
|
6082
|
-
onFinally?.();
|
|
6083
|
-
return value;
|
|
6084
|
-
},
|
|
6085
|
-
(reason) => {
|
|
6086
|
-
onFinally?.();
|
|
6087
|
-
throw reason;
|
|
6088
|
-
}
|
|
6089
|
-
)
|
|
6090
|
-
// @ts-ignore
|
|
6091
|
-
};
|
|
6092
|
-
return inner;
|
|
6093
|
-
}
|
|
6094
|
-
};
|
|
6095
|
-
},
|
|
6096
|
-
// @ts-ignore
|
|
6097
|
-
update(table, key) {
|
|
6098
|
-
return {
|
|
6099
|
-
set: (values) => queue.add(
|
|
6100
|
-
() => database.wrap(
|
|
6101
|
-
{ method: `${getTableName2(table) ?? "unknown"}.update()` },
|
|
6102
|
-
async () => {
|
|
6103
|
-
checkOnchainTable(table, "update");
|
|
6104
|
-
const entry = getCacheEntry(table, key);
|
|
6105
|
-
deleteCacheEntry(table, key);
|
|
6106
|
-
let row;
|
|
6107
|
-
if (entry?.row) {
|
|
6108
|
-
row = entry.row;
|
|
6109
|
-
} else {
|
|
6110
|
-
if (isDatabaseEmpty) {
|
|
6111
|
-
const error = new RecordNotFoundError(
|
|
6112
|
-
`No existing record found in table '${getTableName2(table)}'`
|
|
6113
|
-
);
|
|
6114
|
-
error.meta.push(
|
|
6115
|
-
`db.update arguments:
|
|
6116
|
-
${prettyPrint(key)}`
|
|
6117
|
-
);
|
|
6118
|
-
throw error;
|
|
6119
|
-
}
|
|
6120
|
-
const findResult = await find(table, key);
|
|
6121
|
-
if (findResult) {
|
|
6122
|
-
row = findResult;
|
|
6123
|
-
} else {
|
|
6124
|
-
const error = new RecordNotFoundError(
|
|
6125
|
-
`No existing record found in table '${getTableName2(table)}'`
|
|
6126
|
-
);
|
|
6127
|
-
error.meta.push(
|
|
6128
|
-
`db.update arguments:
|
|
6129
|
-
${prettyPrint(key)}`
|
|
6130
|
-
);
|
|
6131
|
-
throw error;
|
|
6132
|
-
}
|
|
6133
|
-
}
|
|
6134
|
-
if (typeof values === "function") {
|
|
6135
|
-
return setCacheEntry(
|
|
6136
|
-
table,
|
|
6137
|
-
values(row),
|
|
6138
|
-
entry?.type === 0 /* INSERT */ ? 0 /* INSERT */ : 1 /* UPDATE */,
|
|
6139
|
-
row
|
|
6140
|
-
);
|
|
6141
|
-
} else {
|
|
6142
|
-
return setCacheEntry(
|
|
6143
|
-
table,
|
|
6144
|
-
values,
|
|
6145
|
-
entry?.type === 0 /* INSERT */ ? 0 /* INSERT */ : 1 /* UPDATE */,
|
|
6146
|
-
row
|
|
6147
|
-
);
|
|
6148
|
-
}
|
|
6149
|
-
}
|
|
6150
|
-
)
|
|
6151
|
-
)
|
|
6152
|
-
};
|
|
6153
|
-
},
|
|
6154
|
-
// @ts-ignore
|
|
6155
|
-
delete: (table, key) => queue.add(
|
|
6156
|
-
() => database.wrap(
|
|
6157
|
-
{ method: `${getTableName2(table) ?? "unknown"}.delete()` },
|
|
6158
|
-
async () => {
|
|
6159
|
-
checkOnchainTable(table, "delete");
|
|
6160
|
-
const entry = getCacheEntry(table, key);
|
|
6161
|
-
deleteCacheEntry(table, key);
|
|
6162
|
-
if (entry?.row) {
|
|
6163
|
-
if (entry.type === 0 /* INSERT */) {
|
|
6164
|
-
return true;
|
|
6165
|
-
}
|
|
6166
|
-
await database.qb.drizzle.delete(table).where(getWhereCondition(table, key));
|
|
6167
|
-
return true;
|
|
6168
|
-
} else {
|
|
6169
|
-
if (isDatabaseEmpty) {
|
|
6170
|
-
return false;
|
|
6171
|
-
}
|
|
6172
|
-
const deleteResult = await database.qb.drizzle.delete(table).where(getWhereCondition(table, key)).returning();
|
|
6173
|
-
return deleteResult.length > 0;
|
|
6174
|
-
}
|
|
6175
|
-
}
|
|
6176
|
-
)
|
|
6177
|
-
),
|
|
6178
|
-
// @ts-ignore
|
|
6179
|
-
sql: drizzle(
|
|
6180
|
-
async (_sql, params, method, typings) => {
|
|
6181
|
-
await database.createTriggers();
|
|
6182
|
-
await indexingStore.flush();
|
|
6183
|
-
await database.removeTriggers();
|
|
6184
|
-
isDatabaseEmpty = false;
|
|
6185
|
-
const query2 = { sql: _sql, params, typings };
|
|
6186
|
-
const res = await database.wrap({ method: "sql" }, async () => {
|
|
6187
|
-
try {
|
|
6188
|
-
return await database.qb.drizzle._.session.prepareQuery(query2, void 0, void 0, method === "all").execute();
|
|
6189
|
-
} catch (e) {
|
|
6190
|
-
throw parseSqlError(e);
|
|
6191
|
-
}
|
|
6192
|
-
});
|
|
6193
|
-
return { rows: res.rows.map((row) => Object.values(row)) };
|
|
6194
|
-
},
|
|
6195
|
-
{ schema, casing: "snake_case" }
|
|
6196
|
-
),
|
|
6197
|
-
async flush() {
|
|
6198
|
-
await queue.add(async () => {
|
|
6199
|
-
let cacheSize = 0;
|
|
6200
|
-
for (const c of cache.values())
|
|
6201
|
-
cacheSize += c.size;
|
|
6202
|
-
const flushIndex = totalCacheOps - cacheSize * (1 - common.options.indexingCacheFlushRatio);
|
|
6203
|
-
const shouldDelete = cacheBytes > maxBytes;
|
|
6204
|
-
if (shouldDelete)
|
|
6205
|
-
isDatabaseEmpty = false;
|
|
6206
|
-
const promises = [];
|
|
6207
|
-
for (const [table, tableCache] of cache) {
|
|
6208
|
-
const batchSize = Math.round(
|
|
6209
|
-
common.options.databaseMaxQueryParameters / Object.keys(getTableColumns4(table)).length
|
|
6210
|
-
);
|
|
6211
|
-
const insertValues = [];
|
|
6212
|
-
const updateValues = [];
|
|
6213
|
-
for (const [key, entry] of tableCache) {
|
|
6214
|
-
if (entry.type === 0 /* INSERT */) {
|
|
6215
|
-
insertValues.push(entry.row);
|
|
6216
|
-
}
|
|
6217
|
-
if (entry.type === 1 /* UPDATE */) {
|
|
6218
|
-
updateValues.push(entry.row);
|
|
6219
|
-
}
|
|
6220
|
-
if (shouldDelete && entry.operationIndex < flushIndex) {
|
|
6221
|
-
tableCache.delete(key);
|
|
6222
|
-
cacheBytes -= entry.bytes;
|
|
6223
|
-
}
|
|
6224
|
-
entry.type = 2 /* FIND */;
|
|
6225
|
-
}
|
|
6226
|
-
if (insertValues.length > 0) {
|
|
6227
|
-
common.logger.debug({
|
|
6228
|
-
service: "indexing",
|
|
6229
|
-
msg: `Inserting ${insertValues.length} cached '${getTableName2(table)}' rows into the database`
|
|
6230
|
-
});
|
|
6231
|
-
while (insertValues.length > 0) {
|
|
6232
|
-
const values = insertValues.splice(0, batchSize);
|
|
6233
|
-
promises.push(
|
|
6234
|
-
database.wrap(
|
|
6235
|
-
{ method: `${getTableName2(table)}.flush()` },
|
|
6236
|
-
async () => {
|
|
6237
|
-
await database.qb.drizzle.insert(table).values(values).catch((_error) => {
|
|
6238
|
-
const error = _error;
|
|
6239
|
-
common.logger.error({
|
|
6240
|
-
service: "indexing",
|
|
6241
|
-
msg: "Internal error occurred while flushing cache. Please report this error here: https://github.com/ponder-sh/ponder/issues"
|
|
6242
|
-
});
|
|
6243
|
-
throw new FlushError(error.message);
|
|
6244
|
-
});
|
|
6245
|
-
}
|
|
6246
|
-
)
|
|
6247
|
-
);
|
|
6248
|
-
}
|
|
6249
|
-
}
|
|
6250
|
-
if (updateValues.length > 0) {
|
|
6251
|
-
common.logger.debug({
|
|
6252
|
-
service: "indexing",
|
|
6253
|
-
msg: `Updating ${updateValues.length} cached '${getTableName2(table)}' rows in the database`
|
|
6254
|
-
});
|
|
6255
|
-
const primaryKeys = primaryKeysCache.get(table);
|
|
6256
|
-
const set = {};
|
|
6257
|
-
for (const [columnName, column] of Object.entries(
|
|
6258
|
-
getTableColumns4(table)
|
|
6259
|
-
)) {
|
|
6260
|
-
set[columnName] = sql3.raw(
|
|
6261
|
-
`excluded."${getColumnCasing(column, "snake_case")}"`
|
|
6262
|
-
);
|
|
6263
|
-
}
|
|
6264
|
-
while (updateValues.length > 0) {
|
|
6265
|
-
const values = updateValues.splice(0, batchSize);
|
|
6266
|
-
promises.push(
|
|
6267
|
-
database.wrap(
|
|
6268
|
-
{
|
|
6269
|
-
method: `${getTableName2(table)}.flush()`
|
|
6270
|
-
},
|
|
6271
|
-
async () => {
|
|
6272
|
-
await database.qb.drizzle.insert(table).values(values).onConflictDoUpdate({
|
|
6273
|
-
// @ts-ignore
|
|
6274
|
-
target: primaryKeys.map(({ js }) => table[js]),
|
|
6275
|
-
set
|
|
6276
|
-
}).catch((_error) => {
|
|
6277
|
-
const error = _error;
|
|
6278
|
-
common.logger.error({
|
|
6279
|
-
service: "indexing",
|
|
6280
|
-
msg: "Internal error occurred while flushing cache. Please report this error here: https://github.com/ponder-sh/ponder/issues"
|
|
6281
|
-
});
|
|
6282
|
-
throw new FlushError(error.message);
|
|
6283
|
-
});
|
|
6284
|
-
}
|
|
6285
|
-
)
|
|
6286
|
-
);
|
|
6287
|
-
}
|
|
6288
|
-
}
|
|
6289
|
-
}
|
|
6290
|
-
await Promise.all(promises);
|
|
6291
|
-
});
|
|
6292
|
-
},
|
|
6293
|
-
isCacheFull() {
|
|
6294
|
-
return cacheBytes > maxBytes;
|
|
6295
|
-
}
|
|
6296
|
-
};
|
|
6297
|
-
return indexingStore;
|
|
6298
|
-
};
|
|
6299
|
-
|
|
6300
|
-
// src/indexing-store/realtime.ts
|
|
6301
|
-
import {
|
|
6302
|
-
and as and2,
|
|
6303
|
-
eq as eq2,
|
|
6304
|
-
getTableName as getTableName3
|
|
6305
|
-
} from "drizzle-orm";
|
|
6306
|
-
import { getTableConfig as getTableConfig5 } from "drizzle-orm/pg-core";
|
|
6307
|
-
import { drizzle as drizzle2 } from "drizzle-orm/pg-proxy";
|
|
6308
|
-
var checkOnchainTable2 = (table, method) => {
|
|
6309
|
-
if (table === void 0)
|
|
6310
|
-
throw new UndefinedTableError(
|
|
6311
|
-
`Table object passed to db.${method}() is undefined`
|
|
6312
|
-
);
|
|
6313
|
-
if (onchain in table)
|
|
6314
|
-
return;
|
|
6315
|
-
throw new InvalidStoreMethodError(
|
|
6316
|
-
method === "find" ? `db.find() can only be used with onchain tables, and '${getTableConfig5(table).name}' is an offchain table.` : `Indexing functions can only write to onchain tables, and '${getTableConfig5(table).name}' is an offchain table.`
|
|
6317
|
-
);
|
|
6318
|
-
};
|
|
6319
|
-
var createRealtimeIndexingStore = ({
|
|
6320
|
-
schemaBuild: { schema },
|
|
6321
|
-
database
|
|
6322
|
-
}) => {
|
|
6323
|
-
const queue = createQueue({
|
|
6324
|
-
browser: false,
|
|
6325
|
-
initialStart: true,
|
|
6326
|
-
concurrency: 1,
|
|
6327
|
-
worker: (fn) => {
|
|
6328
|
-
return fn();
|
|
6329
|
-
}
|
|
6330
|
-
});
|
|
6331
|
-
const primaryKeysCache = /* @__PURE__ */ new Map();
|
|
6332
|
-
for (const tableName of getTableNames(schema)) {
|
|
6333
|
-
primaryKeysCache.set(
|
|
6334
|
-
schema[tableName.js],
|
|
6335
|
-
getPrimaryKeyColumns(schema[tableName.js])
|
|
6336
|
-
);
|
|
6337
|
-
}
|
|
6338
|
-
const getCacheKey = (table, row) => {
|
|
6339
|
-
const primaryKeys = primaryKeysCache.get(table);
|
|
6340
|
-
return primaryKeys.map((pk) => normalizeColumn(table[pk.js], row[pk.js])).join("_");
|
|
6341
|
-
};
|
|
6342
|
-
const getWhereCondition = (table, key) => {
|
|
6343
|
-
primaryKeysCache.get(table);
|
|
6344
|
-
const conditions = [];
|
|
6345
|
-
for (const { js } of primaryKeysCache.get(table)) {
|
|
6346
|
-
conditions.push(eq2(table[js], key[js]));
|
|
6347
|
-
}
|
|
6348
|
-
return and2(...conditions);
|
|
6349
|
-
};
|
|
6350
|
-
const find = (table, key) => {
|
|
6351
|
-
return database.qb.drizzle.select().from(table).where(getWhereCondition(table, key)).then((res) => res.length === 0 ? null : res[0]);
|
|
6352
|
-
};
|
|
6353
|
-
const indexingStore = {
|
|
6354
|
-
// @ts-ignore
|
|
6355
|
-
find: (table, key) => queue.add(
|
|
6356
|
-
() => database.wrap(
|
|
6357
|
-
{ method: `${getTableName3(table) ?? "unknown"}.find()` },
|
|
6358
|
-
async () => {
|
|
6359
|
-
checkOnchainTable2(table, "find");
|
|
6360
|
-
return find(table, key);
|
|
6361
|
-
}
|
|
6362
|
-
)
|
|
6363
|
-
),
|
|
6364
|
-
// @ts-ignore
|
|
6365
|
-
insert(table) {
|
|
6366
|
-
return {
|
|
6367
|
-
values: (values) => {
|
|
6368
|
-
const inner = {
|
|
6369
|
-
onConflictDoNothing: () => queue.add(
|
|
6370
|
-
() => database.wrap(
|
|
6371
|
-
{
|
|
6372
|
-
method: `${getTableName3(table) ?? "unknown"}.insert()`
|
|
6373
|
-
},
|
|
6374
|
-
async () => {
|
|
6375
|
-
checkOnchainTable2(table, "insert");
|
|
6376
|
-
const parseResult = (result) => {
|
|
6377
|
-
if (Array.isArray(values) === false) {
|
|
6378
|
-
return result.length === 1 ? result[0] : null;
|
|
6379
|
-
}
|
|
6380
|
-
const rows = [];
|
|
6381
|
-
let resultIndex = 0;
|
|
6382
|
-
for (let i = 0; i < values.length; i++) {
|
|
6383
|
-
if (getCacheKey(table, values[i]) === getCacheKey(table, result[resultIndex])) {
|
|
6384
|
-
rows.push(result[resultIndex++]);
|
|
6385
|
-
} else {
|
|
6386
|
-
rows.push(null);
|
|
6387
|
-
}
|
|
6388
|
-
}
|
|
6389
|
-
return rows;
|
|
6390
|
-
};
|
|
6391
|
-
try {
|
|
6392
|
-
return await database.qb.drizzle.insert(table).values(values).onConflictDoNothing().returning().then(parseResult);
|
|
6393
|
-
} catch (e) {
|
|
6394
|
-
throw parseSqlError(e);
|
|
6395
|
-
}
|
|
6396
|
-
}
|
|
6397
|
-
)
|
|
6398
|
-
),
|
|
6399
|
-
onConflictDoUpdate: (valuesU) => queue.add(
|
|
6400
|
-
() => database.wrap(
|
|
6401
|
-
{
|
|
6402
|
-
method: `${getTableName3(table) ?? "unknown"}.insert()`
|
|
6403
|
-
},
|
|
6404
|
-
async () => {
|
|
6405
|
-
checkOnchainTable2(table, "insert");
|
|
6406
|
-
if (typeof valuesU === "object") {
|
|
6407
|
-
try {
|
|
6408
|
-
return await database.qb.drizzle.insert(table).values(values).onConflictDoUpdate({
|
|
6409
|
-
target: primaryKeysCache.get(table).map(({ js }) => table[js]),
|
|
6410
|
-
set: valuesU
|
|
6411
|
-
}).returning().then(
|
|
6412
|
-
(res) => Array.isArray(values) ? res : res[0]
|
|
6413
|
-
);
|
|
6414
|
-
} catch (e) {
|
|
6415
|
-
throw parseSqlError(e);
|
|
6416
|
-
}
|
|
6417
|
-
}
|
|
6418
|
-
if (Array.isArray(values)) {
|
|
6419
|
-
const rows = [];
|
|
6420
|
-
for (const value of values) {
|
|
6421
|
-
const row = await find(table, value);
|
|
6422
|
-
if (row === null) {
|
|
6423
|
-
try {
|
|
6424
|
-
rows.push(
|
|
6425
|
-
await database.qb.drizzle.insert(table).values(value).returning().then((res) => res[0])
|
|
6426
|
-
);
|
|
6427
|
-
} catch (e) {
|
|
6428
|
-
throw parseSqlError(e);
|
|
6429
|
-
}
|
|
6430
|
-
} else {
|
|
6431
|
-
try {
|
|
6432
|
-
rows.push(
|
|
6433
|
-
await database.qb.drizzle.update(table).set(valuesU(row)).where(getWhereCondition(table, value)).returning().then((res) => res[0])
|
|
6434
|
-
);
|
|
6435
|
-
} catch (e) {
|
|
6436
|
-
throw parseSqlError(e);
|
|
6437
|
-
}
|
|
6438
|
-
}
|
|
6439
|
-
}
|
|
6440
|
-
return rows;
|
|
6441
|
-
} else {
|
|
6442
|
-
const row = await find(table, values);
|
|
6443
|
-
if (row === null) {
|
|
6444
|
-
try {
|
|
6445
|
-
return await database.qb.drizzle.insert(table).values(values).returning().then((res) => res[0]);
|
|
6446
|
-
} catch (e) {
|
|
6447
|
-
throw parseSqlError(e);
|
|
6448
|
-
}
|
|
6449
|
-
} else {
|
|
6450
|
-
try {
|
|
6451
|
-
return await database.qb.drizzle.update(table).set(valuesU(row)).where(getWhereCondition(table, values)).returning().then((res) => res[0]);
|
|
6452
|
-
} catch (e) {
|
|
6453
|
-
throw parseSqlError(e);
|
|
6454
|
-
}
|
|
6455
|
-
}
|
|
6456
|
-
}
|
|
6457
|
-
}
|
|
6458
|
-
)
|
|
6459
|
-
),
|
|
6460
|
-
// biome-ignore lint/suspicious/noThenProperty: <explanation>
|
|
6461
|
-
then: (onFulfilled, onRejected) => queue.add(
|
|
6462
|
-
() => database.wrap(
|
|
6463
|
-
{
|
|
6464
|
-
method: `${getTableName3(table) ?? "unknown"}.insert()`
|
|
6465
|
-
},
|
|
6466
|
-
async () => {
|
|
6467
|
-
checkOnchainTable2(table, "insert");
|
|
6468
|
-
try {
|
|
6469
|
-
return await database.qb.drizzle.insert(table).values(values).returning().then(
|
|
6470
|
-
(res) => Array.isArray(values) ? res : res[0]
|
|
6471
|
-
);
|
|
6472
|
-
} catch (e) {
|
|
6473
|
-
throw parseSqlError(e);
|
|
6474
|
-
}
|
|
6475
|
-
}
|
|
6476
|
-
)
|
|
6477
|
-
).then(onFulfilled, onRejected),
|
|
6478
|
-
catch: (onRejected) => inner.then(void 0, onRejected),
|
|
6479
|
-
finally: (onFinally) => inner.then(
|
|
6480
|
-
(value) => {
|
|
6481
|
-
onFinally?.();
|
|
6482
|
-
return value;
|
|
6483
|
-
},
|
|
6484
|
-
(reason) => {
|
|
6485
|
-
onFinally?.();
|
|
6486
|
-
throw reason;
|
|
6487
|
-
}
|
|
6488
|
-
)
|
|
6489
|
-
// @ts-ignore
|
|
6490
|
-
};
|
|
6491
|
-
return inner;
|
|
6492
|
-
}
|
|
6493
|
-
};
|
|
6494
|
-
},
|
|
6495
|
-
// @ts-ignore
|
|
6496
|
-
update(table, key) {
|
|
6497
|
-
return {
|
|
6498
|
-
set: (values) => queue.add(
|
|
6499
|
-
() => database.wrap(
|
|
6500
|
-
{ method: `${getTableName3(table) ?? "unknown"}.update()` },
|
|
6501
|
-
async () => {
|
|
6502
|
-
checkOnchainTable2(table, "update");
|
|
6503
|
-
if (typeof values === "function") {
|
|
6504
|
-
const row = await find(table, key);
|
|
6505
|
-
if (row === null) {
|
|
6506
|
-
const error = new RecordNotFoundError(
|
|
6507
|
-
`No existing record found in table '${getTableName3(table)}'`
|
|
6508
|
-
);
|
|
6509
|
-
error.meta.push(
|
|
6510
|
-
`db.update arguments:
|
|
6511
|
-
${prettyPrint(key)}`
|
|
6512
|
-
);
|
|
6513
|
-
throw error;
|
|
6514
|
-
}
|
|
6515
|
-
try {
|
|
6516
|
-
return await database.qb.drizzle.update(table).set(values(row)).where(getWhereCondition(table, key)).returning().then((res) => res[0]);
|
|
6517
|
-
} catch (e) {
|
|
6518
|
-
throw parseSqlError(e);
|
|
6519
|
-
}
|
|
6520
|
-
} else {
|
|
6521
|
-
try {
|
|
6522
|
-
return await database.qb.drizzle.update(table).set(values).where(getWhereCondition(table, key)).returning().then((res) => res[0]);
|
|
6523
|
-
} catch (e) {
|
|
6524
|
-
throw parseSqlError(e);
|
|
6525
|
-
}
|
|
6526
|
-
}
|
|
6527
|
-
}
|
|
6528
|
-
)
|
|
6529
|
-
)
|
|
6530
|
-
};
|
|
6531
|
-
},
|
|
6532
|
-
// @ts-ignore
|
|
6533
|
-
delete: (table, key) => queue.add(
|
|
6534
|
-
() => database.wrap(
|
|
6535
|
-
{ method: `${getTableName3(table) ?? "unknown"}.delete()` },
|
|
6536
|
-
async () => {
|
|
6537
|
-
checkOnchainTable2(table, "delete");
|
|
6538
|
-
const deleted = await database.qb.drizzle.delete(table).where(getWhereCondition(table, key)).returning();
|
|
6539
|
-
return deleted.length > 0;
|
|
6540
|
-
}
|
|
6541
|
-
)
|
|
6542
|
-
),
|
|
6543
|
-
// @ts-ignore
|
|
6544
|
-
sql: drizzle2(
|
|
6545
|
-
(_sql, params, method, typings) => (
|
|
6546
|
-
// @ts-ignore
|
|
6547
|
-
queue.add(async () => {
|
|
6548
|
-
const query2 = { sql: _sql, params, typings };
|
|
6549
|
-
const res = await database.wrap({ method: "sql" }, async () => {
|
|
6550
|
-
try {
|
|
6551
|
-
return await database.qb.drizzle._.session.prepareQuery(query2, void 0, void 0, method === "all").execute();
|
|
6552
|
-
} catch (e) {
|
|
6553
|
-
throw parseSqlError(e);
|
|
6554
|
-
}
|
|
6555
|
-
});
|
|
6556
|
-
return { rows: res.rows.map((row) => Object.values(row)) };
|
|
6557
|
-
})
|
|
6558
|
-
),
|
|
6559
|
-
{ schema, casing: "snake_case" }
|
|
6560
|
-
)
|
|
6561
|
-
};
|
|
6562
|
-
return indexingStore;
|
|
6563
|
-
};
|
|
6564
|
-
|
|
6565
4946
|
// src/utils/extend.ts
|
|
6566
4947
|
var extend = (create2, _methods) => {
|
|
6567
4948
|
return (...params) => {
|
|
@@ -7528,7 +5909,7 @@ import {
|
|
|
7528
5909
|
} from "viem";
|
|
7529
5910
|
|
|
7530
5911
|
// src/sync-store/encoding.ts
|
|
7531
|
-
import { hexToBigInt as hexToBigInt3, hexToNumber as
|
|
5912
|
+
import { hexToBigInt as hexToBigInt3, hexToNumber as hexToNumber3 } from "viem";
|
|
7532
5913
|
var encodeBlock = ({
|
|
7533
5914
|
block,
|
|
7534
5915
|
chainId
|
|
@@ -7537,7 +5918,7 @@ var encodeBlock = ({
|
|
|
7537
5918
|
hash: block.hash,
|
|
7538
5919
|
chainId,
|
|
7539
5920
|
checkpoint: encodeCheckpoint({
|
|
7540
|
-
blockTimestamp:
|
|
5921
|
+
blockTimestamp: hexToNumber3(block.timestamp),
|
|
7541
5922
|
chainId: BigInt(chainId),
|
|
7542
5923
|
blockNumber: hexToBigInt3(block.number),
|
|
7543
5924
|
transactionIndex: MAX_CHECKPOINT.transactionIndex,
|
|
@@ -7573,7 +5954,7 @@ var encodeLog = ({
|
|
|
7573
5954
|
id: `${log.blockHash}-${log.logIndex}`,
|
|
7574
5955
|
chainId,
|
|
7575
5956
|
checkpoint: block === void 0 ? null : encodeCheckpoint({
|
|
7576
|
-
blockTimestamp:
|
|
5957
|
+
blockTimestamp: hexToNumber3(block.timestamp),
|
|
7577
5958
|
chainId: BigInt(chainId),
|
|
7578
5959
|
blockNumber: hexToBigInt3(log.blockNumber),
|
|
7579
5960
|
transactionIndex: hexToBigInt3(log.transactionIndex),
|
|
@@ -7582,9 +5963,9 @@ var encodeLog = ({
|
|
|
7582
5963
|
}),
|
|
7583
5964
|
blockHash: log.blockHash,
|
|
7584
5965
|
blockNumber: hexToBigInt3(log.blockNumber),
|
|
7585
|
-
logIndex:
|
|
5966
|
+
logIndex: hexToNumber3(log.logIndex),
|
|
7586
5967
|
transactionHash: log.transactionHash,
|
|
7587
|
-
transactionIndex:
|
|
5968
|
+
transactionIndex: hexToNumber3(log.transactionIndex),
|
|
7588
5969
|
address: toLowerCase(log.address),
|
|
7589
5970
|
topic0: log.topics[0] ? log.topics[0] : null,
|
|
7590
5971
|
topic1: log.topics[1] ? log.topics[1] : null,
|
|
@@ -7601,7 +5982,7 @@ var encodeTransaction = ({
|
|
|
7601
5982
|
return {
|
|
7602
5983
|
hash: transaction.hash,
|
|
7603
5984
|
checkpoint: encodeCheckpoint({
|
|
7604
|
-
blockTimestamp:
|
|
5985
|
+
blockTimestamp: hexToNumber3(block.timestamp),
|
|
7605
5986
|
chainId: BigInt(chainId),
|
|
7606
5987
|
blockNumber: hexToBigInt3(transaction.blockNumber),
|
|
7607
5988
|
transactionIndex: hexToBigInt3(transaction.transactionIndex),
|
|
@@ -7618,11 +5999,11 @@ var encodeTransaction = ({
|
|
|
7618
5999
|
input: transaction.input,
|
|
7619
6000
|
maxFeePerGas: transaction.maxFeePerGas ? hexToBigInt3(transaction.maxFeePerGas) : null,
|
|
7620
6001
|
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas ? hexToBigInt3(transaction.maxPriorityFeePerGas) : null,
|
|
7621
|
-
nonce:
|
|
6002
|
+
nonce: hexToNumber3(transaction.nonce),
|
|
7622
6003
|
r: transaction.r ?? null,
|
|
7623
6004
|
s: transaction.s ?? null,
|
|
7624
6005
|
to: transaction.to ? toLowerCase(transaction.to) : null,
|
|
7625
|
-
transactionIndex:
|
|
6006
|
+
transactionIndex: hexToNumber3(transaction.transactionIndex),
|
|
7626
6007
|
type: transaction.type ?? "0x0",
|
|
7627
6008
|
value: hexToBigInt3(transaction.value),
|
|
7628
6009
|
v: transaction.v ? hexToBigInt3(transaction.v) : null
|
|
@@ -7645,7 +6026,7 @@ var encodeTransactionReceipt = ({
|
|
|
7645
6026
|
logsBloom: transactionReceipt.logsBloom,
|
|
7646
6027
|
status: transactionReceipt.status,
|
|
7647
6028
|
to: transactionReceipt.to ? toLowerCase(transactionReceipt.to) : null,
|
|
7648
|
-
transactionIndex:
|
|
6029
|
+
transactionIndex: hexToNumber3(transactionReceipt.transactionIndex),
|
|
7649
6030
|
type: transactionReceipt.type
|
|
7650
6031
|
};
|
|
7651
6032
|
};
|
|
@@ -7659,7 +6040,7 @@ function encodeTrace({
|
|
|
7659
6040
|
id: `${transaction.hash}-${trace.index}`,
|
|
7660
6041
|
chainId,
|
|
7661
6042
|
checkpoint: encodeCheckpoint({
|
|
7662
|
-
blockTimestamp:
|
|
6043
|
+
blockTimestamp: hexToNumber3(block.timestamp),
|
|
7663
6044
|
chainId: BigInt(chainId),
|
|
7664
6045
|
blockNumber: hexToBigInt3(block.number),
|
|
7665
6046
|
transactionIndex: hexToBigInt3(transaction.transactionIndex),
|
|
@@ -8346,7 +6727,7 @@ import {
|
|
|
8346
6727
|
decodeFunctionData,
|
|
8347
6728
|
decodeFunctionResult,
|
|
8348
6729
|
hexToBigInt as hexToBigInt5,
|
|
8349
|
-
hexToNumber as
|
|
6730
|
+
hexToNumber as hexToNumber4
|
|
8350
6731
|
} from "viem";
|
|
8351
6732
|
var buildEvents = ({
|
|
8352
6733
|
sources,
|
|
@@ -8388,7 +6769,7 @@ var buildEvents = ({
|
|
|
8388
6769
|
chainId: filter.chainId,
|
|
8389
6770
|
sourceIndex: i,
|
|
8390
6771
|
checkpoint: encodeCheckpoint({
|
|
8391
|
-
blockTimestamp:
|
|
6772
|
+
blockTimestamp: hexToNumber4(block.timestamp),
|
|
8392
6773
|
chainId: BigInt(filter.chainId),
|
|
8393
6774
|
blockNumber: hexToBigInt5(log.blockNumber),
|
|
8394
6775
|
transactionIndex: hexToBigInt5(log.transactionIndex),
|
|
@@ -8436,7 +6817,7 @@ var buildEvents = ({
|
|
|
8436
6817
|
chainId: filter.chainId,
|
|
8437
6818
|
sourceIndex: i,
|
|
8438
6819
|
checkpoint: encodeCheckpoint({
|
|
8439
|
-
blockTimestamp:
|
|
6820
|
+
blockTimestamp: hexToNumber4(block.timestamp),
|
|
8440
6821
|
chainId: BigInt(filter.chainId),
|
|
8441
6822
|
blockNumber: hexToBigInt5(block.number),
|
|
8442
6823
|
transactionIndex: BigInt(transaction.transactionIndex),
|
|
@@ -8479,7 +6860,7 @@ var buildEvents = ({
|
|
|
8479
6860
|
chainId: filter.chainId,
|
|
8480
6861
|
sourceIndex: i,
|
|
8481
6862
|
checkpoint: encodeCheckpoint({
|
|
8482
|
-
blockTimestamp:
|
|
6863
|
+
blockTimestamp: hexToNumber4(block.timestamp),
|
|
8483
6864
|
chainId: BigInt(filter.chainId),
|
|
8484
6865
|
blockNumber: hexToBigInt5(block.number),
|
|
8485
6866
|
transactionIndex: BigInt(transaction.transactionIndex),
|
|
@@ -8525,7 +6906,7 @@ var buildEvents = ({
|
|
|
8525
6906
|
chainId: filter.chainId,
|
|
8526
6907
|
sourceIndex: i,
|
|
8527
6908
|
checkpoint: encodeCheckpoint({
|
|
8528
|
-
blockTimestamp:
|
|
6909
|
+
blockTimestamp: hexToNumber4(block.timestamp),
|
|
8529
6910
|
chainId: BigInt(filter.chainId),
|
|
8530
6911
|
blockNumber: hexToBigInt5(block.number),
|
|
8531
6912
|
transactionIndex: BigInt(transaction.transactionIndex),
|
|
@@ -8551,7 +6932,7 @@ var buildEvents = ({
|
|
|
8551
6932
|
chainId: filter.chainId,
|
|
8552
6933
|
sourceIndex: i,
|
|
8553
6934
|
checkpoint: encodeCheckpoint({
|
|
8554
|
-
blockTimestamp:
|
|
6935
|
+
blockTimestamp: hexToNumber4(block.timestamp),
|
|
8555
6936
|
chainId: BigInt(filter.chainId),
|
|
8556
6937
|
blockNumber: hexToBigInt5(block.number),
|
|
8557
6938
|
transactionIndex: MAX_CHECKPOINT.transactionIndex,
|
|
@@ -9020,7 +7401,7 @@ function intervalRange(interval) {
|
|
|
9020
7401
|
|
|
9021
7402
|
// src/utils/rpc.ts
|
|
9022
7403
|
import {
|
|
9023
|
-
BlockNotFoundError,
|
|
7404
|
+
BlockNotFoundError as BlockNotFoundError2,
|
|
9024
7405
|
TransactionReceiptNotFoundError,
|
|
9025
7406
|
numberToHex
|
|
9026
7407
|
} from "viem";
|
|
@@ -9035,7 +7416,7 @@ var _eth_getBlockByNumber = (requestQueue, {
|
|
|
9035
7416
|
]
|
|
9036
7417
|
}).then((_block) => {
|
|
9037
7418
|
if (!_block)
|
|
9038
|
-
throw new
|
|
7419
|
+
throw new BlockNotFoundError2({
|
|
9039
7420
|
blockNumber: blockNumber ?? blockTag
|
|
9040
7421
|
});
|
|
9041
7422
|
return _block;
|
|
@@ -9045,7 +7426,7 @@ var _eth_getBlockByHash = (requestQueue, { hash }) => requestQueue.request({
|
|
|
9045
7426
|
params: [hash, true]
|
|
9046
7427
|
}).then((_block) => {
|
|
9047
7428
|
if (!_block)
|
|
9048
|
-
throw new
|
|
7429
|
+
throw new BlockNotFoundError2({
|
|
9049
7430
|
blockHash: hash
|
|
9050
7431
|
});
|
|
9051
7432
|
return _block;
|
|
@@ -9171,7 +7552,7 @@ var _debug_traceBlockByHash = (requestQueue, {
|
|
|
9171
7552
|
import { getLogsRetryHelper } from "@ponder/utils";
|
|
9172
7553
|
import {
|
|
9173
7554
|
hexToBigInt as hexToBigInt6,
|
|
9174
|
-
hexToNumber as
|
|
7555
|
+
hexToNumber as hexToNumber5,
|
|
9175
7556
|
toHex,
|
|
9176
7557
|
zeroHash
|
|
9177
7558
|
} from "viem";
|
|
@@ -9258,7 +7639,7 @@ var createHistoricalSync = async (args) => {
|
|
|
9258
7639
|
});
|
|
9259
7640
|
if (getLogsErrorResponse.shouldRetry === false)
|
|
9260
7641
|
throw error;
|
|
9261
|
-
const range2 =
|
|
7642
|
+
const range2 = hexToNumber5(getLogsErrorResponse.ranges[0].toBlock) - hexToNumber5(getLogsErrorResponse.ranges[0].fromBlock);
|
|
9262
7643
|
args.common.logger.debug({
|
|
9263
7644
|
service: "sync",
|
|
9264
7645
|
msg: `Caught eth_getLogs error on '${args.network.name}', updating recommended range to ${range2}.`
|
|
@@ -9407,7 +7788,7 @@ var createHistoricalSync = async (args) => {
|
|
|
9407
7788
|
const address = isAddressFactory(filter.address) ? await syncAddressFactory(filter.address, interval) : filter.address;
|
|
9408
7789
|
const logs = await syncLogsDynamic({ filter, interval, address });
|
|
9409
7790
|
const blocks = await Promise.all(
|
|
9410
|
-
logs.map((log) => syncBlock(
|
|
7791
|
+
logs.map((log) => syncBlock(hexToNumber5(log.blockNumber)))
|
|
9411
7792
|
);
|
|
9412
7793
|
const requiredBlocks = new Set(blocks.map((b) => b.hash));
|
|
9413
7794
|
for (let i = 0; i < logs.length; i++) {
|
|
@@ -9422,7 +7803,7 @@ var createHistoricalSync = async (args) => {
|
|
|
9422
7803
|
if (log.transactionHash === zeroHash) {
|
|
9423
7804
|
args.common.logger.warn({
|
|
9424
7805
|
service: "sync",
|
|
9425
|
-
msg: `Detected log with empty transaction hash in block ${block.hash} at log index ${
|
|
7806
|
+
msg: `Detected log with empty transaction hash in block ${block.hash} at log index ${hexToNumber5(log.logIndex)}. This is expected for some networks like ZKsync.`
|
|
9426
7807
|
});
|
|
9427
7808
|
} else {
|
|
9428
7809
|
throw new Error(
|
|
@@ -9449,7 +7830,7 @@ var createHistoricalSync = async (args) => {
|
|
|
9449
7830
|
if (log.transactionHash === zeroHash) {
|
|
9450
7831
|
args.common.logger.warn({
|
|
9451
7832
|
service: "sync",
|
|
9452
|
-
msg: `Detected log with empty transaction hash in block ${log.blockHash} at log index ${
|
|
7833
|
+
msg: `Detected log with empty transaction hash in block ${log.blockHash} at log index ${hexToNumber5(log.logIndex)}. This is expected for some networks like ZKsync.`
|
|
9453
7834
|
});
|
|
9454
7835
|
} else {
|
|
9455
7836
|
blockTransactionHashes.add(log.transactionHash);
|
|
@@ -9715,10 +8096,10 @@ var createMutex = () => {
|
|
|
9715
8096
|
};
|
|
9716
8097
|
|
|
9717
8098
|
// src/sync-realtime/index.ts
|
|
9718
|
-
import { hexToNumber as
|
|
8099
|
+
import { hexToNumber as hexToNumber7, zeroHash as zeroHash2 } from "viem";
|
|
9719
8100
|
|
|
9720
8101
|
// src/sync-realtime/bloom.ts
|
|
9721
|
-
import { hexToBytes, hexToNumber as
|
|
8102
|
+
import { hexToBytes, hexToNumber as hexToNumber6, keccak256 } from "viem";
|
|
9722
8103
|
var zeroLogsBloom = "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
|
|
9723
8104
|
var BLOOM_SIZE_BYTES = 256;
|
|
9724
8105
|
var isInBloom = (_bloom, input) => {
|
|
@@ -9735,7 +8116,7 @@ function isFilterInBloom({
|
|
|
9735
8116
|
block,
|
|
9736
8117
|
filter
|
|
9737
8118
|
}) {
|
|
9738
|
-
if (
|
|
8119
|
+
if (hexToNumber6(block.number) < (filter.fromBlock ?? 0) || hexToNumber6(block.number) > (filter.toBlock ?? Number.POSITIVE_INFINITY)) {
|
|
9739
8120
|
return false;
|
|
9740
8121
|
}
|
|
9741
8122
|
const isTopicsInBloom = [
|
|
@@ -9861,7 +8242,7 @@ var createRealtimeSync = (args) => {
|
|
|
9861
8242
|
}) => {
|
|
9862
8243
|
args.common.logger.debug({
|
|
9863
8244
|
service: "realtime",
|
|
9864
|
-
msg: `Started syncing '${args.network.name}' block ${
|
|
8245
|
+
msg: `Started syncing '${args.network.name}' block ${hexToNumber7(block.number)}`
|
|
9865
8246
|
});
|
|
9866
8247
|
for (const log of factoryLogs) {
|
|
9867
8248
|
for (const filter of factories) {
|
|
@@ -9996,12 +8377,12 @@ var createRealtimeSync = (args) => {
|
|
|
9996
8377
|
const text = _text.filter((t) => t !== void 0).join(" and ");
|
|
9997
8378
|
args.common.logger.info({
|
|
9998
8379
|
service: "realtime",
|
|
9999
|
-
msg: `Synced ${text} from '${args.network.name}' block ${
|
|
8380
|
+
msg: `Synced ${text} from '${args.network.name}' block ${hexToNumber7(block.number)}`
|
|
10000
8381
|
});
|
|
10001
8382
|
} else {
|
|
10002
8383
|
args.common.logger.info({
|
|
10003
8384
|
service: "realtime",
|
|
10004
|
-
msg: `Synced block ${
|
|
8385
|
+
msg: `Synced block ${hexToNumber7(block.number)} from '${args.network.name}' `
|
|
10005
8386
|
});
|
|
10006
8387
|
}
|
|
10007
8388
|
unfinalizedBlocks.push(syncBlockToLightBlock(block));
|
|
@@ -10017,20 +8398,20 @@ var createRealtimeSync = (args) => {
|
|
|
10017
8398
|
transactionReceipts,
|
|
10018
8399
|
endClock
|
|
10019
8400
|
});
|
|
10020
|
-
const blockMovesFinality =
|
|
8401
|
+
const blockMovesFinality = hexToNumber7(block.number) >= hexToNumber7(finalizedBlock.number) + 2 * args.network.finalityBlockCount;
|
|
10021
8402
|
if (blockMovesFinality) {
|
|
10022
8403
|
const pendingFinalizedBlock = unfinalizedBlocks.find(
|
|
10023
|
-
(lb) =>
|
|
8404
|
+
(lb) => hexToNumber7(lb.number) === hexToNumber7(block.number) - args.network.finalityBlockCount
|
|
10024
8405
|
);
|
|
10025
8406
|
args.common.logger.debug({
|
|
10026
8407
|
service: "realtime",
|
|
10027
|
-
msg: `Finalized ${
|
|
8408
|
+
msg: `Finalized ${hexToNumber7(pendingFinalizedBlock.number) - hexToNumber7(finalizedBlock.number) + 1} '${args.network.name}' blocks [${hexToNumber7(finalizedBlock.number) + 1}, ${hexToNumber7(pendingFinalizedBlock.number)}]`
|
|
10028
8409
|
});
|
|
10029
8410
|
const finalizedBlocks = unfinalizedBlocks.filter(
|
|
10030
|
-
(lb) =>
|
|
8411
|
+
(lb) => hexToNumber7(lb.number) <= hexToNumber7(pendingFinalizedBlock.number)
|
|
10031
8412
|
);
|
|
10032
8413
|
unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
10033
|
-
(lb) =>
|
|
8414
|
+
(lb) => hexToNumber7(lb.number) > hexToNumber7(pendingFinalizedBlock.number)
|
|
10034
8415
|
);
|
|
10035
8416
|
for (const filter of factories) {
|
|
10036
8417
|
for (const { hash } of finalizedBlocks) {
|
|
@@ -10068,13 +8449,13 @@ var createRealtimeSync = (args) => {
|
|
|
10068
8449
|
const handleReorg = async (block) => {
|
|
10069
8450
|
args.common.logger.warn({
|
|
10070
8451
|
service: "realtime",
|
|
10071
|
-
msg: `Detected forked '${args.network.name}' block at height ${
|
|
8452
|
+
msg: `Detected forked '${args.network.name}' block at height ${hexToNumber7(block.number)}`
|
|
10072
8453
|
});
|
|
10073
8454
|
const reorgedBlocks = unfinalizedBlocks.filter(
|
|
10074
|
-
(lb) =>
|
|
8455
|
+
(lb) => hexToNumber7(lb.number) >= hexToNumber7(block.number)
|
|
10075
8456
|
);
|
|
10076
8457
|
unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
10077
|
-
(lb) =>
|
|
8458
|
+
(lb) => hexToNumber7(lb.number) < hexToNumber7(block.number)
|
|
10078
8459
|
);
|
|
10079
8460
|
let remoteBlock = block;
|
|
10080
8461
|
while (true) {
|
|
@@ -10082,7 +8463,7 @@ var createRealtimeSync = (args) => {
|
|
|
10082
8463
|
if (parentBlock.hash === remoteBlock.parentHash)
|
|
10083
8464
|
break;
|
|
10084
8465
|
if (unfinalizedBlocks.length === 0) {
|
|
10085
|
-
const msg = `Encountered unrecoverable '${args.network.name}' reorg beyond finalized block ${
|
|
8466
|
+
const msg = `Encountered unrecoverable '${args.network.name}' reorg beyond finalized block ${hexToNumber7(finalizedBlock.number)}`;
|
|
10086
8467
|
args.common.logger.warn({ service: "realtime", msg });
|
|
10087
8468
|
throw new Error(msg);
|
|
10088
8469
|
} else {
|
|
@@ -10096,7 +8477,7 @@ var createRealtimeSync = (args) => {
|
|
|
10096
8477
|
await args.onEvent({ type: "reorg", block: commonAncestor, reorgedBlocks });
|
|
10097
8478
|
args.common.logger.warn({
|
|
10098
8479
|
service: "realtime",
|
|
10099
|
-
msg: `Reconciled ${reorgedBlocks.length}-block '${args.network.name}' reorg with common ancestor block ${
|
|
8480
|
+
msg: `Reconciled ${reorgedBlocks.length}-block '${args.network.name}' reorg with common ancestor block ${hexToNumber7(commonAncestor.number)}`
|
|
10100
8481
|
});
|
|
10101
8482
|
unfinalizedChildAddresses.clear();
|
|
10102
8483
|
for (const filter of factories) {
|
|
@@ -10188,7 +8569,7 @@ var createRealtimeSync = (args) => {
|
|
|
10188
8569
|
if (log.transactionHash === zeroHash2) {
|
|
10189
8570
|
args.common.logger.warn({
|
|
10190
8571
|
service: "sync",
|
|
10191
|
-
msg: `Detected '${args.network.name}' log with empty transaction hash in block ${block.hash} at log index ${
|
|
8572
|
+
msg: `Detected '${args.network.name}' log with empty transaction hash in block ${block.hash} at log index ${hexToNumber7(log.logIndex)}. This is expected for some networks like ZKsync.`
|
|
10192
8573
|
});
|
|
10193
8574
|
} else {
|
|
10194
8575
|
throw new Error(
|
|
@@ -10201,7 +8582,7 @@ var createRealtimeSync = (args) => {
|
|
|
10201
8582
|
if (shouldRequestLogs === false && args.sources.some((s) => s.filter.type === "log")) {
|
|
10202
8583
|
args.common.logger.debug({
|
|
10203
8584
|
service: "realtime",
|
|
10204
|
-
msg: `Skipped fetching '${args.network.name}' logs for block ${
|
|
8585
|
+
msg: `Skipped fetching '${args.network.name}' logs for block ${hexToNumber7(block.number)} due to bloom filter result`
|
|
10205
8586
|
});
|
|
10206
8587
|
}
|
|
10207
8588
|
const shouldRequestTraces = traceFilters.length > 0 || transferFilters.length > 0;
|
|
@@ -10246,7 +8627,7 @@ var createRealtimeSync = (args) => {
|
|
|
10246
8627
|
if (log.transactionHash === zeroHash2) {
|
|
10247
8628
|
args.common.logger.warn({
|
|
10248
8629
|
service: "sync",
|
|
10249
|
-
msg: `Detected '${args.network.name}' log with empty transaction hash in block ${block.hash} at log index ${
|
|
8630
|
+
msg: `Detected '${args.network.name}' log with empty transaction hash in block ${block.hash} at log index ${hexToNumber7(log.logIndex)}. This is expected for some networks like ZKsync.`
|
|
10250
8631
|
});
|
|
10251
8632
|
} else {
|
|
10252
8633
|
requiredTransactions.add(log.transactionHash);
|
|
@@ -10344,22 +8725,22 @@ var createRealtimeSync = (args) => {
|
|
|
10344
8725
|
if (latestBlock.hash === block.hash) {
|
|
10345
8726
|
args.common.logger.trace({
|
|
10346
8727
|
service: "realtime",
|
|
10347
|
-
msg: `Skipped processing '${args.network.name}' block ${
|
|
8728
|
+
msg: `Skipped processing '${args.network.name}' block ${hexToNumber7(block.number)}, already synced`
|
|
10348
8729
|
});
|
|
10349
8730
|
return;
|
|
10350
8731
|
}
|
|
10351
8732
|
try {
|
|
10352
|
-
if (
|
|
8733
|
+
if (hexToNumber7(latestBlock.number) >= hexToNumber7(block.number)) {
|
|
10353
8734
|
await handleReorg(block);
|
|
10354
8735
|
processBlock.clear();
|
|
10355
8736
|
return;
|
|
10356
8737
|
}
|
|
10357
|
-
if (
|
|
8738
|
+
if (hexToNumber7(latestBlock.number) + 1 < hexToNumber7(block.number)) {
|
|
10358
8739
|
const missingBlockRange = range(
|
|
10359
|
-
|
|
8740
|
+
hexToNumber7(latestBlock.number) + 1,
|
|
10360
8741
|
Math.min(
|
|
10361
|
-
|
|
10362
|
-
|
|
8742
|
+
hexToNumber7(block.number),
|
|
8743
|
+
hexToNumber7(latestBlock.number) + MAX_QUEUED_BLOCKS
|
|
10363
8744
|
)
|
|
10364
8745
|
);
|
|
10365
8746
|
const pendingBlocks = await Promise.all(
|
|
@@ -10371,9 +8752,9 @@ var createRealtimeSync = (args) => {
|
|
|
10371
8752
|
);
|
|
10372
8753
|
args.common.logger.debug({
|
|
10373
8754
|
service: "realtime",
|
|
10374
|
-
msg: `Fetched ${missingBlockRange.length} missing '${args.network.name}' blocks [${
|
|
10375
|
-
|
|
10376
|
-
|
|
8755
|
+
msg: `Fetched ${missingBlockRange.length} missing '${args.network.name}' blocks [${hexToNumber7(latestBlock.number) + 1}, ${Math.min(
|
|
8756
|
+
hexToNumber7(block.number),
|
|
8757
|
+
hexToNumber7(latestBlock.number) + MAX_QUEUED_BLOCKS
|
|
10377
8758
|
)}]`
|
|
10378
8759
|
});
|
|
10379
8760
|
processBlock.clear();
|
|
@@ -10398,7 +8779,7 @@ var createRealtimeSync = (args) => {
|
|
|
10398
8779
|
}
|
|
10399
8780
|
args.common.logger.warn({
|
|
10400
8781
|
service: "realtime",
|
|
10401
|
-
msg: `Failed to process '${args.network.name}' block ${
|
|
8782
|
+
msg: `Failed to process '${args.network.name}' block ${hexToNumber7(block.number)}`,
|
|
10402
8783
|
error
|
|
10403
8784
|
});
|
|
10404
8785
|
const duration = ERROR_TIMEOUT[consecutiveErrors];
|
|
@@ -10411,7 +8792,7 @@ var createRealtimeSync = (args) => {
|
|
|
10411
8792
|
if (++consecutiveErrors === ERROR_TIMEOUT.length) {
|
|
10412
8793
|
args.common.logger.error({
|
|
10413
8794
|
service: "realtime",
|
|
10414
|
-
msg: `Fatal error: Unable to process '${args.network.name}' block ${
|
|
8795
|
+
msg: `Fatal error: Unable to process '${args.network.name}' block ${hexToNumber7(block.number)} after ${ERROR_TIMEOUT.length} attempts.`,
|
|
10415
8796
|
error
|
|
10416
8797
|
});
|
|
10417
8798
|
args.onFatalError(error);
|
|
@@ -10426,13 +8807,13 @@ var createRealtimeSync = (args) => {
|
|
|
10426
8807
|
});
|
|
10427
8808
|
args.common.logger.debug({
|
|
10428
8809
|
service: "realtime",
|
|
10429
|
-
msg: `Received latest '${args.network.name}' block ${
|
|
8810
|
+
msg: `Received latest '${args.network.name}' block ${hexToNumber7(block.number)}`
|
|
10430
8811
|
});
|
|
10431
8812
|
const latestBlock = getLatestUnfinalizedBlock();
|
|
10432
8813
|
if (latestBlock.hash === block.hash) {
|
|
10433
8814
|
args.common.logger.trace({
|
|
10434
8815
|
service: "realtime",
|
|
10435
|
-
msg: `Skipped processing '${args.network.name}' block ${
|
|
8816
|
+
msg: `Skipped processing '${args.network.name}' block ${hexToNumber7(block.number)}, already synced`
|
|
10436
8817
|
});
|
|
10437
8818
|
return;
|
|
10438
8819
|
}
|
|
@@ -10601,7 +8982,7 @@ var zipperMany = (arrays, compare) => {
|
|
|
10601
8982
|
};
|
|
10602
8983
|
|
|
10603
8984
|
// src/sync/index.ts
|
|
10604
|
-
import { hexToBigInt as hexToBigInt7, hexToNumber as
|
|
8985
|
+
import { hexToBigInt as hexToBigInt7, hexToNumber as hexToNumber8, toHex as toHex2 } from "viem";
|
|
10605
8986
|
var syncBlockToLightBlock = ({
|
|
10606
8987
|
hash,
|
|
10607
8988
|
parentHash,
|
|
@@ -10616,7 +8997,7 @@ var syncBlockToLightBlock = ({
|
|
|
10616
8997
|
var blockToCheckpoint = (block, chainId, rounding) => {
|
|
10617
8998
|
return {
|
|
10618
8999
|
...rounding === "up" ? MAX_CHECKPOINT : ZERO_CHECKPOINT,
|
|
10619
|
-
blockTimestamp:
|
|
9000
|
+
blockTimestamp: hexToNumber8(block.timestamp),
|
|
10620
9001
|
chainId: BigInt(chainId),
|
|
10621
9002
|
blockNumber: hexToBigInt7(block.number)
|
|
10622
9003
|
};
|
|
@@ -10625,16 +9006,16 @@ var isSyncEnd = (syncProgress) => {
|
|
|
10625
9006
|
if (syncProgress.end === void 0 || syncProgress.current === void 0) {
|
|
10626
9007
|
return false;
|
|
10627
9008
|
}
|
|
10628
|
-
return
|
|
9009
|
+
return hexToNumber8(syncProgress.current.number) >= hexToNumber8(syncProgress.end.number);
|
|
10629
9010
|
};
|
|
10630
9011
|
var isSyncFinalized = (syncProgress) => {
|
|
10631
9012
|
if (syncProgress.current === void 0) {
|
|
10632
9013
|
return false;
|
|
10633
9014
|
}
|
|
10634
|
-
return
|
|
9015
|
+
return hexToNumber8(syncProgress.current.number) >= hexToNumber8(syncProgress.finalized.number);
|
|
10635
9016
|
};
|
|
10636
9017
|
var getHistoricalLast = (syncProgress) => {
|
|
10637
|
-
return syncProgress.end === void 0 ? syncProgress.finalized :
|
|
9018
|
+
return syncProgress.end === void 0 ? syncProgress.finalized : hexToNumber8(syncProgress.end.number) > hexToNumber8(syncProgress.finalized.number) ? syncProgress.finalized : syncProgress.end;
|
|
10638
9019
|
};
|
|
10639
9020
|
var splitEvents = (events) => {
|
|
10640
9021
|
let hash;
|
|
@@ -10735,8 +9116,8 @@ var createSync = async (params) => {
|
|
|
10735
9116
|
);
|
|
10736
9117
|
if (localBlock !== void 0) {
|
|
10737
9118
|
status[network.name].block = {
|
|
10738
|
-
timestamp:
|
|
10739
|
-
number:
|
|
9119
|
+
timestamp: hexToNumber8(localBlock.timestamp),
|
|
9120
|
+
number: hexToNumber8(localBlock.number)
|
|
10740
9121
|
};
|
|
10741
9122
|
}
|
|
10742
9123
|
};
|
|
@@ -10820,7 +9201,7 @@ var createSync = async (params) => {
|
|
|
10820
9201
|
});
|
|
10821
9202
|
params.common.logger.debug({
|
|
10822
9203
|
service: "sync",
|
|
10823
|
-
msg: `Extracted ${events.length} '${network.name}' events for block ${
|
|
9204
|
+
msg: `Extracted ${events.length} '${network.name}' events for block ${hexToNumber8(event.block.number)}`
|
|
10824
9205
|
});
|
|
10825
9206
|
if (params.ordering === "multichain") {
|
|
10826
9207
|
const checkpoint = getMultichainCheckpoint({
|
|
@@ -10828,15 +9209,15 @@ var createSync = async (params) => {
|
|
|
10828
9209
|
network
|
|
10829
9210
|
});
|
|
10830
9211
|
status[network.name].block = {
|
|
10831
|
-
timestamp:
|
|
10832
|
-
number:
|
|
9212
|
+
timestamp: hexToNumber8(event.block.timestamp),
|
|
9213
|
+
number: hexToNumber8(event.block.number)
|
|
10833
9214
|
};
|
|
10834
9215
|
const readyEvents = events.concat(pendingEvents);
|
|
10835
9216
|
pendingEvents = [];
|
|
10836
9217
|
executedEvents = executedEvents.concat(readyEvents);
|
|
10837
9218
|
params.common.logger.debug({
|
|
10838
9219
|
service: "sync",
|
|
10839
|
-
msg: `Sequenced ${readyEvents.length} '${network.name}' events for block ${
|
|
9220
|
+
msg: `Sequenced ${readyEvents.length} '${network.name}' events for block ${hexToNumber8(event.block.number)}`
|
|
10840
9221
|
});
|
|
10841
9222
|
params.onRealtimeEvent({
|
|
10842
9223
|
type: "block",
|
|
@@ -10930,7 +9311,7 @@ var createSync = async (params) => {
|
|
|
10930
9311
|
case "reorg": {
|
|
10931
9312
|
let reorgedEvents = 0;
|
|
10932
9313
|
const isReorgedEvent = ({ chainId, block }) => {
|
|
10933
|
-
if (chainId === network.chainId && Number(block.number) >
|
|
9314
|
+
if (chainId === network.chainId && Number(block.number) > hexToNumber8(event.block.number)) {
|
|
10934
9315
|
reorgedEvents++;
|
|
10935
9316
|
return true;
|
|
10936
9317
|
}
|
|
@@ -11041,7 +9422,7 @@ var createSync = async (params) => {
|
|
|
11041
9422
|
);
|
|
11042
9423
|
params.common.logger.info({
|
|
11043
9424
|
service: "sync",
|
|
11044
|
-
msg: `Killing '${network.name}' live indexing because the end block ${
|
|
9425
|
+
msg: `Killing '${network.name}' live indexing because the end block ${hexToNumber8(syncProgress.end.number)} has been finalized`
|
|
11045
9426
|
});
|
|
11046
9427
|
realtimeSync.kill();
|
|
11047
9428
|
}
|
|
@@ -11119,8 +9500,8 @@ var createSync = async (params) => {
|
|
|
11119
9500
|
const { syncProgress, realtimeSync } = perNetworkSync.get(network);
|
|
11120
9501
|
const filters = params.indexingBuild.sources.filter(({ filter }) => filter.chainId === network.chainId).map(({ filter }) => filter);
|
|
11121
9502
|
status[network.name].block = {
|
|
11122
|
-
number:
|
|
11123
|
-
timestamp:
|
|
9503
|
+
number: hexToNumber8(syncProgress.current.number),
|
|
9504
|
+
timestamp: hexToNumber8(syncProgress.current.timestamp)
|
|
11124
9505
|
};
|
|
11125
9506
|
status[network.name].ready = true;
|
|
11126
9507
|
const from = getOmnichainCheckpoint({ tag: "finalized" });
|
|
@@ -11223,30 +9604,30 @@ var getPerChainOnRealtimeSyncEvent = ({
|
|
|
11223
9604
|
syncProgress.current = event.block;
|
|
11224
9605
|
common.logger.debug({
|
|
11225
9606
|
service: "sync",
|
|
11226
|
-
msg: `Updated '${network.name}' current block to ${
|
|
9607
|
+
msg: `Updated '${network.name}' current block to ${hexToNumber8(event.block.number)}`
|
|
11227
9608
|
});
|
|
11228
9609
|
common.metrics.ponder_sync_block.set(
|
|
11229
9610
|
{ network: network.name },
|
|
11230
|
-
|
|
9611
|
+
hexToNumber8(syncProgress.current.number)
|
|
11231
9612
|
);
|
|
11232
9613
|
unfinalizedBlocks.push(event);
|
|
11233
9614
|
return event;
|
|
11234
9615
|
}
|
|
11235
9616
|
case "finalize": {
|
|
11236
9617
|
const finalizedInterval = [
|
|
11237
|
-
|
|
11238
|
-
|
|
9618
|
+
hexToNumber8(syncProgress.finalized.number),
|
|
9619
|
+
hexToNumber8(event.block.number)
|
|
11239
9620
|
];
|
|
11240
9621
|
syncProgress.finalized = event.block;
|
|
11241
9622
|
common.logger.debug({
|
|
11242
9623
|
service: "sync",
|
|
11243
|
-
msg: `Updated '${network.name}' finalized block to ${
|
|
9624
|
+
msg: `Updated '${network.name}' finalized block to ${hexToNumber8(event.block.number)}`
|
|
11244
9625
|
});
|
|
11245
9626
|
const finalizedBlocks = unfinalizedBlocks.filter(
|
|
11246
|
-
({ block }) =>
|
|
9627
|
+
({ block }) => hexToNumber8(block.number) <= hexToNumber8(event.block.number)
|
|
11247
9628
|
);
|
|
11248
9629
|
unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
11249
|
-
({ block }) =>
|
|
9630
|
+
({ block }) => hexToNumber8(block.number) > hexToNumber8(event.block.number)
|
|
11250
9631
|
);
|
|
11251
9632
|
await Promise.all([
|
|
11252
9633
|
syncStore.insertBlocks({
|
|
@@ -11322,14 +9703,14 @@ var getPerChainOnRealtimeSyncEvent = ({
|
|
|
11322
9703
|
syncProgress.current = event.block;
|
|
11323
9704
|
common.logger.debug({
|
|
11324
9705
|
service: "sync",
|
|
11325
|
-
msg: `Updated '${network.name}' current block to ${
|
|
9706
|
+
msg: `Updated '${network.name}' current block to ${hexToNumber8(event.block.number)}`
|
|
11326
9707
|
});
|
|
11327
9708
|
common.metrics.ponder_sync_block.set(
|
|
11328
9709
|
{ network: network.name },
|
|
11329
|
-
|
|
9710
|
+
hexToNumber8(syncProgress.current.number)
|
|
11330
9711
|
);
|
|
11331
9712
|
unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
11332
|
-
({ block }) =>
|
|
9713
|
+
({ block }) => hexToNumber8(block.number) <= hexToNumber8(event.block.number)
|
|
11333
9714
|
);
|
|
11334
9715
|
await syncStore.pruneRpcRequestResult({
|
|
11335
9716
|
chainId: network.chainId,
|
|
@@ -11414,10 +9795,10 @@ async function* getLocalSyncGenerator({
|
|
|
11414
9795
|
historicalSync
|
|
11415
9796
|
}) {
|
|
11416
9797
|
const label = { network: network.name };
|
|
11417
|
-
let cursor =
|
|
9798
|
+
let cursor = hexToNumber8(syncProgress.start.number);
|
|
11418
9799
|
const last = getHistoricalLast(syncProgress);
|
|
11419
9800
|
let estimateRange = 25;
|
|
11420
|
-
if (
|
|
9801
|
+
if (hexToNumber8(syncProgress.start.number) > hexToNumber8(syncProgress.finalized.number)) {
|
|
11421
9802
|
syncProgress.current = syncProgress.finalized;
|
|
11422
9803
|
common.logger.warn({
|
|
11423
9804
|
service: "sync",
|
|
@@ -11425,15 +9806,15 @@ async function* getLocalSyncGenerator({
|
|
|
11425
9806
|
});
|
|
11426
9807
|
common.metrics.ponder_sync_block.set(
|
|
11427
9808
|
label,
|
|
11428
|
-
|
|
9809
|
+
hexToNumber8(syncProgress.current.number)
|
|
11429
9810
|
);
|
|
11430
9811
|
common.metrics.ponder_historical_total_blocks.set(label, 0);
|
|
11431
9812
|
common.metrics.ponder_historical_cached_blocks.set(label, 0);
|
|
11432
9813
|
return;
|
|
11433
9814
|
}
|
|
11434
9815
|
const totalInterval = [
|
|
11435
|
-
|
|
11436
|
-
|
|
9816
|
+
hexToNumber8(syncProgress.start.number),
|
|
9817
|
+
hexToNumber8(last.number)
|
|
11437
9818
|
];
|
|
11438
9819
|
common.logger.debug({
|
|
11439
9820
|
service: "sync",
|
|
@@ -11464,12 +9845,12 @@ async function* getLocalSyncGenerator({
|
|
|
11464
9845
|
if (syncProgress.current !== void 0) {
|
|
11465
9846
|
common.metrics.ponder_sync_block.set(
|
|
11466
9847
|
label,
|
|
11467
|
-
|
|
9848
|
+
hexToNumber8(syncProgress.current.number)
|
|
11468
9849
|
);
|
|
11469
9850
|
yield encodeCheckpoint(
|
|
11470
9851
|
blockToCheckpoint(syncProgress.current, network.chainId, "up")
|
|
11471
9852
|
);
|
|
11472
|
-
if (
|
|
9853
|
+
if (hexToNumber8(syncProgress.current.number) === hexToNumber8(last.number)) {
|
|
11473
9854
|
common.logger.info({
|
|
11474
9855
|
service: "sync",
|
|
11475
9856
|
msg: `Skipped '${network.name}' historical sync because all blocks are cached`
|
|
@@ -11483,7 +9864,7 @@ async function* getLocalSyncGenerator({
|
|
|
11483
9864
|
)} cached`
|
|
11484
9865
|
});
|
|
11485
9866
|
}
|
|
11486
|
-
cursor =
|
|
9867
|
+
cursor = hexToNumber8(syncProgress.current.number) + 1;
|
|
11487
9868
|
} else {
|
|
11488
9869
|
common.logger.info({
|
|
11489
9870
|
service: "historical",
|
|
@@ -11492,8 +9873,8 @@ async function* getLocalSyncGenerator({
|
|
|
11492
9873
|
}
|
|
11493
9874
|
while (true) {
|
|
11494
9875
|
const interval = [
|
|
11495
|
-
Math.min(cursor,
|
|
11496
|
-
Math.min(cursor + estimateRange,
|
|
9876
|
+
Math.min(cursor, hexToNumber8(last.number)),
|
|
9877
|
+
Math.min(cursor + estimateRange, hexToNumber8(last.number))
|
|
11497
9878
|
];
|
|
11498
9879
|
const endClock = startClock();
|
|
11499
9880
|
const synced = await historicalSync.sync(interval);
|
|
@@ -11503,13 +9884,13 @@ async function* getLocalSyncGenerator({
|
|
|
11503
9884
|
});
|
|
11504
9885
|
cursor = interval[1] + 1;
|
|
11505
9886
|
if (synced === void 0) {
|
|
11506
|
-
if (interval[1] ===
|
|
9887
|
+
if (interval[1] === hexToNumber8(last.number)) {
|
|
11507
9888
|
syncProgress.current = last;
|
|
11508
9889
|
} else {
|
|
11509
9890
|
continue;
|
|
11510
9891
|
}
|
|
11511
9892
|
} else {
|
|
11512
|
-
if (interval[1] ===
|
|
9893
|
+
if (interval[1] === hexToNumber8(last.number)) {
|
|
11513
9894
|
syncProgress.current = last;
|
|
11514
9895
|
} else {
|
|
11515
9896
|
syncProgress.current = synced;
|
|
@@ -11517,7 +9898,7 @@ async function* getLocalSyncGenerator({
|
|
|
11517
9898
|
const duration = endClock();
|
|
11518
9899
|
common.metrics.ponder_sync_block.set(
|
|
11519
9900
|
label,
|
|
11520
|
-
|
|
9901
|
+
hexToNumber8(syncProgress.current.number)
|
|
11521
9902
|
);
|
|
11522
9903
|
common.metrics.ponder_historical_duration.observe(label, duration);
|
|
11523
9904
|
common.metrics.ponder_historical_completed_blocks.inc(
|
|
@@ -11574,7 +9955,7 @@ var getLocalSyncProgress = async ({
|
|
|
11574
9955
|
);
|
|
11575
9956
|
const finalized = Math.max(
|
|
11576
9957
|
0,
|
|
11577
|
-
|
|
9958
|
+
hexToNumber8(diagnostics[1].number) - network.finalityBlockCount
|
|
11578
9959
|
);
|
|
11579
9960
|
syncProgress.finalized = await _eth_getBlockByNumber(requestQueue, {
|
|
11580
9961
|
blockNumber: finalized
|
|
@@ -11583,7 +9964,7 @@ var getLocalSyncProgress = async ({
|
|
|
11583
9964
|
if (diagnostics.length === 4) {
|
|
11584
9965
|
syncProgress.current = diagnostics[3];
|
|
11585
9966
|
}
|
|
11586
|
-
if (
|
|
9967
|
+
if (hexToNumber8(diagnostics[0]) !== network.chainId) {
|
|
11587
9968
|
common.logger.warn({
|
|
11588
9969
|
service: "sync",
|
|
11589
9970
|
msg: `Remote chain ID (${diagnostics[0]}) does not match configured chain ID (${network.chainId}) for network "${network.name}"`
|
|
@@ -11593,7 +9974,7 @@ var getLocalSyncProgress = async ({
|
|
|
11593
9974
|
return syncProgress;
|
|
11594
9975
|
}
|
|
11595
9976
|
const end = Math.max(...filters.map((filter) => filter.toBlock));
|
|
11596
|
-
if (end >
|
|
9977
|
+
if (end > hexToNumber8(diagnostics[1].number)) {
|
|
11597
9978
|
syncProgress.end = {
|
|
11598
9979
|
number: toHex2(end),
|
|
11599
9980
|
hash: "0x",
|
|
@@ -12474,7 +10855,7 @@ async function dev({ cliOptions }) {
|
|
|
12474
10855
|
}
|
|
12475
10856
|
|
|
12476
10857
|
// src/bin/commands/list.ts
|
|
12477
|
-
import { sql as
|
|
10858
|
+
import { sql as sql3 } from "kysely";
|
|
12478
10859
|
var emptySchemaBuild = {
|
|
12479
10860
|
schema: {},
|
|
12480
10861
|
statements: {
|
|
@@ -12520,7 +10901,7 @@ async function list({ cliOptions }) {
|
|
|
12520
10901
|
).execute();
|
|
12521
10902
|
let union;
|
|
12522
10903
|
for (const row of ponderSchemas) {
|
|
12523
|
-
const query2 = database.qb.internal.selectFrom(`${row.table_schema}._ponder_meta`).select(["value",
|
|
10904
|
+
const query2 = database.qb.internal.selectFrom(`${row.table_schema}._ponder_meta`).select(["value", sql3`${row.table_schema}`.as("schema")]).where("key", "=", "app");
|
|
12524
10905
|
if (union === void 0) {
|
|
12525
10906
|
union = query2;
|
|
12526
10907
|
} else {
|