@ocap/tx-pipeline 1.18.131 → 1.18.133

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,30 @@
1
+ /* eslint-disable no-await-in-loop */
2
+ const get = require('lodash/get');
1
3
  const { CustomError: Error } = require('@ocap/util/lib/error');
4
+ const { getRelatedAddresses } = require('@ocap/util/lib/get-related-addr');
2
5
 
3
- module.exports = function CreatedVerifyBlockedPipe(filter) {
6
+ module.exports = function CreatedVerifyBlockedPipe({ filter = null, stateKeys = ['tx.from'] } = {}) {
4
7
  return async function VerifyTx(context, next) {
5
- if (typeof filter?.isBlocked === 'function' && context.tx?.from) {
6
- const blocked = await filter.isBlocked(context.tx.from);
7
- if (blocked) {
8
- return next(new Error('FORBIDDEN', 'Sender blocked'));
8
+ const f = filter || context.filter;
9
+ if (typeof f?.isBlocked === 'function') {
10
+ const suspects = [];
11
+ stateKeys.forEach((stateKey) => {
12
+ const state = get(context, stateKey);
13
+ if (state) {
14
+ if (typeof state === 'string') {
15
+ suspects.push(state);
16
+ } else {
17
+ const states = Array.isArray(state) ? state : [state];
18
+ states.forEach((x) => suspects.push(...getRelatedAddresses(x)));
19
+ }
20
+ }
21
+ });
22
+
23
+ for (const suspect of suspects) {
24
+ const blocked = await f.isBlocked(suspect);
25
+ if (blocked) {
26
+ return next(new Error('FORBIDDEN', `Account blocked: ${suspect}`));
27
+ }
9
28
  }
10
29
  }
11
30
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.131",
6
+ "version": "1.18.133",
7
7
  "description": "Pipeline runner and common pipelines to process transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -21,7 +21,7 @@
21
21
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "jest": "^27.5.1",
24
+ "jest": "^29.7.0",
25
25
  "start-server-and-test": "^1.14.0"
26
26
  },
27
27
  "resolutions": {
@@ -29,16 +29,16 @@
29
29
  "elliptic": "6.5.3"
30
30
  },
31
31
  "dependencies": {
32
- "@arcblock/did": "1.18.131",
33
- "@arcblock/did-util": "1.18.131",
34
- "@ocap/mcrypto": "1.18.131",
35
- "@ocap/message": "1.18.131",
36
- "@ocap/state": "1.18.131",
37
- "@ocap/util": "1.18.131",
38
- "@ocap/wallet": "1.18.131",
39
- "debug": "^4.3.4",
32
+ "@arcblock/did": "1.18.133",
33
+ "@arcblock/did-util": "1.18.133",
34
+ "@ocap/mcrypto": "1.18.133",
35
+ "@ocap/message": "1.18.133",
36
+ "@ocap/state": "1.18.133",
37
+ "@ocap/util": "1.18.133",
38
+ "@ocap/wallet": "1.18.133",
39
+ "debug": "^4.3.6",
40
40
  "empty-value": "^1.0.1",
41
41
  "lodash": "^4.17.21"
42
42
  },
43
- "gitHead": "1e07d8baecba883a20db0a1ab44aeba211e97b30"
43
+ "gitHead": "cd4b69aef69b4e30265c3897a22fb63c902c5d4e"
44
44
  }