refactor types

pull/5370/head
yann300 2 years ago committed by Aniket
parent cde0190c0d
commit bda5dc88c8
  1. 27
      apps/debugger/src/app/debugger-api.ts
  2. 7
      apps/debugger/src/app/debugger.ts
  3. 3
      apps/etherscan/src/app/utils/verify.ts
  4. 9
      apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts
  5. 3
      apps/remix-ide/src/app/plugins/parser/services/code-parser-gas-service.ts
  6. 13
      libs/remix-solidity/src/compiler/compiler-abstract.ts
  7. 18
      libs/remix-solidity/src/compiler/types.ts
  8. 2
      libs/remix-solidity/src/index.ts
  9. 16
      libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts

@ -1,7 +1,7 @@
import Web3 from 'web3'
import remixDebug, { TransactionDebugger as Debugger } from '@remix-project/remix-debug'
import { CompilationOutput, Sources } from '@remix-ui/debugger-ui'
import type { CompilationResult } from '@remix-project/remix-solidity-ts'
import { CompilerAbstract } from '@remix-project/remix-solidity'
export const DebuggerApiMixin = (Base) => class extends Base {
@ -161,26 +161,3 @@ export const DebuggerApiMixin = (Base) => class extends Base {
}
}
export class CompilerAbstract implements CompilationOutput { // this is a subset of /remix-ide/src/app/compiler/compiler-abstract.js
languageversion
data
source
constructor (languageversion: string, data: CompilationResult, source: { sources: Sources, target: string }) {
this.languageversion = languageversion
this.data = data
this.source = source // source code
}
getSourceName (fileIndex) {
if (this.data && this.data.sources) {
return Object.keys(this.data.sources)[fileIndex]
} else if (Object.keys(this.source.sources).length === 1) {
// if we don't have ast, we return the only one filename present.
const sourcesArray = Object.keys(this.source.sources)
return sourcesArray[0]
}
return null
}
}

@ -1,9 +1,10 @@
import { PluginClient } from "@remixproject/plugin";
import { createClient } from "@remixproject/plugin-webview";
import { IDebuggerApi, RawLocation, Sources, Asts, LineColumnLocation,
import { IDebuggerApi, LineColumnLocation,
onBreakpointClearedListener, onBreakpointAddedListener, onEditorContentChanged, onEnvChangedListener, TransactionReceipt } from '@remix-ui/debugger-ui'
import { DebuggerApiMixin, CompilerAbstract} from './debugger-api'
import { DebuggerApiMixin } from './debugger-api'
import { CompilerAbstract } from '@remix-project/remix-solidity'
export class DebuggerClientApi extends DebuggerApiMixin(PluginClient) {
constructor () {
super()

@ -1,5 +1,6 @@
import { getNetworkName, getEtherScanApi, getReceiptStatus } from "../utils"
import { CompilationResult } from "@remixproject/plugin-api"
import { CompilerAbstract } from '@remix-project/remix-solidity'
import axios from 'axios'
import { PluginClient } from "@remixproject/plugin"
@ -19,7 +20,7 @@ export const verify = async (
contractAddress: string,
contractArgumentsParam: string,
contractName: string,
compilationResultParam: any,
compilationResultParam: CompilerAbstract,
client: PluginClient,
onVerifiedContract: (value: EtherScanReturn) => void,
setResults: (value: string) => void

@ -6,9 +6,10 @@ import { CompilationResult, CompilationSource } from '@remix-project/remix-solid
import { CodeParser } from "../code-parser";
import { fileDecoration, fileDecorationType } from '@remix-ui/file-decorators'
import { sourceMappingDecoder } from '@remix-project/remix-debug'
import { CompilerRetriggerMode } from '@remix-project/remix-solidity-ts';
import { CompilerRetriggerMode, CompilationSourceCode } from '@remix-project/remix-solidity-ts';
import { MarkerSeverity } from 'monaco-editor';
import { findLinesInStringWithMatch, SearchResultLine } from '@remix-ui/search'
import { lastCompilationResult } from '@remixproject/plugin-api';
type errorMarker = {
message: string
@ -28,7 +29,7 @@ type errorMarker = {
export default class CodeParserCompiler {
plugin: CodeParser
compiler: any // used to compile the current file seperately from the main compiler
onAstFinished: (success: any, data: CompilationResult, source: CompilationSource, input: any, version: any) => Promise<void>;
onAstFinished: (success: any, data: CompilationResult, source: CompilationSourceCode, input: any, version: any) => Promise<void>;
errorState: boolean;
gastEstimateTimeOut: any
constructor(
@ -39,7 +40,7 @@ export default class CodeParserCompiler {
init() {
this.onAstFinished = async (success, data: CompilationResult, source: CompilationSource, input: any, version) => {
this.onAstFinished = async (success, data: CompilationResult, source: CompilationSourceCode, input: any, version) => {
this.plugin.call('editor', 'clearAnnotations')
this.errorState = true
const result = new CompilerAbstract('soljson', data, source, input)
@ -104,7 +105,7 @@ export default class CodeParserCompiler {
this.plugin._buildIndex(data, source)
this.plugin.nodeIndex.nodesPerFile[this.plugin.currentFile] = this.plugin._extractFileNodes(this.plugin.currentFile, this.plugin.compilerAbstract)
this.plugin.nodeIndex.nodesPerFile[this.plugin.currentFile] = this.plugin._extractFileNodes(this.plugin.currentFile, this.plugin.compilerAbstract as unknown as lastCompilationResult)
await this.plugin.gasService.showGasEstimates()
this.plugin.emit('astFinished')
}

@ -1,5 +1,6 @@
import { CodeParser, genericASTNode } from "../code-parser";
import { lineText } from '@remix-ui/editor'
import { lastCompilationResult } from '@remixproject/plugin-api';
export default class CodeParserGasService {
plugin: CodeParser
@ -40,7 +41,7 @@ export default class CodeParserGasService {
return
}
this.plugin.currentFile = await this.plugin.call('fileManager', 'file')
this.plugin.nodeIndex.nodesPerFile[this.plugin.currentFile] = await this.plugin._extractFileNodes(this.plugin.currentFile, this.plugin.compilerAbstract)
this.plugin.nodeIndex.nodesPerFile[this.plugin.currentFile] = await this.plugin._extractFileNodes(this.plugin.currentFile, this.plugin.compilerAbstract as unknown as lastCompilationResult)
const gasEstimates = await this.getGasEstimates(this.plugin.currentFile)

@ -1,16 +1,17 @@
'use strict'
import helper from './helper'
import { CompilationResult, CompilerInput, CompilationSourceCode } from './types'
export class CompilerAbstract {
languageversion: any
data: any
source: any
input: any
constructor (languageversion, data, source, input?) {
languageversion: string
data: CompilationResult
source: CompilationSourceCode
input: CompilerInput
constructor (languageversion: string, data: CompilationResult, source: CompilationSourceCode, input?: CompilerInput) {
this.languageversion = languageversion
this.data = data
this.source = source // source code
this.input = input // source code
this.input = input
}
getContracts () {

@ -270,9 +270,21 @@ export interface CompilationError {
| 'FatalError'
| 'Warning'
/// /////////
// SOURCE //
/// /////////
/// //////////
// SOURCE CODE //
/// //////////
export interface SourcesCode {
[fileName: string] : {content: string}
}
export type CompilationSourceCode = {
sources: SourcesCode;
target: string;
}
/// //////////
// SOURCE AST //
/// //////////
export interface CompilationSource {
/** Identifier of the source (used in source maps) */
id: number

@ -1,7 +1,7 @@
export { Compiler } from './compiler/compiler'
export { compile } from './compiler/compiler-helpers'
export { default as CompilerInput, getValidLanguage } from './compiler/compiler-input'
export { CompilerAbstract } from './compiler/compiler-abstract'
export * from './compiler/compiler-abstract'
export * from './compiler/types'
export { promisedMiniXhr, pathToURL, baseURLBin, baseURLWasm, canUseWorker, urlFromVersion } from './compiler/compiler-utils'
export { default as helper } from './compiler/helper'

@ -1,5 +1,5 @@
import type { CompilationResult, CompilationSource } from '@remix-project/remix-solidity-ts' // eslint-disable-line
import type { CompilationSource, CompilerAbstract, SourcesCode } from '@remix-project/remix-solidity-ts' // eslint-disable-line
export interface LineColumnLocation {
start: {
@ -14,16 +14,6 @@ export interface RawLocation {
start: number, length: number
}
export interface Sources {
[fileName: string] : {content: string}
}
export interface CompilationOutput {
source: { sources: Sources, target: string }
data: CompilationResult
getSourceName: (id: number) => string
}
export interface Asts {
[fileName: string] : CompilationSource // ast
}
@ -45,7 +35,7 @@ export type onDebugRequested = (hash: string, web3?: any) => void
export type onEnvChangedListener = (provider: string) => void
export interface IDebuggerApi {
offsetToLineColumnConverter: { offsetToLineColumn: (sourceLocation: RawLocation, file: number, contents: Sources, asts: Asts) => Promise<LineColumnLocation> }
offsetToLineColumnConverter: { offsetToLineColumn: (sourceLocation: RawLocation, file: number, contents: SourcesCode, asts: Asts) => Promise<LineColumnLocation> }
removeHighlights: boolean
onRemoveHighlights: (listener: VoidFunction) => void
onDebugRequested: (listener: onDebugRequested) => void
@ -55,7 +45,7 @@ export interface IDebuggerApi {
onEnvChanged: (listener: onEnvChangedListener) => void
discardHighlight: () => Promise<void>
highlight: (lineColumnPos: LineColumnLocation, path: string) => Promise<void>
fetchContractAndCompile: (address: string, currentReceipt: TransactionReceipt) => Promise<CompilationOutput>
fetchContractAndCompile: (address: string, currentReceipt: TransactionReceipt) => Promise<CompilerAbstract>
getFile: (path: string) => Promise<string>
setFile: (path: string, content: string) => Promise<void>
getDebugWeb3: () => any // returns an instance of web3.js, if applicable (mainet, goerli, ...) it returns a reference to a node from devops (so we are sure debug endpoint is available)

Loading…
Cancel
Save