diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index a2ccbfd16b..1a295fb793 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -309,6 +309,7 @@ class AppComponent { filePanel.remixdHandle, filePanel.gitHandle, filePanel.hardhatHandle, + filePanel.truffleHandle, filePanel.slitherHandle, linkLibraries, deployLibraries, diff --git a/apps/remix-ide/src/app/files/truffle-handle.js b/apps/remix-ide/src/app/files/truffle-handle.js new file mode 100644 index 0000000000..8ef51ffcd1 --- /dev/null +++ b/apps/remix-ide/src/app/files/truffle-handle.js @@ -0,0 +1,18 @@ +import { WebsocketPlugin } from '@remixproject/engine-web' +import * as packageJson from '../../../../../package.json' + +const profile = { + name: 'truffle', + displayName: 'truffle', + url: 'ws://127.0.0.1:65524', + methods: ['compile'], + description: 'Using Remixd daemon, allow to access truffle API', + kind: 'other', + version: packageJson.version +} + +export class TruffleHandle extends WebsocketPlugin { + constructor () { + super(profile) + } +} diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 6c5e4d0235..25c41920f0 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -7,6 +7,7 @@ import Registry from '../state/registry' import { RemixdHandle } from '../plugins/remixd-handle' const { GitHandle } = require('../files/git-handle.js') const { HardhatHandle } = require('../files/hardhat-handle.js') +const { TruffleHandle } = require('../files/truffle-handle.js') const { SlitherHandle } = require('../files/slither-handle.js') /* @@ -51,6 +52,7 @@ module.exports = class Filepanel extends ViewPlugin { this.remixdHandle = new RemixdHandle(this.fileProviders.localhost, appManager) this.gitHandle = new GitHandle() this.hardhatHandle = new HardhatHandle() + this.truffleHandle = new TruffleHandle() this.slitherHandle = new SlitherHandle() this.workspaces = [] this.appManager = appManager diff --git a/apps/remix-ide/src/app/plugins/remixd-handle.tsx b/apps/remix-ide/src/app/plugins/remixd-handle.tsx index 9ff3d8339f..3b707f0534 100644 --- a/apps/remix-ide/src/app/plugins/remixd-handle.tsx +++ b/apps/remix-ide/src/app/plugins/remixd-handle.tsx @@ -40,6 +40,7 @@ export class RemixdHandle extends WebsocketPlugin { if (super.socket) super.deactivate() // this.appManager.deactivatePlugin('git') // plugin call doesn't work.. see issue https://github.com/ethereum/remix-plugin/issues/342 if (this.appManager.isActive('hardhat')) this.appManager.deactivatePlugin('hardhat') + if (this.appManager.isActive('truffle')) this.appManager.deactivatePlugin('truffle') if (this.appManager.isActive('slither')) this.appManager.deactivatePlugin('slither') this.localhostProvider.close((error) => { if (error) console.log(error) @@ -88,6 +89,7 @@ export class RemixdHandle extends WebsocketPlugin { this.call('filePanel', 'setWorkspace', { name: LOCALHOST, isLocalhost: true }, true) }) this.call('manager', 'activatePlugin', 'hardhat') + this.call('manager', 'activatePlugin', 'truffle') this.call('manager', 'activatePlugin', 'slither') } } diff --git a/apps/remix-ide/src/remixAppManager.js b/apps/remix-ide/src/remixAppManager.js index 764f7db574..e14e98d66f 100644 --- a/apps/remix-ide/src/remixAppManager.js +++ b/apps/remix-ide/src/remixAppManager.js @@ -10,7 +10,7 @@ const requiredModules = [ // services + layout views + system views 'filePanel', 'terminal', 'settings', 'pluginManager', 'tabs', 'udapp', 'dGitProvider', 'solidity-logic', 'gistHandler', 'layout', 'notification', 'permissionhandler', 'walkthrough', 'storage', 'restorebackupzip', 'link-libraries', 'deploy-libraries', 'intelligentScriptExecutor'] -const dependentModules = ['git', 'hardhat', 'slither'] // module which shouldn't be manually activated (e.g git is activated by remixd) +const dependentModules = ['git', 'hardhat', 'truffle', 'slither'] // module which shouldn't be manually activated (e.g git is activated by remixd) export function isNative (name) { const nativePlugins = ['vyper', 'workshops', 'debugger', 'remixd', 'menuicons', 'solidity', 'hardhat-provider', 'solidityStaticAnalysis', 'solidityUnitTesting', 'layout', 'notification'] diff --git a/apps/remix-ide/src/remixEngine.js b/apps/remix-ide/src/remixEngine.js index 63e94d8669..765fb7626d 100644 --- a/apps/remix-ide/src/remixEngine.js +++ b/apps/remix-ide/src/remixEngine.js @@ -13,6 +13,7 @@ export class RemixEngine extends Engine { if (name === 'dGitProvider') return { queueTimeout: 60000 * 4 } if (name === 'slither') return { queueTimeout: 60000 * 4 } // Requires when a solc version is installed if (name === 'hardhat') return { queueTimeout: 60000 * 4 } + if (name === 'truffle') return { queueTimeout: 60000 * 4 } if (name === 'localPlugin') return { queueTimeout: 60000 * 4 } if (name === 'notification') return { queueTimeout: 60000 * 4 } if (name === 'sourcify') return { queueTimeout: 60000 * 4 } diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index 64747b3c51..6a5a9cc867 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -1,3 +1,4 @@ +import React from 'react'; import { compile, helper } from '@remix-project/remix-solidity' import { CompileTabLogic, parseContracts } from '@remix-ui/solidity-compiler' // eslint-disable-line import type { ConfigurationSettings } from '@remix-project/remix-lib-ts' @@ -100,6 +101,10 @@ export const CompilerApiMixin = (Base) => class extends Base { return this.call('hardhat', 'compile', configFile) } + compileWithTruffle () { + return this.call('truffle', 'compile') + } + logToTerminal (content) { return this.call('terminal', 'log', content) } @@ -323,7 +328,8 @@ export const CompilerApiMixin = (Base) => class extends Base { // ctrl+s or command+s if ((e.metaKey || e.ctrlKey) && !e.shiftKey && e.keyCode === 83 && this.currentFile !== '') { e.preventDefault() - this.compileTabLogic.runCompiler(await this.getAppParameter('hardhat-compilation')) + if(await this.getAppParameter('hardhat-compilation')) this.compileTabLogic.runCompiler('hardhat') + else if(await this.getAppParameter('truffle-compilation')) this.compileTabLogic.runCompiler('truffle') } } window.document.addEventListener('keydown', this.data.eventHandlers.onKeyDown) diff --git a/libs/remix-lib/src/types/ICompilerApi.ts b/libs/remix-lib/src/types/ICompilerApi.ts index 4c796ee3c1..d6d8c5a2ba 100644 --- a/libs/remix-lib/src/types/ICompilerApi.ts +++ b/libs/remix-lib/src/types/ICompilerApi.ts @@ -41,6 +41,7 @@ export interface ICompilerApi { logToTerminal: (log: terminalLog) => void compileWithHardhat: (configPath: string) => Promise + compileWithTruffle: () => Promise statusChanged: (data: { key: string, title?: string, type?: string }) => void, emit?: (key: string, ...payload: any) => void } diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index 4bfbe548f6..5e02c1f94b 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -20,7 +20,7 @@ declare global { const _paq = window._paq = window._paq || [] //eslint-disable-line export const CompilerContainer = (props: CompilerContainerProps) => { - const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject } = props // eslint-disable-line + const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject, isTruffleProject } = props // eslint-disable-line const [state, setState] = useState({ hideWarnings: false, autoCompile: false, @@ -42,6 +42,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const compileIcon = useRef(null) const promptMessageInput = useRef(null) const [hhCompilation, sethhCompilation] = useState(false) + const [truffleCompilation, setTruffleCompilation] = useState(false) const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState) useEffect(() => { @@ -325,7 +326,10 @@ export const CompilerContainer = (props: CompilerContainerProps) => { if (!isSolFileSelected()) return _setCompilerVersionFromPragma(currentFile) - compileTabLogic.runCompiler(hhCompilation) + let externalCompType + if (hhCompilation) externalCompType = 'hardhat' + else if (truffleCompilation) externalCompType = 'truffle' + compileTabLogic.runCompiler(externalCompType) } const _updateVersionSelector = (version, customUrl = '') => { @@ -495,11 +499,18 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const updatehhCompilation = (event) => { const checked = event.target.checked - + if (checked) setTruffleCompilation(false) // wayaround to reset the variable sethhCompilation(checked) api.setAppParameter('hardhat-compilation', checked) } + const updateTruffleCompilation = (event) => { + const checked = event.target.checked + if (checked) sethhCompilation(false) // wayaround to reset the variable + setTruffleCompilation(checked) + api.setAppParameter('truffle-compilation', checked) + } + /* The following functions map with the above event handlers. They are an external API for modifying the compiler configuration. @@ -594,6 +605,22 @@ export const CompilerContainer = (props: CompilerContainerProps) => { } + { + isTruffleProject && +
+ + + + + Learn how to use Truffle Compilation + + }> + + + +
+ }