solana-web3-on-steroids 1.0.2
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/LICENSE +21 -0
- package/README.md +86 -0
- package/dist/client/SteroidClient.d.ts +55 -0
- package/dist/client/SteroidClient.js +131 -0
- package/dist/client/SteroidClient.js.map +1 -0
- package/dist/connection/SteroidConnection.d.ts +96 -0
- package/dist/connection/SteroidConnection.js +323 -0
- package/dist/connection/SteroidConnection.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/transaction/SteroidTransaction.d.ts +58 -0
- package/dist/transaction/SteroidTransaction.js +275 -0
- package/dist/transaction/SteroidTransaction.js.map +1 -0
- package/dist/types/SteroidWalletTypes.d.ts +185 -0
- package/dist/types/SteroidWalletTypes.js +56 -0
- package/dist/types/SteroidWalletTypes.js.map +1 -0
- package/dist/wallet/SteroidWallet.d.ts +85 -0
- package/dist/wallet/SteroidWallet.js +270 -0
- package/dist/wallet/SteroidWallet.js.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 solana-web3.js-on_steroids contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Solana web3.js on Steroids ⚙️🧱
|
|
2
|
+
|
|
3
|
+
**A systems-grade resilience layer for `@solana/web3.js`**
|
|
4
|
+
|
|
5
|
+
Solana UX today is fragile: wallet adapters leak abstractions, RPC behavior is inconsistent, and many integrations fall short of production-grade reliability. **Solana on Steroids** treats crypto UX correctness as a systems problem, making network instability and RPC variability invisible to your users.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/solana-web3-on-steroids)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 🌩 The Problem: The "Fragile UX" Trap
|
|
13
|
+
|
|
14
|
+
Standard Solana dApps often suffer from:
|
|
15
|
+
- **Node Lag**: Node A says "confirmed," but Node B (used by the app) says "not found."
|
|
16
|
+
- **Ghost Transactions**: Transactions dropped during congestion with no clear recovery path.
|
|
17
|
+
- **RPC Single-Point-of-Failure**: If your primary RPC provider hiccups, your entire app freezes.
|
|
18
|
+
- **Cryptic Errors**: Raw hex logs and "Simulation failed" messages that confuse users.
|
|
19
|
+
|
|
20
|
+
## 💊 The Solution: Systems-Grade Resilience
|
|
21
|
+
|
|
22
|
+
This library wraps `@solana/web3.js` in a robust, automated engine that handles the edge cases of a high-performance blockchain.
|
|
23
|
+
|
|
24
|
+
### 1. Transparent RPC Failover (Proxy Pattern)
|
|
25
|
+
Uses a JS `Proxy` to wrap the `Connection` object. If a node failure (5xx, network error) is detected, it automatically swaps to a healthy fallback node mid-request. **Your app code stays "dumb" while the infra stays smart.**
|
|
26
|
+
|
|
27
|
+
### 2. Multi-Node Confirmation Polling
|
|
28
|
+
Doesn't trust a single node's word. It polls multiple RPC providers simultaneously for signature status to bypass node lag and ensure the fastest possible confirmation UI.
|
|
29
|
+
|
|
30
|
+
### 3. Continuous Re-broadcasting Loop
|
|
31
|
+
Transactions are "babysat" by an engine that refreshes blockhashes and re-broadcasts automatically until a definitive landing or expiration occurs.
|
|
32
|
+
|
|
33
|
+
### 4. Intelligent Simulation Parsing
|
|
34
|
+
Intercepts simulation logs and translates raw program errors into human-readable insights *before* the user even signs.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🚀 Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install solana-web3-on-steroids
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 🛠 Quick Start
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { SteroidClient } from 'solana-web3-on-steroids';
|
|
48
|
+
|
|
49
|
+
const client = new SteroidClient('https://api.mainnet-beta.solana.com', {
|
|
50
|
+
fallbacks: [
|
|
51
|
+
'https://solana-mainnet.rpc.extrnode.com',
|
|
52
|
+
'https://api.alchemy.com/v2/your-key'
|
|
53
|
+
],
|
|
54
|
+
maxRetries: 5,
|
|
55
|
+
enableLogging: true
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Use it exactly like a standard @solana/web3.js Connection
|
|
59
|
+
const balance = await client.connection.getBalance(myPublicKey);
|
|
60
|
+
|
|
61
|
+
// Connect a wallet adapter for steroidal transactions
|
|
62
|
+
const steroidWallet = client.connectWallet(walletAdapter);
|
|
63
|
+
const signature = await steroidWallet.signAndSend(transaction);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 🧬 Core Architecture
|
|
67
|
+
|
|
68
|
+
### `SteroidConnection`
|
|
69
|
+
A resilient proxy for `web3.js.Connection`.
|
|
70
|
+
- **Health Heartbeat**: Background pings monitor latency and uptime across all fallbacks.
|
|
71
|
+
- **Error classification**: Distinguishes between **Transient** errors (retry same node) and **Node Failures** (failover to next node).
|
|
72
|
+
|
|
73
|
+
### `SteroidTransaction`
|
|
74
|
+
The heavy-duty engine for submission and confirmation.
|
|
75
|
+
- **Signature Polling**: Parallel checks across `confirmationNodes`.
|
|
76
|
+
- **Blockhash Refresh**: Automatically re-fetches `recentBlockhash` if the transaction has been pending too long, preventing expiration before signing.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 📜 License
|
|
81
|
+
|
|
82
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
|
83
|
+
|
|
84
|
+
## 🤝 Contributing
|
|
85
|
+
|
|
86
|
+
We treat reliability as a first-class citizen. If you find an edge case where a transaction could be lost or an RPC error could be better handled, please open an issue or PR.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { SteroidWallet } from '../wallet/SteroidWallet.js';
|
|
2
|
+
import { SteroidTransaction } from '../transaction/SteroidTransaction.js';
|
|
3
|
+
import { SteroidClientConfig, SteroidWalletConfig, ClientStats, RPCHealth, WalletInterface } from '../types/SteroidWalletTypes.js';
|
|
4
|
+
/**
|
|
5
|
+
* SteroidClient is the main entry point for the Wallet UX Reliability Layer.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Resilient RPC connections with automatic failover
|
|
9
|
+
* - Smart transaction handling with retries and blockhash refresh
|
|
10
|
+
* - Normalized wallet error handling
|
|
11
|
+
* - Production-grade reliability out of the box
|
|
12
|
+
*/
|
|
13
|
+
export declare class SteroidClient {
|
|
14
|
+
private connection;
|
|
15
|
+
private transactionEngine;
|
|
16
|
+
private config;
|
|
17
|
+
private isDestroyed;
|
|
18
|
+
/**
|
|
19
|
+
* Initialize a new SteroidClient.
|
|
20
|
+
*
|
|
21
|
+
* @param endpoint The primary Solana RPC endpoint (or array of endpoints)
|
|
22
|
+
* @param config Optional configuration for connection and wallet behavior
|
|
23
|
+
*/
|
|
24
|
+
constructor(endpoint: string | string[], config?: SteroidClientConfig);
|
|
25
|
+
/**
|
|
26
|
+
* Connect a wallet to the Steroid reliability layer.
|
|
27
|
+
*
|
|
28
|
+
* @param wallet A standard Solana wallet adapter
|
|
29
|
+
* @param walletConfig Optional overrides for this specific wallet
|
|
30
|
+
* @returns A SteroidWallet instance with enhanced reliability
|
|
31
|
+
*/
|
|
32
|
+
connectWallet(wallet: WalletInterface, walletConfig?: SteroidWalletConfig): SteroidWallet;
|
|
33
|
+
/**
|
|
34
|
+
* Get the underlying transaction engine for advanced use cases.
|
|
35
|
+
*/
|
|
36
|
+
getTransactionEngine(): SteroidTransaction;
|
|
37
|
+
/**
|
|
38
|
+
* Trigger a manual health check across all RPC nodes.
|
|
39
|
+
*/
|
|
40
|
+
checkAllHealth(): Promise<RPCHealth[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Get detailed statistics about RPC performance and failovers.
|
|
43
|
+
*/
|
|
44
|
+
getStats(): ClientStats;
|
|
45
|
+
/**
|
|
46
|
+
* Cleanup resources and stop background monitors.
|
|
47
|
+
*/
|
|
48
|
+
destroy(): void;
|
|
49
|
+
private ensureNotDestroyed;
|
|
50
|
+
private log;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Convenience factory function to create a SteroidClient.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createSteroidClient(endpoint: string | string[], config?: SteroidClientConfig): SteroidClient;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { SteroidConnection } from '../connection/SteroidConnection.js';
|
|
2
|
+
import { SteroidWallet } from '../wallet/SteroidWallet.js';
|
|
3
|
+
import { SteroidTransaction } from '../transaction/SteroidTransaction.js';
|
|
4
|
+
import { DEFAULT_CONFIG } from '../types/SteroidWalletTypes.js';
|
|
5
|
+
/**
|
|
6
|
+
* SteroidClient is the main entry point for the Wallet UX Reliability Layer.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Resilient RPC connections with automatic failover
|
|
10
|
+
* - Smart transaction handling with retries and blockhash refresh
|
|
11
|
+
* - Normalized wallet error handling
|
|
12
|
+
* - Production-grade reliability out of the box
|
|
13
|
+
*/
|
|
14
|
+
export class SteroidClient {
|
|
15
|
+
connection;
|
|
16
|
+
transactionEngine;
|
|
17
|
+
config;
|
|
18
|
+
isDestroyed = false;
|
|
19
|
+
/**
|
|
20
|
+
* Initialize a new SteroidClient.
|
|
21
|
+
*
|
|
22
|
+
* @param endpoint The primary Solana RPC endpoint (or array of endpoints)
|
|
23
|
+
* @param config Optional configuration for connection and wallet behavior
|
|
24
|
+
*/
|
|
25
|
+
constructor(endpoint, config = {}) {
|
|
26
|
+
this.config = config;
|
|
27
|
+
// Initialize resilient connection
|
|
28
|
+
const endpoints = Array.isArray(endpoint) ? endpoint : [endpoint];
|
|
29
|
+
const [primary, ...additionalFallbacks] = endpoints;
|
|
30
|
+
const connectionConfig = {
|
|
31
|
+
...DEFAULT_CONFIG.CONNECTION,
|
|
32
|
+
...config.connection,
|
|
33
|
+
fallbacks: [
|
|
34
|
+
...(config.connection?.fallbacks || []),
|
|
35
|
+
...additionalFallbacks
|
|
36
|
+
],
|
|
37
|
+
enableLogging: config.enableLogging ?? config.connection?.enableLogging ?? DEFAULT_CONFIG.CONNECTION.enableLogging,
|
|
38
|
+
};
|
|
39
|
+
this.connection = new SteroidConnection(primary, connectionConfig);
|
|
40
|
+
this.transactionEngine = new SteroidTransaction(this.connection);
|
|
41
|
+
this.log('info', 'Initialized with endpoint(s):', endpoint);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Connect a wallet to the Steroid reliability layer.
|
|
45
|
+
*
|
|
46
|
+
* @param wallet A standard Solana wallet adapter
|
|
47
|
+
* @param walletConfig Optional overrides for this specific wallet
|
|
48
|
+
* @returns A SteroidWallet instance with enhanced reliability
|
|
49
|
+
*/
|
|
50
|
+
connectWallet(wallet, walletConfig = {}) {
|
|
51
|
+
this.ensureNotDestroyed();
|
|
52
|
+
const mergedConfig = {
|
|
53
|
+
...DEFAULT_CONFIG.WALLET,
|
|
54
|
+
...this.config.wallet,
|
|
55
|
+
...walletConfig,
|
|
56
|
+
enableLogging: this.config.enableLogging ?? walletConfig.enableLogging ?? DEFAULT_CONFIG.WALLET.enableLogging,
|
|
57
|
+
};
|
|
58
|
+
return new SteroidWallet(wallet, this.connection, mergedConfig);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the underlying transaction engine for advanced use cases.
|
|
62
|
+
*/
|
|
63
|
+
getTransactionEngine() {
|
|
64
|
+
this.ensureNotDestroyed();
|
|
65
|
+
return this.transactionEngine;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Trigger a manual health check across all RPC nodes.
|
|
69
|
+
*/
|
|
70
|
+
async checkAllHealth() {
|
|
71
|
+
this.ensureNotDestroyed();
|
|
72
|
+
return await this.connection.checkHealth();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get detailed statistics about RPC performance and failovers.
|
|
76
|
+
*/
|
|
77
|
+
getStats() {
|
|
78
|
+
this.ensureNotDestroyed();
|
|
79
|
+
return {
|
|
80
|
+
activeEndpoint: this.connection.getActiveEndpoint(),
|
|
81
|
+
allEndpoints: this.connection.getEndpoints(),
|
|
82
|
+
failoverStats: this.connection.getFailoverStats(),
|
|
83
|
+
healthStatus: this.connection.getHealthStatus(),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Cleanup resources and stop background monitors.
|
|
88
|
+
*/
|
|
89
|
+
destroy() {
|
|
90
|
+
if (this.isDestroyed)
|
|
91
|
+
return;
|
|
92
|
+
this.connection.destroy();
|
|
93
|
+
this.isDestroyed = true;
|
|
94
|
+
this.log('info', 'Destroyed');
|
|
95
|
+
}
|
|
96
|
+
ensureNotDestroyed() {
|
|
97
|
+
if (this.isDestroyed) {
|
|
98
|
+
throw new Error('[SteroidClient] Cannot execute operation: instance is already destroyed');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
log(level, ...args) {
|
|
102
|
+
if (!this.config.enableLogging)
|
|
103
|
+
return;
|
|
104
|
+
const prefix = '[SteroidClient]';
|
|
105
|
+
const finalArgs = [...args];
|
|
106
|
+
if (typeof finalArgs[0] === 'string') {
|
|
107
|
+
finalArgs[0] = `${prefix} ${finalArgs[0]}`;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
finalArgs.unshift(prefix);
|
|
111
|
+
}
|
|
112
|
+
switch (level) {
|
|
113
|
+
case 'info':
|
|
114
|
+
console.log(...finalArgs);
|
|
115
|
+
break;
|
|
116
|
+
case 'warn':
|
|
117
|
+
console.warn(...finalArgs);
|
|
118
|
+
break;
|
|
119
|
+
case 'error':
|
|
120
|
+
console.error(...finalArgs);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Convenience factory function to create a SteroidClient.
|
|
127
|
+
*/
|
|
128
|
+
export function createSteroidClient(endpoint, config) {
|
|
129
|
+
return new SteroidClient(endpoint, config);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=SteroidClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SteroidClient.js","sourceRoot":"","sources":["../../src/client/SteroidClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAOL,cAAc,EACf,MAAM,gCAAgC,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,OAAO,aAAa;IAChB,UA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M,MAAM,GAAG,iBAAiB,CAAC;QACjC,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;QAC5B,IAAI,OAAO,SAAS,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YACrC,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;QAED,QAAQ,KAAK,EAAE,CAAC;YACd,KAAK,MAAM;gBACT,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC;gBAC1B,MAAM;YACR,KAAK,MAAM;gBACT,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;gBAC3B,MAAM;YACR,KAAK,OAAO;gBACV,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC;gBAC5B,MAAM;QACV,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAA2B,EAC3B,MAA4B;IAE5B,OAAO,IAAI,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { SteroidConnectionConfig, RPCHealth } from '../types/SteroidWalletTypes.js';
|
|
2
|
+
/**
|
|
3
|
+
* SteroidConnection uses a Proxy pattern to wrap a real @solana/web3.js Connection.
|
|
4
|
+
* This allows swapping the underlying connection (and its internal state/websockets)
|
|
5
|
+
* transparently when a failover occurs.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SteroidConnection {
|
|
8
|
+
private static readonly DEFAULT_HEALTH_CHECK_TIMEOUT_MS;
|
|
9
|
+
private static readonly MAX_BACKOFF_DELAY_MS;
|
|
10
|
+
private static readonly JITTER_MS;
|
|
11
|
+
private activeConnection;
|
|
12
|
+
private urls;
|
|
13
|
+
private currentUrlIndex;
|
|
14
|
+
private config;
|
|
15
|
+
private steroidConfig;
|
|
16
|
+
private healthStatus;
|
|
17
|
+
private healthCheckTimer?;
|
|
18
|
+
private failoverCount;
|
|
19
|
+
private lastFailoverTime;
|
|
20
|
+
constructor(endpoint: string, config?: SteroidConnectionConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Executes a connection method with intelligent retries and failover.
|
|
23
|
+
*/
|
|
24
|
+
private executeWithResilience;
|
|
25
|
+
/**
|
|
26
|
+
* Internal helper to execute a method with a promise-based timeout and AbortController.
|
|
27
|
+
* This effectively cancels the underlying network request on timeout.
|
|
28
|
+
*/
|
|
29
|
+
private callWithTimeout;
|
|
30
|
+
/**
|
|
31
|
+
* Updates health status for a specific URL.
|
|
32
|
+
*/
|
|
33
|
+
private updateHealthStatus;
|
|
34
|
+
/**
|
|
35
|
+
* Decides whether to retry or failover based on the error.
|
|
36
|
+
* @returns true if the loop should continue (retry or failover), false if it should throw.
|
|
37
|
+
*/
|
|
38
|
+
private handleExecutionError;
|
|
39
|
+
private parseErrorContext;
|
|
40
|
+
/**
|
|
41
|
+
* Identifies transient errors that should be retried on the same node (e.g. rate limits).
|
|
42
|
+
*/
|
|
43
|
+
private isTransientError;
|
|
44
|
+
/**
|
|
45
|
+
* Identifies node-level failures that should trigger a failover to a different RPC.
|
|
46
|
+
*/
|
|
47
|
+
private isNodeFailure;
|
|
48
|
+
/**
|
|
49
|
+
* Switches to the next available RPC node.
|
|
50
|
+
*/
|
|
51
|
+
private switchToNextRpc;
|
|
52
|
+
/**
|
|
53
|
+
* Finds the index of the next healthy RPC, or the very next one if all are unhealthy.
|
|
54
|
+
*/
|
|
55
|
+
private findNextAvailableRpcIndex;
|
|
56
|
+
private calculateBackoff;
|
|
57
|
+
private sleep;
|
|
58
|
+
private enhanceError;
|
|
59
|
+
private log;
|
|
60
|
+
/**
|
|
61
|
+
* Perform health checks on all RPC endpoints.
|
|
62
|
+
*/
|
|
63
|
+
private performHealthCheck;
|
|
64
|
+
/**
|
|
65
|
+
* Internal helper to check the health of a single RPC node.
|
|
66
|
+
*/
|
|
67
|
+
private checkNodeHealth;
|
|
68
|
+
private startHealthChecks;
|
|
69
|
+
/**
|
|
70
|
+
* Clean up resources when done.
|
|
71
|
+
*/
|
|
72
|
+
destroy(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get all endpoints for multi-node verification.
|
|
75
|
+
*/
|
|
76
|
+
getEndpoints(): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Get current active endpoint.
|
|
79
|
+
*/
|
|
80
|
+
getActiveEndpoint(): string;
|
|
81
|
+
/**
|
|
82
|
+
* Get health status of all endpoints.
|
|
83
|
+
*/
|
|
84
|
+
getHealthStatus(): RPCHealth[];
|
|
85
|
+
/**
|
|
86
|
+
* Get failover statistics.
|
|
87
|
+
*/
|
|
88
|
+
getFailoverStats(): {
|
|
89
|
+
count: number;
|
|
90
|
+
lastTime: number;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Manually trigger a health check.
|
|
94
|
+
*/
|
|
95
|
+
checkHealth(): Promise<RPCHealth[]>;
|
|
96
|
+
}
|