Skip to content

Commit

Permalink
Bump web3protocol, which add cache for domain name resolution and res…
Browse files Browse the repository at this point in the history
…olve mode determination
  • Loading branch information
nand2 committed Dec 27, 2023
1 parent 55ca60c commit 0d7d844
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1,654 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"eth-provider": "^0.13.6",
"file-url": "^2.0.2",
"undici": "^5.20.0",
"web3protocol": "0.5.0",
"web3protocol": "0.5.4",
"webpack": "^5.76.1",
"webpack-cli": "^5.0.1",
"yargs": "^17.7.1"
Expand Down
53 changes: 27 additions & 26 deletions src/web3-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,35 @@ const registerWeb3Protocol = async (web3ChainOverrides) => {
const { Client } = await import('web3protocol');
const { getDefaultChainList } = await import('web3protocol/chains');

let result = protocol.registerStreamProtocol("web3", async (request, callback) => {
let debuggingHeaders = {}

// Get the default chains
let chainList = getDefaultChainList()

// Handle the overrides
web3ChainOverrides.forEach(chainOverride => {
// Find if the chain already exist
let alreadyDefinedChain = Object.entries(chainList).find(chain => chain[1].id == chainOverride.id) || null

// If it exists, override RPCs
if(alreadyDefinedChain) {
chainList[alreadyDefinedChain[0]].rpcUrls = [...chainOverride.rpcUrls]
}
// If does not exist, create it
else {
let newChain = {
id: chainOverride.id,
name: 'custom-' + chainOverride.id,
rpcUrls: [...chainOverride.rpcUrls],
}
chainList.push(newChain)
// Get the default chains
let chainList = getDefaultChainList()

// Handle the overrides
web3ChainOverrides.forEach(chainOverride => {
// Find if the chain already exist
let alreadyDefinedChain = Object.entries(chainList).find(chain => chain[1].id == chainOverride.id) || null

// If it exists, override RPCs
if(alreadyDefinedChain) {
chainList[alreadyDefinedChain[0]].rpcUrls = [...chainOverride.rpcUrls]
}
// If does not exist, create it
else {
let newChain = {
id: chainOverride.id,
name: 'custom-' + chainOverride.id,
rpcUrls: [...chainOverride.rpcUrls],
}
})
chainList.push(newChain)
}
})

// Create the web3Client
let web3Client = new Client(chainList)

// Create the web3Client
let web3Client = new Client(chainList)
// Process a web3:// call
let result = protocol.registerStreamProtocol("web3", async (request, callback) => {
let debuggingHeaders = {}

try {
// Parse the web3:// URL
Expand Down
Loading

0 comments on commit 0d7d844

Please sign in to comment.