@ocap/resolver 1.18.154 → 1.18.156

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/lib/index.js CHANGED
@@ -210,10 +210,7 @@ module.exports = class OCAPResolver {
210
210
  }
211
211
 
212
212
  async sendTx({ tx: txBase64 }, ctx = {}) {
213
- this.logger.info('sendTx', {
214
- txBase64,
215
- request: ctx.request,
216
- });
213
+ debug('sendTx', { txBase64, request: ctx.request });
217
214
 
218
215
  if (process.env.CHAIN_MODE === 'readonly') {
219
216
  throw new CustomError('FORBIDDEN', 'This chain node is running in readonly mode');
@@ -227,6 +224,7 @@ module.exports = class OCAPResolver {
227
224
  indexdb: this.indexdb,
228
225
  config: this.config,
229
226
  filter: this.filter,
227
+ logger: this.logger,
230
228
  extra: ctx,
231
229
  };
232
230
 
package/lib/token-flow.js CHANGED
@@ -131,19 +131,13 @@ const getInitialBalance = (address, config) => {
131
131
  return account ? fromTokenToUnit(account.balance) : ZERO;
132
132
  };
133
133
 
134
- const fixMigrateReceipts = async ({ accountAddress, tx }, resolver) => {
134
+ const fixMigrateReceipts = async (tx, resolver) => {
135
135
  const migrationChain = await resolver.getMigrationChain();
136
- const address = migrationChain.findAddressAtTime(accountAddress, new Date(tx.time));
137
- const migrations = migrationChain.getMigrationHistory(accountAddress);
138
-
139
- // fix receipts address
140
- if (address && migrations.length) {
141
- tx.receipts.forEach((receipt) => {
142
- if (migrations.some((x) => isSameDid(x.address, receipt.address))) {
143
- receipt.address = address;
144
- }
145
- });
146
- }
136
+ const txTime = new Date(tx.time);
137
+
138
+ tx.receipts?.forEach((receipt) => {
139
+ receipt.address = migrationChain.findAddressAtTime(receipt.address, txTime);
140
+ });
147
141
  };
148
142
 
149
143
  const verifyAccountRisk = async (
@@ -180,8 +174,10 @@ const verifyAccountRisk = async (
180
174
  const address = accountQueue.pop();
181
175
  // Avoid circular query
182
176
  if (checkedAccounts.has(address)) continue;
183
- // skip trusted accounts
184
- if (await resolver.filter.isTrusted(address)) {
177
+
178
+ const trustedConfig = await resolver.filter?.getTrustedAccountConfig(address);
179
+ // Skip trusted accounts that do not have tolerance configured
180
+ if (trustedConfig && !trustedConfig.tolerance) {
185
181
  checkedAccounts.set(address, true);
186
182
  continue;
187
183
  }
@@ -214,14 +210,12 @@ const verifyAccountRisk = async (
214
210
  // Parse txs to get transfer amounts
215
211
  for (const tx of transactions) {
216
212
  // fix migrate receipts
217
- if (accountState.migratedFrom?.length || accountState.migratedTo?.length) {
218
- await fixMigrateReceipts({ accountAddress: address, tx }, resolver, ctx);
219
- }
213
+ await fixMigrateReceipts(tx, resolver, ctx);
214
+
220
215
  // cache tx
221
216
  if (!checkedTx.has(tx.hash)) {
222
217
  checkedTx.set(tx.hash, await getTransferList(tx, tokenAddress));
223
218
  }
224
-
225
219
  const { transferInList, transferOutList } = checkedTx.get(tx.hash);
226
220
 
227
221
  // Calculate the total amount of transfer for this address
@@ -265,6 +259,7 @@ const verifyAccountRisk = async (
265
259
  if (
266
260
  transferIn
267
261
  .sub(transferOut.add(new BN(balance)))
262
+ .add(fromTokenToUnit(trustedConfig?.tolerance || 0))
268
263
  .abs()
269
264
  .gt(toleranceUnit)
270
265
  ) {
@@ -345,7 +340,7 @@ const listTokenFlows = async (
345
340
 
346
341
  for (const tx of transactions) {
347
342
  // fix migrate receipts
348
- await fixMigrateReceipts({ accountAddress: address, tx }, resolver, ctx);
343
+ await fixMigrateReceipts(tx, resolver, ctx);
349
344
  // cache tx
350
345
  if (!checkedTx.has(tx.hash)) {
351
346
  checkedTx.set(tx.hash, await getTransferFlow(tx, tokenAddress));
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.154",
6
+ "version": "1.18.156",
7
7
  "description": "GraphQL resolver built upon ocap statedb and GQL layer",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -22,18 +22,18 @@
22
22
  "jest": "^29.7.0"
23
23
  },
24
24
  "dependencies": {
25
- "@arcblock/did": "1.18.154",
26
- "@arcblock/did-util": "1.18.154",
27
- "@arcblock/validator": "1.18.154",
28
- "@ocap/config": "1.18.154",
29
- "@ocap/indexdb": "1.18.154",
30
- "@ocap/mcrypto": "1.18.154",
31
- "@ocap/message": "1.18.154",
32
- "@ocap/state": "1.18.154",
33
- "@ocap/tx-protocols": "1.18.154",
34
- "@ocap/util": "1.18.154",
25
+ "@arcblock/did": "1.18.156",
26
+ "@arcblock/did-util": "1.18.156",
27
+ "@arcblock/validator": "1.18.156",
28
+ "@ocap/config": "1.18.156",
29
+ "@ocap/indexdb": "1.18.156",
30
+ "@ocap/mcrypto": "1.18.156",
31
+ "@ocap/message": "1.18.156",
32
+ "@ocap/state": "1.18.156",
33
+ "@ocap/tx-protocols": "1.18.156",
34
+ "@ocap/util": "1.18.156",
35
35
  "debug": "^4.3.6",
36
36
  "lodash": "^4.17.21"
37
37
  },
38
- "gitHead": "414d4207886905fca9529912a12a3b6b8c811886"
38
+ "gitHead": "955c3e7ae8e06fc037e6591267babaae1623ef23"
39
39
  }