@acala-network/chopsticks-testing 1.5.0 → 1.5.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/dist/cjs/check.js +52 -1
- package/dist/esm/check.js +52 -1
- package/package.json +2 -2
package/dist/cjs/check.js
CHANGED
|
@@ -69,6 +69,57 @@ function _class_private_method_init(obj, privateSet) {
|
|
|
69
69
|
_check_private_redeclaration(obj, privateSet);
|
|
70
70
|
privateSet.add(obj);
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* `XcmpMessageFormat` index of the `ConcatenatedOpaqueVersionedXcm` variant.
|
|
74
|
+
*
|
|
75
|
+
* The variant is matched by index, not by name, because older versions of
|
|
76
|
+
* `@polkadot/types` do not declare it and cannot decode it.
|
|
77
|
+
*/ const CONCATENATED_OPAQUE_VERSIONED_XCM = 3;
|
|
78
|
+
/**
|
|
79
|
+
* Decode one XCMP message.
|
|
80
|
+
*
|
|
81
|
+
* A message starts with an `XcmpMessageFormat` byte. In the
|
|
82
|
+
* `ConcatenatedOpaqueVersionedXcm` format, each XCM that follows has a compact
|
|
83
|
+
* length prefix. Such a payload is not a single `XcmVersionedXcm`, so it must be
|
|
84
|
+
* read one item at a time. All other formats keep the previous behaviour.
|
|
85
|
+
*
|
|
86
|
+
* @param api - Polkadot API instance
|
|
87
|
+
* @param data - Message bytes, or their hex string, with the format byte first
|
|
88
|
+
*/ /**
|
|
89
|
+
* Convert a hex string to bytes. Storage gives the message as a hex string.
|
|
90
|
+
* Bytes are also accepted.
|
|
91
|
+
*
|
|
92
|
+
* @param data - Hex string or bytes
|
|
93
|
+
*/ const toBytes = (data)=>{
|
|
94
|
+
if (typeof data !== 'string') {
|
|
95
|
+
return data;
|
|
96
|
+
}
|
|
97
|
+
const digits = data.startsWith('0x') ? data.slice(2) : data;
|
|
98
|
+
const bytes = new Uint8Array(digits.length / 2);
|
|
99
|
+
for(let index = 0; index < bytes.length; index++){
|
|
100
|
+
bytes[index] = Number.parseInt(digits.slice(index * 2, index * 2 + 2), 16);
|
|
101
|
+
}
|
|
102
|
+
return bytes;
|
|
103
|
+
};
|
|
104
|
+
const decodeXcmpMessage = (api, data)=>{
|
|
105
|
+
const bytes = toBytes(data);
|
|
106
|
+
if (bytes[0] !== CONCATENATED_OPAQUE_VERSIONED_XCM) {
|
|
107
|
+
return api.createType('(XcmpMessageFormat, XcmVersionedXcm)', data).toJSON();
|
|
108
|
+
}
|
|
109
|
+
const messages = [];
|
|
110
|
+
let offset = 1;
|
|
111
|
+
while(offset < bytes.length){
|
|
112
|
+
const length = api.createType('Compact<u32>', bytes.subarray(offset));
|
|
113
|
+
offset += length.encodedLength;
|
|
114
|
+
const end = offset + length.toNumber();
|
|
115
|
+
messages.push(api.createType('XcmVersionedXcm', bytes.subarray(offset, end)).toJSON());
|
|
116
|
+
offset = end;
|
|
117
|
+
}
|
|
118
|
+
return [
|
|
119
|
+
'ConcatenatedOpaqueVersionedXcm',
|
|
120
|
+
messages
|
|
121
|
+
];
|
|
122
|
+
};
|
|
72
123
|
/**
|
|
73
124
|
* Processes a Codec or array of Codecs with a given transformation function
|
|
74
125
|
* @param codec - Single Codec or array of Codecs to process
|
|
@@ -389,7 +440,7 @@ const setupCheck = (options)=>{
|
|
|
389
440
|
* Check HRMP (Horizontal Relay-routed Message Passing) messages
|
|
390
441
|
* @param api - Polkadot API instance
|
|
391
442
|
*/ const checkHrmp = ({ api })=>check(api.query.parachainSystem.hrmpOutboundMessages(), 'hrmp').map((value)=>value.map(({ recipient, data })=>({
|
|
392
|
-
data: api
|
|
443
|
+
data: decodeXcmpMessage(api, data),
|
|
393
444
|
recipient
|
|
394
445
|
})));
|
|
395
446
|
/**
|
package/dist/esm/check.js
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `XcmpMessageFormat` index of the `ConcatenatedOpaqueVersionedXcm` variant.
|
|
3
|
+
*
|
|
4
|
+
* The variant is matched by index, not by name, because older versions of
|
|
5
|
+
* `@polkadot/types` do not declare it and cannot decode it.
|
|
6
|
+
*/ const CONCATENATED_OPAQUE_VERSIONED_XCM = 3;
|
|
7
|
+
/**
|
|
8
|
+
* Decode one XCMP message.
|
|
9
|
+
*
|
|
10
|
+
* A message starts with an `XcmpMessageFormat` byte. In the
|
|
11
|
+
* `ConcatenatedOpaqueVersionedXcm` format, each XCM that follows has a compact
|
|
12
|
+
* length prefix. Such a payload is not a single `XcmVersionedXcm`, so it must be
|
|
13
|
+
* read one item at a time. All other formats keep the previous behaviour.
|
|
14
|
+
*
|
|
15
|
+
* @param api - Polkadot API instance
|
|
16
|
+
* @param data - Message bytes, or their hex string, with the format byte first
|
|
17
|
+
*/ /**
|
|
18
|
+
* Convert a hex string to bytes. Storage gives the message as a hex string.
|
|
19
|
+
* Bytes are also accepted.
|
|
20
|
+
*
|
|
21
|
+
* @param data - Hex string or bytes
|
|
22
|
+
*/ const toBytes = (data)=>{
|
|
23
|
+
if (typeof data !== 'string') {
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
const digits = data.startsWith('0x') ? data.slice(2) : data;
|
|
27
|
+
const bytes = new Uint8Array(digits.length / 2);
|
|
28
|
+
for(let index = 0; index < bytes.length; index++){
|
|
29
|
+
bytes[index] = Number.parseInt(digits.slice(index * 2, index * 2 + 2), 16);
|
|
30
|
+
}
|
|
31
|
+
return bytes;
|
|
32
|
+
};
|
|
33
|
+
const decodeXcmpMessage = (api, data)=>{
|
|
34
|
+
const bytes = toBytes(data);
|
|
35
|
+
if (bytes[0] !== CONCATENATED_OPAQUE_VERSIONED_XCM) {
|
|
36
|
+
return api.createType('(XcmpMessageFormat, XcmVersionedXcm)', data).toJSON();
|
|
37
|
+
}
|
|
38
|
+
const messages = [];
|
|
39
|
+
let offset = 1;
|
|
40
|
+
while(offset < bytes.length){
|
|
41
|
+
const length = api.createType('Compact<u32>', bytes.subarray(offset));
|
|
42
|
+
offset += length.encodedLength;
|
|
43
|
+
const end = offset + length.toNumber();
|
|
44
|
+
messages.push(api.createType('XcmVersionedXcm', bytes.subarray(offset, end)).toJSON());
|
|
45
|
+
offset = end;
|
|
46
|
+
}
|
|
47
|
+
return [
|
|
48
|
+
'ConcatenatedOpaqueVersionedXcm',
|
|
49
|
+
messages
|
|
50
|
+
];
|
|
51
|
+
};
|
|
1
52
|
/**
|
|
2
53
|
* Processes a Codec or array of Codecs with a given transformation function
|
|
3
54
|
* @param codec - Single Codec or array of Codecs to process
|
|
@@ -301,7 +352,7 @@
|
|
|
301
352
|
* Check HRMP (Horizontal Relay-routed Message Passing) messages
|
|
302
353
|
* @param api - Polkadot API instance
|
|
303
354
|
*/ const checkHrmp = ({ api })=>check(api.query.parachainSystem.hrmpOutboundMessages(), 'hrmp').map((value)=>value.map(({ recipient, data })=>({
|
|
304
|
-
data: api
|
|
355
|
+
data: decodeXcmpMessage(api, data),
|
|
305
356
|
recipient
|
|
306
357
|
})));
|
|
307
358
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-testing",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"author": "Acala Developers <hello@acala.network>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"depcheck": "npx depcheck"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@acala-network/chopsticks-utils": "1.5.
|
|
16
|
+
"@acala-network/chopsticks-utils": "1.5.2",
|
|
17
17
|
"@polkadot/api": "^16.4.1",
|
|
18
18
|
"@polkadot/types": "^16.4.1"
|
|
19
19
|
},
|