@ocap/resolver 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/index.mjs +11 -8
- package/esm/token-flow.mjs +12 -9
- package/lib/index.cjs +9 -6
- package/lib/token-flow.cjs +11 -8
- package/package.json +14 -17
package/esm/index.mjs
CHANGED
|
@@ -5,11 +5,11 @@ import { getInstance } from "./token-cache.mjs";
|
|
|
5
5
|
import { TokenDistributionManager } from "./token-distribution.mjs";
|
|
6
6
|
import { listTokenFlows, verifyAccountRisk } from "./token-flow.mjs";
|
|
7
7
|
import { toStakeAddress } from "@arcblock/did-util";
|
|
8
|
-
import { BN,
|
|
8
|
+
import { BN, fromTokenToUnit, toAddress, toBN } from "@ocap/util";
|
|
9
9
|
import createDebug from "debug";
|
|
10
10
|
import pick from "lodash/pick.js";
|
|
11
11
|
import { fromPublicKey, isValid, toTypeInfo } from "@arcblock/did";
|
|
12
|
-
import {
|
|
12
|
+
import { patterns, v, vDID, vValidate } from "@arcblock/validator";
|
|
13
13
|
import * as Config from "@ocap/config";
|
|
14
14
|
import { types } from "@ocap/mcrypto";
|
|
15
15
|
import { fromTypeUrl } from "@ocap/message";
|
|
@@ -763,7 +763,7 @@ var OCAPResolver = class {
|
|
|
763
763
|
return {
|
|
764
764
|
type,
|
|
765
765
|
id: keyword,
|
|
766
|
-
title: fields ? fields.map((f) => result[f]).find((v) => v) || "" : ""
|
|
766
|
+
title: fields ? fields.map((f) => result[f]).find((v$1) => v$1) || "" : ""
|
|
767
767
|
};
|
|
768
768
|
};
|
|
769
769
|
if (patterns.txHash.test(args.keyword)) return { results: (await Promise.all([doSearch("tx", args.keyword.toUpperCase()), doSearch("rollupBlock", args.keyword)])).filter(Boolean) };
|
|
@@ -1149,7 +1149,7 @@ var OCAPResolver = class {
|
|
|
1149
1149
|
"CreateRollupBlockTx",
|
|
1150
1150
|
"ClaimBlockRewardTx"
|
|
1151
1151
|
];
|
|
1152
|
-
const typeUrl =
|
|
1152
|
+
const typeUrl = tx.tx.itxJson._type || "";
|
|
1153
1153
|
const tokens = [];
|
|
1154
1154
|
if (isDefaultTokenChanged(tx, this.config.token)) tokens.push(this.tokenItx);
|
|
1155
1155
|
if (typeUrl === "AcquireAssetV2Tx") {
|
|
@@ -1253,10 +1253,13 @@ var OCAPResolver = class {
|
|
|
1253
1253
|
}))).filter(Boolean);
|
|
1254
1254
|
}
|
|
1255
1255
|
async updateTokenDistribution({ tokenAddress = this.config.token.address, force = false } = {}) {
|
|
1256
|
-
const validation =
|
|
1257
|
-
tokenAddress:
|
|
1258
|
-
|
|
1259
|
-
|
|
1256
|
+
const validation = vValidate(v.object({
|
|
1257
|
+
tokenAddress: vDID({
|
|
1258
|
+
prefix: true,
|
|
1259
|
+
role: "ROLE_TOKEN"
|
|
1260
|
+
}),
|
|
1261
|
+
force: v.boolean()
|
|
1262
|
+
}), {
|
|
1260
1263
|
tokenAddress,
|
|
1261
1264
|
force
|
|
1262
1265
|
});
|
package/esm/token-flow.mjs
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { BN, fromTokenToUnit, isSameDid } from "@ocap/util";
|
|
2
|
-
import {
|
|
2
|
+
import { schemas, v, vDID, vValidate } from "@arcblock/validator";
|
|
3
3
|
import { CustomError } from "@ocap/util/lib/error";
|
|
4
4
|
import uniq from "lodash/uniq.js";
|
|
5
5
|
import { FORGE_TOKEN_HOLDER } from "@ocap/state/lib/states/tx";
|
|
6
6
|
|
|
7
7
|
//#region src/token-flow.ts
|
|
8
8
|
const ZERO = new BN(0);
|
|
9
|
-
const paramsSchema =
|
|
10
|
-
accountAddress: schemas.tokenHolder
|
|
11
|
-
tokenAddress:
|
|
12
|
-
|
|
9
|
+
const paramsSchema = v.object({
|
|
10
|
+
accountAddress: schemas.tokenHolder,
|
|
11
|
+
tokenAddress: vDID({
|
|
12
|
+
prefix: true,
|
|
13
|
+
role: "ROLE_TOKEN"
|
|
14
|
+
}),
|
|
15
|
+
resolver: v.looseObject({})
|
|
13
16
|
});
|
|
14
17
|
/**
|
|
15
18
|
* Parse transfer in/out list from transaction
|
|
@@ -123,7 +126,7 @@ const fixMigrateReceipts = async (tx, resolver) => {
|
|
|
123
126
|
});
|
|
124
127
|
};
|
|
125
128
|
const verifyAccountRisk = async ({ accountAddress, tokenAddress, accountLimit = 400, txLimit = 1e4, tolerance = "0.0000000001" }, resolver, ctx = {}) => {
|
|
126
|
-
const validation = paramsSchema
|
|
129
|
+
const validation = vValidate(paramsSchema, {
|
|
127
130
|
accountAddress,
|
|
128
131
|
tokenAddress,
|
|
129
132
|
resolver
|
|
@@ -206,7 +209,7 @@ const verifyAccountRisk = async ({ accountAddress, tokenAddress, accountLimit =
|
|
|
206
209
|
if (!accountQueue[depth + 1]) accountQueue[depth + 1] = [];
|
|
207
210
|
const accountsToQueue = transferOutList.filter((item) => {
|
|
208
211
|
if (checkedAccounts.has(item.address)) return false;
|
|
209
|
-
if (schemas.tokenHolder
|
|
212
|
+
if (vValidate(schemas.tokenHolder, item.address).error) return false;
|
|
210
213
|
if (vaultAccounts.includes(item.address)) return false;
|
|
211
214
|
if (["gas", "fee"].includes(item.action || "")) return false;
|
|
212
215
|
return true;
|
|
@@ -274,7 +277,7 @@ const verifyAccountRisk = async ({ accountAddress, tokenAddress, accountLimit =
|
|
|
274
277
|
};
|
|
275
278
|
};
|
|
276
279
|
const listTokenFlows = async ({ accountAddress, tokenAddress, paging = {}, depth = 2, direction = "OUT" }, resolver, ctx = {}) => {
|
|
277
|
-
const { error } = paramsSchema
|
|
280
|
+
const { error } = vValidate(paramsSchema, {
|
|
278
281
|
accountAddress,
|
|
279
282
|
tokenAddress,
|
|
280
283
|
resolver
|
|
@@ -292,7 +295,7 @@ const listTokenFlows = async ({ accountAddress, tokenAddress, paging = {}, depth
|
|
|
292
295
|
while (depthQueue[curDepth]?.length && curDepth <= maxDepth && checkedAccounts.size < maxAccountSize) {
|
|
293
296
|
for (const address of depthQueue[curDepth]) {
|
|
294
297
|
if (checkedAccounts.has(address)) continue;
|
|
295
|
-
if (schemas.tokenHolder
|
|
298
|
+
if (vValidate(schemas.tokenHolder, address).error) continue;
|
|
296
299
|
const transactions = await resolver._getAllResults("transactions", (page) => resolver.listTransactions({
|
|
297
300
|
paging: page,
|
|
298
301
|
accountFilter: { accounts: [address] },
|
package/lib/index.cjs
CHANGED
|
@@ -777,7 +777,7 @@ var OCAPResolver = class {
|
|
|
777
777
|
return {
|
|
778
778
|
type,
|
|
779
779
|
id: keyword,
|
|
780
|
-
title: fields ? fields.map((f) => result[f]).find((v) => v) || "" : ""
|
|
780
|
+
title: fields ? fields.map((f) => result[f]).find((v$1) => v$1) || "" : ""
|
|
781
781
|
};
|
|
782
782
|
};
|
|
783
783
|
if (_arcblock_validator.patterns.txHash.test(args.keyword)) return { results: (await Promise.all([doSearch("tx", args.keyword.toUpperCase()), doSearch("rollupBlock", args.keyword)])).filter(Boolean) };
|
|
@@ -1163,7 +1163,7 @@ var OCAPResolver = class {
|
|
|
1163
1163
|
"CreateRollupBlockTx",
|
|
1164
1164
|
"ClaimBlockRewardTx"
|
|
1165
1165
|
];
|
|
1166
|
-
const typeUrl =
|
|
1166
|
+
const typeUrl = tx.tx.itxJson._type || "";
|
|
1167
1167
|
const tokens = [];
|
|
1168
1168
|
if ((0, _ocap_indexdb_lib_util.isDefaultTokenChanged)(tx, this.config.token)) tokens.push(this.tokenItx);
|
|
1169
1169
|
if (typeUrl === "AcquireAssetV2Tx") {
|
|
@@ -1267,10 +1267,13 @@ var OCAPResolver = class {
|
|
|
1267
1267
|
}))).filter(Boolean);
|
|
1268
1268
|
}
|
|
1269
1269
|
async updateTokenDistribution({ tokenAddress = this.config.token.address, force = false } = {}) {
|
|
1270
|
-
const validation = _arcblock_validator.
|
|
1271
|
-
tokenAddress: _arcblock_validator.
|
|
1272
|
-
|
|
1273
|
-
|
|
1270
|
+
const validation = (0, _arcblock_validator.vValidate)(_arcblock_validator.v.object({
|
|
1271
|
+
tokenAddress: (0, _arcblock_validator.vDID)({
|
|
1272
|
+
prefix: true,
|
|
1273
|
+
role: "ROLE_TOKEN"
|
|
1274
|
+
}),
|
|
1275
|
+
force: _arcblock_validator.v.boolean()
|
|
1276
|
+
}), {
|
|
1274
1277
|
tokenAddress,
|
|
1275
1278
|
force
|
|
1276
1279
|
});
|
package/lib/token-flow.cjs
CHANGED
|
@@ -8,10 +8,13 @@ let _ocap_state_lib_states_tx = require("@ocap/state/lib/states/tx");
|
|
|
8
8
|
|
|
9
9
|
//#region src/token-flow.ts
|
|
10
10
|
const ZERO = new _ocap_util.BN(0);
|
|
11
|
-
const paramsSchema = _arcblock_validator.
|
|
12
|
-
accountAddress: _arcblock_validator.schemas.tokenHolder
|
|
13
|
-
tokenAddress: _arcblock_validator.
|
|
14
|
-
|
|
11
|
+
const paramsSchema = _arcblock_validator.v.object({
|
|
12
|
+
accountAddress: _arcblock_validator.schemas.tokenHolder,
|
|
13
|
+
tokenAddress: (0, _arcblock_validator.vDID)({
|
|
14
|
+
prefix: true,
|
|
15
|
+
role: "ROLE_TOKEN"
|
|
16
|
+
}),
|
|
17
|
+
resolver: _arcblock_validator.v.looseObject({})
|
|
15
18
|
});
|
|
16
19
|
/**
|
|
17
20
|
* Parse transfer in/out list from transaction
|
|
@@ -125,7 +128,7 @@ const fixMigrateReceipts = async (tx, resolver) => {
|
|
|
125
128
|
});
|
|
126
129
|
};
|
|
127
130
|
const verifyAccountRisk = async ({ accountAddress, tokenAddress, accountLimit = 400, txLimit = 1e4, tolerance = "0.0000000001" }, resolver, ctx = {}) => {
|
|
128
|
-
const validation =
|
|
131
|
+
const validation = (0, _arcblock_validator.vValidate)(paramsSchema, {
|
|
129
132
|
accountAddress,
|
|
130
133
|
tokenAddress,
|
|
131
134
|
resolver
|
|
@@ -208,7 +211,7 @@ const verifyAccountRisk = async ({ accountAddress, tokenAddress, accountLimit =
|
|
|
208
211
|
if (!accountQueue[depth + 1]) accountQueue[depth + 1] = [];
|
|
209
212
|
const accountsToQueue = transferOutList.filter((item) => {
|
|
210
213
|
if (checkedAccounts.has(item.address)) return false;
|
|
211
|
-
if (_arcblock_validator.schemas.tokenHolder
|
|
214
|
+
if ((0, _arcblock_validator.vValidate)(_arcblock_validator.schemas.tokenHolder, item.address).error) return false;
|
|
212
215
|
if (vaultAccounts.includes(item.address)) return false;
|
|
213
216
|
if (["gas", "fee"].includes(item.action || "")) return false;
|
|
214
217
|
return true;
|
|
@@ -276,7 +279,7 @@ const verifyAccountRisk = async ({ accountAddress, tokenAddress, accountLimit =
|
|
|
276
279
|
};
|
|
277
280
|
};
|
|
278
281
|
const listTokenFlows = async ({ accountAddress, tokenAddress, paging = {}, depth = 2, direction = "OUT" }, resolver, ctx = {}) => {
|
|
279
|
-
const { error } =
|
|
282
|
+
const { error } = (0, _arcblock_validator.vValidate)(paramsSchema, {
|
|
280
283
|
accountAddress,
|
|
281
284
|
tokenAddress,
|
|
282
285
|
resolver
|
|
@@ -294,7 +297,7 @@ const listTokenFlows = async ({ accountAddress, tokenAddress, paging = {}, depth
|
|
|
294
297
|
while (depthQueue[curDepth]?.length && curDepth <= maxDepth && checkedAccounts.size < maxAccountSize) {
|
|
295
298
|
for (const address of depthQueue[curDepth]) {
|
|
296
299
|
if (checkedAccounts.has(address)) continue;
|
|
297
|
-
if (_arcblock_validator.schemas.tokenHolder
|
|
300
|
+
if ((0, _arcblock_validator.vValidate)(_arcblock_validator.schemas.tokenHolder, address).error) continue;
|
|
298
301
|
const transactions = await resolver._getAllResults("transactions", (page) => resolver.listTransactions({
|
|
299
302
|
paging: page,
|
|
300
303
|
accountFilter: { accounts: [address] },
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.30.0",
|
|
7
7
|
"description": "GraphQL resolver built upon ocap statedb and GQL layer",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./lib/index.cjs",
|
|
@@ -43,29 +43,26 @@
|
|
|
43
43
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@arcblock/jwt": "1.29.27",
|
|
47
|
-
"@ocap/indexdb-memory": "1.29.27",
|
|
48
|
-
"@ocap/statedb-memory": "1.29.27",
|
|
49
46
|
"@types/express": "^4.17.23",
|
|
50
47
|
"@types/lodash": "^4.17.16",
|
|
51
48
|
"@types/node": "^20.10.0",
|
|
52
49
|
"tsdown": "^0.18.4"
|
|
53
50
|
},
|
|
54
51
|
"dependencies": {
|
|
55
|
-
"@arcblock/did": "1.
|
|
56
|
-
"@arcblock/did-ext": "1.
|
|
57
|
-
"@arcblock/did-util": "1.
|
|
52
|
+
"@arcblock/did": "1.30.0",
|
|
53
|
+
"@arcblock/did-ext": "1.30.0",
|
|
54
|
+
"@arcblock/did-util": "1.30.0",
|
|
58
55
|
"@arcblock/nft-display": "^3.2.3",
|
|
59
|
-
"@arcblock/validator": "1.
|
|
60
|
-
"@ocap/config": "1.
|
|
61
|
-
"@ocap/indexdb": "1.
|
|
62
|
-
"@ocap/mcrypto": "1.
|
|
63
|
-
"@ocap/message": "1.
|
|
64
|
-
"@ocap/state": "1.
|
|
65
|
-
"@ocap/tx-protocols": "1.
|
|
66
|
-
"@ocap/types": "1.
|
|
67
|
-
"@ocap/util": "1.
|
|
68
|
-
"@ocap/wallet": "1.
|
|
56
|
+
"@arcblock/validator": "1.30.0",
|
|
57
|
+
"@ocap/config": "1.30.0",
|
|
58
|
+
"@ocap/indexdb": "1.30.0",
|
|
59
|
+
"@ocap/mcrypto": "1.30.0",
|
|
60
|
+
"@ocap/message": "1.30.0",
|
|
61
|
+
"@ocap/state": "1.30.0",
|
|
62
|
+
"@ocap/tx-protocols": "1.30.0",
|
|
63
|
+
"@ocap/types": "1.30.0",
|
|
64
|
+
"@ocap/util": "1.30.0",
|
|
65
|
+
"@ocap/wallet": "1.30.0",
|
|
69
66
|
"debug": "^4.4.3",
|
|
70
67
|
"express": "^4.22.1",
|
|
71
68
|
"lodash": "^4.17.23",
|