@leofcoin/chain 1.9.16 → 1.9.17
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/exports/browser/chain.js +26 -12
- package/exports/chain.js +26 -12
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -6365,27 +6365,41 @@ class Chain extends VersionControl {
|
|
|
6365
6365
|
try {
|
|
6366
6366
|
let response = await peer.request(node.encoded);
|
|
6367
6367
|
response = await new globalThis.peernet.protos["peernet-response"](response);
|
|
6368
|
-
const
|
|
6369
|
-
if (
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6368
|
+
const normalizeResponse = async (payload) => {
|
|
6369
|
+
if (payload && typeof payload === "object" && "response" in payload) {
|
|
6370
|
+
return normalizeResponse(payload.response);
|
|
6371
|
+
}
|
|
6372
|
+
if (payload instanceof Uint8Array || typeof Buffer !== "undefined" && Buffer.isBuffer(payload)) {
|
|
6373
|
+
let bytes = payload;
|
|
6374
|
+
for (let i = 0; i < 3; i++) {
|
|
6375
|
+
try {
|
|
6376
|
+
const nested = await new globalThis.peernet.protos["peernet-response"](bytes);
|
|
6377
|
+
payload = nested?.decoded?.response;
|
|
6378
|
+
if (!(payload instanceof Uint8Array)) break;
|
|
6379
|
+
bytes = payload;
|
|
6380
|
+
} catch {
|
|
6381
|
+
break;
|
|
6382
|
+
}
|
|
6383
|
+
}
|
|
6384
|
+
if (payload instanceof Uint8Array) {
|
|
6385
|
+
try {
|
|
6386
|
+
return JSON.parse(new TextDecoder().decode(payload));
|
|
6387
|
+
} catch {
|
|
6388
|
+
return payload;
|
|
6389
|
+
}
|
|
6377
6390
|
}
|
|
6391
|
+
return payload;
|
|
6378
6392
|
}
|
|
6379
|
-
if (payload
|
|
6393
|
+
if (typeof payload === "string") {
|
|
6380
6394
|
try {
|
|
6381
|
-
return JSON.parse(
|
|
6395
|
+
return JSON.parse(payload);
|
|
6382
6396
|
} catch {
|
|
6383
6397
|
return payload;
|
|
6384
6398
|
}
|
|
6385
6399
|
}
|
|
6386
6400
|
return payload;
|
|
6387
6401
|
};
|
|
6388
|
-
return await
|
|
6402
|
+
return await normalizeResponse(response.decoded.response);
|
|
6389
6403
|
} catch (error) {
|
|
6390
6404
|
const peerId = peer?.peerId || peer?.id || peer?.address || "unknown";
|
|
6391
6405
|
debug(`peernet request failed: ${request} -> ${peerId}:`, error?.message ?? error);
|
package/exports/chain.js
CHANGED
|
@@ -2588,27 +2588,41 @@ class Chain extends VersionControl {
|
|
|
2588
2588
|
try {
|
|
2589
2589
|
let response = await peer.request(node.encoded);
|
|
2590
2590
|
response = await new globalThis.peernet.protos["peernet-response"](response);
|
|
2591
|
-
const
|
|
2592
|
-
if (
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2591
|
+
const normalizeResponse = async (payload) => {
|
|
2592
|
+
if (payload && typeof payload === "object" && "response" in payload) {
|
|
2593
|
+
return normalizeResponse(payload.response);
|
|
2594
|
+
}
|
|
2595
|
+
if (payload instanceof Uint8Array || typeof Buffer !== "undefined" && Buffer.isBuffer(payload)) {
|
|
2596
|
+
let bytes = payload;
|
|
2597
|
+
for (let i = 0; i < 3; i++) {
|
|
2598
|
+
try {
|
|
2599
|
+
const nested = await new globalThis.peernet.protos["peernet-response"](bytes);
|
|
2600
|
+
payload = nested?.decoded?.response;
|
|
2601
|
+
if (!(payload instanceof Uint8Array)) break;
|
|
2602
|
+
bytes = payload;
|
|
2603
|
+
} catch {
|
|
2604
|
+
break;
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
if (payload instanceof Uint8Array) {
|
|
2608
|
+
try {
|
|
2609
|
+
return JSON.parse(new TextDecoder().decode(payload));
|
|
2610
|
+
} catch {
|
|
2611
|
+
return payload;
|
|
2612
|
+
}
|
|
2600
2613
|
}
|
|
2614
|
+
return payload;
|
|
2601
2615
|
}
|
|
2602
|
-
if (payload
|
|
2616
|
+
if (typeof payload === "string") {
|
|
2603
2617
|
try {
|
|
2604
|
-
return JSON.parse(
|
|
2618
|
+
return JSON.parse(payload);
|
|
2605
2619
|
} catch {
|
|
2606
2620
|
return payload;
|
|
2607
2621
|
}
|
|
2608
2622
|
}
|
|
2609
2623
|
return payload;
|
|
2610
2624
|
};
|
|
2611
|
-
return await
|
|
2625
|
+
return await normalizeResponse(response.decoded.response);
|
|
2612
2626
|
} catch (error) {
|
|
2613
2627
|
const peerId = peer?.peerId || peer?.id || peer?.address || "unknown";
|
|
2614
2628
|
debug(`peernet request failed: ${request} -> ${peerId}:`, error?.message ?? error);
|