@leofcoin/chain 1.8.23 → 1.8.24

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.
@@ -6314,24 +6314,11 @@ class Chain extends VersionControl {
6314
6314
  const node = await this.#prepareRequest(request);
6315
6315
  try {
6316
6316
  let response = await peer.request(node.encoded);
6317
- console.log({ rawResponse: response });
6318
- console.log('raw response received, decoding...');
6319
- console.log({ responseBytes: response });
6320
6317
  response = await new globalThis.peernet.protos['peernet-response'](response);
6321
- let responseData = response.decoded.response;
6322
- console.log(`response decoded:`, responseData);
6323
- if (typeof responseData === 'string') {
6324
- console.warn(`Deprecated: ${request} response is a string, attempting to parse as JSON...`);
6325
- try {
6326
- responseData = JSON.parse(responseData);
6327
- }
6328
- catch { }
6318
+ if (!(response.decoded.response instanceof Uint8Array)) {
6319
+ console.warn(`Deprecated: ${response.decoded.response} is not an Uint8Array`);
6329
6320
  }
6330
- if (!(responseData instanceof Uint8Array)) {
6331
- console.warn(`Deprecated: ${request} response is not a Uint8Array and will be ignored.`);
6332
- return responseData;
6333
- }
6334
- return responseData;
6321
+ return response.decoded.response;
6335
6322
  }
6336
6323
  catch (error) {
6337
6324
  const peerId = peer?.peerId || peer?.id || peer?.address || 'unknown';
@@ -6340,7 +6327,18 @@ class Chain extends VersionControl {
6340
6327
  }
6341
6328
  }
6342
6329
  async getPeerTransactionPool(peer) {
6343
- const transactionsInPool = await this.#makeRequest(peer, 'transactionPool');
6330
+ let transactionsInPool = await this.#makeRequest(peer, 'transactionPool');
6331
+ if (transactionsInPool instanceof Uint8Array) {
6332
+ try {
6333
+ const text = new TextDecoder().decode(transactionsInPool);
6334
+ transactionsInPool = JSON.parse(text);
6335
+ }
6336
+ catch (e) {
6337
+ return [];
6338
+ }
6339
+ }
6340
+ if (!Array.isArray(transactionsInPool))
6341
+ return [];
6344
6342
  // todo iterate vs getting all keys?
6345
6343
  const transactions = await globalThis.transactionPoolStore.keys();
6346
6344
  const transactionsToGet = [];
package/exports/chain.js CHANGED
@@ -2455,24 +2455,11 @@ class Chain extends VersionControl {
2455
2455
  const node = await this.#prepareRequest(request);
2456
2456
  try {
2457
2457
  let response = await peer.request(node.encoded);
2458
- console.log({ rawResponse: response });
2459
- console.log('raw response received, decoding...');
2460
- console.log({ responseBytes: response });
2461
2458
  response = await new globalThis.peernet.protos['peernet-response'](response);
2462
- let responseData = response.decoded.response;
2463
- console.log(`response decoded:`, responseData);
2464
- if (typeof responseData === 'string') {
2465
- console.warn(`Deprecated: ${request} response is a string, attempting to parse as JSON...`);
2466
- try {
2467
- responseData = JSON.parse(responseData);
2468
- }
2469
- catch { }
2459
+ if (!(response.decoded.response instanceof Uint8Array)) {
2460
+ console.warn(`Deprecated: ${response.decoded.response} is not an Uint8Array`);
2470
2461
  }
2471
- if (!(responseData instanceof Uint8Array)) {
2472
- console.warn(`Deprecated: ${request} response is not a Uint8Array and will be ignored.`);
2473
- return responseData;
2474
- }
2475
- return responseData;
2462
+ return response.decoded.response;
2476
2463
  }
2477
2464
  catch (error) {
2478
2465
  const peerId = peer?.peerId || peer?.id || peer?.address || 'unknown';
@@ -2481,7 +2468,18 @@ class Chain extends VersionControl {
2481
2468
  }
2482
2469
  }
2483
2470
  async getPeerTransactionPool(peer) {
2484
- const transactionsInPool = await this.#makeRequest(peer, 'transactionPool');
2471
+ let transactionsInPool = await this.#makeRequest(peer, 'transactionPool');
2472
+ if (transactionsInPool instanceof Uint8Array) {
2473
+ try {
2474
+ const text = new TextDecoder().decode(transactionsInPool);
2475
+ transactionsInPool = JSON.parse(text);
2476
+ }
2477
+ catch (e) {
2478
+ return [];
2479
+ }
2480
+ }
2481
+ if (!Array.isArray(transactionsInPool))
2482
+ return [];
2485
2483
  // todo iterate vs getting all keys?
2486
2484
  const transactions = await globalThis.transactionPoolStore.keys();
2487
2485
  const transactionsToGet = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.8.23",
3
+ "version": "1.8.24",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {