@ocap/tx-protocols 1.18.78 → 1.18.80

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.
@@ -20,6 +20,7 @@ runner.use(pipes.VerifyMultiSig(0));
20
20
  const schema = Joi.object({
21
21
  address: Joi.DID().prefix().role('ROLE_ASSET').required(),
22
22
  moniker: Joi.string().min(2).max(255).optional().allow(''),
23
+ consumed: Joi.boolean().optional().default(false),
23
24
  data: Joi.any().optional(),
24
25
  }).options({ stripUnknown: true, noDefaults: false });
25
26
  runner.use((context, next) => {
@@ -54,6 +55,12 @@ runner.use(
54
55
  fn: ({ assetState }) => assetState.readonly === false,
55
56
  persist: true,
56
57
  },
58
+ {
59
+ error: 'CONSUMED_ASSET',
60
+ message: 'Can not consume an already consumed asset',
61
+ fn: ({ assetState, itx }) => !(itx.consumed && assetState.consumedTime),
62
+ persist: true,
63
+ },
57
64
  ])
58
65
  );
59
66
 
@@ -84,7 +91,12 @@ runner.use(EnsureTxCost({ attachSenderChanges: true }));
84
91
  // Update asset state
85
92
  runner.use(
86
93
  async (context, next) => {
87
- const { tx, itx, newData, statedb, senderState, senderUpdates, assetState, updateVaults } = context;
94
+ const { tx, itx, txTime, newData, statedb, senderState, senderUpdates, assetState, updateVaults } = context;
95
+
96
+ const updates = { moniker: itx.moniker || assetState.moniker, data: newData || assetState.data };
97
+ if (itx.consumed && !assetState.consumedTime) {
98
+ updates.consumedTime = txTime;
99
+ }
88
100
 
89
101
  const [newSenderState, newAssetState] = await Promise.all([
90
102
  // update owner state
@@ -95,15 +107,7 @@ runner.use(
95
107
  ),
96
108
 
97
109
  // update asset state
98
- statedb.asset.update(
99
- itx.address,
100
- asset.update(
101
- assetState,
102
- { moniker: itx.moniker || assetState.moniker, data: newData || assetState.data },
103
- context
104
- ),
105
- context
106
- ),
110
+ statedb.asset.update(itx.address, asset.update(assetState, updates, context), context),
107
111
 
108
112
  updateVaults(),
109
113
  ]);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.78",
6
+ "version": "1.18.80",
7
7
  "description": "Predefined tx pipeline sets to execute certain type of transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -21,18 +21,18 @@
21
21
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@arcblock/did": "1.18.78",
25
- "@arcblock/did-util": "1.18.78",
26
- "@arcblock/jwt": "1.18.78",
27
- "@arcblock/validator": "1.18.78",
28
- "@ocap/asset": "1.18.78",
29
- "@ocap/mcrypto": "1.18.78",
30
- "@ocap/merkle-tree": "1.18.78",
31
- "@ocap/message": "1.18.78",
32
- "@ocap/state": "1.18.78",
33
- "@ocap/tx-pipeline": "1.18.78",
34
- "@ocap/util": "1.18.78",
35
- "@ocap/wallet": "1.18.78",
24
+ "@arcblock/did": "1.18.80",
25
+ "@arcblock/did-util": "1.18.80",
26
+ "@arcblock/jwt": "1.18.80",
27
+ "@arcblock/validator": "1.18.80",
28
+ "@ocap/asset": "1.18.80",
29
+ "@ocap/mcrypto": "1.18.80",
30
+ "@ocap/merkle-tree": "1.18.80",
31
+ "@ocap/message": "1.18.80",
32
+ "@ocap/state": "1.18.80",
33
+ "@ocap/tx-pipeline": "1.18.80",
34
+ "@ocap/util": "1.18.80",
35
+ "@ocap/wallet": "1.18.80",
36
36
  "debug": "^4.3.4",
37
37
  "deep-diff": "^1.0.2",
38
38
  "empty-value": "^1.0.1",
@@ -47,5 +47,5 @@
47
47
  "jest": "^27.5.1",
48
48
  "start-server-and-test": "^1.14.0"
49
49
  },
50
- "gitHead": "55bd3460826600a3d7472c6529de1e101621d286"
50
+ "gitHead": "a8336aacf07904ff809bc3915ca44c52cfa68f6d"
51
51
  }