@leofcoin/chain 1.8.19 → 1.8.21

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.
@@ -3955,8 +3955,8 @@ class Transaction extends Protocol {
3955
3955
  try {
3956
3956
  let data;
3957
3957
  const wait = new Promise(async (resolve, reject) => {
3958
- if (pubsub.subscribers[`transaction.completed.${hash}`]) {
3959
- const result = pubsub.subscribers[`transaction.completed.${hash}`].value;
3958
+ if (pubsub.hasSubscribers(`transaction.completed.${hash}`)) {
3959
+ const result = pubsub.getValue(`transaction.completed.${hash}`);
3960
3960
  if (result.status !== 'fulfilled') {
3961
3961
  await transactionPoolStore.delete(hash);
3962
3962
  }
@@ -5507,7 +5507,7 @@ class State extends Contract {
5507
5507
  if (peer.connected && peer.version === this.version) {
5508
5508
  const task = async () => {
5509
5509
  try {
5510
- const result = await peer.request(node.encode());
5510
+ const result = await peer.request(node.encoded);
5511
5511
  debug$1({ result });
5512
5512
  return { result: Uint8Array.from(Object.values(result)), peer };
5513
5513
  }
@@ -5521,6 +5521,7 @@ class State extends Contract {
5521
5521
  }
5522
5522
  }
5523
5523
  // @ts-ignore
5524
+ console.log({ promises });
5524
5525
  promises = await this.promiseRequests(promises);
5525
5526
  console.log({ promises });
5526
5527
  let latest = { index: 0, hash: '0x0', previousHash: '0x0' };
@@ -5653,7 +5654,9 @@ class State extends Contract {
5653
5654
  resolve([{ index: 0, hash: '0x0' }]);
5654
5655
  debug$1('sync timed out');
5655
5656
  }, this.requestTimeout);
5656
- promises = await Promise.allSettled(promises);
5657
+ console.log({ promises });
5658
+ promises = await Promise.any(promises);
5659
+ console.log({ promises });
5657
5660
  promises = promises.filter(({ status }) => status === 'fulfilled');
5658
5661
  clearTimeout(timeout);
5659
5662
  if (promises.length > 0) {
@@ -6364,7 +6367,10 @@ class Chain extends VersionControl {
6364
6367
  }
6365
6368
  let lastBlock;
6366
6369
  try {
6367
- lastBlock = new LastBlockMessage(await this.#makeRequest(peer, 'lastBlock')).encoded;
6370
+ console.log('requesting last block from peer...');
6371
+ console.log(await this.lastBlock);
6372
+ console.log(new LastBlockMessage(await this.#makeRequest(peer, 'lastBlock')));
6373
+ lastBlock = new LastBlockMessage(await this.#makeRequest(peer, 'lastBlock')).decoded;
6368
6374
  }
6369
6375
  catch (error) {
6370
6376
  const peerName = peer?.peerId || peer?.id || peer?.address || peerId || 'unknown';
@@ -1,5 +1,5 @@
1
1
  import Peernet from '@leofcoin/peernet/browser';
2
- import { F as FormatInterface, T as TransactionMessage, C as ContractMessage, B as BlockMessage, b as BWMessage, c as BWRequestMessage, V as ValidatorMessage, D as DEFAULT_NODE_OPTIONS } from './constants-BKKQytjd.js';
2
+ import { F as FormatInterface, T as TransactionMessage, C as ContractMessage, B as BlockMessage, b as BWMessage, c as BWRequestMessage, V as ValidatorMessage, L as LastBlockMessage, D as DEFAULT_NODE_OPTIONS } from './constants-BKKQytjd.js';
3
3
 
4
4
  var proto = {
5
5
  lastblock: Object(),
@@ -29,7 +29,8 @@ var nodeConfig = async (config = {
29
29
  { name: 'bw-message', handler: BWMessage },
30
30
  { name: 'bw-request-message', handler: BWRequestMessage },
31
31
  { name: 'validator-message', handler: ValidatorMessage },
32
- { name: 'state-message', handler: StateMessage }
32
+ { name: 'state-message', handler: StateMessage },
33
+ { name: 'last-block', handler: LastBlockMessage }
33
34
  ];
34
35
  for (const proto of protos) {
35
36
  peernet.addProto(proto.name, proto.handler);
package/exports/chain.js CHANGED
@@ -197,8 +197,8 @@ class Transaction extends Protocol {
197
197
  try {
198
198
  let data;
199
199
  const wait = new Promise(async (resolve, reject) => {
200
- if (pubsub.subscribers[`transaction.completed.${hash}`]) {
201
- const result = pubsub.subscribers[`transaction.completed.${hash}`].value;
200
+ if (pubsub.hasSubscribers(`transaction.completed.${hash}`)) {
201
+ const result = pubsub.getValue(`transaction.completed.${hash}`);
202
202
  if (result.status !== 'fulfilled') {
203
203
  await transactionPoolStore.delete(hash);
204
204
  }
@@ -1648,7 +1648,7 @@ class State extends Contract {
1648
1648
  if (peer.connected && peer.version === this.version) {
1649
1649
  const task = async () => {
1650
1650
  try {
1651
- const result = await peer.request(node.encode());
1651
+ const result = await peer.request(node.encoded);
1652
1652
  debug$1({ result });
1653
1653
  return { result: Uint8Array.from(Object.values(result)), peer };
1654
1654
  }
@@ -1662,6 +1662,7 @@ class State extends Contract {
1662
1662
  }
1663
1663
  }
1664
1664
  // @ts-ignore
1665
+ console.log({ promises });
1665
1666
  promises = await this.promiseRequests(promises);
1666
1667
  console.log({ promises });
1667
1668
  let latest = { index: 0, hash: '0x0', previousHash: '0x0' };
@@ -1794,7 +1795,9 @@ class State extends Contract {
1794
1795
  resolve([{ index: 0, hash: '0x0' }]);
1795
1796
  debug$1('sync timed out');
1796
1797
  }, this.requestTimeout);
1797
- promises = await Promise.allSettled(promises);
1798
+ console.log({ promises });
1799
+ promises = await Promise.any(promises);
1800
+ console.log({ promises });
1798
1801
  promises = promises.filter(({ status }) => status === 'fulfilled');
1799
1802
  clearTimeout(timeout);
1800
1803
  if (promises.length > 0) {
@@ -2505,7 +2508,10 @@ class Chain extends VersionControl {
2505
2508
  }
2506
2509
  let lastBlock;
2507
2510
  try {
2508
- lastBlock = new LastBlockMessage(await this.#makeRequest(peer, 'lastBlock')).encoded;
2511
+ console.log('requesting last block from peer...');
2512
+ console.log(await this.lastBlock);
2513
+ console.log(new LastBlockMessage(await this.#makeRequest(peer, 'lastBlock')));
2514
+ lastBlock = new LastBlockMessage(await this.#makeRequest(peer, 'lastBlock')).decoded;
2509
2515
  }
2510
2516
  catch (error) {
2511
2517
  const peerName = peer?.peerId || peer?.id || peer?.address || peerId || 'unknown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.8.19",
3
+ "version": "1.8.21",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {
@@ -65,11 +65,11 @@
65
65
  "@leofcoin/contracts": "^0.1.16",
66
66
  "@leofcoin/crypto": "^0.2.37",
67
67
  "@leofcoin/errors": "^1.0.25",
68
- "@leofcoin/lib": "^1.2.72",
68
+ "@leofcoin/lib": "^1.2.73",
69
69
  "@leofcoin/messages": "^1.4.40",
70
70
  "@leofcoin/multi-wallet": "^3.1.8",
71
71
  "@leofcoin/networks": "^1.1.25",
72
- "@leofcoin/peernet": "^1.2.14",
72
+ "@leofcoin/peernet": "^1.2.15",
73
73
  "@leofcoin/storage": "^3.5.38",
74
74
  "@leofcoin/utils": "^1.1.40",
75
75
  "@leofcoin/workers": "^1.5.27",