@ocap/resolver 1.18.153 → 1.18.154

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
@@ -162,7 +162,7 @@ module.exports = class OCAPResolver {
162
162
  * @param {object} params.filter bloom filter to do anti-replay check
163
163
  * @param {bool} params.validateTokenConfig should we validate token supply and token-holder balance, should be disabled when starting an existing chain
164
164
  */
165
- constructor({ statedb, indexdb, config, filter, validateTokenConfig = true }) {
165
+ constructor({ statedb, indexdb, config, filter, validateTokenConfig = true, logger }) {
166
166
  if (!statedb) {
167
167
  throw new Error('OCAP Resolver requires a valid statedb implementation to work');
168
168
  }
@@ -170,6 +170,8 @@ module.exports = class OCAPResolver {
170
170
  throw new Error('OCAP Resolver requires a valid indexdb implementation to work');
171
171
  }
172
172
 
173
+ this.logger = logger || { info: debug, warn: debug, error: debug, debug };
174
+
173
175
  this.statedb = statedb;
174
176
  this.indexdb = indexdb;
175
177
  this.filter = filter;
@@ -208,7 +210,10 @@ module.exports = class OCAPResolver {
208
210
  }
209
211
 
210
212
  async sendTx({ tx: txBase64 }, ctx = {}) {
211
- debug('sendTx', txBase64);
213
+ this.logger.info('sendTx', {
214
+ txBase64,
215
+ request: ctx.request,
216
+ });
212
217
 
213
218
  if (process.env.CHAIN_MODE === 'readonly') {
214
219
  throw new CustomError('FORBIDDEN', 'This chain node is running in readonly mode');
@@ -683,7 +688,12 @@ module.exports = class OCAPResolver {
683
688
 
684
689
  async verifyAccountRisk(args, ctx) {
685
690
  return tokenFlow.verifyAccountRisk(
686
- { ...args, accountLimit: process.env.VERIFY_RISK_ACCOUNT_LIMIT, txLimit: process.env.VERIFY_RISK_TX_LIMIT },
691
+ {
692
+ ...args,
693
+ accountLimit: process.env.VERIFY_RISK_ACCOUNT_LIMIT,
694
+ txLimit: process.env.VERIFY_RISK_TX_LIMIT,
695
+ tolerance: process.env.VERIFY_RISK_TOLERANCE,
696
+ },
687
697
  this,
688
698
  ctx
689
699
  );
package/lib/token-flow.js CHANGED
@@ -147,7 +147,7 @@ const fixMigrateReceipts = async ({ accountAddress, tx }, resolver) => {
147
147
  };
148
148
 
149
149
  const verifyAccountRisk = async (
150
- { accountAddress, tokenAddress, accountLimit = 400, txLimit = 10000 },
150
+ { accountAddress, tokenAddress, accountLimit = 400, txLimit = 10000, tolerance = '0.0000000001' },
151
151
  resolver,
152
152
  ctx = {}
153
153
  ) => {
@@ -160,7 +160,8 @@ const verifyAccountRisk = async (
160
160
  const checkedAccounts = new Map();
161
161
  const checkedTx = new Map();
162
162
  const accountQueue = [accountAddress];
163
-
163
+ const tokenState = await resolver.tokenCache.get(tokenAddress);
164
+ const toleranceUnit = fromTokenToUnit(tolerance, tokenState?.decimal);
164
165
  const vaultAccounts = getVaultAccounts(resolver.config);
165
166
 
166
167
  while (accountQueue.length) {
@@ -261,7 +262,12 @@ const verifyAccountRisk = async (
261
262
  checkedAccounts.set(address, true);
262
263
 
263
264
  // Check if the balance not matches the transfer records
264
- if (!transferIn.eq(transferOut.add(new BN(balance)))) {
265
+ if (
266
+ transferIn
267
+ .sub(transferOut.add(new BN(balance)))
268
+ .abs()
269
+ .gt(toleranceUnit)
270
+ ) {
265
271
  debug('Account balance does not match transfer records', {
266
272
  address,
267
273
  transferIn: transferIn.toString(),
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.153",
6
+ "version": "1.18.154",
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.153",
26
- "@arcblock/did-util": "1.18.153",
27
- "@arcblock/validator": "1.18.153",
28
- "@ocap/config": "1.18.153",
29
- "@ocap/indexdb": "1.18.153",
30
- "@ocap/mcrypto": "1.18.153",
31
- "@ocap/message": "1.18.153",
32
- "@ocap/state": "1.18.153",
33
- "@ocap/tx-protocols": "1.18.153",
34
- "@ocap/util": "1.18.153",
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",
35
35
  "debug": "^4.3.6",
36
36
  "lodash": "^4.17.21"
37
37
  },
38
- "gitHead": "ad18c565becef73d6ee782502c3f4858de43b68b"
38
+ "gitHead": "414d4207886905fca9529912a12a3b6b8c811886"
39
39
  }