@leofcoin/chain 1.4.87 → 1.4.89

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.
@@ -1895,6 +1895,9 @@ class State extends Contract {
1895
1895
  #totalSize = 0;
1896
1896
  #machine;
1897
1897
  #loaded = false;
1898
+ get blockHashMap() {
1899
+ return this.#blockHashMap.entries();
1900
+ }
1898
1901
  get loaded() {
1899
1902
  return this.#loaded;
1900
1903
  }
@@ -2156,10 +2159,10 @@ class State extends Contract {
2156
2159
  if (!this.#lastBlock || Number(this.#lastBlock.index) < Number(lastBlock.index)) {
2157
2160
  // TODO: check if valid
2158
2161
  const localIndex = this.#lastBlock ? this.lastBlock.index : 0;
2159
- const index = lastBlock.index - 1;
2162
+ const index = lastBlock.index;
2160
2163
  await this.resolveBlock(lastBlock.hash);
2161
2164
  console.log('ok');
2162
- let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index - localIndex) : index;
2165
+ let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index + -localIndex) : index;
2163
2166
  globalThis.debug(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
2164
2167
  const start = (this.#blocks.length - blocksSynced);
2165
2168
  if (this.#machine)
package/exports/chain.js CHANGED
@@ -515,6 +515,9 @@ class State extends Contract {
515
515
  #totalSize = 0;
516
516
  #machine;
517
517
  #loaded = false;
518
+ get blockHashMap() {
519
+ return this.#blockHashMap.entries();
520
+ }
518
521
  get loaded() {
519
522
  return this.#loaded;
520
523
  }
@@ -776,10 +779,10 @@ class State extends Contract {
776
779
  if (!this.#lastBlock || Number(this.#lastBlock.index) < Number(lastBlock.index)) {
777
780
  // TODO: check if valid
778
781
  const localIndex = this.#lastBlock ? this.lastBlock.index : 0;
779
- const index = lastBlock.index - 1;
782
+ const index = lastBlock.index;
780
783
  await this.resolveBlock(lastBlock.hash);
781
784
  console.log('ok');
782
- let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index - localIndex) : index;
785
+ let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index + -localIndex) : index;
783
786
  globalThis.debug(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
784
787
  const start = (this.#blocks.length - blocksSynced);
785
788
  if (this.#machine)
@@ -0,0 +1,38 @@
1
+ import { BlockMessage } from '@leofcoin/messages';
2
+ import Contract from './contract.js';
3
+ import Machine from './machine.js';
4
+ import { BlockHash } from './types.js';
5
+ declare type SyncState = 'syncing' | 'synced' | 'errored' | 'connectionless';
6
+ export default class State extends Contract {
7
+ #private;
8
+ knownBlocks: BlockHash[];
9
+ get blockHashMap(): IterableIterator<[any, any]>;
10
+ get loaded(): boolean;
11
+ get resolving(): boolean;
12
+ get nativeMints(): number;
13
+ get nativeBurns(): number;
14
+ get nativeTransfers(): number;
15
+ get totalTransactions(): number;
16
+ get nativeCalls(): number;
17
+ get blocks(): any[];
18
+ get lastBlock(): {
19
+ index: number;
20
+ hash: string;
21
+ previousHash: string;
22
+ };
23
+ get totalSize(): number;
24
+ get machine(): Machine;
25
+ constructor();
26
+ init(): Promise<void>;
27
+ updateState(message: any): Promise<void>;
28
+ getLatestBlock(): Promise<BlockMessage.decoded>;
29
+ getAndPutBlock(hash: string): BlockMessage;
30
+ resolveBlock(hash: any): any;
31
+ resolveBlocks(): Promise<void>;
32
+ syncChain(lastBlock?: any): Promise<SyncState>;
33
+ promiseRequests(promises: any): Promise<unknown>;
34
+ get canSync(): boolean;
35
+ get shouldSync(): boolean;
36
+ triggerSync(): Promise<SyncState>;
37
+ }
38
+ export {};
@@ -1 +1,2 @@
1
- export type Address = string;
1
+ export type Address = base58String;
2
+ export type BlockHash = base58String;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.87",
3
+ "version": "1.4.89",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",