@ocap/state 1.18.161 → 1.18.163

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.
Files changed (2) hide show
  1. package/lib/states/tx.js +37 -4
  2. package/package.json +9 -9
package/lib/states/tx.js CHANGED
@@ -18,6 +18,34 @@ const FORGE_TOKEN_HOLDER = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz';
18
18
  const FORGE_FEE_RECEIVER = 'z1EJUBdbPYqMiWHfRZvSAvbYeWcEHB19Xyfc';
19
19
  const QLDB_MIGRATION_TIME = new Date('2021-05-03T12:46:56.245Z');
20
20
 
21
+ function eachReceipts(receipts, callback) {
22
+ (receipts || []).forEach((receipt) => {
23
+ (receipt.changes || []).forEach((change) => {
24
+ callback(receipt.address, change);
25
+ });
26
+ });
27
+ }
28
+
29
+ function groupReceiptTokenChanges(receipts) {
30
+ /**
31
+ * Map of address to token changes
32
+ * @type {Record<string, {[tokenAddress: string]: string}>}
33
+ */
34
+ const tokenChanges = {};
35
+ // get token changes for each account by receipts
36
+ eachReceipts(receipts || [], (address, change) => {
37
+ if (toTypeInfo(change.target).role !== RoleType.ROLE_TOKEN) return;
38
+ if (change.value === '0') return;
39
+ if (!tokenChanges[address]) {
40
+ tokenChanges[address] = {};
41
+ }
42
+ const tokenChange = tokenChanges[address];
43
+ tokenChange[change.target] = new BN(tokenChange[change.target] || 0).add(new BN(change.value)).toString();
44
+ });
45
+
46
+ return tokenChanges;
47
+ }
48
+
21
49
  // Receiver = Whose asset have net gain
22
50
  const getTxReceiver = ({ tx, itx, typeUrl }) => {
23
51
  switch (typeUrl) {
@@ -433,13 +461,15 @@ const getRetrieveSwapReceipts = (tx) => [
433
461
  },
434
462
  ];
435
463
 
436
- const getMigrateReceipts = (tx, { fromState }) => {
464
+ const getMigrateReceipts = (tx, context) => {
465
+ const fromState = context.fromState || context.senderState;
466
+
437
467
  if (!fromState?.tokens) return [];
438
468
  if (!tx.itxJson?.address) return [];
439
469
 
440
- const changes = fromState.tokens
441
- .filter((x) => x.value && x.value !== '0')
442
- .map((x) => ({ target: x.address, action: 'migrate', value: x.value }));
470
+ const changes = Object.entries(fromState.tokens)
471
+ .filter(([, value]) => value && value !== '0')
472
+ .map(([address, value]) => ({ target: address, action: 'migrate', value }));
443
473
 
444
474
  return changes.length
445
475
  ? [
@@ -456,6 +486,7 @@ const getDeclareReceipts = (tx, { config, time }) => {
456
486
 
457
487
  if (!tx.itxJson?.issuer) return [];
458
488
  if (!config?.token) return [];
489
+ if (!time) return [];
459
490
  if (txTime >= QLDB_MIGRATION_TIME) return [];
460
491
 
461
492
  const gas = fromTokenToUnit('0.5', config.token.decimal);
@@ -766,5 +797,7 @@ module.exports = {
766
797
  mergeTxReceipts,
767
798
  attachPaidTxGas,
768
799
  verifyTxReceipts,
800
+ eachReceipts,
801
+ groupReceiptTokenChanges,
769
802
  FORGE_TOKEN_HOLDER,
770
803
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.161",
6
+ "version": "1.18.163",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,13 +18,13 @@
18
18
  "coverage": "start-server-and-test start http://127.0.0.1:4001 test:ci"
19
19
  },
20
20
  "dependencies": {
21
- "@arcblock/did": "1.18.161",
22
- "@arcblock/validator": "1.18.161",
23
- "@ocap/contract": "1.18.161",
24
- "@ocap/mcrypto": "1.18.161",
25
- "@ocap/message": "1.18.161",
26
- "@ocap/util": "1.18.161",
27
- "@ocap/wallet": "1.18.161",
21
+ "@arcblock/did": "1.18.163",
22
+ "@arcblock/validator": "1.18.163",
23
+ "@ocap/contract": "1.18.163",
24
+ "@ocap/mcrypto": "1.18.163",
25
+ "@ocap/message": "1.18.163",
26
+ "@ocap/util": "1.18.163",
27
+ "@ocap/wallet": "1.18.163",
28
28
  "bloom-filters": "^1.3.9",
29
29
  "lodash": "^4.17.21"
30
30
  },
@@ -35,5 +35,5 @@
35
35
  "keywords": [],
36
36
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
37
37
  "license": "MIT",
38
- "gitHead": "5d8436fdf5218fcbf2218b77ae370d50617ba3d0"
38
+ "gitHead": "c4bb7fae24dbac7a56ffbb84d19f64b90ea770b7"
39
39
  }