@ -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