github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/metadata/network.go (about) 1 /* 2 * Copyright (C) 2017 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package metadata 19 20 import "fmt" 21 22 // NetworkDefinition structure holds all parameters which describe particular network 23 type NetworkDefinition struct { 24 // Deprecated: use DiscoveryAddress 25 MysteriumAPIAddress string 26 DiscoveryAddress string 27 AccessPolicyOracleAddress string 28 BrokerAddresses []string 29 TransactorAddress string 30 AffiliatorAddress string 31 Chain1 ChainDefinition 32 Chain2 ChainDefinition 33 MMNAddress string 34 MMNAPIAddress string 35 PilvytisAddress string 36 ObserverAddress string 37 DNSMap map[string][]string 38 DefaultChainID int64 39 DefaultCurrency string 40 LocationAddress string 41 Payments Payments 42 } 43 44 // ChainDefinition defines the configuration for the chain. 45 type ChainDefinition struct { 46 RegistryAddress string 47 HermesID string 48 ChannelImplAddress string 49 ChainID int64 50 MystAddress string 51 EtherClientRPC []string 52 KnownHermeses []string 53 } 54 55 // Payments defines payments configuration 56 type Payments struct { 57 DataLeewayMegabytes uint64 58 } 59 60 // MainnetDefinition defines parameters for mainnet network (currently default network) 61 var MainnetDefinition = NetworkDefinition{ 62 MysteriumAPIAddress: "https://discovery.mysterium.network/api/v4", 63 DiscoveryAddress: "https://discovery.mysterium.network/api/v4", 64 AccessPolicyOracleAddress: "https://trust.mysterium.network/api/v1/access-policies/", 65 BrokerAddresses: []string{"nats://broker.mysterium.network"}, 66 TransactorAddress: "https://transactor.mysterium.network/api/v1", 67 AffiliatorAddress: "https://affiliator.mysterium.network/api/v1", 68 Chain1: ChainDefinition{ // TODO: Update when mainnet deployed. 69 RegistryAddress: "0x87F0F4b7e0FAb14A565C87BAbbA6c40c92281b51", 70 ChannelImplAddress: "0xbd20839b331a7a8d10e34cdf7219edf334814c4f", 71 HermesID: "0xa62a2a75949d25e17c6f08a7818e7be97c18a8d2", 72 ChainID: 1, 73 MystAddress: "0x4Cf89ca06ad997bC732Dc876ed2A7F26a9E7f361", 74 EtherClientRPC: []string{ 75 "https://ethereum1.mysterium.network/", 76 "https://cloudflare-eth.com/", 77 }, 78 KnownHermeses: []string{ 79 "0xa62a2a75949d25e17c6f08a7818e7be97c18a8d2", 80 }, 81 }, 82 Chain2: ChainDefinition{ 83 RegistryAddress: "0x87F0F4b7e0FAb14A565C87BAbbA6c40c92281b51", 84 ChannelImplAddress: "0x6b423D3885B4877b5760E149364f85f185f477aD", 85 HermesID: "0x80ed28d84792d8b153bf2f25f0c4b7a1381de4ab", 86 ChainID: 137, 87 MystAddress: "0x1379e8886a944d2d9d440b3d88df536aea08d9f3", 88 EtherClientRPC: []string{ 89 "https://polygon1.mysterium.network/", 90 "https://polygon-rpc.com/", 91 }, 92 KnownHermeses: []string{ 93 "0xa62a2a75949d25e17c6f08a7818e7be97c18a8d2", 94 "0x80ed28d84792d8b153bf2f25f0c4b7a1381de4ab", 95 }, 96 }, 97 MMNAddress: "https://my.mystnodes.com", 98 MMNAPIAddress: "https://api.mystnodes.com/api/v1", 99 PilvytisAddress: "https://pilvytis.mysterium.network", 100 ObserverAddress: "https://observer.mysterium.network", 101 DNSMap: map[string][]string{ 102 "discovery.mysterium.network": {"51.158.204.30", "51.158.204.75", "51.158.204.9", "51.158.204.23"}, 103 "trust.mysterium.network": {"51.158.204.30", "51.158.204.75", "51.158.204.9", "51.158.204.23"}, 104 "broker.mysterium.network": {"51.158.204.30", "51.158.204.75", "51.158.204.9", "51.158.204.23"}, 105 "transactor.mysterium.network": {"51.158.204.30", "51.158.204.75", "51.158.204.9", "51.158.204.23"}, 106 "affiliator.mysterium.network": {"51.158.204.30", "51.158.204.75", "51.158.204.9", "51.158.204.23"}, 107 "pilvytis.mysterium.network": {"51.158.204.30", "51.158.204.75", "51.158.204.9", "51.158.204.23"}, 108 "observer.mysterium.network": {"51.158.204.30", "51.158.204.75", "51.158.204.9", "51.158.204.23"}, 109 }, 110 DefaultChainID: 137, 111 DefaultCurrency: "MYST", 112 LocationAddress: "https://location.mysterium.network/api/v1/location", 113 Payments: Payments{ 114 DataLeewayMegabytes: 20, 115 }, 116 } 117 118 // LocalnetDefinition defines parameters for local network 119 // Expects discovery, broker and morqa services on localhost 120 var LocalnetDefinition = NetworkDefinition{ 121 MysteriumAPIAddress: "http://localhost:8001/v1", 122 DiscoveryAddress: "http://localhost:8001/v1", 123 AccessPolicyOracleAddress: "https://localhost:8081/api/v1/access-policies/", 124 BrokerAddresses: []string{"localhost"}, 125 MMNAddress: "http://localhost/", 126 MMNAPIAddress: "http://localhost/api/v1", 127 PilvytisAddress: "http://localhost:8002/api/v1", 128 DNSMap: map[string][]string{ 129 "localhost": {"127.0.0.1"}, 130 }, 131 DefaultChainID: 1, 132 } 133 134 // TestnetDefinition defines parameters for testnet network 135 var TestnetDefinition = NetworkDefinition{ 136 MysteriumAPIAddress: "https://discovery-testnet.mysterium.network/api/v4", 137 DiscoveryAddress: "https://discovery-testnet.mysterium.network/api/v4", 138 AccessPolicyOracleAddress: "https://trust-testnet.mysterium.network/api/v1/access-policies/", 139 BrokerAddresses: []string{"nats://broker.mysterium.network:4223"}, 140 TransactorAddress: "https://transactor-testnet.mysterium.network/api/v1", 141 AffiliatorAddress: "https://affiliator.mysterium.network/api/v1", 142 Chain1: ChainDefinition{ 143 ChainID: 1, 144 EtherClientRPC: []string{ 145 "https://ethereum1.mysterium.network/", 146 "https://cloudflare-eth.com/", 147 }, 148 }, 149 Chain2: ChainDefinition{ 150 RegistryAddress: "0x935305eBD48264E72067c242231b9c1638f8722c", 151 ChannelImplAddress: "0xA7D2b4834e059720b18EAfa56Fc076622a6d6275", 152 HermesID: "0xf1e8f60009005cc760c8e96fb3cabd992f9004e6", 153 ChainID: 80002, 154 MystAddress: "0x5B75A099da7533CC800e77eeAEc3409c12420A15", 155 EtherClientRPC: []string{ 156 "https://polygon-amoy1.mysterium.network", 157 }, 158 KnownHermeses: []string{ 159 "0xf1e8f60009005cc760c8e96fb3cabd992f9004e6", 160 }, 161 }, 162 MMNAddress: "https://my.mystnodes.com", 163 MMNAPIAddress: "https://api.mystnodes.com/api/v1", 164 PilvytisAddress: "https://pilvytis-testnet.mysterium.network", 165 ObserverAddress: "https://observer-testnet.mysterium.network", 166 DNSMap: map[string][]string{ 167 "trust.mysterium.network": {"51.158.204.30", "51.158.204.75", "51.158.204.9", "51.158.204.23"}, 168 "broker.mysterium.network": {"51.158.204.30", "51.158.204.75", "51.158.204.9", "51.158.204.23"}, 169 "affiliator.mysterium.network": {"51.158.204.30", "51.158.204.75", "51.158.204.9", "51.158.204.23"}, 170 }, 171 DefaultChainID: 80002, 172 DefaultCurrency: "MYST", 173 LocationAddress: "https://location.mysterium.network/api/v1/location", 174 Payments: Payments{ 175 DataLeewayMegabytes: 20, 176 }, 177 } 178 179 // GetDefaultFlagValues returns a map of flag name to default value for the network 180 func (n *NetworkDefinition) GetDefaultFlagValues() map[string]any { 181 res := map[string]any{ 182 FlagNames.MysteriumAPIAddress: n.MysteriumAPIAddress, 183 FlagNames.DiscoveryAddress: n.DiscoveryAddress, 184 FlagNames.AccessPolicyOracleAddress: n.AccessPolicyOracleAddress, 185 FlagNames.BrokerAddressesFlag: n.BrokerAddresses, 186 FlagNames.TransactorAddress: n.TransactorAddress, 187 FlagNames.AffiliatorAddress: n.AffiliatorAddress, 188 189 FlagNames.MMNAddress: n.MMNAddress, 190 FlagNames.MMNAPIAddress: n.MMNAPIAddress, 191 FlagNames.PilvytisAddress: n.PilvytisAddress, 192 FlagNames.ObserverAddress: n.ObserverAddress, 193 FlagNames.DefaultChainIDFlag: n.DefaultChainID, 194 FlagNames.DefaultCurrency: n.DefaultCurrency, 195 FlagNames.LocationAddress: n.LocationAddress, 196 FlagNames.PaymentsDataLeewayMegabytes: n.Payments.DataLeewayMegabytes, 197 } 198 199 //chain 1 200 for k, v := range n.getChainFlagValues(1) { 201 res[k] = v 202 } 203 //chain 2 204 for k, v := range n.getChainFlagValues(2) { 205 res[k] = v 206 } 207 208 return res 209 } 210 211 // NetworkDefinitionFlagNames structure holds all parameters which define the flags for a network 212 type NetworkDefinitionFlagNames struct { 213 NetworkDefinition 214 BrokerAddressesFlag string 215 Chain1Flag ChainDefinitionFlagNames 216 Chain2Flag ChainDefinitionFlagNames 217 DefaultChainIDFlag string 218 PaymentsDataLeewayMegabytes string 219 } 220 221 // ChainDefinitionFlagNames structure holds all parameters which define the flags for a chain 222 type ChainDefinitionFlagNames struct { 223 ChainDefinition 224 ChainIDFlag string 225 EtherClientRPCFlag string 226 KnownHermesesFlag string 227 } 228 229 // FlagNames defines the flag that sets each network parameter 230 var FlagNames = NetworkDefinitionFlagNames{ 231 NetworkDefinition: NetworkDefinition{ 232 MysteriumAPIAddress: "api.address", 233 DiscoveryAddress: "discovery.address", 234 AccessPolicyOracleAddress: "access-policy.address", 235 TransactorAddress: "transactor.address", 236 AffiliatorAddress: "affiliator.address", 237 MMNAddress: "mmn.web-address", 238 MMNAPIAddress: "mmn.api-address", 239 PilvytisAddress: "pilvytis.address", 240 ObserverAddress: "observer.address", 241 DefaultCurrency: "default-currency", 242 LocationAddress: "location.address", 243 }, 244 BrokerAddressesFlag: "broker-address", 245 Chain1Flag: getChainDefinitionFlagNames(1), 246 Chain2Flag: getChainDefinitionFlagNames(2), 247 DefaultChainIDFlag: "chain-id", 248 PaymentsDataLeewayMegabytes: "payments.consumer.data-leeway-megabytes", 249 } 250 251 // DefaultNetwork defines default network values when no runtime parameters are given 252 var DefaultNetwork = MainnetDefinition 253 254 func getChainDefinitionFlagNames(chainIndex int) ChainDefinitionFlagNames { 255 return ChainDefinitionFlagNames{ 256 ChainDefinition: ChainDefinition{ 257 RegistryAddress: fmt.Sprintf("chains.%v.registry", chainIndex), 258 HermesID: fmt.Sprintf("chains.%v.hermes", chainIndex), 259 ChannelImplAddress: fmt.Sprintf("chains.%v.channelImplementation", chainIndex), 260 MystAddress: fmt.Sprintf("chains.%v.myst", chainIndex), 261 }, 262 ChainIDFlag: fmt.Sprintf("chains.%v.chainID", chainIndex), 263 EtherClientRPCFlag: fmt.Sprintf("ether.client.rpcl%v", chainIndex), 264 KnownHermesesFlag: fmt.Sprintf("chains.%v.knownHermeses", chainIndex), 265 } 266 } 267 268 func (n *NetworkDefinition) getChainFlagValues(chainIndex int) map[string]any { 269 chainDefinition := n.Chain1 270 if chainIndex == 2 { 271 chainDefinition = n.Chain2 272 } 273 274 flagNames := FlagNames.Chain1Flag 275 if chainIndex == 2 { 276 flagNames = FlagNames.Chain2Flag 277 } 278 279 return map[string]any{ 280 flagNames.RegistryAddress: chainDefinition.RegistryAddress, 281 flagNames.HermesID: chainDefinition.HermesID, 282 flagNames.ChannelImplAddress: chainDefinition.ChannelImplAddress, 283 flagNames.ChainIDFlag: chainDefinition.ChainID, 284 flagNames.MystAddress: chainDefinition.MystAddress, 285 flagNames.EtherClientRPCFlag: chainDefinition.EtherClientRPC, 286 flagNames.KnownHermesesFlag: chainDefinition.KnownHermeses, 287 } 288 }