Skip to content

Commit

Permalink
🚨 Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
William Cory authored and William Cory committed Aug 11, 2024
1 parent b3f12a5 commit 6abdb65
Showing 1 changed file with 57 additions and 57 deletions.
114 changes: 57 additions & 57 deletions bundler-packages/whatsabi/src/resolveContractUri.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,67 @@ import { loadAbi } from './loadAbi.js'
import { parseUri } from './parseUri.js'

export class UnknownChainError extends Error {
/**
* @type {'UnknownChainError'}
* @override
*/
name = 'UnknownChainError'
/**
* @type {'UnknownChainError'}
*/
_tag = 'UnknownChainError'
/**
* @param {number} chainId
*/
constructor(chainId) {
super(
`Unknown chain ID: ${chainId}. No default rpc known. Please pass in a valid rpc url as a query string \`?rpcUrl=\${rpcUrl}\` or open a pr to viem to add your chain to viem/chains`,
)
}
/**
* @type {'UnknownChainError'}
* @override
*/
name = 'UnknownChainError'
/**
* @type {'UnknownChainError'}
*/
_tag = 'UnknownChainError'
/**
* @param {number} chainId
*/
constructor(chainId) {
super(
`Unknown chain ID: ${chainId}. No default rpc known. Please pass in a valid rpc url as a query string \`?rpcUrl=\${rpcUrl}\` or open a pr to viem to add your chain to viem/chains`,
)
}
}

// TODO pass in tevm config too
/**
* @param {import('./ContractUri.js').ContractUri} contractUri
* @param {import('@tevm/config').ResolvedCompilerConfig} config
* @returns { Promise<{abi: import('@tevm/utils').Abi, address: import('@tevm/utils').Address, deployedBytecode: import('@tevm/utils').Hex} | undefined>}
* @throws {UnknownChainError} if the chainId is not known and no rpcUrl is provided
*/
* @param {import('./ContractUri.js').ContractUri} contractUri
* @param {import('@tevm/config').ResolvedCompilerConfig} config
* @returns { Promise<{abi: import('@tevm/utils').Abi, address: import('@tevm/utils').Address, deployedBytecode: import('@tevm/utils').Hex} | undefined>}
* @throws {UnknownChainError} if the chainId is not known and no rpcUrl is provided
*/
export const resolveContractUri = async (contractUri, config) => {
console.log('todo config', config)
const parsedUri = parseUri(contractUri)
if (!parsedUri) {
return undefined
}
const chain = knownChains[parsedUri.chainId]
if (!chain && !parsedUri.rpcUrl) {
throw new UnknownChainError(parsedUri.chainId)
}
const client = createClient({
transport: http(parsedUri.rpcUrl),
chain,
})
const explorerUrl = parsedUri.etherscanBaseUrl ?? chain.blockExplorers?.default.url
console.log('todo config', config)
const parsedUri = parseUri(contractUri)
if (!parsedUri) {
return undefined
}
const chain = knownChains[parsedUri.chainId]
if (!chain && !parsedUri.rpcUrl) {
throw new UnknownChainError(parsedUri.chainId)
}
const client = createClient({
transport: http(parsedUri.rpcUrl),
chain,
})
const explorerUrl = parsedUri.etherscanBaseUrl ?? chain.blockExplorers?.default.url

const whatsabiResult = await loadAbi({
client,
explorerUrl,
address: parsedUri.address,
followProxies: parsedUri.followProxies ?? true,
etherscanApiKey: parsedUri.etherscanApiKey,
})
const deployedBytecode = await getCode(client, {
address: /** @type {import('@tevm/utils').Address}*/ (whatsabiResult.address),
})
if (!deployedBytecode) {
throw new Error('Could not fetch deployed bytecode')
}
return {
abi: /** @type {any}*/ (whatsabiResult.abi),
address: parsedUri.address,
deployedBytecode,
// TODO we want to represent proxies in some way like listing the resolved addy
// ...{resolvedAddress: whatsabiResult.address},
// TODO if we can get a verified contract we should compile it with solc and return solc output too
}
const whatsabiResult = await loadAbi({
client,
explorerUrl,
address: parsedUri.address,
followProxies: parsedUri.followProxies ?? true,
etherscanApiKey: parsedUri.etherscanApiKey,
})
const deployedBytecode = await getCode(client, {
address: /** @type {import('@tevm/utils').Address}*/ (whatsabiResult.address),
})
if (!deployedBytecode) {
throw new Error('Could not fetch deployed bytecode')
}
return {
abi: /** @type {any}*/ (whatsabiResult.abi),
address: parsedUri.address,
deployedBytecode,
// TODO we want to represent proxies in some way like listing the resolved addy
// ...{resolvedAddress: whatsabiResult.address},
// TODO if we can get a verified contract we should compile it with solc and return solc output too
}
}

0 comments on commit 6abdb65

Please sign in to comment.