Add lookup function to EtherscanVerifier

pull/5285/head
Manuel Wedler 4 months ago committed by Aniket
parent b7283789af
commit e9eee01cf5
  1. 45
      apps/contract-verification/src/app/Verifiers/EtherscanVerifier.ts

@ -1,6 +1,6 @@
import { CompilerAbstract } from '@remix-project/remix-solidity'
import { AbstractVerifier } from './AbstractVerifier'
import { SubmittedContract, VerificationResponse, VerificationStatus } from '../types/VerificationTypes'
import { LookupResponse, SubmittedContract, VerificationResponse, VerificationStatus } from '../types/VerificationTypes'
interface EtherscanVerificationRequest {
chainId?: string
@ -12,7 +12,7 @@ interface EtherscanVerificationRequest {
constructorArguements?: string
}
interface EtherscanVerificationResponse {
interface EtherscanRpcResponse {
status: '0' | '1'
message: string
result: string
@ -69,7 +69,7 @@ export class EtherscanVerifier extends AbstractVerifier {
throw new Error(responseText)
}
const verificationResponse: EtherscanVerificationResponse = await response.json()
const verificationResponse: EtherscanRpcResponse = await response.json()
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)
@ -89,9 +89,7 @@ export class EtherscanVerifier extends AbstractVerifier {
url.searchParams.append('apikey', this.apiKey)
}
const response = await fetch(url.href, {
method: 'GET',
})
const response = await fetch(url.href, { method: 'GET' })
if (!response.ok) {
const responseText = await response.text()
@ -125,13 +123,32 @@ export class EtherscanVerifier extends AbstractVerifier {
return status
}
async lookup(): Promise<any> {
// TODO type
// Implement the lookup logic here
console.log('Etherscan lookup started')
// Placeholder logic for lookup
const lookupResult = {} // Replace with actual lookup logic
console.log('Etherscan lookup completed')
return lookupResult
async lookup(contractAddress: string, chainId: string): Promise<LookupResponse> {
const url = new URL('api', this.apiUrl)
url.searchParams.append('module', 'contract')
url.searchParams.append('action', 'getabi')
url.searchParams.append('address', contractAddress)
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 lookup at ' + this.apiUrl + '\nStatus: ' + response.status + '\nResponse: ' + responseText)
throw new Error(responseText)
}
const lookupResponse: EtherscanRpcResponse = await response.json()
if (lookupResponse.result === 'Contract source code not verified') {
return { status: 'not verified' }
} 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' }
}
}

Loading…
Cancel
Save