@ocap/tx-protocols 1.29.27 → 1.30.1
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/_virtual/rolldown_runtime.mjs +32 -0
- package/esm/node_modules/bn.js/lib/bn.mjs +2551 -0
- package/esm/node_modules/valibot/dist/index.mjs +663 -0
- package/esm/protocols/account/delegate.mjs +42 -36
- package/esm/protocols/account/migrate.mjs +7 -10
- package/esm/protocols/account/revoke-delegate.mjs +11 -11
- package/esm/protocols/asset/acquire-v2.mjs +19 -13
- package/esm/protocols/asset/acquire-v3.mjs +17 -14
- package/esm/protocols/asset/consume.mjs +9 -9
- package/esm/protocols/asset/create.mjs +2 -1
- package/esm/protocols/asset/mint.mjs +19 -13
- package/esm/protocols/asset/update.mjs +11 -11
- package/esm/protocols/governance/claim-stake.mjs +10 -10
- package/esm/protocols/governance/return-stake.mjs +11 -11
- package/esm/protocols/governance/revoke-stake.mjs +10 -10
- package/esm/protocols/governance/slash-stake.mjs +11 -11
- package/esm/protocols/governance/stake.mjs +16 -16
- package/esm/protocols/rollup/claim-reward.mjs +21 -18
- package/esm/protocols/rollup/close.mjs +16 -13
- package/esm/protocols/rollup/create-block.mjs +25 -22
- package/esm/protocols/rollup/join.mjs +14 -12
- package/esm/protocols/rollup/leave.mjs +12 -11
- package/esm/protocols/rollup/migrate.mjs +15 -12
- package/esm/protocols/rollup/pause.mjs +9 -9
- package/esm/protocols/rollup/resume.mjs +9 -9
- package/esm/protocols/rollup/update.mjs +31 -28
- package/esm/protocols/token/create.mjs +25 -22
- package/esm/protocols/token/deposit-v2.mjs +20 -14
- package/esm/protocols/token/withdraw-v2.mjs +20 -14
- package/esm/protocols/token-factory/burn.mjs +12 -12
- package/esm/protocols/token-factory/create.mjs +45 -37
- package/esm/protocols/token-factory/mint.mjs +13 -12
- package/esm/protocols/token-factory/update.mjs +21 -21
- package/esm/protocols/trade/exchange-v2.mjs +15 -15
- package/esm/protocols/trade/transfer-v2.mjs +12 -12
- package/esm/protocols/trade/transfer-v3.mjs +7 -10
- package/esm/util.d.mts +3 -1
- package/esm/util.mjs +16 -1
- package/lib/_virtual/rolldown_runtime.cjs +2 -0
- package/lib/node_modules/bn.js/lib/bn.cjs +2554 -0
- package/lib/node_modules/valibot/dist/index.cjs +683 -0
- package/lib/protocols/account/delegate.cjs +41 -35
- package/lib/protocols/account/migrate.cjs +6 -9
- package/lib/protocols/account/revoke-delegate.cjs +10 -10
- package/lib/protocols/asset/acquire-v2.cjs +18 -12
- package/lib/protocols/asset/acquire-v3.cjs +16 -13
- package/lib/protocols/asset/consume.cjs +8 -8
- package/lib/protocols/asset/create.cjs +2 -1
- package/lib/protocols/asset/mint.cjs +18 -12
- package/lib/protocols/asset/update.cjs +10 -10
- package/lib/protocols/governance/claim-stake.cjs +9 -9
- package/lib/protocols/governance/return-stake.cjs +10 -10
- package/lib/protocols/governance/revoke-stake.cjs +9 -9
- package/lib/protocols/governance/slash-stake.cjs +10 -10
- package/lib/protocols/governance/stake.cjs +15 -15
- package/lib/protocols/rollup/claim-reward.cjs +20 -17
- package/lib/protocols/rollup/close.cjs +15 -12
- package/lib/protocols/rollup/create-block.cjs +24 -21
- package/lib/protocols/rollup/join.cjs +13 -11
- package/lib/protocols/rollup/leave.cjs +11 -10
- package/lib/protocols/rollup/migrate.cjs +14 -11
- package/lib/protocols/rollup/pause.cjs +8 -8
- package/lib/protocols/rollup/resume.cjs +8 -8
- package/lib/protocols/rollup/update.cjs +29 -27
- package/lib/protocols/token/create.cjs +23 -20
- package/lib/protocols/token/deposit-v2.cjs +19 -13
- package/lib/protocols/token/withdraw-v2.cjs +19 -13
- package/lib/protocols/token-factory/burn.cjs +11 -11
- package/lib/protocols/token-factory/create.cjs +43 -35
- package/lib/protocols/token-factory/mint.cjs +12 -11
- package/lib/protocols/token-factory/update.cjs +19 -19
- package/lib/protocols/trade/exchange-v2.cjs +14 -14
- package/lib/protocols/trade/transfer-v2.cjs +11 -11
- package/lib/protocols/trade/transfer-v3.cjs +6 -9
- package/lib/util.cjs +17 -0
- package/lib/util.d.cts +3 -1
- package/package.json +16 -18
- package/tools/fixtures.ts +2 -1
|
@@ -10,54 +10,60 @@ import { scopeMatchAny } from "@ocap/util";
|
|
|
10
10
|
import Debug from "debug";
|
|
11
11
|
import { formatMessage } from "@ocap/message";
|
|
12
12
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
13
|
-
import {
|
|
13
|
+
import { v, vBN, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
14
14
|
|
|
15
15
|
//#region src/protocols/account/delegate.ts
|
|
16
16
|
const debug = Debug("@ocap/tx-protocols:delegate");
|
|
17
17
|
const runner = new Runner("delegate");
|
|
18
18
|
runner.use(pipes.VerifyMultiSig(0));
|
|
19
|
-
const rateLimit =
|
|
20
|
-
interval:
|
|
21
|
-
anchor:
|
|
19
|
+
const rateLimit = v.object({
|
|
20
|
+
interval: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
21
|
+
anchor: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0)
|
|
22
22
|
});
|
|
23
|
-
const tokenLimit =
|
|
24
|
-
address:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
const tokenLimit = v.object({
|
|
24
|
+
address: vDID({
|
|
25
|
+
prefix: true,
|
|
26
|
+
role: "ROLE_TOKEN"
|
|
27
|
+
}),
|
|
28
|
+
toList: v.optional(v.nullable(v.pipe(v.array(vDID({ prefix: true })), v.maxLength(32))), []),
|
|
29
|
+
txCount: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0),
|
|
30
|
+
txAllowance: v.optional(v.nullable(vBN()), "0"),
|
|
31
|
+
totalAllowance: v.optional(v.nullable(vBN()), "0"),
|
|
32
|
+
validUntil: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0),
|
|
33
|
+
rate: v.optional(v.nullable(rateLimit))
|
|
31
34
|
});
|
|
32
|
-
const assetLimit =
|
|
33
|
-
address:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const assetLimit = v.object({
|
|
36
|
+
address: v.optional(v.nullable(v.pipe(v.array(vDID({
|
|
37
|
+
prefix: true,
|
|
38
|
+
role: "ROLE_ASSET"
|
|
39
|
+
})), v.maxLength(1024))), []),
|
|
40
|
+
toList: v.optional(v.nullable(v.pipe(v.array(vDID({ prefix: true })), v.maxLength(32))), []),
|
|
41
|
+
txCount: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0),
|
|
42
|
+
validUntil: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0),
|
|
43
|
+
rate: v.optional(v.nullable(rateLimit))
|
|
38
44
|
});
|
|
39
|
-
const schema =
|
|
40
|
-
address:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const schema = v.pipe(v.object({
|
|
46
|
+
address: vDID({
|
|
47
|
+
prefix: true,
|
|
48
|
+
role: "ROLE_DELEGATION"
|
|
49
|
+
}),
|
|
50
|
+
to: vDID({ prefix: true }),
|
|
51
|
+
opsList: v.pipe(v.array(v.object({
|
|
52
|
+
typeUrl: v.string(),
|
|
53
|
+
limit: v.optional(v.nullable(v.object({
|
|
54
|
+
tokensList: v.optional(v.pipe(v.array(tokenLimit), v.maxLength(32)), []),
|
|
55
|
+
assetsList: v.optional(v.pipe(v.array(assetLimit), v.maxLength(32)), [])
|
|
56
|
+
})), {
|
|
48
57
|
tokensList: [],
|
|
49
58
|
assetsList: []
|
|
50
59
|
})
|
|
51
|
-
})).
|
|
52
|
-
denyList:
|
|
53
|
-
validUntil:
|
|
54
|
-
data:
|
|
55
|
-
})
|
|
56
|
-
stripUnknown: true,
|
|
57
|
-
noDefaults: false
|
|
58
|
-
});
|
|
60
|
+
})), v.minLength(1), v.check((arr) => new Set(arr.map((x) => x.typeUrl)).size === arr.length, "opsList must not contain duplicate typeUrl entries")),
|
|
61
|
+
denyList: v.optional(v.nullable(v.pipe(v.array(v.pipe(v.string(), v.regex(/^fg:/), v.maxLength(256))), v.maxLength(128), v.check((arr) => new Set(arr).size === arr.length, "denyList must not contain duplicates"))), []),
|
|
62
|
+
validUntil: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0),
|
|
63
|
+
data: v.optional(v.nullable(v.any()))
|
|
64
|
+
}), vStripUnknown());
|
|
59
65
|
runner.use((context, next) => {
|
|
60
|
-
const { error, value } = schema
|
|
66
|
+
const { error, value } = vValidate(schema, context.itx);
|
|
61
67
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
62
68
|
context.formattedItx = formatMessage("DelegateTx", context.itx);
|
|
63
69
|
context.validatedItx = value;
|
|
@@ -6,7 +6,7 @@ import { CustomError } from "@ocap/util/lib/error";
|
|
|
6
6
|
import { fromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
7
7
|
import { account } from "@ocap/state";
|
|
8
8
|
import Debug from "debug";
|
|
9
|
-
import {
|
|
9
|
+
import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
10
10
|
import { types } from "@ocap/mcrypto";
|
|
11
11
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
12
12
|
import flatten from "lodash/flatten.js";
|
|
@@ -17,16 +17,13 @@ const { RoleType } = types;
|
|
|
17
17
|
const debug = Debug("@ocap/tx-protocols:migrate");
|
|
18
18
|
const runner = new Runner("account_migrate");
|
|
19
19
|
runner.use(pipes.VerifyMultiSig(0));
|
|
20
|
-
const schema =
|
|
21
|
-
address:
|
|
22
|
-
pk:
|
|
23
|
-
data:
|
|
24
|
-
})
|
|
25
|
-
stripUnknown: true,
|
|
26
|
-
noDefaults: false
|
|
27
|
-
});
|
|
20
|
+
const schema = v.pipe(v.object({
|
|
21
|
+
address: vDID({ prefix: true }),
|
|
22
|
+
pk: v.any(),
|
|
23
|
+
data: v.optional(v.nullable(v.any()))
|
|
24
|
+
}), vStripUnknown());
|
|
28
25
|
runner.use((context, next) => {
|
|
29
|
-
const { error } = schema
|
|
26
|
+
const { error } = vValidate(schema, context.itx);
|
|
30
27
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
31
28
|
return next();
|
|
32
29
|
});
|
|
@@ -8,23 +8,23 @@ import { account, delegation } from "@ocap/state";
|
|
|
8
8
|
import Debug from "debug";
|
|
9
9
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
10
10
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
11
|
-
import {
|
|
11
|
+
import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
12
|
|
|
13
13
|
//#region src/protocols/account/revoke-delegate.ts
|
|
14
14
|
const debug = Debug("@ocap/tx-protocols:delegate");
|
|
15
15
|
const runner = new Runner("revoke_delegate");
|
|
16
16
|
runner.use(pipes.VerifyMultiSig(0));
|
|
17
|
-
const schema =
|
|
18
|
-
address:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
17
|
+
const schema = v.pipe(v.object({
|
|
18
|
+
address: vDID({
|
|
19
|
+
prefix: true,
|
|
20
|
+
role: "ROLE_DELEGATION"
|
|
21
|
+
}),
|
|
22
|
+
to: vDID({ prefix: true }),
|
|
23
|
+
typeUrlsList: v.pipe(v.array(v.string()), v.minLength(1)),
|
|
24
|
+
data: v.optional(v.nullable(v.any()))
|
|
25
|
+
}), vStripUnknown());
|
|
26
26
|
runner.use((context, next) => {
|
|
27
|
-
const { error } = schema
|
|
27
|
+
const { error } = vValidate(schema, context.itx);
|
|
28
28
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
29
29
|
return next();
|
|
30
30
|
});
|
|
@@ -11,7 +11,7 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
|
11
11
|
import { CustomError } from "@ocap/util/lib/error";
|
|
12
12
|
import { account, asset, delegation, factory } from "@ocap/state";
|
|
13
13
|
import Debug from "debug";
|
|
14
|
-
import {
|
|
14
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
15
15
|
import { promisify } from "node:util";
|
|
16
16
|
|
|
17
17
|
//#region src/protocols/asset/acquire-v2.ts
|
|
@@ -22,19 +22,25 @@ const verifyTokenBalance = promisify(pipes.VerifyTokenBalance({
|
|
|
22
22
|
}));
|
|
23
23
|
const runner = new Runner("acquire_asset_v2");
|
|
24
24
|
runner.use(pipes.VerifyMultiSig(0));
|
|
25
|
-
const schema =
|
|
26
|
-
factory:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
const schema = v.pipe(v.object({
|
|
26
|
+
factory: vDID({
|
|
27
|
+
prefix: true,
|
|
28
|
+
role: "ROLE_FACTORY"
|
|
29
|
+
}),
|
|
30
|
+
address: vDID({
|
|
31
|
+
prefix: true,
|
|
32
|
+
role: "ROLE_ASSET"
|
|
33
|
+
}),
|
|
34
|
+
assetsList: v.optional(v.array(vDID({
|
|
35
|
+
prefix: true,
|
|
36
|
+
role: "ROLE_ASSET"
|
|
37
|
+
})), []),
|
|
38
|
+
variablesList: v.optional(v.nullable(v.array(schemas.variableInput)), []),
|
|
39
|
+
issuer: schemas.nftIssuer,
|
|
40
|
+
data: v.optional(v.nullable(v.any()))
|
|
41
|
+
}), vStripUnknown());
|
|
36
42
|
runner.use(({ itx }, next) => {
|
|
37
|
-
const { error } = schema
|
|
43
|
+
const { error } = vValidate(schema, itx);
|
|
38
44
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
39
45
|
return next();
|
|
40
46
|
});
|
|
@@ -13,7 +13,7 @@ import { account, asset, factory } from "@ocap/state";
|
|
|
13
13
|
import { BN } from "@ocap/util";
|
|
14
14
|
import Debug from "debug";
|
|
15
15
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
16
|
-
import {
|
|
16
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
17
17
|
import { promisify } from "node:util";
|
|
18
18
|
import isEqual from "lodash/isEqual.js";
|
|
19
19
|
|
|
@@ -24,20 +24,23 @@ const verifyAssetOwner = promisify(pipes.VerifyUpdater({
|
|
|
24
24
|
ownerKey: "owner"
|
|
25
25
|
}));
|
|
26
26
|
const runner = new Runner("acquire_asset_v3");
|
|
27
|
-
const schema =
|
|
28
|
-
factory:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
const schema = v.pipe(v.object({
|
|
28
|
+
factory: vDID({
|
|
29
|
+
prefix: true,
|
|
30
|
+
role: "ROLE_FACTORY"
|
|
31
|
+
}),
|
|
32
|
+
address: vDID({
|
|
33
|
+
prefix: true,
|
|
34
|
+
role: "ROLE_ASSET"
|
|
35
|
+
}),
|
|
36
|
+
inputsList: v.pipe(schemas.multiInput, v.minLength(1)),
|
|
37
|
+
owner: schemas.tokenHolder,
|
|
38
|
+
variablesList: v.optional(v.nullable(v.array(schemas.variableInput)), []),
|
|
39
|
+
issuer: schemas.nftIssuer,
|
|
40
|
+
data: v.optional(v.nullable(v.any()))
|
|
41
|
+
}), vStripUnknown());
|
|
39
42
|
runner.use(({ itx }, next) => {
|
|
40
|
-
const { error } = schema
|
|
43
|
+
const { error } = vValidate(schema, itx);
|
|
41
44
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
42
45
|
return next();
|
|
43
46
|
});
|
|
@@ -4,21 +4,21 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
|
4
4
|
import { CustomError } from "@ocap/util/lib/error";
|
|
5
5
|
import { account, asset } from "@ocap/state";
|
|
6
6
|
import Debug from "debug";
|
|
7
|
-
import {
|
|
7
|
+
import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
8
8
|
|
|
9
9
|
//#region src/protocols/asset/consume.ts
|
|
10
10
|
const debug = Debug("@ocap/tx-protocols:consume-asset");
|
|
11
11
|
const runner = new Runner("consume_asset");
|
|
12
|
-
const schema =
|
|
13
|
-
address:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
12
|
+
const schema = v.pipe(v.object({
|
|
13
|
+
address: vDID({
|
|
14
|
+
prefix: true,
|
|
15
|
+
role: "ROLE_ASSET"
|
|
16
|
+
}),
|
|
17
|
+
data: v.optional(v.nullable(v.any()))
|
|
18
|
+
}), vStripUnknown());
|
|
19
19
|
runner.use((context, next) => {
|
|
20
20
|
const { itx } = context;
|
|
21
|
-
const { error } = schema
|
|
21
|
+
const { error } = vValidate(schema, itx);
|
|
22
22
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
23
23
|
return next();
|
|
24
24
|
});
|
|
@@ -9,13 +9,14 @@ import Debug from "debug";
|
|
|
9
9
|
import { formatMessage } from "@ocap/message";
|
|
10
10
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
11
11
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
12
|
+
import { schemas, vValidate } from "@arcblock/validator";
|
|
12
13
|
|
|
13
14
|
//#region src/protocols/asset/create.ts
|
|
14
15
|
const debug = Debug("@ocap/tx-protocols:create-asset");
|
|
15
16
|
const runner = new Runner("create_asset");
|
|
16
17
|
runner.use((context, next) => {
|
|
17
18
|
const itx = formatMessage("CreateAssetTx", context.itx);
|
|
18
|
-
const { error } =
|
|
19
|
+
const { error } = vValidate(schemas.assetSchema, itx);
|
|
19
20
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
20
21
|
return next();
|
|
21
22
|
});
|
|
@@ -8,25 +8,31 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
|
8
8
|
import { CustomError } from "@ocap/util/lib/error";
|
|
9
9
|
import { account, asset, factory } from "@ocap/state";
|
|
10
10
|
import Debug from "debug";
|
|
11
|
-
import {
|
|
11
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
12
|
|
|
13
13
|
//#region src/protocols/asset/mint.ts
|
|
14
14
|
const debug = Debug("@ocap/tx-protocols:mint-asset");
|
|
15
15
|
const runner = new Runner("mint_asset");
|
|
16
16
|
runner.use(pipes.VerifyMultiSig(0));
|
|
17
|
-
const schema =
|
|
18
|
-
factory:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
const schema = v.pipe(v.object({
|
|
18
|
+
factory: vDID({
|
|
19
|
+
prefix: true,
|
|
20
|
+
role: "ROLE_FACTORY"
|
|
21
|
+
}),
|
|
22
|
+
address: vDID({
|
|
23
|
+
prefix: true,
|
|
24
|
+
role: "ROLE_ASSET"
|
|
25
|
+
}),
|
|
26
|
+
assetsList: v.optional(v.array(vDID({
|
|
27
|
+
prefix: true,
|
|
28
|
+
role: "ROLE_ASSET"
|
|
29
|
+
})), []),
|
|
30
|
+
variablesList: v.optional(v.nullable(v.array(schemas.variableInput)), []),
|
|
31
|
+
owner: schemas.tokenHolder,
|
|
32
|
+
data: v.optional(v.nullable(v.any()))
|
|
33
|
+
}), vStripUnknown());
|
|
28
34
|
runner.use(({ itx }, next) => {
|
|
29
|
-
const { error } = schema
|
|
35
|
+
const { error } = vValidate(schema, itx);
|
|
30
36
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
31
37
|
return next();
|
|
32
38
|
});
|
|
@@ -5,25 +5,25 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
|
5
5
|
import { CustomError } from "@ocap/util/lib/error";
|
|
6
6
|
import { account, asset } from "@ocap/state";
|
|
7
7
|
import Debug from "debug";
|
|
8
|
-
import {
|
|
8
|
+
import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
9
9
|
import { diff } from "deep-diff";
|
|
10
10
|
|
|
11
11
|
//#region src/protocols/asset/update.ts
|
|
12
12
|
const debug = Debug("@ocap/tx-protocols:update-asset");
|
|
13
13
|
const runner = new Runner("update_asset");
|
|
14
14
|
runner.use(pipes.VerifyMultiSig(0));
|
|
15
|
-
const schema =
|
|
16
|
-
address:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
15
|
+
const schema = v.pipe(v.object({
|
|
16
|
+
address: vDID({
|
|
17
|
+
prefix: true,
|
|
18
|
+
role: "ROLE_ASSET"
|
|
19
|
+
}),
|
|
20
|
+
moniker: v.optional(v.nullable(v.pipe(v.string(), v.maxLength(255)))),
|
|
21
|
+
consumed: v.optional(v.nullable(v.boolean()), false),
|
|
22
|
+
data: v.optional(v.nullable(v.any()))
|
|
23
|
+
}), vStripUnknown());
|
|
24
24
|
runner.use((context, next) => {
|
|
25
25
|
const { itx } = context;
|
|
26
|
-
const { error } = schema
|
|
26
|
+
const { error } = vValidate(schema, itx);
|
|
27
27
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
28
28
|
if (!itx.moniker && !itx.data) return next(new CustomError("INVALID_TX", "itx.moniker and itx.data can not be empty at the same time"));
|
|
29
29
|
context.newData = decodeAnySafe(itx.data ?? null);
|
|
@@ -6,23 +6,23 @@ import { CustomError } from "@ocap/util/lib/error";
|
|
|
6
6
|
import { account, asset, evidence, stake } from "@ocap/state";
|
|
7
7
|
import { BN } from "@ocap/util";
|
|
8
8
|
import Debug from "debug";
|
|
9
|
-
import {
|
|
9
|
+
import { patterns, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
10
10
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
11
11
|
|
|
12
12
|
//#region src/protocols/governance/claim-stake.ts
|
|
13
13
|
const debug = Debug("@ocap/tx-protocols:claim-stake");
|
|
14
14
|
const runner = new Runner("claim_stake");
|
|
15
15
|
runner.use(pipes.VerifyMultiSig(0));
|
|
16
|
-
const schema =
|
|
17
|
-
address:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
16
|
+
const schema = v.pipe(v.object({
|
|
17
|
+
address: vDID({
|
|
18
|
+
prefix: true,
|
|
19
|
+
role: "ROLE_STAKE"
|
|
20
|
+
}),
|
|
21
|
+
evidence: v.object({ hash: v.pipe(v.string(), v.regex(patterns.txHash)) }),
|
|
22
|
+
data: v.optional(v.nullable(v.any()))
|
|
23
|
+
}), vStripUnknown());
|
|
24
24
|
runner.use(({ itx }, next) => {
|
|
25
|
-
const { error } = schema
|
|
25
|
+
const { error } = vValidate(schema, itx);
|
|
26
26
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
27
27
|
});
|
|
28
28
|
runner.use(pipes.ExtractState({
|
|
@@ -7,7 +7,7 @@ import { account, asset, stake } from "@ocap/state";
|
|
|
7
7
|
import { BN } from "@ocap/util";
|
|
8
8
|
import Debug from "debug";
|
|
9
9
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
10
|
-
import {
|
|
10
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
11
11
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
12
12
|
import isEmpty from "lodash/isEmpty.js";
|
|
13
13
|
|
|
@@ -15,17 +15,17 @@ import isEmpty from "lodash/isEmpty.js";
|
|
|
15
15
|
const debug = Debug("@ocap/tx-protocols:return-stake");
|
|
16
16
|
const runner = new Runner("return_stake");
|
|
17
17
|
runner.use(pipes.VerifyMultiSig(0));
|
|
18
|
-
const schema =
|
|
19
|
-
address:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
18
|
+
const schema = v.pipe(v.object({
|
|
19
|
+
address: vDID({
|
|
20
|
+
prefix: true,
|
|
21
|
+
role: "ROLE_STAKE"
|
|
22
|
+
}),
|
|
23
|
+
message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(256)),
|
|
24
|
+
outputsList: v.pipe(schemas.multiInput, v.minLength(1)),
|
|
25
|
+
data: v.optional(v.nullable(v.any()))
|
|
26
|
+
}), vStripUnknown());
|
|
27
27
|
runner.use(({ itx }, next) => {
|
|
28
|
-
const { error } = schema
|
|
28
|
+
const { error } = vValidate(schema, itx);
|
|
29
29
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
30
30
|
});
|
|
31
31
|
runner.use(pipes.VerifyTxInput({
|
|
@@ -7,7 +7,7 @@ import { account, stake } from "@ocap/state";
|
|
|
7
7
|
import { BN } from "@ocap/util";
|
|
8
8
|
import Debug from "debug";
|
|
9
9
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
10
|
-
import {
|
|
10
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
11
11
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
12
12
|
import isEmpty from "lodash/isEmpty.js";
|
|
13
13
|
|
|
@@ -15,16 +15,16 @@ import isEmpty from "lodash/isEmpty.js";
|
|
|
15
15
|
const debug = Debug("@ocap/tx-protocols:revoke-stake");
|
|
16
16
|
const runner = new Runner("revoke_stake");
|
|
17
17
|
runner.use(pipes.VerifyMultiSig(0));
|
|
18
|
-
const schema =
|
|
19
|
-
address:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
18
|
+
const schema = v.pipe(v.object({
|
|
19
|
+
address: vDID({
|
|
20
|
+
prefix: true,
|
|
21
|
+
role: "ROLE_STAKE"
|
|
22
|
+
}),
|
|
23
|
+
outputsList: v.pipe(schemas.multiInput, v.minLength(1)),
|
|
24
|
+
data: v.optional(v.nullable(v.any()))
|
|
25
|
+
}), vStripUnknown());
|
|
26
26
|
runner.use(({ itx }, next) => {
|
|
27
|
-
const { error } = schema
|
|
27
|
+
const { error } = vValidate(schema, itx);
|
|
28
28
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
29
29
|
});
|
|
30
30
|
runner.use(pipes.VerifyTxInput({
|
|
@@ -7,7 +7,7 @@ import { account, asset, stake } from "@ocap/state";
|
|
|
7
7
|
import { BN } from "@ocap/util";
|
|
8
8
|
import Debug from "debug";
|
|
9
9
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
10
|
-
import {
|
|
10
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
11
11
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
12
12
|
import isEmpty from "lodash/isEmpty.js";
|
|
13
13
|
|
|
@@ -15,17 +15,17 @@ import isEmpty from "lodash/isEmpty.js";
|
|
|
15
15
|
const debug = Debug("@ocap/tx-protocols:slash-stake");
|
|
16
16
|
const runner = new Runner("slash_stake");
|
|
17
17
|
runner.use(pipes.VerifyMultiSig(0));
|
|
18
|
-
const schema =
|
|
19
|
-
address:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
18
|
+
const schema = v.pipe(v.object({
|
|
19
|
+
address: vDID({
|
|
20
|
+
prefix: true,
|
|
21
|
+
role: "ROLE_STAKE"
|
|
22
|
+
}),
|
|
23
|
+
message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(256)),
|
|
24
|
+
outputsList: v.pipe(schemas.multiInput, v.minLength(1)),
|
|
25
|
+
data: v.optional(v.nullable(v.any()))
|
|
26
|
+
}), vStripUnknown());
|
|
27
27
|
runner.use(({ itx }, next) => {
|
|
28
|
-
const { error } = schema
|
|
28
|
+
const { error } = vValidate(schema, itx);
|
|
29
29
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
30
30
|
});
|
|
31
31
|
runner.use(pipes.VerifyTxInput({
|
|
@@ -9,7 +9,7 @@ import { account, asset, stake } from "@ocap/state";
|
|
|
9
9
|
import { BN, fromTokenToUnit } from "@ocap/util";
|
|
10
10
|
import Debug from "debug";
|
|
11
11
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
12
|
-
import {
|
|
12
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
13
13
|
import { promisify } from "node:util";
|
|
14
14
|
import isEmpty from "lodash/isEmpty.js";
|
|
15
15
|
|
|
@@ -20,22 +20,22 @@ const verifyAssetOwner = promisify(pipes.VerifyUpdater({
|
|
|
20
20
|
ownerKey: "owner"
|
|
21
21
|
}));
|
|
22
22
|
const runner = new Runner("stake");
|
|
23
|
-
const schema =
|
|
24
|
-
address:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
23
|
+
const schema = v.pipe(v.object({
|
|
24
|
+
address: vDID({
|
|
25
|
+
prefix: true,
|
|
26
|
+
role: "ROLE_STAKE"
|
|
27
|
+
}),
|
|
28
|
+
receiver: vDID({ prefix: true }),
|
|
29
|
+
slashersList: v.optional(v.array(vDID({ prefix: true })), []),
|
|
30
|
+
locked: v.optional(v.boolean(), false),
|
|
31
|
+
inputsList: v.pipe(schemas.multiInput, v.minLength(1)),
|
|
32
|
+
message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(256)),
|
|
33
|
+
revokeWaitingPeriod: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 0),
|
|
34
|
+
data: v.optional(v.nullable(v.any())),
|
|
35
|
+
nonce: v.optional(v.nullable(v.union([v.literal(""), v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(256))])))
|
|
36
|
+
}), vStripUnknown());
|
|
37
37
|
runner.use(({ itx }, next) => {
|
|
38
|
-
const { error } = schema
|
|
38
|
+
const { error } = vValidate(schema, itx);
|
|
39
39
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
40
40
|
});
|
|
41
41
|
runner.use(pipes.VerifyTxInput({
|