Skip to content

Commit

Permalink
fix: update API evmVersion + solidityCompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Tien Nam Dao committed Nov 21, 2022
1 parent c367863 commit 61bea0e
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .tikici.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ deployment_config:
port: '3000'
envFrom:
- secretRef:
name: env-explorer-fe
name: explorer-fe
optional: false
replicaCount: 1
prod:
Expand All @@ -95,6 +95,6 @@ deployment_config:
port: '3000'
envFrom:
- secretRef:
name: env-explorer-fe
name: explorer-fe
optional: false
replicaCount: 1
4 changes: 3 additions & 1 deletion api/api_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const API_LIST = {

CONTRACT_CODE: 'evm_/api/v1?module=contract&action=getsourcecode',
VERIFY_CONTRACT: 'https://blockscout.astranaut.dev/verify_smart_contract/contract_verifications',
CHECK_VERIFY_STATUS: 'evm_/api/v1?module=contract&action=checkverifystatus'
CHECK_VERIFY_STATUS: 'evm_/api/v1?module=contract&action=checkverifystatus',
GET_EVM_VERSION: 'evm_/api/v1/evm-versions',
GET_SOLIDITY_COMPILER: 'evm_/api/v1/compiler-versions?compiler=solc'
}

export default API_LIST
1 change: 1 addition & 0 deletions components/FormItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const FormItem = ({ label, type, inputProps }: Props) => {
data-for={data?.id}
onChange={value => props.onSelect(value)}
options={data.items}
defaultInputValue={data.currentValue}
{...props}
/>
)
Expand Down
22 changes: 10 additions & 12 deletions components/VerifyContract/ContractFlattenedVerify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useEffect, useRef, useState } from 'react'
import AddressDisplay from './AddressDisplay'
import Header from './Header'
import useContractVerifyStatus from './hook/useContractVerifyStatus'
import useEvmVersion from './hook/useEvmVersion'
import useSolidityCompiler from './hook/useSolidityCompiler'
import styles from './style.module.scss'

interface Props {
Expand All @@ -24,7 +26,7 @@ const ContractFlattenedVerify = ({ address, onClose, onSuccess }: Props) => {
const [contractName, setContractName] = useState('')
const [hasNightlyBuild, setHasNightlyBuild] = useState(true)
const [compiler, setCompiler] = useState(undefined)
const [evmVersion, setEvmVersion] = useState(undefined)
const [evmVersion, setEvmVersion] = useState('default')
const [hasOptimization, setOptimization] = useState(true)
const [optimizeRun, setOptimizeRun] = useState(200)
const [solidityCode, setSolidityCode] = useState('')
Expand All @@ -33,6 +35,8 @@ const ContractFlattenedVerify = ({ address, onClose, onSuccess }: Props) => {
const [guid, setGuid] = useState(undefined)
const [libs, setLib] = useState<LibraryItem[]>([])

const versions = useEvmVersion()
const solidityCompilers = useSolidityCompiler()
const isValidated = useContractVerifyStatus(guid)

const addLibraryItem = () => {
Expand All @@ -51,7 +55,7 @@ const ContractFlattenedVerify = ({ address, onClose, onSuccess }: Props) => {
setContractName('')
setHasNightlyBuild(true)
setCompiler(undefined)
setEvmVersion(undefined)
setEvmVersion('default')
setOptimization(true)
setOptimizeRun(200)
setSolidityCode('')
Expand All @@ -64,8 +68,8 @@ const ContractFlattenedVerify = ({ address, onClose, onSuccess }: Props) => {
'smart_contract[address_hash]': address,
'smart_contract[name]': contractName,
'smart_contract[nightly_builds]': hasNightlyBuild,
'smart_contract[compiler_version]': 'v0.8.4+commit.c7e474f2', // compiler,
'smart_contract[evm_version]': 'default', // evmVersion,
'smart_contract[compiler_version]': compiler,
'smart_contract[evm_version]': evmVersion,
'smart_contract[optimization]': hasOptimization,
'smart_contract[optimization_runs]': optimizeRun,
'smart_contract[contract_source_code]': solidityCode,
Expand Down Expand Up @@ -161,10 +165,7 @@ const ContractFlattenedVerify = ({ address, onClose, onSuccess }: Props) => {
},
data: {
currentValue: compiler,
items: [
{ label: 'Yes', value: 'yes' },
{ label: 'No', value: 'no' }
],
items: solidityCompilers.map(v => ({ label: v, value: v })),
id: 'verify-compiler',
tooltip: `The compiler version is specified in pragma solidity X.X.X. Use the compiler version rather than the nightly build. If using the Solidity compiler, run solc —version to check.`
} as FormSelectData
Expand All @@ -180,10 +181,7 @@ const ContractFlattenedVerify = ({ address, onClose, onSuccess }: Props) => {
},
data: {
currentValue: evmVersion,
items: [
{ label: 'Yes', value: 'yes' },
{ label: 'No', value: 'no' }
],
items: versions.map(v => ({ label: v, value: v })),
id: 'verify-evm-version',
tooltip:
'The EVM version the contract is written for. If the bytecode does not match the version, we try to verify using the latest EVM version. EVM version details.'
Expand Down
20 changes: 20 additions & 0 deletions components/VerifyContract/hook/useEvmVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import API_LIST from 'api/api_list'
import { useEffect, useState } from 'react'
import useSWRImmutable from 'swr/immutable'

const useEvmVersion = (): string[] => {
const [evmVersions, setEvmVersions] = useState([])
const _fetchCondition = () => {
return [API_LIST.GET_EVM_VERSION]
}
const { data } = useSWRImmutable<any>(_fetchCondition())

useEffect(() => {
if (data && data?.result) {
setEvmVersions(data?.result?.versions)
}
}, [data])
return evmVersions || []
}

export default useEvmVersion
20 changes: 20 additions & 0 deletions components/VerifyContract/hook/useSolidityCompiler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import API_LIST from 'api/api_list'
import { useEffect, useState } from 'react'
import useSWRImmutable from 'swr/immutable'

const useSolidityCompiler = (): string[] => {
const [evmVersions, setEvmVersions] = useState([])
const _fetchCondition = () => {
return [API_LIST.GET_SOLIDITY_COMPILER]
}
const { data } = useSWRImmutable<any>(_fetchCondition())

useEffect(() => {
if (data && data?.result) {
setEvmVersions(data?.result?.versions)
}
}, [data])
return evmVersions || []
}

export default useSolidityCompiler
2 changes: 0 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import '../prism-theme/dark.scss'
import store, { persistor } from '../store'
import '../styles.css'

console.log(process.env)

dayjs.locale('en')

export function reportWebVitals(metric: NextWebVitalsMetric) {
Expand Down
9 changes: 8 additions & 1 deletion types/address.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ interface AbiResponse {
interface HashAbiResponse {
message: string
result: {
abi: any
abi: {
inputs: []
name: string
outputs: any
stateMutability: any
type: any
}
verified: boolean
}
status: string
}
Expand Down
17 changes: 7 additions & 10 deletions views/transactions/DecodeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,24 @@ export default function DecodeInput({ dataInput, address, evmHash }: DecodeInput
router.reload()
}

const getAbi = async (address: string): Promise<{ abi: AbiItem[]; hasAbi: boolean }> => {
const addressAbiRes = await evmApi.get<AbiResponse>(`${API_LIST.ABI}${address}`)
if (addressAbiRes.data.message === 'OK') {
return { abi: JSON.parse(addressAbiRes?.data?.result), hasAbi: true }
}
const getAbi = async (address: string): Promise<{ abi: AbiItem[]; hasVerified: boolean }> => {
// datainput from hash
if (evmHash) {
const hashAbiRes = await evmApi.get<HashAbiResponse>(`${API_LIST.HASH_ABI}${evmHash}`)

if (hashAbiRes.data.message === 'OK') {
return { abi: [hashAbiRes?.data?.result?.abi], hasAbi: false }
return { abi: [hashAbiRes?.data?.result?.abi], hasVerified: hashAbiRes?.data?.result?.verified }
}
}

return { abi: undefined, hasAbi: false }
return { abi: undefined, hasVerified: false }
}

useEffect(() => {
async function data() {
if (!isEmpty(dataInput)) {
let items: LogElementProps[] = []
const { abi, hasAbi } = await getAbi(address)
const { abi, hasVerified } = await getAbi(address)
const item: LogElementProps = {
address: address,
data: '',
Expand All @@ -71,8 +68,8 @@ export default function DecodeInput({ dataInput, address, evmHash }: DecodeInput
items.push(item)
item.methodId = evmMethodId(dataInput)

item.verified = hasAbi
item.useDraftAbiToDecode = !hasAbi && !!abi
item.verified = hasVerified
item.useDraftAbiToDecode = !hasVerified && !!abi

if (Array.isArray(abi)) {
abiDecoder.addABI(abi)
Expand Down
56 changes: 33 additions & 23 deletions views/transactions/Log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import API_LIST from 'api/api_list'
import { EventDecode } from 'components/Card/CardInfo/Components/Decode'
import RowLoader from 'components/Loader/RowLoader'
import Empty from 'components/Typography/Empty'
import { isEmpty } from 'lodash'
import { isEmpty, isUndefined } from 'lodash'
import { useEffect, useState } from 'react'
import { evmMethodId } from 'utils/evm'
import { AbiItem } from 'web3-utils'
Expand All @@ -15,30 +15,30 @@ interface AbiItemDecode extends AbiItem {

type LogProps = {
logs: EvmLog[]
evmHash: string
display: boolean
}

export default function Log({ logs, display }: LogProps) {
export default function Log({ logs, display, evmHash }: LogProps) {
const [load, setLoad] = useState(false)
const [items, setItems] = useState<LogElementProps[]>()

// no display and no load
if (!display && !load) {
return null
}

const getAbi = async (address: string): Promise<AbiItem[]> => {
const res = await evmApi.get<AbiResponse>(`${API_LIST.ABI}${address}`)
if (res.data.message === 'OK') {
return JSON.parse(res?.data?.result)
if (evmHash) {
const hashAbiRes = await evmApi.get<HashAbiResponse>(`${API_LIST.HASH_ABI}${evmHash}`)

if (hashAbiRes.data.message === 'OK') {
return [hashAbiRes?.data?.result?.abi]
}
}

return undefined
}

useEffect(() => {
async function data() {
if (!isEmpty(logs)) {
const items: LogElementProps[] = []
let items: LogElementProps[] = []
for (let log of logs) {
const abi = await getAbi(log.address)
const item: LogElementProps = {
Expand All @@ -50,20 +50,24 @@ export default function Log({ logs, display }: LogProps) {
item.verified = true
abiDecoder.addABI(abi)
const logObj = abiDecoder.decodeLogs([log])[0] as AbiItemDecode
const name = logObj.name
const interfaceItem = abi.find(item => item.name === name)
const params = interfaceItem.inputs
const call = `${interfaceItem.name}(${interfaceItem.inputs
.map(input => `${input.type} ${input.indexed ? 'indexed' : ''} ${input.name}`)
.join(', ')})`
item.call = call
for (let para of params) {
const input = logObj?.events.find(input => input.name === para.name)
if (input) {
input.indexed = para.indexed
if (!isUndefined(logObj)) {
const name = logObj.name
const interfaceItem = abi.find(item => item.name === name)
const params = interfaceItem.inputs
const call = `${interfaceItem.name}(${interfaceItem.inputs
.map(input => `${input.type} ${input.indexed ? 'indexed' : ''} ${input.name}`)
.join(', ')})`
item.call = call
for (let para of params) {
const input = logObj?.events.find(input => input.name === para.name)
if (input) {
input.indexed = para.indexed
}
}
item.methodParams = logObj.events
}
item.methodParams = logObj.events
} else {
items = []
}
}
setItems(items)
Expand All @@ -72,6 +76,12 @@ export default function Log({ logs, display }: LogProps) {
}
data()
}, [logs])

// no display and no load
if (!display && !load) {
return null
}

return (
<div className="width-100">
{!load ? (
Expand Down
2 changes: 1 addition & 1 deletion views/transactions/TransactionTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function TransactionTabs({
{ title: 'Raw Trace', id: 'trace' }
]
const contents = {
logs: <Log logs={logs} display />,
logs: <Log logs={logs} display evmHash={evmHash} />,
trace: <RawTrace text={JSON.stringify(rawTrace, null, '\t')} />
}

Expand Down

0 comments on commit 61bea0e

Please sign in to comment.