@leofcoin/chain 1.9.14 → 1.9.16

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.
@@ -1,4 +1,6 @@
1
- import { j as getDefaultExportFromCjs } from './identity-B8_RBemH-Dq17MYzU.js';
1
+ import { g as getDefaultExportFromCjs } from './node-browser-y2adT6_R.js';
2
+ import 'crypto';
3
+ import './constants-V2VjIc2r.js';
2
4
 
3
5
  function _mergeNamespaces$1(n, m) {
4
6
  m.forEach(function (e) {
@@ -1,4 +1,6 @@
1
- import { j as getDefaultExportFromCjs } from './identity-B8_RBemH-Dq17MYzU.js';
1
+ import { g as getDefaultExportFromCjs } from './node-browser-y2adT6_R.js';
2
+ import 'crypto';
3
+ import './constants-V2VjIc2r.js';
2
4
 
3
5
  function _mergeNamespaces$1(n, m) {
4
6
  m.forEach(function (e) {
@@ -6309,9 +6309,11 @@ class Chain extends VersionControl {
6309
6309
  });
6310
6310
  await globalThis.peernet.addRequestHandler("transactionPool", this.#transactionPoolHandler.bind(this));
6311
6311
  await globalThis.peernet.addRequestHandler("version", this.#versionHandler.bind(this));
6312
- await globalThis.peernet.addRequestHandler("stateInfo", () => {
6312
+ await globalThis.peernet.addRequestHandler("stateInfo", async () => {
6313
+ const lastblock = await this.lastBlock || { index: 0, hash: "0x0", previousHash: "0x0" };
6314
+ const values = this.machine?.states?.info || {};
6313
6315
  return new globalThis.peernet.protos["peernet-response"]({
6314
- response: new StateMessage(this.machine.states.info).encoded
6316
+ response: new StateMessage({ lastblock, values }).encoded
6315
6317
  });
6316
6318
  });
6317
6319
  globalThis.peernet.subscribe("add-block", this.#addBlock.bind(this));
@@ -6363,10 +6365,27 @@ class Chain extends VersionControl {
6363
6365
  try {
6364
6366
  let response = await peer.request(node.encoded);
6365
6367
  response = await new globalThis.peernet.protos["peernet-response"](response);
6366
- if (!(response.decoded.response instanceof Uint8Array)) {
6367
- console.warn(`Deprecated: ${response.decoded.response} is not an Uint8Array`);
6368
- }
6369
- return response.decoded.response;
6368
+ const decodeResponse = async (payload) => {
6369
+ if (!(payload instanceof Uint8Array)) return payload;
6370
+ for (let i = 0; i < 3; i++) {
6371
+ try {
6372
+ const nested = await new globalThis.peernet.protos["peernet-response"](payload);
6373
+ payload = nested?.decoded?.response;
6374
+ if (!(payload instanceof Uint8Array)) break;
6375
+ } catch {
6376
+ break;
6377
+ }
6378
+ }
6379
+ if (payload instanceof Uint8Array) {
6380
+ try {
6381
+ return JSON.parse(new TextDecoder().decode(payload));
6382
+ } catch {
6383
+ return payload;
6384
+ }
6385
+ }
6386
+ return payload;
6387
+ };
6388
+ return await decodeResponse(response.decoded.response);
6370
6389
  } catch (error) {
6371
6390
  const peerId = peer?.peerId || peer?.id || peer?.address || "unknown";
6372
6391
  debug(`peernet request failed: ${request} -> ${peerId}:`, error?.message ?? error);
@@ -6553,7 +6572,8 @@ class Chain extends VersionControl {
6553
6572
  try {
6554
6573
  let stateInfo = await this.#makeRequest(peer, "stateInfo");
6555
6574
  if (stateInfo instanceof Uint8Array) {
6556
- stateInfo = new StateMessage(stateInfo).decoded;
6575
+ const decodedStateInfo = new StateMessage(stateInfo).decoded;
6576
+ stateInfo = decodedStateInfo?.values ?? decodedStateInfo;
6557
6577
  }
6558
6578
  debug(
6559
6579
  `sync start with peer ${peerId}: local=${localBlock?.index ?? -1} remote=${lastBlock?.index ?? -1} hash=${lastBlock?.hash}`