Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelwedler committed Oct 29, 2024
1 parent 424863b commit ee43748
Show file tree
Hide file tree
Showing 7 changed files with 347 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class BlockscoutVerifier extends EtherscanVerifier {
super(apiUrl, apiUrl, undefined)
}

getContractCodeUrl(address: string): string {
getContractCodeUrl(address: string, chainId: string): string {
const url = new URL(this.explorerUrl + `/address/${address}`)
url.searchParams.append('tab', 'contract')
return url.href
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ export class EtherscanVerifier extends AbstractVerifier {
}

const verificationResponse: EtherscanRpcResponse = await response.json()
const lookupUrl = this.getContractCodeUrl(submittedContract.address, submittedContract.chainId)

if (verificationResponse.result.includes('already verified')) {
return { status: 'already verified', receiptId: null, lookupUrl: this.getContractCodeUrl(submittedContract.address) }
return { status: 'already verified', receiptId: null, lookupUrl }
}

if (verificationResponse.status !== '1' || verificationResponse.message !== 'OK') {
console.error('Error on Etherscan API verification at ' + this.apiUrl + '\nStatus: ' + verificationResponse.status + '\nMessage: ' + verificationResponse.message + '\nResult: ' + verificationResponse.result)
throw new Error(verificationResponse.result)
}

const lookupUrl = this.getContractCodeUrl(submittedContract.address)
return { status: 'pending', receiptId: verificationResponse.result, lookupUrl }
}

Expand Down Expand Up @@ -239,13 +239,13 @@ export class EtherscanVerifier extends AbstractVerifier {
return { status: 'not verified' }
}

const lookupUrl = this.getContractCodeUrl(contractAddress)
const lookupUrl = this.getContractCodeUrl(contractAddress, chainId)
const { sourceFiles, targetFilePath } = this.processReceivedFiles(lookupResponse.result[0], contractAddress, chainId)

return { status: 'verified', lookupUrl, sourceFiles, targetFilePath }
}

getContractCodeUrl(address: string): string {
getContractCodeUrl(address: string, chainId: string): string {
const url = new URL(this.explorerUrl + `/address/${address}#code`)
return url.href
}
Expand Down
10 changes: 10 additions & 0 deletions apps/contract-verification/src/app/Verifiers/RoutescanVerifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { EtherscanVerifier } from "./EtherscanVerifier";

export class RoutescanVerifier extends EtherscanVerifier {
LOOKUP_STORE_DIR = 'routescan-verified'

getContractCodeUrl(address: string, chainId: string): string {
const url = new URL(this.explorerUrl + `/address/${address}/contract/${chainId}/code`)
return url.href
}
}
4 changes: 4 additions & 0 deletions apps/contract-verification/src/app/Verifiers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { AbstractVerifier } from './AbstractVerifier'
import { BlockscoutVerifier } from './BlockscoutVerifier'
import { EtherscanVerifier } from './EtherscanVerifier'
import { SourcifyVerifier } from './SourcifyVerifier'
import { RoutescanVerifier } from './RoutescanVerifier'

export { AbstractVerifier } from './AbstractVerifier'
export { BlockscoutVerifier } from './BlockscoutVerifier'
export { SourcifyVerifier } from './SourcifyVerifier'
export { EtherscanVerifier } from './EtherscanVerifier'
export { RoutescanVerifier } from './RoutescanVerifier'

export function getVerifier(identifier: VerifierIdentifier, settings: VerifierSettings): AbstractVerifier {
switch (identifier) {
Expand All @@ -26,5 +28,7 @@ export function getVerifier(identifier: VerifierIdentifier, settings: VerifierSe
return new EtherscanVerifier(settings.apiUrl, settings.explorerUrl, settings.apiKey)
case 'Blockscout':
return new BlockscoutVerifier(settings.apiUrl)
case 'Routescan':
return new RoutescanVerifier(settings.apiUrl, settings.explorerUrl, settings.apiKey)
}
}
4 changes: 2 additions & 2 deletions apps/contract-verification/src/app/types/VerificationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export interface Chain {
infoURL?: string
}

export type VerifierIdentifier = 'Sourcify' | 'Etherscan' | 'Blockscout'
export const VERIFIERS: VerifierIdentifier[] = ['Sourcify', 'Etherscan', 'Blockscout']
export type VerifierIdentifier = 'Sourcify' | 'Etherscan' | 'Blockscout' | 'Routescan'
export const VERIFIERS: VerifierIdentifier[] = ['Sourcify', 'Etherscan', 'Blockscout', 'Routescan']

export interface VerifierInfo {
name: VerifierIdentifier
Expand Down
Loading

0 comments on commit ee43748

Please sign in to comment.