Add lookupUrls to lookup function results

pull/5285/head
Manuel Wedler 4 months ago committed by Aniket
parent e9eee01cf5
commit 724b1ad695
  1. 8
      apps/contract-verification/src/app/Verifiers/AbstractVerifier.ts
  2. 18
      apps/contract-verification/src/app/Verifiers/EtherscanVerifier.ts
  3. 10
      apps/contract-verification/src/app/Verifiers/SourcifyVerifier.ts
  4. 6
      apps/contract-verification/src/app/Verifiers/index.ts
  5. 1
      apps/contract-verification/src/app/types/VerificationTypes.ts
  6. 2
      apps/contract-verification/src/app/views/VerifyView.tsx

@ -6,14 +6,10 @@ export interface AbstractVerifier {
}
export abstract class AbstractVerifier {
apiUrl: string
// TODO remove prop
enabled: boolean
enabled = true
constructor(apiUrl: string) {
this.apiUrl = apiUrl
this.enabled = true
}
constructor(public apiUrl: string, public explorerUrl: string) {}
abstract verify(submittedContract: SubmittedContract, compilerAbstract: CompilerAbstract): Promise<VerificationResponse>
abstract lookup(contractAddress: string, chainId: string): Promise<LookupResponse>

@ -25,11 +25,8 @@ interface EtherscanCheckStatusResponse {
}
export class EtherscanVerifier extends AbstractVerifier {
apiKey?: string
constructor(apiUrl: string, apiKey?: string) {
super(apiUrl)
this.apiKey = apiKey
constructor(apiUrl: string, explorerUrl: string, private apiKey?: string) {
super(apiUrl, explorerUrl)
}
async verify(submittedContract: SubmittedContract, compilerAbstract: CompilerAbstract): Promise<VerificationResponse> {
@ -142,13 +139,20 @@ export class EtherscanVerifier extends AbstractVerifier {
const lookupResponse: EtherscanRpcResponse = await response.json()
const lookupUrl = this.getContractCodeUrl(contractAddress)
if (lookupResponse.result === 'Contract source code not verified') {
return { status: 'not verified' }
return { status: 'not verified', lookupUrl }
} else if (lookupResponse.status !== '1' || !lookupResponse.message.startsWith('OK')) {
console.error('Error on Etherscan API lookup at ' + this.apiUrl + '\nStatus: ' + lookupResponse.status + '\nMessage: ' + lookupResponse.message + '\nResult: ' + lookupResponse.result)
throw new Error(lookupResponse.result)
}
return { status: 'verified' }
return { status: 'verified', lookupUrl }
}
getContractCodeUrl(address: string): string {
const url = new URL(`address/${address}#code`, this.explorerUrl)
return url.href
}
}

@ -113,14 +113,22 @@ export class SourcifyVerifier extends AbstractVerifier {
const lookupResponse: SourcifyLookupResponse = (await response.json())[0]
let status: VerificationStatus = 'unknown'
let lookupUrl: string | undefined = undefined
if (lookupResponse.status === 'false') {
status = 'not verified'
} else if (lookupResponse.chainIds?.[0].status === 'perfect') {
status = 'fully verified'
lookupUrl = this.getContractCodeUrl(contractAddress, chainId, true)
} else if (lookupResponse.chainIds?.[0].status === 'partial') {
status = 'partially verified'
lookupUrl = this.getContractCodeUrl(contractAddress, chainId, false)
}
return { status }
return { status, lookupUrl }
}
getContractCodeUrl(address: string, chainId: string, fullMatch: boolean): string {
const url = new URL(`contracts/${fullMatch ? 'full_match' : 'partial_match'}/${chainId}/${address}`, this.explorerUrl)
return url.href
}
}

@ -10,13 +10,13 @@ export { EtherscanVerifier } from './EtherscanVerifier'
export function getVerifier(identifier: VerifierIdentifier, settings: VerifierSettings): AbstractVerifier {
switch (identifier) {
case 'Sourcify':
return new SourcifyVerifier(settings.apiUrl)
return new SourcifyVerifier(settings.apiUrl, settings.explorerUrl)
case 'Etherscan':
if (!settings.apiKey) {
throw new Error('The Etherscan verifier requires an API key.')
}
return new EtherscanVerifier(settings.apiUrl, settings.apiKey)
return new EtherscanVerifier(settings.apiUrl, settings.explorerUrl, settings.apiKey)
case 'Blockscout':
return new EtherscanVerifier(settings.apiUrl)
return new EtherscanVerifier(settings.apiUrl, settings.explorerUrl)
}
}

@ -21,6 +21,7 @@ export type VerifierIdentifier = 'Sourcify' | 'Etherscan' | 'Blockscout'
export interface VerifierSettings {
apiUrl: string
explorerUrl: string
apiKey?: string
}

@ -66,7 +66,7 @@ export const VerifyView = () => {
// Verify for each verifier. forEach does not wait for await and each promise will execute in parallel
receipts.forEach(async (receipt) => {
const { verifierInfo } = receipt
const verifier = getVerifier(verifierInfo.name, { apiUrl: verifierInfo.apiUrl })
const verifier = getVerifier(verifierInfo.name, { apiUrl: verifierInfo.apiUrl, explorerUrl: '' })
try {
const response = await verifier.verify(newSubmittedContract, compilerAbstract)
receipt.status = response.status

Loading…
Cancel
Save