|
|
|
@ -1,10 +1,37 @@ |
|
|
|
|
import { CompilerAbstract, SourcesCode } from '@remix-project/remix-solidity' |
|
|
|
|
import { AbstractVerifier } from './AbstractVerifier' |
|
|
|
|
import { SourcifyReceipt } from '../Receipts/SourcifyReceipt' |
|
|
|
|
import { SourcifyVerificationError, SourcifyVerificationResponse, SubmittedContract } from '../types/VerificationTypes' |
|
|
|
|
import { SubmittedContract, VerificationResponse } from '../types/VerificationTypes' |
|
|
|
|
|
|
|
|
|
interface SourcifyVerifyRequest { |
|
|
|
|
address: string |
|
|
|
|
chain: string |
|
|
|
|
files: Record<string, string> |
|
|
|
|
creatorTxHash?: string |
|
|
|
|
chosenContract?: string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type SourcifyVerificationStatus = 'perfect' | 'partial' | null |
|
|
|
|
|
|
|
|
|
interface SourcifyVerificationResponse { |
|
|
|
|
result: [ |
|
|
|
|
{ |
|
|
|
|
address: string |
|
|
|
|
chainId: string |
|
|
|
|
status: SourcifyVerificationStatus |
|
|
|
|
libraryMap: { |
|
|
|
|
[key: string]: string |
|
|
|
|
} |
|
|
|
|
message?: string |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface SourcifyVerificationError { |
|
|
|
|
error: 'string' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class SourcifyVerifier extends AbstractVerifier { |
|
|
|
|
async verify(submittedContract: SubmittedContract, compilerAbstract: CompilerAbstract) { |
|
|
|
|
async verify(submittedContract: SubmittedContract, compilerAbstract: CompilerAbstract): Promise<VerificationResponse> { |
|
|
|
|
const metadataStr = compilerAbstract.data.contracts[submittedContract.filePath][submittedContract.contractName].metadata |
|
|
|
|
const sources = compilerAbstract.source.sources |
|
|
|
|
console.log('selectedFilePath:', submittedContract.filePath) |
|
|
|
@ -20,8 +47,8 @@ export class SourcifyVerifier extends AbstractVerifier { |
|
|
|
|
acc[fileName] = content |
|
|
|
|
return acc |
|
|
|
|
}, {}) |
|
|
|
|
const body = { |
|
|
|
|
chainId: submittedContract.chainId, |
|
|
|
|
const body: SourcifyVerifyRequest = { |
|
|
|
|
chain: submittedContract.chainId, |
|
|
|
|
address: submittedContract.address, |
|
|
|
|
files: { |
|
|
|
|
'metadata.json': metadataStr, |
|
|
|
@ -41,12 +68,26 @@ export class SourcifyVerifier extends AbstractVerifier { |
|
|
|
|
|
|
|
|
|
if (!response.ok) { |
|
|
|
|
const errorResponse: SourcifyVerificationError = await response.json() |
|
|
|
|
console.error('Error on Sourcify verification at', this.apiUrl, 'Status:', response.status, 'Response:', JSON.stringify(errorResponse)) |
|
|
|
|
console.error('Error on Sourcify verification at ' + this.apiUrl + '\nStatus: ' + response.status + '\nResponse: ' + JSON.stringify(errorResponse)) |
|
|
|
|
throw new Error(errorResponse.error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const jsonResponse: SourcifyVerificationResponse = await response.json() |
|
|
|
|
return jsonResponse |
|
|
|
|
const verificationResponse: SourcifyVerificationResponse = await response.json() |
|
|
|
|
|
|
|
|
|
if (verificationResponse.result[0].status === null) { |
|
|
|
|
console.error('Error on Sourcify verification at ' + this.apiUrl + '\nStatus: ' + response.status + '\nResponse: ' + verificationResponse.result[0].message) |
|
|
|
|
throw new Error(verificationResponse.result[0].message) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Map to a user-facing status message
|
|
|
|
|
let status = 'unknown' |
|
|
|
|
if (verificationResponse.result[0].status === 'perfect') { |
|
|
|
|
status = 'fully verified' |
|
|
|
|
} else if (verificationResponse.result[0].status === 'partial') { |
|
|
|
|
status = 'partially verified' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { status, receiptId: null } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async lookup(): Promise<any> { |
|
|
|
|