@talismn/chain-connectors 0.1.1 → 1.0.0

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.d.mts CHANGED
@@ -1,139 +1,150 @@
1
- import { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
2
- import { DotNetworkId, IChaindataNetworkProvider, DotNetwork, EthNetworkId, IChaindataTokenProvider, EthNetwork, SolNetworkId, SolNetwork } from '@talismn/chaindata-provider';
3
- import { TalismanConnectionMetaDatabase } from '@talismn/connection-meta';
4
- import { PublicClient, Account, WalletClient } from 'viem';
5
- import { Connection } from '@solana/web3.js';
6
-
1
+ import { Account, PublicClient, WalletClient } from "viem";
2
+ import { Rpc, RpcTransport, SolanaRpcApi } from "@solana/kit";
3
+ import { DotNetwork, DotNetworkId, EthNetwork, EthNetworkId, IChaindataNetworkProvider, IChaindataTokenProvider, SolNetwork, SolNetworkId } from "@talismn/chaindata-provider";
4
+ //#region src/dot/IChainConnectorDot.d.ts
5
+ /** Callback signature for RPC subscriptions (error-first, matches the legacy polkadot-js ProviderInterfaceCallback) */
6
+ type SubscriptionCallback = (error: Error | null, result: any) => void;
7
7
  interface IChainConnectorDot {
8
- asProvider(chainId: DotNetworkId): ProviderInterface;
9
- send<T = unknown>(chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean, extraOptions?: {
10
- expectErrors?: boolean;
11
- }): Promise<T>;
12
- subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
13
- reset(chainId: DotNetworkId): Promise<void>;
8
+ send<T = unknown>(chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean, extraOptions?: {
9
+ expectErrors?: boolean;
10
+ }): Promise<T>;
11
+ subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: SubscriptionCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
12
+ reset(chainId: DotNetworkId): Promise<void>;
14
13
  }
15
-
14
+ //#endregion
15
+ //#region src/dot/ChainConnectorDot.d.ts
16
16
  declare class ChainConnectionError extends Error {
17
- type: "CHAIN_CONNECTION_ERROR";
18
- chainId: string;
19
- constructor(chainId: string, options?: ErrorOptions);
17
+ type: "CHAIN_CONNECTION_ERROR";
18
+ chainId: string;
19
+ constructor(chainId: string, options?: ErrorOptions);
20
20
  }
21
21
  declare class StaleRpcError extends Error {
22
- type: "STALE_RPC_ERROR";
23
- chainId: string;
24
- constructor(chainId: string, options?: ErrorOptions);
25
- }
26
- declare class WebsocketAllocationExhaustedError extends Error {
27
- type: "WEBSOCKET_ALLOCATION_EXHAUSTED_ERROR";
28
- chainId: string;
29
- constructor(chainId: string, options?: ErrorOptions);
22
+ type: "STALE_RPC_ERROR";
23
+ chainId: string;
24
+ constructor(chainId: string, options?: ErrorOptions);
30
25
  }
31
26
  /**
32
- * ChainConnector provides an interface similar to WsProvider, but with three points of difference:
27
+ * ChainConnector provides an interface similar to a websocket JSON-RPC provider, but with three points of difference:
33
28
  *
34
29
  * 1. ChainConnector methods all accept a `chainId` instead of an array of RPCs. RPCs are then fetched internally from chaindata.
35
- * 2. ChainConnector creates only one `WsProvider` per chain and ensures that all downstream requests to a chain share the one socket connection.
36
- * 3. Subscriptions return a callable `unsubscribe` method instead of an id.
30
+ * 2. ChainConnector creates only one socket connection per chain (via polkadot-api's ws-provider, which handles
31
+ * endpoint rotation, reconnection and stale-socket detection) and ensures that all downstream requests to a chain
32
+ * share that connection.
33
+ * 3. Subscriptions return a callable `unsubscribe` method instead of an id, and are automatically re-established
34
+ * when the provider reconnects (possibly to another endpoint).
37
35
  *
38
36
  * Additionally, when run on the clientside of a dapp where `window.talismanSub` is available, instead of spinning up new websocket
39
37
  * connections this class will forward all requests through to the wallet backend - where another instance of this class will
40
38
  * handle the websocket connections.
41
39
  */
42
40
  declare class ChainConnectorDot implements IChainConnectorDot {
43
- #private;
44
- constructor(chaindataChainProvider: IChaindataNetworkProvider, connectionMetaDb?: TalismanConnectionMetaDatabase);
45
- /**
46
- * Creates a facade over this ChainConnector which conforms to the PJS ProviderInterface
47
- * @example // Using a chainConnector as a Provider for an ApiPromise
48
- * const provider = chainConnector.asProvider('polkadot')
49
- * const api = new ApiPromise({ provider })
50
- */
51
- asProvider(chainId: DotNetworkId): ProviderInterface;
52
- send<T = any>(chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean | undefined, extraOptions?: {
53
- /**
54
- * Set to `true` if this query is speculative, i.e. if on some chains it's expected that it will raise a wasm unreachable error of the form:
55
- *
56
- * 4003: Client error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
57
- *
58
- * By setting expectErrors to true, this method won't pollute the logs with errors we intend to have happen.
59
- * An example use case of this is when you plan to catch the wasm unreachable error on chains that don't support the query, and then fall back
60
- * to another query or perhaps an empty result.
61
- */
62
- expectErrors?: boolean;
63
- }): Promise<T>;
64
- subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
65
- /**
66
- * Kills current websocket if any
67
- * Useful after changing rpc order to make sure it's applied for futher requests
68
- */
69
- reset(chainId: DotNetworkId): Promise<void>;
70
- /**
71
- * Wait for websocket to be ready, but don't wait forever
72
- */
73
- private waitForWs;
41
+ #private;
42
+ constructor(chaindataChainProvider: IChaindataNetworkProvider);
43
+ send<T = any>(chainId: DotNetworkId, method: string, params: unknown[], _isCacheable?: boolean | undefined, extraOptions?: {
74
44
  /**
75
- * Connect to an RPC via chainId
45
+ * Set to `true` if this query is speculative, i.e. if on some chains it's expected that it will raise a wasm unreachable error of the form:
46
+ *
47
+ * 4003: Client error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
76
48
  *
77
- * The caller must call disconnectChainSocket with the returned SocketUserId once they are finished with it
49
+ * By setting expectErrors to true, this method won't pollute the logs with errors we intend to have happen.
50
+ * An example use case of this is when you plan to catch the wasm unreachable error on chains that don't support the query, and then fall back
51
+ * to another query or perhaps an empty result.
78
52
  */
79
- private connectChainSocket;
80
- private disconnectChainSocket;
81
- private addSocketUser;
82
- private removeSocketUser;
83
- /** continues to generate a random number until it finds one which is not present in the exclude list */
84
- private getExclusiveRandomId;
85
- /** generates a random number */
86
- private getRandomId;
87
- private getTalismanSub;
88
- private updateRpcPriority;
89
- private getEndpoints;
53
+ expectErrors?: boolean;
54
+ }): Promise<T>;
55
+ subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: SubscriptionCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
56
+ /**
57
+ * Kills and recreates the connection for a chain, if any.
58
+ * Useful after changing a network's rpcs to make sure the new list is applied for further requests.
59
+ * Active subscriptions are automatically re-established on the new connection.
60
+ */
61
+ reset(chainId: DotNetworkId): Promise<void>;
62
+ /** Sends a request over a connection, throwing `Error("TIMEOUT")` if no response arrives in time */
63
+ private request;
64
+ /** Issues the subscribe request and routes notifications to the subscription callback */
65
+ private startSubscription;
66
+ /**
67
+ * Get (or create) the shared connection for a chain.
68
+ *
69
+ * The caller must call releaseConnection with the returned SocketUserId once they are finished with it.
70
+ */
71
+ private acquireConnection;
72
+ private createConnection;
73
+ private handleStatusChange;
74
+ private releaseConnection;
75
+ private destroyConnection;
76
+ private getGenesisHash;
77
+ /** continues to generate a random number until it finds one which is not present in the exclude list */
78
+ private getExclusiveRandomId;
79
+ /** generates a random number */
80
+ private getRandomId;
81
+ private getTalismanSub;
90
82
  }
91
-
83
+ //#endregion
84
+ //#region src/dot/ChainConnectorDotStub.d.ts
92
85
  declare class ChainConnectorDotStub implements IChainConnectorDot {
93
- #private;
94
- constructor(network: DotNetwork);
95
- asProvider(): ProviderInterface;
96
- send<T = unknown>(_chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean): Promise<T>;
97
- subscribe(_chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
98
- reset(): Promise<void>;
86
+ #private;
87
+ constructor(network: DotNetwork);
88
+ send<T = unknown>(_chainId: DotNetworkId, method: string, params: unknown[], _isCacheable?: boolean): Promise<T>;
89
+ subscribe(_chainId: DotNetworkId, subscribeMethod: string, _responseMethod: string, params: unknown[], callback: SubscriptionCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
90
+ reset(): Promise<void>;
91
+ destroy(): void;
99
92
  }
100
-
93
+ //#endregion
94
+ //#region src/eth/IChainConnectorEth.d.ts
101
95
  interface IChainConnectorEth {
102
- getPublicClientForEvmNetwork: (evmNetworkId: EthNetworkId) => Promise<PublicClient | null>;
103
- getWalletClientForEvmNetwork: (evmNetworkId: EthNetworkId, account?: `0x${string}` | Account) => Promise<WalletClient | null>;
104
- clearRpcProvidersCache: (evmNetworkId?: EthNetworkId) => void;
96
+ getPublicClientForEvmNetwork: (evmNetworkId: EthNetworkId) => Promise<PublicClient | null>;
97
+ getWalletClientForEvmNetwork: (evmNetworkId: EthNetworkId, account?: `0x${string}` | Account) => Promise<WalletClient | null>;
98
+ clearRpcProvidersCache: (evmNetworkId?: EthNetworkId) => void;
105
99
  }
106
-
100
+ //#endregion
101
+ //#region src/eth/ChainConnectorEth.d.ts
107
102
  declare class ChainConnectorEth implements IChainConnectorEth {
108
- #private;
109
- constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
110
- getPublicClientForEvmNetwork(evmNetworkId: EthNetworkId): Promise<PublicClient | null>;
111
- getWalletClientForEvmNetwork(evmNetworkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
112
- clearRpcProvidersCache(evmNetworkId?: EthNetworkId): void;
103
+ #private;
104
+ constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
105
+ getPublicClientForEvmNetwork(evmNetworkId: EthNetworkId): Promise<PublicClient | null>;
106
+ getWalletClientForEvmNetwork(evmNetworkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
107
+ clearRpcProvidersCache(evmNetworkId?: EthNetworkId): void;
113
108
  }
114
-
109
+ //#endregion
110
+ //#region src/eth/ChainConnectorEthStub.d.ts
115
111
  declare class ChainConnectorEthStub implements IChainConnectorEth {
116
- #private;
117
- constructor(network: EthNetwork);
118
- getPublicClientForEvmNetwork(): Promise<PublicClient | null>;
119
- getWalletClientForEvmNetwork(_networkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
120
- clearRpcProvidersCache(): void;
112
+ #private;
113
+ constructor(network: EthNetwork);
114
+ getPublicClientForEvmNetwork(): Promise<PublicClient | null>;
115
+ getWalletClientForEvmNetwork(_networkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
116
+ clearRpcProvidersCache(): void;
121
117
  }
122
-
118
+ //#endregion
119
+ //#region src/sol/getSolRpc.d.ts
120
+ type SolRpc = Rpc<SolanaRpcApi>;
121
+ declare const getSolTransport: (_networkId: SolNetworkId, rpcs: string[]) => RpcTransport;
122
+ declare const getSolRpc: (networkId: SolNetworkId, rpcs: string[]) => SolRpc;
123
+ //#endregion
124
+ //#region src/sol/IChainConnectorSol.d.ts
123
125
  interface IChainConnectorSol {
124
- getConnection: (networkId: SolNetworkId) => Promise<Connection>;
126
+ getRpc: (networkId: SolNetworkId) => Promise<SolRpc>;
127
+ /** Raw JSON-RPC transport, used by the background script to relay frontend RPC requests */
128
+ getTransport: (networkId: SolNetworkId) => Promise<RpcTransport>;
125
129
  }
126
-
130
+ //#endregion
131
+ //#region src/sol/ChainConnectorSol.d.ts
127
132
  declare class ChainConnectorSol implements IChainConnectorSol {
128
- #private;
129
- constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
130
- getConnection(networkId: SolNetworkId): Promise<Connection>;
133
+ #private;
134
+ constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
135
+ getTransport(networkId: SolNetworkId): Promise<RpcTransport>;
136
+ getRpc(networkId: SolNetworkId): Promise<SolRpc>;
137
+ /** Drops cached transports/rpcs so the next call re-reads the network's rpcs from chaindata */
138
+ clearRpcProvidersCache(networkId?: SolNetworkId): void;
131
139
  }
132
-
140
+ //#endregion
141
+ //#region src/sol/ChainConnectorSolStub.d.ts
133
142
  declare class ChainConnectorSolStub implements IChainConnectorSol {
134
- #private;
135
- constructor(networkOrConnection: Pick<SolNetwork, "id" | "rpcs"> | Connection);
136
- getConnection(): Promise<Connection>;
143
+ #private;
144
+ constructor(network: Pick<SolNetwork, "id" | "rpcs">);
145
+ getRpc(): Promise<SolRpc>;
146
+ getTransport(): Promise<RpcTransport>;
137
147
  }
138
-
139
- export { ChainConnectionError, ChainConnectorDot, ChainConnectorDotStub, ChainConnectorEth, ChainConnectorEthStub, ChainConnectorSol, ChainConnectorSolStub, type IChainConnectorDot, type IChainConnectorEth, type IChainConnectorSol, StaleRpcError, WebsocketAllocationExhaustedError };
148
+ //#endregion
149
+ export { ChainConnectionError, ChainConnectorDot, ChainConnectorDotStub, ChainConnectorEth, ChainConnectorEthStub, ChainConnectorSol, ChainConnectorSolStub, IChainConnectorDot, IChainConnectorEth, IChainConnectorSol, SolRpc, StaleRpcError, SubscriptionCallback, getSolRpc, getSolTransport };
150
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/dot/IChainConnectorDot.ts","../src/dot/ChainConnectorDot.ts","../src/dot/ChainConnectorDotStub.ts","../src/eth/IChainConnectorEth.ts","../src/eth/ChainConnectorEth.ts","../src/eth/ChainConnectorEthStub.ts","../src/sol/getSolRpc.ts","../src/sol/IChainConnectorSol.ts","../src/sol/ChainConnectorSol.ts","../src/sol/ChainConnectorSolStub.ts"],"mappings":";;;;;KAIY,wBAAwB,OAAO,cAAc;UAExC;EACf,KAAK,aACH,SAAS,cACT,gBACA,mB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QAAQ;;EAE7C,eAAe,WAAW,iBAAiB,QAAQ;;;;cCIxC,6BAA6B;;EAKxC,YAAY,mBAAmB,4BAA4B;EAWrD,aAAa,WAAW,eAAe,QAAQ;EAU/C,OAAO,WAAW,eAAe,QAAQ;;EAQ/C,uBAAuB,YAAY;;;;cCtCxB,iCAAiC;;EAI5C,YAAY,SAAS,KAAK;EAKpB,UAAU,QAAQ;EAIlB,gBAAgB,QAAQ"}
package/dist/index.d.ts CHANGED
@@ -1,139 +1,150 @@
1
- import { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
2
- import { DotNetworkId, IChaindataNetworkProvider, DotNetwork, EthNetworkId, IChaindataTokenProvider, EthNetwork, SolNetworkId, SolNetwork } from '@talismn/chaindata-provider';
3
- import { TalismanConnectionMetaDatabase } from '@talismn/connection-meta';
4
- import { PublicClient, Account, WalletClient } from 'viem';
5
- import { Connection } from '@solana/web3.js';
6
-
1
+ import { DotNetwork, DotNetworkId, EthNetwork, EthNetworkId, IChaindataNetworkProvider, IChaindataTokenProvider, SolNetwork, SolNetworkId } from "@talismn/chaindata-provider";
2
+ import { Account, PublicClient, WalletClient } from "viem";
3
+ import { Rpc, RpcTransport, SolanaRpcApi } from "@solana/kit";
4
+ //#region src/dot/IChainConnectorDot.d.ts
5
+ /** Callback signature for RPC subscriptions (error-first, matches the legacy polkadot-js ProviderInterfaceCallback) */
6
+ type SubscriptionCallback = (error: Error | null, result: any) => void;
7
7
  interface IChainConnectorDot {
8
- asProvider(chainId: DotNetworkId): ProviderInterface;
9
- send<T = unknown>(chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean, extraOptions?: {
10
- expectErrors?: boolean;
11
- }): Promise<T>;
12
- subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
13
- reset(chainId: DotNetworkId): Promise<void>;
8
+ send<T = unknown>(chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean, extraOptions?: {
9
+ expectErrors?: boolean;
10
+ }): Promise<T>;
11
+ subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: SubscriptionCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
12
+ reset(chainId: DotNetworkId): Promise<void>;
14
13
  }
15
-
14
+ //#endregion
15
+ //#region src/dot/ChainConnectorDot.d.ts
16
16
  declare class ChainConnectionError extends Error {
17
- type: "CHAIN_CONNECTION_ERROR";
18
- chainId: string;
19
- constructor(chainId: string, options?: ErrorOptions);
17
+ type: "CHAIN_CONNECTION_ERROR";
18
+ chainId: string;
19
+ constructor(chainId: string, options?: ErrorOptions);
20
20
  }
21
21
  declare class StaleRpcError extends Error {
22
- type: "STALE_RPC_ERROR";
23
- chainId: string;
24
- constructor(chainId: string, options?: ErrorOptions);
25
- }
26
- declare class WebsocketAllocationExhaustedError extends Error {
27
- type: "WEBSOCKET_ALLOCATION_EXHAUSTED_ERROR";
28
- chainId: string;
29
- constructor(chainId: string, options?: ErrorOptions);
22
+ type: "STALE_RPC_ERROR";
23
+ chainId: string;
24
+ constructor(chainId: string, options?: ErrorOptions);
30
25
  }
31
26
  /**
32
- * ChainConnector provides an interface similar to WsProvider, but with three points of difference:
27
+ * ChainConnector provides an interface similar to a websocket JSON-RPC provider, but with three points of difference:
33
28
  *
34
29
  * 1. ChainConnector methods all accept a `chainId` instead of an array of RPCs. RPCs are then fetched internally from chaindata.
35
- * 2. ChainConnector creates only one `WsProvider` per chain and ensures that all downstream requests to a chain share the one socket connection.
36
- * 3. Subscriptions return a callable `unsubscribe` method instead of an id.
30
+ * 2. ChainConnector creates only one socket connection per chain (via polkadot-api's ws-provider, which handles
31
+ * endpoint rotation, reconnection and stale-socket detection) and ensures that all downstream requests to a chain
32
+ * share that connection.
33
+ * 3. Subscriptions return a callable `unsubscribe` method instead of an id, and are automatically re-established
34
+ * when the provider reconnects (possibly to another endpoint).
37
35
  *
38
36
  * Additionally, when run on the clientside of a dapp where `window.talismanSub` is available, instead of spinning up new websocket
39
37
  * connections this class will forward all requests through to the wallet backend - where another instance of this class will
40
38
  * handle the websocket connections.
41
39
  */
42
40
  declare class ChainConnectorDot implements IChainConnectorDot {
43
- #private;
44
- constructor(chaindataChainProvider: IChaindataNetworkProvider, connectionMetaDb?: TalismanConnectionMetaDatabase);
45
- /**
46
- * Creates a facade over this ChainConnector which conforms to the PJS ProviderInterface
47
- * @example // Using a chainConnector as a Provider for an ApiPromise
48
- * const provider = chainConnector.asProvider('polkadot')
49
- * const api = new ApiPromise({ provider })
50
- */
51
- asProvider(chainId: DotNetworkId): ProviderInterface;
52
- send<T = any>(chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean | undefined, extraOptions?: {
53
- /**
54
- * Set to `true` if this query is speculative, i.e. if on some chains it's expected that it will raise a wasm unreachable error of the form:
55
- *
56
- * 4003: Client error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
57
- *
58
- * By setting expectErrors to true, this method won't pollute the logs with errors we intend to have happen.
59
- * An example use case of this is when you plan to catch the wasm unreachable error on chains that don't support the query, and then fall back
60
- * to another query or perhaps an empty result.
61
- */
62
- expectErrors?: boolean;
63
- }): Promise<T>;
64
- subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
65
- /**
66
- * Kills current websocket if any
67
- * Useful after changing rpc order to make sure it's applied for futher requests
68
- */
69
- reset(chainId: DotNetworkId): Promise<void>;
70
- /**
71
- * Wait for websocket to be ready, but don't wait forever
72
- */
73
- private waitForWs;
41
+ #private;
42
+ constructor(chaindataChainProvider: IChaindataNetworkProvider);
43
+ send<T = any>(chainId: DotNetworkId, method: string, params: unknown[], _isCacheable?: boolean | undefined, extraOptions?: {
74
44
  /**
75
- * Connect to an RPC via chainId
45
+ * Set to `true` if this query is speculative, i.e. if on some chains it's expected that it will raise a wasm unreachable error of the form:
46
+ *
47
+ * 4003: Client error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
76
48
  *
77
- * The caller must call disconnectChainSocket with the returned SocketUserId once they are finished with it
49
+ * By setting expectErrors to true, this method won't pollute the logs with errors we intend to have happen.
50
+ * An example use case of this is when you plan to catch the wasm unreachable error on chains that don't support the query, and then fall back
51
+ * to another query or perhaps an empty result.
78
52
  */
79
- private connectChainSocket;
80
- private disconnectChainSocket;
81
- private addSocketUser;
82
- private removeSocketUser;
83
- /** continues to generate a random number until it finds one which is not present in the exclude list */
84
- private getExclusiveRandomId;
85
- /** generates a random number */
86
- private getRandomId;
87
- private getTalismanSub;
88
- private updateRpcPriority;
89
- private getEndpoints;
53
+ expectErrors?: boolean;
54
+ }): Promise<T>;
55
+ subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: SubscriptionCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
56
+ /**
57
+ * Kills and recreates the connection for a chain, if any.
58
+ * Useful after changing a network's rpcs to make sure the new list is applied for further requests.
59
+ * Active subscriptions are automatically re-established on the new connection.
60
+ */
61
+ reset(chainId: DotNetworkId): Promise<void>;
62
+ /** Sends a request over a connection, throwing `Error("TIMEOUT")` if no response arrives in time */
63
+ private request;
64
+ /** Issues the subscribe request and routes notifications to the subscription callback */
65
+ private startSubscription;
66
+ /**
67
+ * Get (or create) the shared connection for a chain.
68
+ *
69
+ * The caller must call releaseConnection with the returned SocketUserId once they are finished with it.
70
+ */
71
+ private acquireConnection;
72
+ private createConnection;
73
+ private handleStatusChange;
74
+ private releaseConnection;
75
+ private destroyConnection;
76
+ private getGenesisHash;
77
+ /** continues to generate a random number until it finds one which is not present in the exclude list */
78
+ private getExclusiveRandomId;
79
+ /** generates a random number */
80
+ private getRandomId;
81
+ private getTalismanSub;
90
82
  }
91
-
83
+ //#endregion
84
+ //#region src/dot/ChainConnectorDotStub.d.ts
92
85
  declare class ChainConnectorDotStub implements IChainConnectorDot {
93
- #private;
94
- constructor(network: DotNetwork);
95
- asProvider(): ProviderInterface;
96
- send<T = unknown>(_chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean): Promise<T>;
97
- subscribe(_chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
98
- reset(): Promise<void>;
86
+ #private;
87
+ constructor(network: DotNetwork);
88
+ send<T = unknown>(_chainId: DotNetworkId, method: string, params: unknown[], _isCacheable?: boolean): Promise<T>;
89
+ subscribe(_chainId: DotNetworkId, subscribeMethod: string, _responseMethod: string, params: unknown[], callback: SubscriptionCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
90
+ reset(): Promise<void>;
91
+ destroy(): void;
99
92
  }
100
-
93
+ //#endregion
94
+ //#region src/eth/IChainConnectorEth.d.ts
101
95
  interface IChainConnectorEth {
102
- getPublicClientForEvmNetwork: (evmNetworkId: EthNetworkId) => Promise<PublicClient | null>;
103
- getWalletClientForEvmNetwork: (evmNetworkId: EthNetworkId, account?: `0x${string}` | Account) => Promise<WalletClient | null>;
104
- clearRpcProvidersCache: (evmNetworkId?: EthNetworkId) => void;
96
+ getPublicClientForEvmNetwork: (evmNetworkId: EthNetworkId) => Promise<PublicClient | null>;
97
+ getWalletClientForEvmNetwork: (evmNetworkId: EthNetworkId, account?: `0x${string}` | Account) => Promise<WalletClient | null>;
98
+ clearRpcProvidersCache: (evmNetworkId?: EthNetworkId) => void;
105
99
  }
106
-
100
+ //#endregion
101
+ //#region src/eth/ChainConnectorEth.d.ts
107
102
  declare class ChainConnectorEth implements IChainConnectorEth {
108
- #private;
109
- constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
110
- getPublicClientForEvmNetwork(evmNetworkId: EthNetworkId): Promise<PublicClient | null>;
111
- getWalletClientForEvmNetwork(evmNetworkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
112
- clearRpcProvidersCache(evmNetworkId?: EthNetworkId): void;
103
+ #private;
104
+ constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
105
+ getPublicClientForEvmNetwork(evmNetworkId: EthNetworkId): Promise<PublicClient | null>;
106
+ getWalletClientForEvmNetwork(evmNetworkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
107
+ clearRpcProvidersCache(evmNetworkId?: EthNetworkId): void;
113
108
  }
114
-
109
+ //#endregion
110
+ //#region src/eth/ChainConnectorEthStub.d.ts
115
111
  declare class ChainConnectorEthStub implements IChainConnectorEth {
116
- #private;
117
- constructor(network: EthNetwork);
118
- getPublicClientForEvmNetwork(): Promise<PublicClient | null>;
119
- getWalletClientForEvmNetwork(_networkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
120
- clearRpcProvidersCache(): void;
112
+ #private;
113
+ constructor(network: EthNetwork);
114
+ getPublicClientForEvmNetwork(): Promise<PublicClient | null>;
115
+ getWalletClientForEvmNetwork(_networkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
116
+ clearRpcProvidersCache(): void;
121
117
  }
122
-
118
+ //#endregion
119
+ //#region src/sol/getSolRpc.d.ts
120
+ type SolRpc = Rpc<SolanaRpcApi>;
121
+ declare const getSolTransport: (_networkId: SolNetworkId, rpcs: string[]) => RpcTransport;
122
+ declare const getSolRpc: (networkId: SolNetworkId, rpcs: string[]) => SolRpc;
123
+ //#endregion
124
+ //#region src/sol/IChainConnectorSol.d.ts
123
125
  interface IChainConnectorSol {
124
- getConnection: (networkId: SolNetworkId) => Promise<Connection>;
126
+ getRpc: (networkId: SolNetworkId) => Promise<SolRpc>;
127
+ /** Raw JSON-RPC transport, used by the background script to relay frontend RPC requests */
128
+ getTransport: (networkId: SolNetworkId) => Promise<RpcTransport>;
125
129
  }
126
-
130
+ //#endregion
131
+ //#region src/sol/ChainConnectorSol.d.ts
127
132
  declare class ChainConnectorSol implements IChainConnectorSol {
128
- #private;
129
- constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
130
- getConnection(networkId: SolNetworkId): Promise<Connection>;
133
+ #private;
134
+ constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
135
+ getTransport(networkId: SolNetworkId): Promise<RpcTransport>;
136
+ getRpc(networkId: SolNetworkId): Promise<SolRpc>;
137
+ /** Drops cached transports/rpcs so the next call re-reads the network's rpcs from chaindata */
138
+ clearRpcProvidersCache(networkId?: SolNetworkId): void;
131
139
  }
132
-
140
+ //#endregion
141
+ //#region src/sol/ChainConnectorSolStub.d.ts
133
142
  declare class ChainConnectorSolStub implements IChainConnectorSol {
134
- #private;
135
- constructor(networkOrConnection: Pick<SolNetwork, "id" | "rpcs"> | Connection);
136
- getConnection(): Promise<Connection>;
143
+ #private;
144
+ constructor(network: Pick<SolNetwork, "id" | "rpcs">);
145
+ getRpc(): Promise<SolRpc>;
146
+ getTransport(): Promise<RpcTransport>;
137
147
  }
138
-
139
- export { ChainConnectionError, ChainConnectorDot, ChainConnectorDotStub, ChainConnectorEth, ChainConnectorEthStub, ChainConnectorSol, ChainConnectorSolStub, type IChainConnectorDot, type IChainConnectorEth, type IChainConnectorSol, StaleRpcError, WebsocketAllocationExhaustedError };
148
+ //#endregion
149
+ export { ChainConnectionError, ChainConnectorDot, ChainConnectorDotStub, ChainConnectorEth, ChainConnectorEthStub, ChainConnectorSol, ChainConnectorSolStub, IChainConnectorDot, IChainConnectorEth, IChainConnectorSol, SolRpc, StaleRpcError, SubscriptionCallback, getSolRpc, getSolTransport };
150
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/dot/IChainConnectorDot.ts","../src/dot/ChainConnectorDot.ts","../src/dot/ChainConnectorDotStub.ts","../src/eth/IChainConnectorEth.ts","../src/eth/ChainConnectorEth.ts","../src/eth/ChainConnectorEthStub.ts","../src/sol/getS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