@ocap/resolver 1.31.5 → 1.31.6

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/esm/hooks.mjs CHANGED
@@ -133,6 +133,14 @@ const updateRollupStats = async (address, value, key, indexdb) => {
133
133
  console.error("update rollup error", err);
134
134
  }
135
135
  };
136
+ /**
137
+ * A `deposit_token_v2` of the bridge branch, by its branch signals only: a bridge kind (1/2/3), or the v2 bridge row the
138
+ * protocol picked (`isBridgeV2`). A missing `rollupState` is not one of them: a v1 deposit is never skipped for it.
139
+ */
140
+ const isBridgeDepositHook = (tx, ctx) => {
141
+ const kind = tx.tx.itxJson.kind;
142
+ return ctx.isBridgeV2 === true || kind === 1 || kind === 2 || kind === 3;
143
+ };
136
144
  const onDepositTokenV2 = async (tx, ctx, indexdb) => {
137
145
  const { signatures } = tx.tx;
138
146
  const { rollupState } = ctx;
@@ -258,11 +266,15 @@ const onCreateTx = async (tx, ctx, resolver) => {
258
266
  case "fg:t:claim_stake": return onClaimStake(tx, ctx, indexdb);
259
267
  case "fg:t:join_rollup": return onJoinRollup(tx, ctx, indexdb);
260
268
  case "fg:t:leave_rollup": return onLeaveRollup(tx, ctx, indexdb);
261
- case "fg:t:deposit_token_v2": return onDepositTokenV2(tx, ctx, indexdb);
269
+ case "fg:t:deposit_token_v2":
270
+ if (isBridgeDepositHook(tx, ctx)) return;
271
+ return onDepositTokenV2(tx, ctx, indexdb);
262
272
  case "fg:t:claim_block_reward":
263
273
  await onClaimBlockReward(tx, ctx, indexdb);
264
274
  return;
265
- case "fg:t:withdraw_token_v2": return updateRollupStats(ctx.rollupState.address, tx.tx.itxJson.token.value, "totalWithdrawAmount", indexdb);
275
+ case "fg:t:withdraw_token_v2":
276
+ if (ctx.isBridgeV2 || !ctx.rollupState) return;
277
+ return updateRollupStats(ctx.rollupState.address, tx.tx.itxJson.token.value, "totalWithdrawAmount", indexdb);
266
278
  case "fg:t:account_migrate": return onAccountMigrate(tx, resolver);
267
279
  default:
268
280
  }
package/esm/index.d.mts CHANGED
@@ -167,6 +167,14 @@ declare class OCAPResolver implements IResolver {
167
167
  connectIndexDB(): void;
168
168
  private listIndexFailureRows;
169
169
  private deleteIndexFailureRow;
170
+ /**
171
+ * The rollup inputs the live path hands createIndexedTransaction, rebuilt from statedb for a replayed tx row (#1693;
172
+ * the same lookup rebuild.ts does, by `itx.rollup`). A v2 bridge row named by a deposit_token_v2 / withdraw_token_v2 is
173
+ * the bridge branch: `isBridgeV2` plus the resolved bridge (`release.bridge` / `bridge`), so the row is listed under the
174
+ * bridge and the hooks skip it, exactly as live. Any other existing row is a v1 `rollupState`. A failed read throws,
175
+ * so the failure stays queued instead of being replayed without its rollup.
176
+ */
177
+ private getReplayTxRollupContext;
170
178
  private replayIndexFailureRow;
171
179
  /**
172
180
  * Replay pending records in `indexdb.indexFailure` with exponential backoff and dead-letter cap (#67 Phase 2).
package/esm/index.mjs CHANGED
@@ -19,8 +19,10 @@ import * as states from "@ocap/state";
19
19
  import { TxTimer, assertRawWireEnvelope, assertStatelessTxRules, assertTxAdmission, classifyErrorStrikeCategory, createExecutor, getTxSecurityWarningByHash, inspectTransactionPreFlight, recordActorSecurityStrike, resolveVerifiedStrikeActors, setTxSecurityWarningForHash } from "@ocap/tx-protocols";
20
20
  import { decodeAnySafe } from "@ocap/tx-protocols/lib/util";
21
21
  import { DEFAULT_TOKEN_DECIMAL } from "@ocap/util/lib/constant";
22
+ import { stripDefaultDepositV2BridgeFields } from "@ocap/util/lib/deposit-v2-bridge-fields";
22
23
  import { CustomError } from "@ocap/util/lib/error";
23
24
  import { md5 } from "@ocap/util/lib/md5";
25
+ import cloneDeep from "lodash/cloneDeep.js";
24
26
  import get from "lodash/get.js";
25
27
  import isEmpty from "lodash/isEmpty.js";
26
28
  import isEqual from "lodash/isEqual.js";
@@ -135,7 +137,7 @@ const maxGasOps = {
135
137
  create: 2,
136
138
  update: 13
137
139
  },
138
- "fg:t:release_bridge_token": {
140
+ "fg:t:deposit_token_v2_bridge": {
139
141
  create: 3,
140
142
  update: 20
141
143
  },
@@ -423,7 +425,7 @@ var OCAPResolver = class {
423
425
  return "";
424
426
  };
425
427
  const sourceItx = ctx.itxJson && typeof ctx.itxJson === "object" ? ctx.itxJson : ctx.itx && typeof ctx.itx === "object" ? ctx.itx : null;
426
- const itxJson = sourceItx ? { ...sourceItx } : {
428
+ const itxJson = sourceItx ? stripDefaultDepositV2BridgeFields(typeName || txType, cloneDeep(sourceItx)) : {
427
429
  ...typeName ? { _type: typeName } : {},
428
430
  type_url: txType
429
431
  };
@@ -1306,6 +1308,33 @@ var OCAPResolver = class {
1306
1308
  id
1307
1309
  });
1308
1310
  }
1311
+ /**
1312
+ * The rollup inputs the live path hands createIndexedTransaction, rebuilt from statedb for a replayed tx row (#1693;
1313
+ * the same lookup rebuild.ts does, by `itx.rollup`). A v2 bridge row named by a deposit_token_v2 / withdraw_token_v2 is
1314
+ * the bridge branch: `isBridgeV2` plus the resolved bridge (`release.bridge` / `bridge`), so the row is listed under the
1315
+ * bridge and the hooks skip it, exactly as live. Any other existing row is a v1 `rollupState`. A failed read throws,
1316
+ * so the failure stays queued instead of being replayed without its rollup.
1317
+ */
1318
+ async getReplayTxRollupContext(state) {
1319
+ const type = typeof state?.type === "string" ? state.type : "";
1320
+ const txType = type ? `fg:t:${type}` : "";
1321
+ const address = state?.tx?.itxJson?.rollup;
1322
+ if (typeof address !== "string" || !address) return txType ? { txType } : {};
1323
+ const row = await this.statedb.rollup.get(address);
1324
+ if (!row) return txType ? { txType } : {};
1325
+ if (states.rollup.isBridgeV2(row) && (type === "deposit_token_v2" || type === "withdraw_token_v2")) {
1326
+ const bridge = { address: row.address };
1327
+ return {
1328
+ txType,
1329
+ isBridgeV2: true,
1330
+ ...type === "deposit_token_v2" ? { release: { bridge } } : { bridge }
1331
+ };
1332
+ }
1333
+ return {
1334
+ txType,
1335
+ rollupState: row
1336
+ };
1337
+ }
1309
1338
  async replayIndexFailureRow(row) {
1310
1339
  const table = String(row.table || "");
1311
1340
  const event = String(row.event || "create");
@@ -1325,16 +1354,18 @@ var OCAPResolver = class {
1325
1354
  return;
1326
1355
  }
1327
1356
  if (table === "tx") {
1357
+ state = omit(state, ["$loki", "meta"]);
1328
1358
  const ctx$1 = {
1329
1359
  statedb: this.statedb,
1330
- indexdb: this.indexdb
1360
+ indexdb: this.indexdb,
1361
+ ...await this.getReplayTxRollupContext(state)
1331
1362
  };
1332
1363
  const doc$1 = state?.tx && state?.hash && typeof state?.Valid !== "undefined" ? state : await createIndexedTransaction(state, ctx$1, this.indexdb);
1333
1364
  const existing$1 = await this.indexdb.tx.get(doc$1.hash);
1334
1365
  if (event === "update" && existing$1) await this.indexdb.tx.update(doc$1.hash, doc$1);
1335
1366
  else if (!existing$1) await this.indexdb.tx.insert(doc$1);
1336
1367
  else await this.indexdb.tx.update(doc$1.hash, doc$1);
1337
- if (event === "create" && typeof onCreateTx === "function") await onCreateTx(doc$1, ctx$1, this);
1368
+ if (event === "create" && !existing$1 && typeof onCreateTx === "function") await onCreateTx(doc$1, ctx$1, this);
1338
1369
  return;
1339
1370
  }
1340
1371
  const entry = {
package/lib/hooks.cjs CHANGED
@@ -137,6 +137,14 @@ const updateRollupStats = async (address, value, key, indexdb) => {
137
137
  console.error("update rollup error", err);
138
138
  }
139
139
  };
140
+ /**
141
+ * A `deposit_token_v2` of the bridge branch, by its branch signals only: a bridge kind (1/2/3), or the v2 bridge row the
142
+ * protocol picked (`isBridgeV2`). A missing `rollupState` is not one of them: a v1 deposit is never skipped for it.
143
+ */
144
+ const isBridgeDepositHook = (tx, ctx) => {
145
+ const kind = tx.tx.itxJson.kind;
146
+ return ctx.isBridgeV2 === true || kind === 1 || kind === 2 || kind === 3;
147
+ };
140
148
  const onDepositTokenV2 = async (tx, ctx, indexdb) => {
141
149
  const { signatures } = tx.tx;
142
150
  const { rollupState } = ctx;
@@ -262,11 +270,15 @@ const onCreateTx = async (tx, ctx, resolver) => {
262
270
  case "fg:t:claim_stake": return onClaimStake(tx, ctx, indexdb);
263
271
  case "fg:t:join_rollup": return onJoinRollup(tx, ctx, indexdb);
264
272
  case "fg:t:leave_rollup": return onLeaveRollup(tx, ctx, indexdb);
265
- case "fg:t:deposit_token_v2": return onDepositTokenV2(tx, ctx, indexdb);
273
+ case "fg:t:deposit_token_v2":
274
+ if (isBridgeDepositHook(tx, ctx)) return;
275
+ return onDepositTokenV2(tx, ctx, indexdb);
266
276
  case "fg:t:claim_block_reward":
267
277
  await onClaimBlockReward(tx, ctx, indexdb);
268
278
  return;
269
- case "fg:t:withdraw_token_v2": return updateRollupStats(ctx.rollupState.address, tx.tx.itxJson.token.value, "totalWithdrawAmount", indexdb);
279
+ case "fg:t:withdraw_token_v2":
280
+ if (ctx.isBridgeV2 || !ctx.rollupState) return;
281
+ return updateRollupStats(ctx.rollupState.address, tx.tx.itxJson.token.value, "totalWithdrawAmount", indexdb);
270
282
  case "fg:t:account_migrate": return onAccountMigrate(tx, resolver);
271
283
  default:
272
284
  }
package/lib/index.cjs CHANGED
@@ -25,8 +25,11 @@ _ocap_state = require_rolldown_runtime.__toESM(_ocap_state);
25
25
  let _ocap_tx_protocols = require("@ocap/tx-protocols");
26
26
  let _ocap_tx_protocols_lib_util = require("@ocap/tx-protocols/lib/util");
27
27
  let _ocap_util_lib_constant = require("@ocap/util/lib/constant");
28
+ let _ocap_util_lib_deposit_v2_bridge_fields = require("@ocap/util/lib/deposit-v2-bridge-fields");
28
29
  let _ocap_util_lib_error = require("@ocap/util/lib/error");
29
30
  let _ocap_util_lib_md5 = require("@ocap/util/lib/md5");
31
+ let lodash_cloneDeep = require("lodash/cloneDeep");
32
+ lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
30
33
  let lodash_get = require("lodash/get");
31
34
  lodash_get = require_rolldown_runtime.__toESM(lodash_get);
32
35
  let lodash_isEmpty = require("lodash/isEmpty");
@@ -149,7 +152,7 @@ const maxGasOps = {
149
152
  create: 2,
150
153
  update: 13
151
154
  },
152
- "fg:t:release_bridge_token": {
155
+ "fg:t:deposit_token_v2_bridge": {
153
156
  create: 3,
154
157
  update: 20
155
158
  },
@@ -437,7 +440,7 @@ var OCAPResolver = class {
437
440
  return "";
438
441
  };
439
442
  const sourceItx = ctx.itxJson && typeof ctx.itxJson === "object" ? ctx.itxJson : ctx.itx && typeof ctx.itx === "object" ? ctx.itx : null;
440
- const itxJson = sourceItx ? { ...sourceItx } : {
443
+ const itxJson = sourceItx ? (0, _ocap_util_lib_deposit_v2_bridge_fields.stripDefaultDepositV2BridgeFields)(typeName || txType, (0, lodash_cloneDeep.default)(sourceItx)) : {
441
444
  ...typeName ? { _type: typeName } : {},
442
445
  type_url: txType
443
446
  };
@@ -1320,6 +1323,33 @@ var OCAPResolver = class {
1320
1323
  id
1321
1324
  });
1322
1325
  }
1326
+ /**
1327
+ * The rollup inputs the live path hands createIndexedTransaction, rebuilt from statedb for a replayed tx row (#1693;
1328
+ * the same lookup rebuild.ts does, by `itx.rollup`). A v2 bridge row named by a deposit_token_v2 / withdraw_token_v2 is
1329
+ * the bridge branch: `isBridgeV2` plus the resolved bridge (`release.bridge` / `bridge`), so the row is listed under the
1330
+ * bridge and the hooks skip it, exactly as live. Any other existing row is a v1 `rollupState`. A failed read throws,
1331
+ * so the failure stays queued instead of being replayed without its rollup.
1332
+ */
1333
+ async getReplayTxRollupContext(state) {
1334
+ const type = typeof state?.type === "string" ? state.type : "";
1335
+ const txType = type ? `fg:t:${type}` : "";
1336
+ const address = state?.tx?.itxJson?.rollup;
1337
+ if (typeof address !== "string" || !address) return txType ? { txType } : {};
1338
+ const row = await this.statedb.rollup.get(address);
1339
+ if (!row) return txType ? { txType } : {};
1340
+ if (_ocap_state.rollup.isBridgeV2(row) && (type === "deposit_token_v2" || type === "withdraw_token_v2")) {
1341
+ const bridge = { address: row.address };
1342
+ return {
1343
+ txType,
1344
+ isBridgeV2: true,
1345
+ ...type === "deposit_token_v2" ? { release: { bridge } } : { bridge }
1346
+ };
1347
+ }
1348
+ return {
1349
+ txType,
1350
+ rollupState: row
1351
+ };
1352
+ }
1323
1353
  async replayIndexFailureRow(row) {
1324
1354
  const table = String(row.table || "");
1325
1355
  const event = String(row.event || "create");
@@ -1339,16 +1369,18 @@ var OCAPResolver = class {
1339
1369
  return;
1340
1370
  }
1341
1371
  if (table === "tx") {
1372
+ state = (0, lodash_omit.default)(state, ["$loki", "meta"]);
1342
1373
  const ctx$1 = {
1343
1374
  statedb: this.statedb,
1344
- indexdb: this.indexdb
1375
+ indexdb: this.indexdb,
1376
+ ...await this.getReplayTxRollupContext(state)
1345
1377
  };
1346
1378
  const doc$1 = state?.tx && state?.hash && typeof state?.Valid !== "undefined" ? state : await (0, _ocap_indexdb_lib_util.createIndexedTransaction)(state, ctx$1, this.indexdb);
1347
1379
  const existing$1 = await this.indexdb.tx.get(doc$1.hash);
1348
1380
  if (event === "update" && existing$1) await this.indexdb.tx.update(doc$1.hash, doc$1);
1349
1381
  else if (!existing$1) await this.indexdb.tx.insert(doc$1);
1350
1382
  else await this.indexdb.tx.update(doc$1.hash, doc$1);
1351
- if (event === "create" && typeof require_hooks.onCreateTx === "function") await require_hooks.onCreateTx(doc$1, ctx$1, this);
1383
+ if (event === "create" && !existing$1 && typeof require_hooks.onCreateTx === "function") await require_hooks.onCreateTx(doc$1, ctx$1, this);
1352
1384
  return;
1353
1385
  }
1354
1386
  const entry = {
package/lib/index.d.cts CHANGED
@@ -167,6 +167,14 @@ declare class OCAPResolver implements IResolver {
167
167
  connectIndexDB(): void;
168
168
  private listIndexFailureRows;
169
169
  private deleteIndexFailureRow;
170
+ /**
171
+ * The rollup inputs the live path hands createIndexedTransaction, rebuilt from statedb for a replayed tx row (#1693;
172
+ * the same lookup rebuild.ts does, by `itx.rollup`). A v2 bridge row named by a deposit_token_v2 / withdraw_token_v2 is
173
+ * the bridge branch: `isBridgeV2` plus the resolved bridge (`release.bridge` / `bridge`), so the row is listed under the
174
+ * bridge and the hooks skip it, exactly as live. Any other existing row is a v1 `rollupState`. A failed read throws,
175
+ * so the failure stays queued instead of being replayed without its rollup.
176
+ */
177
+ private getReplayTxRollupContext;
170
178
  private replayIndexFailureRow;
171
179
  /**
172
180
  * Replay pending records in `indexdb.indexFailure` with exponential backoff and dead-letter cap (#67 Phase 2).
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.31.5",
6
+ "version": "1.31.6",
7
7
  "description": "GraphQL resolver built upon ocap statedb and GQL layer",
8
8
  "type": "module",
9
9
  "main": "./lib/index.cjs",
@@ -49,20 +49,20 @@
49
49
  "tsdown": "^0.18.4"
50
50
  },
51
51
  "dependencies": {
52
- "@arcblock/did": "1.31.5",
53
- "@arcblock/did-ext": "1.31.5",
54
- "@arcblock/did-util": "1.31.5",
52
+ "@arcblock/did": "1.31.6",
53
+ "@arcblock/did-ext": "1.31.6",
54
+ "@arcblock/did-util": "1.31.6",
55
55
  "@arcblock/nft-display": "^3.2.3",
56
- "@arcblock/validator": "1.31.5",
57
- "@ocap/config": "1.31.5",
58
- "@ocap/indexdb": "1.31.5",
59
- "@ocap/mcrypto": "1.31.5",
60
- "@ocap/message": "1.31.5",
61
- "@ocap/state": "1.31.5",
62
- "@ocap/tx-protocols": "1.31.5",
63
- "@ocap/types": "1.31.5",
64
- "@ocap/util": "1.31.5",
65
- "@ocap/wallet": "1.31.5",
56
+ "@arcblock/validator": "1.31.6",
57
+ "@ocap/config": "1.31.6",
58
+ "@ocap/indexdb": "1.31.6",
59
+ "@ocap/mcrypto": "1.31.6",
60
+ "@ocap/message": "1.31.6",
61
+ "@ocap/state": "1.31.6",
62
+ "@ocap/tx-protocols": "1.31.6",
63
+ "@ocap/types": "1.31.6",
64
+ "@ocap/util": "1.31.6",
65
+ "@ocap/wallet": "1.31.6",
66
66
  "debug": "^4.4.3",
67
67
  "express": "^4.22.1",
68
68
  "lodash": "^4.17.23",