forked from StellarRouter/StellarRouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetworks.ts
More file actions
58 lines (55 loc) · 1.82 KB
/
Copy pathnetworks.ts
File metadata and controls
58 lines (55 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type { NetworkConfig, NetworkName } from "./types.js";
/**
* Default connection parameters for supported Stellar networks.
*
* Consumers with a private or stand-alone RPC endpoint should pass a full
* {@link NetworkConfig} instead of relying on these presets.
*/
export const NETWORKS: Record<NetworkName, NetworkConfig> = {
testnet: {
rpcUrl: "https://soroban-testnet.stellar.org",
networkPassphrase: "Test SDF Network ; September 2015",
},
futurenet: {
rpcUrl: "https://rpc-futurenet.stellar.org",
networkPassphrase: "Futurenet Network ; September 2024",
},
mainnet: {
rpcUrl: "https://soroban-mainnet.stellar.org",
networkPassphrase: "Public Global Stellar Network ; September 2015",
},
local: {
rpcUrl: "http://localhost:8000",
networkPassphrase: "Standalone Network ; February 2017",
},
};
/** Applies any overrides to a network preset, producing a concrete config. */
export function withOverrides(
network: NetworkConfig,
overrides: Partial<Pick<NetworkConfig, "rpcUrl" | "networkPassphrase">>,
): NetworkConfig {
return {
rpcUrl: overrides.rpcUrl ?? network.rpcUrl,
networkPassphrase: overrides.networkPassphrase ?? network.networkPassphrase,
};
}
/**
* Resolve a named preset (or an explicit config object) into concrete
* connection parameters.
*
* @throws if `network` names a preset that is not known to the SDK.
*/
export function resolveNetwork(network: string | NetworkConfig): NetworkConfig {
if (typeof network !== "string") {
return network;
}
const key = network.toLowerCase() as NetworkName;
const preset = NETWORKS[key];
if (!preset) {
throw new Error(
`Unknown network "${network}". Use one of ${Object.keys(NETWORKS).join(", ")} ` +
"or pass an explicit { rpcUrl, networkPassphrase } config.",
);
}
return preset;
}