From a0fdb3e2221a0229e35fe3a7018b963dc6fe4bfe Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 18 May 2023 12:55:57 +0530 Subject: [PATCH] chainid to verify --- apps/etherscan/src/app/RemixPlugin.tsx | 4 ++-- apps/etherscan/src/app/app.tsx | 2 +- apps/etherscan/src/app/utils/utilities.ts | 17 ++++------------- apps/etherscan/src/app/utils/verify.ts | 14 ++++++++++---- apps/etherscan/src/app/views/ReceiptsView.tsx | 2 +- apps/etherscan/src/app/views/VerifyView.tsx | 1 + 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/apps/etherscan/src/app/RemixPlugin.tsx b/apps/etherscan/src/app/RemixPlugin.tsx index 13d5bdfe73..a62f9cefbd 100644 --- a/apps/etherscan/src/app/RemixPlugin.tsx +++ b/apps/etherscan/src/app/RemixPlugin.tsx @@ -9,7 +9,7 @@ export class RemixClient extends PluginClient { } async verify (apiKey: string, contractAddress: string, contractArguments: string, contractName: string, compilationResultParam: any) { - const result = await verify(apiKey, contractAddress, contractArguments, contractName, compilationResultParam, this, + const result = await verify(apiKey, contractAddress, contractArguments, contractName, compilationResultParam, null, this, (value: EtherScanReturn) => {}, (value: string) => {}) return result } @@ -20,7 +20,7 @@ export class RemixClient extends PluginClient { if (network === "vm") { throw new Error("Cannot check the receipt status in the selected network") } - const etherscanApi = getEtherScanApi(network, networkId) + const etherscanApi = getEtherScanApi(networkId) const receiptStatus = await getReceiptStatus(receiptGuid, apiKey, etherscanApi) return { message: receiptStatus.result, diff --git a/apps/etherscan/src/app/app.tsx b/apps/etherscan/src/app/app.tsx index be6564d422..b5f06bc166 100644 --- a/apps/etherscan/src/app/app.tsx +++ b/apps/etherscan/src/app/app.tsx @@ -106,7 +106,7 @@ const App = () => { const status = await getReceiptStatus( item.guid, apiKey, - getEtherScanApi(network, networkId) + getEtherScanApi(networkId) ) if (status.result === "Pass - Verified" || status.result === "Already Verified") { newReceipts = newReceipts.map((currentReceipt: Receipt) => { diff --git a/apps/etherscan/src/app/utils/utilities.ts b/apps/etherscan/src/app/utils/utilities.ts index 500872e2d1..20eb38c73e 100644 --- a/apps/etherscan/src/app/utils/utilities.ts +++ b/apps/etherscan/src/app/utils/utilities.ts @@ -14,20 +14,11 @@ export type receiptStatus = { status: string } -export const getEtherScanApi = (network: string, networkId: any) => { - let apiUrl - - if (network === "main") { - apiUrl = "https://api.etherscan.io/api" - } else if (network === "custom") { - if (!(networkId in scanAPIurls)) { - throw new Error("no known network to verify against") - } - apiUrl = (scanAPIurls as any)[networkId] - } else { - apiUrl = `https://api-${network}.etherscan.io/api` +export const getEtherScanApi = (networkId: any) => { + if (!(networkId in scanAPIurls)) { + throw new Error("no known network to verify against") } - + const apiUrl = (scanAPIurls as any)[networkId] return apiUrl } diff --git a/apps/etherscan/src/app/utils/verify.ts b/apps/etherscan/src/app/utils/verify.ts index 1b2040ad0b..3d8bd875ae 100644 --- a/apps/etherscan/src/app/utils/verify.ts +++ b/apps/etherscan/src/app/utils/verify.ts @@ -20,19 +20,25 @@ export const verify = async ( contractAddress: string, contractArgumentsParam: string, contractName: string, - compilationResultParam: CompilerAbstract, + compilationResultParam: CompilerAbstract, + chainId: number | string, client: PluginClient, onVerifiedContract: (value: EtherScanReturn) => void, setResults: (value: string) => void ) => { - const { network, networkId } = await getNetworkName(client) - if (network === "vm") { + let networkChainId + if (chainId) networkChainId = chainId + else { + const { network, networkId } = await getNetworkName(client) + if (network === "vm") { return { succeed: false, message: "Cannot verify in the selected network" } + } else networkChainId = networkId } - const etherscanApi = getEtherScanApi(network, networkId) + + const etherscanApi = getEtherScanApi(networkChainId) try { const contractMetadata = getContractMetadata( diff --git a/apps/etherscan/src/app/views/ReceiptsView.tsx b/apps/etherscan/src/app/views/ReceiptsView.tsx index f1643ac3ad..a65e935dab 100644 --- a/apps/etherscan/src/app/views/ReceiptsView.tsx +++ b/apps/etherscan/src/app/views/ReceiptsView.tsx @@ -28,7 +28,7 @@ export const ReceiptsView: React.FC = () => { }) return } - const etherscanApi = getEtherScanApi(network, networkId) + const etherscanApi = getEtherScanApi(networkId) const result = await getReceiptStatus( values.receiptGuid, apiKey, diff --git a/apps/etherscan/src/app/views/VerifyView.tsx b/apps/etherscan/src/app/views/VerifyView.tsx index 20730222ca..64871207e4 100644 --- a/apps/etherscan/src/app/views/VerifyView.tsx +++ b/apps/etherscan/src/app/views/VerifyView.tsx @@ -64,6 +64,7 @@ export const VerifyView: React.FC = ({ contractArguments, values.contractName, compilationResult, + null, client, onVerifiedContract, setResults,