phantasma-sdk-ts 0.9.0 → 0.9.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/dist/cjs/rpc/phantasma.js +162 -21
- package/dist/cjs/types/carbon-serialization.js +38 -29
- package/dist/esm/rpc/phantasma.js +161 -20
- package/dist/esm/types/carbon-serialization.js +38 -29
- package/dist/types/rpc/phantasma.d.ts +9 -1
- package/dist/types/rpc/phantasma.d.ts.map +1 -1
- package/dist/types/types/carbon-serialization.d.ts +2 -0
- package/dist/types/types/carbon-serialization.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PhantasmaAPI = void 0;
|
|
6
|
+
exports.PhantasmaAPI = exports.DEFAULT_MAX_RPC_RESPONSE_BYTES = void 0;
|
|
7
7
|
const logger_js_1 = require("../utils/logger.js");
|
|
8
8
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
9
9
|
const rpc_result_js_1 = require("./rpc-result.js");
|
|
@@ -17,10 +17,120 @@ function rpcHttpError(status, statusText) {
|
|
|
17
17
|
statusText,
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
exports.DEFAULT_MAX_RPC_RESPONSE_BYTES = 16 * 1024 * 1024;
|
|
20
21
|
function parseRpcNumber(result) {
|
|
21
22
|
return typeof result === 'string' ? parseInt(result, 10) : result;
|
|
22
23
|
}
|
|
24
|
+
function rpcResponseIdMatches(responseId, requestId) {
|
|
25
|
+
if (typeof responseId === 'string') {
|
|
26
|
+
return responseId === requestId;
|
|
27
|
+
}
|
|
28
|
+
if (typeof responseId === 'number' && Number.isInteger(responseId)) {
|
|
29
|
+
return String(responseId) === requestId;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
function normalizeMaxRpcResponseBytes(value) {
|
|
34
|
+
const maxBytes = value ?? exports.DEFAULT_MAX_RPC_RESPONSE_BYTES;
|
|
35
|
+
if (maxBytes !== Number.POSITIVE_INFINITY && (!Number.isFinite(maxBytes) || maxBytes <= 0)) {
|
|
36
|
+
throw new Error('maxRpcResponseBytes must be a positive number');
|
|
37
|
+
}
|
|
38
|
+
return maxBytes;
|
|
39
|
+
}
|
|
40
|
+
function isObject(value) {
|
|
41
|
+
return typeof value === 'object' && value !== null;
|
|
42
|
+
}
|
|
43
|
+
function isWebReadableStream(value) {
|
|
44
|
+
return (isObject(value) &&
|
|
45
|
+
'getReader' in value &&
|
|
46
|
+
typeof value.getReader === 'function');
|
|
47
|
+
}
|
|
48
|
+
function isAsyncIterableBody(value) {
|
|
49
|
+
return isObject(value) && Symbol.asyncIterator in value;
|
|
50
|
+
}
|
|
51
|
+
function chunkBytes(chunk) {
|
|
52
|
+
return typeof chunk === 'string' ? new TextEncoder().encode(chunk) : chunk;
|
|
53
|
+
}
|
|
54
|
+
function appendLimitedChunk(chunks, chunk, totalBytes, maxBytes, method) {
|
|
55
|
+
const bytes = chunkBytes(chunk);
|
|
56
|
+
const nextTotal = totalBytes + bytes.byteLength;
|
|
57
|
+
if (nextTotal > maxBytes) {
|
|
58
|
+
throw new Error(`RPC request ${method} response body exceeds ${maxBytes} bytes`);
|
|
59
|
+
}
|
|
60
|
+
chunks.push(bytes);
|
|
61
|
+
return nextTotal;
|
|
62
|
+
}
|
|
63
|
+
function decodeChunks(chunks, totalBytes) {
|
|
64
|
+
const body = new Uint8Array(totalBytes);
|
|
65
|
+
let offset = 0;
|
|
66
|
+
for (const chunk of chunks) {
|
|
67
|
+
body.set(chunk, offset);
|
|
68
|
+
offset += chunk.byteLength;
|
|
69
|
+
}
|
|
70
|
+
return new TextDecoder().decode(body);
|
|
71
|
+
}
|
|
72
|
+
async function readStreamBody(body, method, maxBytes) {
|
|
73
|
+
const chunks = [];
|
|
74
|
+
let totalBytes = 0;
|
|
75
|
+
if (isWebReadableStream(body)) {
|
|
76
|
+
const reader = body.getReader();
|
|
77
|
+
try {
|
|
78
|
+
for (;;) {
|
|
79
|
+
const { done, value } = await reader.read();
|
|
80
|
+
if (done)
|
|
81
|
+
break;
|
|
82
|
+
if (value) {
|
|
83
|
+
totalBytes = appendLimitedChunk(chunks, value, totalBytes, maxBytes, method);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
await reader.cancel().catch(() => undefined);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
reader.releaseLock();
|
|
93
|
+
}
|
|
94
|
+
return decodeChunks(chunks, totalBytes);
|
|
95
|
+
}
|
|
96
|
+
for await (const chunk of body) {
|
|
97
|
+
totalBytes = appendLimitedChunk(chunks, chunk, totalBytes, maxBytes, method);
|
|
98
|
+
}
|
|
99
|
+
return decodeChunks(chunks, totalBytes);
|
|
100
|
+
}
|
|
101
|
+
async function readJsonResponseBody(res, method, maxBytes) {
|
|
102
|
+
const contentLength = res.headers.get('content-length');
|
|
103
|
+
if (contentLength !== null) {
|
|
104
|
+
const contentLengthBytes = Number(contentLength);
|
|
105
|
+
if (Number.isFinite(contentLengthBytes) && contentLengthBytes > maxBytes) {
|
|
106
|
+
throw new Error(`RPC request ${method} response body exceeds ${maxBytes} bytes`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
let text;
|
|
110
|
+
const body = res.body;
|
|
111
|
+
if (isWebReadableStream(body) || isAsyncIterableBody(body)) {
|
|
112
|
+
text = await readStreamBody(body, method, maxBytes);
|
|
113
|
+
}
|
|
114
|
+
else if (contentLength !== null || maxBytes === Number.POSITIVE_INFINITY) {
|
|
115
|
+
text = await res.text();
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
throw new Error(`RPC request ${method} response body stream is not available`);
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
return JSON.parse(text);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
125
|
+
throw new Error(`Invalid JSON: ${message}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
23
128
|
class PhantasmaAPI {
|
|
129
|
+
nextJsonRpcRequestId() {
|
|
130
|
+
const requestId = String(this.nextRpcRequestId);
|
|
131
|
+
this.nextRpcRequestId += 1;
|
|
132
|
+
return requestId;
|
|
133
|
+
}
|
|
24
134
|
pingAsync(host) {
|
|
25
135
|
return new Promise((resolve, reject) => {
|
|
26
136
|
const started = new Date().getTime();
|
|
@@ -49,11 +159,13 @@ class PhantasmaAPI {
|
|
|
49
159
|
}
|
|
50
160
|
});
|
|
51
161
|
}
|
|
52
|
-
constructor(defHost, peersUrlJson, nexus) {
|
|
162
|
+
constructor(defHost, peersUrlJson, nexus, options = {}) {
|
|
163
|
+
this.nextRpcRequestId = 1;
|
|
53
164
|
this.rpcName = 'Auto';
|
|
54
165
|
this.nexus = nexus;
|
|
55
166
|
this.host = defHost;
|
|
56
167
|
this.availableHosts = [];
|
|
168
|
+
this.maxRpcResponseBytes = normalizeMaxRpcResponseBytes(options.maxRpcResponseBytes);
|
|
57
169
|
if (peersUrlJson != undefined && peersUrlJson != null) {
|
|
58
170
|
(0, cross_fetch_1.default)(peersUrlJson + '?_=' + new Date().getTime()).then(async (res) => {
|
|
59
171
|
const data = (await res.json());
|
|
@@ -77,6 +189,7 @@ class PhantasmaAPI {
|
|
|
77
189
|
}
|
|
78
190
|
}
|
|
79
191
|
async JSONRPCResult(method, params) {
|
|
192
|
+
const requestId = this.nextJsonRpcRequestId();
|
|
80
193
|
let res;
|
|
81
194
|
try {
|
|
82
195
|
res = await (0, cross_fetch_1.default)(this.host, {
|
|
@@ -86,7 +199,7 @@ class PhantasmaAPI {
|
|
|
86
199
|
jsonrpc: '2.0',
|
|
87
200
|
method: method,
|
|
88
201
|
params: params,
|
|
89
|
-
id:
|
|
202
|
+
id: requestId,
|
|
90
203
|
}),
|
|
91
204
|
headers: { 'Content-Type': 'application/json' },
|
|
92
205
|
});
|
|
@@ -99,7 +212,7 @@ class PhantasmaAPI {
|
|
|
99
212
|
}
|
|
100
213
|
let resJson;
|
|
101
214
|
try {
|
|
102
|
-
resJson = await res.
|
|
215
|
+
resJson = await readJsonResponseBody(res, method, this.maxRpcResponseBytes);
|
|
103
216
|
}
|
|
104
217
|
catch (error) {
|
|
105
218
|
return (0, rpc_result_js_1.normalizeRpcError)(error, `RPC request ${method} returned invalid JSON`);
|
|
@@ -109,6 +222,9 @@ class PhantasmaAPI {
|
|
|
109
222
|
return (0, rpc_result_js_1.normalizeRpcError)(undefined, `RPC request ${method} returned an invalid response`);
|
|
110
223
|
}
|
|
111
224
|
const response = resJson;
|
|
225
|
+
if (!rpcResponseIdMatches(response.id, requestId)) {
|
|
226
|
+
return (0, rpc_result_js_1.normalizeRpcError)(undefined, `RPC request ${method} returned a mismatched response id`);
|
|
227
|
+
}
|
|
112
228
|
if (response.error !== undefined && response.error !== null) {
|
|
113
229
|
return (0, rpc_result_js_1.normalizeRpcError)(response.error, `RPC request ${method} failed`);
|
|
114
230
|
}
|
|
@@ -118,25 +234,50 @@ class PhantasmaAPI {
|
|
|
118
234
|
return response.result;
|
|
119
235
|
}
|
|
120
236
|
async JSONRPC(method, params) {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
237
|
+
const requestId = this.nextJsonRpcRequestId();
|
|
238
|
+
let res;
|
|
239
|
+
try {
|
|
240
|
+
res = await (0, cross_fetch_1.default)(this.host, {
|
|
241
|
+
method: 'POST',
|
|
242
|
+
mode: 'cors',
|
|
243
|
+
body: JSON.stringify({
|
|
244
|
+
jsonrpc: '2.0',
|
|
245
|
+
method: method,
|
|
246
|
+
params: params,
|
|
247
|
+
id: requestId,
|
|
248
|
+
}),
|
|
249
|
+
headers: { 'Content-Type': 'application/json' },
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
254
|
+
throw new Error(`RPC request ${method} failed: ${message}`);
|
|
255
|
+
}
|
|
256
|
+
if (!res.ok) {
|
|
257
|
+
throw new Error(res.statusText ? `HTTP ${res.status}: ${res.statusText}` : `HTTP ${res.status}`);
|
|
258
|
+
}
|
|
259
|
+
const resJson = await readJsonResponseBody(res, method, this.maxRpcResponseBytes);
|
|
133
260
|
logger_js_1.logger.log('method', method, resJson);
|
|
134
|
-
if (resJson
|
|
135
|
-
|
|
136
|
-
return { error: resJson.error.message };
|
|
137
|
-
return { error: resJson.error };
|
|
261
|
+
if (!isObjectRecord(resJson)) {
|
|
262
|
+
throw new Error(`RPC request ${method} returned an invalid response`);
|
|
138
263
|
}
|
|
139
|
-
|
|
264
|
+
const response = resJson;
|
|
265
|
+
if (!rpcResponseIdMatches(response.id, requestId)) {
|
|
266
|
+
throw new Error(`RPC request ${method} returned a mismatched response id`);
|
|
267
|
+
}
|
|
268
|
+
if (response.error) {
|
|
269
|
+
if (typeof response.error === 'object' && response.error.message)
|
|
270
|
+
return { error: response.error.message };
|
|
271
|
+
return { error: response.error };
|
|
272
|
+
}
|
|
273
|
+
if (!('result' in response)) {
|
|
274
|
+
throw new Error(`RPC request ${method} returned no result`);
|
|
275
|
+
}
|
|
276
|
+
return response.result;
|
|
277
|
+
}
|
|
278
|
+
setMaxRpcResponseBytes(maxBytes) {
|
|
279
|
+
this.maxRpcResponseBytes = normalizeMaxRpcResponseBytes(maxBytes);
|
|
280
|
+
return this;
|
|
140
281
|
}
|
|
141
282
|
setRpcHost(rpcHost) {
|
|
142
283
|
this.host = rpcHost;
|
|
@@ -199,45 +199,54 @@ class CarbonBinaryReader {
|
|
|
199
199
|
this.bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
200
200
|
this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
|
|
201
201
|
}
|
|
202
|
+
remaining() {
|
|
203
|
+
return this.bytes.length - this.offset;
|
|
204
|
+
}
|
|
202
205
|
take(count) {
|
|
203
|
-
Throw.If(
|
|
206
|
+
Throw.If(!Number.isInteger(count) || count < 0, 'invalid byte count');
|
|
207
|
+
Throw.If(count > this.remaining(), 'end of stream reached');
|
|
204
208
|
const out = this.bytes.subarray(this.offset, this.offset + count);
|
|
205
209
|
this.offset += count;
|
|
206
210
|
return out;
|
|
207
211
|
}
|
|
212
|
+
readLength(elementSize = 1) {
|
|
213
|
+
const len = this.read4();
|
|
214
|
+
Throw.If(len < 0, 'invalid array length');
|
|
215
|
+
Throw.If(!Number.isInteger(elementSize) || elementSize <= 0, 'invalid array element size');
|
|
216
|
+
Throw.If(len > Math.floor(this.remaining() / elementSize), `array length ${len} exceeds remaining bytes ${this.remaining()}`);
|
|
217
|
+
return len;
|
|
218
|
+
}
|
|
208
219
|
readRemaining() {
|
|
209
220
|
return this.take(this.bytes.length - this.offset);
|
|
210
221
|
}
|
|
211
222
|
// Raw reads
|
|
212
223
|
read1() {
|
|
213
|
-
|
|
214
|
-
this.offset += 1;
|
|
215
|
-
return b;
|
|
224
|
+
return this.take(1)[0];
|
|
216
225
|
}
|
|
217
226
|
read2() {
|
|
218
|
-
const
|
|
219
|
-
this.
|
|
220
|
-
return
|
|
227
|
+
const offset = this.offset;
|
|
228
|
+
this.take(2);
|
|
229
|
+
return this.view.getInt16(offset, true);
|
|
221
230
|
}
|
|
222
231
|
read4() {
|
|
223
|
-
const
|
|
224
|
-
this.
|
|
225
|
-
return
|
|
232
|
+
const offset = this.offset;
|
|
233
|
+
this.take(4);
|
|
234
|
+
return this.view.getInt32(offset, true);
|
|
226
235
|
}
|
|
227
236
|
read4u() {
|
|
228
|
-
const
|
|
229
|
-
this.
|
|
230
|
-
return
|
|
237
|
+
const offset = this.offset;
|
|
238
|
+
this.take(4);
|
|
239
|
+
return this.view.getUint32(offset, true);
|
|
231
240
|
}
|
|
232
241
|
read8() {
|
|
233
|
-
const
|
|
234
|
-
this.
|
|
235
|
-
return
|
|
242
|
+
const offset = this.offset;
|
|
243
|
+
this.take(8);
|
|
244
|
+
return this.view.getBigInt64(offset, true);
|
|
236
245
|
}
|
|
237
246
|
read8u() {
|
|
238
|
-
const
|
|
239
|
-
this.
|
|
240
|
-
return
|
|
247
|
+
const offset = this.offset;
|
|
248
|
+
this.take(8);
|
|
249
|
+
return this.view.getBigUint64(offset, true);
|
|
241
250
|
}
|
|
242
251
|
// Fixed-size blobs
|
|
243
252
|
readExactly(count) {
|
|
@@ -268,7 +277,7 @@ class CarbonBinaryReader {
|
|
|
268
277
|
return t;
|
|
269
278
|
}
|
|
270
279
|
readArrayBlob(ctor) {
|
|
271
|
-
const len = this.
|
|
280
|
+
const len = this.readLength();
|
|
272
281
|
const arr = new Array(len);
|
|
273
282
|
for (let i = 0; i < len; i++) {
|
|
274
283
|
const t = new ctor();
|
|
@@ -300,7 +309,7 @@ class CarbonBinaryReader {
|
|
|
300
309
|
return twosComplementLEToBigInt(word);
|
|
301
310
|
}
|
|
302
311
|
readArrayBigInt() {
|
|
303
|
-
const len = this.
|
|
312
|
+
const len = this.readLength();
|
|
304
313
|
const arr = new Array(len);
|
|
305
314
|
for (let i = 0; i < len; i++)
|
|
306
315
|
arr[i] = this.readBigInt();
|
|
@@ -320,7 +329,7 @@ class CarbonBinaryReader {
|
|
|
320
329
|
return textDecoder.decode(slice);
|
|
321
330
|
}
|
|
322
331
|
readArraySz() {
|
|
323
|
-
const len = this.
|
|
332
|
+
const len = this.readLength();
|
|
324
333
|
const out = new Array(len);
|
|
325
334
|
for (let i = 0; i < len; i++)
|
|
326
335
|
out[i] = this.readSz();
|
|
@@ -328,46 +337,46 @@ class CarbonBinaryReader {
|
|
|
328
337
|
}
|
|
329
338
|
// Variable-length byte arrays
|
|
330
339
|
readArray() {
|
|
331
|
-
const len = this.
|
|
340
|
+
const len = this.readLength();
|
|
332
341
|
return this.readExactly(len);
|
|
333
342
|
}
|
|
334
343
|
readArrayOfArrays() {
|
|
335
|
-
const len = this.
|
|
344
|
+
const len = this.readLength(4);
|
|
336
345
|
const arr = new Array(len);
|
|
337
346
|
for (let i = 0; i < len; i++)
|
|
338
347
|
arr[i] = this.readArray();
|
|
339
348
|
return arr;
|
|
340
349
|
}
|
|
341
350
|
readArray64u() {
|
|
342
|
-
const len = this.
|
|
351
|
+
const len = this.readLength(8);
|
|
343
352
|
const out = new Array(len);
|
|
344
353
|
for (let i = 0; i < len; i++)
|
|
345
354
|
out[i] = this.read8u();
|
|
346
355
|
return out;
|
|
347
356
|
}
|
|
348
357
|
readArray64() {
|
|
349
|
-
const len = this.
|
|
358
|
+
const len = this.readLength(8);
|
|
350
359
|
const out = new Array(len);
|
|
351
360
|
for (let i = 0; i < len; i++)
|
|
352
361
|
out[i] = this.read8();
|
|
353
362
|
return out;
|
|
354
363
|
}
|
|
355
364
|
readArray32() {
|
|
356
|
-
const len = this.
|
|
365
|
+
const len = this.readLength(4);
|
|
357
366
|
const out = new Array(len);
|
|
358
367
|
for (let i = 0; i < len; i++)
|
|
359
368
|
out[i] = this.read4();
|
|
360
369
|
return out;
|
|
361
370
|
}
|
|
362
371
|
readArray16() {
|
|
363
|
-
const len = this.
|
|
372
|
+
const len = this.readLength(2);
|
|
364
373
|
const out = new Array(len);
|
|
365
374
|
for (let i = 0; i < len; i++)
|
|
366
375
|
out[i] = this.read2();
|
|
367
376
|
return out;
|
|
368
377
|
}
|
|
369
378
|
readArray8() {
|
|
370
|
-
const len = this.
|
|
379
|
+
const len = this.readLength();
|
|
371
380
|
const out = new Array(len);
|
|
372
381
|
for (let i = 0; i < len; i++)
|
|
373
382
|
out[i] = this.read1();
|
|
@@ -11,10 +11,120 @@ function rpcHttpError(status, statusText) {
|
|
|
11
11
|
statusText,
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
+
export const DEFAULT_MAX_RPC_RESPONSE_BYTES = 16 * 1024 * 1024;
|
|
14
15
|
function parseRpcNumber(result) {
|
|
15
16
|
return typeof result === 'string' ? parseInt(result, 10) : result;
|
|
16
17
|
}
|
|
18
|
+
function rpcResponseIdMatches(responseId, requestId) {
|
|
19
|
+
if (typeof responseId === 'string') {
|
|
20
|
+
return responseId === requestId;
|
|
21
|
+
}
|
|
22
|
+
if (typeof responseId === 'number' && Number.isInteger(responseId)) {
|
|
23
|
+
return String(responseId) === requestId;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
function normalizeMaxRpcResponseBytes(value) {
|
|
28
|
+
const maxBytes = value ?? DEFAULT_MAX_RPC_RESPONSE_BYTES;
|
|
29
|
+
if (maxBytes !== Number.POSITIVE_INFINITY && (!Number.isFinite(maxBytes) || maxBytes <= 0)) {
|
|
30
|
+
throw new Error('maxRpcResponseBytes must be a positive number');
|
|
31
|
+
}
|
|
32
|
+
return maxBytes;
|
|
33
|
+
}
|
|
34
|
+
function isObject(value) {
|
|
35
|
+
return typeof value === 'object' && value !== null;
|
|
36
|
+
}
|
|
37
|
+
function isWebReadableStream(value) {
|
|
38
|
+
return (isObject(value) &&
|
|
39
|
+
'getReader' in value &&
|
|
40
|
+
typeof value.getReader === 'function');
|
|
41
|
+
}
|
|
42
|
+
function isAsyncIterableBody(value) {
|
|
43
|
+
return isObject(value) && Symbol.asyncIterator in value;
|
|
44
|
+
}
|
|
45
|
+
function chunkBytes(chunk) {
|
|
46
|
+
return typeof chunk === 'string' ? new TextEncoder().encode(chunk) : chunk;
|
|
47
|
+
}
|
|
48
|
+
function appendLimitedChunk(chunks, chunk, totalBytes, maxBytes, method) {
|
|
49
|
+
const bytes = chunkBytes(chunk);
|
|
50
|
+
const nextTotal = totalBytes + bytes.byteLength;
|
|
51
|
+
if (nextTotal > maxBytes) {
|
|
52
|
+
throw new Error(`RPC request ${method} response body exceeds ${maxBytes} bytes`);
|
|
53
|
+
}
|
|
54
|
+
chunks.push(bytes);
|
|
55
|
+
return nextTotal;
|
|
56
|
+
}
|
|
57
|
+
function decodeChunks(chunks, totalBytes) {
|
|
58
|
+
const body = new Uint8Array(totalBytes);
|
|
59
|
+
let offset = 0;
|
|
60
|
+
for (const chunk of chunks) {
|
|
61
|
+
body.set(chunk, offset);
|
|
62
|
+
offset += chunk.byteLength;
|
|
63
|
+
}
|
|
64
|
+
return new TextDecoder().decode(body);
|
|
65
|
+
}
|
|
66
|
+
async function readStreamBody(body, method, maxBytes) {
|
|
67
|
+
const chunks = [];
|
|
68
|
+
let totalBytes = 0;
|
|
69
|
+
if (isWebReadableStream(body)) {
|
|
70
|
+
const reader = body.getReader();
|
|
71
|
+
try {
|
|
72
|
+
for (;;) {
|
|
73
|
+
const { done, value } = await reader.read();
|
|
74
|
+
if (done)
|
|
75
|
+
break;
|
|
76
|
+
if (value) {
|
|
77
|
+
totalBytes = appendLimitedChunk(chunks, value, totalBytes, maxBytes, method);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
await reader.cancel().catch(() => undefined);
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
reader.releaseLock();
|
|
87
|
+
}
|
|
88
|
+
return decodeChunks(chunks, totalBytes);
|
|
89
|
+
}
|
|
90
|
+
for await (const chunk of body) {
|
|
91
|
+
totalBytes = appendLimitedChunk(chunks, chunk, totalBytes, maxBytes, method);
|
|
92
|
+
}
|
|
93
|
+
return decodeChunks(chunks, totalBytes);
|
|
94
|
+
}
|
|
95
|
+
async function readJsonResponseBody(res, method, maxBytes) {
|
|
96
|
+
const contentLength = res.headers.get('content-length');
|
|
97
|
+
if (contentLength !== null) {
|
|
98
|
+
const contentLengthBytes = Number(contentLength);
|
|
99
|
+
if (Number.isFinite(contentLengthBytes) && contentLengthBytes > maxBytes) {
|
|
100
|
+
throw new Error(`RPC request ${method} response body exceeds ${maxBytes} bytes`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
let text;
|
|
104
|
+
const body = res.body;
|
|
105
|
+
if (isWebReadableStream(body) || isAsyncIterableBody(body)) {
|
|
106
|
+
text = await readStreamBody(body, method, maxBytes);
|
|
107
|
+
}
|
|
108
|
+
else if (contentLength !== null || maxBytes === Number.POSITIVE_INFINITY) {
|
|
109
|
+
text = await res.text();
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
throw new Error(`RPC request ${method} response body stream is not available`);
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
return JSON.parse(text);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
119
|
+
throw new Error(`Invalid JSON: ${message}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
17
122
|
export class PhantasmaAPI {
|
|
123
|
+
nextJsonRpcRequestId() {
|
|
124
|
+
const requestId = String(this.nextRpcRequestId);
|
|
125
|
+
this.nextRpcRequestId += 1;
|
|
126
|
+
return requestId;
|
|
127
|
+
}
|
|
18
128
|
pingAsync(host) {
|
|
19
129
|
return new Promise((resolve, reject) => {
|
|
20
130
|
const started = new Date().getTime();
|
|
@@ -43,11 +153,13 @@ export class PhantasmaAPI {
|
|
|
43
153
|
}
|
|
44
154
|
});
|
|
45
155
|
}
|
|
46
|
-
constructor(defHost, peersUrlJson, nexus) {
|
|
156
|
+
constructor(defHost, peersUrlJson, nexus, options = {}) {
|
|
157
|
+
this.nextRpcRequestId = 1;
|
|
47
158
|
this.rpcName = 'Auto';
|
|
48
159
|
this.nexus = nexus;
|
|
49
160
|
this.host = defHost;
|
|
50
161
|
this.availableHosts = [];
|
|
162
|
+
this.maxRpcResponseBytes = normalizeMaxRpcResponseBytes(options.maxRpcResponseBytes);
|
|
51
163
|
if (peersUrlJson != undefined && peersUrlJson != null) {
|
|
52
164
|
fetch(peersUrlJson + '?_=' + new Date().getTime()).then(async (res) => {
|
|
53
165
|
const data = (await res.json());
|
|
@@ -71,6 +183,7 @@ export class PhantasmaAPI {
|
|
|
71
183
|
}
|
|
72
184
|
}
|
|
73
185
|
async JSONRPCResult(method, params) {
|
|
186
|
+
const requestId = this.nextJsonRpcRequestId();
|
|
74
187
|
let res;
|
|
75
188
|
try {
|
|
76
189
|
res = await fetch(this.host, {
|
|
@@ -80,7 +193,7 @@ export class PhantasmaAPI {
|
|
|
80
193
|
jsonrpc: '2.0',
|
|
81
194
|
method: method,
|
|
82
195
|
params: params,
|
|
83
|
-
id:
|
|
196
|
+
id: requestId,
|
|
84
197
|
}),
|
|
85
198
|
headers: { 'Content-Type': 'application/json' },
|
|
86
199
|
});
|
|
@@ -93,7 +206,7 @@ export class PhantasmaAPI {
|
|
|
93
206
|
}
|
|
94
207
|
let resJson;
|
|
95
208
|
try {
|
|
96
|
-
resJson = await res.
|
|
209
|
+
resJson = await readJsonResponseBody(res, method, this.maxRpcResponseBytes);
|
|
97
210
|
}
|
|
98
211
|
catch (error) {
|
|
99
212
|
return normalizeRpcError(error, `RPC request ${method} returned invalid JSON`);
|
|
@@ -103,6 +216,9 @@ export class PhantasmaAPI {
|
|
|
103
216
|
return normalizeRpcError(undefined, `RPC request ${method} returned an invalid response`);
|
|
104
217
|
}
|
|
105
218
|
const response = resJson;
|
|
219
|
+
if (!rpcResponseIdMatches(response.id, requestId)) {
|
|
220
|
+
return normalizeRpcError(undefined, `RPC request ${method} returned a mismatched response id`);
|
|
221
|
+
}
|
|
106
222
|
if (response.error !== undefined && response.error !== null) {
|
|
107
223
|
return normalizeRpcError(response.error, `RPC request ${method} failed`);
|
|
108
224
|
}
|
|
@@ -112,25 +228,50 @@ export class PhantasmaAPI {
|
|
|
112
228
|
return response.result;
|
|
113
229
|
}
|
|
114
230
|
async JSONRPC(method, params) {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
231
|
+
const requestId = this.nextJsonRpcRequestId();
|
|
232
|
+
let res;
|
|
233
|
+
try {
|
|
234
|
+
res = await fetch(this.host, {
|
|
235
|
+
method: 'POST',
|
|
236
|
+
mode: 'cors',
|
|
237
|
+
body: JSON.stringify({
|
|
238
|
+
jsonrpc: '2.0',
|
|
239
|
+
method: method,
|
|
240
|
+
params: params,
|
|
241
|
+
id: requestId,
|
|
242
|
+
}),
|
|
243
|
+
headers: { 'Content-Type': 'application/json' },
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
248
|
+
throw new Error(`RPC request ${method} failed: ${message}`);
|
|
249
|
+
}
|
|
250
|
+
if (!res.ok) {
|
|
251
|
+
throw new Error(res.statusText ? `HTTP ${res.status}: ${res.statusText}` : `HTTP ${res.status}`);
|
|
252
|
+
}
|
|
253
|
+
const resJson = await readJsonResponseBody(res, method, this.maxRpcResponseBytes);
|
|
127
254
|
logger.log('method', method, resJson);
|
|
128
|
-
if (resJson
|
|
129
|
-
|
|
130
|
-
return { error: resJson.error.message };
|
|
131
|
-
return { error: resJson.error };
|
|
255
|
+
if (!isObjectRecord(resJson)) {
|
|
256
|
+
throw new Error(`RPC request ${method} returned an invalid response`);
|
|
132
257
|
}
|
|
133
|
-
|
|
258
|
+
const response = resJson;
|
|
259
|
+
if (!rpcResponseIdMatches(response.id, requestId)) {
|
|
260
|
+
throw new Error(`RPC request ${method} returned a mismatched response id`);
|
|
261
|
+
}
|
|
262
|
+
if (response.error) {
|
|
263
|
+
if (typeof response.error === 'object' && response.error.message)
|
|
264
|
+
return { error: response.error.message };
|
|
265
|
+
return { error: response.error };
|
|
266
|
+
}
|
|
267
|
+
if (!('result' in response)) {
|
|
268
|
+
throw new Error(`RPC request ${method} returned no result`);
|
|
269
|
+
}
|
|
270
|
+
return response.result;
|
|
271
|
+
}
|
|
272
|
+
setMaxRpcResponseBytes(maxBytes) {
|
|
273
|
+
this.maxRpcResponseBytes = normalizeMaxRpcResponseBytes(maxBytes);
|
|
274
|
+
return this;
|
|
134
275
|
}
|
|
135
276
|
setRpcHost(rpcHost) {
|
|
136
277
|
this.host = rpcHost;
|
|
@@ -190,45 +190,54 @@ export class CarbonBinaryReader {
|
|
|
190
190
|
this.bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
191
191
|
this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
|
|
192
192
|
}
|
|
193
|
+
remaining() {
|
|
194
|
+
return this.bytes.length - this.offset;
|
|
195
|
+
}
|
|
193
196
|
take(count) {
|
|
194
|
-
Throw.If(
|
|
197
|
+
Throw.If(!Number.isInteger(count) || count < 0, 'invalid byte count');
|
|
198
|
+
Throw.If(count > this.remaining(), 'end of stream reached');
|
|
195
199
|
const out = this.bytes.subarray(this.offset, this.offset + count);
|
|
196
200
|
this.offset += count;
|
|
197
201
|
return out;
|
|
198
202
|
}
|
|
203
|
+
readLength(elementSize = 1) {
|
|
204
|
+
const len = this.read4();
|
|
205
|
+
Throw.If(len < 0, 'invalid array length');
|
|
206
|
+
Throw.If(!Number.isInteger(elementSize) || elementSize <= 0, 'invalid array element size');
|
|
207
|
+
Throw.If(len > Math.floor(this.remaining() / elementSize), `array length ${len} exceeds remaining bytes ${this.remaining()}`);
|
|
208
|
+
return len;
|
|
209
|
+
}
|
|
199
210
|
readRemaining() {
|
|
200
211
|
return this.take(this.bytes.length - this.offset);
|
|
201
212
|
}
|
|
202
213
|
// Raw reads
|
|
203
214
|
read1() {
|
|
204
|
-
|
|
205
|
-
this.offset += 1;
|
|
206
|
-
return b;
|
|
215
|
+
return this.take(1)[0];
|
|
207
216
|
}
|
|
208
217
|
read2() {
|
|
209
|
-
const
|
|
210
|
-
this.
|
|
211
|
-
return
|
|
218
|
+
const offset = this.offset;
|
|
219
|
+
this.take(2);
|
|
220
|
+
return this.view.getInt16(offset, true);
|
|
212
221
|
}
|
|
213
222
|
read4() {
|
|
214
|
-
const
|
|
215
|
-
this.
|
|
216
|
-
return
|
|
223
|
+
const offset = this.offset;
|
|
224
|
+
this.take(4);
|
|
225
|
+
return this.view.getInt32(offset, true);
|
|
217
226
|
}
|
|
218
227
|
read4u() {
|
|
219
|
-
const
|
|
220
|
-
this.
|
|
221
|
-
return
|
|
228
|
+
const offset = this.offset;
|
|
229
|
+
this.take(4);
|
|
230
|
+
return this.view.getUint32(offset, true);
|
|
222
231
|
}
|
|
223
232
|
read8() {
|
|
224
|
-
const
|
|
225
|
-
this.
|
|
226
|
-
return
|
|
233
|
+
const offset = this.offset;
|
|
234
|
+
this.take(8);
|
|
235
|
+
return this.view.getBigInt64(offset, true);
|
|
227
236
|
}
|
|
228
237
|
read8u() {
|
|
229
|
-
const
|
|
230
|
-
this.
|
|
231
|
-
return
|
|
238
|
+
const offset = this.offset;
|
|
239
|
+
this.take(8);
|
|
240
|
+
return this.view.getBigUint64(offset, true);
|
|
232
241
|
}
|
|
233
242
|
// Fixed-size blobs
|
|
234
243
|
readExactly(count) {
|
|
@@ -259,7 +268,7 @@ export class CarbonBinaryReader {
|
|
|
259
268
|
return t;
|
|
260
269
|
}
|
|
261
270
|
readArrayBlob(ctor) {
|
|
262
|
-
const len = this.
|
|
271
|
+
const len = this.readLength();
|
|
263
272
|
const arr = new Array(len);
|
|
264
273
|
for (let i = 0; i < len; i++) {
|
|
265
274
|
const t = new ctor();
|
|
@@ -291,7 +300,7 @@ export class CarbonBinaryReader {
|
|
|
291
300
|
return twosComplementLEToBigInt(word);
|
|
292
301
|
}
|
|
293
302
|
readArrayBigInt() {
|
|
294
|
-
const len = this.
|
|
303
|
+
const len = this.readLength();
|
|
295
304
|
const arr = new Array(len);
|
|
296
305
|
for (let i = 0; i < len; i++)
|
|
297
306
|
arr[i] = this.readBigInt();
|
|
@@ -311,7 +320,7 @@ export class CarbonBinaryReader {
|
|
|
311
320
|
return textDecoder.decode(slice);
|
|
312
321
|
}
|
|
313
322
|
readArraySz() {
|
|
314
|
-
const len = this.
|
|
323
|
+
const len = this.readLength();
|
|
315
324
|
const out = new Array(len);
|
|
316
325
|
for (let i = 0; i < len; i++)
|
|
317
326
|
out[i] = this.readSz();
|
|
@@ -319,46 +328,46 @@ export class CarbonBinaryReader {
|
|
|
319
328
|
}
|
|
320
329
|
// Variable-length byte arrays
|
|
321
330
|
readArray() {
|
|
322
|
-
const len = this.
|
|
331
|
+
const len = this.readLength();
|
|
323
332
|
return this.readExactly(len);
|
|
324
333
|
}
|
|
325
334
|
readArrayOfArrays() {
|
|
326
|
-
const len = this.
|
|
335
|
+
const len = this.readLength(4);
|
|
327
336
|
const arr = new Array(len);
|
|
328
337
|
for (let i = 0; i < len; i++)
|
|
329
338
|
arr[i] = this.readArray();
|
|
330
339
|
return arr;
|
|
331
340
|
}
|
|
332
341
|
readArray64u() {
|
|
333
|
-
const len = this.
|
|
342
|
+
const len = this.readLength(8);
|
|
334
343
|
const out = new Array(len);
|
|
335
344
|
for (let i = 0; i < len; i++)
|
|
336
345
|
out[i] = this.read8u();
|
|
337
346
|
return out;
|
|
338
347
|
}
|
|
339
348
|
readArray64() {
|
|
340
|
-
const len = this.
|
|
349
|
+
const len = this.readLength(8);
|
|
341
350
|
const out = new Array(len);
|
|
342
351
|
for (let i = 0; i < len; i++)
|
|
343
352
|
out[i] = this.read8();
|
|
344
353
|
return out;
|
|
345
354
|
}
|
|
346
355
|
readArray32() {
|
|
347
|
-
const len = this.
|
|
356
|
+
const len = this.readLength(4);
|
|
348
357
|
const out = new Array(len);
|
|
349
358
|
for (let i = 0; i < len; i++)
|
|
350
359
|
out[i] = this.read4();
|
|
351
360
|
return out;
|
|
352
361
|
}
|
|
353
362
|
readArray16() {
|
|
354
|
-
const len = this.
|
|
363
|
+
const len = this.readLength(2);
|
|
355
364
|
const out = new Array(len);
|
|
356
365
|
for (let i = 0; i < len; i++)
|
|
357
366
|
out[i] = this.read2();
|
|
358
367
|
return out;
|
|
359
368
|
}
|
|
360
369
|
readArray8() {
|
|
361
|
-
const len = this.
|
|
370
|
+
const len = this.readLength();
|
|
362
371
|
const out = new Array(len);
|
|
363
372
|
for (let i = 0; i < len; i++)
|
|
364
373
|
out[i] = this.read1();
|
|
@@ -23,15 +23,23 @@ interface RpcPeer {
|
|
|
23
23
|
info?: string;
|
|
24
24
|
msecs?: number;
|
|
25
25
|
}
|
|
26
|
+
export interface PhantasmaAPIOptions {
|
|
27
|
+
maxRpcResponseBytes?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare const DEFAULT_MAX_RPC_RESPONSE_BYTES: number;
|
|
26
30
|
export declare class PhantasmaAPI {
|
|
27
31
|
host: string;
|
|
28
32
|
rpcName: string;
|
|
29
33
|
nexus: string;
|
|
30
34
|
availableHosts: RpcPeer[];
|
|
35
|
+
maxRpcResponseBytes: number;
|
|
36
|
+
private nextRpcRequestId;
|
|
37
|
+
private nextJsonRpcRequestId;
|
|
31
38
|
pingAsync(host: string): Promise<number>;
|
|
32
|
-
constructor(defHost: string, peersUrlJson: string | undefined | null, nexus: string);
|
|
39
|
+
constructor(defHost: string, peersUrlJson: string | undefined | null, nexus: string, options?: PhantasmaAPIOptions);
|
|
33
40
|
JSONRPCResult<T = unknown>(method: string, params: JsonRpcParam[]): Promise<RpcResult<T>>;
|
|
34
41
|
JSONRPC(method: string, params: JsonRpcParam[]): Promise<unknown>;
|
|
42
|
+
setMaxRpcResponseBytes(maxBytes: number): this;
|
|
35
43
|
setRpcHost(rpcHost: string): void;
|
|
36
44
|
setRpcByName(rpcName: string): void;
|
|
37
45
|
setNexus(nexus: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phantasma.d.ts","sourceRoot":"","sources":["../../../src/rpc/phantasma.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,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ACrB,MAAM,GAAE,MAAW,EACnB,wBAAwB,GAAE,OAAc,GACvC,OAAO,CAAC,qBAAqB,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAehD,gBAAgB,CAAC,kBAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM7E,WAAW,CACf,kBAAkB,EAAE,MAAM,EAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;IAM1B,UAAU,CAAC,kBAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOxF,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAO9C,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM1F,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAc,GAAG,OAAO,CAAC,GAAG,CAAC;IAK7E,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,QAAQ,GAAE,OAAc,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAKnF,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;IAItC,oBAAoB,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAInF"}
|
|
@@ -49,7 +49,9 @@ export declare class CarbonBinaryReader {
|
|
|
49
49
|
private readonly view;
|
|
50
50
|
private readonly bytes;
|
|
51
51
|
constructor(buffer: ArrayBuffer | Uint8Array);
|
|
52
|
+
private remaining;
|
|
52
53
|
private take;
|
|
54
|
+
private readLength;
|
|
53
55
|
readRemaining(): Uint8Array;
|
|
54
56
|
read1(): number;
|
|
55
57
|
read2(): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"carbon-serialization.d.ts","sourceRoot":"","sources":["../../../src/types/carbon-serialization.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAK9C,qBAAa,KAAK;IAChB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAK3C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,SAAqB,GAAG,IAAI;CAK7D;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,IAAI,CAAK;IAEjB,OAAO,CAAC,IAAI;IAKZ,YAAY,IAAI,UAAU;IAW1B,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAG7B,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAKvB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAKvB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAKvB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAKxB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAMvB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAQxB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAInD,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,GAAG,IAAI;IAIzC,OAAO,CAAC,IA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