@ocap/tx-protocols 1.29.27 → 1.30.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/_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
|
@@ -8,22 +8,22 @@ import pick from "lodash/pick.js";
|
|
|
8
8
|
import { account, token, tokenFactory } from "@ocap/state";
|
|
9
9
|
import { BN, fromUnitToToken } from "@ocap/util";
|
|
10
10
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
11
|
-
import {
|
|
11
|
+
import { schemas, v, vBN, vBNGreater, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
12
|
|
|
13
13
|
//#region src/protocols/token-factory/burn.ts
|
|
14
14
|
const runner = new Runner("burn_token");
|
|
15
|
-
const schema =
|
|
16
|
-
tokenFactory:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
15
|
+
const schema = v.pipe(v.object({
|
|
16
|
+
tokenFactory: vDID({
|
|
17
|
+
prefix: true,
|
|
18
|
+
role: "ROLE_TOKEN_FACTORY"
|
|
19
|
+
}),
|
|
20
|
+
receiver: schemas.tokenHolder,
|
|
21
|
+
minReserve: v.optional(v.union([vBN(vBNGreater(0)), v.literal("")])),
|
|
22
|
+
inputsList: v.pipe(schemas.multiInput, v.minLength(1)),
|
|
23
|
+
data: v.optional(v.nullable(v.any()))
|
|
24
|
+
}), vStripUnknown());
|
|
25
25
|
runner.use(({ itx }, next) => {
|
|
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
|
return next();
|
|
29
29
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { applyTokenChange, decodeAnySafe, getDelegationRequirements } from "../../util.mjs";
|
|
1
|
+
import { applyTokenChange, decodeAnySafe, getDelegationRequirements, isHttpUrl, isHttpsUrl } from "../../util.mjs";
|
|
2
2
|
import ensure_cost_default from "../../pipes/ensure-cost.mjs";
|
|
3
3
|
import ensure_gas_default from "../../pipes/ensure-gas.mjs";
|
|
4
|
+
import { any, array, check, literal, maxLength, maxValue, minLength, minValue, nullable, number, object, optional, picklist, pipe, safeParse, string, toLowerCase, toUpperCase, union } from "../../node_modules/valibot/dist/index.mjs";
|
|
4
5
|
import verify_icon_default from "./pipes/verify-icon.mjs";
|
|
5
6
|
import verify_ownership_default from "./pipes/verify-ownership.mjs";
|
|
6
7
|
import verify_url_default from "./pipes/verify-url.mjs";
|
|
@@ -12,58 +13,65 @@ import { BN, fromTokenToUnit, fromUnitToToken } from "@ocap/util";
|
|
|
12
13
|
import Debug from "debug";
|
|
13
14
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
14
15
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
15
|
-
import {
|
|
16
|
+
import { vBN, vBNGreater, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
16
17
|
import uniq from "lodash/uniq.js";
|
|
17
18
|
import isEmpty from "lodash/isEmpty.js";
|
|
18
19
|
|
|
19
20
|
//#region src/protocols/token-factory/create.ts
|
|
20
21
|
const debug = Debug("@ocap/tx-protocols:create-token-factory");
|
|
21
22
|
const runner = new Runner("create_token_factory");
|
|
22
|
-
const
|
|
23
|
+
const isValidUrl = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" || process.env.CI ? isHttpUrl : isHttpsUrl;
|
|
23
24
|
runner.use(pipes.VerifyMultiSig(0));
|
|
24
|
-
const schema =
|
|
25
|
-
address:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
is: "CreditToken",
|
|
29
|
-
then: Joi.valid(null).optional().messages({ "any.only": "Should not provide curve for CreditToken" }),
|
|
30
|
-
otherwise: tokenFactory.curveSchema.required()
|
|
25
|
+
const schema = pipe(object({
|
|
26
|
+
address: vDID({
|
|
27
|
+
prefix: true,
|
|
28
|
+
role: "ROLE_TOKEN_FACTORY"
|
|
31
29
|
}),
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
30
|
+
feeRate: pipe(number(), minValue(0), maxValue(2e3)),
|
|
31
|
+
curve: optional(nullable(any())),
|
|
32
|
+
reserveAddress: vDID({
|
|
33
|
+
prefix: true,
|
|
34
|
+
role: "ROLE_TOKEN"
|
|
35
|
+
}),
|
|
36
|
+
token: object({
|
|
37
|
+
name: pipe(string(), minLength(1), maxLength(32)),
|
|
38
|
+
description: pipe(string(), minLength(16), maxLength(128)),
|
|
39
|
+
symbol: pipe(string(), minLength(2), maxLength(6), toUpperCase()),
|
|
40
|
+
unit: pipe(string(), minLength(1), maxLength(6), toLowerCase()),
|
|
41
|
+
decimal: pipe(number(), minValue(2), maxValue(18)),
|
|
42
|
+
icon: optional(nullable(string())),
|
|
43
|
+
maxTotalSupply: optional(nullable(union([vBN(vBNGreater(0)), literal("")]))),
|
|
44
|
+
website: optional(nullable(union([literal(""), pipe(string(), maxLength(256), check(isValidUrl, "Must be a valid URL"))]))),
|
|
45
|
+
metadata: any(),
|
|
46
|
+
spendersList: optional(nullable(pipe(array(vDID({ prefix: true })), maxLength(30))), null),
|
|
47
|
+
mintersList: optional(nullable(pipe(array(vDID({ prefix: true })), maxLength(30))), null),
|
|
48
|
+
type: picklist(["CreditToken", "BondingCurveToken"])
|
|
49
|
+
}),
|
|
50
|
+
data: optional(nullable(any()))
|
|
51
|
+
}), vStripUnknown());
|
|
55
52
|
runner.use((context, next) => {
|
|
56
|
-
const { error, value } = schema
|
|
53
|
+
const { error, value } = vValidate(schema, context.itx);
|
|
57
54
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
58
|
-
context.itx.
|
|
55
|
+
if (context.itx.token?.type === "CreditToken") {
|
|
56
|
+
if (context.itx.curve != null) return next(new CustomError("INVALID_TX", "Invalid itx: Should not provide curve for CreditToken"));
|
|
57
|
+
context.itx.curve = value.curve;
|
|
58
|
+
} else {
|
|
59
|
+
if (context.itx.curve == null) return next(new CustomError("INVALID_TX", "Invalid itx: curve is required for non-CreditToken"));
|
|
60
|
+
const curveResult = safeParse(tokenFactory.vCurveSchema, context.itx.curve);
|
|
61
|
+
if (!curveResult.success) return next(new CustomError("INVALID_TX", `Invalid itx: ${curveResult.issues.map((i) => i.message).join("; ")}`));
|
|
62
|
+
context.itx.curve = curveResult.output;
|
|
63
|
+
}
|
|
59
64
|
const itxToken = context.itx.token;
|
|
60
65
|
if (itxToken.metadata) {
|
|
61
66
|
const metadata = decodeAnySafe(itxToken.metadata ?? null);
|
|
62
|
-
const { error: metadataError, value: metadataValue } = token.metadataSchema
|
|
67
|
+
const { error: metadataError, value: metadataValue } = vValidate(token.metadataSchema, metadata?.value);
|
|
63
68
|
if (metadataError) return next(new CustomError("INVALID_TX", `Invalid metadata: ${metadataError.message}`));
|
|
69
|
+
const validKeys = new Set(Object.keys(metadataValue));
|
|
70
|
+
const orderedValue = {};
|
|
71
|
+
for (const key of Object.keys(metadata?.value || {})) if (validKeys.has(key)) orderedValue[key] = metadataValue[key];
|
|
64
72
|
itxToken.metadata = {
|
|
65
73
|
...metadata,
|
|
66
|
-
value:
|
|
74
|
+
value: orderedValue
|
|
67
75
|
};
|
|
68
76
|
}
|
|
69
77
|
const tokenWithLists = itxToken;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { applyTokenChange, applyTokenUpdates } from "../../util.mjs";
|
|
2
2
|
import ensure_cost_default from "../../pipes/ensure-cost.mjs";
|
|
3
3
|
import ensure_gas_default from "../../pipes/ensure-gas.mjs";
|
|
4
|
+
import { any, nullable, object, optional, pipe } from "../../node_modules/valibot/dist/index.mjs";
|
|
4
5
|
import calc_reserve_default from "./pipes/calc-reserve.mjs";
|
|
5
6
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
6
7
|
import { CustomError } from "@ocap/util/lib/error";
|
|
@@ -8,22 +9,22 @@ import pick from "lodash/pick.js";
|
|
|
8
9
|
import { account, token, tokenFactory } from "@ocap/state";
|
|
9
10
|
import { BN, fromUnitToToken } from "@ocap/util";
|
|
10
11
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
11
|
-
import {
|
|
12
|
+
import { schemas, vBN, vBNGreater, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
13
|
|
|
13
14
|
//#region src/protocols/token-factory/mint.ts
|
|
14
15
|
const runner = new Runner("mint_token");
|
|
15
|
-
const schema =
|
|
16
|
-
tokenFactory:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
16
|
+
const schema = pipe(object({
|
|
17
|
+
tokenFactory: vDID({
|
|
18
|
+
prefix: true,
|
|
19
|
+
role: "ROLE_TOKEN_FACTORY"
|
|
20
|
+
}),
|
|
21
|
+
receiver: schemas.tokenHolder,
|
|
22
|
+
amount: vBN(vBNGreater(0)),
|
|
23
|
+
data: optional(nullable(any())),
|
|
24
|
+
inputsList: optional(schemas.multiInput)
|
|
25
|
+
}), vStripUnknown());
|
|
25
26
|
runner.use(({ itx }, next) => {
|
|
26
|
-
const { error } = schema
|
|
27
|
+
const { error } = vValidate(schema, itx);
|
|
27
28
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
28
29
|
return next();
|
|
29
30
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyTokenChange, decodeAnySafe, getDelegationRequirements } from "../../util.mjs";
|
|
1
|
+
import { applyTokenChange, decodeAnySafe, getDelegationRequirements, isHttpUrl, isHttpsUrl } from "../../util.mjs";
|
|
2
2
|
import ensure_cost_default from "../../pipes/ensure-cost.mjs";
|
|
3
3
|
import ensure_gas_default from "../../pipes/ensure-gas.mjs";
|
|
4
4
|
import verify_icon_default from "./pipes/verify-icon.mjs";
|
|
@@ -8,40 +8,40 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
|
8
8
|
import { CustomError } from "@ocap/util/lib/error";
|
|
9
9
|
import { account, delegation, token, tokenFactory } from "@ocap/state";
|
|
10
10
|
import Debug from "debug";
|
|
11
|
-
import {
|
|
11
|
+
import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
12
|
|
|
13
13
|
//#region src/protocols/token-factory/update.ts
|
|
14
14
|
const debug = Debug("@ocap/tx-protocols:update-token-factory");
|
|
15
15
|
const runner = new Runner("update_token_factory");
|
|
16
16
|
const isTest = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" || process.env.CI;
|
|
17
17
|
runner.use(pipes.VerifyMultiSig(0));
|
|
18
|
-
const schema =
|
|
19
|
-
address:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
metadata:
|
|
28
|
-
})
|
|
29
|
-
data:
|
|
30
|
-
})
|
|
31
|
-
stripUnknown: true,
|
|
32
|
-
noDefaults: false
|
|
33
|
-
});
|
|
18
|
+
const schema = v.pipe(v.object({
|
|
19
|
+
address: vDID({
|
|
20
|
+
prefix: true,
|
|
21
|
+
role: "ROLE_TOKEN_FACTORY"
|
|
22
|
+
}),
|
|
23
|
+
feeRate: v.optional(v.nullable(v.pipe(v.number(), v.minValue(0), v.maxValue(2e3)))),
|
|
24
|
+
token: v.optional(v.nullable(v.object({
|
|
25
|
+
icon: v.optional(v.nullable(v.union([v.literal(""), v.string()]))),
|
|
26
|
+
website: v.optional(v.nullable(v.union([v.literal(""), v.pipe(v.string(), v.maxLength(256), v.check(isTest ? isHttpUrl : isHttpsUrl, "Must be a valid URL"))]))),
|
|
27
|
+
metadata: v.optional(v.nullable(v.any()))
|
|
28
|
+
}))),
|
|
29
|
+
data: v.optional(v.nullable(v.any()))
|
|
30
|
+
}), vStripUnknown());
|
|
34
31
|
runner.use((context, next) => {
|
|
35
|
-
const { error } = schema
|
|
32
|
+
const { error } = vValidate(schema, context.itx);
|
|
36
33
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
37
34
|
if (context.itx.token?.metadata) {
|
|
38
35
|
const metadata = decodeAnySafe(context.itx.token.metadata ?? null);
|
|
39
36
|
if (metadata) {
|
|
40
|
-
const { error: metadataError, value: metadataValue } = token.metadataSchema
|
|
37
|
+
const { error: metadataError, value: metadataValue } = vValidate(token.metadataSchema, metadata.value);
|
|
41
38
|
if (metadataError) return next(new CustomError("INVALID_TX", `Invalid metadata: ${metadataError.message}`));
|
|
39
|
+
const validKeys = new Set(Object.keys(metadataValue));
|
|
40
|
+
const orderedValue = {};
|
|
41
|
+
for (const key of Object.keys(metadata?.value || {})) if (validKeys.has(key)) orderedValue[key] = metadataValue[key];
|
|
42
42
|
context.itx.token.metadata = {
|
|
43
43
|
...metadata,
|
|
44
|
-
value:
|
|
44
|
+
value: orderedValue
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -8,29 +8,29 @@ import { BN } from "@ocap/util";
|
|
|
8
8
|
import Debug from "debug";
|
|
9
9
|
import { decodeBigInt } from "@ocap/message";
|
|
10
10
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
11
|
-
import {
|
|
11
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
12
|
import { createSortedList } from "@ocap/util/lib/create-sorted-list";
|
|
13
13
|
import isEmpty from "lodash/isEmpty.js";
|
|
14
14
|
|
|
15
15
|
//#region src/protocols/trade/exchange-v2.ts
|
|
16
16
|
const debug = Debug("@ocap/tx-protocols:exchange-v2");
|
|
17
17
|
const runner = new Runner("exchange_v2");
|
|
18
|
-
const exchangeInfoSchema =
|
|
19
|
-
value:
|
|
20
|
-
tokensList:
|
|
21
|
-
assetsList:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
sender: exchangeInfoSchema.required(),
|
|
26
|
-
receiver: exchangeInfoSchema.required(),
|
|
27
|
-
data: Joi.any().optional().allow(null)
|
|
28
|
-
}).options({
|
|
29
|
-
stripUnknown: true,
|
|
30
|
-
noDefaults: false
|
|
18
|
+
const exchangeInfoSchema = v.object({
|
|
19
|
+
value: v.optional(v.nullable(v.any())),
|
|
20
|
+
tokensList: v.optional(v.array(schemas.tokenInput), []),
|
|
21
|
+
assetsList: v.optional(v.array(vDID({
|
|
22
|
+
prefix: true,
|
|
23
|
+
role: "ROLE_ASSET"
|
|
24
|
+
})), [])
|
|
31
25
|
});
|
|
26
|
+
const schema = v.pipe(v.object({
|
|
27
|
+
to: schemas.tokenHolder,
|
|
28
|
+
sender: exchangeInfoSchema,
|
|
29
|
+
receiver: exchangeInfoSchema,
|
|
30
|
+
data: v.optional(v.nullable(v.any()))
|
|
31
|
+
}), vStripUnknown());
|
|
32
32
|
runner.use(({ itx }, next) => {
|
|
33
|
-
const { error } = schema
|
|
33
|
+
const { error } = vValidate(schema, itx);
|
|
34
34
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
35
35
|
});
|
|
36
36
|
runner.use(pipes.VerifyMultiSig(1));
|
|
@@ -8,25 +8,25 @@ import { account, delegation } from "@ocap/state";
|
|
|
8
8
|
import { BN } from "@ocap/util";
|
|
9
9
|
import { decodeBigInt } from "@ocap/message";
|
|
10
10
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
11
|
-
import {
|
|
11
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
12
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
13
13
|
import isEmpty from "lodash/isEmpty.js";
|
|
14
14
|
|
|
15
15
|
//#region src/protocols/trade/transfer-v2.ts
|
|
16
16
|
const runner = new Runner("transfer_v2");
|
|
17
17
|
runner.use(pipes.VerifyMultiSig(0));
|
|
18
|
-
const schema =
|
|
19
|
-
to: schemas.tokenHolder
|
|
20
|
-
value:
|
|
21
|
-
tokensList:
|
|
22
|
-
assetsList:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
18
|
+
const schema = v.pipe(v.object({
|
|
19
|
+
to: schemas.tokenHolder,
|
|
20
|
+
value: v.optional(v.nullable(v.any())),
|
|
21
|
+
tokensList: v.optional(v.array(schemas.tokenInput), []),
|
|
22
|
+
assetsList: v.optional(v.array(vDID({
|
|
23
|
+
prefix: true,
|
|
24
|
+
role: "ROLE_ASSET"
|
|
25
|
+
})), []),
|
|
26
|
+
data: v.optional(v.nullable(v.any()))
|
|
27
|
+
}), vStripUnknown());
|
|
28
28
|
runner.use((context, next) => {
|
|
29
|
-
const { error } = schema
|
|
29
|
+
const { error } = vValidate(schema, context.itx);
|
|
30
30
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
31
31
|
return next();
|
|
32
32
|
});
|
|
@@ -7,7 +7,7 @@ import { account, asset } 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, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
11
11
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
12
12
|
import { promisify } from "node:util";
|
|
13
13
|
import isEqual from "lodash/isEqual.js";
|
|
@@ -19,16 +19,13 @@ const verifyAssetOwner = promisify(pipes.VerifyUpdater({
|
|
|
19
19
|
assetKey: "assets",
|
|
20
20
|
ownerKey: "owner"
|
|
21
21
|
}));
|
|
22
|
-
const schema =
|
|
23
|
-
inputsList: schemas.multiInput.
|
|
24
|
-
outputsList: schemas.multiInput.
|
|
25
|
-
data:
|
|
26
|
-
})
|
|
27
|
-
stripUnknown: true,
|
|
28
|
-
noDefaults: false
|
|
29
|
-
});
|
|
22
|
+
const schema = v.pipe(v.object({
|
|
23
|
+
inputsList: v.pipe(schemas.multiInput, v.minLength(1)),
|
|
24
|
+
outputsList: v.pipe(schemas.multiInput, v.minLength(1)),
|
|
25
|
+
data: v.optional(v.nullable(v.any()))
|
|
26
|
+
}), vStripUnknown());
|
|
30
27
|
runner.use(({ itx }, next) => {
|
|
31
|
-
const { error } = schema
|
|
28
|
+
const { error } = vValidate(schema, itx);
|
|
32
29
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
33
30
|
});
|
|
34
31
|
runner.use(pipes.VerifyTxInput({
|
package/esm/util.d.mts
CHANGED
|
@@ -137,5 +137,7 @@ declare const ensureBlockReward: (rollupState: IRollupStateForReward, minReward:
|
|
|
137
137
|
declare const isGasStakeAddress: (sender: string, stakeId: string) => boolean;
|
|
138
138
|
declare const isGasStakeInput: (inputs: ITxInput[], token: string) => boolean;
|
|
139
139
|
declare const isGasStakeValid: (state: IStakeState | null | undefined, config: IChainConfig) => boolean;
|
|
140
|
+
declare const isHttpUrl: (s: string) => boolean;
|
|
141
|
+
declare const isHttpsUrl: (s: string) => boolean;
|
|
140
142
|
//#endregion
|
|
141
|
-
export { RATE_BASE, applyTokenChange, applyTokenUpdates, decodeAnySafe, ensureBlockReward, fixTokenInput, getBNSum, getDelegationRequirements, getRewardLocker, getTxFee, isFixedFee, isGasStakeAddress, isGasStakeInput, isGasStakeValid, splitTxFee };
|
|
143
|
+
export { RATE_BASE, applyTokenChange, applyTokenUpdates, decodeAnySafe, ensureBlockReward, fixTokenInput, getBNSum, getDelegationRequirements, getRewardLocker, getTxFee, isFixedFee, isGasStakeAddress, isGasStakeInput, isGasStakeValid, isHttpUrl, isHttpsUrl, splitTxFee };
|
package/esm/util.mjs
CHANGED
|
@@ -273,6 +273,21 @@ const isGasStakeValid = (state, config) => {
|
|
|
273
273
|
}
|
|
274
274
|
return false;
|
|
275
275
|
};
|
|
276
|
+
const isHttpUrl = (s) => {
|
|
277
|
+
try {
|
|
278
|
+
const url = new URL(s);
|
|
279
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
280
|
+
} catch {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const isHttpsUrl = (s) => {
|
|
285
|
+
try {
|
|
286
|
+
return new URL(s).protocol === "https:";
|
|
287
|
+
} catch {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
276
291
|
|
|
277
292
|
//#endregion
|
|
278
|
-
export { RATE_BASE, applyTokenChange, applyTokenUpdates, decodeAnySafe, ensureBlockReward, fixTokenInput, getBNSum, getDelegationRequirements, getRewardLocker, getTxFee, isFixedFee, isGasStakeAddress, isGasStakeInput, isGasStakeValid, splitTxFee };
|
|
293
|
+
export { RATE_BASE, applyTokenChange, applyTokenUpdates, decodeAnySafe, ensureBlockReward, fixTokenInput, getBNSum, getDelegationRequirements, getRewardLocker, getTxFee, isFixedFee, isGasStakeAddress, isGasStakeInput, isGasStakeValid, isHttpUrl, isHttpsUrl, splitTxFee };
|
|
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
8
9
|
var __copyProps = (to, from, except, desc) => {
|
|
9
10
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
11
|
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
@@ -26,4 +27,5 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
27
|
|
|
27
28
|
//#endregion
|
|
28
29
|
|
|
30
|
+
exports.__commonJSMin = __commonJSMin;
|
|
29
31
|
exports.__toESM = __toESM;
|