@ocap/tx-protocols 1.23.0 → 1.23.1

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.
@@ -3,6 +3,7 @@ const { Joi, schemas } = require('@arcblock/validator');
3
3
  const { BN, fromUnitToToken } = require('@ocap/util');
4
4
  const { Runner, pipes } = require('@ocap/tx-pipeline');
5
5
  const { account, tokenFactory, token } = require('@ocap/state');
6
+ const pick = require('lodash/pick');
6
7
 
7
8
  const EnsureTxGas = require('../../pipes/ensure-gas');
8
9
  const EnsureTxCost = require('../../pipes/ensure-cost');
@@ -252,7 +253,7 @@ runner.use(
252
253
  }
253
254
  // Ensure the sender exists in accountUpdates, because even if there is no balance change, we need to update his nonce
254
255
  if (!accountUpdates[tx.from]) {
255
- accountUpdates[tx.from] = {};
256
+ accountUpdates[tx.from] = senderState || {};
256
257
  }
257
258
 
258
259
  // update owner
@@ -281,12 +282,14 @@ runner.use(
281
282
  // We can use updateOrCreate here because the owner and signer have already been validated to exist earlier,
282
283
  // the sender and receiver are allowed to be created in the transaction.
283
284
  const state = [senderState, receiverState, ownerState, ...signerStates].find((x) => x?.address === address);
284
- const senderUpdated = address === tx.from ? { nonce: tx.nonce, pk: tx.pk } : {};
285
- return statedb.account.updateOrCreate(
286
- state,
287
- account.updateOrCreate(state, Object.assign({ address }, senderUpdated, updates), context),
288
- context
289
- );
285
+
286
+ // Should only update nonce and pk for sender and new accounts
287
+ const actualUpdates =
288
+ address === tx.from || !state
289
+ ? { ...updates, address, nonce: tx.nonce, pk: tx.pk }
290
+ : pick(updates, ['tokens']);
291
+
292
+ return statedb.account.updateOrCreate(state, account.updateOrCreate(state, actualUpdates, context), context);
290
293
  })
291
294
  ),
292
295
 
@@ -3,6 +3,7 @@ const { Joi, schemas } = require('@arcblock/validator');
3
3
  const { BN, fromUnitToToken } = require('@ocap/util');
4
4
  const { Runner, pipes } = require('@ocap/tx-pipeline');
5
5
  const { account, tokenFactory, token } = require('@ocap/state');
6
+ const pick = require('lodash/pick');
6
7
 
7
8
  const EnsureTxGas = require('../../pipes/ensure-gas');
8
9
  const EnsureTxCost = require('../../pipes/ensure-cost');
@@ -237,7 +238,7 @@ runner.use(
237
238
  }
238
239
  // Ensure the sender exists in accountUpdates, because even if there is no balance change, we need to update his nonce
239
240
  if (!accountUpdates[tx.from]) {
240
- accountUpdates[tx.from] = {};
241
+ accountUpdates[tx.from] = senderState || {};
241
242
  }
242
243
 
243
244
  // update owner
@@ -266,12 +267,14 @@ runner.use(
266
267
  // We can use updateOrCreate here because the owner and signer have already been validated to exist earlier,
267
268
  // the sender and receiver are allowed to be created in the transaction.
268
269
  const state = [senderState, receiverState, ownerState, ...signerStates].find((x) => x?.address === address);
269
- const senderUpdated = address === tx.from ? { nonce: tx.nonce, pk: tx.pk } : {};
270
- return statedb.account.updateOrCreate(
271
- state,
272
- account.updateOrCreate(state, Object.assign({ address }, senderUpdated, updates), context),
273
- context
274
- );
270
+
271
+ // Should only update nonce and pk for sender and new accounts
272
+ const actualUpdates =
273
+ address === tx.from || !state
274
+ ? { ...updates, address, nonce: tx.nonce, pk: tx.pk }
275
+ : pick(updates, ['tokens']);
276
+
277
+ return statedb.account.updateOrCreate(state, account.updateOrCreate(state, actualUpdates, context), context);
275
278
  })
276
279
  ),
277
280
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.23.0",
6
+ "version": "1.23.1",
7
7
  "description": "Predefined tx pipeline sets to execute certain type of transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,19 +18,19 @@
18
18
  "empty-value": "^1.0.1",
19
19
  "lodash": "^4.17.21",
20
20
  "url-join": "^4.0.1",
21
- "@arcblock/did": "1.23.0",
22
- "@arcblock/did-util": "1.23.0",
23
- "@arcblock/jwt": "1.23.0",
24
- "@arcblock/validator": "1.23.0",
25
- "@ocap/asset": "1.23.0",
26
- "@ocap/client": "1.23.0",
27
- "@ocap/mcrypto": "1.23.0",
28
- "@ocap/merkle-tree": "1.23.0",
29
- "@ocap/message": "1.23.0",
30
- "@ocap/state": "1.23.0",
31
- "@ocap/tx-pipeline": "1.23.0",
32
- "@ocap/util": "1.23.0",
33
- "@ocap/wallet": "1.23.0"
21
+ "@arcblock/did": "1.23.1",
22
+ "@arcblock/did-util": "1.23.1",
23
+ "@arcblock/jwt": "1.23.1",
24
+ "@arcblock/validator": "1.23.1",
25
+ "@ocap/asset": "1.23.1",
26
+ "@ocap/client": "1.23.1",
27
+ "@ocap/mcrypto": "1.23.1",
28
+ "@ocap/merkle-tree": "1.23.1",
29
+ "@ocap/message": "1.23.1",
30
+ "@ocap/state": "1.23.1",
31
+ "@ocap/tx-pipeline": "1.23.1",
32
+ "@ocap/util": "1.23.1",
33
+ "@ocap/wallet": "1.23.1"
34
34
  },
35
35
  "resolutions": {
36
36
  "bn.js": "5.2.1",
@@ -39,8 +39,8 @@
39
39
  "devDependencies": {
40
40
  "jest": "^29.7.0",
41
41
  "start-server-and-test": "^1.14.0",
42
- "@ocap/e2e-test": "1.23.0",
43
- "@ocap/statedb-memory": "1.23.0"
42
+ "@ocap/e2e-test": "1.23.1",
43
+ "@ocap/statedb-memory": "1.23.1"
44
44
  },
45
45
  "scripts": {
46
46
  "lint": "eslint tests lib",