Add checkVerificationStatus to Etherscan Verifier

pull/5285/head
Manuel Wedler 5 months ago committed by Aniket
parent cfbf7e55a0
commit 8cf9ee652f
  1. 6
      apps/contract-verification/src/app/Verifiers/AbstractVerifier.ts
  2. 57
      apps/contract-verification/src/app/Verifiers/EtherscanVerifier.ts
  3. 6
      apps/contract-verification/src/app/types/VerificationTypes.ts

@ -1,5 +1,9 @@
import { CompilerAbstract } from '@remix-project/remix-solidity'
import { SubmittedContract, VerificationResponse } from '../types/VerificationTypes'
import { SubmittedContract, VerificationResponse, VerificationStatus } from '../types/VerificationTypes'
export interface AbstractVerifier {
checkVerificationStatus?(receiptId: string): Promise<VerificationStatus>
}
export abstract class AbstractVerifier {
apiUrl: string

@ -1,6 +1,6 @@
import { CompilerAbstract } from '@remix-project/remix-solidity'
import { AbstractVerifier } from './AbstractVerifier'
import { SubmittedContract, VerificationResponse } from '../types/VerificationTypes'
import { SubmittedContract, VerificationResponse, VerificationStatus } from '../types/VerificationTypes'
interface EtherscanVerificationRequest {
chainId?: string
@ -18,6 +18,12 @@ interface EtherscanVerificationResponse {
result: string
}
interface EtherscanCheckStatusResponse {
status: '0' | '1'
message: string
result: 'Pending in queue' | 'Pass - Verified' | 'Fail - Unable to verify' | 'Unknown UID'
}
export class EtherscanVerifier extends AbstractVerifier {
apiKey?: string
@ -59,7 +65,7 @@ export class EtherscanVerifier extends AbstractVerifier {
if (!response.ok) {
const responseText = await response.text()
console.error('Error on Etherscan API verification at ' + this.apiUrl + '\nStatus: ' + response.status + '\nResponse: ' + (responseText))
console.error('Error on Etherscan API verification at ' + this.apiUrl + '\nStatus: ' + response.status + '\nResponse: ' + responseText)
throw new Error(responseText)
}
@ -73,7 +79,54 @@ export class EtherscanVerifier extends AbstractVerifier {
return { status: 'pending', receiptId: verificationResponse.result }
}
// TODO retry with backoff in case this throws error
async checkVerificationStatus(receiptId: string): Promise<VerificationStatus> {
const url = new URL('api', this.apiUrl)
url.searchParams.append('module', 'contract')
url.searchParams.append('action', 'checkverifystatus')
url.searchParams.append('guid', receiptId)
if (this.apiKey) {
url.searchParams.append('apikey', this.apiKey)
}
const response = await fetch(url.href, {
method: 'GET',
})
if (!response.ok) {
const responseText = await response.text()
console.error('Error on Etherscan API check verification status at ' + this.apiUrl + '\nStatus: ' + response.status + '\nResponse: ' + responseText)
throw new Error(responseText)
}
const checkStatusResponse: EtherscanCheckStatusResponse = await response.json()
if (checkStatusResponse.status !== '1' || !checkStatusResponse.message.startsWith('OK')) {
console.error('Error on Etherscan API check verification status at ' + this.apiUrl + '\nStatus: ' + checkStatusResponse.status + '\nMessage: ' + checkStatusResponse.message + '\nResult: ' + checkStatusResponse.result)
throw new Error(checkStatusResponse.result)
}
if (checkStatusResponse.result === 'Unknown UID') {
console.error('Error on Etherscan API check verification status at ' + this.apiUrl + '\nStatus: ' + checkStatusResponse.status + '\nMessage: ' + checkStatusResponse.message + '\nResult: ' + checkStatusResponse.result)
throw new Error(checkStatusResponse.result)
}
let status = 'unknown'
if (checkStatusResponse.result === 'Fail - Unable to verify') {
status = 'failed'
}
if (checkStatusResponse.result === 'Pending in queue') {
status = 'pending'
}
if (checkStatusResponse.result === 'Pass - Verified') {
status = 'verified'
}
return status
}
async lookup(): Promise<any> {
// TODO type
// Implement the lookup logic here
console.log('Etherscan lookup started')
// Placeholder logic for lookup

@ -32,7 +32,7 @@ export interface VerifierInfo {
export interface VerificationReceipt {
receiptId?: string
verifierInfo: VerifierInfo
status: string | 'error' | 'pending' | null
status: VerificationStatus | null
message?: string
}
@ -68,7 +68,9 @@ export function isContract(contract: SubmittedContract | SubmittedProxyContract)
return contract.type === 'contract'
}
export type VerificationStatus = string | 'error' | 'pending'
export interface VerificationResponse {
status: string | 'pending'
status: VerificationStatus
receiptId: string | null
}

Loading…
Cancel
Save