pull/5285/head
parent
c2b185dc02
commit
7ad629c4c4
@ -0,0 +1,57 @@ |
||||
import {SourcesCode} from '@remix-project/remix-solidity' |
||||
import {AbstractVerifier} from './AbstractVerifier' |
||||
|
||||
export class SourcifyVerifier { |
||||
name: string |
||||
apiUrl: string |
||||
|
||||
constructor(apiUrl: string, name: string = 'Sourcify') { |
||||
this.apiUrl = apiUrl |
||||
this.name = name |
||||
} |
||||
|
||||
async verify(chainId: string, address: string, sources: SourcesCode, metadataStr: string): Promise<boolean> { |
||||
// from { "filename.sol": {content: "contract MyContract { ... }"} }
|
||||
// to { "filename.sol": "contract MyContract { ... }" }
|
||||
const formattedSources = Object.entries(sources).reduce((acc, [fileName, {content}]) => { |
||||
acc[fileName] = content |
||||
return acc |
||||
}, {}) |
||||
const body = { |
||||
chainId, |
||||
address, |
||||
files: { |
||||
'metadata.json': metadataStr, |
||||
...formattedSources, |
||||
}, |
||||
} |
||||
|
||||
console.log(body) |
||||
|
||||
const response = await fetch(new URL('verify', this.apiUrl).href, { |
||||
method: 'POST', |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
}, |
||||
body: JSON.stringify(body), |
||||
}) |
||||
|
||||
if (!response.ok) { |
||||
throw new Error(`Error on Sourcify verification at ${this.apiUrl}: Status:${response.status} Response: ${await response.text()}`) |
||||
} |
||||
|
||||
const data = await response.json() |
||||
console.log(data) |
||||
|
||||
return data.result |
||||
} |
||||
|
||||
async lookup(): Promise<any> { |
||||
// Implement the lookup logic here
|
||||
console.log('Sourcify lookup started') |
||||
// Placeholder logic for lookup
|
||||
const lookupResult = {} // Replace with actual lookup logic
|
||||
console.log('Sourcify lookup completed') |
||||
return lookupResult |
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
import {SourcifyVerifier} from '../Verifiers/SourcifyVerifier' |
||||
|
||||
export interface VerifiedContract { |
||||
name: string |
||||
address: string |
||||
chainId: string |
||||
date: Date |
||||
verifier: SourcifyVerifier |
||||
status: string |
||||
receipt?: string |
||||
} |
||||
|
||||
interface Currency { |
||||
name: string |
||||
symbol: string |
||||
decimals: number |
||||
} |
||||
// types for https://chainid.network/chains.json (i.e. https://github.com/ethereum-lists/chains)
|
||||
export interface Chain { |
||||
name: string |
||||
title?: string |
||||
chainId: number |
||||
shortName?: string |
||||
network?: string |
||||
networkId?: number |
||||
nativeCurrency?: Currency |
||||
rpc: Array<string> |
||||
faucets?: string[] |
||||
infoURL?: string |
||||
} |
Loading…
Reference in new issue