@apibara/protocol 2.1.0-beta.52 → 2.1.0-beta.54

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/dist/index.cjs CHANGED
@@ -6,7 +6,7 @@ const assert = require('node:assert');
6
6
  const consola = require('consola');
7
7
  const niceGrpc = require('nice-grpc');
8
8
  require('protobufjs/minimal.js');
9
- const rpc_index = require('./shared/protocol.54f17699.cjs');
9
+ const rpc_index = require('./shared/protocol.a44ea889.cjs');
10
10
  require('viem');
11
11
  require('long');
12
12
 
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { s as stream } from './shared/protocol.0e734e33.cjs';
2
2
  export { B as Bytes, b as BytesFromUint8Array, w as Client, u as ClientCallOptions, x as CreateClientOptions, C as Cursor, e as CursorFromBytes, c as CursorProto, q as Data, g as DataFinality, h as DataProduction, D as DnaStreamClient, a as DnaStreamDefinition, k as Duration, j as DurationCodec, F as Finalize, G as GrpcClient, H as Heartbeat, I as Invalidate, R as ResponseWithoutData, S as StatusRequest, f as StatusResponse, o as StdErr, m as StdOut, t as StreamConfig, A as StreamDataIterable, v as StreamDataOptions, l as StreamDataRequest, r as StreamDataResponse, p as SystemMessage, T as TimeoutError, z as createAuthenticatedClient, y as createClient, d as createCursor, i as isCursor, n as normalizeCursor } from './shared/protocol.0e734e33.cjs';
3
3
  import _m0 from 'protobufjs/minimal.js';
4
- export { i as rpc } from './shared/protocol.7aa4aab6.cjs';
4
+ export { i as rpc } from './shared/protocol.5dc2fc0d.cjs';
5
5
  export { ClientError, Metadata, ServerError, Status } from 'nice-grpc';
6
6
  import './codec.cjs';
7
7
  import 'nice-grpc-common';
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { s as stream } from './shared/protocol.21e66b9e.mjs';
2
2
  export { B as Bytes, b as BytesFromUint8Array, w as Client, u as ClientCallOptions, x as CreateClientOptions, C as Cursor, e as CursorFromBytes, c as CursorProto, q as Data, g as DataFinality, h as DataProduction, D as DnaStreamClient, a as DnaStreamDefinition, k as Duration, j as DurationCodec, F as Finalize, G as GrpcClient, H as Heartbeat, I as Invalidate, R as ResponseWithoutData, S as StatusRequest, f as StatusResponse, o as StdErr, m as StdOut, t as StreamConfig, A as StreamDataIterable, v as StreamDataOptions, l as StreamDataRequest, r as StreamDataResponse, p as SystemMessage, T as TimeoutError, z as createAuthenticatedClient, y as createClient, d as createCursor, i as isCursor, n as normalizeCursor } from './shared/protocol.21e66b9e.mjs';
3
3
  import _m0 from 'protobufjs/minimal.js';
4
- export { i as rpc } from './shared/protocol.6ab8d6dd.mjs';
4
+ export { i as rpc } from './shared/protocol.1a69a01d.mjs';
5
5
  export { ClientError, Metadata, ServerError, Status } from 'nice-grpc';
6
6
  import './codec.mjs';
7
7
  import 'nice-grpc-common';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { s as stream } from './shared/protocol.8fb09325.js';
2
2
  export { B as Bytes, b as BytesFromUint8Array, w as Client, u as ClientCallOptions, x as CreateClientOptions, C as Cursor, e as CursorFromBytes, c as CursorProto, q as Data, g as DataFinality, h as DataProduction, D as DnaStreamClient, a as DnaStreamDefinition, k as Duration, j as DurationCodec, F as Finalize, G as GrpcClient, H as Heartbeat, I as Invalidate, R as ResponseWithoutData, S as StatusRequest, f as StatusResponse, o as StdErr, m as StdOut, t as StreamConfig, A as StreamDataIterable, v as StreamDataOptions, l as StreamDataRequest, r as StreamDataResponse, p as SystemMessage, T as TimeoutError, z as createAuthenticatedClient, y as createClient, d as createCursor, i as isCursor, n as normalizeCursor } from './shared/protocol.8fb09325.js';
3
3
  import _m0 from 'protobufjs/minimal.js';
4
- export { i as rpc } from './shared/protocol.8407f25e.js';
4
+ export { i as rpc } from './shared/protocol.1b2e5598.js';
5
5
  export { ClientError, Metadata, ServerError, Status } from 'nice-grpc';
6
6
  import './codec.js';
7
7
  import 'nice-grpc-common';
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ import consola from 'consola';
6
6
  import { createChannel, createClient as createClient$1, Metadata } from 'nice-grpc';
7
7
  export { ClientError, Metadata, ServerError, Status } from 'nice-grpc';
8
8
  import 'protobufjs/minimal.js';
9
- export { i as rpc } from './shared/protocol.bde61588.mjs';
9
+ export { i as rpc } from './shared/protocol.e329df99.mjs';
10
10
  import 'viem';
11
11
  import 'long';
12
12
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const rpc_index = require('../shared/protocol.54f17699.cjs');
3
+ const rpc_index = require('../shared/protocol.a44ea889.cjs');
4
4
  require('viem');
5
5
 
6
6
 
@@ -1,4 +1,4 @@
1
- export { B as BlockInfo, c as FetchBlockByNumberArgs, d as FetchBlockByNumberResult, F as FetchBlockRangeArgs, b as FetchBlockRangeResult, a as FetchBlockResult, e as FetchCursorArgs, f as RpcClient, h as RpcDataStream, R as RpcStreamConfig, V as ValidateFilterResult, g as createRpcClient } from '../shared/protocol.7aa4aab6.cjs';
1
+ export { B as BlockInfo, c as FetchBlockByHashArgs, d as FetchBlockByHashResult, F as FetchBlockRangeArgs, b as FetchBlockRangeResult, a as FetchBlockResult, e as FetchCursorArgs, f as FetchCursorRangeArgs, g as RpcClient, j as RpcDataStream, R as RpcStreamConfig, V as ValidateFilterResult, h as createRpcClient } from '../shared/protocol.5dc2fc0d.cjs';
2
2
  import '../shared/protocol.0e734e33.cjs';
3
3
  import '../codec.cjs';
4
4
  import 'nice-grpc-common';
@@ -1,4 +1,4 @@
1
- export { B as BlockInfo, c as FetchBlockByNumberArgs, d as FetchBlockByNumberResult, F as FetchBlockRangeArgs, b as FetchBlockRangeResult, a as FetchBlockResult, e as FetchCursorArgs, f as RpcClient, h as RpcDataStream, R as RpcStreamConfig, V as ValidateFilterResult, g as createRpcClient } from '../shared/protocol.6ab8d6dd.mjs';
1
+ export { B as BlockInfo, c as FetchBlockByHashArgs, d as FetchBlockByHashResult, F as FetchBlockRangeArgs, b as FetchBlockRangeResult, a as FetchBlockResult, e as FetchCursorArgs, f as FetchCursorRangeArgs, g as RpcClient, j as RpcDataStream, R as RpcStreamConfig, V as ValidateFilterResult, h as createRpcClient } from '../shared/protocol.1a69a01d.mjs';
2
2
  import '../shared/protocol.21e66b9e.mjs';
3
3
  import '../codec.mjs';
4
4
  import 'nice-grpc-common';
@@ -1,4 +1,4 @@
1
- export { B as BlockInfo, c as FetchBlockByNumberArgs, d as FetchBlockByNumberResult, F as FetchBlockRangeArgs, b as FetchBlockRangeResult, a as FetchBlockResult, e as FetchCursorArgs, f as RpcClient, h as RpcDataStream, R as RpcStreamConfig, V as ValidateFilterResult, g as createRpcClient } from '../shared/protocol.8407f25e.js';
1
+ export { B as BlockInfo, c as FetchBlockByHashArgs, d as FetchBlockByHashResult, F as FetchBlockRangeArgs, b as FetchBlockRangeResult, a as FetchBlockResult, e as FetchCursorArgs, f as FetchCursorRangeArgs, g as RpcClient, j as RpcDataStream, R as RpcStreamConfig, V as ValidateFilterResult, h as createRpcClient } from '../shared/protocol.1b2e5598.js';
2
2
  import '../shared/protocol.8fb09325.js';
3
3
  import '../codec.js';
4
4
  import 'nice-grpc-common';
@@ -1,3 +1,3 @@
1
- export { a as RpcClient, b as RpcDataStream, R as RpcStreamConfig, c as createRpcClient } from '../shared/protocol.bde61588.mjs';
1
+ export { a as RpcClient, b as RpcDataStream, R as RpcStreamConfig, c as createRpcClient } from '../shared/protocol.e329df99.mjs';
2
2
  import 'viem';
3
3
  //# sourceMappingURL=index.mjs.map
@@ -2,7 +2,7 @@ import { C as Cursor, B as Bytes, w as Client, S as StatusRequest, u as ClientCa
2
2
 
3
3
  type FetchBlockRangeArgs<TFilter> = {
4
4
  startBlock: bigint;
5
- finalizedBlock: bigint;
5
+ maxBlock: bigint;
6
6
  force: boolean;
7
7
  filter: TFilter;
8
8
  };
@@ -21,19 +21,18 @@ type BlockInfo = {
21
21
  blockHash: Bytes;
22
22
  parentBlockHash: Bytes;
23
23
  };
24
- type FetchBlockByNumberArgs<TFilter> = {
25
- blockNumber: bigint;
26
- expectedParentBlockHash: Bytes;
24
+ type FetchBlockByHashArgs<TFilter> = {
25
+ blockHash: Bytes;
27
26
  isAtHead: boolean;
28
27
  filter: TFilter;
29
28
  };
30
- type FetchBlockByNumberResult<TBlock> = {
31
- status: "success";
29
+ type FetchBlockByHashResult<TBlock> = {
32
30
  data: FetchBlockResult<TBlock>;
33
31
  blockInfo: BlockInfo;
34
- } | {
35
- status: "reorg";
36
- blockInfo: BlockInfo;
32
+ };
33
+ type FetchCursorRangeArgs = {
34
+ startBlockNumber: bigint;
35
+ endBlockNumber: bigint;
37
36
  };
38
37
  type FetchCursorArgs = {
39
38
  blockTag: "latest" | "finalized";
@@ -58,10 +57,11 @@ type ValidateFilterResult = {
58
57
  declare abstract class RpcStreamConfig<TFilter, TBlock> {
59
58
  abstract headRefreshIntervalMs(): number;
60
59
  abstract finalizedRefreshIntervalMs(): number;
60
+ abstract fetchCursorRange(args: FetchCursorRangeArgs): Promise<BlockInfo[]>;
61
61
  abstract fetchCursor(args: FetchCursorArgs): Promise<BlockInfo | null>;
62
62
  abstract validateFilter(filter: TFilter): ValidateFilterResult;
63
63
  abstract fetchBlockRange(args: FetchBlockRangeArgs<TFilter>): Promise<FetchBlockRangeResult<TBlock>>;
64
- abstract fetchBlockByNumber(args: FetchBlockByNumberArgs<TFilter>): Promise<FetchBlockByNumberResult<TBlock>>;
64
+ abstract fetchBlockByHash(args: FetchBlockByHashArgs<TFilter>): Promise<FetchBlockByHashResult<TBlock>>;
65
65
  }
66
66
 
67
67
  declare class RpcClient<TFilter, TBlock> implements Client<TFilter, TBlock> {
@@ -83,12 +83,13 @@ declare class RpcDataStream<TFilter, TBlock> {
83
83
  }
84
84
 
85
85
  type index_BlockInfo = BlockInfo;
86
- type index_FetchBlockByNumberArgs<TFilter> = FetchBlockByNumberArgs<TFilter>;
87
- type index_FetchBlockByNumberResult<TBlock> = FetchBlockByNumberResult<TBlock>;
86
+ type index_FetchBlockByHashArgs<TFilter> = FetchBlockByHashArgs<TFilter>;
87
+ type index_FetchBlockByHashResult<TBlock> = FetchBlockByHashResult<TBlock>;
88
88
  type index_FetchBlockRangeArgs<TFilter> = FetchBlockRangeArgs<TFilter>;
89
89
  type index_FetchBlockRangeResult<TBlock> = FetchBlockRangeResult<TBlock>;
90
90
  type index_FetchBlockResult<TBlock> = FetchBlockResult<TBlock>;
91
91
  type index_FetchCursorArgs = FetchCursorArgs;
92
+ type index_FetchCursorRangeArgs = FetchCursorRangeArgs;
92
93
  type index_RpcClient<TFilter, TBlock> = RpcClient<TFilter, TBlock>;
93
94
  declare const index_RpcClient: typeof RpcClient;
94
95
  type index_RpcDataStream<TFilter, TBlock> = RpcDataStream<TFilter, TBlock>;
@@ -98,7 +99,7 @@ declare const index_RpcStreamConfig: typeof RpcStreamConfig;
98
99
  type index_ValidateFilterResult = ValidateFilterResult;
99
100
  declare const index_createRpcClient: typeof createRpcClient;
100
101
  declare namespace index {
101
- export { type index_BlockInfo as BlockInfo, type index_FetchBlockByNumberArgs as FetchBlockByNumberArgs, type index_FetchBlockByNumberResult as FetchBlockByNumberResult, type index_FetchBlockRangeArgs as FetchBlockRangeArgs, type index_FetchBlockRangeResult as FetchBlockRangeResult, type index_FetchBlockResult as FetchBlockResult, type index_FetchCursorArgs as FetchCursorArgs, index_RpcClient as RpcClient, index_RpcDataStream as RpcDataStream, index_RpcStreamConfig as RpcStreamConfig, type index_ValidateFilterResult as ValidateFilterResult, index_createRpcClient as createRpcClient };
102
+ export { type index_BlockInfo as BlockInfo, type index_FetchBlockByHashArgs as FetchBlockByHashArgs, type index_FetchBlockByHashResult as FetchBlockByHashResult, type index_FetchBlockRangeArgs as FetchBlockRangeArgs, type index_FetchBlockRangeResult as FetchBlockRangeResult, type index_FetchBlockResult as FetchBlockResult, type index_FetchCursorArgs as FetchCursorArgs, type index_FetchCursorRangeArgs as FetchCursorRangeArgs, index_RpcClient as RpcClient, index_RpcDataStream as RpcDataStream, index_RpcStreamConfig as RpcStreamConfig, type index_ValidateFilterResult as ValidateFilterResult, index_createRpcClient as createRpcClient };
102
103
  }
103
104
 
104
- export { type BlockInfo as B, type FetchBlockRangeArgs as F, RpcStreamConfig as R, type ValidateFilterResult as V, type FetchBlockResult as a, type FetchBlockRangeResult as b, type FetchBlockByNumberArgs as c, type FetchBlockByNumberResult as d, type FetchCursorArgs as e, RpcClient as f, createRpcClient as g, RpcDataStream as h, index as i };
105
+ export { type BlockInfo as B, type FetchBlockRangeArgs as F, RpcStreamConfig as R, type ValidateFilterResult as V, type FetchBlockResult as a, type FetchBlockRangeResult as b, type FetchBlockByHashArgs as c, type FetchBlockByHashResult as d, type FetchCursorArgs as e, type FetchCursorRangeArgs as f, RpcClient as g, createRpcClient as h, index as i, RpcDataStream as j };
@@ -2,7 +2,7 @@ import { C as Cursor, B as Bytes, w as Client, S as StatusRequest, u as ClientCa
2
2
 
3
3
  type FetchBlockRangeArgs<TFilter> = {
4
4
  startBlock: bigint;
5
- finalizedBlock: bigint;
5
+ maxBlock: bigint;
6
6
  force: boolean;
7
7
  filter: TFilter;
8
8
  };
@@ -21,19 +21,18 @@ type BlockInfo = {
21
21
  blockHash: Bytes;
22
22
  parentBlockHash: Bytes;
23
23
  };
24
- type FetchBlockByNumberArgs<TFilter> = {
25
- blockNumber: bigint;
26
- expectedParentBlockHash: Bytes;
24
+ type FetchBlockByHashArgs<TFilter> = {
25
+ blockHash: Bytes;
27
26
  isAtHead: boolean;
28
27
  filter: TFilter;
29
28
  };
30
- type FetchBlockByNumberResult<TBlock> = {
31
- status: "success";
29
+ type FetchBlockByHashResult<TBlock> = {
32
30
  data: FetchBlockResult<TBlock>;
33
31
  blockInfo: BlockInfo;
34
- } | {
35
- status: "reorg";
36
- blockInfo: BlockInfo;
32
+ };
33
+ type FetchCursorRangeArgs = {
34
+ startBlockNumber: bigint;
35
+ endBlockNumber: bigint;
37
36
  };
38
37
  type FetchCursorArgs = {
39
38
  blockTag: "latest" | "finalized";
@@ -58,10 +57,11 @@ type ValidateFilterResult = {
58
57
  declare abstract class RpcStreamConfig<TFilter, TBlock> {
59
58
  abstract headRefreshIntervalMs(): number;
60
59
  abstract finalizedRefreshIntervalMs(): number;
60
+ abstract fetchCursorRange(args: FetchCursorRangeArgs): Promise<BlockInfo[]>;
61
61
  abstract fetchCursor(args: FetchCursorArgs): Promise<BlockInfo | null>;
62
62
  abstract validateFilter(filter: TFilter): ValidateFilterResult;
63
63
  abstract fetchBlockRange(args: FetchBlockRangeArgs<TFilter>): Promise<FetchBlockRangeResult<TBlock>>;
64
- abstract fetchBlockByNumber(args: FetchBlockByNumberArgs<TFilter>): Promise<FetchBlockByNumberResult<TBlock>>;
64
+ abstract fetchBlockByHash(args: FetchBlockByHashArgs<TFilter>): Promise<FetchBlockByHashResult<TBlock>>;
65
65
  }
66
66
 
67
67
  declare class RpcClient<TFilter, TBlock> implements Client<TFilter, TBlock> {
@@ -83,12 +83,13 @@ declare class RpcDataStream<TFilter, TBlock> {
83
83
  }
84
84
 
85
85
  type index_BlockInfo = BlockInfo;
86
- type index_FetchBlockByNumberArgs<TFilter> = FetchBlockByNumberArgs<TFilter>;
87
- type index_FetchBlockByNumberResult<TBlock> = FetchBlockByNumberResult<TBlock>;
86
+ type index_FetchBlockByHashArgs<TFilter> = FetchBlockByHashArgs<TFilter>;
87
+ type index_FetchBlockByHashResult<TBlock> = FetchBlockByHashResult<TBlock>;
88
88
  type index_FetchBlockRangeArgs<TFilter> = FetchBlockRangeArgs<TFilter>;
89
89
  type index_FetchBlockRangeResult<TBlock> = FetchBlockRangeResult<TBlock>;
90
90
  type index_FetchBlockResult<TBlock> = FetchBlockResult<TBlock>;
91
91
  type index_FetchCursorArgs = FetchCursorArgs;
92
+ type index_FetchCursorRangeArgs = FetchCursorRangeArgs;
92
93
  type index_RpcClient<TFilter, TBlock> = RpcClient<TFilter, TBlock>;
93
94
  declare const index_RpcClient: typeof RpcClient;
94
95
  type index_RpcDataStream<TFilter, TBlock> = RpcDataStream<TFilter, TBlock>;
@@ -98,7 +99,7 @@ declare const index_RpcStreamConfig: typeof RpcStreamConfig;
98
99
  type index_ValidateFilterResult = ValidateFilterResult;
99
100
  declare const index_createRpcClient: typeof createRpcClient;
100
101
  declare namespace index {
101
- export { type index_BlockInfo as BlockInfo, type index_FetchBlockByNumberArgs as FetchBlockByNumberArgs, type index_FetchBlockByNumberResult as FetchBlockByNumberResult, type index_FetchBlockRangeArgs as FetchBlockRangeArgs, type index_FetchBlockRangeResult as FetchBlockRangeResult, type index_FetchBlockResult as FetchBlockResult, type index_FetchCursorArgs as FetchCursorArgs, index_RpcClient as RpcClient, index_RpcDataStream as RpcDataStream, index_RpcStreamConfig as RpcStreamConfig, type index_ValidateFilterResult as ValidateFilterResult, index_createRpcClient as createRpcClient };
102
+ export { type index_BlockInfo as BlockInfo, type index_FetchBlockByHashArgs as FetchBlockByHashArgs, type index_FetchBlockByHashResult as FetchBlockByHashResult, type index_FetchBlockRangeArgs as FetchBlockRangeArgs, type index_FetchBlockRangeResult as FetchBlockRangeResult, type index_FetchBlockResult as FetchBlockResult, type index_FetchCursorArgs as FetchCursorArgs, type index_FetchCursorRangeArgs as FetchCursorRangeArgs, index_RpcClient as RpcClient, index_RpcDataStream as RpcDataStream, index_RpcStreamConfig as RpcStreamConfig, type index_ValidateFilterResult as ValidateFilterResult, index_createRpcClient as createRpcClient };
102
103
  }
103
104
 
104
- export { type BlockInfo as B, type FetchBlockRangeArgs as F, RpcStreamConfig as R, type ValidateFilterResult as V, type FetchBlockResult as a, type FetchBlockRangeResult as b, type FetchBlockByNumberArgs as c, type FetchBlockByNumberResult as d, type FetchCursorArgs as e, RpcClient as f, createRpcClient as g, RpcDataStream as h, index as i };
105
+ export { type BlockInfo as B, type FetchBlockRangeArgs as F, RpcStreamConfig as R, type ValidateFilterResult as V, type FetchBlockResult as a, type FetchBlockRangeResult as b, type FetchBlockByHashArgs as c, type FetchBlockByHashResult as d, type FetchCursorArgs as e, type FetchCursorRangeArgs as f, RpcClient as g, createRpcClient as h, index as i, RpcDataStream as j };
@@ -2,7 +2,7 @@ import { C as Cursor, B as Bytes, w as Client, S as StatusRequest, u as ClientCa
2
2
 
3
3
  type FetchBlockRangeArgs<TFilter> = {
4
4
  startBlock: bigint;
5
- finalizedBlock: bigint;
5
+ maxBlock: bigint;
6
6
  force: boolean;
7
7
  filter: TFilter;
8
8
  };
@@ -21,19 +21,18 @@ type BlockInfo = {
21
21
  blockHash: Bytes;
22
22
  parentBlockHash: Bytes;
23
23
  };
24
- type FetchBlockByNumberArgs<TFilter> = {
25
- blockNumber: bigint;
26
- expectedParentBlockHash: Bytes;
24
+ type FetchBlockByHashArgs<TFilter> = {
25
+ blockHash: Bytes;
27
26
  isAtHead: boolean;
28
27
  filter: TFilter;
29
28
  };
30
- type FetchBlockByNumberResult<TBlock> = {
31
- status: "success";
29
+ type FetchBlockByHashResult<TBlock> = {
32
30
  data: FetchBlockResult<TBlock>;
33
31
  blockInfo: BlockInfo;
34
- } | {
35
- status: "reorg";
36
- blockInfo: BlockInfo;
32
+ };
33
+ type FetchCursorRangeArgs = {
34
+ startBlockNumber: bigint;
35
+ endBlockNumber: bigint;
37
36
  };
38
37
  type FetchCursorArgs = {
39
38
  blockTag: "latest" | "finalized";
@@ -58,10 +57,11 @@ type ValidateFilterResult = {
58
57
  declare abstract class RpcStreamConfig<TFilter, TBlock> {
59
58
  abstract headRefreshIntervalMs(): number;
60
59
  abstract finalizedRefreshIntervalMs(): number;
60
+ abstract fetchCursorRange(args: FetchCursorRangeArgs): Promise<BlockInfo[]>;
61
61
  abstract fetchCursor(args: FetchCursorArgs): Promise<BlockInfo | null>;
62
62
  abstract validateFilter(filter: TFilter): ValidateFilterResult;
63
63
  abstract fetchBlockRange(args: FetchBlockRangeArgs<TFilter>): Promise<FetchBlockRangeResult<TBlock>>;
64
- abstract fetchBlockByNumber(args: FetchBlockByNumberArgs<TFilter>): Promise<FetchBlockByNumberResult<TBlock>>;
64
+ abstract fetchBlockByHash(args: FetchBlockByHashArgs<TFilter>): Promise<FetchBlockByHashResult<TBlock>>;
65
65
  }
66
66
 
67
67
  declare class RpcClient<TFilter, TBlock> implements Client<TFilter, TBlock> {
@@ -83,12 +83,13 @@ declare class RpcDataStream<TFilter, TBlock> {
83
83
  }
84
84
 
85
85
  type index_BlockInfo = BlockInfo;
86
- type index_FetchBlockByNumberArgs<TFilter> = FetchBlockByNumberArgs<TFilter>;
87
- type index_FetchBlockByNumberResult<TBlock> = FetchBlockByNumberResult<TBlock>;
86
+ type index_FetchBlockByHashArgs<TFilter> = FetchBlockByHashArgs<TFilter>;
87
+ type index_FetchBlockByHashResult<TBlock> = FetchBlockByHashResult<TBlock>;
88
88
  type index_FetchBlockRangeArgs<TFilter> = FetchBlockRangeArgs<TFilter>;
89
89
  type index_FetchBlockRangeResult<TBlock> = FetchBlockRangeResult<TBlock>;
90
90
  type index_FetchBlockResult<TBlock> = FetchBlockResult<TBlock>;
91
91
  type index_FetchCursorArgs = FetchCursorArgs;
92
+ type index_FetchCursorRangeArgs = FetchCursorRangeArgs;
92
93
  type index_RpcClient<TFilter, TBlock> = RpcClient<TFilter, TBlock>;
93
94
  declare const index_RpcClient: typeof RpcClient;
94
95
  type index_RpcDataStream<TFilter, TBlock> = RpcDataStream<TFilter, TBlock>;
@@ -98,7 +99,7 @@ declare const index_RpcStreamConfig: typeof RpcStreamConfig;
98
99
  type index_ValidateFilterResult = ValidateFilterResult;
99
100
  declare const index_createRpcClient: typeof createRpcClient;
100
101
  declare namespace index {
101
- export { type index_BlockInfo as BlockInfo, type index_FetchBlockByNumberArgs as FetchBlockByNumberArgs, type index_FetchBlockByNumberResult as FetchBlockByNumberResult, type index_FetchBlockRangeArgs as FetchBlockRangeArgs, type index_FetchBlockRangeResult as FetchBlockRangeResult, type index_FetchBlockResult as FetchBlockResult, type index_FetchCursorArgs as FetchCursorArgs, index_RpcClient as RpcClient, index_RpcDataStream as RpcDataStream, index_RpcStreamConfig as RpcStreamConfig, type index_ValidateFilterResult as ValidateFilterResult, index_createRpcClient as createRpcClient };
102
+ export { type index_BlockInfo as BlockInfo, type index_FetchBlockByHashArgs as FetchBlockByHashArgs, type index_FetchBlockByHashResult as FetchBlockByHashResult, type index_FetchBlockRangeArgs as FetchBlockRangeArgs, type index_FetchBlockRangeResult as FetchBlockRangeResult, type index_FetchBlockResult as FetchBlockResult, type index_FetchCursorArgs as FetchCursorArgs, type index_FetchCursorRangeArgs as FetchCursorRangeArgs, index_RpcClient as RpcClient, index_RpcDataStream as RpcDataStream, index_RpcStreamConfig as RpcStreamConfig, type index_ValidateFilterResult as ValidateFilterResult, index_createRpcClient as createRpcClient };
102
103
  }
103
104
 
104
- export { type BlockInfo as B, type FetchBlockRangeArgs as F, RpcStreamConfig as R, type ValidateFilterResult as V, type FetchBlockResult as a, type FetchBlockRangeResult as b, type FetchBlockByNumberArgs as c, type FetchBlockByNumberResult as d, type FetchCursorArgs as e, RpcClient as f, createRpcClient as g, RpcDataStream as h, index as i };
105
+ export { type BlockInfo as B, type FetchBlockRangeArgs as F, RpcStreamConfig as R, type ValidateFilterResult as V, type FetchBlockResult as a, type FetchBlockRangeResult as b, type FetchBlockByHashArgs as c, type FetchBlockByHashResult as d, type FetchCursorArgs as e, type FetchCursorRangeArgs as f, RpcClient as g, createRpcClient as h, index as i, RpcDataStream as j };
@@ -30,14 +30,20 @@ var __privateSet = (obj, member, value, setter) => {
30
30
  setter ? setter.call(obj, value) : member.set(obj, value);
31
31
  return value;
32
32
  };
33
- var _finalized, _head, _canonical;
33
+ var _finalized, _head, _canonical, _batchSize;
34
34
  class ChainTracker {
35
- constructor({ head, finalized }) {
35
+ constructor({
36
+ head,
37
+ finalized,
38
+ batchSize
39
+ }) {
36
40
  __privateAdd(this, _finalized, void 0);
37
41
  __privateAdd(this, _head, void 0);
38
42
  __privateAdd(this, _canonical, void 0);
43
+ __privateAdd(this, _batchSize, void 0);
39
44
  __privateSet(this, _finalized, finalized);
40
45
  __privateSet(this, _head, head);
46
+ __privateSet(this, _batchSize, batchSize);
41
47
  __privateSet(this, _canonical, /* @__PURE__ */ new Map([
42
48
  [finalized.blockNumber, finalized],
43
49
  [head.blockNumber, head]
@@ -87,7 +93,8 @@ class ChainTracker {
87
93
  }
88
94
  async updateHead({
89
95
  newHead,
90
- fetchCursorByHash
96
+ fetchCursorByHash,
97
+ fetchCursorRange
91
98
  }) {
92
99
  if (newHead.blockNumber === __privateGet(this, _head).blockNumber && newHead.blockHash === __privateGet(this, _head).blockHash) {
93
100
  return { status: "unchanged" };
@@ -137,46 +144,43 @@ class ChainTracker {
137
144
  }
138
145
  throw new Error("Cannot reconcile new head with canonical chain.");
139
146
  }
140
- let current = newHead;
141
- let reorgDetected = false;
142
- const blocksToApply = [newHead];
147
+ let currentBlockNumber = __privateGet(this, _head).blockNumber + 1n;
143
148
  while (true) {
144
- const parent = await fetchCursorByHash(current.parentBlockHash);
145
- if (!parent) {
146
- throw new Error(
147
- "Cannot reconcile new head with canonical chain: failed to fetch parent"
148
- );
149
+ let endBlockNumber = currentBlockNumber + __privateGet(this, _batchSize);
150
+ if (endBlockNumber > newHead.blockNumber) {
151
+ endBlockNumber = newHead.blockNumber;
149
152
  }
150
- if (parent.blockNumber === __privateGet(this, _head).blockNumber) {
151
- if (parent.blockHash === __privateGet(this, _head).blockHash) {
152
- break;
153
- }
154
- const headParent = __privateGet(this, _canonical).get(__privateGet(this, _head).blockNumber - 1n);
155
- if (!headParent) {
153
+ const missing = await fetchCursorRange({
154
+ startBlockNumber: currentBlockNumber,
155
+ endBlockNumber
156
+ });
157
+ for (const block of missing) {
158
+ const canonicalParent = __privateGet(this, _canonical).get(block.blockNumber - 1n);
159
+ if (!canonicalParent || canonicalParent.blockHash !== block.parentBlockHash) {
156
160
  throw new Error(
157
- "Cannot reconcile new head with canonical chain: missing parent in canonical chain"
161
+ "Chain reorganization detected. Recovery not implemented"
158
162
  );
159
163
  }
160
- __privateGet(this, _canonical).delete(__privateGet(this, _head).blockNumber);
161
- __privateSet(this, _head, headParent);
162
- reorgDetected = true;
164
+ __privateGet(this, _canonical).set(block.blockNumber, block);
163
165
  }
164
- blocksToApply.push(parent);
165
- current = parent;
166
- }
167
- for (const block of blocksToApply.reverse()) {
168
- __privateGet(this, _canonical).set(block.blockNumber, block);
166
+ if (endBlockNumber === newHead.blockNumber) {
167
+ break;
168
+ }
169
+ currentBlockNumber = endBlockNumber + 1n;
169
170
  }
170
- const previousHead = __privateGet(this, _head);
171
171
  __privateSet(this, _head, newHead);
172
- if (reorgDetected) {
173
- return {
174
- status: "reorg",
175
- cursor: blockInfoToCursor(previousHead)
176
- };
177
- }
178
172
  return { status: "success" };
179
173
  }
174
+ isCanonical({ orderKey, uniqueKey }) {
175
+ if (!uniqueKey) {
176
+ return true;
177
+ }
178
+ const block = __privateGet(this, _canonical).get(orderKey);
179
+ if (!block) {
180
+ return true;
181
+ }
182
+ return block.blockHash === uniqueKey;
183
+ }
180
184
  async initializeStartingCursor({
181
185
  cursor,
182
186
  fetchCursor
@@ -230,11 +234,13 @@ class ChainTracker {
230
234
  _finalized = new WeakMap();
231
235
  _head = new WeakMap();
232
236
  _canonical = new WeakMap();
237
+ _batchSize = new WeakMap();
233
238
  function createChainTracker({
234
239
  head,
235
- finalized
240
+ finalized,
241
+ batchSize
236
242
  }) {
237
- return new ChainTracker({ finalized, head });
243
+ return new ChainTracker({ finalized, head, batchSize });
238
244
  }
239
245
 
240
246
  var __defProp = Object.defineProperty;
@@ -275,7 +281,8 @@ class RpcDataStream {
275
281
  }
276
282
  const chainTracker = createChainTracker({
277
283
  head,
278
- finalized
284
+ finalized,
285
+ batchSize: 20n
279
286
  });
280
287
  let cursor;
281
288
  if (this.request.startingCursor) {
@@ -295,7 +302,9 @@ class RpcDataStream {
295
302
  cursor,
296
303
  lastHeartbeat: Date.now(),
297
304
  lastFinalizedRefresh: Date.now(),
305
+ lastHeadRefresh: Date.now(),
298
306
  lastBackfillMessage: Date.now(),
307
+ lastEmptyBlockNumber: void 0,
299
308
  chainTracker,
300
309
  config: this.config,
301
310
  heartbeatIntervalMs: this.heartbeatIntervalMs,
@@ -332,7 +341,7 @@ async function* dataStreamLoop(state) {
332
341
  if (isAtHead(state)) {
333
342
  yield* waitForHeadChange(state);
334
343
  } else {
335
- yield* produceNextBlock(state);
344
+ yield* produceLiveBlocks(state);
336
345
  }
337
346
  }
338
347
  }
@@ -343,7 +352,7 @@ async function* backfillFinalizedBlocks(state) {
343
352
  const force = shouldForceBackfill(state);
344
353
  const filterData = await config.fetchBlockRange({
345
354
  startBlock: cursor.orderKey + 1n,
346
- finalizedBlock: finalized.orderKey,
355
+ maxBlock: finalized.orderKey,
347
356
  force,
348
357
  filter
349
358
  });
@@ -372,43 +381,79 @@ async function* backfillFinalizedBlocks(state) {
372
381
  state.cursor = { orderKey: filterData.endBlock };
373
382
  }
374
383
  }
375
- async function* produceNextBlock(state) {
376
- const currentBlockHash = state.cursor.uniqueKey;
377
- if (currentBlockHash === void 0) {
378
- throw new Error("Live production phase without cursor's hash.");
379
- }
380
- const result = await state.config.fetchBlockByNumber({
381
- blockNumber: state.cursor.orderKey + 1n,
382
- isAtHead: isAtHead(state),
383
- expectedParentBlockHash: currentBlockHash,
384
- filter: state.filter
385
- });
386
- if (result.status === "reorg") {
387
- throw new Error("Reorg not implemented");
384
+ async function* produceLiveBlocks(state) {
385
+ const { config, cursor, chainTracker, filter } = state;
386
+ if (shouldRefreshHead(state)) {
387
+ const maybeNewHead = await config.fetchCursor({ blockTag: "latest" });
388
+ if (maybeNewHead === null) {
389
+ throw new Error("Failed to fetch the latest block");
390
+ }
391
+ const result = await chainTracker.updateHead({
392
+ newHead: maybeNewHead,
393
+ fetchCursorByHash: (blockHash) => config.fetchCursor({ blockHash }),
394
+ fetchCursorRange: (args) => config.fetchCursorRange(args)
395
+ });
396
+ state.lastHeadRefresh = Date.now();
397
+ if (result.status === "reorg") {
398
+ const { cursor: cursor2 } = result;
399
+ if (cursor2.orderKey < state.cursor.orderKey || state.lastEmptyBlockNumber !== void 0 && cursor2.orderKey < state.lastEmptyBlockNumber) {
400
+ state.cursor = cursor2;
401
+ yield {
402
+ _tag: "invalidate",
403
+ invalidate: { cursor: cursor2 }
404
+ };
405
+ return;
406
+ }
407
+ }
388
408
  }
389
- const { data, blockInfo } = result;
390
- state.cursor = {
391
- orderKey: blockInfo.blockNumber,
392
- uniqueKey: blockInfo.blockHash
393
- };
394
- const { status: headUpdateStatus } = state.chainTracker.addToCanonicalChain({
395
- blockInfo
409
+ const head = chainTracker.head();
410
+ const filterData = await config.fetchBlockRange({
411
+ startBlock: cursor.orderKey + 1n,
412
+ maxBlock: head.orderKey,
413
+ force: false,
414
+ filter
396
415
  });
397
- if (headUpdateStatus !== "success") {
398
- throw new Error("Failed to update head. Would cause reorg.");
416
+ if (filterData.data.length === 0 && head.uniqueKey !== void 0) {
417
+ if (state.lastEmptyBlockNumber === void 0 || head.orderKey > state.lastEmptyBlockNumber) {
418
+ const { data } = await config.fetchBlockByHash({
419
+ blockHash: head.uniqueKey,
420
+ isAtHead: true,
421
+ filter
422
+ });
423
+ yield {
424
+ _tag: "data",
425
+ data: {
426
+ cursor: data.cursor,
427
+ endCursor: data.endCursor,
428
+ data: [data.block],
429
+ finality: "accepted",
430
+ production: "live"
431
+ }
432
+ };
433
+ state.lastEmptyBlockNumber = head.orderKey;
434
+ }
399
435
  }
400
- if (data.block !== null) {
401
- state.lastHeartbeat = Date.now();
402
- const production = isAtHead(state) ? "live" : "backfill";
403
- yield {
404
- _tag: "data",
405
- data: {
406
- cursor: data.cursor,
407
- endCursor: data.endCursor,
408
- data: [data.block],
409
- finality: "accepted",
410
- production
411
- }
436
+ for (const { cursor: cursor2, endCursor, block } of filterData.data) {
437
+ if (!chainTracker.isCanonical(endCursor)) {
438
+ throw new Error("Trying to process non-canonical block");
439
+ }
440
+ if (block !== null) {
441
+ state.lastHeartbeat = Date.now();
442
+ const production = isAtHead(state) ? "live" : "backfill";
443
+ yield {
444
+ _tag: "data",
445
+ data: {
446
+ cursor: cursor2,
447
+ endCursor,
448
+ data: [block],
449
+ finality: "accepted",
450
+ production
451
+ }
452
+ };
453
+ }
454
+ state.cursor = {
455
+ orderKey: endCursor.orderKey,
456
+ uniqueKey: endCursor.uniqueKey
412
457
  };
413
458
  }
414
459
  }
@@ -427,7 +472,8 @@ async function* waitForHeadChange(state) {
427
472
  }
428
473
  const result = await chainTracker.updateHead({
429
474
  newHead: maybeNewHead,
430
- fetchCursorByHash: (blockHash) => config.fetchCursor({ blockHash })
475
+ fetchCursorByHash: (blockHash) => config.fetchCursor({ blockHash }),
476
+ fetchCursorRange: (args) => config.fetchCursorRange(args)
431
477
  });
432
478
  switch (result.status) {
433
479
  case "unchanged": {
@@ -480,6 +526,11 @@ function shouldRefreshFinalized(state) {
480
526
  const now = Date.now();
481
527
  return now - lastFinalizedRefresh >= config.finalizedRefreshIntervalMs();
482
528
  }
529
+ function shouldRefreshHead(state) {
530
+ const { lastHeadRefresh, config } = state;
531
+ const now = Date.now();
532
+ return now - lastHeadRefresh >= config.headRefreshIntervalMs();
533
+ }
483
534
  function isAtHead(state) {
484
535
  const head = state.chainTracker.head();
485
536
  return state.cursor.orderKey === head.orderKey;
@@ -533,4 +584,4 @@ exports.RpcDataStream = RpcDataStream;
533
584
  exports.RpcStreamConfig = RpcStreamConfig;
534
585
  exports.createRpcClient = createRpcClient;
535
586
  exports.index = index;
536
- //# sourceMappingURL=protocol.54f17699.cjs.map
587
+ //# sourceMappingURL=protocol.a44ea889.cjs.map