forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ts
More file actions
78 lines (68 loc) · 2.95 KB
/
Copy pathutil.ts
File metadata and controls
78 lines (68 loc) · 2.95 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { z } from "zod";
import { WalletNetwork } from "@creit.tech/stellar-wallets-kit";
import { Network, NetworkType } from "../debug/types/types";
const envSchema = z.object({
PUBLIC_STELLAR_NETWORK: z.enum([
"PUBLIC",
"FUTURENET",
"TESTNET",
"LOCAL",
"STANDALONE", // deprecated in favor of LOCAL
] as const),
PUBLIC_STELLAR_NETWORK_PASSPHRASE: z.nativeEnum(WalletNetwork),
PUBLIC_STELLAR_RPC_URL: z.string(),
PUBLIC_STELLAR_HORIZON_URL: z.string(),
});
const parsed = envSchema.safeParse(import.meta.env);
const env: z.infer<typeof envSchema> = parsed.success
? parsed.data
: {
PUBLIC_STELLAR_NETWORK: "LOCAL",
PUBLIC_STELLAR_NETWORK_PASSPHRASE: WalletNetwork.STANDALONE,
PUBLIC_STELLAR_RPC_URL: "http://localhost:8000/rpc",
PUBLIC_STELLAR_HORIZON_URL: "http://localhost:8000",
};
export const stellarNetwork =
env.PUBLIC_STELLAR_NETWORK === "STANDALONE"
? "LOCAL"
: env.PUBLIC_STELLAR_NETWORK;
export const networkPassphrase = env.PUBLIC_STELLAR_NETWORK_PASSPHRASE;
const stellarEncode = (str: string) => {
return str.replace(/\//g, "//").replace(/;/g, "/;");
};
export const labPrefix = () => {
switch (stellarNetwork) {
case "LOCAL":
return `http://localhost:8000/lab/transaction-dashboard?$=network$id=custom&label=Custom&horizonUrl=${stellarEncode(horizonUrl)}&rpcUrl=${stellarEncode(rpcUrl)}&passphrase=${stellarEncode(networkPassphrase)};`;
case "PUBLIC":
return `https://lab.stellar.org/transaction-dashboard?$=network$id=mainnet&label=Mainnet&horizonUrl=${stellarEncode(horizonUrl)}&rpcUrl=${stellarEncode(rpcUrl)}&passphrase=${stellarEncode(networkPassphrase)};`;
case "TESTNET":
return `https://lab.stellar.org/transaction-dashboard?$=network$id=testnet&label=Testnet&horizonUrl=${stellarEncode(horizonUrl)}&rpcUrl=${stellarEncode(rpcUrl)}&passphrase=${stellarEncode(networkPassphrase)};`;
case "FUTURENET":
return `https://lab.stellar.org/transaction-dashboard?$=network$id=futurenet&label=Futurenet&horizonUrl=${stellarEncode(horizonUrl)}&rpcUrl=${stellarEncode(rpcUrl)}&passphrase=${stellarEncode(networkPassphrase)};`;
default:
return `https://lab.stellar.org/transaction-dashboard?$=network$id=testnet&label=Testnet&horizonUrl=${stellarEncode(horizonUrl)}&rpcUrl=${stellarEncode(rpcUrl)}&passphrase=${stellarEncode(networkPassphrase)};`;
}
};
// NOTE: needs to be exported for contract files in this directory
export const rpcUrl = env.PUBLIC_STELLAR_RPC_URL;
export const horizonUrl = env.PUBLIC_STELLAR_HORIZON_URL;
const networkToId = (network: string): NetworkType => {
switch (network) {
case "PUBLIC":
return "mainnet";
case "TESTNET":
return "testnet";
case "FUTURENET":
return "futurenet";
default:
return "custom";
}
};
export const network: Network = {
id: networkToId(stellarNetwork),
label: stellarNetwork.toLowerCase(),
passphrase: networkPassphrase,
rpcUrl: rpcUrl,
horizonUrl: horizonUrl,
};