@ocap/state 1.18.162 → 1.18.164
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/states/tx.js +37 -4
- 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,
|
|
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((
|
|
442
|
-
.map((
|
|
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.
|
|
6
|
+
"version": "1.18.164",
|
|
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.
|
|
22
|
-
"@arcblock/validator": "1.18.
|
|
23
|
-
"@ocap/contract": "1.18.
|
|
24
|
-
"@ocap/mcrypto": "1.18.
|
|
25
|
-
"@ocap/message": "1.18.
|
|
26
|
-
"@ocap/util": "1.18.
|
|
27
|
-
"@ocap/wallet": "1.18.
|
|
21
|
+
"@arcblock/did": "1.18.164",
|
|
22
|
+
"@arcblock/validator": "1.18.164",
|
|
23
|
+
"@ocap/contract": "1.18.164",
|
|
24
|
+
"@ocap/mcrypto": "1.18.164",
|
|
25
|
+
"@ocap/message": "1.18.164",
|
|
26
|
+
"@ocap/util": "1.18.164",
|
|
27
|
+
"@ocap/wallet": "1.18.164",
|
|
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": "
|
|
38
|
+
"gitHead": "f517d0620f7fb4acd26716ab76f68829587b6483"
|
|
39
39
|
}
|