@keplr-wallet/chain-validator 0.12.0-alpha.0 → 0.12.0-alpha.2
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/LICENSE +8 -2
- package/build/connection.d.ts +8 -1
- package/build/connection.js +34 -18
- package/build/connection.js.map +1 -1
- package/build/feature.d.ts +29 -0
- package/build/feature.js +154 -0
- package/build/feature.js.map +1 -0
- package/build/feature.spec.d.ts +1 -0
- package/build/feature.spec.js +377 -0
- package/build/feature.spec.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +6 -1
- package/build/index.js.map +1 -1
- package/build/schema.d.ts +5 -10
- package/build/schema.js +23 -24
- package/build/schema.js.map +1 -1
- package/build/schema.spec.js +84 -0
- package/build/schema.spec.js.map +1 -1
- package/package.json +5 -6
- package/src/connection.ts +58 -33
- package/src/feature.spec.ts +457 -0
- package/src/feature.ts +198 -0
- package/src/index.ts +1 -0
- package/src/schema.spec.ts +94 -0
- package/src/schema.ts +31 -28
package/LICENSE
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
License: Apache2.0
|
|
1
|
+
License: Apache2.0 (Extension) / All rights reserved (Mobile)
|
|
2
|
+
|
|
3
|
+
## Keplr Extension License:
|
|
2
4
|
|
|
3
5
|
Apache License
|
|
4
6
|
Version 2.0, January 2004
|
|
@@ -200,4 +202,8 @@ License: Apache2.0
|
|
|
200
202
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
203
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
204
|
See the License for the specific language governing permissions and
|
|
203
|
-
limitations under the License.
|
|
205
|
+
limitations under the License.
|
|
206
|
+
|
|
207
|
+
## Keplr Mobile License
|
|
208
|
+
|
|
209
|
+
Copyright (c) 2021 Chainapsis Inc. All rights reserved.
|
package/build/connection.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare class DifferentChainVersionError extends Error {
|
|
2
|
+
constructor(m: string);
|
|
3
|
+
}
|
|
4
|
+
export declare function checkRPCConnectivity(chainId: string, rpc: string, wsObject?: (url: string) => {
|
|
5
|
+
readonly readyState: number;
|
|
6
|
+
onerror: ((event: any) => void) | null;
|
|
7
|
+
close(): void;
|
|
8
|
+
}): Promise<void>;
|
|
2
9
|
export declare function checkRestConnectivity(chainId: string, rest: string): Promise<void>;
|
package/build/connection.js
CHANGED
|
@@ -8,50 +8,64 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.checkRestConnectivity = exports.checkRPCConnectivity = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
12
|
+
exports.checkRestConnectivity = exports.checkRPCConnectivity = exports.DifferentChainVersionError = void 0;
|
|
17
13
|
const cosmos_1 = require("@keplr-wallet/cosmos");
|
|
14
|
+
const simple_fetch_1 = require("@keplr-wallet/simple-fetch");
|
|
15
|
+
class DifferentChainVersionError extends Error {
|
|
16
|
+
constructor(m) {
|
|
17
|
+
super(m);
|
|
18
|
+
// Set the prototype explicitly.
|
|
19
|
+
Object.setPrototypeOf(this, DifferentChainVersionError.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.DifferentChainVersionError = DifferentChainVersionError;
|
|
18
23
|
function checkRPCConnectivity(chainId, rpc, wsObject) {
|
|
19
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const rpcInstance = axios_1.default.create({
|
|
21
|
-
baseURL: rpc,
|
|
22
|
-
});
|
|
23
25
|
let resultStatus;
|
|
24
26
|
try {
|
|
25
27
|
// Get the status to get the chain id.
|
|
26
|
-
resultStatus = yield
|
|
28
|
+
resultStatus = yield (0, simple_fetch_1.simpleFetch)(rpc, "/status");
|
|
27
29
|
}
|
|
28
30
|
catch (e) {
|
|
29
31
|
console.log(e);
|
|
30
32
|
throw new Error("Failed to get response /status from rpc endpoint");
|
|
31
33
|
}
|
|
32
34
|
const version = cosmos_1.ChainIdHelper.parse(chainId);
|
|
33
|
-
const
|
|
35
|
+
const statusResult = (() => {
|
|
36
|
+
if ("result" in resultStatus.data) {
|
|
37
|
+
return resultStatus.data.result;
|
|
38
|
+
}
|
|
39
|
+
return resultStatus.data;
|
|
40
|
+
})();
|
|
41
|
+
const versionFromRPCStatus = cosmos_1.ChainIdHelper.parse(statusResult.node_info.network);
|
|
34
42
|
if (versionFromRPCStatus.identifier !== version.identifier) {
|
|
35
|
-
throw new Error(`RPC endpoint has different chain id (expected: ${chainId}, actual: ${
|
|
43
|
+
throw new Error(`RPC endpoint has different chain id (expected: ${chainId}, actual: ${statusResult.node_info.network})`);
|
|
36
44
|
}
|
|
37
45
|
else if (versionFromRPCStatus.version !== version.version) {
|
|
38
46
|
// In the form of {chain_identifier}-{chain_version}, if the identifier is the same but the version is different, it is strictly an error,
|
|
39
47
|
// but it is actually the same chain but the chain version of the node is different.
|
|
40
48
|
// In this case, it is possible to treat as a warning and proceed as it is, so this is separated with above error.
|
|
41
|
-
throw new
|
|
49
|
+
throw new DifferentChainVersionError(`RPC endpoint has different chain id (expected: ${chainId}, actual: ${statusResult.node_info.network})`);
|
|
42
50
|
}
|
|
43
51
|
let wsURL = rpc;
|
|
44
52
|
if (wsURL.startsWith("http")) {
|
|
45
53
|
wsURL = wsURL.replace("http", "ws");
|
|
46
54
|
}
|
|
47
55
|
wsURL = wsURL.endsWith("/") ? wsURL + "websocket" : wsURL + "/websocket";
|
|
48
|
-
const wsInstance = wsObject ?
|
|
56
|
+
const wsInstance = wsObject ? wsObject(wsURL) : new WebSocket(wsURL);
|
|
57
|
+
wsInstance.onerror = () => {
|
|
58
|
+
// To prevent not catchable error,
|
|
59
|
+
// provide noop handler.
|
|
60
|
+
};
|
|
61
|
+
let wsConnected = false;
|
|
49
62
|
// Try 15 times at 1 second intervals to test websocket connectivity.
|
|
50
63
|
for (let i = 0; i < 15; i++) {
|
|
51
64
|
// If ws state is not "connecting"
|
|
52
65
|
if (wsInstance.readyState !== 0) {
|
|
53
66
|
// If ws state is "open", it means that app can connect ws to /websocket rpc
|
|
54
67
|
if (wsInstance.readyState === 1) {
|
|
68
|
+
wsConnected = true;
|
|
55
69
|
break;
|
|
56
70
|
}
|
|
57
71
|
else {
|
|
@@ -61,18 +75,20 @@ function checkRPCConnectivity(chainId, rpc, wsObject) {
|
|
|
61
75
|
}
|
|
62
76
|
yield new Promise((resolve) => setTimeout(resolve, 1000));
|
|
63
77
|
}
|
|
78
|
+
// Close web socket
|
|
79
|
+
wsInstance.close();
|
|
80
|
+
if (!wsConnected) {
|
|
81
|
+
throw new Error("Failed to connect websocket to /websocket rpc");
|
|
82
|
+
}
|
|
64
83
|
});
|
|
65
84
|
}
|
|
66
85
|
exports.checkRPCConnectivity = checkRPCConnectivity;
|
|
67
86
|
function checkRestConnectivity(chainId, rest) {
|
|
68
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const restInstance = axios_1.default.create({
|
|
70
|
-
baseURL: rest,
|
|
71
|
-
});
|
|
72
88
|
let resultLCDNodeInfo;
|
|
73
89
|
try {
|
|
74
90
|
// Get the node info to get the chain id.
|
|
75
|
-
resultLCDNodeInfo = yield
|
|
91
|
+
resultLCDNodeInfo = yield (0, simple_fetch_1.simpleFetch)(rest, "/cosmos/base/tendermint/v1beta1/node_info");
|
|
76
92
|
}
|
|
77
93
|
catch (e) {
|
|
78
94
|
console.log(e);
|
|
@@ -87,7 +103,7 @@ function checkRestConnectivity(chainId, rest) {
|
|
|
87
103
|
// In the form of {chain_identifier}-{chain_version}, if the identifier is the same but the version is different, it is strictly an error,
|
|
88
104
|
// but it is actually the same chain but the chain version of the node is different.
|
|
89
105
|
// In this case, it is possible to treat as a warning and proceed as it is, so this is separated with above error.
|
|
90
|
-
throw new
|
|
106
|
+
throw new DifferentChainVersionError(`LCD endpoint has different chain id (expected: ${chainId}, actual: ${resultLCDNodeInfo.data.default_node_info.network})`);
|
|
91
107
|
}
|
|
92
108
|
});
|
|
93
109
|
}
|
package/build/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAqD;AACrD,6DAA8E;AAE9E,MAAa,0BAA2B,SAAQ,KAAK;IACnD,YAAY,CAAS;QACnB,KAAK,CAAC,CAAC,CAAC,CAAC;QACT,gCAAgC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,0BAA0B,CAAC,SAAS,CAAC,CAAC;IACpE,CAAC;CACF;AAND,gEAMC;AAED,SAAsB,oBAAoB,CACxC,OAAe,EACf,GAAW,EACX,QAIC;;QAED,IAAI,YAaH,CAAC;QAEF,IAAI;YACF,sCAAsC;YACtC,YAAY,GAAG,MAAM,IAAA,0BAAW,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC;SAClD;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;SACrE;QAED,MAAM,OAAO,GAAG,sBAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE7C,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE;YACzB,IAAI,QAAQ,IAAI,YAAY,CAAC,IAAI,EAAE;gBACjC,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;aACjC;YACD,OAAO,YAAY,CAAC,IAAI,CAAC;QA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1I,oFAAoF;YACpF,kHAAkH;YAClH,MAAM,IAAI,0BAA0B,CAClC,kDAAkD,OAAO,aAAa,iBAAiB,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,GAAG,CAC1H,CAAC;SACH;IACH,CAAC;CAAA;AA1CD,sDA0CC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ChainInfo } from "@keplr-wallet/types";
|
|
2
|
+
/**
|
|
3
|
+
* Indicate the features which keplr supports.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SupportedChainFeatures: string[];
|
|
6
|
+
/**
|
|
7
|
+
* Describe the way to know whether that feature is needed.
|
|
8
|
+
* This is used in `checkChainFeatures` function.
|
|
9
|
+
* `checkChainFeatures` function iterate this constant
|
|
10
|
+
* and execute method in sequence
|
|
11
|
+
* and if it returns "true", it pushes that feature and deliver it to next method.
|
|
12
|
+
* So, the order is important.
|
|
13
|
+
*/
|
|
14
|
+
export declare const RecognizableChainFeaturesMethod: {
|
|
15
|
+
feature: string;
|
|
16
|
+
fetch: (features: ReadonlyArray<string>, rpc: string, rest: string) => Promise<boolean>;
|
|
17
|
+
}[];
|
|
18
|
+
/**
|
|
19
|
+
* Indicate the features which keplr can know whether that feature is needed.
|
|
20
|
+
*/
|
|
21
|
+
export declare const RecognizableChainFeatures: string[];
|
|
22
|
+
export declare const NonRecognizableChainFeatures: string[];
|
|
23
|
+
export type ChainInfoForCheck = Pick<ChainInfo, "rpc" | "rest" | "features">;
|
|
24
|
+
/**
|
|
25
|
+
* Returns features that chain will have to update
|
|
26
|
+
* @param chainInfo
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkChainFeatures(chainInfo: ChainInfoForCheck): Promise<string[]>;
|
|
29
|
+
export declare function hasFeature(chainInfo: Readonly<ChainInfoForCheck>, feature: string): Promise<boolean>;
|
package/build/feature.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.hasFeature = exports.checkChainFeatures = exports.NonRecognizableChainFeatures = exports.RecognizableChainFeatures = exports.RecognizableChainFeaturesMethod = exports.SupportedChainFeatures = void 0;
|
|
13
|
+
const simple_fetch_1 = require("@keplr-wallet/simple-fetch");
|
|
14
|
+
/**
|
|
15
|
+
* Indicate the features which keplr supports.
|
|
16
|
+
*/
|
|
17
|
+
exports.SupportedChainFeatures = [
|
|
18
|
+
"stargate",
|
|
19
|
+
"cosmwasm",
|
|
20
|
+
"wasmd_0.24+",
|
|
21
|
+
"secretwasm",
|
|
22
|
+
"ibc-transfer",
|
|
23
|
+
"no-legacy-stdTx",
|
|
24
|
+
"ibc-go",
|
|
25
|
+
"eth-address-gen",
|
|
26
|
+
"eth-key-sign",
|
|
27
|
+
"query:/cosmos/bank/v1beta1/spendable_balances",
|
|
28
|
+
"axelar-evm-bridge",
|
|
29
|
+
"osmosis-txfees",
|
|
30
|
+
"terra-classic-fee",
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Describe the way to know whether that feature is needed.
|
|
34
|
+
* This is used in `checkChainFeatures` function.
|
|
35
|
+
* `checkChainFeatures` function iterate this constant
|
|
36
|
+
* and execute method in sequence
|
|
37
|
+
* and if it returns "true", it pushes that feature and deliver it to next method.
|
|
38
|
+
* So, the order is important.
|
|
39
|
+
*/
|
|
40
|
+
exports.RecognizableChainFeaturesMethod = [
|
|
41
|
+
{
|
|
42
|
+
feature: "ibc-go",
|
|
43
|
+
fetch: (_features, _rpc, rest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
const response = yield (0, simple_fetch_1.simpleFetch)(rest, "/ibc/apps/transfer/v1/params", {
|
|
45
|
+
validateStatus: (status) => {
|
|
46
|
+
return status === 200 || status === 501;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return response.status === 200;
|
|
50
|
+
}),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
feature: "ibc-transfer",
|
|
54
|
+
fetch: (features, _rpc, rest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const requestUrl = features.includes("ibc-go")
|
|
56
|
+
? "/ibc/apps/transfer/v1/params"
|
|
57
|
+
: "/ibc/applications/transfer/v1beta1/params";
|
|
58
|
+
const result = yield (0, simple_fetch_1.simpleFetch)(rest, requestUrl, {
|
|
59
|
+
validateStatus: (status) => {
|
|
60
|
+
return status === 200 || status === 501;
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return (result.status === 200 &&
|
|
64
|
+
result.data.params.receive_enabled &&
|
|
65
|
+
result.data.params.send_enabled);
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
feature: "wasmd_0.24+",
|
|
70
|
+
fetch: (features, _rpc, rest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
if (features.includes("cosmwasm")) {
|
|
72
|
+
const result = yield (0, simple_fetch_1.simpleFetch)(rest, "/cosmwasm/wasm/v1/contract/test/smart/test", {
|
|
73
|
+
validateStatus: (status) => {
|
|
74
|
+
return status === 400 || status === 501;
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
if (result.status === 400) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}),
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
feature: "query:/cosmos/bank/v1beta1/spendable_balances",
|
|
86
|
+
fetch: (_features, _rpc, rest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
const result = yield (0, simple_fetch_1.simpleFetch)(rest, "/cosmos/bank/v1beta1/spendable_balances/test", {
|
|
88
|
+
validateStatus: (status) => {
|
|
89
|
+
return status === 400 || status === 501;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
return result.status === 400;
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
/**
|
|
97
|
+
* Indicate the features which keplr can know whether that feature is needed.
|
|
98
|
+
*/
|
|
99
|
+
exports.RecognizableChainFeatures = exports.RecognizableChainFeaturesMethod.map((method) => method.feature);
|
|
100
|
+
exports.NonRecognizableChainFeatures = (() => {
|
|
101
|
+
const m = {};
|
|
102
|
+
for (const feature of exports.RecognizableChainFeatures) {
|
|
103
|
+
m[feature] = true;
|
|
104
|
+
}
|
|
105
|
+
const r = [];
|
|
106
|
+
for (const feature of exports.SupportedChainFeatures) {
|
|
107
|
+
if (!m[feature]) {
|
|
108
|
+
r.push(feature);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return r;
|
|
112
|
+
})();
|
|
113
|
+
/**
|
|
114
|
+
* Returns features that chain will have to update
|
|
115
|
+
* @param chainInfo
|
|
116
|
+
*/
|
|
117
|
+
function checkChainFeatures(chainInfo) {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const newFeatures = [];
|
|
121
|
+
const features = (_b = (_a = chainInfo.features) === null || _a === void 0 ? void 0 : _a.slice()) !== null && _b !== void 0 ? _b : [];
|
|
122
|
+
for (const method of exports.RecognizableChainFeaturesMethod) {
|
|
123
|
+
if (features.includes(method.feature)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
if (yield method.fetch(features, chainInfo.rpc, chainInfo.rest)) {
|
|
128
|
+
newFeatures.push(method.feature);
|
|
129
|
+
features.push(method.feature);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
console.log(`Failed to try to fetch feature (${method.feature}): ${e.message || e}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return newFeatures;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
exports.checkChainFeatures = checkChainFeatures;
|
|
140
|
+
function hasFeature(chainInfo, feature) {
|
|
141
|
+
var _a, _b, _c;
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
if ((_a = chainInfo.features) === null || _a === void 0 ? void 0 : _a.includes(feature)) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
const method = exports.RecognizableChainFeaturesMethod.find((m) => m.feature === feature);
|
|
147
|
+
if (!method) {
|
|
148
|
+
throw new Error(`${feature} not exist on RecognizableChainFeaturesMethod`);
|
|
149
|
+
}
|
|
150
|
+
return method.fetch((_c = (_b = chainInfo.features) === null || _b === void 0 ? void 0 : _b.slice()) !== null && _c !== void 0 ? _c : [], chainInfo.rpc, chainInfo.rest);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
exports.hasFeature = hasFeature;
|
|
154
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature.js","sourceRoot":"","sources":["../src/feature.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6DAAyD;AAEzD;;GAEG;AACU,QAAA,sBAAsB,GAAG;IACpC,UAAU;IACV,UAAU;IACV,aAAa;IACb,YAAY;IACZ,cAAc;IACd,iBAAiB;IACjB,QAAQ;IACR,iBAAiB;IACjB,cAAc;IACd,+CAA+C;IAC/C,mBAAmB;IACnB,gBAAgB;IAChB,mBAAmB;CACpB,CAAC;AAEF;;;;;;;GAOG;AACU,QAAA,+BAA+B,GAOtC;IACJ;QACE,OAAO,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