@ocap/tx-protocols 1.14.1 → 1.14.5

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/execute.js CHANGED
@@ -62,7 +62,7 @@ module.exports = ({ filter, runAsLambda }) => {
62
62
  // we should only flush events when retry is not supported
63
63
  // otherwise the outer caller should handle these 2
64
64
  if (shouldPersistTx(err) && isRetrySupported === false) {
65
- const txState = context.states.tx.create(context, err ? err.code : 'OK');
65
+ const txState = context.states.tx.create(context, err ? err.code || 'INTERNAL' : 'OK');
66
66
  try {
67
67
  await context.statedb.tx.create(txState.hash, txState, context);
68
68
  } catch (e) {
@@ -100,7 +100,7 @@ module.exports = ({ filter, runAsLambda }) => {
100
100
  } finally {
101
101
  if (shouldPersistTx(error)) {
102
102
  try {
103
- const txState = context.states.tx.create(ctx, error ? error.code : 'OK');
103
+ const txState = context.states.tx.create(ctx, error ? error.code || 'INTERNAL' : 'OK');
104
104
  flushEvents(ctx, { txState });
105
105
  await runAsLambda(async (txn) => {
106
106
  const newCtx = { ...omit(ctx, ['txn']), txn };
@@ -38,11 +38,15 @@ runner.use(
38
38
  const { tx, itx, statedb } = context;
39
39
  const tokens = { [context.config.token.address]: '0' };
40
40
 
41
- context.senderState = await statedb.account.create(
42
- tx.from,
43
- account.create({ address: tx.from, pk: toBase58(tx.pk), nonce: tx.nonce, tokens, ...itx }, context),
44
- context
45
- );
41
+ const [senderState] = await Promise.all([
42
+ statedb.account.create(
43
+ tx.from,
44
+ account.create({ address: tx.from, pk: toBase58(tx.pk), nonce: tx.nonce, tokens, ...itx }, context),
45
+ context
46
+ ),
47
+ ]);
48
+
49
+ context.senderState = senderState;
46
50
 
47
51
  next();
48
52
  },
@@ -2,7 +2,6 @@
2
2
  const Error = require('@ocap/util/lib/error');
3
3
  const isEmpty = require('lodash/isEmpty');
4
4
  const cloneDeep = require('lodash/cloneDeep');
5
- const Joi = require('@ocap/validator');
6
5
  const { Runner, pipes } = require('@ocap/tx-pipeline');
7
6
  const { account, asset } = require('@ocap/state');
8
7
  const { toAssetAddress } = require('@arcblock/did-util');
@@ -18,18 +17,8 @@ const runner = new Runner();
18
17
  runner.use(pipes.VerifyMultiSig(0));
19
18
 
20
19
  // Verify itx
21
- const schema = Joi.object({
22
- moniker: Joi.string().min(2).max(255).required(),
23
- data: Joi.any().required(),
24
- readonly: Joi.boolean().default(false),
25
- transferrable: Joi.boolean().default(false),
26
- ttl: Joi.number().min(0).default(0),
27
- parent: Joi.DID().optional().allow(''),
28
- address: Joi.DID().role('ROLE_ASSET').required(),
29
- issuer: Joi.DID().optional().allow(''),
30
- }).options({ stripUnknown: true, noDefaults: false });
31
20
  runner.use(({ itx }, next) => {
32
- const { error } = schema.validate(itx);
21
+ const { error } = asset.schema.validate(itx);
33
22
  if (error) {
34
23
  return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
35
24
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.14.1",
6
+ "version": "1.14.5",
7
7
  "description": "Predefined tx pipeline sets to execute certain type of transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -12,24 +12,26 @@
12
12
  "scripts": {
13
13
  "lint": "eslint tests lib",
14
14
  "lint:fix": "eslint --fix tests lib",
15
+ "start": "node tools/start-chain.js",
15
16
  "test": "jest --forceExit --detectOpenHandles",
16
- "coverage": "npm run test -- --coverage"
17
+ "test:ci": "jest --forceExit --detectOpenHandles --coverage",
18
+ "coverage": "start-server-and-test start http://127.0.0.1:4001 test:ci"
17
19
  },
18
20
  "keywords": [],
19
21
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
22
  "license": "MIT",
21
23
  "dependencies": {
22
- "@arcblock/did": "1.14.1",
23
- "@arcblock/did-util": "1.14.1",
24
- "@ocap/asset": "1.14.1",
25
- "@ocap/mcrypto": "1.14.1",
26
- "@ocap/merkle-tree": "1.14.1",
27
- "@ocap/message": "1.14.1",
28
- "@ocap/state": "1.14.1",
29
- "@ocap/tx-pipeline": "1.14.1",
30
- "@ocap/util": "1.14.1",
31
- "@ocap/validator": "1.14.1",
32
- "@ocap/wallet": "1.14.1",
24
+ "@arcblock/did": "1.14.5",
25
+ "@arcblock/did-util": "1.14.5",
26
+ "@ocap/asset": "1.14.5",
27
+ "@ocap/mcrypto": "1.14.5",
28
+ "@ocap/merkle-tree": "1.14.5",
29
+ "@ocap/message": "1.14.5",
30
+ "@ocap/state": "1.14.5",
31
+ "@ocap/tx-pipeline": "1.14.5",
32
+ "@ocap/util": "1.14.5",
33
+ "@ocap/validator": "1.14.5",
34
+ "@ocap/wallet": "1.14.5",
33
35
  "debug": "^4.3.2",
34
36
  "empty-value": "^1.0.1",
35
37
  "lodash": "^4.17.21",
@@ -40,7 +42,8 @@
40
42
  "elliptic": "6.5.3"
41
43
  },
42
44
  "devDependencies": {
43
- "jest": "^27.3.1"
45
+ "jest": "^27.3.1",
46
+ "start-server-and-test": "^1.14.0"
44
47
  },
45
- "gitHead": "ad0f82d07b1656581665f09953c738b24be07298"
48
+ "gitHead": "9a685c7182412efc208a5193c17b92ec299dccb2"
46
49
  }