@ocap/tx-protocols 1.29.8 → 1.29.9
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/esm/execute.mjs +20 -0
- package/lib/execute.cjs +20 -0
- package/package.json +18 -18
package/esm/execute.mjs
CHANGED
|
@@ -143,6 +143,8 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
143
143
|
if (typeof runAsLambda === "function") return async (context, protocols) => {
|
|
144
144
|
let ctx = context;
|
|
145
145
|
context.timer = new TxTimer();
|
|
146
|
+
let entryFinalized = false;
|
|
147
|
+
let savedLedgerSequence;
|
|
146
148
|
try {
|
|
147
149
|
const txState = await runAsLambda(async (txn) => {
|
|
148
150
|
ctx = pick(context, [
|
|
@@ -160,6 +162,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
160
162
|
]);
|
|
161
163
|
ctx.txn = txn;
|
|
162
164
|
await execute(ctx, protocols, true);
|
|
165
|
+
if (ctx.ledgerSequence && !savedLedgerSequence) savedLedgerSequence = ctx.ledgerSequence;
|
|
163
166
|
const state = getStates(context).tx.create(ctx, "OK");
|
|
164
167
|
await context.statedb.tx.create(state.hash, state, ctx);
|
|
165
168
|
return state;
|
|
@@ -171,6 +174,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
171
174
|
if (ctx.txHash && ctx.ledger && ctx.ledgerSequence && ctx.txBase64) try {
|
|
172
175
|
await ctx.ledger.finalizeEntry(ctx.txHash, stateCommitHash || "", ctx.ledgerSequence, ctx.txBase64);
|
|
173
176
|
ctx.stateCommitHash = stateCommitHash || "";
|
|
177
|
+
entryFinalized = true;
|
|
174
178
|
} catch (err) {
|
|
175
179
|
ctx.logger?.error("Failed to finalize ledger entry", {
|
|
176
180
|
txHash: ctx.txHash,
|
|
@@ -225,6 +229,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
225
229
|
if (ctx.txHash && ctx.ledger && ctx.ledgerSequence && ctx.txBase64) try {
|
|
226
230
|
await ctx.ledger.finalizeEntry(ctx.txHash, stateCommitHash || "", ctx.ledgerSequence, ctx.txBase64);
|
|
227
231
|
ctx.stateCommitHash = stateCommitHash || "";
|
|
232
|
+
entryFinalized = true;
|
|
228
233
|
} catch (err$1) {
|
|
229
234
|
ctx.logger?.error("Failed to finalize ledger entry", {
|
|
230
235
|
txHash: ctx.txHash,
|
|
@@ -263,6 +268,21 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
263
268
|
}
|
|
264
269
|
throw error;
|
|
265
270
|
} finally {
|
|
271
|
+
if (!entryFinalized) {
|
|
272
|
+
const ledger = ctx.ledger || context.ledger;
|
|
273
|
+
const txHash = ctx.txHash || context.txHash;
|
|
274
|
+
const txBase64 = ctx.txBase64 || context.txBase64;
|
|
275
|
+
const sequence = ctx.ledgerSequence || savedLedgerSequence || context.ledgerSequence;
|
|
276
|
+
if (ledger && txHash && sequence && txBase64) try {
|
|
277
|
+
await ledger.finalizeEntry(txHash, "", sequence, txBase64);
|
|
278
|
+
} catch (err) {
|
|
279
|
+
(ctx.logger || context.logger)?.error("Failed to finalize orphaned ledger entry", {
|
|
280
|
+
txHash,
|
|
281
|
+
sequence,
|
|
282
|
+
error: err
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
266
286
|
merge(context, ctx);
|
|
267
287
|
}
|
|
268
288
|
return ctx;
|
package/lib/execute.cjs
CHANGED
|
@@ -149,6 +149,8 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
149
149
|
if (typeof runAsLambda === "function") return async (context, protocols) => {
|
|
150
150
|
let ctx = context;
|
|
151
151
|
context.timer = new require_tx_timer.TxTimer();
|
|
152
|
+
let entryFinalized = false;
|
|
153
|
+
let savedLedgerSequence;
|
|
152
154
|
try {
|
|
153
155
|
const txState = await runAsLambda(async (txn) => {
|
|
154
156
|
ctx = (0, lodash_pick.default)(context, [
|
|
@@ -166,6 +168,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
166
168
|
]);
|
|
167
169
|
ctx.txn = txn;
|
|
168
170
|
await execute(ctx, protocols, true);
|
|
171
|
+
if (ctx.ledgerSequence && !savedLedgerSequence) savedLedgerSequence = ctx.ledgerSequence;
|
|
169
172
|
const state = getStates(context).tx.create(ctx, "OK");
|
|
170
173
|
await context.statedb.tx.create(state.hash, state, ctx);
|
|
171
174
|
return state;
|
|
@@ -177,6 +180,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
177
180
|
if (ctx.txHash && ctx.ledger && ctx.ledgerSequence && ctx.txBase64) try {
|
|
178
181
|
await ctx.ledger.finalizeEntry(ctx.txHash, stateCommitHash || "", ctx.ledgerSequence, ctx.txBase64);
|
|
179
182
|
ctx.stateCommitHash = stateCommitHash || "";
|
|
183
|
+
entryFinalized = true;
|
|
180
184
|
} catch (err) {
|
|
181
185
|
ctx.logger?.error("Failed to finalize ledger entry", {
|
|
182
186
|
txHash: ctx.txHash,
|
|
@@ -231,6 +235,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
231
235
|
if (ctx.txHash && ctx.ledger && ctx.ledgerSequence && ctx.txBase64) try {
|
|
232
236
|
await ctx.ledger.finalizeEntry(ctx.txHash, stateCommitHash || "", ctx.ledgerSequence, ctx.txBase64);
|
|
233
237
|
ctx.stateCommitHash = stateCommitHash || "";
|
|
238
|
+
entryFinalized = true;
|
|
234
239
|
} catch (err$1) {
|
|
235
240
|
ctx.logger?.error("Failed to finalize ledger entry", {
|
|
236
241
|
txHash: ctx.txHash,
|
|
@@ -269,6 +274,21 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
269
274
|
}
|
|
270
275
|
throw error;
|
|
271
276
|
} finally {
|
|
277
|
+
if (!entryFinalized) {
|
|
278
|
+
const ledger = ctx.ledger || context.ledger;
|
|
279
|
+
const txHash = ctx.txHash || context.txHash;
|
|
280
|
+
const txBase64 = ctx.txBase64 || context.txBase64;
|
|
281
|
+
const sequence = ctx.ledgerSequence || savedLedgerSequence || context.ledgerSequence;
|
|
282
|
+
if (ledger && txHash && sequence && txBase64) try {
|
|
283
|
+
await ledger.finalizeEntry(txHash, "", sequence, txBase64);
|
|
284
|
+
} catch (err) {
|
|
285
|
+
(ctx.logger || context.logger)?.error("Failed to finalize orphaned ledger entry", {
|
|
286
|
+
txHash,
|
|
287
|
+
sequence,
|
|
288
|
+
error: err
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
272
292
|
(0, lodash_merge.default)(context, ctx);
|
|
273
293
|
}
|
|
274
294
|
return ctx;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.29.
|
|
6
|
+
"version": "1.29.9",
|
|
7
7
|
"description": "Predefined tx pipeline sets to execute certain type of transactions",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./lib/index.cjs",
|
|
@@ -46,22 +46,22 @@
|
|
|
46
46
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
47
47
|
"license": "MIT",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@arcblock/did": "1.29.
|
|
50
|
-
"@arcblock/did-util": "1.29.
|
|
51
|
-
"@arcblock/jwt": "1.29.
|
|
52
|
-
"@arcblock/validator": "1.29.
|
|
53
|
-
"@arcblock/vc": "1.29.
|
|
49
|
+
"@arcblock/did": "1.29.9",
|
|
50
|
+
"@arcblock/did-util": "1.29.9",
|
|
51
|
+
"@arcblock/jwt": "1.29.9",
|
|
52
|
+
"@arcblock/validator": "1.29.9",
|
|
53
|
+
"@arcblock/vc": "1.29.9",
|
|
54
54
|
"@blocklet/xss": "^0.3.7",
|
|
55
|
-
"@ocap/asset": "1.29.
|
|
56
|
-
"@ocap/client": "1.29.
|
|
57
|
-
"@ocap/mcrypto": "1.29.
|
|
58
|
-
"@ocap/merkle-tree": "1.29.
|
|
59
|
-
"@ocap/message": "1.29.
|
|
60
|
-
"@ocap/state": "1.29.
|
|
61
|
-
"@ocap/tx-pipeline": "1.29.
|
|
62
|
-
"@ocap/types": "1.29.
|
|
63
|
-
"@ocap/util": "1.29.
|
|
64
|
-
"@ocap/wallet": "1.29.
|
|
55
|
+
"@ocap/asset": "1.29.9",
|
|
56
|
+
"@ocap/client": "1.29.9",
|
|
57
|
+
"@ocap/mcrypto": "1.29.9",
|
|
58
|
+
"@ocap/merkle-tree": "1.29.9",
|
|
59
|
+
"@ocap/message": "1.29.9",
|
|
60
|
+
"@ocap/state": "1.29.9",
|
|
61
|
+
"@ocap/tx-pipeline": "1.29.9",
|
|
62
|
+
"@ocap/types": "1.29.9",
|
|
63
|
+
"@ocap/util": "1.29.9",
|
|
64
|
+
"@ocap/wallet": "1.29.9",
|
|
65
65
|
"debug": "^4.4.3",
|
|
66
66
|
"deep-diff": "^1.0.2",
|
|
67
67
|
"lodash": "^4.17.23",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"elliptic": "6.5.3"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@ocap/e2e-test": "1.29.
|
|
76
|
-
"@ocap/statedb-memory": "1.29.
|
|
75
|
+
"@ocap/e2e-test": "1.29.9",
|
|
76
|
+
"@ocap/statedb-memory": "1.29.9",
|
|
77
77
|
"@types/debug": "^4.1.12",
|
|
78
78
|
"@types/lodash": "^4.17.16",
|
|
79
79
|
"start-server-and-test": "^1.14.0"
|