@ocap/tx-pipeline 1.18.130 → 1.18.132

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.130",
6
+ "version": "1.18.132",
7
7
  "description": "Pipeline runner and common pipelines to process transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -29,16 +29,16 @@
29
29
  "elliptic": "6.5.3"
30
30
  },
31
31
  "dependencies": {
32
- "@arcblock/did": "1.18.130",
33
- "@arcblock/did-util": "1.18.130",
34
- "@ocap/mcrypto": "1.18.130",
35
- "@ocap/message": "1.18.130",
36
- "@ocap/state": "1.18.130",
37
- "@ocap/util": "1.18.130",
38
- "@ocap/wallet": "1.18.130",
32
+ "@arcblock/did": "1.18.132",
33
+ "@arcblock/did-util": "1.18.132",
34
+ "@ocap/mcrypto": "1.18.132",
35
+ "@ocap/message": "1.18.132",
36
+ "@ocap/state": "1.18.132",
37
+ "@ocap/util": "1.18.132",
38
+ "@ocap/wallet": "1.18.132",
39
39
  "debug": "^4.3.4",
40
40
  "empty-value": "^1.0.1",
41
41
  "lodash": "^4.17.21"
42
42
  },
43
- "gitHead": "d4846249beb92ef45faad7a23781f631523f288e"
43
+ "gitHead": "6699d47364eb94f564e0fcf6ea55b6e7ea005d0d"
44
44
  }