@ocap/tx-protocols 1.31.1 → 1.31.3
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/bridge-release-crypto.d.mts +39 -0
- package/esm/bridge-release-crypto.mjs +88 -0
- package/esm/bridge-release-window.d.mts +47 -0
- package/esm/bridge-release-window.mjs +62 -0
- package/esm/bridge-reserve.d.mts +24 -0
- package/esm/bridge-reserve.mjs +41 -0
- package/esm/execute.d.mts +1 -1
- package/esm/execute.mjs +58 -5
- package/esm/gas-security-guard.d.mts +6 -2
- package/esm/gas-security-guard.mjs +16 -9
- package/esm/index.d.mts +37 -18
- package/esm/index.mjs +6 -2
- package/esm/pipes/ensure-cost.mjs +7 -1
- package/esm/pipes/write-ledger.d.mts +2 -2
- package/esm/pipes/write-ledger.mjs +6 -3
- package/esm/protocols/account/delegate.mjs +6 -4
- package/esm/protocols/account/migrate.mjs +5 -3
- package/esm/protocols/account/revoke-delegate.mjs +5 -3
- package/esm/protocols/asset/acquire-v2.mjs +3 -1
- package/esm/protocols/asset/acquire-v3.mjs +4 -2
- package/esm/protocols/asset/consume.mjs +3 -1
- package/esm/protocols/asset/create.mjs +4 -2
- package/esm/protocols/asset/mint.mjs +4 -2
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +1 -1
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +1 -1
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +1 -1
- package/esm/protocols/asset/update.mjs +4 -2
- package/esm/protocols/bridge/release.d.mts +34 -0
- package/esm/protocols/bridge/release.mjs +385 -0
- package/esm/protocols/factory/create.mjs +4 -2
- package/esm/protocols/governance/claim-stake.mjs +4 -2
- package/esm/protocols/governance/return-stake.mjs +4 -2
- package/esm/protocols/governance/revoke-ledger.mjs +1 -1
- package/esm/protocols/governance/revoke-stake.d.mts +7 -2
- package/esm/protocols/governance/revoke-stake.mjs +49 -28
- package/esm/protocols/governance/slash-stake.mjs +5 -3
- package/esm/protocols/governance/stake.mjs +6 -4
- package/esm/protocols/rollup/bridge-create.d.mts +13 -0
- package/esm/protocols/rollup/bridge-create.mjs +206 -0
- package/esm/protocols/rollup/bridge-membership.d.mts +10 -0
- package/esm/protocols/rollup/bridge-membership.mjs +154 -0
- package/esm/protocols/rollup/bridge-migrate.d.mts +10 -0
- package/esm/protocols/rollup/bridge-migrate.mjs +208 -0
- package/esm/protocols/rollup/bridge-v2.d.mts +113 -0
- package/esm/protocols/rollup/bridge-v2.mjs +219 -0
- package/esm/protocols/rollup/claim-reward.mjs +4 -2
- package/esm/protocols/rollup/close.d.mts +2 -1
- package/esm/protocols/rollup/close.mjs +59 -6
- package/esm/protocols/rollup/create-block.mjs +4 -2
- package/esm/protocols/rollup/create.d.mts +3 -0
- package/esm/protocols/rollup/create.mjs +45 -6
- package/esm/protocols/rollup/join.d.mts +2 -1
- package/esm/protocols/rollup/join.mjs +31 -23
- package/esm/protocols/rollup/leave.d.mts +2 -1
- package/esm/protocols/rollup/leave.mjs +32 -24
- package/esm/protocols/rollup/migrate.d.mts +2 -1
- package/esm/protocols/rollup/migrate.mjs +19 -10
- package/esm/protocols/rollup/pause.d.mts +4 -1
- package/esm/protocols/rollup/pause.mjs +50 -6
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +2 -2
- package/esm/protocols/rollup/resume.d.mts +2 -1
- package/esm/protocols/rollup/resume.mjs +26 -6
- package/esm/protocols/rollup/update.d.mts +5 -1
- package/esm/protocols/rollup/update.mjs +56 -9
- package/esm/protocols/token/create.mjs +4 -2
- package/esm/protocols/token/deposit-v2.mjs +5 -3
- package/esm/protocols/token/withdraw-v2.mjs +5 -3
- package/esm/protocols/token-factory/burn.mjs +4 -2
- package/esm/protocols/token-factory/create.mjs +8 -4
- package/esm/protocols/token-factory/mint.mjs +4 -2
- package/esm/protocols/token-factory/update.mjs +20 -5
- package/esm/protocols/trade/exchange-v2.d.mts +5 -1
- package/esm/protocols/trade/exchange-v2.mjs +89 -4
- package/esm/protocols/trade/transfer-v2.mjs +15 -4
- package/esm/protocols/trade/transfer-v3.mjs +5 -3
- package/esm/stateless-prefix.d.mts +16 -0
- package/esm/stateless-prefix.mjs +82 -0
- package/esm/tx-timer.d.mts +1 -1
- package/esm/tx-timer.mjs +1 -1
- package/esm/util.mjs +2 -2
- package/lib/bridge-release-crypto.cjs +93 -0
- package/lib/bridge-release-crypto.d.cts +39 -0
- package/lib/bridge-release-window.cjs +69 -0
- package/lib/bridge-release-window.d.cts +47 -0
- package/lib/bridge-reserve.cjs +45 -0
- package/lib/bridge-reserve.d.cts +24 -0
- package/lib/execute.cjs +58 -5
- package/lib/gas-security-guard.cjs +16 -9
- package/lib/gas-security-guard.d.cts +6 -2
- package/lib/index.cjs +8 -1
- package/lib/index.d.cts +36 -17
- package/lib/pipes/ensure-cost.cjs +7 -1
- package/lib/pipes/write-ledger.cjs +6 -3
- package/lib/pipes/write-ledger.d.cts +2 -2
- package/lib/protocols/account/delegate.cjs +6 -4
- package/lib/protocols/account/migrate.cjs +5 -3
- package/lib/protocols/account/revoke-delegate.cjs +5 -3
- package/lib/protocols/asset/acquire-v2.cjs +3 -1
- package/lib/protocols/asset/acquire-v3.cjs +4 -2
- package/lib/protocols/asset/consume.cjs +3 -1
- package/lib/protocols/asset/create.cjs +4 -2
- package/lib/protocols/asset/mint.cjs +4 -2
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +1 -1
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +1 -1
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +1 -1
- package/lib/protocols/asset/update.cjs +4 -2
- package/lib/protocols/bridge/release.cjs +390 -0
- package/lib/protocols/bridge/release.d.cts +34 -0
- package/lib/protocols/factory/create.cjs +4 -2
- package/lib/protocols/governance/claim-stake.cjs +4 -2
- package/lib/protocols/governance/return-stake.cjs +4 -2
- package/lib/protocols/governance/revoke-ledger.cjs +1 -1
- package/lib/protocols/governance/revoke-stake.cjs +49 -28
- package/lib/protocols/governance/revoke-stake.d.cts +7 -2
- package/lib/protocols/governance/slash-stake.cjs +5 -3
- package/lib/protocols/governance/stake.cjs +6 -4
- package/lib/protocols/rollup/bridge-create.cjs +209 -0
- package/lib/protocols/rollup/bridge-create.d.cts +13 -0
- package/lib/protocols/rollup/bridge-membership.cjs +157 -0
- package/lib/protocols/rollup/bridge-membership.d.cts +10 -0
- package/lib/protocols/rollup/bridge-migrate.cjs +212 -0
- package/lib/protocols/rollup/bridge-migrate.d.cts +10 -0
- package/lib/protocols/rollup/bridge-v2.cjs +244 -0
- package/lib/protocols/rollup/bridge-v2.d.cts +113 -0
- package/lib/protocols/rollup/claim-reward.cjs +4 -2
- package/lib/protocols/rollup/close.cjs +59 -6
- package/lib/protocols/rollup/close.d.cts +2 -1
- package/lib/protocols/rollup/create-block.cjs +4 -2
- package/lib/protocols/rollup/create.cjs +45 -6
- package/lib/protocols/rollup/create.d.cts +3 -0
- package/lib/protocols/rollup/join.cjs +31 -23
- package/lib/protocols/rollup/join.d.cts +2 -1
- package/lib/protocols/rollup/leave.cjs +32 -24
- package/lib/protocols/rollup/leave.d.cts +2 -1
- package/lib/protocols/rollup/migrate.cjs +19 -10
- package/lib/protocols/rollup/migrate.d.cts +2 -1
- package/lib/protocols/rollup/pause.cjs +50 -6
- package/lib/protocols/rollup/pause.d.cts +4 -1
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +2 -2
- package/lib/protocols/rollup/resume.cjs +26 -6
- package/lib/protocols/rollup/resume.d.cts +2 -1
- package/lib/protocols/rollup/update.cjs +56 -9
- package/lib/protocols/rollup/update.d.cts +5 -1
- package/lib/protocols/token/create.cjs +4 -2
- package/lib/protocols/token/deposit-v2.cjs +5 -3
- package/lib/protocols/token/withdraw-v2.cjs +5 -3
- package/lib/protocols/token-factory/burn.cjs +4 -2
- package/lib/protocols/token-factory/create.cjs +8 -4
- package/lib/protocols/token-factory/mint.cjs +4 -2
- package/lib/protocols/token-factory/update.cjs +20 -5
- package/lib/protocols/trade/exchange-v2.cjs +90 -3
- package/lib/protocols/trade/exchange-v2.d.cts +5 -1
- package/lib/protocols/trade/transfer-v2.cjs +15 -4
- package/lib/protocols/trade/transfer-v3.cjs +5 -3
- package/lib/stateless-prefix.cjs +88 -0
- package/lib/stateless-prefix.d.cts +16 -0
- package/lib/tx-timer.cjs +1 -1
- package/lib/tx-timer.d.cts +1 -1
- package/lib/util.cjs +2 -2
- package/package.json +16 -16
- package/tools/fixtures.ts +9 -4
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
3
|
+
let lodash_camelCase = require("lodash/camelCase");
|
|
4
|
+
lodash_camelCase = require_rolldown_runtime.__toESM(lodash_camelCase);
|
|
5
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
6
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
7
|
+
|
|
8
|
+
//#region src/stateless-prefix.ts
|
|
9
|
+
/**
|
|
10
|
+
* Early rejection of statelessly-invalid txs (follow-up to #1419).
|
|
11
|
+
*
|
|
12
|
+
* Every protocol runner starts with pipes that only look at the decoded tx and the chain config: the itx schema,
|
|
13
|
+
* `VerifyInfo` conditions, list-size limits. A tx they reject can never become valid, whatever the chain state is,
|
|
14
|
+
* yet without this module it is only rejected after it went through the single-writer queue and the executor's
|
|
15
|
+
* state lookups (duplicate / nonce / delegation checks).
|
|
16
|
+
*
|
|
17
|
+
* A protocol opts in by calling `markStatelessPrefix(runner)` right after its last leading stateless pipe.
|
|
18
|
+
* `assertStatelessTxRules` then runs exactly those pipes, the same function objects the protocol runs later, so:
|
|
19
|
+
* - error code, message and `props.persist` are the ones the protocol produces today;
|
|
20
|
+
* - nothing that the protocol accepts can be rejected here (no second copy of a rule that could drift);
|
|
21
|
+
* - the in-protocol check stays where it is: this is an optimisation, never the only gate.
|
|
22
|
+
* A rejection from here never counts as a security strike (see the end of `assertStatelessTxRules`).
|
|
23
|
+
*
|
|
24
|
+
* Rules for a pipe placed before the mark: it may read `tx`, `itx`, `txType`, `txEncoding`, `extra` and `config`
|
|
25
|
+
* only. No statedb / indexdb / ledger access, no network or DNS, no clock, no process-local state, and no
|
|
26
|
+
* signature verification that the protocol does not repeat anyway. Those handles are removed from the context the
|
|
27
|
+
* prefix runs on, and a prefix that crashes instead of rejecting is ignored (the in-protocol run decides).
|
|
28
|
+
*/
|
|
29
|
+
const prefixLengths = /* @__PURE__ */ new WeakMap();
|
|
30
|
+
const toProtocolName = (typeUrl) => (0, lodash_camelCase.default)(typeUrl.split(":").pop() ?? "");
|
|
31
|
+
/** Declare that every pipe added to `runner` so far is stateless (see the rules above). */
|
|
32
|
+
function markStatelessPrefix(runner) {
|
|
33
|
+
const target = runner;
|
|
34
|
+
prefixLengths.set(target, target.pipes.length);
|
|
35
|
+
}
|
|
36
|
+
/** Number of leading pipes of `runner` that were declared stateless (0 when the protocol did not opt in). */
|
|
37
|
+
function getStatelessPrefixLength(runner) {
|
|
38
|
+
if (!runner || typeof runner !== "object") return 0;
|
|
39
|
+
return prefixLengths.get(runner) ?? 0;
|
|
40
|
+
}
|
|
41
|
+
const isProtocolRejection = (err) => {
|
|
42
|
+
const e = err;
|
|
43
|
+
return Boolean(e) && typeof e?.code === "string" && typeof e?.props === "object" && e?.props !== null;
|
|
44
|
+
};
|
|
45
|
+
let defaultProtocols = {};
|
|
46
|
+
/** Registered once by `index.ts` with the protocol map every executor uses. */
|
|
47
|
+
function setDefaultStatelessProtocols(protocols) {
|
|
48
|
+
defaultProtocols = protocols;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Run the stateless prefix of the protocol that handles `context.txType`.
|
|
52
|
+
* Resolves when the tx passes (or when there is nothing to check), rejects with the protocol's own error.
|
|
53
|
+
* Needs a decoded context (`tx`, `itx`, `txType`); never touches state and never mutates `context`.
|
|
54
|
+
*/
|
|
55
|
+
async function assertStatelessTxRules(context, protocols = defaultProtocols) {
|
|
56
|
+
const ctx = context;
|
|
57
|
+
if (!ctx || typeof ctx.txType !== "string" || !ctx.tx || !ctx.itx) return;
|
|
58
|
+
const protocol = protocols[toProtocolName(ctx.txType)];
|
|
59
|
+
const length = getStatelessPrefixLength(protocol);
|
|
60
|
+
if (!protocol || length <= 0) return;
|
|
61
|
+
const prefix = new _ocap_tx_pipeline.Runner(`${protocol.name || "protocol"}:stateless`);
|
|
62
|
+
prefix.pipes = protocol.pipes.slice(0, length);
|
|
63
|
+
const isolated = {
|
|
64
|
+
...ctx,
|
|
65
|
+
tx: (0, lodash_cloneDeep.default)(ctx.tx),
|
|
66
|
+
itx: (0, lodash_cloneDeep.default)(ctx.itx),
|
|
67
|
+
statedb: void 0,
|
|
68
|
+
indexdb: void 0,
|
|
69
|
+
ledger: void 0,
|
|
70
|
+
txn: void 0,
|
|
71
|
+
timer: void 0,
|
|
72
|
+
logger: void 0,
|
|
73
|
+
filter: void 0
|
|
74
|
+
};
|
|
75
|
+
const err = await new Promise((resolve) => {
|
|
76
|
+
prefix.run(isolated, (e) => resolve(e));
|
|
77
|
+
});
|
|
78
|
+
if (isProtocolRejection(err)) {
|
|
79
|
+
err._strikeRecorded = true;
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
exports.assertStatelessTxRules = assertStatelessTxRules;
|
|
86
|
+
exports.getStatelessPrefixLength = getStatelessPrefixLength;
|
|
87
|
+
exports.markStatelessPrefix = markStatelessPrefix;
|
|
88
|
+
exports.setDefaultStatelessProtocols = setDefaultStatelessProtocols;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/stateless-prefix.d.ts
|
|
2
|
+
type StatelessProtocolsMap = Record<string, unknown>;
|
|
3
|
+
/** Declare that every pipe added to `runner` so far is stateless (see the rules above). */
|
|
4
|
+
declare function markStatelessPrefix(runner: unknown): void;
|
|
5
|
+
/** Number of leading pipes of `runner` that were declared stateless (0 when the protocol did not opt in). */
|
|
6
|
+
declare function getStatelessPrefixLength(runner: unknown): number;
|
|
7
|
+
/** Registered once by `index.ts` with the protocol map every executor uses. */
|
|
8
|
+
declare function setDefaultStatelessProtocols(protocols: StatelessProtocolsMap): void;
|
|
9
|
+
/**
|
|
10
|
+
* Run the stateless prefix of the protocol that handles `context.txType`.
|
|
11
|
+
* Resolves when the tx passes (or when there is nothing to check), rejects with the protocol's own error.
|
|
12
|
+
* Needs a decoded context (`tx`, `itx`, `txType`); never touches state and never mutates `context`.
|
|
13
|
+
*/
|
|
14
|
+
declare function assertStatelessTxRules(context: unknown, protocols?: StatelessProtocolsMap): Promise<void>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { StatelessProtocolsMap, assertStatelessTxRules, getStatelessPrefixLength, markStatelessPrefix, setDefaultStatelessProtocols };
|
package/lib/tx-timer.cjs
CHANGED
package/lib/tx-timer.d.cts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* - FAILED txs without persistence stop after the protocol error.
|
|
20
20
|
* - PERSISTED_FAILED txs go through gas-charge runAsLambda and produce a second set.
|
|
21
21
|
*/
|
|
22
|
-
declare const STAGE_LABELS: readonly ["queueWait", "decode", "verify", "lockWait", "
|
|
22
|
+
declare const STAGE_LABELS: readonly ["queueWait", "decode", "verify", "lockWait", "protocolRead", "protocolWrite", "protocolDiff", "ledger", "txstate", "commit", "indexdb"];
|
|
23
23
|
type StageLabel = (typeof STAGE_LABELS)[number];
|
|
24
24
|
declare const COUNTER_NAMES: readonly ["stateReads", "stateWrites", "tokenWrites", "indexEvents"];
|
|
25
25
|
type CounterName = (typeof COUNTER_NAMES)[number];
|
package/lib/util.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
3
|
-
let _ocap_util = require("@ocap/util");
|
|
4
2
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
5
3
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
4
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
5
|
+
let _ocap_util = require("@ocap/util");
|
|
6
6
|
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
7
7
|
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
8
8
|
let _ocap_message = require("@ocap/message");
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.31.
|
|
6
|
+
"version": "1.31.3",
|
|
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.31.
|
|
50
|
-
"@arcblock/did-util": "1.31.
|
|
51
|
-
"@arcblock/jwt": "1.31.
|
|
52
|
-
"@arcblock/validator": "1.31.
|
|
53
|
-
"@arcblock/vc": "1.31.
|
|
49
|
+
"@arcblock/did": "1.31.3",
|
|
50
|
+
"@arcblock/did-util": "1.31.3",
|
|
51
|
+
"@arcblock/jwt": "1.31.3",
|
|
52
|
+
"@arcblock/validator": "1.31.3",
|
|
53
|
+
"@arcblock/vc": "1.31.3",
|
|
54
54
|
"@blocklet/xss": "^0.3.7",
|
|
55
|
-
"@ocap/asset": "1.31.
|
|
56
|
-
"@ocap/client": "1.31.
|
|
57
|
-
"@ocap/mcrypto": "1.31.
|
|
58
|
-
"@ocap/merkle-tree": "1.31.
|
|
59
|
-
"@ocap/message": "1.31.
|
|
60
|
-
"@ocap/state": "1.31.
|
|
61
|
-
"@ocap/tx-pipeline": "1.31.
|
|
62
|
-
"@ocap/types": "1.31.
|
|
63
|
-
"@ocap/util": "1.31.
|
|
64
|
-
"@ocap/wallet": "1.31.
|
|
55
|
+
"@ocap/asset": "1.31.3",
|
|
56
|
+
"@ocap/client": "1.31.3",
|
|
57
|
+
"@ocap/mcrypto": "1.31.3",
|
|
58
|
+
"@ocap/merkle-tree": "1.31.3",
|
|
59
|
+
"@ocap/message": "1.31.3",
|
|
60
|
+
"@ocap/state": "1.31.3",
|
|
61
|
+
"@ocap/tx-pipeline": "1.31.3",
|
|
62
|
+
"@ocap/types": "1.31.3",
|
|
63
|
+
"@ocap/util": "1.31.3",
|
|
64
|
+
"@ocap/wallet": "1.31.3",
|
|
65
65
|
"debug": "^4.4.3",
|
|
66
66
|
"deep-diff": "^1.0.2",
|
|
67
67
|
"lodash": "^4.17.23",
|
package/tools/fixtures.ts
CHANGED
|
@@ -5,7 +5,7 @@ import crypto from 'node:crypto';
|
|
|
5
5
|
import cloneDeep from 'lodash/cloneDeep';
|
|
6
6
|
import { types, getRandomBytes, toTxHash } from '@ocap/mcrypto';
|
|
7
7
|
import { fromRandom } from '@ocap/wallet';
|
|
8
|
-
import { fromTypeUrl } from '@ocap/message';
|
|
8
|
+
import { fromTypeUrl, toTypeUrl } from '@ocap/message';
|
|
9
9
|
import { encodeTx as encodeTxCbor } from '@ocap/message/cbor';
|
|
10
10
|
import { encodeTx as encodeTxProto } from '@ocap/message/protobuf';
|
|
11
11
|
import { toBase64, toBN, fromUnitToToken, fromTokenToUnit, toBase58, toHex } from '@ocap/util';
|
|
@@ -17,6 +17,7 @@ import { getTestChain, closeTestChain } from '@ocap/e2e-test/fixture';
|
|
|
17
17
|
import defaultConfigModule from '@ocap/e2e-test/config';
|
|
18
18
|
|
|
19
19
|
import { execute, createExecutor } from '../src';
|
|
20
|
+
import { DIRECT_GAS_REQUIRED_TX_TYPES, normalizeShortTxType } from '../src/gas-security-guard';
|
|
20
21
|
|
|
21
22
|
const defaultConfig = cloneDeep(defaultConfigModule);
|
|
22
23
|
|
|
@@ -204,12 +205,12 @@ export const prepareGasPayer = async () => {
|
|
|
204
205
|
return gasPayer;
|
|
205
206
|
};
|
|
206
207
|
|
|
207
|
-
export const getGasPayerHeader = async (txBuffer: Uint8Array) => {
|
|
208
|
+
export const getGasPayerHeader = async (txBuffer: Uint8Array, claims: Record<string, unknown> = {}) => {
|
|
208
209
|
const gasPayer = await prepareGasPayer();
|
|
209
210
|
return {
|
|
210
211
|
gasStakeHeaders: {
|
|
211
212
|
pk: toBase58(gasPayer.publicKey),
|
|
212
|
-
token: await JWT.sign(gasPayer.address, gasPayer.secretKey, { txHash: toTxHash(txBuffer) }),
|
|
213
|
+
token: await JWT.sign(gasPayer.address, gasPayer.secretKey, { txHash: toTxHash(txBuffer), ...claims }),
|
|
213
214
|
},
|
|
214
215
|
};
|
|
215
216
|
};
|
|
@@ -580,9 +581,13 @@ export const executeTx = (tx: any, withTxHash = false, _statedb: any = {}, optio
|
|
|
580
581
|
// Accept both so the gas-payer path keeps working across the transition.
|
|
581
582
|
const typeName = tx.itx.typeUrl ? fromTypeUrl(tx.itx.typeUrl) : tx.itx.type;
|
|
582
583
|
const { buffer: txBuffer } = await getClient()[`encode${typeName}`]({ tx });
|
|
584
|
+
// #1420: a sponsor's stake cannot waive gas for DIRECT_GAS_REQUIRED_TX_TYPES. A sponsor that covers such a
|
|
585
|
+
// tx pays real gas from its balance (paymaster direct-charge mode), so the fixture signs that mode for them.
|
|
586
|
+
const shortType = normalizeShortTxType(tx.itx.typeUrl || toTypeUrl(typeName));
|
|
587
|
+
const claims = DIRECT_GAS_REQUIRED_TX_TYPES.has(shortType) ? { mode: 'paymaster' } : {};
|
|
583
588
|
ctx.extra = {
|
|
584
589
|
...(ctx.extra || {}),
|
|
585
|
-
...(await getGasPayerHeader(txBuffer)),
|
|
590
|
+
...(await getGasPayerHeader(txBuffer, claims)),
|
|
586
591
|
};
|
|
587
592
|
}
|
|
588
593
|
|