add nodes json

This commit is contained in:
ivan grachev 2023-11-01 19:20:01 +03:00
parent 9e9b34e689
commit d92f2eba41
3 changed files with 46 additions and 5 deletions

View File

@ -378,6 +378,7 @@
2C96D3A82763D13400687301 /* DataStateView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DataStateView.xib; sourceTree = "<group>"; };
2C9931DB2AEEC0E200577C8A /* NetworksListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworksListView.swift; sourceTree = "<group>"; };
2C9B55D02AF2AE4B008BE899 /* BundledNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundledNetwork.swift; sourceTree = "<group>"; };
2C9B55D42AF2B004008BE899 /* nodes-to-bundle.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "nodes-to-bundle.json"; sourceTree = "<group>"; };
2C9F0B6726BDCB2E008FA3D6 /* EthereumNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumNetwork.swift; sourceTree = "<group>"; };
2CAA412426C7CD93009F3535 /* ReviewRequester.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewRequester.swift; sourceTree = "<group>"; };
2CB3844327654BF600A189B9 /* error.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = error.js; path = "web3-provider/error.js"; sourceTree = "<group>"; };
@ -872,6 +873,7 @@
isa = PBXGroup;
children = (
2CED86A92AF00F56006F9E26 /* bundled-networks.json */,
2C9B55D42AF2B004008BE899 /* nodes-to-bundle.json */,
2CED86B52AF17D5A006F9E26 /* BundledNodes.swift */,
);
path = generated;

View File

@ -0,0 +1,27 @@
{
"1" : "https://mainnet.infura.io/v3/",
"5" : "https://goerli.infura.io/v3/",
"10" : "https://optimism-mainnet.infura.io/v3/",
"56" : "https://bsc-dataseed1.bnbchain.org",
"69" : "https://kovan.optimism.io/",
"97" : "https://data-seed-prebsc-1-s1.bnbchain.org:8545",
"100" : "https://rpc.gnosischain.com",
"137" : "https://polygon-mainnet.infura.io/v3/",
"250" : "https://rpc.ftm.tools",
"4002" : "https://rpc.testnet.fantom.network",
"8217" : "https://1rpc.io/klay",
"8453" : "https://mainnet.base.org/",
"42161" : "https://arbitrum-mainnet.infura.io/v3/",
"42220" : "https://forno.celo.org",
"43113" : "https://api.avax-test.network/ext/bc/C/rpc",
"43114" : "https://api.avax.network/ext/bc/C/rpc",
"64240" : "https://rpcapi.sonic.fantom.network/",
"80001" : "https://rpc-mumbai.maticvigil.com",
"421611" : "https://rinkeby.arbitrum.io/rpc",
"534351" : "https://sepolia-rpc.scroll.io",
"534352" : "https://rpc.scroll.io",
"7777777" : "https://rpc.zora.energy/",
"245022926" : "https://devnet.neonevm.org",
"245022934" : "https://neon-proxy-mainnet.solana.p2p.org/",
"1313161554" : "https://mainnet.aurora.dev"
}

View File

@ -5,8 +5,11 @@ import Foundation
let semaphore = DispatchSemaphore(value: 0)
let projectDir = FileManager.default.currentDirectoryPath
let networksFileURL = URL(fileURLWithPath: "\(projectDir)/tools/generated/bundled-networks.json")
let nodesFileURL = URL(fileURLWithPath: "\(projectDir)/tools/generated/BundledNodes.swift")
let base = "\(projectDir)/tools/generated/"
let bundledNetworksFileURL = URL(fileURLWithPath: base + "bundled-networks.json")
let nodesFileURL = URL(fileURLWithPath: base + "nodes-to-bundle.json")
let bundledNodesFileURL = URL(fileURLWithPath: base + "BundledNodes.swift")
let https = "https://"
@ -20,6 +23,15 @@ func fetchChains(completion: @escaping ([EIP155ChainData]) -> Void) {
}
func updateNodesFile(networks: [EthereumNetwork]) {
var dict = [String: String]()
for n in networks {
dict[String(n.chainId)] = n.nodeURLString
}
let dictData = try! JSONSerialization.data(withJSONObject: dict, options: [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes])
try! dictData.write(to: nodesFileURL)
let dictString = networks.map { "\($0.chainId): \"\($0.nodeURLString.dropFirst(https.count))\"" }.joined(separator: ",\n ")
let contents = """
import Foundation
@ -34,11 +46,11 @@ func updateNodesFile(networks: [EthereumNetwork]) {
"""
try! contents.data(using: .utf8)?.write(to: nodesFileURL)
try! contents.data(using: .utf8)?.write(to: bundledNodesFileURL)
}
fetchChains { chains in
let currentData = try! Data(contentsOf: networksFileURL)
let currentData = try! Data(contentsOf: bundledNetworksFileURL)
let currentNetworks = try! JSONDecoder().decode([EthereumNetwork].self, from: currentData)
let ids = Set(currentNetworks.map { $0.chainId })
@ -55,7 +67,7 @@ fetchChains { chains in
result = currentNetworks
let data = (try! encoder.encode(result)) + "\n".data(using: .utf8)!
try! data.write(to: networksFileURL)
try! data.write(to: bundledNetworksFileURL)
updateNodesFile(networks: result)
semaphore.signal()