code.vegaprotocol.io/vega@v0.79.0/paths/paths.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package paths 17 18 import "path/filepath" 19 20 // VegaHome is the name of the Vega folder for every type of file structure. 21 var VegaHome = "vega" 22 23 // File structure for cache 24 // 25 // CACHE_PATH 26 // └── data-node/ 27 28 type CachePath string 29 30 func (p CachePath) String() string { 31 return string(p) 32 } 33 34 // JoinCachePath joins any number of path elements with a root CachePath into a 35 // single path, separating them with an OS specific Separator, and returns it 36 // as a CachePath. 37 func JoinCachePath(p CachePath, elem ...string) CachePath { 38 return CachePath(JoinCachePathStr(p, elem...)) 39 } 40 41 // JoinCachePathStr joins any number of path elements with a root CachePath 42 // into a single path, separating them with an OS specific Separator, and 43 // returns it as a string. 44 func JoinCachePathStr(p CachePath, elem ...string) string { 45 return filepath.Join(append([]string{string(p)}, elem...)...) 46 } 47 48 // DataNodeCacheHome is the folder containing the cache used by the 49 // data-node. 50 var DataNodeCacheHome = CachePath("data-node") 51 52 // File structure for configuration 53 // 54 // CONFIG_PATH 55 // ├── data-node/ 56 // │ └── config.toml 57 // ├── faucet/ 58 // │ └── config.toml 59 // ├── node/ 60 // │ ├── config.toml 61 // │ └── wallets.toml 62 // ├── wallet-cli/ 63 // │ └── config.toml 64 // ├── wallet-app/ 65 // │ ├── config.fairground.toml 66 // │ └── config.toml 67 // └── wallet-service/ 68 // ├── config.toml 69 // └── networks/ 70 71 type ConfigPath string 72 73 func (p ConfigPath) String() string { 74 return string(p) 75 } 76 77 // JoinConfigPath joins any number of path elements with a root ConfigPath into a 78 // single path, separating them with an OS specific Separator, and returns it 79 // as a ConfigPath. 80 func JoinConfigPath(p ConfigPath, elem ...string) ConfigPath { 81 return ConfigPath(JoinConfigPathStr(p, elem...)) 82 } 83 84 // JoinConfigPathStr joins any number of path elements with a root ConfigPath 85 // into a single path, separating them with an OS specific Separator, and 86 // returns it as a string. 87 func JoinConfigPathStr(p ConfigPath, elem ...string) string { 88 return filepath.Join(append([]string{string(p)}, elem...)...) 89 } 90 91 var ( 92 // BlockExplorerConfigHome is the folder containing the configuration files 93 // used by the block explorer. 94 BlockExplorerConfigHome = ConfigPath("blockexplorer") 95 96 // BlockExplorerDefaultConfigFile is the default configuration file for the 97 // block explorer. 98 BlockExplorerDefaultConfigFile = JoinConfigPath(BlockExplorerConfigHome, "config.toml") 99 100 // DataNodeConfigHome is the folder containing the configuration files 101 // used by the node. 102 DataNodeConfigHome = ConfigPath("data-node") 103 104 // DataNodeDefaultConfigFile is the default configuration file for the 105 // data-node. 106 DataNodeDefaultConfigFile = JoinConfigPath(DataNodeConfigHome, "config.toml") 107 108 // FaucetConfigHome is the folder containing the configuration files 109 // used by the node. 110 FaucetConfigHome = ConfigPath("faucet") 111 112 // FaucetDefaultConfigFile is the default configuration file for the 113 // data-node. 114 FaucetDefaultConfigFile = JoinConfigPath(FaucetConfigHome, "config.toml") 115 116 // NodeConfigHome is the folder containing the configuration files used by 117 // the node. 118 NodeConfigHome = ConfigPath("node") 119 120 // NodeDefaultConfigFile is the default configuration file for the node. 121 NodeDefaultConfigFile = JoinConfigPath(NodeConfigHome, "config.toml") 122 123 // NodeWalletsConfigFile is the configuration file for the node wallets. 124 NodeWalletsConfigFile = JoinConfigPath(NodeConfigHome, "wallets.encrypted") 125 126 // WalletCLIConfigHome is the folder containing the configuration files 127 // used by the wallet CLI. 128 WalletCLIConfigHome = ConfigPath("wallet-cli") 129 130 // WalletCLIDefaultConfigFile is the default configuration file for the 131 // wallet CLI. 132 WalletCLIDefaultConfigFile = JoinConfigPath(WalletCLIConfigHome, "config.toml") 133 134 // WalletAppConfigHome is the folder containing the configuration files 135 // used by the wallet app application. 136 WalletAppConfigHome = ConfigPath("wallet-app") 137 138 // WalletAppFairgroundConfigFile is the Fairground configuration file for the 139 // wallet app application. 140 WalletAppFairgroundConfigFile = JoinConfigPath(WalletAppConfigHome, "config.fairground.toml") 141 142 // WalletAppDefaultConfigFile is the default configuration file for the 143 // wallet app application. 144 WalletAppDefaultConfigFile = JoinConfigPath(WalletAppConfigHome, "config.toml") 145 146 // WalletServiceConfigHome is the folder containing the configuration files 147 // used by the wallet service. 148 WalletServiceConfigHome = ConfigPath("wallet-service") 149 150 // WalletServiceDefaultConfigFile is the default configuration file for the 151 // wallet service. 152 WalletServiceDefaultConfigFile = JoinConfigPath(WalletServiceConfigHome, "config.toml") 153 154 // WalletServiceNetworksConfigHome is the folder containing the network 155 // configuration files used to connect to a network. 156 WalletServiceNetworksConfigHome = JoinConfigPath(WalletServiceConfigHome, "networks") 157 ) 158 159 // File structure for data 160 // 161 // DATA_PATH 162 // ├── node/ 163 // │ └── wallets/ 164 // │ ├── vega/ 165 // │ │ └── vega.<timestamp> 166 // │ └── ethereum/ 167 // │ └── eth-node-wallet 168 // ├── faucet/ 169 // │ └── wallets/ 170 // │ └── vega.<timestamp> 171 // ├── wallets/ 172 // │ ├── vega-wallet-1 173 // │ └── vega-wallet-2 174 // └── wallet-service/ 175 // ├── tokens.json 176 // ├── sessions.toml 177 // └── rsa-keys/ 178 // ├── private.pem 179 // └── public.pem 180 181 type DataPath string 182 183 func (p DataPath) String() string { 184 return string(p) 185 } 186 187 // JoinDataPath joins any number of path elements with a root DataPath into a 188 // single path, separating them with an OS specific Separator, and returns it 189 // as a DataPath. 190 func JoinDataPath(p DataPath, elem ...string) DataPath { 191 return DataPath(JoinDataPathStr(p, elem...)) 192 } 193 194 // JoinDataPathStr joins any number of path elements with a root DataPath 195 // into a single path, separating them with an OS specific Separator, and 196 // returns it as a string. 197 func JoinDataPathStr(p DataPath, elem ...string) string { 198 return filepath.Join(append([]string{string(p)}, elem...)...) 199 } 200 201 var ( 202 // NodeDataHome is the folder containing the data used by the node. 203 NodeDataHome = DataPath("node") 204 205 // NodeWalletsDataHome is the folder containing the data used by the 206 // node wallets. 207 NodeWalletsDataHome = DataPath(filepath.Join(NodeDataHome.String(), "wallets")) 208 209 // VegaNodeWalletsDataHome is the folder containing the vega wallet 210 // used by the node. 211 VegaNodeWalletsDataHome = DataPath(filepath.Join(NodeWalletsDataHome.String(), "vega")) 212 213 // EthereumNodeWalletsDataHome is the folder containing the ethereum wallet 214 // used by the node. 215 EthereumNodeWalletsDataHome = DataPath(filepath.Join(NodeWalletsDataHome.String(), "ethereum")) 216 217 // FaucetDataHome is the folder containing the data used by the faucet. 218 FaucetDataHome = DataPath("faucet") 219 220 // FaucetWalletsDataHome is the folder containing the data used by the 221 // faucet wallets. 222 FaucetWalletsDataHome = DataPath(filepath.Join(FaucetDataHome.String(), "wallets")) 223 224 // WalletsDataHome is the folder containing the user wallets. 225 WalletsDataHome = DataPath("wallets") 226 227 // WalletServiceDataHome is the folder containing the data used by the 228 // wallet service. 229 WalletServiceDataHome = DataPath("wallet-service") 230 231 // WalletServiceAPITokensDataFile is the file containing all the API tokens 232 // used by the third-party applications to connect to the wallet API. 233 WalletServiceAPITokensDataFile = DataPath(filepath.Join(WalletServiceDataHome.String(), "tokens.json")) 234 235 // WalletServiceSessionTokensDataFile is the file containing all the session tokens 236 // generated to initiates the connection with the third-party applications to 237 // connect to the wallet API. 238 WalletServiceSessionTokensDataFile = DataPath(filepath.Join(WalletServiceDataHome.String(), "sessions.toml")) 239 240 // WalletServiceRSAKeysDataHome is the folder containing the RSA keys used by 241 // the wallet service. 242 WalletServiceRSAKeysDataHome = DataPath(filepath.Join(WalletServiceDataHome.String(), "rsa-keys")) 243 244 // WalletServicePublicRSAKeyDataFile is the file containing the public RSA key 245 // used by the wallet service. 246 WalletServicePublicRSAKeyDataFile = DataPath(filepath.Join(WalletServiceRSAKeysDataHome.String(), "public.pem")) 247 248 // WalletServicePrivateRSAKeyDataFile is the file containing the private RSA key 249 // used by the wallet service. 250 WalletServicePrivateRSAKeyDataFile = DataPath(filepath.Join(WalletServiceRSAKeysDataHome.String(), "private.pem")) 251 ) 252 253 // File structure for state 254 // 255 // STATE_HOME 256 // ├── data-node/ 257 // │ ├── archivedeventbuffers/ 258 // │ ├── autocert/ 259 // │ ├── eventsbuffer/ 260 // │ ├── logs/ 261 // │ ├── networkhistory/ 262 // │ │ ├── snapshotscopyfrom/ 263 // │ │ └── snapshotscopyto/ 264 // │ └── storage/ 265 // │ ├── postgres/ 266 // │ └── sqlstore/ 267 // │ └── node-data/ 268 // ├── node/ 269 // │ ├── logs/ 270 // │ ├── checkpoints/ 271 // │ └── snapshots/ 272 // │ └── ldb 273 // ├── wallet-cli/ 274 // │ └── logs/ 275 // ├── wallet-app/ 276 // │ └── logs/ 277 // └── wallet-service/ 278 // └── logs/ 279 280 type StatePath string 281 282 func (p StatePath) String() string { 283 return string(p) 284 } 285 286 // JoinStatePath joins any number of path elements with a root StatePath into a 287 // single path, separating them with an OS specific Separator, and returns it 288 // as a StatePath. 289 func JoinStatePath(p StatePath, elem ...string) StatePath { 290 return StatePath(JoinStatePathStr(p, elem...)) 291 } 292 293 // JoinStatePathStr joins any number of path elements with a root StatePath 294 // into a single path, separating them with an OS specific Separator, and 295 // returns it as a string. 296 func JoinStatePathStr(p StatePath, elem ...string) string { 297 return filepath.Join(append([]string{string(p)}, elem...)...) 298 } 299 300 var ( 301 // DataNodeStateHome is the folder containing the state used by the 302 // data-node. 303 DataNodeStateHome = StatePath("data-node") 304 305 // DataNodeAutoCertHome is the folder containing the automatically generated SSL certificates. 306 DataNodeAutoCertHome = StatePath(filepath.Join(DataNodeStateHome.String(), "autocert")) 307 308 // DataNodeLogsHome is the folder containing the logs of the data-node. 309 DataNodeLogsHome = StatePath(filepath.Join(DataNodeStateHome.String(), "logs")) 310 311 // DataNodeStorageHome is the folder containing the data storage of the 312 // data-node. 313 DataNodeStorageHome = StatePath(filepath.Join(DataNodeStateHome.String(), "storage")) 314 315 // DataNodeStorageSQLStoreHome is the folder containing the data of the 316 // SQL store. 317 DataNodeStorageSQLStoreHome = StatePath(filepath.Join(DataNodeStateHome.String(), "sqlstore")) 318 319 // DataNodeStorageSQLStoreNodeDataHome is the folder containing the data of the 320 // SQL store. 321 DataNodeStorageSQLStoreNodeDataHome = StatePath(filepath.Join(DataNodeStorageSQLStoreHome.String(), "node-data")) 322 323 // DataNodeEmbeddedPostgresRuntimeDir is the runtime directory for embedded postgres. 324 DataNodeEmbeddedPostgresRuntimeDir = StatePath(filepath.Join(DataNodeStorageHome.String(), "postgres")) 325 326 // DataNodeNetworkHistoryHome is the folder containing the network history data. 327 DataNodeNetworkHistoryHome = StatePath(filepath.Join(DataNodeStateHome.String(), "networkhistory")) 328 329 // DataNodeNetworkHistorySnapshotCopyTo is the folder in which the datanode creates snapshots. 330 DataNodeNetworkHistorySnapshotCopyTo = StatePath(filepath.Join(DataNodeNetworkHistoryHome.String(), "snapshotscopyto")) 331 332 // DataNodeNetworkHistorySnapshotCopyFrom is the folder from which the datanode reads snapshot data. 333 DataNodeNetworkHistorySnapshotCopyFrom = StatePath(filepath.Join(DataNodeNetworkHistoryHome.String(), "snapshotscopyfrom")) 334 335 // DataNodeEventBufferHome is the folder containing event buffer files. 336 DataNodeEventBufferHome = StatePath(filepath.Join(DataNodeStateHome.String(), "eventsbuffer")) 337 338 // DataNodeArchivedEventBufferHome is the folder containing archived event buffer files. 339 DataNodeArchivedEventBufferHome = StatePath(filepath.Join(DataNodeStateHome.String(), "archivedeventbuffers")) 340 341 // NodeStateHome is the folder containing the state of the node. 342 NodeStateHome = StatePath("node") 343 344 // NodeLogsHome is the folder containing the logs of the node. 345 NodeLogsHome = StatePath(filepath.Join(NodeStateHome.String(), "logs")) 346 347 // CheckpointStateHome is the folder containing the checkpoint files 348 // of to the node. 349 CheckpointStateHome = StatePath(filepath.Join(NodeStateHome.String(), "checkpoints")) 350 351 // SnapshotStateHome is the folder containing the snapshot files 352 // of to the node. 353 SnapshotStateHome = StatePath(filepath.Join(NodeStateHome.String(), "snapshots")) 354 355 // SnapshotDBStateFile is the DB file for GoLevelDB used in snapshots. 356 SnapshotDBStateFile = StatePath(filepath.Join(SnapshotStateHome.String(), "snapshot.db")) 357 358 // SnapshotMetadataDBStateFile is the DB file containing metadata about the snapshots. 359 SnapshotMetadataDBStateFile = StatePath(filepath.Join(SnapshotStateHome.String(), "snapshot_meta.db")) 360 361 // WalletCLIStateHome is the folder containing the state of the wallet CLI. 362 WalletCLIStateHome = StatePath("wallet-cli") 363 364 // WalletCLILogsHome is the folder containing the logs of the wallet CLI. 365 WalletCLILogsHome = StatePath(filepath.Join(WalletCLIStateHome.String(), "logs")) 366 367 // WalletAppStateHome is the folder containing the state of the wallet 368 // app. 369 WalletAppStateHome = StatePath("wallet-app") 370 371 // WalletAppLogsHome is the folder containing the logs of the wallet 372 // app. 373 WalletAppLogsHome = StatePath(filepath.Join(WalletAppStateHome.String(), "logs")) 374 375 // WalletServiceStateHome is the folder containing the state of the node. 376 WalletServiceStateHome = StatePath("wallet-service") 377 378 // WalletServiceLogsHome is the folder containing the logs of the node. 379 WalletServiceLogsHome = StatePath(filepath.Join(WalletServiceStateHome.String(), "logs")) 380 )