Skip to content

Commit

Permalink
Simplify network name function (#2136)
Browse files Browse the repository at this point in the history
# Description
An alternative to PR #2130. It simplifies the network name function to
only include networks we actually use.
If a network is unknown, the string name includes both network and chain
id.
Notably compared to #2130, there are no naming changes.

# Changes

- Removed unused networks.
- Added Sepolia
- Added extra information to unknown networks.

## How to test

Unknown, as I don't know any protocol using other networks but those I
left here.
Specifically for Sepolia, you can compare with the autogenerated entry
[here](https://github.com/cowprotocol/services/pull/2130/files#diff-6fe1d095c8577cf6c68e84fa7d84e110cad2d1a38b83a3421513e475e9692007R1088).
  • Loading branch information
fedgiac authored Dec 8, 2023
1 parent bd466e5 commit 1b585b5
Showing 1 changed file with 7 additions and 152 deletions.
159 changes: 7 additions & 152 deletions crates/shared/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,162 +1,17 @@
use std::time::Duration;

/// Maps (NetworkId, ChainId) to the network name.
/// Contents of the "match" block obtained via:
/// wget -O - -o /dev/null https://chainid.network/chains.json | jq -r '.[] | [.networkId, .chainId, .name] | @tsv' | gawk '{print("(\""$1"\", "$2") => \""$3"\",")}'
/// If the output is from a known network, it represents the canonical name of
/// the network on CoW Protocol.
pub fn network_name(network_id: &str, chain_id: u64) -> &'static str {
// You can find a list of available networks by network and chain id here:
// https://chainid.network/chains.json
match (network_id, chain_id) {
("1", 1) => "Ethereum / Mainnet",
("10", 10) => "Optimistic",
("100", 100) => "xDAI",
("10000", 10000) => "Smart",
("10001", 10001) => "Smart",
("1001", 1001) => "Klaytn",
("1007", 1007) => "Newton",
("1", 101) => "EtherInc",
("1010", 1010) => "Evrice",
("1012", 1012) => "Newton",
("102", 102) => "Web3Games",
("1023", 1023) => "Clover",
("1024", 1024) => "Clover",
("108", 108) => "ThunderCore",
("11", 11) => "Metadium",
("1122334455", 1122334455) => "IPOS",
("1139", 1139) => "MathChain",
("1140", 1140) => "MathChain",
("12", 12) => "Metadium",
("122", 122) => "Fuse",
("128", 128) => "Huobi",
("1284", 1284) => "Moonbeam",
("1285", 1285) => "Moonriver",
("1286", 1286) => "Moonrock",
("1287", 1287) => "Moonbeam",
("13", 13) => "Diode",
("1313114", 1313114) => "Ether-1",
("1313161554", 1313161554) => "NEAR",
("1313161555", 1313161555) => "NEAR",
("1313161556", 1313161556) => "NEAR",
("1313500", 1313500) => "Xerom",
("13371337", 13371337) => "PepChain",
("137", 137) => "Matic",
("14", 14) => "Flare",
("15", 15) => "Diode",
("16", 16) => "Flare",
("162", 162) => "Lightstreams",
("11235813", 1620) => "Atheios",
("163", 163) => "Lightstreams",
("1666600000", 1666600000) => "Harmony",
("1666600001", 1666600001) => "Harmony",
("1666600002", 1666600002) => "Harmony",
("1666600003", 1666600003) => "Harmony",
("1666700000", 1666700000) => "Harmony",
("1666700001", 1666700001) => "Harmony",
("1666700002", 1666700002) => "Harmony",
("1666700003", 1666700003) => "Harmony",
("17", 17) => "ThaiChain",
("170", 170) => "HOO",
("18", 18) => "ThunderCore",
("18289463", 18289463) => "IOLite",
("1", 1856) => "Teslafunds",
("1987", 1987) => "EtherGem",
("1", 2) => "Expanse",
("20", 20) => "ELA-ETH-Sidechain",
("200625", 200625) => "Akroma",
("2020", 2020) => "420coin",
("2021", 2021) => "Edgeware",
("2022", 2022) => "Beresheet",
("21", 21) => "ELA-ETH-Sidechain",
("0", 211) => "Freight",
("22", 22) => "ELA-DID-Sidechain",
("23", 23) => "ELA-DID-Sidechain",
("37129", 24484) => "Webchain",
("246", 246) => "Energy",
("246529", 246529) => "ARTIS",
("246785", 246785) => "ARTIS",
("37480", 24734) => "MintMe.com",
("250", 250) => "Fantom",
("256", 256) => "Huobi",
("100", 269) => "High",
("28945486", 28945486) => "Auxilium",
("3", 3) => "Ethereum / Ropsten",
("30", 30) => "RSK",
("31", 31) => "RSK",
("1", 31102) => "Ethersocial",
("3125659152", 3125659152) => "Pirl",
("322", 322) => "KuCoin",
("32659", 32659) => "Fusion",
("33", 33) => "GoodData",
("35", 35) => "TBWG",
("35855456", 35855456) => "Joys",
("38", 38) => "Valorbit",
("385", 385) => "Lisinski",
("39797", 39797) => "Energi",
("4", 4) => "Ethereum / Rinkeby",
("40", 40) => "Telos",
("41", 41) => "Telos",
("42", 42) => "Ethereum / Kovan",
("420", 420) => "Optimistic",
("42069", 42069) => "pegglecoin",
("42220", 42220) => "Celo",
("43", 43) => "Darwinia",
("43110", 43110) => "Athereum",
("1", 43113) => "Avalanche",
("1", 43114) => "Avalanche",
("44", 44) => "Darwinia",
("44787", 44787) => "Celo",
("4689", 4689) => "IoTeX",
("4690", 4690) => "IoTeX",
("49797", 49797) => "Energi",
("499", 499) => "Rupaya",
("5", 5) => "Ethereum / Goerli",
("50", 50) => "XinFin",
("51", 51) => "XinFin",
("52", 52) => "CoinEx",
("53", 53) => "CoinEx",
("558", 558) => "Tao",
("56", 56) => "Binance",
("5869", 5869) => "Wegochain",
("595", 595) => "Acala",
("6", 6) => "Ethereum Classic / Kotti",
("60", 60) => "GoChain",
("1", 61) => "Ethereum Classic / Mainnet",
("61717561", 61717561) => "Aquachain",
("2", 62) => "Ethereum Classic / Morden",
("62320", 62320) => "Celo",
("7", 63) => "Ethereum Classic / Mordor",
("64", 64) => "Ellaism",
("65", 65) => "OKExChain",
("66", 66) => "OKExChain",
("67", 67) => "DBChain",
("68", 68) => "SoterOne",
("686", 686) => "Karura",
("69", 69) => "Optimistic",
("7", 7) => "ThaiChain",
("73799", 73799) => "Energy",
("76", 76) => "Mix",
("77", 77) => "POA",
("7762959", 7762959) => "Musicoin",
("777", 777) => "Ethermint",
("78", 78) => "PrimusChain",
("78110", 78110) => "Firenze",
("787", 787) => "Acala",
("88", 8) => "Ubiq",
("80001", 80001) => "Matic",
("8029", 8029) => "MDGL",
("82", 82) => "Meter",
("1", 820) => "Callisto",
("2", 821) => "Callisto",
("8217", 8217) => "Klaytn",
("8285", 8285) => "KorthoTest",
("88", 88) => "TomoChain",
("888", 888) => "Wanchain",
("8995", 8995) => "bloxberg",
("2", 9) => "Ubiq",
("97", 97) => "Binance",
("977", 977) => "Nepal",
("99", 99) => "POA",
("99415706", 99415706) => "Joys",
("999", 999) => "Wanchain",
_ => "<unknown>",
("100", 100) => "xDAI",
("11155111", 11155111) => "Ethereum / Sepolia",
_ => panic!("Unknown network (network_id={network_id}, chain_id={chain_id})"),
}
}

Expand Down

0 comments on commit 1b585b5

Please sign in to comment.