tracking compile results

pull/5370/head
Joseph Izang 12 months ago
parent cec124a2dc
commit c894d158d3
  1. 2
      apps/vyper/src/app/components/CompilerButton.tsx
  2. 65
      apps/vyper/src/app/components/VyperResult.tsx
  3. 34
      apps/vyper/src/app/utils/compiler.tsx
  4. 64
      libs/remix-ui/solidity-compile-details/src/lib/components/solidityCompile.tsx
  5. 92
      libs/remix-ui/solidity-compile-details/src/lib/components/vyperCompile.tsx
  6. 75
      libs/remix-ui/solidity-compile-details/src/lib/solidity-compile-details.tsx
  7. 2
      libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx

@ -109,6 +109,8 @@ function CompilerButton({contract, setOutput, compilerUrl, resetCompilerState}:
}) })
const data = toStandardOutput(_contract.name, output) const data = toStandardOutput(_contract.name, output)
remixClient.compilationFinish(_contract.name, _contract.content, data) remixClient.compilationFinish(_contract.name, _contract.content, data)
console.log(data)
setOutput(_contract.name, data)
// remixClient.call('compilationDetails' as any, 'showDetails', data) // remixClient.call('compilationDetails' as any, 'showDetails', data)
} catch (err: any) { } catch (err: any) {
remixClient.changeStatus({ remixClient.changeStatus({

@ -10,7 +10,6 @@ import { VyperCompilationResult } from '../utils/types'
interface VyperResultProps { interface VyperResultProps {
output?: any output?: any
themeColor?: string
} }
export type ExampleContract = { export type ExampleContract = {
@ -25,9 +24,8 @@ type TabContentMembers = {
className: string className: string
} }
function VyperResult({ output, themeColor }: VyperResultProps) { function VyperResult({ output }: VyperResultProps) {
// const [active, setActive] = useState<keyof VyperCompilationResult>('abi') // const [active, setActive] = useState<keyof VyperCompilationResult>('abi')
const [active, setActive] = useState<keyof VyperCompilationResult>('abi')
if (!output) if (!output)
return ( return (
@ -55,58 +53,17 @@ function VyperResult({ output, themeColor }: VyperResultProps) {
) )
} }
// const tabContent = [
// {
// tabHeadingText: 'ABI',
// tabPayload: Object.values(output)[0]['abi'],
// tabMemberType: 'abi',
// tabButtonText: () => 'Copy ABI',
// eventKey: 'abi'
// },
// {
// tabHeadingText: 'Bytecode',
// // tabPayload: Object.values(output)[0]['bytecode'].object.toString(),
// tabMemberType: 'bytecode',
// tabButtonText: () => 'Copy Bytecode',
// eventKey: 'bytecode'
// },
// {
// tabHeadingText: 'Runtime Bytecode',
// // tabPayload: Object.values(output)[0]['runtimeBytecode'].object.toString(),
// tabMemberType: 'bytecode_runtime',
// tabButtonText: () => 'Copy Runtime Bytecode',
// eventKey: 'bytecode_runtime'
// },
// {
// tabHeadingText: 'LLL',
// tabPayload: Object.values(output)[0]['ir'] ? '' : '',
// tabMemberType: 'ir',
// tabButtonText: () => Object.values(output)[0]['ir'] ? 'Copy LLL Code' : 'Nothing to copy yet',
// eventKey: 'ir'
// }
// ]
return ( return (
// <Tabs id="result" activeKey={active} onSelect={(key: any) => setActive(key)} justify> <>
// {tabContent.map((content, index) => ( <div className="border border-top"></div>
// <Tab eventKey={content.eventKey} title={content.tabHeadingText} as={'span'} key={`${index}-${content.eventKey}`}> <div>
// {/* <CopyToClipboard getContent={() => content.eventKey !== 'abi' ? content.tabPayload : JSON.stringify(Object.values(output)[0]['abi'])}> <button className="btn btn-secondary btn-block mx-2" onClick={() => {
// <Button variant="info" className="copy" data-id={content.eventKey === 'abi' ? "copy-abi" : ''}>
// {content.tabButtonText()} }}>
// </Button> <span>Compilation Details</span>
// </CopyToClipboard> </button>
// { </div>
// content.eventKey === 'abi' ? <JSONTree src={content.tabPayload} theme={themeColor as any}/> : ( </>
// <textarea defaultValue={content.tabPayload}></textarea>
// )
// }
// } */}
// <Button>
// {content.tabButtonText()}
// </Button>
// </Tab>))}
// </Tabs>
<h1>There was a result!</h1>
) )
} }

@ -1,6 +1,6 @@
import {CompilationResult, ABIDescription} from '@remixproject/plugin-api' import {CompilationResult, ABIDescription} from '@remixproject/plugin-api'
import axios from 'axios' import axios from 'axios'
import { VyperCompilationResultType, CompileFormat, BytecodeObject, AST, ABI, ETHPM3Format, CompilerInformationObject } from './types' import { VyperCompilationResultType, CompileFormat, ETHPM3Format, CompilerInformationObject } from './types'
export interface Contract { export interface Contract {
name: string name: string
@ -108,6 +108,7 @@ export async function compile(url: string, contract: Contract): Promise<any> {
result = await(await axios.get(url + 'artifacts/' + compileCode , { result = await(await axios.get(url + 'artifacts/' + compileCode , {
method: 'Get' method: 'Get'
})).data })).data
console.log(result)
return result return result
} else if (status === 'FAILED') { } else if (status === 'FAILED') {
const intermediate = await(await axios.get(url + 'exceptions/' + compileCode , { const intermediate = await(await axios.get(url + 'exceptions/' + compileCode , {
@ -167,6 +168,37 @@ export function toStandardOutput(fileName: string, compilationResult: any): any
} }
} }
} }
export type StandardOutput = {
sources: {
[fileName: string]: {
id: number,
ast: AST
}
},
contracts: {
[fileName: string]: {
[contractName: string]: {
abi: ABI,
contractName: string,
evm: {
bytecode: BytecodeObject,
deployedBytecode: BytecodeObject,
methodIdentifiers: {
[method: string]: string
}
}
}
}
}
}
type AST = any // Replace with the actual AST type
type ABI = ABIDescription[] // Replace with the actual ABI type
type BytecodeObject = {
linkReferences: Record<string, any>,
object: string,
opcodes: string
}
/* /*
export function createCompilationResultMessage(name: string, result: any) { export function createCompilationResultMessage(name: string, result: any) {

@ -0,0 +1,64 @@
import { CopyToClipboard } from '@remix-ui/clipboard'
import { CustomTooltip } from '@remix-ui/helper'
import { ContractPropertyName } from '@remix-ui/solidity-compiler'
import { TreeView, TreeViewItem } from '@remix-ui/tree-view'
import { useIntl } from 'react-intl'
const _paq = (window._paq = window._paq || [])
export default function SolidityCompile({ contractProperties, selectedContract, help, insertValue, saveAs, plugin }: any) {
const intl = useIntl()
const downloadFn = () => {
_paq.push(['trackEvent', 'compiler', 'compilerDetails', 'download'])
saveAs(new Blob([JSON.stringify(contractProperties, null, '\t')]), `${selectedContract}_compData.json`)
}
return (
<>
<div className="d-flex justify-content-between align-items-center mr-1">
<span className="lead">{selectedContract}</span>
<CustomTooltip tooltipText={intl.formatMessage({id: 'solidity.compileDetails'})}>
<span className="btn btn-outline-success border-success mr-1" onClick={downloadFn}>Download</span>
</CustomTooltip>
</div>
<div className="remixui_detailsJSON">
{<TreeView>
{Object.keys(contractProperties).map((propertyName: ContractPropertyName, index) => {
const copyDetails = (
<span className="remixui_copyDetails">
<CopyToClipboard tip={intl.formatMessage({id: 'solidity.copy'})} content={contractProperties[propertyName]} direction="top" />
</span>
)
const questionMark = (
<span className="remixui_questionMark">
<i
title={intl.formatMessage({
id: `solidity.${propertyName}`,
defaultMessage: help[propertyName]
})}
className="fas fa-question-circle"
aria-hidden="true"
></i>
</span>
)
return (
<div className="remixui_log" key={index}>
<TreeViewItem
label={
<div data-id={`remixui_treeviewitem_${propertyName}`} className="remixui_key">
{propertyName} {copyDetails} {questionMark}
</div>
}
expand={propertyName === 'metadata' || propertyName === 'bytecode' ? true : false}
iconY='fas fa-caret-down'
>
{insertValue(contractProperties, propertyName)}
</TreeViewItem>
</div>
)
})}
</TreeView>}
</div>
</>
)
}

@ -0,0 +1,92 @@
import { CopyToClipboard } from '@remix-ui/clipboard'
import { CustomTooltip } from '@remix-ui/helper'
import JSONTree, { ThemeKeys } from 'react-json-view'
import React, { useState } from 'react'
// import { Tabs, Tab, Button } from 'react-bootstrap'
import { useIntl } from 'react-intl'
import Tabs from 'react-bootstrap/Tabs'
import Tab from 'react-bootstrap/Tab'
import Button from 'react-bootstrap/Button'
import { TreeView, TreeViewItem } from '@remix-ui/tree-view'
import { ABIDescription } from '@remixproject/plugin-api'
const _paq = (window._paq = window._paq || [])
export interface VyperCompilationResult {
status: 'success'
bytecode: string
bytecode_runtime: string
abi: ABIDescription[]
ir: string
method_identifiers: {
[method: string]: string
}
}
export default function VyperCompile({ saveAs, contractProperties, selectedContract }: any) {
const intl = useIntl()
const downloadFn = () => {
_paq.push(['trackEvent', 'compiler', 'compilerDetails', 'download'])
saveAs(new Blob([JSON.stringify(contractProperties, null, '\t')]), `${selectedContract}_compData.json`)
}
const [active, setActive] = useState<keyof VyperCompilationResult>('abi')
const tabContent = [
{
tabHeadingText: 'ABI',
tabPayload: Object.values(contractProperties)[0]['abi'],
tabMemberType: 'abi',
tabButtonText: () => 'Copy ABI',
eventKey: 'abi'
},
{
tabHeadingText: 'Bytecode',
tabPayload: Object.values(contractProperties)[0]['bytecode'].object.toString(),
tabMemberType: 'bytecode',
tabButtonText: () => 'Copy Bytecode',
eventKey: 'bytecode'
},
{
tabHeadingText: 'Runtime Bytecode',
tabPayload: Object.values(contractProperties)[0]['runtimeBytecode'].object.toString(),
tabMemberType: 'bytecode_runtime',
tabButtonText: () => 'Copy Runtime Bytecode',
eventKey: 'bytecode_runtime'
}
// {
// tabHeadingText: 'LLL',
// tabPayload: Object.values(contractProperties)[0]['ir'] ? '' : '',
// tabMemberType: 'ir',
// tabButtonText: () => Object.values(contractProperties)[0]['ir'] ? 'Copy LLL Code' : 'Nothing to copy yet',
// eventKey: 'ir'
// }
]
return (
<>
<div className="d-flex justify-content-between align-items-center mr-1">
<span className="lead">{selectedContract}</span>
<CustomTooltip tooltipText={intl.formatMessage({id: 'solidity.compileDetails'})}>
<span className="btn btn-outline-success border-success mr-1" onClick={downloadFn}>Download</span>
</CustomTooltip>
</div>
<Tabs id="result" activeKey={active} onSelect={(key: any) => setActive(key)} justify>
{tabContent.map((content, index) => (
<Tab eventKey={content.eventKey} title={content.tabHeadingText} as={'span'} key={`${index}-${content.eventKey}`}>
<CopyToClipboard getContent={() => content.eventKey !== 'abi' ? content.tabPayload : JSON.stringify(Object.values(contractProperties)[0]['abi'])}>
<Button variant="info" className="copy" data-id={content.eventKey === 'abi' ? "copy-abi" : ''}>
{content.tabButtonText()}
</Button>
</CopyToClipboard>
{
content.eventKey === 'abi' ? <JSONTree src={content.tabPayload} theme={{} as any}/> : (
<textarea defaultValue={content.tabPayload}></textarea>
)
}
<Button>
{content.tabButtonText()}
</Button>
</Tab>))}
</Tabs>
</>
)
}

@ -4,72 +4,41 @@ import { TreeView, TreeViewItem } from '@remix-ui/tree-view'
import { ContractPropertyName } from '@remix-ui/solidity-compiler' import { ContractPropertyName } from '@remix-ui/solidity-compiler'
import React from 'react' import React from 'react'
import { useIntl } from 'react-intl' import SolidityCompile from './components/solidityCompile'
import VyperCompile from './components/vyperCompile'
export interface RemixUiCompileDetailsProps { export interface RemixUiCompileDetailsProps {
plugin: any plugin?: any
contractProperties: any contractProperties: any
selectedContract: string selectedContract: string
help: any help?: any
insertValue: any insertValue?: any
saveAs: any saveAs: any
} }
const _paq = (window._paq = window._paq || []) const _paq = (window._paq = window._paq || [])
export function RemixUiCompileDetails({ plugin, contractProperties, selectedContract, saveAs, help, insertValue }: RemixUiCompileDetailsProps) { export function RemixUiCompileDetails({ plugin, contractProperties, selectedContract, saveAs, help, insertValue }: RemixUiCompileDetailsProps) {
const intl = useIntl() console.log(contractProperties)
const downloadFn = () => {
_paq.push(['trackEvent', 'compiler', 'compilerDetails', 'download'])
saveAs(new Blob([JSON.stringify(contractProperties, null, '\t')]), `${selectedContract}_compData.json`)
}
return (
<>
<div className="d-flex justify-content-between align-items-center mr-1">
<span className="lead">{selectedContract}</span>
<CustomTooltip tooltipText={intl.formatMessage({id: 'solidity.compileDetails'})}>
<span className="btn btn-outline-success border-success mr-1" onClick={downloadFn}>Download</span>
</CustomTooltip>
</div>
<div className="remixui_detailsJSON">
{<TreeView>
{Object.keys(contractProperties).map((propertyName: ContractPropertyName, index) => {
const copyDetails = (
<span className="remixui_copyDetails">
<CopyToClipboard tip={intl.formatMessage({id: 'solidity.copy'})} content={contractProperties[propertyName]} direction="top" />
</span>
)
const questionMark = (
<span className="remixui_questionMark">
<i
title={intl.formatMessage({
id: `solidity.${propertyName}`,
defaultMessage: help[propertyName]
})}
className="fas fa-question-circle"
aria-hidden="true"
></i>
</span>
)
return ( return (
<div className="remixui_log" key={index}> <>
<TreeViewItem {
label={ contractProperties.abi && contractProperties.gasEstimates.Creation && contractProperties.web3Deploy ? (
<div data-id={`remixui_treeviewitem_${propertyName}`} className="remixui_key"> <SolidityCompile
{propertyName} {copyDetails} {questionMark} contractProperties={contractProperties}
</div> plugin={plugin}
selectedContract={selectedContract}
help={help}
insertValue={insertValue}
saveAs={saveAs}
/> ) :
<VyperCompile
saveAs={saveAs}
contractProperties={contractProperties}
selectedContract={selectedContract}
/>
} }
expand={propertyName === 'metadata' || propertyName === 'bytecode' ? true : false}
iconY='fas fa-caret-down'
>
{insertValue(contractProperties, propertyName)}
</TreeViewItem>
</div>
)
})}
</TreeView>}
</div>
</> </>
) )
} }

@ -123,7 +123,6 @@ export const ContractSelection = (props: ContractSelectionProps) => {
} }
const insertValue = (details, propertyName: ContractPropertyName) => { const insertValue = (details, propertyName: ContractPropertyName) => {
console.log({ details })
let node let node
if (propertyName === 'web3Deploy' || propertyName === 'name' || propertyName === 'Assembly') { if (propertyName === 'web3Deploy' || propertyName === 'name' || propertyName === 'Assembly') {
node = <pre>{details[propertyName]}</pre> node = <pre>{details[propertyName]}</pre>
@ -311,6 +310,7 @@ export const ContractSelection = (props: ContractSelectionProps) => {
</span> </span>
</CustomTooltip> </CustomTooltip>
</button> </button>
{console.log(payload)}
<button <button
data-id="compilation-details" data-id="compilation-details"
className="btn btn-secondary btn-block" className="btn btn-secondary btn-block"

Loading…
Cancel
Save