@ocap/tx-protocols 1.29.4 → 1.29.6
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.d.mts +5 -0
- package/esm/execute.mjs +61 -4
- package/esm/index.d.mts +737 -73
- package/esm/index.mjs +2 -1
- package/esm/pipes/write-ledger.d.mts +73 -0
- package/esm/pipes/write-ledger.mjs +97 -0
- package/esm/protocols/account/delegate.d.mts +52 -1
- package/esm/protocols/account/migrate.d.mts +15 -1
- package/esm/protocols/account/revoke-delegate.d.mts +14 -1
- package/esm/protocols/asset/acquire-v2.d.mts +39 -1
- package/esm/protocols/asset/acquire-v3.d.mts +43 -1
- package/esm/protocols/asset/calls/transfer-token.d.mts +4 -1
- package/esm/protocols/asset/calls/transfer.d.mts +4 -1
- package/esm/protocols/asset/consume.d.mts +14 -1
- package/esm/protocols/asset/create.d.mts +23 -1
- package/esm/protocols/asset/mint.d.mts +28 -1
- package/esm/protocols/asset/update.d.mts +15 -1
- package/esm/protocols/factory/create.d.mts +23 -1
- package/esm/protocols/governance/claim-stake.d.mts +24 -1
- package/esm/protocols/governance/return-stake.d.mts +20 -1
- package/esm/protocols/governance/revoke-stake.d.mts +20 -1
- package/esm/protocols/governance/slash-stake.d.mts +30 -1
- package/esm/protocols/governance/stake.d.mts +27 -1
- package/esm/protocols/rollup/claim-reward.d.mts +57 -1
- package/esm/protocols/rollup/close.d.mts +16 -1
- package/esm/protocols/rollup/create-block.d.mts +42 -1
- package/esm/protocols/rollup/create.d.mts +28 -1
- package/esm/protocols/rollup/join.d.mts +18 -1
- package/esm/protocols/rollup/leave.d.mts +16 -1
- package/esm/protocols/rollup/migrate.d.mts +11 -1
- package/esm/protocols/rollup/pause.d.mts +11 -1
- package/esm/protocols/rollup/resume.d.mts +11 -1
- package/esm/protocols/rollup/update.d.mts +11 -1
- package/esm/protocols/token/create.d.mts +14 -1
- package/esm/protocols/token/deposit-v2.d.mts +23 -1
- package/esm/protocols/token/withdraw-v2.d.mts +33 -1
- package/esm/protocols/token-factory/burn.d.mts +29 -1
- package/esm/protocols/token-factory/create.d.mts +16 -1
- package/esm/protocols/token-factory/mint.d.mts +27 -1
- package/esm/protocols/token-factory/update.d.mts +15 -1
- package/esm/protocols/trade/exchange-v2.d.mts +40 -1
- package/esm/protocols/trade/transfer-v2.d.mts +32 -1
- package/esm/protocols/trade/transfer-v3.d.mts +31 -1
- package/esm/util.d.mts +1 -1
- package/lib/execute.cjs +61 -4
- package/lib/execute.d.cts +5 -0
- package/lib/index.cjs +2 -0
- package/lib/index.d.cts +737 -73
- package/lib/pipes/write-ledger.cjs +102 -0
- package/lib/pipes/write-ledger.d.cts +73 -0
- package/lib/protocols/account/delegate.d.cts +52 -1
- package/lib/protocols/account/migrate.d.cts +15 -1
- package/lib/protocols/account/revoke-delegate.d.cts +14 -1
- package/lib/protocols/asset/acquire-v2.d.cts +39 -1
- package/lib/protocols/asset/acquire-v3.d.cts +43 -1
- package/lib/protocols/asset/calls/transfer-token.d.cts +4 -1
- package/lib/protocols/asset/calls/transfer.d.cts +4 -1
- package/lib/protocols/asset/consume.d.cts +14 -1
- package/lib/protocols/asset/create.d.cts +23 -1
- package/lib/protocols/asset/mint.d.cts +28 -1
- package/lib/protocols/asset/update.d.cts +15 -1
- package/lib/protocols/factory/create.d.cts +23 -1
- package/lib/protocols/governance/claim-stake.d.cts +24 -1
- package/lib/protocols/governance/return-stake.d.cts +20 -1
- package/lib/protocols/governance/revoke-stake.d.cts +20 -1
- package/lib/protocols/governance/slash-stake.d.cts +30 -1
- package/lib/protocols/governance/stake.d.cts +27 -1
- package/lib/protocols/rollup/claim-reward.d.cts +57 -1
- package/lib/protocols/rollup/close.d.cts +16 -1
- package/lib/protocols/rollup/create-block.d.cts +42 -1
- package/lib/protocols/rollup/create.d.cts +28 -1
- package/lib/protocols/rollup/join.d.cts +18 -1
- package/lib/protocols/rollup/leave.d.cts +16 -1
- package/lib/protocols/rollup/migrate.d.cts +11 -1
- package/lib/protocols/rollup/pause.d.cts +11 -1
- package/lib/protocols/rollup/resume.d.cts +11 -1
- package/lib/protocols/rollup/update.d.cts +11 -1
- package/lib/protocols/token/create.d.cts +14 -1
- package/lib/protocols/token/deposit-v2.d.cts +23 -1
- package/lib/protocols/token/withdraw-v2.d.cts +33 -1
- package/lib/protocols/token-factory/burn.d.cts +29 -1
- package/lib/protocols/token-factory/create.d.cts +16 -1
- package/lib/protocols/token-factory/mint.d.cts +27 -1
- package/lib/protocols/token-factory/update.d.cts +15 -1
- package/lib/protocols/trade/exchange-v2.d.cts +40 -1
- package/lib/protocols/trade/transfer-v2.d.cts +32 -1
- package/lib/protocols/trade/transfer-v3.d.cts +31 -1
- package/lib/util.d.cts +2 -2
- package/package.json +20 -19
package/esm/execute.d.mts
CHANGED
|
@@ -27,6 +27,10 @@ interface IExecutionContext extends IGasContext {
|
|
|
27
27
|
txn?: unknown;
|
|
28
28
|
cacheStates?: unknown;
|
|
29
29
|
senderState?: IAccountState;
|
|
30
|
+
/** Ledger sequence number set by WriteLedger pipe */
|
|
31
|
+
ledgerSequence?: number;
|
|
32
|
+
/** State commit hash set by onCommit callback (Dolt only) */
|
|
33
|
+
stateCommitHash?: string;
|
|
30
34
|
}
|
|
31
35
|
/** Protocol runner interface */
|
|
32
36
|
interface IProtocolRunner {
|
|
@@ -41,6 +45,7 @@ interface IExecuteOptions {
|
|
|
41
45
|
cleanWorkingSet: boolean;
|
|
42
46
|
verifyHash: boolean;
|
|
43
47
|
context: IExecutionContext;
|
|
48
|
+
onCommit?: (commitHash?: string) => void | Promise<void>;
|
|
44
49
|
}) => Promise<T>;
|
|
45
50
|
}
|
|
46
51
|
/** Execute function type */
|
package/esm/execute.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ensure_cost_default from "./pipes/ensure-cost.mjs";
|
|
2
2
|
import ensure_gas_default from "./pipes/ensure-gas.mjs";
|
|
3
|
+
import { WriteLedger } from "./pipes/write-ledger.mjs";
|
|
3
4
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
4
5
|
import { CustomError } from "@ocap/util/lib/error";
|
|
5
6
|
import camelCase from "lodash/camelCase.js";
|
|
@@ -52,6 +53,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
52
53
|
});
|
|
53
54
|
pre.use(pipes.VerifyTxSize);
|
|
54
55
|
pre.use(pipes.VerifySignature);
|
|
56
|
+
pre.use(WriteLedger);
|
|
55
57
|
const ensureGasFeePaid = (context) => {
|
|
56
58
|
const gasRunner = new Runner("ensure-gas-fee-paid");
|
|
57
59
|
gasRunner.use(ensureTxGas);
|
|
@@ -142,11 +144,13 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
142
144
|
"txBase64",
|
|
143
145
|
"statedb",
|
|
144
146
|
"indexdb",
|
|
147
|
+
"ledger",
|
|
145
148
|
"config",
|
|
146
149
|
"states",
|
|
147
150
|
"filter",
|
|
148
151
|
"extra",
|
|
149
|
-
"logger"
|
|
152
|
+
"logger",
|
|
153
|
+
"ledgerSequence"
|
|
150
154
|
]);
|
|
151
155
|
ctx.txn = txn;
|
|
152
156
|
await execute(ctx, protocols, true);
|
|
@@ -156,9 +160,27 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
156
160
|
}, {
|
|
157
161
|
cleanWorkingSet: true,
|
|
158
162
|
verifyHash: true,
|
|
159
|
-
context: ctx
|
|
163
|
+
context: ctx,
|
|
164
|
+
onCommit: async (stateCommitHash) => {
|
|
165
|
+
if (ctx.txHash && ctx.ledger && ctx.ledgerSequence && ctx.txBase64) try {
|
|
166
|
+
await ctx.ledger.finalizeEntry(ctx.txHash, stateCommitHash || "", ctx.ledgerSequence, ctx.txBase64);
|
|
167
|
+
ctx.stateCommitHash = stateCommitHash || "";
|
|
168
|
+
} catch (err) {
|
|
169
|
+
ctx.logger?.error("Failed to finalize ledger entry", {
|
|
170
|
+
txHash: ctx.txHash,
|
|
171
|
+
stateCommitHash,
|
|
172
|
+
error: err
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
160
176
|
});
|
|
161
177
|
flushEvents(ctx, { txState });
|
|
178
|
+
ctx.ledger?.createCheckpointIfNeeded()?.catch((err) => {
|
|
179
|
+
ctx.logger?.error("Background checkpoint creation failed", {
|
|
180
|
+
txHash: ctx.txHash,
|
|
181
|
+
error: err
|
|
182
|
+
});
|
|
183
|
+
});
|
|
162
184
|
ctx.logger?.info("Tx finalized", {
|
|
163
185
|
txHash: ctx.txHash,
|
|
164
186
|
txState,
|
|
@@ -190,9 +212,27 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
190
212
|
}, {
|
|
191
213
|
cleanWorkingSet: true,
|
|
192
214
|
verifyHash: true,
|
|
193
|
-
context: ctx
|
|
215
|
+
context: ctx,
|
|
216
|
+
onCommit: async (stateCommitHash) => {
|
|
217
|
+
if (ctx.txHash && ctx.ledger && ctx.ledgerSequence && ctx.txBase64) try {
|
|
218
|
+
await ctx.ledger.finalizeEntry(ctx.txHash, stateCommitHash || "", ctx.ledgerSequence, ctx.txBase64);
|
|
219
|
+
ctx.stateCommitHash = stateCommitHash || "";
|
|
220
|
+
} catch (err$1) {
|
|
221
|
+
ctx.logger?.error("Failed to finalize ledger entry", {
|
|
222
|
+
txHash: ctx.txHash,
|
|
223
|
+
stateCommitHash,
|
|
224
|
+
error: err$1
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
194
228
|
});
|
|
195
229
|
flushEvents(ctx, { txState });
|
|
230
|
+
ctx.ledger?.createCheckpointIfNeeded()?.catch((err$1) => {
|
|
231
|
+
ctx.logger?.error("Background checkpoint creation failed", {
|
|
232
|
+
txHash: ctx.txHash,
|
|
233
|
+
error: err$1
|
|
234
|
+
});
|
|
235
|
+
});
|
|
196
236
|
ctx.logger?.info("Tx finalized", {
|
|
197
237
|
txHash: ctx.txHash,
|
|
198
238
|
txState,
|
|
@@ -217,7 +257,24 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
217
257
|
}
|
|
218
258
|
return ctx;
|
|
219
259
|
};
|
|
220
|
-
return
|
|
260
|
+
return async (context, protocols) => {
|
|
261
|
+
const result = await execute(context, protocols);
|
|
262
|
+
if (result.ledger && result.txHash && result.ledgerSequence && result.txBase64) try {
|
|
263
|
+
await result.ledger.finalizeEntry(result.txHash, "", result.ledgerSequence, result.txBase64);
|
|
264
|
+
} catch (err) {
|
|
265
|
+
result.logger?.error("Failed to finalize ledger entry (fallback)", {
|
|
266
|
+
txHash: result.txHash,
|
|
267
|
+
error: err
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
result.ledger?.createCheckpointIfNeeded()?.catch((err) => {
|
|
271
|
+
result.logger?.error("Background checkpoint creation failed", {
|
|
272
|
+
txHash: result.txHash,
|
|
273
|
+
error: err
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
return result;
|
|
277
|
+
};
|
|
221
278
|
};
|
|
222
279
|
var execute_default = createExecute;
|
|
223
280
|
|