@ocap/tx-protocols 1.28.9 → 1.29.0
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 +53 -0
- package/esm/execute.mjs +225 -0
- package/esm/index.d.mts +95 -0
- package/esm/index.mjs +100 -0
- package/esm/pipes/ensure-cost.d.mts +18 -0
- package/esm/pipes/ensure-cost.mjs +136 -0
- package/esm/pipes/ensure-gas.d.mts +14 -0
- package/esm/pipes/ensure-gas.mjs +38 -0
- package/esm/protocols/account/delegate.d.mts +4 -0
- package/esm/protocols/account/delegate.mjs +195 -0
- package/esm/protocols/account/migrate.d.mts +4 -0
- package/esm/protocols/account/migrate.mjs +130 -0
- package/esm/protocols/account/revoke-delegate.d.mts +4 -0
- package/esm/protocols/account/revoke-delegate.mjs +102 -0
- package/esm/protocols/asset/acquire-v2.d.mts +9 -0
- package/esm/protocols/asset/acquire-v2.mjs +213 -0
- package/esm/protocols/asset/acquire-v3.d.mts +17 -0
- package/esm/protocols/asset/acquire-v3.mjs +265 -0
- package/esm/protocols/asset/calls/transfer-token.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer-token.mjs +36 -0
- package/esm/protocols/asset/calls/transfer.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer.mjs +32 -0
- package/esm/protocols/asset/consume.d.mts +4 -0
- package/esm/protocols/asset/consume.mjs +92 -0
- package/esm/protocols/asset/create.d.mts +4 -0
- package/esm/protocols/asset/create.mjs +136 -0
- package/esm/protocols/asset/mint.d.mts +4 -0
- package/esm/protocols/asset/mint.mjs +156 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +24 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +54 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.d.mts +21 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +22 -0
- package/esm/protocols/asset/pipes/verify-itx-address.d.mts +32 -0
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +56 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.d.mts +18 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +27 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.d.mts +17 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.mjs +20 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.d.mts +15 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.mjs +14 -0
- package/esm/protocols/asset/update.d.mts +4 -0
- package/esm/protocols/asset/update.mjs +111 -0
- package/esm/protocols/factory/create.d.mts +29 -0
- package/esm/protocols/factory/create.mjs +155 -0
- package/esm/protocols/governance/claim-stake.d.mts +27 -0
- package/esm/protocols/governance/claim-stake.mjs +220 -0
- package/esm/protocols/governance/return-stake.d.mts +27 -0
- package/esm/protocols/governance/return-stake.mjs +211 -0
- package/esm/protocols/governance/revoke-stake.d.mts +27 -0
- package/esm/protocols/governance/revoke-stake.mjs +178 -0
- package/esm/protocols/governance/slash-stake.d.mts +17 -0
- package/esm/protocols/governance/slash-stake.mjs +213 -0
- package/esm/protocols/governance/stake.d.mts +15 -0
- package/esm/protocols/governance/stake.mjs +270 -0
- package/esm/protocols/rollup/claim-reward.d.mts +11 -0
- package/esm/protocols/rollup/claim-reward.mjs +322 -0
- package/esm/protocols/rollup/close.d.mts +4 -0
- package/esm/protocols/rollup/close.mjs +105 -0
- package/esm/protocols/rollup/create-block.d.mts +11 -0
- package/esm/protocols/rollup/create-block.mjs +303 -0
- package/esm/protocols/rollup/create.d.mts +4 -0
- package/esm/protocols/rollup/create.mjs +164 -0
- package/esm/protocols/rollup/join.d.mts +4 -0
- package/esm/protocols/rollup/join.mjs +152 -0
- package/esm/protocols/rollup/leave.d.mts +4 -0
- package/esm/protocols/rollup/leave.mjs +137 -0
- package/esm/protocols/rollup/migrate.d.mts +4 -0
- package/esm/protocols/rollup/migrate.mjs +85 -0
- package/esm/protocols/rollup/pause.d.mts +4 -0
- package/esm/protocols/rollup/pause.mjs +76 -0
- package/esm/protocols/rollup/pipes/ensure-validator.d.mts +6 -0
- package/esm/protocols/rollup/pipes/ensure-validator.mjs +12 -0
- package/esm/protocols/rollup/pipes/verify-evidence.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +29 -0
- package/esm/protocols/rollup/pipes/verify-signers.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-signers.mjs +36 -0
- package/esm/protocols/rollup/pipes/verify-status.d.mts +13 -0
- package/esm/protocols/rollup/pipes/verify-status.mjs +26 -0
- package/esm/protocols/rollup/resume.d.mts +4 -0
- package/esm/protocols/rollup/resume.mjs +79 -0
- package/esm/protocols/rollup/update.d.mts +4 -0
- package/esm/protocols/rollup/update.mjs +111 -0
- package/esm/protocols/token/create.d.mts +4 -0
- package/esm/protocols/token/create.mjs +150 -0
- package/esm/protocols/token/deposit-v2.d.mts +11 -0
- package/esm/protocols/token/deposit-v2.mjs +216 -0
- package/esm/protocols/token/withdraw-v2.d.mts +9 -0
- package/esm/protocols/token/withdraw-v2.mjs +222 -0
- package/esm/protocols/token-factory/burn.d.mts +15 -0
- package/esm/protocols/token-factory/burn.mjs +233 -0
- package/esm/protocols/token-factory/create.d.mts +4 -0
- package/esm/protocols/token-factory/create.mjs +254 -0
- package/esm/protocols/token-factory/mint.d.mts +15 -0
- package/esm/protocols/token-factory/mint.mjs +234 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.d.mts +21 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.mjs +34 -0
- package/esm/protocols/token-factory/pipes/verify-icon.d.mts +14 -0
- package/esm/protocols/token-factory/pipes/verify-icon.mjs +18 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.mjs +63 -0
- package/esm/protocols/token-factory/pipes/verify-url.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-url.mjs +26 -0
- package/esm/protocols/token-factory/update.d.mts +10 -0
- package/esm/protocols/token-factory/update.mjs +152 -0
- package/esm/protocols/trade/exchange-v2.d.mts +9 -0
- package/esm/protocols/trade/exchange-v2.mjs +239 -0
- package/esm/protocols/trade/transfer-v2.d.mts +9 -0
- package/esm/protocols/trade/transfer-v2.mjs +226 -0
- package/esm/protocols/trade/transfer-v3.d.mts +17 -0
- package/esm/protocols/trade/transfer-v3.mjs +270 -0
- package/esm/util.d.mts +141 -0
- package/esm/util.mjs +278 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/execute.cjs +231 -0
- package/lib/execute.d.cts +53 -0
- package/lib/index.cjs +105 -0
- package/lib/index.d.cts +95 -0
- package/lib/pipes/ensure-cost.cjs +141 -0
- package/lib/pipes/ensure-cost.d.cts +18 -0
- package/lib/pipes/ensure-gas.cjs +41 -0
- package/lib/pipes/ensure-gas.d.cts +14 -0
- package/lib/protocols/account/delegate.cjs +201 -0
- package/lib/protocols/account/delegate.d.cts +4 -0
- package/lib/protocols/account/migrate.cjs +135 -0
- package/lib/protocols/account/migrate.d.cts +4 -0
- package/lib/protocols/account/revoke-delegate.cjs +107 -0
- package/lib/protocols/account/revoke-delegate.d.cts +4 -0
- package/lib/protocols/asset/acquire-v2.cjs +216 -0
- package/lib/protocols/asset/acquire-v2.d.cts +9 -0
- package/lib/protocols/asset/acquire-v3.cjs +269 -0
- package/lib/protocols/asset/acquire-v3.d.cts +17 -0
- package/lib/protocols/asset/calls/transfer-token.cjs +40 -0
- package/lib/protocols/asset/calls/transfer-token.d.cts +4 -0
- package/lib/protocols/asset/calls/transfer.cjs +35 -0
- package/lib/protocols/asset/calls/transfer.d.cts +4 -0
- package/lib/protocols/asset/consume.cjs +95 -0
- package/lib/protocols/asset/consume.d.cts +4 -0
- package/lib/protocols/asset/create.cjs +140 -0
- package/lib/protocols/asset/create.d.cts +4 -0
- package/lib/protocols/asset/mint.cjs +159 -0
- package/lib/protocols/asset/mint.d.cts +4 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +57 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +24 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +25 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.d.cts +21 -0
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +59 -0
- package/lib/protocols/asset/pipes/verify-itx-address.d.cts +32 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +29 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.d.cts +18 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.cjs +22 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.d.cts +17 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.cjs +16 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.d.cts +15 -0
- package/lib/protocols/asset/update.cjs +114 -0
- package/lib/protocols/asset/update.d.cts +4 -0
- package/lib/protocols/factory/create.cjs +161 -0
- package/lib/protocols/factory/create.d.cts +29 -0
- package/lib/protocols/governance/claim-stake.cjs +223 -0
- package/lib/protocols/governance/claim-stake.d.cts +27 -0
- package/lib/protocols/governance/return-stake.cjs +215 -0
- package/lib/protocols/governance/return-stake.d.cts +27 -0
- package/lib/protocols/governance/revoke-stake.cjs +182 -0
- package/lib/protocols/governance/revoke-stake.d.cts +27 -0
- package/lib/protocols/governance/slash-stake.cjs +217 -0
- package/lib/protocols/governance/slash-stake.d.cts +17 -0
- package/lib/protocols/governance/stake.cjs +275 -0
- package/lib/protocols/governance/stake.d.cts +15 -0
- package/lib/protocols/rollup/claim-reward.cjs +328 -0
- package/lib/protocols/rollup/claim-reward.d.cts +11 -0
- package/lib/protocols/rollup/close.cjs +107 -0
- package/lib/protocols/rollup/close.d.cts +4 -0
- package/lib/protocols/rollup/create-block.cjs +309 -0
- package/lib/protocols/rollup/create-block.d.cts +11 -0
- package/lib/protocols/rollup/create.cjs +169 -0
- package/lib/protocols/rollup/create.d.cts +4 -0
- package/lib/protocols/rollup/join.cjs +157 -0
- package/lib/protocols/rollup/join.d.cts +4 -0
- package/lib/protocols/rollup/leave.cjs +141 -0
- package/lib/protocols/rollup/leave.d.cts +4 -0
- package/lib/protocols/rollup/migrate.cjs +87 -0
- package/lib/protocols/rollup/migrate.d.cts +4 -0
- package/lib/protocols/rollup/pause.cjs +78 -0
- package/lib/protocols/rollup/pause.d.cts +4 -0
- package/lib/protocols/rollup/pipes/ensure-validator.cjs +14 -0
- package/lib/protocols/rollup/pipes/ensure-validator.d.cts +6 -0
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +32 -0
- package/lib/protocols/rollup/pipes/verify-evidence.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-signers.cjs +39 -0
- package/lib/protocols/rollup/pipes/verify-signers.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-status.cjs +28 -0
- package/lib/protocols/rollup/pipes/verify-status.d.cts +13 -0
- package/lib/protocols/rollup/resume.cjs +81 -0
- package/lib/protocols/rollup/resume.d.cts +4 -0
- package/lib/protocols/rollup/update.cjs +114 -0
- package/lib/protocols/rollup/update.d.cts +4 -0
- package/lib/protocols/token/create.cjs +156 -0
- package/lib/protocols/token/create.d.cts +4 -0
- package/lib/protocols/token/deposit-v2.cjs +219 -0
- package/lib/protocols/token/deposit-v2.d.cts +11 -0
- package/lib/protocols/token/withdraw-v2.cjs +225 -0
- package/lib/protocols/token/withdraw-v2.d.cts +9 -0
- package/lib/protocols/token-factory/burn.cjs +236 -0
- package/lib/protocols/token-factory/burn.d.cts +15 -0
- package/lib/protocols/token-factory/create.cjs +260 -0
- package/lib/protocols/token-factory/create.d.cts +4 -0
- package/lib/protocols/token-factory/mint.cjs +237 -0
- package/lib/protocols/token-factory/mint.d.cts +15 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.cjs +38 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.d.cts +21 -0
- package/lib/protocols/token-factory/pipes/verify-icon.cjs +22 -0
- package/lib/protocols/token-factory/pipes/verify-icon.d.cts +14 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.cjs +66 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.d.cts +12 -0
- package/lib/protocols/token-factory/pipes/verify-url.cjs +29 -0
- package/lib/protocols/token-factory/pipes/verify-url.d.cts +12 -0
- package/lib/protocols/token-factory/update.cjs +155 -0
- package/lib/protocols/token-factory/update.d.cts +10 -0
- package/lib/protocols/trade/exchange-v2.cjs +243 -0
- package/lib/protocols/trade/exchange-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v2.cjs +229 -0
- package/lib/protocols/trade/transfer-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v3.cjs +274 -0
- package/lib/protocols/trade/transfer-v3.d.cts +17 -0
- package/lib/util.cjs +296 -0
- package/lib/util.d.cts +141 -0
- package/package.json +49 -22
- package/tools/fixtures.ts +564 -0
- package/lib/execute.js +0 -254
- package/lib/index.js +0 -117
- package/lib/pipes/ensure-cost.js +0 -193
- package/lib/pipes/ensure-gas.js +0 -48
- package/lib/protocols/account/delegate.js +0 -223
- package/lib/protocols/account/migrate.js +0 -153
- package/lib/protocols/account/revoke-delegate.js +0 -110
- package/lib/protocols/asset/acquire-v2.js +0 -262
- package/lib/protocols/asset/acquire-v3.js +0 -330
- package/lib/protocols/asset/calls/README.md +0 -5
- package/lib/protocols/asset/calls/transfer-token.js +0 -36
- package/lib/protocols/asset/calls/transfer.js +0 -28
- package/lib/protocols/asset/consume.js +0 -105
- package/lib/protocols/asset/create.js +0 -151
- package/lib/protocols/asset/mint.js +0 -199
- package/lib/protocols/asset/pipes/exec-mint-hook.js +0 -62
- package/lib/protocols/asset/pipes/extract-factory-tokens.js +0 -18
- package/lib/protocols/asset/pipes/verify-itx-address.js +0 -54
- package/lib/protocols/asset/pipes/verify-itx-assets.js +0 -51
- package/lib/protocols/asset/pipes/verify-itx-variables.js +0 -26
- package/lib/protocols/asset/pipes/verify-mint-limit.js +0 -13
- package/lib/protocols/asset/update.js +0 -131
- package/lib/protocols/factory/create.js +0 -191
- package/lib/protocols/governance/claim-stake.js +0 -266
- package/lib/protocols/governance/return-stake.js +0 -248
- package/lib/protocols/governance/revoke-stake.js +0 -172
- package/lib/protocols/governance/slash-stake.js +0 -271
- package/lib/protocols/governance/stake.js +0 -303
- package/lib/protocols/rollup/claim-reward.js +0 -342
- package/lib/protocols/rollup/close.js +0 -104
- package/lib/protocols/rollup/create-block.js +0 -413
- package/lib/protocols/rollup/create.js +0 -197
- package/lib/protocols/rollup/join.js +0 -182
- package/lib/protocols/rollup/leave.js +0 -145
- package/lib/protocols/rollup/migrate.js +0 -85
- package/lib/protocols/rollup/pause.js +0 -75
- package/lib/protocols/rollup/pipes/ensure-validator.js +0 -12
- package/lib/protocols/rollup/pipes/verify-evidence.js +0 -37
- package/lib/protocols/rollup/pipes/verify-signers.js +0 -87
- package/lib/protocols/rollup/pipes/verify-status.js +0 -30
- package/lib/protocols/rollup/resume.js +0 -75
- package/lib/protocols/rollup/update.js +0 -122
- package/lib/protocols/token/create.js +0 -199
- package/lib/protocols/token/deposit-v2.js +0 -290
- package/lib/protocols/token/withdraw-v2.js +0 -305
- package/lib/protocols/token-factory/burn.js +0 -371
- package/lib/protocols/token-factory/create.js +0 -342
- package/lib/protocols/token-factory/mint.js +0 -385
- package/lib/protocols/token-factory/pipes/calc-reserve.js +0 -37
- package/lib/protocols/token-factory/pipes/verify-icon.js +0 -27
- package/lib/protocols/token-factory/pipes/verify-ownership.js +0 -93
- package/lib/protocols/token-factory/pipes/verify-url.js +0 -32
- package/lib/protocols/token-factory/update.js +0 -208
- package/lib/protocols/trade/exchange-v2.js +0 -239
- package/lib/protocols/trade/transfer-v2.js +0 -233
- package/lib/protocols/trade/transfer-v3.js +0 -333
- package/lib/util.js +0 -442
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util = require("@ocap/util");
|
|
4
|
+
let debug = require("debug");
|
|
5
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
6
|
+
|
|
7
|
+
//#region src/pipes/ensure-gas.ts
|
|
8
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:pipes:ensure-gas");
|
|
9
|
+
function CreateGasEnsureFn(estimateTxGas) {
|
|
10
|
+
return function EnsureTxGas(context, next) {
|
|
11
|
+
const { txHash = "", config } = context;
|
|
12
|
+
const { txGas } = config.transaction;
|
|
13
|
+
const basePrice = new _ocap_util.BN(txGas.price);
|
|
14
|
+
const estimate = estimateTxGas(context);
|
|
15
|
+
let totalGas = new _ocap_util.BN(0);
|
|
16
|
+
if (context.txBaseGas) {
|
|
17
|
+
totalGas = basePrice.mul(new _ocap_util.BN(txGas.dataStorage)).mul(new _ocap_util.BN(context.txSize));
|
|
18
|
+
totalGas = totalGas.add(basePrice.mul(new _ocap_util.BN(txGas.createState)).mul(new _ocap_util.BN(estimate.create + 1)));
|
|
19
|
+
totalGas = totalGas.add(basePrice.mul(new _ocap_util.BN(txGas.updateState)).mul(new _ocap_util.BN(estimate.update)));
|
|
20
|
+
}
|
|
21
|
+
const { txGas: gasVaults = [] } = config.vaults;
|
|
22
|
+
const gasVault = gasVaults[gasVaults.length > 0 ? (0, _ocap_util.hexToNumber)(txHash.slice(-8)) % gasVaults.length : 0];
|
|
23
|
+
context.gasVault = gasVault;
|
|
24
|
+
debug$1({
|
|
25
|
+
txType: context.txType,
|
|
26
|
+
txHash: context.txHash,
|
|
27
|
+
txSize: context.txSize,
|
|
28
|
+
txBaseGas: context.txBaseGas,
|
|
29
|
+
totalGas: totalGas.toString(10),
|
|
30
|
+
gasVault,
|
|
31
|
+
estimate
|
|
32
|
+
});
|
|
33
|
+
context.totalGas = totalGas;
|
|
34
|
+
context.gasEstimate = estimate;
|
|
35
|
+
return next();
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
var ensure_gas_default = CreateGasEnsureFn;
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.default = ensure_gas_default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
2
|
+
|
|
3
|
+
//#region src/pipes/ensure-gas.d.ts
|
|
4
|
+
/** Gas estimate result */
|
|
5
|
+
interface IGasEstimate {
|
|
6
|
+
create: number;
|
|
7
|
+
update: number;
|
|
8
|
+
payment?: number;
|
|
9
|
+
}
|
|
10
|
+
/** Gas estimator function type - uses any for flexible context access */
|
|
11
|
+
type GasEstimatorFn = (context: any) => IGasEstimate;
|
|
12
|
+
declare function CreateGasEnsureFn(estimateTxGas: GasEstimatorFn): PipeFunction<any>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { CreateGasEnsureFn as default };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
6
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
|
+
let lodash_get = require("lodash/get");
|
|
8
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
9
|
+
let lodash_pick = require("lodash/pick");
|
|
10
|
+
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
11
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
12
|
+
let _ocap_state = require("@ocap/state");
|
|
13
|
+
let debug = require("debug");
|
|
14
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
15
|
+
let _ocap_message = require("@ocap/message");
|
|
16
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
17
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
18
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
19
|
+
|
|
20
|
+
//#region src/protocols/account/delegate.ts
|
|
21
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:delegate");
|
|
22
|
+
const runner = new _ocap_tx_pipeline.Runner("delegate");
|
|
23
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
24
|
+
const rateLimit = _arcblock_validator.Joi.object({
|
|
25
|
+
interval: _arcblock_validator.Joi.number().integer().greater(0).required(),
|
|
26
|
+
anchor: _arcblock_validator.Joi.number().integer().min(0).optional().allow(null).default(0)
|
|
27
|
+
});
|
|
28
|
+
const tokenLimit = _arcblock_validator.Joi.object({
|
|
29
|
+
address: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN").required(),
|
|
30
|
+
toList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix()).max(32).unique().optional().allow(null).default([]),
|
|
31
|
+
txCount: _arcblock_validator.Joi.number().integer().min(0).empty("").optional().allow(null).default(0),
|
|
32
|
+
txAllowance: _arcblock_validator.Joi.BN().optional().allow(null).default("0"),
|
|
33
|
+
totalAllowance: _arcblock_validator.Joi.BN().optional().allow(null).default("0"),
|
|
34
|
+
validUntil: _arcblock_validator.Joi.number().integer().min(0).empty("").optional().allow(null).default(0),
|
|
35
|
+
rate: rateLimit.optional().allow(null)
|
|
36
|
+
});
|
|
37
|
+
const assetLimit = _arcblock_validator.Joi.object({
|
|
38
|
+
address: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix().role("ROLE_ASSET")).unique().max(1024).optional().allow(null).default([]),
|
|
39
|
+
toList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix()).unique().max(32).optional().allow(null).default([]),
|
|
40
|
+
txCount: _arcblock_validator.Joi.number().integer().min(0).empty("").optional().allow(null).default(0),
|
|
41
|
+
validUntil: _arcblock_validator.Joi.number().integer().min(0).empty("").optional().allow(null).default(0),
|
|
42
|
+
rate: rateLimit.optional().allow(null)
|
|
43
|
+
});
|
|
44
|
+
const schema = _arcblock_validator.Joi.object({
|
|
45
|
+
address: _arcblock_validator.Joi.DID().prefix().role("ROLE_DELEGATION").required(),
|
|
46
|
+
to: _arcblock_validator.Joi.DID().prefix().required(),
|
|
47
|
+
opsList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.object({
|
|
48
|
+
typeUrl: _arcblock_validator.Joi.string().required(),
|
|
49
|
+
limit: _arcblock_validator.Joi.object({
|
|
50
|
+
tokensList: _arcblock_validator.Joi.array().items(tokenLimit).unique((a, b) => a.address === b.address).max(32),
|
|
51
|
+
assetsList: _arcblock_validator.Joi.array().items(assetLimit).max(32)
|
|
52
|
+
}).optional().allow(null).default({
|
|
53
|
+
tokensList: [],
|
|
54
|
+
assetsList: []
|
|
55
|
+
})
|
|
56
|
+
})).unique((a, b) => a.typeUrl === b.typeUrl).min(1).required(),
|
|
57
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
58
|
+
}).options({
|
|
59
|
+
stripUnknown: true,
|
|
60
|
+
noDefaults: false
|
|
61
|
+
});
|
|
62
|
+
runner.use((context, next) => {
|
|
63
|
+
const { error, value } = schema.validate(context.itx);
|
|
64
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
65
|
+
context.formattedItx = (0, _ocap_message.formatMessage)("DelegateTx", context.itx);
|
|
66
|
+
context.validatedItx = value;
|
|
67
|
+
return next();
|
|
68
|
+
});
|
|
69
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
70
|
+
error: "INVALID_TX",
|
|
71
|
+
message: "Delegation address does not match",
|
|
72
|
+
fn: (ctx) => {
|
|
73
|
+
const context = ctx;
|
|
74
|
+
return (0, _arcblock_did_util.toDelegateAddress)(context.tx.from, context.itx.to) === context.itx.address;
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
error: "INVALID_DELEGATION_TYPE_URL",
|
|
78
|
+
message: "Delegation type url is not allowed",
|
|
79
|
+
fn: (ctx) => {
|
|
80
|
+
const context = ctx;
|
|
81
|
+
const allowed = (0, lodash_get.default)(context.config, "transaction.delegate.typeUrls", []);
|
|
82
|
+
return (context.formattedItx?.ops || []).every((op) => allowed.includes(op.typeUrl));
|
|
83
|
+
}
|
|
84
|
+
}]));
|
|
85
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
86
|
+
from: "tx.from",
|
|
87
|
+
to: "senderState",
|
|
88
|
+
status: "OK",
|
|
89
|
+
table: "account"
|
|
90
|
+
}));
|
|
91
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
92
|
+
stateKey: "senderState",
|
|
93
|
+
addressKey: "tx.from"
|
|
94
|
+
}));
|
|
95
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
96
|
+
from: "itx.to",
|
|
97
|
+
to: "receiverState",
|
|
98
|
+
status: "OK",
|
|
99
|
+
table: "account"
|
|
100
|
+
}));
|
|
101
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["receiverState"] }));
|
|
102
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
103
|
+
stateKey: "receiverState",
|
|
104
|
+
addressKey: "itx.to"
|
|
105
|
+
}));
|
|
106
|
+
runner.use(_ocap_tx_pipeline.pipes.AntiLandAttack({
|
|
107
|
+
senderState: "senderState",
|
|
108
|
+
receiverState: "receiverState"
|
|
109
|
+
}));
|
|
110
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
111
|
+
from: "itx.address",
|
|
112
|
+
to: "delegationState",
|
|
113
|
+
table: "delegation",
|
|
114
|
+
status: "OK"
|
|
115
|
+
}));
|
|
116
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
117
|
+
const result = {
|
|
118
|
+
create: 0,
|
|
119
|
+
update: 1,
|
|
120
|
+
payment: 0
|
|
121
|
+
};
|
|
122
|
+
if (context.receiverState) result.update += 1;
|
|
123
|
+
else result.create += 1;
|
|
124
|
+
if (context.delegationState) result.update += 1;
|
|
125
|
+
else result.create += 1;
|
|
126
|
+
return result;
|
|
127
|
+
}));
|
|
128
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
129
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
130
|
+
runner.use(async (context, next) => {
|
|
131
|
+
const { tx, itx, formattedItx, validatedItx, statedb, senderState, receiverState, delegationState, senderUpdates, updateVaults } = context;
|
|
132
|
+
const ops = formattedItx?.ops || [];
|
|
133
|
+
const opsList = validatedItx?.opsList || [];
|
|
134
|
+
const merged = (0, lodash_cloneDeep.default)(ops).reduce((acc, x, i) => {
|
|
135
|
+
const tokens = x.limit?.tokens || [];
|
|
136
|
+
const assets = x.limit?.assets || [];
|
|
137
|
+
acc[x.typeUrl] = { limit: {
|
|
138
|
+
tokens: tokens.map((y, j) => {
|
|
139
|
+
const input = opsList[i]?.limit?.tokensList?.[j] || {};
|
|
140
|
+
return Object.assign(y, (0, lodash_pick.default)(input, [
|
|
141
|
+
"txCount",
|
|
142
|
+
"txAllowance",
|
|
143
|
+
"totalAllowance",
|
|
144
|
+
"validUntil",
|
|
145
|
+
"rate"
|
|
146
|
+
]), {
|
|
147
|
+
txSent: 0,
|
|
148
|
+
lastTx: y.rate ? y.rate.anchor : 0,
|
|
149
|
+
spentAllowance: "0"
|
|
150
|
+
});
|
|
151
|
+
}),
|
|
152
|
+
assets: assets.map((y, j) => {
|
|
153
|
+
const input = opsList[i]?.limit?.assetsList?.[j] || {};
|
|
154
|
+
return Object.assign(y, (0, lodash_pick.default)(input, [
|
|
155
|
+
"txCount",
|
|
156
|
+
"validUntil",
|
|
157
|
+
"rate"
|
|
158
|
+
]), {
|
|
159
|
+
txSent: 0,
|
|
160
|
+
lastTx: y.rate ? y.rate.anchor : 0
|
|
161
|
+
});
|
|
162
|
+
})
|
|
163
|
+
} };
|
|
164
|
+
return acc;
|
|
165
|
+
}, delegationState ? delegationState.ops : {});
|
|
166
|
+
const sender = senderState ? senderState.address : tx.from;
|
|
167
|
+
const receiver = receiverState ? receiverState.address : itx.to;
|
|
168
|
+
const tokenAddress = context.config.token.address;
|
|
169
|
+
const [newSenderState, newReceiverState, newDelegationState] = await Promise.all([
|
|
170
|
+
statedb.account.updateOrCreate(senderState ?? null, _ocap_state.account.updateOrCreate(senderState ?? null, {
|
|
171
|
+
...senderUpdates,
|
|
172
|
+
address: sender,
|
|
173
|
+
nonce: tx.nonce,
|
|
174
|
+
pk: tx.pk
|
|
175
|
+
}, context), context),
|
|
176
|
+
receiverState ? Promise.resolve(receiverState) : statedb.account.create(receiver, _ocap_state.account.create({
|
|
177
|
+
address: receiver,
|
|
178
|
+
tokens: { [tokenAddress]: "0" }
|
|
179
|
+
}, context), context),
|
|
180
|
+
delegationState ? statedb.delegation.update(itx.address, _ocap_state.delegation.update(delegationState, {
|
|
181
|
+
...itx,
|
|
182
|
+
from: sender,
|
|
183
|
+
ops: merged
|
|
184
|
+
}, context), context) : statedb.delegation.create(itx.address, _ocap_state.delegation.create({
|
|
185
|
+
...itx,
|
|
186
|
+
from: sender,
|
|
187
|
+
ops: merged
|
|
188
|
+
}, context), context)
|
|
189
|
+
]);
|
|
190
|
+
if (updateVaults) await updateVaults();
|
|
191
|
+
debug$1(delegationState ? "update" : "create", newDelegationState);
|
|
192
|
+
context.senderState = newSenderState;
|
|
193
|
+
context.receiverState = newReceiverState;
|
|
194
|
+
context.delegationState = newDelegationState;
|
|
195
|
+
return next();
|
|
196
|
+
}, { persistError: true });
|
|
197
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
198
|
+
var delegate_default = runner;
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
exports.default = delegate_default;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_util = require('../../util.cjs');
|
|
4
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
7
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
8
|
+
let _arcblock_did = require("@arcblock/did");
|
|
9
|
+
let _ocap_state = require("@ocap/state");
|
|
10
|
+
let debug = require("debug");
|
|
11
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
12
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
13
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
14
|
+
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
15
|
+
let lodash_flatten = require("lodash/flatten");
|
|
16
|
+
lodash_flatten = require_rolldown_runtime.__toESM(lodash_flatten);
|
|
17
|
+
let lodash_uniq = require("lodash/uniq");
|
|
18
|
+
lodash_uniq = require_rolldown_runtime.__toESM(lodash_uniq);
|
|
19
|
+
|
|
20
|
+
//#region src/protocols/account/migrate.ts
|
|
21
|
+
const { RoleType } = _ocap_mcrypto.types;
|
|
22
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:migrate");
|
|
23
|
+
const runner = new _ocap_tx_pipeline.Runner("account_migrate");
|
|
24
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
25
|
+
const schema = _arcblock_validator.Joi.object({
|
|
26
|
+
address: _arcblock_validator.Joi.DID().prefix().required(),
|
|
27
|
+
pk: _arcblock_validator.Joi.any().required(),
|
|
28
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
29
|
+
}).options({
|
|
30
|
+
stripUnknown: true,
|
|
31
|
+
noDefaults: false
|
|
32
|
+
});
|
|
33
|
+
runner.use((context, next) => {
|
|
34
|
+
const { error } = schema.validate(context.itx);
|
|
35
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
36
|
+
return next();
|
|
37
|
+
});
|
|
38
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
39
|
+
error: "INVALID_RECEIVER_STATE",
|
|
40
|
+
message: "Receiver pk and address does not match",
|
|
41
|
+
fn: (ctx) => {
|
|
42
|
+
const context = ctx;
|
|
43
|
+
return (0, _arcblock_did.fromPublicKey)(context.itx.pk, (0, _arcblock_did.toTypeInfo)(context.itx.address)) === context.itx.address && context.itx.address !== context.tx.from;
|
|
44
|
+
}
|
|
45
|
+
}]));
|
|
46
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
47
|
+
from: "tx.from",
|
|
48
|
+
to: "senderState",
|
|
49
|
+
status: "OK",
|
|
50
|
+
table: "account"
|
|
51
|
+
}));
|
|
52
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
53
|
+
stateKey: "senderState",
|
|
54
|
+
addressKey: "tx.from"
|
|
55
|
+
}));
|
|
56
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
57
|
+
const { senderState, tx, itx } = context;
|
|
58
|
+
if ([senderState?.address || tx.from, itx.address].every((address) => (0, _arcblock_did.toTypeInfo)(address).role === RoleType.ROLE_APPLICATION)) {
|
|
59
|
+
Object.defineProperty(context, "txBaseGas", { value: false });
|
|
60
|
+
return {
|
|
61
|
+
create: 0,
|
|
62
|
+
update: 0,
|
|
63
|
+
payment: 0
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (itx.data) {
|
|
67
|
+
const decodedValue = require_util.decodeAnySafe(itx.data)?.value;
|
|
68
|
+
if (decodedValue && decodedValue.purpose === "connect-wallet") {
|
|
69
|
+
Object.defineProperty(context, "txBaseGas", { value: false });
|
|
70
|
+
return {
|
|
71
|
+
create: 0,
|
|
72
|
+
update: 0,
|
|
73
|
+
payment: 0
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
create: context.senderState ? 1 : 2,
|
|
79
|
+
update: context.senderState ? (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(context.senderState).length : 0,
|
|
80
|
+
payment: 0
|
|
81
|
+
};
|
|
82
|
+
}));
|
|
83
|
+
runner.use(require_pipes_ensure_cost.default({
|
|
84
|
+
attachSenderChanges: true,
|
|
85
|
+
throwOnInsufficientFund: false
|
|
86
|
+
}));
|
|
87
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
88
|
+
runner.use(async (context, next) => {
|
|
89
|
+
const { statedb, tx, itx, senderUpdates, updateVaults } = context;
|
|
90
|
+
const sender = context.senderState;
|
|
91
|
+
const receiver = await statedb.account.get(itx.address, context);
|
|
92
|
+
const tokenAddress = context.config.token.address;
|
|
93
|
+
const senderTokens = sender?.tokens || { [tokenAddress]: "0" };
|
|
94
|
+
const senderAddress = sender?.address || tx.from;
|
|
95
|
+
if (receiver) return next(new _ocap_util_lib_error.CustomError("INVALID_RECEIVER_STATE", "Can not migrate to an existing account"));
|
|
96
|
+
const newAccount = await statedb.account.create(itx.address, _ocap_state.account.create({
|
|
97
|
+
...sender || { tokens: senderTokens },
|
|
98
|
+
...senderUpdates,
|
|
99
|
+
address: itx.address,
|
|
100
|
+
pk: itx.pk,
|
|
101
|
+
migratedFrom: sender ? (0, lodash_uniq.default)((0, lodash_flatten.default)([sender.address, ...sender.migratedFrom || []])) : [senderAddress]
|
|
102
|
+
}, context), context);
|
|
103
|
+
debug$1("new account", newAccount);
|
|
104
|
+
const addresses = sender ? (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(sender) : [senderAddress];
|
|
105
|
+
const states = await Promise.all(addresses.map(async (address) => {
|
|
106
|
+
let state;
|
|
107
|
+
if (address === senderAddress) {
|
|
108
|
+
state = _ocap_state.account.updateOrCreate(sender ?? null, {
|
|
109
|
+
address,
|
|
110
|
+
tokens: senderTokens,
|
|
111
|
+
migratedTo: [itx.address],
|
|
112
|
+
nonce: tx.nonce
|
|
113
|
+
}, context);
|
|
114
|
+
await statedb.account.updateOrCreate(sender ?? null, state, context);
|
|
115
|
+
} else {
|
|
116
|
+
const old = await statedb.account.get(address, {
|
|
117
|
+
traceMigration: false,
|
|
118
|
+
txn: context.txn
|
|
119
|
+
});
|
|
120
|
+
state = _ocap_state.account.update(old, { migratedTo: [itx.address] }, context);
|
|
121
|
+
await statedb.account.update(address, state, context);
|
|
122
|
+
}
|
|
123
|
+
return state;
|
|
124
|
+
}));
|
|
125
|
+
debug$1("old accounts", states);
|
|
126
|
+
if (updateVaults) await updateVaults();
|
|
127
|
+
context.receiverState = newAccount;
|
|
128
|
+
context.senderState = states.find((x) => x.address === senderAddress);
|
|
129
|
+
return next();
|
|
130
|
+
}, { persistError: true });
|
|
131
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
132
|
+
var migrate_default = runner;
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
exports.default = migrate_default;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
6
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
|
+
let lodash_get = require("lodash/get");
|
|
8
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
9
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
10
|
+
let _ocap_state = require("@ocap/state");
|
|
11
|
+
let debug = require("debug");
|
|
12
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
13
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
14
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
15
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
16
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
17
|
+
|
|
18
|
+
//#region src/protocols/account/revoke-delegate.ts
|
|
19
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:delegate");
|
|
20
|
+
const runner = new _ocap_tx_pipeline.Runner("revoke_delegate");
|
|
21
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
22
|
+
const schema = _arcblock_validator.Joi.object({
|
|
23
|
+
address: _arcblock_validator.Joi.DID().prefix().role("ROLE_DELEGATION").required(),
|
|
24
|
+
to: _arcblock_validator.Joi.DID().prefix().required(),
|
|
25
|
+
typeUrlsList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.string().required()).min(1).required(),
|
|
26
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
27
|
+
}).options({
|
|
28
|
+
stripUnknown: true,
|
|
29
|
+
noDefaults: false
|
|
30
|
+
});
|
|
31
|
+
runner.use((context, next) => {
|
|
32
|
+
const { error } = schema.validate(context.itx);
|
|
33
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
34
|
+
return next();
|
|
35
|
+
});
|
|
36
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
37
|
+
{
|
|
38
|
+
error: "OK",
|
|
39
|
+
fn: (ctx) => {
|
|
40
|
+
const context = ctx;
|
|
41
|
+
context.typeUrls = (0, _ocap_util_lib_get_list_field.getListField)(context, "itx.typeUrls");
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
error: "INVALID_TX",
|
|
47
|
+
message: "Delegation address does not match",
|
|
48
|
+
fn: (ctx) => {
|
|
49
|
+
const context = ctx;
|
|
50
|
+
return (0, _arcblock_did_util.toDelegateAddress)(context.tx.from, context.itx.to) === context.itx.address;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
error: "INVALID_DELEGATION_TYPE_URL",
|
|
55
|
+
message: "Delegation type url is not allowed",
|
|
56
|
+
fn: (ctx) => {
|
|
57
|
+
const context = ctx;
|
|
58
|
+
const allowed = (0, lodash_get.default)(context.config, "transaction.delegate.typeUrls", []);
|
|
59
|
+
return (context.typeUrls || []).every((x) => allowed.includes(x));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
]));
|
|
63
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
64
|
+
from: "itx.address",
|
|
65
|
+
to: "delegationState",
|
|
66
|
+
status: "INVALID_DELEGATION",
|
|
67
|
+
table: "delegation"
|
|
68
|
+
}));
|
|
69
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
70
|
+
from: "tx.from",
|
|
71
|
+
to: "senderState",
|
|
72
|
+
status: "INVALID_SENDER_STATE",
|
|
73
|
+
table: "account"
|
|
74
|
+
}));
|
|
75
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
76
|
+
stateKey: "senderState",
|
|
77
|
+
addressKey: "tx.from"
|
|
78
|
+
}));
|
|
79
|
+
runner.use(require_pipes_ensure_gas.default(() => ({
|
|
80
|
+
create: 0,
|
|
81
|
+
update: 2,
|
|
82
|
+
payment: 0
|
|
83
|
+
})));
|
|
84
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
85
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
86
|
+
runner.use(async (context, next) => {
|
|
87
|
+
const { tx, itx, typeUrls, statedb, senderState, senderUpdates, delegationState, updateVaults } = context;
|
|
88
|
+
debug$1("update", {
|
|
89
|
+
address: itx.address,
|
|
90
|
+
typeUrls
|
|
91
|
+
});
|
|
92
|
+
const newOps = (0, lodash_cloneDeep.default)(delegationState.ops);
|
|
93
|
+
(typeUrls || []).forEach((x) => delete newOps[x]);
|
|
94
|
+
const [newSenderState, newDelegationState] = await Promise.all([statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
95
|
+
...senderUpdates,
|
|
96
|
+
nonce: tx.nonce
|
|
97
|
+
}, context), context), statedb.delegation.update(itx.address, _ocap_state.delegation.update(delegationState, { ops: newOps }, context), context)]);
|
|
98
|
+
if (updateVaults) await updateVaults();
|
|
99
|
+
context.senderState = newSenderState;
|
|
100
|
+
context.delegationState = newDelegationState;
|
|
101
|
+
return next();
|
|
102
|
+
}, { persistError: true });
|
|
103
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
104
|
+
var revoke_delegate_default = runner;
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
exports.default = revoke_delegate_default;
|