envio 2.31.0-alpha.2 → 2.31.0-alpha.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envio",
3
- "version": "v2.31.0-alpha.2",
3
+ "version": "v2.31.0-alpha.3",
4
4
  "description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
5
5
  "bin": "./bin.js",
6
6
  "main": "./index.js",
@@ -25,10 +25,10 @@
25
25
  },
26
26
  "homepage": "https://envio.dev",
27
27
  "optionalDependencies": {
28
- "envio-linux-x64": "v2.31.0-alpha.2",
29
- "envio-linux-arm64": "v2.31.0-alpha.2",
30
- "envio-darwin-x64": "v2.31.0-alpha.2",
31
- "envio-darwin-arm64": "v2.31.0-alpha.2"
28
+ "envio-linux-x64": "v2.31.0-alpha.3",
29
+ "envio-linux-arm64": "v2.31.0-alpha.3",
30
+ "envio-darwin-x64": "v2.31.0-alpha.3",
31
+ "envio-darwin-arm64": "v2.31.0-alpha.3"
32
32
  },
33
33
  "dependencies": {
34
34
  "@envio-dev/hypersync-client": "0.6.6",
package/src/Internal.res CHANGED
@@ -251,6 +251,7 @@ let fuelTransferParamsSchema = S.schema(s => {
251
251
  type entity = private {id: string}
252
252
  type genericEntityConfig<'entity> = {
253
253
  name: string,
254
+ index: int,
254
255
  schema: S.t<'entity>,
255
256
  rowsSchema: S.t<array<'entity>>,
256
257
  table: Table.table,
@@ -156,13 +156,13 @@ let init = {
156
156
  Logging.info(`Found existing indexer storage. Resuming indexing state...`)
157
157
  let initialState = await persistence.storage.resumeInitialState()
158
158
  persistence.storageStatus = Ready(initialState)
159
- let checkpoints = Js.Dict.empty()
159
+ let progress = Js.Dict.empty()
160
160
  initialState.chains->Js.Array2.forEach(c => {
161
- checkpoints->Utils.Dict.setByInt(c.id, c.progressBlockNumber)
161
+ progress->Utils.Dict.setByInt(c.id, c.progressBlockNumber)
162
162
  })
163
163
  Logging.info({
164
164
  "msg": `Successfully resumed indexing state! Continuing from the last checkpoint.`,
165
- "checkpoints": checkpoints,
165
+ "progress": progress,
166
166
  })
167
167
  }
168
168
  resolveRef.contents()
@@ -82,13 +82,13 @@ async function init(persistence, chainConfigs, resetOpt) {
82
82
  TAG: "Ready",
83
83
  _0: initialState$1
84
84
  };
85
- var checkpoints = {};
85
+ var progress = {};
86
86
  initialState$1.chains.forEach(function (c) {
87
- checkpoints[c.id] = c.progressBlockNumber;
87
+ progress[c.id] = c.progressBlockNumber;
88
88
  });
89
89
  Logging.info({
90
90
  msg: "Successfully resumed indexing state! Continuing from the last checkpoint.",
91
- checkpoints: checkpoints
91
+ progress: progress
92
92
  });
93
93
  }
94
94
 
@@ -42,9 +42,19 @@ type t<'entity> = {
42
42
  makeGetRollbackRestoredEntitiesQuery: (~pgSchema: string) => string,
43
43
  }
44
44
 
45
- let historyTableName = (~entityName) => "envio_history_" ++ entityName
45
+ let maxPgTableNameLength = 63
46
+ let historyTableName = (~entityName, ~entityIndex) => {
47
+ let fullName = "envio_history_" ++ entityName
48
+ if fullName->String.length > maxPgTableNameLength {
49
+ let entityIndexStr = entityIndex->Belt.Int.toString
50
+ fullName->Js.String.slice(~from=0, ~to_=maxPgTableNameLength - entityIndexStr->String.length) ++
51
+ entityIndexStr
52
+ } else {
53
+ fullName
54
+ }
55
+ }
46
56
 
47
- let fromTable = (table: table, ~schema: S.t<'entity>): t<'entity> => {
57
+ let fromTable = (table: table, ~schema: S.t<'entity>, ~entityIndex): t<'entity> => {
48
58
  let id = "id"
49
59
 
50
60
  let dataFields = table.fields->Belt.Array.keepMap(field =>
@@ -79,7 +89,7 @@ let fromTable = (table: table, ~schema: S.t<'entity>): t<'entity> => {
79
89
  // let dataFieldNames = dataFields->Belt.Array.map(field => field->getFieldName)
80
90
 
81
91
  let entityTableName = table.tableName
82
- let historyTableName = historyTableName(~entityName=entityTableName)
92
+ let historyTableName = historyTableName(~entityName=entityTableName, ~entityIndex)
83
93
  //ignore composite indices
84
94
  let table = mkTable(
85
95
  historyTableName,
@@ -179,8 +189,8 @@ type safeReorgBlocks = {
179
189
  // - Rollbacks will not cross the safe checkpoint id, so rows older than the anchor can never be referenced again.
180
190
  // - If nothing changed in reorg threshold (after the safe checkpoint), the current state for that id can be reconstructed from the
181
191
  // origin table; we do not need a pre-safe anchor for it.
182
- let makePruneStaleEntityHistoryQuery = (~entityName, ~pgSchema) => {
183
- let historyTableRef = `"${pgSchema}"."${historyTableName(~entityName)}"`
192
+ let makePruneStaleEntityHistoryQuery = (~entityName, ~entityIndex, ~pgSchema) => {
193
+ let historyTableRef = `"${pgSchema}"."${historyTableName(~entityName, ~entityIndex)}"`
184
194
 
185
195
  `WITH anchors AS (
186
196
  SELECT t.id, MAX(t.${checkpointIdFieldName}) AS keep_checkpoint_id
@@ -202,16 +212,23 @@ WHERE d.id = a.id
202
212
  );`
203
213
  }
204
214
 
205
- let pruneStaleEntityHistory = (sql, ~entityName, ~pgSchema, ~safeCheckpointId): promise<unit> => {
215
+ let pruneStaleEntityHistory = (
216
+ sql,
217
+ ~entityName,
218
+ ~entityIndex,
219
+ ~pgSchema,
220
+ ~safeCheckpointId,
221
+ ): promise<unit> => {
206
222
  sql->Postgres.preparedUnsafe(
207
- makePruneStaleEntityHistoryQuery(~entityName, ~pgSchema),
223
+ makePruneStaleEntityHistoryQuery(~entityName, ~entityIndex, ~pgSchema),
208
224
  [safeCheckpointId]->Utils.magic,
209
225
  )
210
226
  }
211
227
 
212
228
  // If an entity doesn't have a history before the update
213
229
  // we create it automatically with checkpoint_id 0
214
- let makeBackfillHistoryQuery = (~pgSchema, ~entityName) => {
230
+ let makeBackfillHistoryQuery = (~pgSchema, ~entityName, ~entityIndex) => {
231
+ let historyTableRef = `"${pgSchema}"."${historyTableName(~entityName, ~entityIndex)}"`
215
232
  `WITH target_ids AS (
216
233
  SELECT UNNEST($1::${(Text: Table.fieldType :> string)}[]) AS id
217
234
  ),
@@ -219,17 +236,20 @@ missing_history AS (
219
236
  SELECT e.*
220
237
  FROM "${pgSchema}"."${entityName}" e
221
238
  JOIN target_ids t ON e.id = t.id
222
- LEFT JOIN "${pgSchema}"."${historyTableName(~entityName)}" h ON h.id = e.id
239
+ LEFT JOIN ${historyTableRef} h ON h.id = e.id
223
240
  WHERE h.id IS NULL
224
241
  )
225
- INSERT INTO "${pgSchema}"."${historyTableName(~entityName)}"
242
+ INSERT INTO ${historyTableRef}
226
243
  SELECT *, 0 AS ${checkpointIdFieldName}, '${(RowAction.SET :> string)}' as ${changeFieldName}
227
244
  FROM missing_history;`
228
245
  }
229
246
 
230
- let backfillHistory = (sql, ~pgSchema, ~entityName, ~ids: array<string>) => {
247
+ let backfillHistory = (sql, ~pgSchema, ~entityName, ~entityIndex, ~ids: array<string>) => {
231
248
  sql
232
- ->Postgres.preparedUnsafe(makeBackfillHistoryQuery(~entityName, ~pgSchema), [ids]->Obj.magic)
249
+ ->Postgres.preparedUnsafe(
250
+ makeBackfillHistoryQuery(~entityName, ~entityIndex, ~pgSchema),
251
+ [ids]->Obj.magic,
252
+ )
233
253
  ->Promise.ignoreValue
234
254
  }
235
255
 
@@ -248,11 +268,12 @@ let insertDeleteUpdates = (
248
268
  ->Promise.ignoreValue
249
269
  }
250
270
 
251
- let rollback = (sql, ~pgSchema, ~entityName, ~rollbackTargetCheckpointId: int) => {
271
+ let rollback = (sql, ~pgSchema, ~entityName, ~entityIndex, ~rollbackTargetCheckpointId: int) => {
252
272
  sql
253
273
  ->Postgres.preparedUnsafe(
254
274
  `DELETE FROM "${pgSchema}"."${historyTableName(
255
275
  ~entityName,
276
+ ~entityIndex,
256
277
  )}" WHERE "${checkpointIdFieldName}" > $1;`,
257
278
  [rollbackTargetCheckpointId]->Utils.magic,
258
279
  )
@@ -2,6 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  var Table = require("./Table.res.js");
5
+ var Js_string = require("rescript/lib/js/js_string.js");
5
6
  var Belt_Array = require("rescript/lib/js/belt_Array.js");
6
7
  var S$RescriptSchema = require("rescript-schema/src/S.res.js");
7
8
 
@@ -38,11 +39,16 @@ function makeSetUpdateSchema(entitySchema) {
38
39
  });
39
40
  }
40
41
 
41
- function historyTableName(entityName) {
42
- return "envio_history_" + entityName;
42
+ function historyTableName(entityName, entityIndex) {
43
+ var fullName = "envio_history_" + entityName;
44
+ if (fullName.length <= 63) {
45
+ return fullName;
46
+ }
47
+ var entityIndexStr = String(entityIndex);
48
+ return Js_string.slice(0, 63 - entityIndexStr.length | 0, fullName) + entityIndexStr;
43
49
  }
44
50
 
45
- function fromTable(table, schema) {
51
+ function fromTable(table, schema, entityIndex) {
46
52
  var dataFields = Belt_Array.keepMap(table.fields, (function (field) {
47
53
  if (field.TAG !== "Field") {
48
54
  return ;
@@ -84,8 +90,8 @@ function fromTable(table, schema) {
84
90
  var actionField = Table.mkField(changeFieldName, name, S$RescriptSchema.never, undefined, undefined, undefined, undefined, undefined, undefined);
85
91
  var checkpointIdField = Table.mkField(checkpointIdFieldName, "INTEGER", S$RescriptSchema.$$int, undefined, undefined, undefined, true, undefined, undefined);
86
92
  var entityTableName = table.tableName;
87
- var historyTableName = "envio_history_" + entityTableName;
88
- var table$1 = Table.mkTable(historyTableName, undefined, Belt_Array.concat(dataFields, [
93
+ var historyTableName$1 = historyTableName(entityTableName, entityIndex);
94
+ var table$1 = Table.mkTable(historyTableName$1, undefined, Belt_Array.concat(dataFields, [
89
95
  checkpointIdField,
90
96
  actionField
91
97
  ]));
@@ -109,7 +115,7 @@ function fromTable(table, schema) {
109
115
  }));
110
116
  var selectPartsStr = selectParts.join(", ");
111
117
  var makeInsertDeleteUpdatesQuery = function (pgSchema) {
112
- return "INSERT INTO \"" + pgSchema + "\".\"" + historyTableName + "\" (" + allFieldNamesStr + ")\nSELECT " + selectPartsStr + "\nFROM UNNEST($1::text[], $2::int[]) AS u(id, checkpoint_id)";
118
+ return "INSERT INTO \"" + pgSchema + "\".\"" + historyTableName$1 + "\" (" + allFieldNamesStr + ")\nSELECT " + selectPartsStr + "\nFROM UNNEST($1::text[], $2::int[]) AS u(id, checkpoint_id)";
113
119
  };
114
120
  var dataFieldNames = Belt_Array.keep(Belt_Array.map(table$1.fields, (function (field) {
115
121
  return Table.getFieldName(field);
@@ -124,10 +130,10 @@ function fromTable(table, schema) {
124
130
  return "\"" + name + "\"";
125
131
  })).join(", ");
126
132
  var makeGetRollbackRemovedIdsQuery = function (pgSchema) {
127
- return "SELECT DISTINCT id\nFROM \"" + pgSchema + "\".\"" + historyTableName + "\"\nWHERE \"" + checkpointIdFieldName + "\" > $1\n AND NOT EXISTS (\n SELECT 1\n FROM \"" + pgSchema + "\".\"" + historyTableName + "\" h\n WHERE h.id = \"" + historyTableName + "\".id\n AND h.\"" + checkpointIdFieldName + "\" <= $1\n )";
133
+ return "SELECT DISTINCT id\nFROM \"" + pgSchema + "\".\"" + historyTableName$1 + "\"\nWHERE \"" + checkpointIdFieldName + "\" > $1\n AND NOT EXISTS (\n SELECT 1\n FROM \"" + pgSchema + "\".\"" + historyTableName$1 + "\" h\n WHERE h.id = \"" + historyTableName$1 + "\".id\n AND h.\"" + checkpointIdFieldName + "\" <= $1\n )";
128
134
  };
129
135
  var makeGetRollbackRestoredEntitiesQuery = function (pgSchema) {
130
- return "SELECT DISTINCT ON (id) " + dataFieldsCommaSeparated + "\nFROM \"" + pgSchema + "\".\"" + historyTableName + "\"\nWHERE \"" + checkpointIdFieldName + "\" <= $1\n AND EXISTS (\n SELECT 1\n FROM \"" + pgSchema + "\".\"" + historyTableName + "\" h\n WHERE h.id = \"" + historyTableName + "\".id\n AND h.\"" + checkpointIdFieldName + "\" > $1\n )\nORDER BY id, \"" + checkpointIdFieldName + "\" DESC";
136
+ return "SELECT DISTINCT ON (id) " + dataFieldsCommaSeparated + "\nFROM \"" + pgSchema + "\".\"" + historyTableName$1 + "\"\nWHERE \"" + checkpointIdFieldName + "\" <= $1\n AND EXISTS (\n SELECT 1\n FROM \"" + pgSchema + "\".\"" + historyTableName$1 + "\" h\n WHERE h.id = \"" + historyTableName$1 + "\".id\n AND h.\"" + checkpointIdFieldName + "\" > $1\n )\nORDER BY id, \"" + checkpointIdFieldName + "\" DESC";
131
137
  };
132
138
  return {
133
139
  table: table$1,
@@ -139,21 +145,22 @@ function fromTable(table, schema) {
139
145
  };
140
146
  }
141
147
 
142
- function makePruneStaleEntityHistoryQuery(entityName, pgSchema) {
143
- var historyTableRef = "\"" + pgSchema + "\".\"envio_history_" + entityName + "\"";
148
+ function makePruneStaleEntityHistoryQuery(entityName, entityIndex, pgSchema) {
149
+ var historyTableRef = "\"" + pgSchema + "\".\"" + historyTableName(entityName, entityIndex) + "\"";
144
150
  return "WITH anchors AS (\n SELECT t.id, MAX(t." + checkpointIdFieldName + ") AS keep_checkpoint_id\n FROM " + historyTableRef + " t WHERE t." + checkpointIdFieldName + " <= $1\n GROUP BY t.id\n)\nDELETE FROM " + historyTableRef + " d\nUSING anchors a\nWHERE d.id = a.id\n AND (\n d." + checkpointIdFieldName + " < a.keep_checkpoint_id\n OR (\n d." + checkpointIdFieldName + " = a.keep_checkpoint_id AND\n NOT EXISTS (\n SELECT 1 FROM " + historyTableRef + " ps \n WHERE ps.id = d.id AND ps." + checkpointIdFieldName + " > $1\n ) \n )\n );";
145
151
  }
146
152
 
147
- function pruneStaleEntityHistory(sql, entityName, pgSchema, safeCheckpointId) {
148
- return sql.unsafe(makePruneStaleEntityHistoryQuery(entityName, pgSchema), [safeCheckpointId], {prepare: true});
153
+ function pruneStaleEntityHistory(sql, entityName, entityIndex, pgSchema, safeCheckpointId) {
154
+ return sql.unsafe(makePruneStaleEntityHistoryQuery(entityName, entityIndex, pgSchema), [safeCheckpointId], {prepare: true});
149
155
  }
150
156
 
151
- function makeBackfillHistoryQuery(pgSchema, entityName) {
152
- return "WITH target_ids AS (\n SELECT UNNEST($1::TEXT[]) AS id\n),\nmissing_history AS (\n SELECT e.*\n FROM \"" + pgSchema + "\".\"" + entityName + "\" e\n JOIN target_ids t ON e.id = t.id\n LEFT JOIN \"" + pgSchema + "\".\"envio_history_" + entityName + "\" h ON h.id = e.id\n WHERE h.id IS NULL\n)\nINSERT INTO \"" + pgSchema + "\".\"envio_history_" + entityName + "\"\nSELECT *, 0 AS " + checkpointIdFieldName + ", '" + "SET" + "' as " + changeFieldName + "\nFROM missing_history;";
157
+ function makeBackfillHistoryQuery(pgSchema, entityName, entityIndex) {
158
+ var historyTableRef = "\"" + pgSchema + "\".\"" + historyTableName(entityName, entityIndex) + "\"";
159
+ return "WITH target_ids AS (\n SELECT UNNEST($1::TEXT[]) AS id\n),\nmissing_history AS (\n SELECT e.*\n FROM \"" + pgSchema + "\".\"" + entityName + "\" e\n JOIN target_ids t ON e.id = t.id\n LEFT JOIN " + historyTableRef + " h ON h.id = e.id\n WHERE h.id IS NULL\n)\nINSERT INTO " + historyTableRef + "\nSELECT *, 0 AS " + checkpointIdFieldName + ", '" + "SET" + "' as " + changeFieldName + "\nFROM missing_history;";
153
160
  }
154
161
 
155
- function backfillHistory(sql, pgSchema, entityName, ids) {
156
- return sql.unsafe(makeBackfillHistoryQuery(pgSchema, entityName), [ids], {prepare: true});
162
+ function backfillHistory(sql, pgSchema, entityName, entityIndex, ids) {
163
+ return sql.unsafe(makeBackfillHistoryQuery(pgSchema, entityName, entityIndex), [ids], {prepare: true});
157
164
  }
158
165
 
159
166
  function insertDeleteUpdates(sql, pgSchema, entityHistory, batchDeleteEntityIds, batchDeleteCheckpointIds) {
@@ -163,14 +170,17 @@ function insertDeleteUpdates(sql, pgSchema, entityHistory, batchDeleteEntityIds,
163
170
  ], {prepare: true});
164
171
  }
165
172
 
166
- function rollback(sql, pgSchema, entityName, rollbackTargetCheckpointId) {
167
- return sql.unsafe("DELETE FROM \"" + pgSchema + "\".\"envio_history_" + entityName + "\" WHERE \"" + checkpointIdFieldName + "\" > $1;", [rollbackTargetCheckpointId], {prepare: true});
173
+ function rollback(sql, pgSchema, entityName, entityIndex, rollbackTargetCheckpointId) {
174
+ return sql.unsafe("DELETE FROM \"" + pgSchema + "\".\"" + historyTableName(entityName, entityIndex) + "\" WHERE \"" + checkpointIdFieldName + "\" > $1;", [rollbackTargetCheckpointId], {prepare: true});
168
175
  }
169
176
 
177
+ var maxPgTableNameLength = 63;
178
+
170
179
  exports.RowAction = RowAction;
171
180
  exports.changeFieldName = changeFieldName;
172
181
  exports.checkpointIdFieldName = checkpointIdFieldName;
173
182
  exports.makeSetUpdateSchema = makeSetUpdateSchema;
183
+ exports.maxPgTableNameLength = maxPgTableNameLength;
174
184
  exports.historyTableName = historyTableName;
175
185
  exports.fromTable = fromTable;
176
186
  exports.makePruneStaleEntityHistoryQuery = makePruneStaleEntityHistoryQuery;
@@ -7,6 +7,7 @@ let isIndex = true
7
7
 
8
8
  module DynamicContractRegistry = {
9
9
  let name = "dynamic_contract_registry"
10
+ let index = -1
10
11
 
11
12
  let makeId = (~chainId, ~contractAddress) => {
12
13
  chainId->Belt.Int.toString ++ "-" ++ contractAddress->Address.toString
@@ -58,12 +59,13 @@ module DynamicContractRegistry = {
58
59
  ],
59
60
  )
60
61
 
61
- let entityHistory = table->EntityHistory.fromTable(~schema)
62
+ let entityHistory = table->EntityHistory.fromTable(~schema, ~entityIndex=index)
62
63
 
63
64
  external castToInternal: t => Internal.entity = "%identity"
64
65
 
65
66
  let config = {
66
67
  name,
68
+ index,
67
69
  schema,
68
70
  rowsSchema,
69
71
  table,
@@ -606,35 +608,35 @@ module Views = {
606
608
 
607
609
  let makeMetaViewQuery = (~pgSchema) => {
608
610
  `CREATE VIEW "${pgSchema}"."${metaViewName}" AS
609
- SELECT
610
- "${(#id: Chains.field :> string)}" AS "chainId",
611
- "${(#start_block: Chains.field :> string)}" AS "startBlock",
612
- "${(#end_block: Chains.field :> string)}" AS "endBlock",
613
- "${(#progress_block: Chains.field :> string)}" AS "progressBlock",
614
- "${(#buffer_block: Chains.field :> string)}" AS "bufferBlock",
615
- "${(#first_event_block: Chains.field :> string)}" AS "firstEventBlock",
616
- "${(#events_processed: Chains.field :> string)}" AS "eventsProcessed",
617
- "${(#source_block: Chains.field :> string)}" AS "sourceBlock",
618
- "${(#ready_at: Chains.field :> string)}" AS "readyAt",
619
- ("${(#ready_at: Chains.field :> string)}" IS NOT NULL) AS "isReady"
620
- FROM "${pgSchema}"."${Chains.table.tableName}"
621
- ORDER BY "${(#id: Chains.field :> string)}";`
611
+ SELECT
612
+ "${(#id: Chains.field :> string)}" AS "chainId",
613
+ "${(#start_block: Chains.field :> string)}" AS "startBlock",
614
+ "${(#end_block: Chains.field :> string)}" AS "endBlock",
615
+ "${(#progress_block: Chains.field :> string)}" AS "progressBlock",
616
+ "${(#buffer_block: Chains.field :> string)}" AS "bufferBlock",
617
+ "${(#first_event_block: Chains.field :> string)}" AS "firstEventBlock",
618
+ "${(#events_processed: Chains.field :> string)}" AS "eventsProcessed",
619
+ "${(#source_block: Chains.field :> string)}" AS "sourceBlock",
620
+ "${(#ready_at: Chains.field :> string)}" AS "readyAt",
621
+ ("${(#ready_at: Chains.field :> string)}" IS NOT NULL) AS "isReady"
622
+ FROM "${pgSchema}"."${Chains.table.tableName}"
623
+ ORDER BY "${(#id: Chains.field :> string)}";`
622
624
  }
623
625
 
624
626
  let makeChainMetadataViewQuery = (~pgSchema) => {
625
627
  `CREATE VIEW "${pgSchema}"."${chainMetadataViewName}" AS
626
- SELECT
627
- "${(#source_block: Chains.field :> string)}" AS "block_height",
628
- "${(#id: Chains.field :> string)}" AS "chain_id",
629
- "${(#end_block: Chains.field :> string)}" AS "end_block",
630
- "${(#first_event_block: Chains.field :> string)}" AS "first_event_block_number",
631
- "${(#_is_hyper_sync: Chains.field :> string)}" AS "is_hyper_sync",
632
- "${(#buffer_block: Chains.field :> string)}" AS "latest_fetched_block_number",
633
- "${(#progress_block: Chains.field :> string)}" AS "latest_processed_block",
634
- "${(#_num_batches_fetched: Chains.field :> string)}" AS "num_batches_fetched",
635
- "${(#events_processed: Chains.field :> string)}" AS "num_events_processed",
636
- "${(#start_block: Chains.field :> string)}" AS "start_block",
637
- "${(#ready_at: Chains.field :> string)}" AS "timestamp_caught_up_to_head_or_endblock"
638
- FROM "${pgSchema}"."${Chains.table.tableName}";`
628
+ SELECT
629
+ "${(#source_block: Chains.field :> string)}" AS "block_height",
630
+ "${(#id: Chains.field :> string)}" AS "chain_id",
631
+ "${(#end_block: Chains.field :> string)}" AS "end_block",
632
+ "${(#first_event_block: Chains.field :> string)}" AS "first_event_block_number",
633
+ "${(#_is_hyper_sync: Chains.field :> string)}" AS "is_hyper_sync",
634
+ "${(#buffer_block: Chains.field :> string)}" AS "latest_fetched_block_number",
635
+ "${(#progress_block: Chains.field :> string)}" AS "latest_processed_block",
636
+ "${(#_num_batches_fetched: Chains.field :> string)}" AS "num_batches_fetched",
637
+ "${(#events_processed: Chains.field :> string)}" AS "num_events_processed",
638
+ "${(#start_block: Chains.field :> string)}" AS "start_block",
639
+ "${(#ready_at: Chains.field :> string)}" AS "timestamp_caught_up_to_head_or_endblock"
640
+ FROM "${pgSchema}"."${Chains.table.tableName}";`
639
641
  }
640
642
  }
@@ -47,10 +47,11 @@ var table = Table.mkTable(name, undefined, [
47
47
  Table.mkField("contract_name", "TEXT", S$RescriptSchema.string, undefined, undefined, undefined, undefined, undefined, undefined)
48
48
  ]);
49
49
 
50
- var entityHistory = EntityHistory.fromTable(table, schema);
50
+ var entityHistory = EntityHistory.fromTable(table, schema, -1);
51
51
 
52
52
  var config = {
53
53
  name: name,
54
+ index: -1,
54
55
  schema: schema,
55
56
  rowsSchema: rowsSchema,
56
57
  table: table,
@@ -59,6 +60,7 @@ var config = {
59
60
 
60
61
  var DynamicContractRegistry = {
61
62
  name: name,
63
+ index: -1,
62
64
  makeId: makeId,
63
65
  schema: schema,
64
66
  rowsSchema: rowsSchema,
@@ -362,11 +364,11 @@ var metaViewName = "_meta";
362
364
  var chainMetadataViewName = "chain_metadata";
363
365
 
364
366
  function makeMetaViewQuery(pgSchema) {
365
- return "CREATE VIEW \"" + pgSchema + "\".\"" + metaViewName + "\" AS \n SELECT \n \"" + "id" + "\" AS \"chainId\",\n \"" + "start_block" + "\" AS \"startBlock\", \n \"" + "end_block" + "\" AS \"endBlock\",\n \"" + "progress_block" + "\" AS \"progressBlock\",\n \"" + "buffer_block" + "\" AS \"bufferBlock\",\n \"" + "first_event_block" + "\" AS \"firstEventBlock\",\n \"" + "events_processed" + "\" AS \"eventsProcessed\",\n \"" + "source_block" + "\" AS \"sourceBlock\",\n \"" + "ready_at" + "\" AS \"readyAt\",\n (\"" + "ready_at" + "\" IS NOT NULL) AS \"isReady\"\n FROM \"" + pgSchema + "\".\"" + table$1.tableName + "\"\n ORDER BY \"" + "id" + "\";";
367
+ return "CREATE VIEW \"" + pgSchema + "\".\"" + metaViewName + "\" AS \nSELECT \n \"" + "id" + "\" AS \"chainId\",\n \"" + "start_block" + "\" AS \"startBlock\", \n \"" + "end_block" + "\" AS \"endBlock\",\n \"" + "progress_block" + "\" AS \"progressBlock\",\n \"" + "buffer_block" + "\" AS \"bufferBlock\",\n \"" + "first_event_block" + "\" AS \"firstEventBlock\",\n \"" + "events_processed" + "\" AS \"eventsProcessed\",\n \"" + "source_block" + "\" AS \"sourceBlock\",\n \"" + "ready_at" + "\" AS \"readyAt\",\n (\"" + "ready_at" + "\" IS NOT NULL) AS \"isReady\"\nFROM \"" + pgSchema + "\".\"" + table$1.tableName + "\"\nORDER BY \"" + "id" + "\";";
366
368
  }
367
369
 
368
370
  function makeChainMetadataViewQuery(pgSchema) {
369
- return "CREATE VIEW \"" + pgSchema + "\".\"" + chainMetadataViewName + "\" AS \n SELECT \n \"" + "source_block" + "\" AS \"block_height\",\n \"" + "id" + "\" AS \"chain_id\",\n \"" + "end_block" + "\" AS \"end_block\", \n \"" + "first_event_block" + "\" AS \"first_event_block_number\",\n \"" + "_is_hyper_sync" + "\" AS \"is_hyper_sync\",\n \"" + "buffer_block" + "\" AS \"latest_fetched_block_number\",\n \"" + "progress_block" + "\" AS \"latest_processed_block\",\n \"" + "_num_batches_fetched" + "\" AS \"num_batches_fetched\",\n \"" + "events_processed" + "\" AS \"num_events_processed\",\n \"" + "start_block" + "\" AS \"start_block\",\n \"" + "ready_at" + "\" AS \"timestamp_caught_up_to_head_or_endblock\"\n FROM \"" + pgSchema + "\".\"" + table$1.tableName + "\";";
371
+ return "CREATE VIEW \"" + pgSchema + "\".\"" + chainMetadataViewName + "\" AS \nSELECT \n \"" + "source_block" + "\" AS \"block_height\",\n \"" + "id" + "\" AS \"chain_id\",\n \"" + "end_block" + "\" AS \"end_block\", \n \"" + "first_event_block" + "\" AS \"first_event_block_number\",\n \"" + "_is_hyper_sync" + "\" AS \"is_hyper_sync\",\n \"" + "buffer_block" + "\" AS \"latest_fetched_block_number\",\n \"" + "progress_block" + "\" AS \"latest_processed_block\",\n \"" + "_num_batches_fetched" + "\" AS \"num_batches_fetched\",\n \"" + "events_processed" + "\" AS \"num_events_processed\",\n \"" + "start_block" + "\" AS \"start_block\",\n \"" + "ready_at" + "\" AS \"timestamp_caught_up_to_head_or_endblock\"\nFROM \"" + pgSchema + "\".\"" + table$1.tableName + "\";";
370
372
  }
371
373
 
372
374
  var Views = {