@cfxdevkit/core 0.1.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/CHANGELOG.md +35 -0
- package/LICENSE +72 -0
- package/README.md +257 -0
- package/dist/clients/index.cjs +2053 -0
- package/dist/clients/index.cjs.map +1 -0
- package/dist/clients/index.d.cts +7 -0
- package/dist/clients/index.d.ts +7 -0
- package/dist/clients/index.js +2043 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/config/index.cjs +423 -0
- package/dist/config/index.cjs.map +1 -0
- package/dist/config/index.d.cts +99 -0
- package/dist/config/index.d.ts +99 -0
- package/dist/config/index.js +380 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config-BMtaWM0X.d.cts +165 -0
- package/dist/config-BMtaWM0X.d.ts +165 -0
- package/dist/core-C5qe16RS.d.ts +352 -0
- package/dist/core-RZA4aKwj.d.cts +352 -0
- package/dist/index-BhCpy6Fz.d.cts +165 -0
- package/dist/index-Qz84U9Oq.d.ts +165 -0
- package/dist/index.cjs +3773 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +945 -0
- package/dist/index.d.ts +945 -0
- package/dist/index.js +3730 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.cjs +44 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +5 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +17 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +83 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +11 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +56 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/wallet/index.cjs +852 -0
- package/dist/wallet/index.cjs.map +1 -0
- package/dist/wallet/index.d.cts +726 -0
- package/dist/wallet/index.d.ts +726 -0
- package/dist/wallet/index.js +815 -0
- package/dist/wallet/index.js.map +1 -0
- package/package.json +119 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import './config/index.cjs';
|
|
2
|
+
import { C as ChainType, A as Address, B as BaseTransaction, T as TransactionReceipt, E as EventCallback, a as BlockEvent, U as UnwatchFunction, b as TransactionEvent } from './config-BMtaWM0X.cjs';
|
|
3
|
+
import { Address as Address$2, PublicClient as PublicClient$1, WalletClient as WalletClient$2, TestClient as TestClient$1 } from 'cive';
|
|
4
|
+
import { PublicClient, Chain, Address as Address$1, WalletClient as WalletClient$1 } from 'viem';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Unified interface for both Core and EVM clients
|
|
8
|
+
* Abstracts away the differences between cive and viem
|
|
9
|
+
*/
|
|
10
|
+
interface ChainClient {
|
|
11
|
+
readonly chainType: ChainType;
|
|
12
|
+
readonly chainId: number;
|
|
13
|
+
readonly address: Address;
|
|
14
|
+
getBlockNumber(): Promise<bigint>;
|
|
15
|
+
getBalance(address: Address): Promise<string>;
|
|
16
|
+
getGasPrice(): Promise<bigint>;
|
|
17
|
+
estimateGas(tx: BaseTransaction): Promise<bigint>;
|
|
18
|
+
sendTransaction(tx: BaseTransaction): Promise<string>;
|
|
19
|
+
waitForTransaction(hash: string): Promise<TransactionReceipt>;
|
|
20
|
+
getTokenBalance(tokenAddress: Address, holderAddress?: Address): Promise<string>;
|
|
21
|
+
watchBlocks(callback: EventCallback<BlockEvent>): UnwatchFunction;
|
|
22
|
+
watchTransactions(callback: EventCallback<TransactionEvent>): UnwatchFunction;
|
|
23
|
+
isValidAddress(address: string): boolean;
|
|
24
|
+
formatAmount(amount: bigint): string;
|
|
25
|
+
parseAmount(amount: string): bigint;
|
|
26
|
+
getInternalClient(): unknown;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Wallet client interface for signing transactions
|
|
30
|
+
*/
|
|
31
|
+
interface WalletClient {
|
|
32
|
+
readonly address: Address;
|
|
33
|
+
readonly chainType: ChainType;
|
|
34
|
+
sendTransaction(tx: BaseTransaction): Promise<string>;
|
|
35
|
+
signMessage(message: string): Promise<string>;
|
|
36
|
+
getInternalClient(): unknown;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Test client interface for development operations
|
|
40
|
+
*/
|
|
41
|
+
interface TestClient extends ChainClient {
|
|
42
|
+
mine(blocks?: number): Promise<void>;
|
|
43
|
+
setNextBlockTimestamp(timestamp: number): Promise<void>;
|
|
44
|
+
increaseTime(seconds: number): Promise<void>;
|
|
45
|
+
impersonateAccount(address: Address): Promise<void>;
|
|
46
|
+
stopImpersonatingAccount(address: Address): Promise<void>;
|
|
47
|
+
setBalance(address: Address, balance: bigint): Promise<void>;
|
|
48
|
+
getStorageAt(address: Address, slot: string): Promise<string>;
|
|
49
|
+
setStorageAt(address: Address, slot: string, value: string): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Client factory interface
|
|
53
|
+
*/
|
|
54
|
+
interface ClientFactory {
|
|
55
|
+
createPublicClient(chainType: ChainType, config: ClientConfig): ChainClient;
|
|
56
|
+
createWalletClient(chainType: ChainType, config: WalletConfig): WalletClient;
|
|
57
|
+
createTestClient(chainType: ChainType, config: TestConfig): TestClient;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Configuration interfaces for client creation
|
|
61
|
+
*/
|
|
62
|
+
interface ClientConfig {
|
|
63
|
+
readonly rpcUrl: string;
|
|
64
|
+
readonly wsUrl?: string;
|
|
65
|
+
readonly chainId: number;
|
|
66
|
+
readonly pollingInterval?: number;
|
|
67
|
+
readonly account?: string | {
|
|
68
|
+
privateKey: string;
|
|
69
|
+
accountIndex?: number;
|
|
70
|
+
};
|
|
71
|
+
readonly testMode?: boolean;
|
|
72
|
+
}
|
|
73
|
+
interface WalletConfig extends ClientConfig {
|
|
74
|
+
readonly privateKey: string;
|
|
75
|
+
readonly accountIndex?: number;
|
|
76
|
+
}
|
|
77
|
+
interface TestConfig extends ClientConfig {
|
|
78
|
+
readonly enableTestMode: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Client manager interface
|
|
82
|
+
* Manages lifecycle of both Core and EVM clients
|
|
83
|
+
*/
|
|
84
|
+
interface ClientManager {
|
|
85
|
+
initialize(): Promise<void>;
|
|
86
|
+
shutdown(): Promise<void>;
|
|
87
|
+
getCoreClient(): ChainClient;
|
|
88
|
+
getEvmClient(): ChainClient;
|
|
89
|
+
getCoreWalletClient(accountIndex?: number): WalletClient;
|
|
90
|
+
getEvmWalletClient(accountIndex?: number): WalletClient;
|
|
91
|
+
getCoreTestClient(): TestClient;
|
|
92
|
+
getEvmTestClient(): TestClient;
|
|
93
|
+
isInitialized(): boolean;
|
|
94
|
+
getStatus(): {
|
|
95
|
+
core: {
|
|
96
|
+
isConnected: boolean;
|
|
97
|
+
blockNumber: bigint;
|
|
98
|
+
};
|
|
99
|
+
evm: {
|
|
100
|
+
isConnected: boolean;
|
|
101
|
+
blockNumber: bigint;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
checkHealth(): Promise<boolean>;
|
|
105
|
+
on(event: 'block', callback: EventCallback<BlockEvent>): void;
|
|
106
|
+
on(event: 'transaction', callback: EventCallback<TransactionEvent>): void;
|
|
107
|
+
on(event: 'error', callback: EventCallback<Error>): void;
|
|
108
|
+
off(event: 'block', callback: EventCallback<BlockEvent>): void;
|
|
109
|
+
off(event: 'transaction', callback: EventCallback<TransactionEvent>): void;
|
|
110
|
+
off(event: 'error', callback: EventCallback<Error>): void;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* EVM Space (eSpace) Client Implementation
|
|
115
|
+
* Provides unified interface for Ethereum-compatible operations on Conflux eSpace
|
|
116
|
+
*/
|
|
117
|
+
declare class EspaceClient implements ChainClient {
|
|
118
|
+
readonly chainId: number;
|
|
119
|
+
readonly chainType: "evm";
|
|
120
|
+
readonly publicClient: PublicClient;
|
|
121
|
+
protected readonly chain: Chain;
|
|
122
|
+
address: Address$1;
|
|
123
|
+
constructor(config: ClientConfig);
|
|
124
|
+
getBlockNumber(): Promise<bigint>;
|
|
125
|
+
getBalance(address: Address$1): Promise<string>;
|
|
126
|
+
estimateGas(tx: BaseTransaction): Promise<bigint>;
|
|
127
|
+
waitForTransaction(hash: string): Promise<TransactionReceipt>;
|
|
128
|
+
getGasPrice(): Promise<bigint>;
|
|
129
|
+
/**
|
|
130
|
+
* Get the current chain ID from the network
|
|
131
|
+
*/
|
|
132
|
+
getChainId(): Promise<number>;
|
|
133
|
+
/**
|
|
134
|
+
* Check if the client is connected to the network
|
|
135
|
+
*/
|
|
136
|
+
isConnected(): Promise<boolean>;
|
|
137
|
+
sendTransaction(_tx: BaseTransaction): Promise<string>;
|
|
138
|
+
getTokenBalance(_address: string, _tokenAddress: string): Promise<string>;
|
|
139
|
+
watchBlocks(callback: EventCallback<BlockEvent>): () => void;
|
|
140
|
+
watchTransaction(_hash: string, _callback: (receipt: TransactionReceipt) => void): Promise<() => void>;
|
|
141
|
+
getInternalClient(): PublicClient | WalletClient$1;
|
|
142
|
+
watchTransactions(_callback: EventCallback<TransactionEvent>): () => void;
|
|
143
|
+
isValidAddress(address: string): boolean;
|
|
144
|
+
formatAmount(amount: bigint): string;
|
|
145
|
+
parseAmount(amount: string): bigint;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* EVM Space Wallet Client
|
|
149
|
+
* Extends EspaceClient with transaction and account functionality
|
|
150
|
+
*/
|
|
151
|
+
declare class EspaceWalletClient extends EspaceClient implements WalletClient {
|
|
152
|
+
private readonly walletClient;
|
|
153
|
+
private readonly account;
|
|
154
|
+
constructor(config: ClientConfig & {
|
|
155
|
+
privateKey: string;
|
|
156
|
+
});
|
|
157
|
+
getAddress(): Address$1;
|
|
158
|
+
sendTransaction(tx: BaseTransaction): Promise<string>;
|
|
159
|
+
signMessage(message: string): Promise<string>;
|
|
160
|
+
deployContract(abi: unknown[], bytecode: string, constructorArgs?: unknown[]): Promise<string>;
|
|
161
|
+
callContract<T = unknown>(address: string, abi: unknown[], functionName: string, args?: unknown[]): Promise<T>;
|
|
162
|
+
writeContract(address: string, abi: unknown[], functionName: string, args?: unknown[], value?: bigint): Promise<string>;
|
|
163
|
+
/**
|
|
164
|
+
* Transfer CFX from eSpace to Core Space
|
|
165
|
+
* Uses the built-in withdrawal mechanism
|
|
166
|
+
*/
|
|
167
|
+
faucetToCore(coreAddress: string, amount: string): Promise<string>;
|
|
168
|
+
getInternalClient(): PublicClient | WalletClient$1;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* EVM Space Test Client
|
|
172
|
+
* Extends EspaceWalletClient with additional testing utilities
|
|
173
|
+
*/
|
|
174
|
+
declare class EspaceTestClient extends EspaceWalletClient implements TestClient {
|
|
175
|
+
private readonly testClient;
|
|
176
|
+
constructor(config: TestConfig & {
|
|
177
|
+
privateKey: string;
|
|
178
|
+
});
|
|
179
|
+
mine(blocks?: number): Promise<void>;
|
|
180
|
+
setNextBlockTimestamp(timestamp: number): Promise<void>;
|
|
181
|
+
increaseTime(seconds: number): Promise<void>;
|
|
182
|
+
impersonateAccount(address: string): Promise<void>;
|
|
183
|
+
stopImpersonatingAccount(address: string): Promise<void>;
|
|
184
|
+
setBalance(address: string, balance: bigint): Promise<void>;
|
|
185
|
+
snapshot(): Promise<string>;
|
|
186
|
+
revert(snapshotId: string): Promise<void>;
|
|
187
|
+
getStorageAt(address: string, slot: string): Promise<string>;
|
|
188
|
+
setStorageAt(address: string, slot: string, value: string): Promise<void>;
|
|
189
|
+
watchTransactions(callback: EventCallback<TransactionEvent>): () => void;
|
|
190
|
+
isValidAddress(address: string): boolean;
|
|
191
|
+
getCurrentEpoch(): Promise<bigint>;
|
|
192
|
+
generateAccounts(count: number): Promise<string[]>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
type HealthStatus = 'healthy' | 'unhealthy' | 'disconnected' | 'unknown';
|
|
196
|
+
|
|
197
|
+
interface CoreClientInstance {
|
|
198
|
+
publicClient: CoreClient;
|
|
199
|
+
walletClient?: CoreWalletClient;
|
|
200
|
+
testClient?: CoreTestClient;
|
|
201
|
+
}
|
|
202
|
+
interface EspaceClientInstance {
|
|
203
|
+
publicClient: EspaceClient;
|
|
204
|
+
walletClient?: EspaceWalletClient;
|
|
205
|
+
testClient?: EspaceTestClient;
|
|
206
|
+
}
|
|
207
|
+
interface StartOptions {
|
|
208
|
+
mining?: boolean;
|
|
209
|
+
waitForBlocks?: number;
|
|
210
|
+
fundingAmount?: string;
|
|
211
|
+
}
|
|
212
|
+
interface DeployOptions {
|
|
213
|
+
abi: unknown[];
|
|
214
|
+
bytecode: string;
|
|
215
|
+
args?: unknown[];
|
|
216
|
+
account: number;
|
|
217
|
+
chain?: 'core' | 'evm';
|
|
218
|
+
chains?: ('core' | 'evm')[];
|
|
219
|
+
value?: bigint;
|
|
220
|
+
}
|
|
221
|
+
interface ReadOptions {
|
|
222
|
+
address: string;
|
|
223
|
+
abi: unknown[];
|
|
224
|
+
functionName: string;
|
|
225
|
+
args?: unknown[];
|
|
226
|
+
chain: 'core' | 'evm';
|
|
227
|
+
}
|
|
228
|
+
interface WriteOptions {
|
|
229
|
+
address: string;
|
|
230
|
+
abi: unknown[];
|
|
231
|
+
functionName: string;
|
|
232
|
+
args?: unknown[];
|
|
233
|
+
account: number;
|
|
234
|
+
chain: 'core' | 'evm';
|
|
235
|
+
value?: bigint;
|
|
236
|
+
waitForConfirmation?: boolean;
|
|
237
|
+
}
|
|
238
|
+
interface ContractResult {
|
|
239
|
+
core?: string;
|
|
240
|
+
evm?: string;
|
|
241
|
+
}
|
|
242
|
+
interface ChainStatus {
|
|
243
|
+
core: {
|
|
244
|
+
connected: boolean;
|
|
245
|
+
status: string;
|
|
246
|
+
};
|
|
247
|
+
evm: {
|
|
248
|
+
connected: boolean;
|
|
249
|
+
status: string;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
interface FaucetBalances {
|
|
253
|
+
coreBalance: string;
|
|
254
|
+
evmBalance: string;
|
|
255
|
+
}
|
|
256
|
+
interface MiningStatus {
|
|
257
|
+
isRunning: boolean;
|
|
258
|
+
interval: number;
|
|
259
|
+
blocksMined: number;
|
|
260
|
+
startTime?: Date;
|
|
261
|
+
}
|
|
262
|
+
interface ChainBalances {
|
|
263
|
+
core: string;
|
|
264
|
+
evm: string;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Core Space Client Implementation
|
|
269
|
+
* Wraps cive client with unified interface
|
|
270
|
+
*/
|
|
271
|
+
declare class CoreClient implements ChainClient {
|
|
272
|
+
readonly chainType: "core";
|
|
273
|
+
readonly chainId: number;
|
|
274
|
+
readonly address: Address$2;
|
|
275
|
+
private readonly publicClient;
|
|
276
|
+
private readonly chain;
|
|
277
|
+
constructor(config: ClientConfig);
|
|
278
|
+
getBlockNumber(): Promise<bigint>;
|
|
279
|
+
getBalance(address: Address$2): Promise<string>;
|
|
280
|
+
getGasPrice(): Promise<bigint>;
|
|
281
|
+
estimateGas(tx: BaseTransaction): Promise<bigint>;
|
|
282
|
+
sendTransaction(_tx: BaseTransaction): Promise<string>;
|
|
283
|
+
waitForTransaction(hash: string): Promise<TransactionReceipt>;
|
|
284
|
+
getTokenBalance(tokenAddress: Address$2, holderAddress?: Address$2): Promise<string>;
|
|
285
|
+
watchBlocks(callback: EventCallback<BlockEvent>): UnwatchFunction;
|
|
286
|
+
watchTransactions(callback: EventCallback<TransactionEvent>): UnwatchFunction;
|
|
287
|
+
isValidAddress(address: string): boolean;
|
|
288
|
+
formatAmount(amount: bigint): string;
|
|
289
|
+
parseAmount(amount: string): bigint;
|
|
290
|
+
getInternalClient(): PublicClient$1;
|
|
291
|
+
private formatTokenAmount;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Core Space Wallet Client Implementation
|
|
295
|
+
*/
|
|
296
|
+
declare class CoreWalletClient implements WalletClient {
|
|
297
|
+
readonly chainType: "core";
|
|
298
|
+
readonly address: Address$2;
|
|
299
|
+
readonly chainId: number;
|
|
300
|
+
private readonly walletClient;
|
|
301
|
+
private readonly publicClient;
|
|
302
|
+
private readonly account;
|
|
303
|
+
private readonly chain;
|
|
304
|
+
constructor(config: WalletConfig);
|
|
305
|
+
sendTransaction(tx: BaseTransaction): Promise<string>;
|
|
306
|
+
signMessage(message: string): Promise<string>;
|
|
307
|
+
getInternalClient(): WalletClient$2;
|
|
308
|
+
waitForTransaction(hash: string): Promise<TransactionReceipt>;
|
|
309
|
+
/**
|
|
310
|
+
* Unified faucet functionality
|
|
311
|
+
* Automatically detects address type and sends CFX accordingly:
|
|
312
|
+
* - Core address: Direct transfer
|
|
313
|
+
* - eSpace address: Cross-chain transfer via internal contract
|
|
314
|
+
*/
|
|
315
|
+
faucet(address: string, amount: string): Promise<string>;
|
|
316
|
+
/**
|
|
317
|
+
* Cross-chain faucet functionality (Core → eSpace)
|
|
318
|
+
* Sends CFX from Core space to eSpace address via internal contract
|
|
319
|
+
* @deprecated Use faucet() instead which auto-detects address type
|
|
320
|
+
*/
|
|
321
|
+
faucetToEspace(espaceAddress: string, amount: string): Promise<string>;
|
|
322
|
+
/**
|
|
323
|
+
* Deploy a contract to Core Space
|
|
324
|
+
*/
|
|
325
|
+
deployContract(abi: unknown[], bytecode: string, constructorArgs?: unknown[]): Promise<string>;
|
|
326
|
+
/**
|
|
327
|
+
* Call a contract method (read-only)
|
|
328
|
+
*/
|
|
329
|
+
callContract<T = unknown>(address: string, abi: unknown[], functionName: string, args?: unknown[]): Promise<T>;
|
|
330
|
+
/**
|
|
331
|
+
* Write to a contract (transaction)
|
|
332
|
+
*/
|
|
333
|
+
writeContract(address: string, abi: unknown[], functionName: string, args?: unknown[], value?: bigint): Promise<string>;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Core Space Test Client Implementation
|
|
337
|
+
*/
|
|
338
|
+
declare class CoreTestClient extends CoreClient implements TestClient {
|
|
339
|
+
private readonly testClient;
|
|
340
|
+
constructor(config: TestConfig);
|
|
341
|
+
mine(blocks?: number): Promise<void>;
|
|
342
|
+
setNextBlockTimestamp(_timestamp: number): Promise<void>;
|
|
343
|
+
increaseTime(_seconds: number): Promise<void>;
|
|
344
|
+
impersonateAccount(_address: Address$2): Promise<void>;
|
|
345
|
+
stopImpersonatingAccount(_address: Address$2): Promise<void>;
|
|
346
|
+
setBalance(_address: Address$2, _balance: bigint): Promise<void>;
|
|
347
|
+
getStorageAt(_address: Address$2, _slot: string): Promise<string>;
|
|
348
|
+
setStorageAt(_address: Address$2, _slot: string, _value: string): Promise<void>;
|
|
349
|
+
getInternalTestClient(): TestClient$1;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export { CoreClient as C, type DeployOptions as D, EspaceClient as E, type FaucetBalances as F, type HealthStatus as H, type MiningStatus as M, type ReadOptions as R, type StartOptions as S, type TestClient as T, type WalletClient as W, CoreTestClient as a, CoreWalletClient as b, EspaceTestClient as c, EspaceWalletClient as d, type ClientConfig as e, type CoreClientInstance as f, type EspaceClientInstance as g, type ChainBalances as h, type ChainClient as i, type ChainStatus as j, type ClientFactory as k, type ClientManager as l, type ContractResult as m, type TestConfig as n, type WalletConfig as o, type WriteOptions as p };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { H as HealthStatus, e as ClientConfig, f as CoreClientInstance, g as EspaceClientInstance } from './core-RZA4aKwj.cjs';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { C as ChainType } from './config-BMtaWM0X.cjs';
|
|
4
|
+
import { SupportedChainId } from './config/index.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Client Manager Events
|
|
8
|
+
*/
|
|
9
|
+
interface ClientManagerEvents {
|
|
10
|
+
'client:ready': [{
|
|
11
|
+
type: ChainType;
|
|
12
|
+
chainId: SupportedChainId;
|
|
13
|
+
}];
|
|
14
|
+
'client:error': [
|
|
15
|
+
{
|
|
16
|
+
type: ChainType;
|
|
17
|
+
chainId: SupportedChainId;
|
|
18
|
+
error: Error;
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
'client:health': [
|
|
22
|
+
{
|
|
23
|
+
type: ChainType;
|
|
24
|
+
chainId: SupportedChainId;
|
|
25
|
+
status: HealthStatus;
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
'server:started': [
|
|
29
|
+
{
|
|
30
|
+
coreChainId: SupportedChainId;
|
|
31
|
+
evmChainId: SupportedChainId;
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
'server:stopped': [];
|
|
35
|
+
'network:switched': [{
|
|
36
|
+
from: SupportedChainId;
|
|
37
|
+
to: SupportedChainId;
|
|
38
|
+
}];
|
|
39
|
+
'manager:ready': [];
|
|
40
|
+
'manager:error': [{
|
|
41
|
+
error: Error;
|
|
42
|
+
}];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Client Manager Configuration
|
|
46
|
+
*/
|
|
47
|
+
interface ClientManagerConfig {
|
|
48
|
+
/** Core Space client configuration */
|
|
49
|
+
core: ClientConfig;
|
|
50
|
+
/** eSpace client configuration */
|
|
51
|
+
evm: ClientConfig;
|
|
52
|
+
/** Enable automatic health monitoring */
|
|
53
|
+
enableHealthMonitoring?: boolean;
|
|
54
|
+
/** Health check interval in milliseconds */
|
|
55
|
+
healthCheckInterval?: number;
|
|
56
|
+
/** Health check timeout in milliseconds */
|
|
57
|
+
healthCheckTimeout?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Client Manager Status
|
|
61
|
+
*/
|
|
62
|
+
interface ClientManagerStatus {
|
|
63
|
+
initialized: boolean;
|
|
64
|
+
coreClient: {
|
|
65
|
+
connected: boolean;
|
|
66
|
+
chainId: SupportedChainId;
|
|
67
|
+
health: HealthStatus;
|
|
68
|
+
lastHealthCheck?: Date;
|
|
69
|
+
};
|
|
70
|
+
evmClient: {
|
|
71
|
+
connected: boolean;
|
|
72
|
+
chainId: SupportedChainId;
|
|
73
|
+
health: HealthStatus;
|
|
74
|
+
lastHealthCheck?: Date;
|
|
75
|
+
};
|
|
76
|
+
networkSelector: {
|
|
77
|
+
currentChain: SupportedChainId;
|
|
78
|
+
isLocalNode: boolean;
|
|
79
|
+
lockedToLocal: boolean;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Unified Client Manager
|
|
84
|
+
*
|
|
85
|
+
* This is the main orchestration layer that manages:
|
|
86
|
+
* - Core Space and eSpace client instances
|
|
87
|
+
* - Local development server lifecycle
|
|
88
|
+
* - Network switching and chain coordination
|
|
89
|
+
* - Health monitoring and error recovery
|
|
90
|
+
* - Event coordination between components
|
|
91
|
+
*
|
|
92
|
+
* Key Design Principles:
|
|
93
|
+
* 1. **Dual Chain Support**: Manages both Core and eSpace clients simultaneously
|
|
94
|
+
* 2. **Network Awareness**: Automatically switches to local chains when dev server runs
|
|
95
|
+
* 3. **Health Monitoring**: Continuous health checks with automatic recovery
|
|
96
|
+
* 4. **Event Coordination**: Unified event system for all components
|
|
97
|
+
* 5. **Type Safety**: Full TypeScript support with proper error handling
|
|
98
|
+
*/
|
|
99
|
+
declare class ClientManager extends EventEmitter<ClientManagerEvents> {
|
|
100
|
+
private config;
|
|
101
|
+
private coreClient;
|
|
102
|
+
private evmClient;
|
|
103
|
+
private healthCheckInterval;
|
|
104
|
+
private networkSelectorUnsubscribe;
|
|
105
|
+
private nodeRunningUnsubscribe;
|
|
106
|
+
private initialized;
|
|
107
|
+
constructor(config: ClientManagerConfig);
|
|
108
|
+
/**
|
|
109
|
+
* Initialize the Client Manager
|
|
110
|
+
* Sets up clients, server, and monitoring
|
|
111
|
+
*/
|
|
112
|
+
initialize(): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Gracefully shutdown the Client Manager
|
|
115
|
+
*/
|
|
116
|
+
shutdown(): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Get current Core Space client
|
|
119
|
+
*/
|
|
120
|
+
getCoreClient(): CoreClientInstance | null;
|
|
121
|
+
/**
|
|
122
|
+
* Get current eSpace client
|
|
123
|
+
*/
|
|
124
|
+
getEvmClient(): EspaceClientInstance | null;
|
|
125
|
+
/**
|
|
126
|
+
* Get comprehensive status
|
|
127
|
+
*/
|
|
128
|
+
getStatus(): ClientManagerStatus;
|
|
129
|
+
/**
|
|
130
|
+
* Switch to a specific network
|
|
131
|
+
* @param chainId - Target chain ID
|
|
132
|
+
* @param force - Force switch even if node is running (for wallet operations)
|
|
133
|
+
*/
|
|
134
|
+
switchNetwork(chainId: SupportedChainId, force?: boolean): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Initialize or reinitialize client instances based on current network
|
|
137
|
+
*/
|
|
138
|
+
private initializeClients;
|
|
139
|
+
/**
|
|
140
|
+
* Set up network selector event listeners
|
|
141
|
+
*/
|
|
142
|
+
private setupNetworkListeners;
|
|
143
|
+
/**
|
|
144
|
+
* Start health monitoring for all clients
|
|
145
|
+
*/
|
|
146
|
+
private startHealthMonitoring;
|
|
147
|
+
/**
|
|
148
|
+
* Stop health monitoring
|
|
149
|
+
*/
|
|
150
|
+
private stopHealthMonitoring;
|
|
151
|
+
/**
|
|
152
|
+
* Perform health checks on all clients
|
|
153
|
+
*/
|
|
154
|
+
private performHealthChecks;
|
|
155
|
+
/**
|
|
156
|
+
* Check Core client health
|
|
157
|
+
*/
|
|
158
|
+
private checkCoreClientHealth;
|
|
159
|
+
/**
|
|
160
|
+
* Check eSpace client health
|
|
161
|
+
*/
|
|
162
|
+
private checkEvmClientHealth;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { ClientManager as C, type ClientManagerConfig as a, type ClientManagerEvents as b, type ClientManagerStatus as c };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { H as HealthStatus, e as ClientConfig, f as CoreClientInstance, g as EspaceClientInstance } from './core-C5qe16RS.js';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { C as ChainType } from './config-BMtaWM0X.js';
|
|
4
|
+
import { SupportedChainId } from './config/index.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Client Manager Events
|
|
8
|
+
*/
|
|
9
|
+
interface ClientManagerEvents {
|
|
10
|
+
'client:ready': [{
|
|
11
|
+
type: ChainType;
|
|
12
|
+
chainId: SupportedChainId;
|
|
13
|
+
}];
|
|
14
|
+
'client:error': [
|
|
15
|
+
{
|
|
16
|
+
type: ChainType;
|
|
17
|
+
chainId: SupportedChainId;
|
|
18
|
+
error: Error;
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
'client:health': [
|
|
22
|
+
{
|
|
23
|
+
type: ChainType;
|
|
24
|
+
chainId: SupportedChainId;
|
|
25
|
+
status: HealthStatus;
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
'server:started': [
|
|
29
|
+
{
|
|
30
|
+
coreChainId: SupportedChainId;
|
|
31
|
+
evmChainId: SupportedChainId;
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
'server:stopped': [];
|
|
35
|
+
'network:switched': [{
|
|
36
|
+
from: SupportedChainId;
|
|
37
|
+
to: SupportedChainId;
|
|
38
|
+
}];
|
|
39
|
+
'manager:ready': [];
|
|
40
|
+
'manager:error': [{
|
|
41
|
+
error: Error;
|
|
42
|
+
}];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Client Manager Configuration
|
|
46
|
+
*/
|
|
47
|
+
interface ClientManagerConfig {
|
|
48
|
+
/** Core Space client configuration */
|
|
49
|
+
core: ClientConfig;
|
|
50
|
+
/** eSpace client configuration */
|
|
51
|
+
evm: ClientConfig;
|
|
52
|
+
/** Enable automatic health monitoring */
|
|
53
|
+
enableHealthMonitoring?: boolean;
|
|
54
|
+
/** Health check interval in milliseconds */
|
|
55
|
+
healthCheckInterval?: number;
|
|
56
|
+
/** Health check timeout in milliseconds */
|
|
57
|
+
healthCheckTimeout?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Client Manager Status
|
|
61
|
+
*/
|
|
62
|
+
interface ClientManagerStatus {
|
|
63
|
+
initialized: boolean;
|
|
64
|
+
coreClient: {
|
|
65
|
+
connected: boolean;
|
|
66
|
+
chainId: SupportedChainId;
|
|
67
|
+
health: HealthStatus;
|
|
68
|
+
lastHealthCheck?: Date;
|
|
69
|
+
};
|
|
70
|
+
evmClient: {
|
|
71
|
+
connected: boolean;
|
|
72
|
+
chainId: SupportedChainId;
|
|
73
|
+
health: HealthStatus;
|
|
74
|
+
lastHealthCheck?: Date;
|
|
75
|
+
};
|
|
76
|
+
networkSelector: {
|
|
77
|
+
currentChain: SupportedChainId;
|
|
78
|
+
isLocalNode: boolean;
|
|
79
|
+
lockedToLocal: boolean;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Unified Client Manager
|
|
84
|
+
*
|
|
85
|
+
* This is the main orchestration layer that manages:
|
|
86
|
+
* - Core Space and eSpace client instances
|
|
87
|
+
* - Local development server lifecycle
|
|
88
|
+
* - Network switching and chain coordination
|
|
89
|
+
* - Health monitoring and error recovery
|
|
90
|
+
* - Event coordination between components
|
|
91
|
+
*
|
|
92
|
+
* Key Design Principles:
|
|
93
|
+
* 1. **Dual Chain Support**: Manages both Core and eSpace clients simultaneously
|
|
94
|
+
* 2. **Network Awareness**: Automatically switches to local chains when dev server runs
|
|
95
|
+
* 3. **Health Monitoring**: Continuous health checks with automatic recovery
|
|
96
|
+
* 4. **Event Coordination**: Unified event system for all components
|
|
97
|
+
* 5. **Type Safety**: Full TypeScript support with proper error handling
|
|
98
|
+
*/
|
|
99
|
+
declare class ClientManager extends EventEmitter<ClientManagerEvents> {
|
|
100
|
+
private config;
|
|
101
|
+
private coreClient;
|
|
102
|
+
private evmClient;
|
|
103
|
+
private healthCheckInterval;
|
|
104
|
+
private networkSelectorUnsubscribe;
|
|
105
|
+
private nodeRunningUnsubscribe;
|
|
106
|
+
private initialized;
|
|
107
|
+
constructor(config: ClientManagerConfig);
|
|
108
|
+
/**
|
|
109
|
+
* Initialize the Client Manager
|
|
110
|
+
* Sets up clients, server, and monitoring
|
|
111
|
+
*/
|
|
112
|
+
initialize(): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Gracefully shutdown the Client Manager
|
|
115
|
+
*/
|
|
116
|
+
shutdown(): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Get current Core Space client
|
|
119
|
+
*/
|
|
120
|
+
getCoreClient(): CoreClientInstance | null;
|
|
121
|
+
/**
|
|
122
|
+
* Get current eSpace client
|
|
123
|
+
*/
|
|
124
|
+
getEvmClient(): EspaceClientInstance | null;
|
|
125
|
+
/**
|
|
126
|
+
* Get comprehensive status
|
|
127
|
+
*/
|
|
128
|
+
getStatus(): ClientManagerStatus;
|
|
129
|
+
/**
|
|
130
|
+
* Switch to a specific network
|
|
131
|
+
* @param chainId - Target chain ID
|
|
132
|
+
* @param force - Force switch even if node is running (for wallet operations)
|
|
133
|
+
*/
|
|
134
|
+
switchNetwork(chainId: SupportedChainId, force?: boolean): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Initialize or reinitialize client instances based on current network
|
|
137
|
+
*/
|
|
138
|
+
private initializeClients;
|
|
139
|
+
/**
|
|
140
|
+
* Set up network selector event listeners
|
|
141
|
+
*/
|
|
142
|
+
private setupNetworkListeners;
|
|
143
|
+
/**
|
|
144
|
+
* Start health monitoring for all clients
|
|
145
|
+
*/
|
|
146
|
+
private startHealthMonitoring;
|
|
147
|
+
/**
|
|
148
|
+
* Stop health monitoring
|
|
149
|
+
*/
|
|
150
|
+
private stopHealthMonitoring;
|
|
151
|
+
/**
|
|
152
|
+
* Perform health checks on all clients
|
|
153
|
+
*/
|
|
154
|
+
private performHealthChecks;
|
|
155
|
+
/**
|
|
156
|
+
* Check Core client health
|
|
157
|
+
*/
|
|
158
|
+
private checkCoreClientHealth;
|
|
159
|
+
/**
|
|
160
|
+
* Check eSpace client health
|
|
161
|
+
*/
|
|
162
|
+
private checkEvmClientHealth;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { ClientManager as C, type ClientManagerConfig as a, type ClientManagerEvents as b, type ClientManagerStatus as c };
|