@ocap/tx-protocols 1.30.24 → 1.30.25
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 +6 -2
- package/esm/execute.mjs +214 -25
- package/esm/index.d.mts +25 -2
- package/esm/index.mjs +2 -2
- package/esm/pipes/ensure-cost.mjs +2 -2
- package/esm/pipes/write-ledger.mjs +7 -0
- package/esm/protocols/account/delegate.mjs +7 -6
- package/esm/protocols/account/migrate.mjs +2 -2
- package/esm/protocols/account/revoke-delegate.mjs +1 -1
- package/esm/protocols/asset/acquire-v2.mjs +25 -6
- package/esm/protocols/asset/acquire-v3.d.mts +11 -1
- package/esm/protocols/asset/acquire-v3.mjs +78 -9
- package/esm/protocols/asset/consume.mjs +1 -1
- package/esm/protocols/asset/create.mjs +1 -1
- package/esm/protocols/asset/mint.mjs +8 -2
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +1 -1
- package/esm/protocols/asset/update.mjs +1 -1
- package/esm/protocols/factory/create.mjs +4 -3
- package/esm/protocols/governance/claim-stake.mjs +2 -2
- package/esm/protocols/governance/return-stake.mjs +2 -2
- package/esm/protocols/governance/revoke-stake.mjs +2 -2
- package/esm/protocols/governance/slash-stake.mjs +2 -2
- package/esm/protocols/governance/stake.mjs +2 -2
- package/esm/protocols/rollup/claim-reward.mjs +5 -4
- package/esm/protocols/rollup/close.mjs +1 -1
- package/esm/protocols/rollup/create-block.mjs +1 -1
- package/esm/protocols/rollup/create.mjs +1 -1
- package/esm/protocols/rollup/join.mjs +2 -2
- package/esm/protocols/rollup/leave.mjs +1 -1
- package/esm/protocols/rollup/migrate.mjs +1 -1
- package/esm/protocols/rollup/pause.mjs +1 -1
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +5 -2
- package/esm/protocols/rollup/pipes/verify-signers.mjs +5 -3
- package/esm/protocols/rollup/resume.mjs +1 -1
- package/esm/protocols/rollup/update.mjs +4 -4
- package/esm/protocols/token/create.mjs +2 -2
- package/esm/protocols/token/deposit-v2.mjs +2 -2
- package/esm/protocols/token/withdraw-v2.mjs +13 -9
- package/esm/protocols/token-factory/burn.mjs +4 -4
- package/esm/protocols/token-factory/create.mjs +2 -2
- package/esm/protocols/token-factory/mint.mjs +2 -2
- package/esm/protocols/token-factory/update.mjs +7 -5
- package/esm/protocols/trade/exchange-v2.d.mts +3 -1
- package/esm/protocols/trade/exchange-v2.mjs +69 -11
- package/esm/protocols/trade/transfer-v2.mjs +39 -23
- package/esm/protocols/trade/transfer-v3.d.mts +11 -1
- package/esm/protocols/trade/transfer-v3.mjs +102 -11
- package/esm/tx-timer.d.mts +5 -0
- package/esm/tx-timer.mjs +13 -0
- package/esm/util.mjs +2 -1
- package/lib/execute.cjs +211 -20
- package/lib/execute.d.cts +6 -2
- package/lib/index.cjs +3 -1
- package/lib/index.d.cts +25 -2
- package/lib/pipes/ensure-cost.cjs +2 -2
- package/lib/pipes/write-ledger.cjs +7 -0
- package/lib/protocols/account/delegate.cjs +7 -6
- package/lib/protocols/account/migrate.cjs +2 -2
- package/lib/protocols/account/revoke-delegate.cjs +1 -1
- package/lib/protocols/asset/acquire-v2.cjs +24 -5
- package/lib/protocols/asset/acquire-v3.cjs +77 -8
- package/lib/protocols/asset/acquire-v3.d.cts +11 -1
- package/lib/protocols/asset/consume.cjs +1 -1
- package/lib/protocols/asset/create.cjs +1 -1
- package/lib/protocols/asset/mint.cjs +7 -1
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +1 -1
- package/lib/protocols/asset/update.cjs +1 -1
- package/lib/protocols/factory/create.cjs +4 -3
- package/lib/protocols/governance/claim-stake.cjs +2 -2
- package/lib/protocols/governance/return-stake.cjs +2 -2
- package/lib/protocols/governance/revoke-stake.cjs +2 -2
- package/lib/protocols/governance/slash-stake.cjs +2 -2
- package/lib/protocols/governance/stake.cjs +2 -2
- package/lib/protocols/rollup/claim-reward.cjs +5 -4
- package/lib/protocols/rollup/close.cjs +1 -1
- package/lib/protocols/rollup/create-block.cjs +1 -1
- package/lib/protocols/rollup/create.cjs +1 -1
- package/lib/protocols/rollup/join.cjs +2 -2
- package/lib/protocols/rollup/leave.cjs +1 -1
- package/lib/protocols/rollup/migrate.cjs +1 -1
- package/lib/protocols/rollup/pause.cjs +1 -1
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +5 -2
- package/lib/protocols/rollup/pipes/verify-signers.cjs +5 -4
- package/lib/protocols/rollup/resume.cjs +1 -1
- package/lib/protocols/rollup/update.cjs +4 -4
- package/lib/protocols/token/create.cjs +2 -2
- package/lib/protocols/token/deposit-v2.cjs +2 -2
- package/lib/protocols/token/withdraw-v2.cjs +13 -9
- package/lib/protocols/token-factory/burn.cjs +4 -4
- package/lib/protocols/token-factory/create.cjs +2 -2
- package/lib/protocols/token-factory/mint.cjs +2 -2
- package/lib/protocols/token-factory/update.cjs +7 -5
- package/lib/protocols/trade/exchange-v2.cjs +68 -10
- package/lib/protocols/trade/exchange-v2.d.cts +3 -1
- package/lib/protocols/trade/transfer-v2.cjs +39 -23
- package/lib/protocols/trade/transfer-v3.cjs +101 -10
- package/lib/protocols/trade/transfer-v3.d.cts +11 -1
- package/lib/tx-timer.cjs +13 -0
- package/lib/tx-timer.d.cts +5 -0
- package/lib/util.cjs +2 -1
- package/package.json +16 -16
package/lib/execute.cjs
CHANGED
|
@@ -4,7 +4,10 @@ const require_pipes_ensure_cost = require('./pipes/ensure-cost.cjs');
|
|
|
4
4
|
const require_pipes_ensure_gas = require('./pipes/ensure-gas.cjs');
|
|
5
5
|
const require_pipes_write_ledger = require('./pipes/write-ledger.cjs');
|
|
6
6
|
const require_tx_timer = require('./tx-timer.cjs');
|
|
7
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
8
|
+
let _ocap_state = require("@ocap/state");
|
|
7
9
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
|
+
let _ocap_util = require("@ocap/util");
|
|
8
11
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
9
12
|
let lodash_camelCase = require("lodash/camelCase");
|
|
10
13
|
lodash_camelCase = require_rolldown_runtime.__toESM(lodash_camelCase);
|
|
@@ -43,8 +46,119 @@ const flushEvents = (context, extra = {}) => {
|
|
|
43
46
|
context.events = [];
|
|
44
47
|
};
|
|
45
48
|
const shouldPersistTx = (err) => !err || Boolean((0, lodash_get.default)(err, "props.persist"));
|
|
49
|
+
const toUnsignedEvidenceKey = (unsignedTxHash) => (0, _ocap_mcrypto.toTxHash)(Buffer.from(`unsigned-tx:${unsignedTxHash}`));
|
|
50
|
+
const UNSIGNED_TX_EVIDENCE_DATA_PREFIX = "unsigned-tx:";
|
|
51
|
+
const hasEvidenceStore = (statedb) => Boolean(statedb && typeof statedb.evidence?.get === "function" && typeof statedb.evidence?.create === "function");
|
|
52
|
+
const stateDbSyncMap = /* @__PURE__ */ new WeakMap();
|
|
53
|
+
const getOrCreateSyncState = (target) => {
|
|
54
|
+
let state = stateDbSyncMap.get(target);
|
|
55
|
+
if (!state) {
|
|
56
|
+
state = {
|
|
57
|
+
inFlightUnsignedTxHashes: /* @__PURE__ */ new Map(),
|
|
58
|
+
inFlightTxHashes: /* @__PURE__ */ new Map(),
|
|
59
|
+
preWriteLockPromise: Promise.resolve()
|
|
60
|
+
};
|
|
61
|
+
stateDbSyncMap.set(target, state);
|
|
62
|
+
}
|
|
63
|
+
return state;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Determine whether `unsignedTxHash` deduplication in `statedb.evidence` is active
|
|
67
|
+
* for the current execution context.
|
|
68
|
+
*/
|
|
69
|
+
const isUnsignedDedupActive = async (context) => {
|
|
70
|
+
if (!context.unsignedTxHash) return false;
|
|
71
|
+
return (0, _ocap_tx_pipeline.isDedupHeightActive)(context);
|
|
72
|
+
};
|
|
46
73
|
const createExecute = ({ filter, runAsLambda }) => {
|
|
74
|
+
const fallbackSyncTarget = {};
|
|
75
|
+
const getSyncState = (context) => {
|
|
76
|
+
return getOrCreateSyncState((context?.statedb && typeof context.statedb === "object" ? context.statedb : null) || (context?.ledger && typeof context.ledger === "object" ? context.ledger : null) || fallbackSyncTarget);
|
|
77
|
+
};
|
|
78
|
+
const withPreWriteLock = async (context, fn) => {
|
|
79
|
+
const syncState = getSyncState(context);
|
|
80
|
+
const prev = syncState.preWriteLockPromise;
|
|
81
|
+
let release;
|
|
82
|
+
syncState.preWriteLockPromise = new Promise((r) => {
|
|
83
|
+
release = r;
|
|
84
|
+
});
|
|
85
|
+
await prev;
|
|
86
|
+
try {
|
|
87
|
+
return await fn();
|
|
88
|
+
} finally {
|
|
89
|
+
release();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const releaseInFlight = (execId, ...contexts) => {
|
|
93
|
+
for (const c of contexts) {
|
|
94
|
+
const syncState = getSyncState(c);
|
|
95
|
+
if (c?.txHash && syncState.inFlightTxHashes.get(c.txHash) === execId) syncState.inFlightTxHashes.delete(c.txHash);
|
|
96
|
+
if (c?.unsignedTxHash && syncState.inFlightUnsignedTxHashes.get(c.unsignedTxHash) === execId) syncState.inFlightUnsignedTxHashes.delete(c.unsignedTxHash);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const runSinglePipe = (pipeFn, ctx) => new Promise((resolve, reject) => {
|
|
100
|
+
Promise.resolve(pipeFn(ctx, (err) => {
|
|
101
|
+
if (err) return reject(err);
|
|
102
|
+
resolve();
|
|
103
|
+
})).catch(reject);
|
|
104
|
+
});
|
|
105
|
+
const hasCommittedUnsignedTx = async (context) => {
|
|
106
|
+
if (!context.unsignedTxHash || !hasEvidenceStore(context.statedb)) return false;
|
|
107
|
+
const unsignedKey = toUnsignedEvidenceKey(context.unsignedTxHash);
|
|
108
|
+
const exist = await context.statedb.evidence.get(unsignedKey, { txn: context.txn });
|
|
109
|
+
return Boolean(exist);
|
|
110
|
+
};
|
|
111
|
+
const recordUnsignedTxInStateDb = async (context, txHash) => {
|
|
112
|
+
if (!context.unsignedTxHash || !hasEvidenceStore(context.statedb)) return;
|
|
113
|
+
if (!await isUnsignedDedupActive(context)) return;
|
|
114
|
+
const unsignedKey = toUnsignedEvidenceKey(context.unsignedTxHash);
|
|
115
|
+
if (!await context.statedb.evidence.get(unsignedKey, { txn: context.txn })) {
|
|
116
|
+
const evState = _ocap_state.evidence.create({
|
|
117
|
+
hash: unsignedKey,
|
|
118
|
+
data: `${UNSIGNED_TX_EVIDENCE_DATA_PREFIX}${txHash}`
|
|
119
|
+
}, {
|
|
120
|
+
txHash,
|
|
121
|
+
txTime: context.txTime || (/* @__PURE__ */ new Date(0)).toISOString()
|
|
122
|
+
});
|
|
123
|
+
await context.statedb.evidence.create(unsignedKey, evState, { txn: context.txn });
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Post-activation sender nonce precheck, run under the pre-write lock BEFORE WriteLedger.
|
|
128
|
+
*
|
|
129
|
+
* Every persisted pre-activation tx has `nonce <= sender.nonce` once the offline migration
|
|
130
|
+
* restored each account's max historical nonce. Rejecting stale nonces here (instead of
|
|
131
|
+
* relying on each protocol's `account.update` after WriteLedger) means a signature-malleated
|
|
132
|
+
* twin of ANY historical tx is refused without appending a ledger row and without depending
|
|
133
|
+
* on every protocol path updating the sender nonce. This is what lets the migration skip the
|
|
134
|
+
* full historical `unsigned-tx:` evidence backfill.
|
|
135
|
+
*
|
|
136
|
+
* - Sender account missing (first tx, e.g. declare) or non-account sender: skip; the protocol
|
|
137
|
+
* decides as before.
|
|
138
|
+
* - Sender migrated (statedb resolves `tx.from` to its successor): reject like
|
|
139
|
+
* VerifyAccountMigration, but before the ledger write.
|
|
140
|
+
*
|
|
141
|
+
* Activation boundary: only runs when the tx is already active at the expected sequence. A tx
|
|
142
|
+
* that is pre-activation here but lands on the activation sequence after WriteLedger skips this
|
|
143
|
+
* precheck once; the post-write nonce/dedup checks and the protocol's account.update still apply.
|
|
144
|
+
*/
|
|
145
|
+
const assertSenderNonceFresh = async (context) => {
|
|
146
|
+
const from = context.tx?.from;
|
|
147
|
+
const accountStore = context.statedb?.account;
|
|
148
|
+
if (!from || typeof accountStore?.get !== "function") return;
|
|
149
|
+
const senderState = await accountStore.get(from, context);
|
|
150
|
+
if (!senderState) return;
|
|
151
|
+
if (senderState.address !== from && senderState.address !== _ocap_state.account.ensureChecksumAddress(from)) throw new _ocap_util_lib_error.CustomError("ACCOUNT_MIGRATED", `account ${from} is migrated`);
|
|
152
|
+
const incomingNonceBn = (0, _ocap_state.parseNonceBn)(context.tx?.nonce);
|
|
153
|
+
const currentNonceBn = (0, _ocap_state.parseNonceBn)(senderState.nonce) ?? new _ocap_util.BN(0);
|
|
154
|
+
if (!incomingNonceBn || incomingNonceBn.lte(currentNonceBn)) throw new _ocap_util_lib_error.CustomError("INVALID_NONCE", "nonce must be greater in newer transactions");
|
|
155
|
+
};
|
|
47
156
|
const pre = new _ocap_tx_pipeline.Runner("pre-execute");
|
|
157
|
+
pre.use(async (context, next) => {
|
|
158
|
+
const dedupHeight = (0, _ocap_state.resolveDedupActivationHeight)(context);
|
|
159
|
+
if (dedupHeight > 0 && dedupHeight < _ocap_state.PENDING_DEDUP_ACTIVATION_HEIGHT) await (0, _ocap_tx_pipeline.resolveEffectiveHeight)(context);
|
|
160
|
+
return next();
|
|
161
|
+
});
|
|
48
162
|
pre.use(_ocap_tx_pipeline.pipes.DecodeTx);
|
|
49
163
|
pre.use(_ocap_tx_pipeline.pipes.VerifyBlocked({
|
|
50
164
|
filter,
|
|
@@ -54,15 +168,70 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
54
168
|
pre.use(_ocap_tx_pipeline.pipes.VerifyTx);
|
|
55
169
|
pre.use(_ocap_tx_pipeline.pipes.VerifyServiceFee);
|
|
56
170
|
pre.use(async (context, next) => {
|
|
171
|
+
const syncState = getSyncState(context);
|
|
172
|
+
const execId = context.executionId;
|
|
173
|
+
const inFlightTxOwner = context.txHash ? syncState.inFlightTxHashes.get(context.txHash) : void 0;
|
|
174
|
+
if (inFlightTxOwner && inFlightTxOwner !== execId) return next(new _ocap_util_lib_error.CustomError("DUPLICATE_TX", "Can not execute duplicate transaction"));
|
|
57
175
|
if (filter.has(context.txHash)) {
|
|
58
176
|
if (await context.statedb.tx.get(context.txHash, context)) return next(new _ocap_util_lib_error.CustomError("DUPLICATE_TX", "Can not execute duplicate transaction"));
|
|
59
177
|
}
|
|
178
|
+
if (await isUnsignedDedupActive(context)) {
|
|
179
|
+
const inFlightUnsignedOwner = context.unsignedTxHash ? syncState.inFlightUnsignedTxHashes.get(context.unsignedTxHash) : void 0;
|
|
180
|
+
if (inFlightUnsignedOwner && inFlightUnsignedOwner !== execId || await hasCommittedUnsignedTx(context)) return next(new _ocap_util_lib_error.CustomError("DUPLICATE_TX", "Can not execute duplicate transaction"));
|
|
181
|
+
}
|
|
60
182
|
filter.add(context.txHash);
|
|
61
183
|
return next();
|
|
62
184
|
});
|
|
63
185
|
pre.use(_ocap_tx_pipeline.pipes.VerifyTxSize);
|
|
64
186
|
pre.use(_ocap_tx_pipeline.pipes.VerifySignature);
|
|
65
|
-
pre.use(
|
|
187
|
+
pre.use(async (context, next) => {
|
|
188
|
+
try {
|
|
189
|
+
await withPreWriteLock(context, async () => {
|
|
190
|
+
const syncState = getSyncState(context);
|
|
191
|
+
if (context.height === void 0 && !context.ledgerSequence) {
|
|
192
|
+
delete context.expectedLedgerSequence;
|
|
193
|
+
delete context.dedupActive;
|
|
194
|
+
const dedupHeight = (0, _ocap_state.resolveDedupActivationHeight)(context);
|
|
195
|
+
if (dedupHeight > 0 && dedupHeight < _ocap_state.PENDING_DEDUP_ACTIVATION_HEIGHT) await (0, _ocap_tx_pipeline.resolveEffectiveHeight)(context);
|
|
196
|
+
}
|
|
197
|
+
const isActiveNow = await isUnsignedDedupActive(context);
|
|
198
|
+
context.dedupActive = isActiveNow;
|
|
199
|
+
const execId = context.executionId || Symbol("tx-exec");
|
|
200
|
+
context.executionId = execId;
|
|
201
|
+
if (context.txHash) {
|
|
202
|
+
const existingTxOwner = syncState.inFlightTxHashes.get(context.txHash);
|
|
203
|
+
if (existingTxOwner && existingTxOwner !== execId) throw new _ocap_util_lib_error.CustomError("DUPLICATE_TX", "Can not execute duplicate transaction");
|
|
204
|
+
}
|
|
205
|
+
if (isActiveNow) {
|
|
206
|
+
(0, _ocap_tx_pipeline.assertCanonicalActiveTx)(context);
|
|
207
|
+
const nonceBn = (0, _ocap_state.parseNonceBn)(context.tx?.nonce);
|
|
208
|
+
if (!nonceBn || nonceBn.lte(new _ocap_util.BN(0))) throw new _ocap_util_lib_error.CustomError("INVALID_NONCE", "tx.nonce should be a positive integer");
|
|
209
|
+
await assertSenderNonceFresh(context);
|
|
210
|
+
if (context.unsignedTxHash) {
|
|
211
|
+
const existingUnsignedOwner = syncState.inFlightUnsignedTxHashes.get(context.unsignedTxHash);
|
|
212
|
+
if (existingUnsignedOwner && existingUnsignedOwner !== execId) throw new _ocap_util_lib_error.CustomError("DUPLICATE_TX", "Can not execute duplicate transaction");
|
|
213
|
+
}
|
|
214
|
+
if (await hasCommittedUnsignedTx(context)) throw new _ocap_util_lib_error.CustomError("DUPLICATE_TX", "Can not execute duplicate transaction");
|
|
215
|
+
}
|
|
216
|
+
if (context.txHash) syncState.inFlightTxHashes.set(context.txHash, execId);
|
|
217
|
+
if (isActiveNow && context.unsignedTxHash) syncState.inFlightUnsignedTxHashes.set(context.unsignedTxHash, execId);
|
|
218
|
+
await runSinglePipe(require_pipes_write_ledger.WriteLedger, context);
|
|
219
|
+
delete context.dedupActive;
|
|
220
|
+
const isActiveAfterWrite = await isUnsignedDedupActive(context);
|
|
221
|
+
context.dedupActive = isActiveAfterWrite;
|
|
222
|
+
if (isActiveAfterWrite) {
|
|
223
|
+
if (!isActiveNow) (0, _ocap_tx_pipeline.assertCanonicalActiveTx)(context);
|
|
224
|
+
const nonceBn = (0, _ocap_state.parseNonceBn)(context.tx?.nonce);
|
|
225
|
+
if (!nonceBn || nonceBn.lte(new _ocap_util.BN(0))) throw new _ocap_util_lib_error.CustomError("INVALID_NONCE", "tx.nonce should be a positive integer");
|
|
226
|
+
if (await hasCommittedUnsignedTx(context)) throw new _ocap_util_lib_error.CustomError("DUPLICATE_TX", "Can not execute duplicate transaction");
|
|
227
|
+
if (context.unsignedTxHash) syncState.inFlightUnsignedTxHashes.set(context.unsignedTxHash, execId);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
return next();
|
|
231
|
+
} catch (err) {
|
|
232
|
+
return next(err);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
66
235
|
const ensureGasFeePaid = (context) => {
|
|
67
236
|
const gasRunner = new _ocap_tx_pipeline.Runner("ensure-gas-fee-paid");
|
|
68
237
|
gasRunner.use(ensureTxGas);
|
|
@@ -124,6 +293,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
124
293
|
txState = states.tx.create(context, txStatus);
|
|
125
294
|
}
|
|
126
295
|
await context.statedb.tx.create(txState.hash, txState, context);
|
|
296
|
+
await recordUnsignedTxInStateDb(context, txState.hash);
|
|
127
297
|
context.timer?.mark("txstate");
|
|
128
298
|
context.timer?.mark("commit");
|
|
129
299
|
flushEvents(context, { txState });
|
|
@@ -161,6 +331,8 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
161
331
|
});
|
|
162
332
|
});
|
|
163
333
|
if (typeof runAsLambda === "function") return async (context, protocols) => {
|
|
334
|
+
const executionId = Symbol("tx-exec");
|
|
335
|
+
context.executionId = executionId;
|
|
164
336
|
let ctx = context;
|
|
165
337
|
context.timer = context.timer || new require_tx_timer.TxTimer();
|
|
166
338
|
let entryFinalized = false;
|
|
@@ -178,14 +350,24 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
178
350
|
"extra",
|
|
179
351
|
"logger",
|
|
180
352
|
"ledgerSequence",
|
|
181
|
-
"
|
|
353
|
+
"height",
|
|
354
|
+
"timer",
|
|
355
|
+
"executionId"
|
|
182
356
|
]);
|
|
183
357
|
ctx.txn = txn;
|
|
358
|
+
if (savedLedgerSequence !== void 0) ctx.ledgerSequence = savedLedgerSequence;
|
|
184
359
|
ctx.timer?.mark("lockWait");
|
|
185
|
-
|
|
186
|
-
|
|
360
|
+
try {
|
|
361
|
+
await execute(ctx, protocols, true);
|
|
362
|
+
} finally {
|
|
363
|
+
if (ctx.ledgerSequence && !savedLedgerSequence) {
|
|
364
|
+
savedLedgerSequence = ctx.ledgerSequence;
|
|
365
|
+
context.ledgerSequence = ctx.ledgerSequence;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
187
368
|
const state = getStates(context).tx.create(ctx, "OK");
|
|
188
369
|
await context.statedb.tx.create(state.hash, state, ctx);
|
|
370
|
+
await recordUnsignedTxInStateDb(ctx, state.hash);
|
|
189
371
|
ctx.timer?.mark("txstate");
|
|
190
372
|
return state;
|
|
191
373
|
}, {
|
|
@@ -255,6 +437,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
255
437
|
await ensureGasFeePaid(ctx);
|
|
256
438
|
const state = getStates(context).tx.create(ctx, txStatus);
|
|
257
439
|
await ctx.statedb.tx.create(state.hash, state, ctx);
|
|
440
|
+
await recordUnsignedTxInStateDb(ctx, state.hash);
|
|
258
441
|
ctx.timer?.mark("txstate");
|
|
259
442
|
return state;
|
|
260
443
|
}, {
|
|
@@ -351,31 +534,39 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
351
534
|
}
|
|
352
535
|
}
|
|
353
536
|
(0, lodash_merge.default)(context, ctx);
|
|
537
|
+
releaseInFlight(executionId, ctx, context);
|
|
354
538
|
}
|
|
355
539
|
return ctx;
|
|
356
540
|
};
|
|
357
541
|
return async (context, protocols) => {
|
|
542
|
+
const executionId = Symbol("tx-exec");
|
|
543
|
+
context.executionId = executionId;
|
|
358
544
|
context.timer = context.timer || new require_tx_timer.TxTimer();
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
545
|
+
try {
|
|
546
|
+
return await execute(context, protocols);
|
|
547
|
+
} finally {
|
|
548
|
+
releaseInFlight(executionId, context);
|
|
549
|
+
if (context.ledger && context.txHash && context.ledgerSequence && context.txBase64) try {
|
|
550
|
+
await context.ledger.finalizeEntry(context.txHash, "", context.ledgerSequence, context.txBase64);
|
|
551
|
+
} catch (err) {
|
|
552
|
+
context.logger?.error("Failed to finalize ledger entry (fallback)", {
|
|
553
|
+
txHash: context.txHash,
|
|
554
|
+
error: err
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
context.timer?.mark("finalize");
|
|
558
|
+
context.ledger?.createCheckpointIfNeeded()?.catch((err) => {
|
|
559
|
+
context.logger?.error("Background checkpoint creation failed", {
|
|
560
|
+
txHash: context.txHash,
|
|
561
|
+
error: err
|
|
562
|
+
});
|
|
366
563
|
});
|
|
367
564
|
}
|
|
368
|
-
result.timer?.mark("finalize");
|
|
369
|
-
result.ledger?.createCheckpointIfNeeded()?.catch((err) => {
|
|
370
|
-
result.logger?.error("Background checkpoint creation failed", {
|
|
371
|
-
txHash: result.txHash,
|
|
372
|
-
error: err
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
return result;
|
|
376
565
|
};
|
|
377
566
|
};
|
|
378
567
|
var execute_default = createExecute;
|
|
379
568
|
|
|
380
569
|
//#endregion
|
|
381
|
-
exports.
|
|
570
|
+
exports.UNSIGNED_TX_EVIDENCE_DATA_PREFIX = UNSIGNED_TX_EVIDENCE_DATA_PREFIX;
|
|
571
|
+
exports.default = execute_default;
|
|
572
|
+
exports.toUnsignedEvidenceKey = toUnsignedEvidenceKey;
|
package/lib/execute.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TxTimer } from "./tx-timer.cjs";
|
|
2
|
+
import { Blacklist } from "@ocap/state";
|
|
2
3
|
import { IAccountState, IGasContext } from "@ocap/types";
|
|
3
4
|
import { CustomError } from "@ocap/util/lib/error";
|
|
4
|
-
import { Blacklist } from "@ocap/state";
|
|
5
5
|
|
|
6
6
|
//#region src/execute.d.ts
|
|
7
7
|
/** State helpers interface */
|
|
@@ -34,6 +34,8 @@ interface IExecutionContext extends IGasContext {
|
|
|
34
34
|
stateCommitHash?: string;
|
|
35
35
|
/** Transaction execution timer */
|
|
36
36
|
timer?: TxTimer;
|
|
37
|
+
/** Per-invocation identifier for in-flight deduplication across retries */
|
|
38
|
+
executionId?: symbol;
|
|
37
39
|
}
|
|
38
40
|
/** Protocol runner interface */
|
|
39
41
|
interface IProtocolRunner {
|
|
@@ -53,9 +55,11 @@ interface IExecuteOptions {
|
|
|
53
55
|
}
|
|
54
56
|
/** Execute function type */
|
|
55
57
|
type ExecuteFn = (context: IExecutionContext, protocols: ProtocolsMap, isRetrySupported?: boolean) => Promise<IExecutionContext>;
|
|
58
|
+
declare const toUnsignedEvidenceKey: (unsignedTxHash: string) => string;
|
|
59
|
+
declare const UNSIGNED_TX_EVIDENCE_DATA_PREFIX = "unsigned-tx:";
|
|
56
60
|
declare const createExecute: ({
|
|
57
61
|
filter,
|
|
58
62
|
runAsLambda
|
|
59
63
|
}: IExecuteOptions) => ExecuteFn;
|
|
60
64
|
//#endregion
|
|
61
|
-
export { createExecute as default };
|
|
65
|
+
export { UNSIGNED_TX_EVIDENCE_DATA_PREFIX, createExecute as default, toUnsignedEvidenceKey };
|
package/lib/index.cjs
CHANGED
|
@@ -105,7 +105,9 @@ var src_default = defaultExecutor;
|
|
|
105
105
|
exports.COUNTER_NAMES = require_tx_timer.COUNTER_NAMES;
|
|
106
106
|
exports.STAGE_LABELS = require_tx_timer.STAGE_LABELS;
|
|
107
107
|
exports.TxTimer = require_tx_timer.TxTimer;
|
|
108
|
+
exports.UNSIGNED_TX_EVIDENCE_DATA_PREFIX = require_execute.UNSIGNED_TX_EVIDENCE_DATA_PREFIX;
|
|
108
109
|
exports.WriteLedger = require_pipes_write_ledger.WriteLedger;
|
|
109
110
|
exports.createExecutor = createExecutor;
|
|
110
111
|
exports.default = src_default;
|
|
111
|
-
exports.execute = execute;
|
|
112
|
+
exports.execute = execute;
|
|
113
|
+
exports.toUnsignedEvidenceKey = require_execute.toUnsignedEvidenceKey;
|
package/lib/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { COUNTER_NAMES, CounterName, QueueState, STAGE_LABELS, StageLabel, TxMeta, TxStatus, TxTimer, TxTimerSummaryV2 } from "./tx-timer.cjs";
|
|
2
|
+
import { UNSIGNED_TX_EVIDENCE_DATA_PREFIX, toUnsignedEvidenceKey } from "./execute.cjs";
|
|
2
3
|
import { TokenInput } from "./protocols/trade/transfer-v2.cjs";
|
|
3
4
|
import { MultiInput } from "./protocols/trade/transfer-v3.cjs";
|
|
4
5
|
import { TokenInput as TokenInput$1 } from "./protocols/trade/exchange-v2.cjs";
|
|
@@ -18,8 +19,8 @@ import { MultiInput as MultiInput$5, TokenCondition as TokenCondition$2 } from "
|
|
|
18
19
|
import { TokenChange as TokenChange$1 } from "./protocols/rollup/create-block.cjs";
|
|
19
20
|
import { TokenChange as TokenChange$2 } from "./protocols/rollup/claim-reward.cjs";
|
|
20
21
|
import { WriteLedger } from "./pipes/write-ledger.cjs";
|
|
21
|
-
import * as _ocap_types0 from "@ocap/types";
|
|
22
22
|
import * as states from "@ocap/state";
|
|
23
|
+
import * as _ocap_types0 from "@ocap/types";
|
|
23
24
|
import * as _ocap_tx_pipeline0 from "@ocap/tx-pipeline";
|
|
24
25
|
import * as _ocap_message0 from "@ocap/message";
|
|
25
26
|
import * as _ocap_util0 from "@ocap/util";
|
|
@@ -78,6 +79,11 @@ declare const createExecutor: ({
|
|
|
78
79
|
outputAssets?: string[];
|
|
79
80
|
tokenStates?: _ocap_types0.ITokenState[];
|
|
80
81
|
assetStates?: _ocap_types0.IAssetState[];
|
|
82
|
+
delegatorState?: _ocap_types0.IAccountState;
|
|
83
|
+
delegationState?: _ocap_types0.IDelegateState;
|
|
84
|
+
msSignerStates?: _ocap_types0.IAccountState[];
|
|
85
|
+
delegatorStates?: (_ocap_types0.IAccountState | null)[];
|
|
86
|
+
delegationStates?: _ocap_types0.IDelegateState[];
|
|
81
87
|
}>;
|
|
82
88
|
exchangeV2: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TExchangeV2Tx> & _ocap_types0.IWithSender & _ocap_types0.IWithReceiver & Partial<_ocap_types0.IWithDelegator> & Partial<_ocap_types0.IWithSigners> & Partial<_ocap_types0.IWithDelegation> & {
|
|
83
89
|
senderAssets?: string[];
|
|
@@ -95,6 +101,7 @@ declare const createExecutor: ({
|
|
|
95
101
|
};
|
|
96
102
|
tokenStates?: _ocap_types0.ITokenState[];
|
|
97
103
|
receiver?: string;
|
|
104
|
+
delegationStates?: _ocap_types0.IDelegateState[];
|
|
98
105
|
priv?: {
|
|
99
106
|
senderAssets?: _ocap_types0.IAssetState[];
|
|
100
107
|
receiverAssets?: _ocap_types0.IAssetState[];
|
|
@@ -192,6 +199,11 @@ declare const createExecutor: ({
|
|
|
192
199
|
mintedAsset?: Record<string, unknown>;
|
|
193
200
|
mintedAddress?: string;
|
|
194
201
|
tokenUpdates?: Record<string, string>;
|
|
202
|
+
delegatorState?: _ocap_types0.IAccountState;
|
|
203
|
+
delegationState?: _ocap_types0.IDelegateState;
|
|
204
|
+
msSignerStates?: _ocap_types0.IAccountState[];
|
|
205
|
+
delegatorStates?: (_ocap_types0.IAccountState | null)[];
|
|
206
|
+
delegationStates?: _ocap_types0.IDelegateState[];
|
|
195
207
|
}>;
|
|
196
208
|
mintAsset: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TMintAssetTx> & Partial<_ocap_types0.IWithSender> & Partial<_ocap_types0.IWithFactory> & Partial<_ocap_types0.IWithOwner> & Partial<_ocap_types0.IWithReceiver> & {
|
|
197
209
|
duplicateAsset?: _ocap_types0.IAssetState;
|
|
@@ -437,6 +449,11 @@ declare const defaultExecutor: {
|
|
|
437
449
|
outputAssets?: string[];
|
|
438
450
|
tokenStates?: _ocap_types0.ITokenState[];
|
|
439
451
|
assetStates?: _ocap_types0.IAssetState[];
|
|
452
|
+
delegatorState?: _ocap_types0.IAccountState;
|
|
453
|
+
delegationState?: _ocap_types0.IDelegateState;
|
|
454
|
+
msSignerStates?: _ocap_types0.IAccountState[];
|
|
455
|
+
delegatorStates?: (_ocap_types0.IAccountState | null)[];
|
|
456
|
+
delegationStates?: _ocap_types0.IDelegateState[];
|
|
440
457
|
}>;
|
|
441
458
|
exchangeV2: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TExchangeV2Tx> & _ocap_types0.IWithSender & _ocap_types0.IWithReceiver & Partial<_ocap_types0.IWithDelegator> & Partial<_ocap_types0.IWithSigners> & Partial<_ocap_types0.IWithDelegation> & {
|
|
442
459
|
senderAssets?: string[];
|
|
@@ -454,6 +471,7 @@ declare const defaultExecutor: {
|
|
|
454
471
|
};
|
|
455
472
|
tokenStates?: _ocap_types0.ITokenState[];
|
|
456
473
|
receiver?: string;
|
|
474
|
+
delegationStates?: _ocap_types0.IDelegateState[];
|
|
457
475
|
priv?: {
|
|
458
476
|
senderAssets?: _ocap_types0.IAssetState[];
|
|
459
477
|
receiverAssets?: _ocap_types0.IAssetState[];
|
|
@@ -551,6 +569,11 @@ declare const defaultExecutor: {
|
|
|
551
569
|
mintedAsset?: Record<string, unknown>;
|
|
552
570
|
mintedAddress?: string;
|
|
553
571
|
tokenUpdates?: Record<string, string>;
|
|
572
|
+
delegatorState?: _ocap_types0.IAccountState;
|
|
573
|
+
delegationState?: _ocap_types0.IDelegateState;
|
|
574
|
+
msSignerStates?: _ocap_types0.IAccountState[];
|
|
575
|
+
delegatorStates?: (_ocap_types0.IAccountState | null)[];
|
|
576
|
+
delegationStates?: _ocap_types0.IDelegateState[];
|
|
554
577
|
}>;
|
|
555
578
|
mintAsset: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TMintAssetTx> & Partial<_ocap_types0.IWithSender> & Partial<_ocap_types0.IWithFactory> & Partial<_ocap_types0.IWithOwner> & Partial<_ocap_types0.IWithReceiver> & {
|
|
556
579
|
duplicateAsset?: _ocap_types0.IAssetState;
|
|
@@ -757,4 +780,4 @@ declare const defaultExecutor: {
|
|
|
757
780
|
};
|
|
758
781
|
declare const execute: (context: unknown, done?: (err: Error | null, res?: unknown) => void) => any;
|
|
759
782
|
//#endregion
|
|
760
|
-
export { COUNTER_NAMES, type CounterName, type QueueState, STAGE_LABELS, type StageLabel, type TxMeta, type TxStatus, TxTimer, type TxTimerSummaryV2, WriteLedger, createExecutor, defaultExecutor as default, execute };
|
|
783
|
+
export { COUNTER_NAMES, type CounterName, type QueueState, STAGE_LABELS, type StageLabel, type TxMeta, type TxStatus, TxTimer, type TxTimerSummaryV2, UNSIGNED_TX_EVIDENCE_DATA_PREFIX, WriteLedger, createExecutor, defaultExecutor as default, execute, toUnsignedEvidenceKey };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
3
|
const require_util = require('../util.cjs');
|
|
4
|
+
let _ocap_state = require("@ocap/state");
|
|
5
|
+
let _ocap_util = require("@ocap/util");
|
|
4
6
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
5
7
|
let _arcblock_did = require("@arcblock/did");
|
|
6
8
|
let _arcblock_did_util = require("@arcblock/did-util");
|
|
7
9
|
let _arcblock_jwt = require("@arcblock/jwt");
|
|
8
10
|
_arcblock_jwt = require_rolldown_runtime.__toESM(_arcblock_jwt);
|
|
9
|
-
let _ocap_state = require("@ocap/state");
|
|
10
|
-
let _ocap_util = require("@ocap/util");
|
|
11
11
|
let lodash_noop = require("lodash/noop");
|
|
12
12
|
lodash_noop = require_rolldown_runtime.__toESM(lodash_noop);
|
|
13
13
|
let debug = require("debug");
|
|
@@ -52,6 +52,13 @@ const WriteLedger = async (context, next) => {
|
|
|
52
52
|
});
|
|
53
53
|
return next();
|
|
54
54
|
}
|
|
55
|
+
if (context.ledgerSequence !== void 0) {
|
|
56
|
+
debug$1("Transaction already written to ledger in previous attempt, skipping write", {
|
|
57
|
+
txHash,
|
|
58
|
+
sequence: context.ledgerSequence
|
|
59
|
+
});
|
|
60
|
+
return next();
|
|
61
|
+
}
|
|
55
62
|
try {
|
|
56
63
|
let txExtra;
|
|
57
64
|
if (extra?.txExtra || extra?.gasStakeHeaders) {
|
|
@@ -2,18 +2,19 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
3
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
4
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
let _ocap_state = require("@ocap/state");
|
|
5
6
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
7
|
+
let _ocap_util = require("@ocap/util");
|
|
6
8
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
9
|
let lodash_get = require("lodash/get");
|
|
8
10
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
9
11
|
let lodash_pick = require("lodash/pick");
|
|
10
12
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
11
13
|
let _arcblock_did_util = require("@arcblock/did-util");
|
|
12
|
-
let _ocap_state = require("@ocap/state");
|
|
13
|
-
let _ocap_util = require("@ocap/util");
|
|
14
14
|
let debug = require("debug");
|
|
15
15
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
16
16
|
let _ocap_message = require("@ocap/message");
|
|
17
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
17
18
|
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
18
19
|
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
19
20
|
let _arcblock_validator = require("@arcblock/validator");
|
|
@@ -139,15 +140,15 @@ runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
|
139
140
|
runner.use(async (context, next) => {
|
|
140
141
|
const { tx, itx, formattedItx, validatedItx, statedb, senderState, receiverState, delegationState, senderUpdates, updateVaults } = context;
|
|
141
142
|
const ops = formattedItx?.ops || [];
|
|
142
|
-
const opsList = validatedItx
|
|
143
|
-
const deny = itx
|
|
143
|
+
const opsList = (0, _ocap_util_lib_get_list_field.getListField)(validatedItx, "ops");
|
|
144
|
+
const deny = (0, _ocap_util_lib_get_list_field.getListField)(itx, "deny");
|
|
144
145
|
const validUntil = itx.validUntil || 0;
|
|
145
146
|
const merged = (0, lodash_cloneDeep.default)(ops).reduce((acc, x, i) => {
|
|
146
147
|
const tokens = x.limit?.tokens || [];
|
|
147
148
|
const assets = x.limit?.assets || [];
|
|
148
149
|
acc[x.typeUrl] = { limit: {
|
|
149
150
|
tokens: tokens.map((y, j) => {
|
|
150
|
-
const input = opsList[i]?.limit
|
|
151
|
+
const input = (0, _ocap_util_lib_get_list_field.getListField)(opsList[i]?.limit, "tokens")[j] || {};
|
|
151
152
|
return Object.assign(y, (0, lodash_pick.default)(input, [
|
|
152
153
|
"txCount",
|
|
153
154
|
"txAllowance",
|
|
@@ -161,7 +162,7 @@ runner.use(async (context, next) => {
|
|
|
161
162
|
});
|
|
162
163
|
}),
|
|
163
164
|
assets: assets.map((y, j) => {
|
|
164
|
-
const input = opsList[i]?.limit
|
|
165
|
+
const input = (0, _ocap_util_lib_get_list_field.getListField)(opsList[i]?.limit, "assets")[j] || {};
|
|
165
166
|
return Object.assign(y, (0, lodash_pick.default)(input, [
|
|
166
167
|
"txCount",
|
|
167
168
|
"validUntil",
|
|
@@ -3,14 +3,14 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_util = require('../../util.cjs');
|
|
4
4
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
7
|
+
let _ocap_state = require("@ocap/state");
|
|
6
8
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
7
9
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
8
10
|
let _arcblock_did = require("@arcblock/did");
|
|
9
|
-
let _ocap_state = require("@ocap/state");
|
|
10
11
|
let debug = require("debug");
|
|
11
12
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
12
13
|
let _arcblock_validator = require("@arcblock/validator");
|
|
13
|
-
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
14
14
|
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
15
15
|
let lodash_flatten = require("lodash/flatten");
|
|
16
16
|
lodash_flatten = require_rolldown_runtime.__toESM(lodash_flatten);
|
|
@@ -2,12 +2,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
3
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
4
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
let _ocap_state = require("@ocap/state");
|
|
5
6
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
6
7
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
8
|
let lodash_get = require("lodash/get");
|
|
8
9
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
9
10
|
let _arcblock_did_util = require("@arcblock/did-util");
|
|
10
|
-
let _ocap_state = require("@ocap/state");
|
|
11
11
|
let debug = require("debug");
|
|
12
12
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
13
13
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
@@ -9,11 +9,12 @@ const require_protocols_asset_pipes_verify_itx_address = require('./pipes/verify
|
|
|
9
9
|
const require_protocols_asset_pipes_verify_itx_assets = require('./pipes/verify-itx-assets.cjs');
|
|
10
10
|
const require_protocols_asset_pipes_verify_itx_variables = require('./pipes/verify-itx-variables.cjs');
|
|
11
11
|
const require_protocols_asset_pipes_verify_mint_limit = require('./pipes/verify-mint-limit.cjs');
|
|
12
|
+
let _ocap_state = require("@ocap/state");
|
|
12
13
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
13
14
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
14
|
-
let _ocap_state = require("@ocap/state");
|
|
15
15
|
let debug = require("debug");
|
|
16
16
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
17
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
17
18
|
let _arcblock_validator = require("@arcblock/validator");
|
|
18
19
|
let node_util = require("node:util");
|
|
19
20
|
|
|
@@ -82,15 +83,23 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
82
83
|
status: "INVALID_FACTORY_STATE",
|
|
83
84
|
table: "factory"
|
|
84
85
|
}));
|
|
86
|
+
runner.use(require_protocols_asset_pipes_extract_factory_tokens.default);
|
|
85
87
|
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
86
88
|
type: "signature",
|
|
87
89
|
signerKey: "senderState",
|
|
88
90
|
delegatorKey: "delegatorState",
|
|
89
91
|
getRequirements: (context) => {
|
|
90
|
-
|
|
92
|
+
const ctx = context;
|
|
93
|
+
const tokens = ctx.factoryTokens || [];
|
|
94
|
+
const assets = (0, _ocap_util_lib_get_list_field.getListField)(ctx.itx, "assets") || [];
|
|
95
|
+
return [...tokens.map((x) => ({
|
|
91
96
|
type: "token",
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
address: x.address,
|
|
98
|
+
value: String(x.value)
|
|
99
|
+
})), ...assets.map((x) => ({
|
|
100
|
+
type: "asset",
|
|
101
|
+
address: x
|
|
102
|
+
}))];
|
|
94
103
|
}
|
|
95
104
|
}));
|
|
96
105
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
@@ -136,13 +145,18 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
136
145
|
status: "OK",
|
|
137
146
|
table: "factory"
|
|
138
147
|
}));
|
|
139
|
-
runner.use(require_protocols_asset_pipes_extract_factory_tokens.default);
|
|
140
148
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
141
149
|
from: "tokenAddress",
|
|
142
150
|
to: "tokenStates",
|
|
143
151
|
status: "INVALID_TOKEN",
|
|
144
152
|
table: "token"
|
|
145
153
|
}));
|
|
154
|
+
runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
155
|
+
statesKey: "tokenStates",
|
|
156
|
+
listFieldKey: "spenders",
|
|
157
|
+
accountKeys: ["senderState"],
|
|
158
|
+
errorMessage: "Account {address} is not allowed to use token {tokenAddress}"
|
|
159
|
+
}));
|
|
146
160
|
runner.use(require_protocols_asset_pipes_verify_mint_limit.default);
|
|
147
161
|
runner.use(require_protocols_asset_pipes_verify_itx_variables.default);
|
|
148
162
|
runner.use(require_protocols_asset_pipes_verify_itx_address.default("acquire-v2"));
|
|
@@ -168,6 +182,11 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
|
168
182
|
ownerKey: "assetOwner"
|
|
169
183
|
}));
|
|
170
184
|
runner.use(require_protocols_asset_pipes_verify_itx_assets.default);
|
|
185
|
+
runner.use(async (context, next) => {
|
|
186
|
+
const { itx, assetOwner, assetStates = [] } = context;
|
|
187
|
+
const consumedAssets = assetStates.map((x) => x.address);
|
|
188
|
+
return next(await (0, _ocap_tx_pipeline.verifyAssetHierarchy)([itx.address], assetOwner?.address, context, void 0, consumedAssets) || void 0);
|
|
189
|
+
});
|
|
171
190
|
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
172
191
|
const result = {
|
|
173
192
|
create: 1,
|