Move abiEncodedConstrArgs state to VerifyView and pass along the EtherscanRequest

pull/5285/head
Kaan Uzdoğan 5 months ago committed by Aniket
parent 7c106b6f34
commit 23293a6b85
  1. 12
      apps/contract-verification/src/app/Verifiers/EtherscanVerifier.ts
  2. 8
      apps/contract-verification/src/app/components/ConstructorArguments.tsx
  3. 9
      apps/contract-verification/src/app/types/VerificationTypes.ts
  4. 5
      apps/contract-verification/src/app/views/VerifyView.tsx

@ -1,7 +1,7 @@
import {CompilerAbstract} from '@remix-project/remix-solidity'
import {AbstractVerifier} from './AbstractVerifier'
import {EtherscanReceipt} from '../Receipts/EtherscanReceipt'
import {EtherscanResponse} from '../types/VerificationTypes'
import {EtherscanRequest, EtherscanResponse} from '../types/VerificationTypes'
export class EtherscanVerifier extends AbstractVerifier {
apiKey: string
@ -11,21 +11,25 @@ export class EtherscanVerifier extends AbstractVerifier {
this.apiKey = apiKey
}
async verify(chainId: string, address: string, compilerAbstract: CompilerAbstract, selectedContractFileAndName: string) {
async verify(chainId: string, address: string, compilerAbstract: CompilerAbstract, selectedContractFileAndName: string, abiEncodedConstructorArgs?: string) {
const CODE_FORMAT = 'solidity-standard-json-input'
const [_triggerFilePath, selectedFilePath, selectedContractName] = selectedContractFileAndName.split(':')
// TODO: Handle version Vyper contracts. This relies on Solidity metadata.
const metadata = JSON.parse(compilerAbstract.data.contracts[selectedFilePath][selectedContractName].metadata)
const body = {
const body: EtherscanRequest = {
chainId,
codeformat: CODE_FORMAT,
sourceCode: compilerAbstract.input,
sourceCode: JSON.stringify(compilerAbstract.input),
contractaddress: address,
contractname: selectedContractFileAndName,
compilerversion: metadata.compiler.version,
}
if (abiEncodedConstructorArgs) {
body.constructorArguements = abiEncodedConstructorArgs
}
const url = new URL('api', this.apiUrl)
url.searchParams.append('module', 'contract')
url.searchParams.append('action', 'verifysourcecode')

@ -5,10 +5,14 @@ import {AppContext} from '../AppContext'
const abiCoder = new ethers.utils.AbiCoder()
export const ConstructorArguments = () => {
interface ConstructorArgumentsProps {
abiEncodedConstructorArgs: string
setAbiEncodedConstructorArgs: React.Dispatch<React.SetStateAction<string>>
}
export const ConstructorArguments: React.FC<ConstructorArgumentsProps> = ({abiEncodedConstructorArgs, setAbiEncodedConstructorArgs}) => {
const {selectedContractFileAndName, compilationOutput} = React.useContext(AppContext)
const [constructorArgsValues, setConstructorArgsValues] = React.useState<string[]>([])
const [abiEncodedConstructorArgs, setAbiEncodedConstructorArgs] = React.useState<string>('')
const [abiEncodingError, setAbiEncodingError] = React.useState<string | null>('')
const [toggleRawInput, setToggleRawInput] = React.useState<boolean>(false)

@ -63,6 +63,15 @@ export interface SourcifyVerificationError {
error: 'string'
}
export interface EtherscanRequest {
chainId?: string
codeformat: 'solidity-standard-json-input'
sourceCode: string
contractaddress: string
contractname: string
compilerversion: string
constructorArguements?: string
}
export interface EtherscanResponse {
status: '0' | '1'
message: string

@ -15,6 +15,7 @@ export const VerifyView = () => {
const [contractAddress, setContractAddress] = useState('')
const [contractAddressError, setContractAddressError] = useState('')
const [selectedChain, setSelectedChain] = useState<Chain | undefined>()
const [abiEncodedConstructorArgs, setAbiEncodedConstructorArgs] = React.useState<string>('')
const navigate = useNavigate()
useEffect(() => {
@ -79,7 +80,7 @@ export const VerifyView = () => {
}
} else if (verifier instanceof EtherscanVerifier) {
try {
const response = await verifier.verify(selectedChain?.chainId.toString(), contractAddress, compilerAbstract, selectedContractFileAndName)
const response = await verifier.verify(selectedChain?.chainId.toString(), contractAddress, compilerAbstract, selectedContractFileAndName, abiEncodedConstructorArgs)
receipt.status = 'perfect'
} catch (e) {
const err = e as Error
@ -152,7 +153,7 @@ export const VerifyView = () => {
))}
</div>
<div>
<ConstructorArguments />
<ConstructorArguments abiEncodedConstructorArgs={abiEncodedConstructorArgs} setAbiEncodedConstructorArgs={setAbiEncodedConstructorArgs} />
</div>
</form>
</div>

Loading…
Cancel
Save