Merge pull request #193 from victaphu/master

update: add support for contract verification on different shards
pull/195/head
Artem 3 years ago committed by GitHub
commit 621aa6ae9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/api/explorerV1.ts
  2. 14
      src/pages/AddressPage/ContractDetails/index.tsx
  3. 7
      src/pages/AddressPage/index.tsx
  4. 22
      src/pages/VerifyContract/VerifyContract.tsx

@ -1,3 +1,4 @@
import { ShardID } from "src/types";
import { AbiItem } from "web3-utils"; import { AbiItem } from "web3-utils";
import { getContractsByField } from "./client"; import { getContractsByField } from "./client";
@ -18,6 +19,7 @@ export interface IVerifyContractData {
tab: string; tab: string;
fileList?: File[]; fileList?: File[];
language: number; language: number;
shard?: 0;
} }
export interface IVerifyContractDataSendData { export interface IVerifyContractDataSendData {
@ -32,6 +34,7 @@ export interface IVerifyContractDataSendData {
contractName: string; contractName: string;
fileList?: File[], fileList?: File[],
tab: string, tab: string,
shard?: number
} }
@ -108,9 +111,9 @@ export const verifyContractCode = async (data: IVerifyContractDataSendData) => {
} }
}; };
export const loadSourceCode = async (address: string): Promise<ISourceCode> => { export const loadSourceCode = async (address: string, shard: ShardID): Promise<ISourceCode> => {
const response = await fetch( const response = await fetch(
`${process.env.REACT_APP_EXPLORER_V1_API_URL}fetchContractCode?contractAddress=${address}`, `${process.env.REACT_APP_EXPLORER_V1_API_URL}fetchContractCode?contractAddress=${address}&shard=${shard}`,
{ {
mode: "cors", mode: "cors",
cache: "no-cache", cache: "no-cache",

@ -1,6 +1,6 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { Box, Text, TextArea } from "grommet"; import { Box, Text, TextArea } from "grommet";
import { AddressDetails } from "src/types"; import { AddressDetails, ShardID } from "src/types";
import { Item } from "../AddressDetails"; import { Item } from "../AddressDetails";
import { useHistory } from "react-router-dom"; import { useHistory } from "react-router-dom";
import styled from "styled-components"; import styled from "styled-components";
@ -19,6 +19,7 @@ export const ContractDetails = (props: {
address: string; address: string;
contracts?: AddressDetails | null; contracts?: AddressDetails | null;
sourceCode?: ISourceCode | null; sourceCode?: ISourceCode | null;
shard?: ShardID;
}) => { }) => {
// console.log(111, appendABI(abi, props.address)); // console.log(111, appendABI(abi, props.address));
@ -28,6 +29,7 @@ export const ContractDetails = (props: {
sourceCode={props.sourceCode} sourceCode={props.sourceCode}
contracts={props.contracts} contracts={props.contracts}
address={props.address} address={props.address}
shard={props.shard || 0}
/> />
); );
} }
@ -37,6 +39,7 @@ export const ContractDetails = (props: {
<NoVerifiedContractDetails <NoVerifiedContractDetails
contracts={props.contracts} contracts={props.contracts}
address={props.address} address={props.address}
shard={props.shard || 0}
/> />
); );
} }
@ -71,6 +74,7 @@ export const AbiMethods = (props: {
export const VerifiedButMissingImplementation = (props: { export const VerifiedButMissingImplementation = (props: {
address: string; address: string;
shard: number;
}) => { }) => {
const history = useHistory(); const history = useHistory();
@ -94,7 +98,7 @@ export const VerifiedButMissingImplementation = (props: {
size="small" size="small"
style={{ cursor: "pointer" }} style={{ cursor: "pointer" }}
onClick={() => onClick={() =>
history.push(`/verifycontract?address=${props.address}`) history.push(`/verifycontract?address=${props.address}&shard=${props.shard}`)
} }
color="brand" color="brand"
> >
@ -152,6 +156,7 @@ export const ProxyContractDetails = (props: {
export const NoVerifiedContractDetails = (props: { export const NoVerifiedContractDetails = (props: {
contracts: AddressDetails; contracts: AddressDetails;
address: string; address: string;
shard: number;
}) => { }) => {
const history = useHistory(); const history = useHistory();
@ -164,7 +169,7 @@ export const NoVerifiedContractDetails = (props: {
size="small" size="small"
style={{ cursor: "pointer" }} style={{ cursor: "pointer" }}
onClick={() => onClick={() =>
history.push(`/verifycontract?address=${props.address}`) history.push(`/verifycontract?address=${props.address}&shard=${props.shard}`)
} }
color="brand" color="brand"
> >
@ -230,6 +235,7 @@ export const VerifiedContractDetails = (props: {
sourceCode: ISourceCode; sourceCode: ISourceCode;
address: string; address: string;
contracts?: AddressDetails | null; contracts?: AddressDetails | null;
shard: number;
}) => { }) => {
const [tab, setTab] = useState<V_TABS>(V_TABS.CODE); const [tab, setTab] = useState<V_TABS>(V_TABS.CODE);
const [metamaskAddress, setMetamask] = useState(""); const [metamaskAddress, setMetamask] = useState("");
@ -250,7 +256,7 @@ export const VerifiedContractDetails = (props: {
return ( return (
<Box direction="column"> <Box direction="column">
{props.sourceCode?.proxyAddress && !props.sourceCode?.proxy && <VerifiedButMissingImplementation address={props.sourceCode.proxyAddress}/>} {props.sourceCode?.proxyAddress && !props.sourceCode?.proxy && <VerifiedButMissingImplementation address={props.sourceCode.proxyAddress} shard={props.shard}/>}
<Box direction="row" align="center" margin={{ top: props.sourceCode?.proxyAddress && !props.sourceCode?.proxy ? "" : "medium" }}> <Box direction="row" align="center" margin={{ top: props.sourceCode?.proxyAddress && !props.sourceCode?.proxy ? "" : "medium" }}>
<TabButton <TabButton
text={V_TABS.CODE} text={V_TABS.CODE}

@ -147,15 +147,15 @@ export function AddressPage() {
// contract defined and contract address same as id // contract defined and contract address same as id
// note: when we toggle there is scenarios where the id are not the same // note: when we toggle there is scenarios where the id are not the same
// @ts-ignore // @ts-ignore
if (!!contracts && contracts?.address === id) { if (!!contracts && contracts?.address === id && contractShardId !== null) {
loadSourceCode(id) loadSourceCode(id, contractShardId)
.then((res) => setSourceCode(res)) .then((res) => setSourceCode(res))
.catch((except) => { .catch((except) => {
console.log(except); console.log(except);
setSourceCode(null) setSourceCode(null)
}); });
} }
}, [id, contracts]); }, [id, contracts, contractShardId]);
const getContractInAllShards = async (contractId: string) => { const getContractInAllShards = async (contractId: string) => {
const { availableShards } = config const { availableShards } = config
@ -425,6 +425,7 @@ export function AddressPage() {
address={id} address={id}
contracts={contracts} contracts={contracts}
sourceCode={sourceCode} sourceCode={sourceCode}
shard={contractShardId || 0}
/> />
</Tab> </Tab>
) : null} ) : null}

@ -68,6 +68,7 @@ class VerifyContractBase extends React.Component<
{ {
isLessTablet: boolean; isLessTablet: boolean;
address?: string; address?: string;
shard?: number;
}, },
IVerifyContractData IVerifyContractData
> { > {
@ -86,10 +87,11 @@ class VerifyContractBase extends React.Component<
statusText: "", statusText: "",
error: "", error: "",
tab: V_TABS.SINGLE, tab: V_TABS.SINGLE,
language: 0 language: 0,
shard: 0
}; };
getBytecode = async () => { getBytecode = async (shard: number) => {
this.setState({ ...this.state, argsLoading: true }); this.setState({ ...this.state, argsLoading: true });
try { try {
@ -97,14 +99,14 @@ class VerifyContractBase extends React.Component<
const address = getAddress(this.state.contractAddress).basicHex; const address = getAddress(this.state.contractAddress).basicHex;
const contracts: any = await getContractsByField([ const contracts: any = await getContractsByField([
0, shard,
"address", "address",
address, address,
]); ]);
if (contracts?.transactionHash) { if (contracts?.transactionHash) {
const trx = await getTransactionByField([ const trx = await getTransactionByField([
0, shard,
"hash", "hash",
contracts.transactionHash, contracts.transactionHash,
]); ]);
@ -141,6 +143,7 @@ class VerifyContractBase extends React.Component<
const res = await verifyContractCode({ const res = await verifyContractCode({
...state, ...state,
libraries: this.state.libraries.map((i) => i.value), libraries: this.state.libraries.map((i) => i.value),
shard: this.props.shard || 0
}); });
if (res.success === true) { if (res.success === true) {
@ -161,7 +164,7 @@ class VerifyContractBase extends React.Component<
}; };
render() { render() {
const { isLessTablet } = this.props; const { isLessTablet, shard } = this.props;
const { isLoading } = this.state; const { isLoading } = this.state;
return ( return (
@ -331,7 +334,7 @@ class VerifyContractBase extends React.Component<
<Spinner size={"xsmall"} /> <Spinner size={"xsmall"} />
</Box> </Box>
) : ( ) : (
<Box onClick={() => this.getBytecode()}> <Box onClick={() => this.getBytecode(shard || 0)}>
<Text color="#00AEE9">paste arguments from tx input</Text> <Text color="#00AEE9">paste arguments from tx input</Text>
</Box> </Box>
)} )}
@ -465,5 +468,10 @@ export const VerifyContract = () => {
history.location.search.substring(1) history.location.search.substring(1)
); );
return <VerifyContractBase isLessTablet={isLessTablet} address={address} />; const shard = getQueryVariable(
"shard",
history.location.search.substring(1)
);
return <VerifyContractBase isLessTablet={isLessTablet} address={address} shard={+(shard || 0)} />;
}; };

Loading…
Cancel
Save