@ocap/tx-protocols 1.20.2 → 1.20.4
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/README.md +1 -1
- package/lib/execute.js +39 -29
- package/package.json +27 -25
package/README.md
CHANGED
package/lib/execute.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable consistent-return */
|
|
2
2
|
const get = require('lodash/get');
|
|
3
3
|
const pick = require('lodash/pick');
|
|
4
|
+
const merge = require('lodash/merge');
|
|
4
5
|
const camelCase = require('lodash/camelCase');
|
|
5
6
|
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
6
7
|
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
@@ -159,54 +160,60 @@ module.exports = ({ filter, runAsLambda }) => {
|
|
|
159
160
|
const startTime = Date.now();
|
|
160
161
|
|
|
161
162
|
try {
|
|
162
|
-
await runAsLambda(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
const txState = await runAsLambda(
|
|
164
|
+
async (txn) => {
|
|
165
|
+
// create a new context each time in case we are retrying
|
|
166
|
+
ctx = pick(context, ['txBase64', 'statedb', 'indexdb', 'config', 'states', 'filter', 'extra', 'logger']);
|
|
167
|
+
ctx.txn = txn;
|
|
166
168
|
|
|
167
|
-
|
|
169
|
+
await execute(ctx, protocols, true);
|
|
168
170
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
+
const state = context.states.tx.create(ctx, 'OK');
|
|
172
|
+
await context.statedb.tx.create(state.hash, state, ctx);
|
|
171
173
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
return state;
|
|
175
|
+
},
|
|
176
|
+
{ cleanWorkingSet: true, verifyHash: true }
|
|
177
|
+
);
|
|
174
178
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
// update indexdb after statedb commit
|
|
180
|
+
flushEvents(ctx, { txState });
|
|
181
|
+
|
|
182
|
+
ctx.logger?.info('Tx finalized', {
|
|
183
|
+
txHash: ctx.txHash,
|
|
184
|
+
txState,
|
|
185
|
+
txStatus: 'OK',
|
|
186
|
+
duration: Date.now() - startTime,
|
|
181
187
|
});
|
|
182
188
|
} catch (error) {
|
|
183
189
|
const txStatus = error.code || 'INTERNAL';
|
|
184
|
-
let txState = context.states.tx.create(ctx, txStatus, false);
|
|
190
|
+
let txState = ctx.tx ? context.states.tx.create(ctx, txStatus, false) : null;
|
|
185
191
|
|
|
186
192
|
ctx.logger?.error('Failed to execute transaction', { error, txHash: ctx.txHash, txState });
|
|
187
193
|
|
|
188
|
-
if (shouldPersistTx(error)) {
|
|
194
|
+
if (txState && shouldPersistTx(error)) {
|
|
189
195
|
try {
|
|
190
|
-
await runAsLambda(async (txn) => {
|
|
196
|
+
txState = await runAsLambda(async (txn) => {
|
|
191
197
|
ctx = Object.assign({}, ctx, { txn, cacheStates: null });
|
|
192
198
|
|
|
193
199
|
await ensureGasFeePaid(ctx);
|
|
194
200
|
|
|
195
201
|
// Recreate tx to pick up gas related fields
|
|
196
|
-
|
|
202
|
+
const state = context.states.tx.create(ctx, txStatus);
|
|
203
|
+
await ctx.statedb.tx.create(state.hash, state, ctx);
|
|
197
204
|
|
|
198
|
-
|
|
205
|
+
return state;
|
|
206
|
+
});
|
|
199
207
|
|
|
200
|
-
|
|
201
|
-
|
|
208
|
+
// update indexdb after statedb commit
|
|
209
|
+
flushEvents(ctx, { txState });
|
|
202
210
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
});
|
|
211
|
+
ctx.logger?.info('Tx finalized', {
|
|
212
|
+
txHash: ctx.txHash,
|
|
213
|
+
txState,
|
|
214
|
+
txStatus,
|
|
215
|
+
error,
|
|
216
|
+
duration: Date.now() - startTime,
|
|
210
217
|
});
|
|
211
218
|
} catch (err) {
|
|
212
219
|
ctx.logger?.error('Failed to save invalid transaction to statedb', {
|
|
@@ -221,6 +228,9 @@ module.exports = ({ filter, runAsLambda }) => {
|
|
|
221
228
|
}
|
|
222
229
|
|
|
223
230
|
throw error;
|
|
231
|
+
} finally {
|
|
232
|
+
// Merge new ctx to original context
|
|
233
|
+
merge(context, ctx);
|
|
224
234
|
}
|
|
225
235
|
|
|
226
236
|
return ctx;
|
package/package.json
CHANGED
|
@@ -3,41 +3,35 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.20.
|
|
6
|
+
"version": "1.20.4",
|
|
7
7
|
"description": "Predefined tx pipeline sets to execute certain type of transactions",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
10
10
|
"lib"
|
|
11
11
|
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"lint": "eslint tests lib",
|
|
14
|
-
"lint:fix": "eslint --fix tests lib",
|
|
15
|
-
"start": "node tools/start-chain.js",
|
|
16
|
-
"test": "jest --forceExit --detectOpenHandles",
|
|
17
|
-
"test:ci": "jest --forceExit --detectOpenHandles --coverage",
|
|
18
|
-
"coverage": "start-server-and-test start http://127.0.0.1:4001 test:ci"
|
|
19
|
-
},
|
|
20
12
|
"keywords": [],
|
|
21
13
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
22
14
|
"license": "MIT",
|
|
23
15
|
"dependencies": {
|
|
24
|
-
"@arcblock/did": "1.20.2",
|
|
25
|
-
"@arcblock/did-util": "1.20.2",
|
|
26
|
-
"@arcblock/jwt": "1.20.2",
|
|
27
|
-
"@arcblock/validator": "1.20.2",
|
|
28
|
-
"@ocap/asset": "1.20.2",
|
|
29
|
-
"@ocap/mcrypto": "1.20.2",
|
|
30
|
-
"@ocap/merkle-tree": "1.20.2",
|
|
31
|
-
"@ocap/message": "1.20.2",
|
|
32
|
-
"@ocap/state": "1.20.2",
|
|
33
|
-
"@ocap/tx-pipeline": "1.20.2",
|
|
34
|
-
"@ocap/util": "1.20.2",
|
|
35
|
-
"@ocap/wallet": "1.20.2",
|
|
36
16
|
"debug": "^4.3.6",
|
|
37
17
|
"deep-diff": "^1.0.2",
|
|
38
18
|
"empty-value": "^1.0.1",
|
|
39
19
|
"lodash": "^4.17.21",
|
|
40
|
-
"url-join": "^4.0.1"
|
|
20
|
+
"url-join": "^4.0.1",
|
|
21
|
+
"@arcblock/did": "1.20.4",
|
|
22
|
+
"@arcblock/did-util": "1.20.4",
|
|
23
|
+
"@arcblock/jwt": "1.20.4",
|
|
24
|
+
"@arcblock/validator": "1.20.4",
|
|
25
|
+
"@ocap/asset": "1.20.4",
|
|
26
|
+
"@ocap/mcrypto": "1.20.4",
|
|
27
|
+
"@ocap/merkle-tree": "1.20.4",
|
|
28
|
+
"@ocap/state": "1.20.4",
|
|
29
|
+
"@ocap/util": "1.20.4",
|
|
30
|
+
"@ocap/message": "1.20.4",
|
|
31
|
+
"@ocap/tx-pipeline": "1.20.4",
|
|
32
|
+
"@ocap/wallet": "1.20.4",
|
|
33
|
+
"@ocap/client": "1.20.4",
|
|
34
|
+
"@ocap/statedb-memory": "1.20.4"
|
|
41
35
|
},
|
|
42
36
|
"resolutions": {
|
|
43
37
|
"bn.js": "5.2.1",
|
|
@@ -45,7 +39,15 @@
|
|
|
45
39
|
},
|
|
46
40
|
"devDependencies": {
|
|
47
41
|
"jest": "^29.7.0",
|
|
48
|
-
"start-server-and-test": "^1.14.0"
|
|
42
|
+
"start-server-and-test": "^1.14.0",
|
|
43
|
+
"@ocap/e2e-test": "1.20.4"
|
|
49
44
|
},
|
|
50
|
-
"
|
|
51
|
-
|
|
45
|
+
"scripts": {
|
|
46
|
+
"lint": "eslint tests lib",
|
|
47
|
+
"lint:fix": "eslint --fix tests lib",
|
|
48
|
+
"start": "node tools/start-chain.js",
|
|
49
|
+
"test": "jest --forceExit --detectOpenHandles",
|
|
50
|
+
"test:ci": "jest --forceExit --detectOpenHandles --coverage",
|
|
51
|
+
"coverage": "start-server-and-test start http://127.0.0.1:4001 test:ci"
|
|
52
|
+
}
|
|
53
|
+
}
|