@ocap/tx-protocols 1.19.5 → 1.19.7
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.
|
@@ -41,16 +41,21 @@ runner.use(
|
|
|
41
41
|
);
|
|
42
42
|
|
|
43
43
|
// Ensure sender exist
|
|
44
|
-
runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: '
|
|
44
|
+
runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'OK', table: 'account' })); // prettier-ignore
|
|
45
45
|
runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
|
|
46
46
|
|
|
47
47
|
// Ensure tx fee and gas
|
|
48
48
|
runner.use(
|
|
49
49
|
EnsureTxGas((context) => {
|
|
50
|
-
return {
|
|
50
|
+
return {
|
|
51
|
+
create: context.senderState ? 1 : 2,
|
|
52
|
+
update: context.senderState ? getRelatedAddresses(context.senderState).length : 0,
|
|
53
|
+
payment: 0,
|
|
54
|
+
};
|
|
51
55
|
})
|
|
52
56
|
);
|
|
53
57
|
runner.use(EnsureTxCost({ attachSenderChanges: true, throwOnInsufficientFund: false }));
|
|
58
|
+
runner.use(pipes.VerifyGasPayer());
|
|
54
59
|
|
|
55
60
|
// Save context snapshot before updating states
|
|
56
61
|
runner.use(pipes.TakeStateSnapshot());
|
|
@@ -62,6 +67,8 @@ runner.use(
|
|
|
62
67
|
|
|
63
68
|
const sender = context.senderState;
|
|
64
69
|
const receiver = await statedb.account.get(itx.address, context);
|
|
70
|
+
const senderTokens = sender?.tokens || { [context.config.token.address]: '0' };
|
|
71
|
+
const senderAddress = sender?.address || tx.from;
|
|
65
72
|
|
|
66
73
|
// Ensure receiver does not exist
|
|
67
74
|
if (receiver) {
|
|
@@ -73,11 +80,11 @@ runner.use(
|
|
|
73
80
|
itx.address,
|
|
74
81
|
account.create(
|
|
75
82
|
{
|
|
76
|
-
...sender, // copy all old account data to new account
|
|
83
|
+
...(sender || { tokens: senderTokens }), // copy all old account data to new account
|
|
77
84
|
...senderUpdates,
|
|
78
85
|
address: itx.address,
|
|
79
86
|
pk: itx.pk,
|
|
80
|
-
migratedFrom: uniq(flatten([sender.address, ...sender.migratedFrom])),
|
|
87
|
+
migratedFrom: sender ? uniq(flatten([sender.address, ...sender.migratedFrom])) : [senderAddress],
|
|
81
88
|
},
|
|
82
89
|
context
|
|
83
90
|
),
|
|
@@ -86,18 +93,23 @@ runner.use(
|
|
|
86
93
|
debug('new account', newAccount);
|
|
87
94
|
|
|
88
95
|
// Update old accounts
|
|
89
|
-
const addresses = getRelatedAddresses(sender);
|
|
96
|
+
const addresses = sender ? getRelatedAddresses(sender) : [senderAddress];
|
|
90
97
|
const states = await Promise.all(
|
|
91
98
|
addresses.map(async (address) => {
|
|
92
99
|
let state = null;
|
|
93
|
-
if (address ===
|
|
94
|
-
state = account.
|
|
100
|
+
if (address === senderAddress) {
|
|
101
|
+
state = account.updateOrCreate(
|
|
102
|
+
sender,
|
|
103
|
+
{ address, tokens: senderTokens, migratedTo: itx.address, nonce: tx.nonce },
|
|
104
|
+
context
|
|
105
|
+
);
|
|
106
|
+
await statedb.account.updateOrCreate(sender, state, context);
|
|
95
107
|
} else {
|
|
96
108
|
const old = await statedb.account.get(address, { traceMigration: false, txn: context.txn });
|
|
97
109
|
state = account.update(old, { migratedTo: itx.address }, context);
|
|
110
|
+
await statedb.account.update(address, state, context);
|
|
98
111
|
}
|
|
99
112
|
|
|
100
|
-
await statedb.account.update(address, state, context);
|
|
101
113
|
return state;
|
|
102
114
|
})
|
|
103
115
|
);
|
|
@@ -107,7 +119,7 @@ runner.use(
|
|
|
107
119
|
|
|
108
120
|
// Update context
|
|
109
121
|
context.receiverState = newAccount;
|
|
110
|
-
context.senderState = states.find((x) => x.address ===
|
|
122
|
+
context.senderState = states.find((x) => x.address === senderAddress);
|
|
111
123
|
|
|
112
124
|
return next();
|
|
113
125
|
},
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.19.
|
|
6
|
+
"version": "1.19.7",
|
|
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.19.
|
|
25
|
-
"@arcblock/did-util": "1.19.
|
|
26
|
-
"@arcblock/jwt": "1.19.
|
|
27
|
-
"@arcblock/validator": "1.19.
|
|
28
|
-
"@ocap/asset": "1.19.
|
|
29
|
-
"@ocap/mcrypto": "1.19.
|
|
30
|
-
"@ocap/merkle-tree": "1.19.
|
|
31
|
-
"@ocap/message": "1.19.
|
|
32
|
-
"@ocap/state": "1.19.
|
|
33
|
-
"@ocap/tx-pipeline": "1.19.
|
|
34
|
-
"@ocap/util": "1.19.
|
|
35
|
-
"@ocap/wallet": "1.19.
|
|
24
|
+
"@arcblock/did": "1.19.7",
|
|
25
|
+
"@arcblock/did-util": "1.19.7",
|
|
26
|
+
"@arcblock/jwt": "1.19.7",
|
|
27
|
+
"@arcblock/validator": "1.19.7",
|
|
28
|
+
"@ocap/asset": "1.19.7",
|
|
29
|
+
"@ocap/mcrypto": "1.19.7",
|
|
30
|
+
"@ocap/merkle-tree": "1.19.7",
|
|
31
|
+
"@ocap/message": "1.19.7",
|
|
32
|
+
"@ocap/state": "1.19.7",
|
|
33
|
+
"@ocap/tx-pipeline": "1.19.7",
|
|
34
|
+
"@ocap/util": "1.19.7",
|
|
35
|
+
"@ocap/wallet": "1.19.7",
|
|
36
36
|
"debug": "^4.3.6",
|
|
37
37
|
"deep-diff": "^1.0.2",
|
|
38
38
|
"empty-value": "^1.0.1",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"jest": "^29.7.0",
|
|
48
48
|
"start-server-and-test": "^1.14.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "b3a8e11bd01dd1dc6e2d222bc7dd2476f278a9f7"
|
|
51
51
|
}
|