add deployLibraries and linkLibraries

pull/2208/head
yann300 3 years ago
parent faa7a2bef5
commit 6d3adc068c
  1. 11
      apps/remix-ide/src/app.js
  2. 3
      apps/remix-ide/src/remixAppManager.js
  3. 3
      libs/remix-core-plugin/src/index.ts
  4. 74
      libs/remix-core-plugin/src/lib/link-libraries.ts
  5. 26
      libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts
  6. 23
      libs/remix-core-plugin/src/types/contract.ts
  7. 20
      libs/remix-lib/src/execution/txFormat.ts
  8. 5
      libs/remix-ui/run-tab/src/lib/actions/index.ts
  9. 2
      libs/remix-ui/run-tab/src/lib/actions/payload.ts
  10. 3
      libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx
  11. 3
      libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx
  12. 2
      libs/remix-ui/run-tab/src/lib/reducers/runTab.ts
  13. 3
      libs/remix-ui/run-tab/src/lib/run-tab.tsx
  14. 24
      libs/remix-ui/run-tab/src/lib/types/index.ts

@ -12,6 +12,7 @@ import { LandingPage } from './app/ui/landing-page/landing-page'
import { MainPanel } from './app/components/main-panel'
import { PermissionHandlerPlugin } from './app/plugins/permission-handler-plugin'
import { AstWalker } from '@remix-project/remix-astwalker'
import { LinkLibraries, DeployLibraries, OpenZeppelinProxy } from '@remix-project/core-plugin'
import { WalkthroughService } from './walkthroughService'
@ -268,6 +269,9 @@ class AppComponent {
])
// CONTENT VIEWS & DEFAULT PLUGINS
const openZeppelinProxy = new OpenZeppelinProxy(blockchain)
const linkLibraries = new LinkLibraries(blockchain)
const deployLibraries = new DeployLibraries(blockchain)
const compileTab = new CompileTab(
Registry.getInstance().get('config').api,
Registry.getInstance().get('filemanager').api
@ -302,7 +306,10 @@ class AppComponent {
filePanel.remixdHandle,
filePanel.gitHandle,
filePanel.hardhatHandle,
filePanel.slitherHandle
filePanel.slitherHandle,
linkLibraries,
deployLibraries,
openZeppelinProxy
])
this.layout.panels = {
@ -386,7 +393,7 @@ class AppComponent {
}
})
// activate solidity plugin
this.appManager.activatePlugin(['solidity', 'udapp'])
this.appManager.activatePlugin(['solidity', 'udapp', 'deploy-libraries', 'link-libraries', 'openzeppelin-proxy'])
// Load and start the service who manager layout and frame
}
}

@ -7,7 +7,8 @@ const _paq = window._paq = window._paq || []
const requiredModules = [ // services + layout views + system views
'manager', 'config', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme',
'fileManager', 'contentImport', 'blockchain', 'web3Provider', 'scriptRunner', 'fetchAndCompile', 'mainPanel', 'hiddenPanel', 'sidePanel', 'menuicons',
'filePanel', 'terminal', 'settings', 'pluginManager', 'tabs', 'udapp', 'dGitProvider', 'solidity-logic', 'gistHandler', 'layout', 'notification', 'permissionhandler', 'walkthrough', 'storage', 'restorebackupzip']
'filePanel', 'terminal', 'settings', 'pluginManager', 'tabs', 'udapp', 'dGitProvider', 'solidity-logic', 'gistHandler', 'layout',
'notification', 'permissionhandler', 'walkthrough', 'storage', 'restorebackupzip', 'link-libraries', 'deploy-libraries']
const dependentModules = ['git', 'hardhat', 'slither'] // module which shouldn't be manually activated (e.g git is activated by remixd)

@ -5,3 +5,6 @@ export { CompilerImports } from './lib/compiler-content-imports'
export { CompilerArtefacts } from './lib/compiler-artefacts'
export { EditorContextListener } from './lib/editor-context-listener'
export { GistHandler } from './lib/gist-handler'
export * from './types/contract'
export { LinkLibraries, DeployLibraries } from './lib/link-libraries'
export { OpenZeppelinProxy } from './lib/openzeppelin-proxy'

@ -0,0 +1,74 @@
import { execution } from '@remix-project/remix-lib'
const { txFormat } = execution
import { Plugin } from '@remixproject/engine';
import { ContractData } from '../types/contract';
const profileDeployLibraries = {
name: 'deploy-libraries',
displayName: 'deploy-libraries',
description: 'deploy-libraries',
methods: ['isConcerned', 'execute']
};
const profileLinkLibraries = {
name: 'link-libraries',
displayName: 'link-libraries',
description: 'link-libraries',
methods: ['isConcerned', 'execute']
};
export class DeployLibraries extends Plugin {
blockchain: any
constructor(blockchain) {
super(profileDeployLibraries)
this.blockchain = blockchain
}
async isConcerned(contractData: ContractData): Promise<boolean> {
return Object.keys(contractData.bytecodeLinkReferences).length > 0;
}
execute(contractData: ContractData, contractMetadata: any, compiledContracts: any) {
// we deploy libraries
// and return the linked bytecode
return new Promise((resolve, reject) => {
txFormat.linkBytecode(contractData.object, compiledContracts, (error, bytecode) => {
if (error) return reject (error)
// final Callback
resolve(bytecode)
},
(message) => {
// step Callback
console.log(message)
}, (data, runTxCallback) => {
// deploy library Callback
// called for libraries deployment
this.blockchain.runTx(data, () => {}, () => {}, () => {}, runTxCallback)
})
})
}
}
export class LinkLibraries extends Plugin {
blockchain: any
constructor(blockchain) {
super(profileLinkLibraries)
this.blockchain = blockchain
}
async isConcerned(contractData: ContractData): Promise<boolean> {
return Object.keys(contractData.bytecodeLinkReferences).length > 0;
}
execute(contractData: ContractData, contractMetadata: any, compiledContracts: any) {
// we just link libraries
// and return the linked bytecode
return new Promise((resolve, reject) => {
txFormat.linkLibraries(contractData, contractMetadata.linkReferences, contractData.bytecodeLinkReferences, (error, bytecode) => {
if (error) return reject(error)
resolve(bytecode)
})
})
}
}

@ -0,0 +1,26 @@
import { Plugin } from '@remixproject/engine';
import { ContractData } from '../types/contract';
const proxyProfile = {
name: 'openzeppelin-proxy',
displayName: 'openzeppelin-proxy',
description: 'openzeppelin-proxy',
methods: ['isConcerned', 'execute']
};
export class OpenZeppelinProxy extends Plugin {
blockchain: any
constructor(blockchain) {
super(proxyProfile)
this.blockchain = blockchain
}
async isConcerned(contractData: ContractData): Promise<boolean> {
// check in the AST if it's an upgradable contract
return false
}
async execute(contractData: ContractData, contractMetadata: any, compiledContracts: any) {
// deploy the proxy, or use an existing one
}
}

@ -0,0 +1,23 @@
export interface FuncABI {
name: string,
type: string,
inputs: { name: string, type: string }[],
stateMutability: string,
payable: boolean,
constant: any
}
export interface ContractData {
name: string,
contract: any,
compiler: any,
abi: FuncABI[],
bytecodeObject: any,
bytecodeLinkReferences: any,
object: any,
deployedBytecode: any,
getConstructorInterface: () => any,
getConstructorInputs: () => any,
isOverSizeLimit: () => boolean,
metadata: any
}

@ -96,7 +96,22 @@ export function encodeFunctionCall (params, funAbi, callback) {
export function encodeConstructorCallAndLinkLibraries (contract, params, funAbi, linkLibraries, linkReferences, callback) {
encodeParams(params, funAbi, (error, encodedParam) => {
if (error) return callback(error)
let bytecodeToDeploy = contract.evm.bytecode.object
linkLibraries(contract, linkLibraries, linkReferences, (error, bytecodeToDeploy) => {
callback(error, { dataHex: bytecodeToDeploy + encodedParam.dataHex, funAbi, funArgs: encodedParam.funArgs, contractBytecode: contract.evm.bytecode.object })
})
})
}
/**
* link with provided libraries if needed
*
* @param {Object} contract - input paramater of the function to call
* @param {Object} linkLibraries - contains {linkReferences} object which list all the addresses to be linked
* @param {Object} linkReferences - given by the compiler, contains the proper linkReferences
* @param {Function} callback - callback
*/
export function linkLibraries (contract, linkLibraries, linkReferences, callback) {
let bytecodeToDeploy = contract.evm.bytecode.object
if (bytecodeToDeploy.indexOf('_') >= 0) {
if (linkLibraries && linkReferences) {
for (const libFile in linkLibraries) {
@ -111,8 +126,7 @@ export function encodeConstructorCallAndLinkLibraries (contract, params, funAbi,
if (bytecodeToDeploy.indexOf('_') >= 0) {
return callback('Failed to link some libraries')
}
return callback(null, { dataHex: bytecodeToDeploy + encodedParam.dataHex, funAbi, funArgs: encodedParam.funArgs, contractBytecode: contract.evm.bytecode.object })
})
return callback(null, bytecodeToDeploy)
}
/**

@ -7,7 +7,8 @@ import { addNewInstance, addProvider, clearAllInstances, clearRecorderCount, dis
import { RunTab } from '../types/run-tab'
import { CompilerAbstract } from '@remix-project/remix-solidity'
import * as remixLib from '@remix-project/remix-lib'
import { ContractData, FuncABI, MainnetPrompt } from '../types'
import { MainnetPrompt } from '../types'
import { ContractData, FuncABI, } from '@remix-project/core-plugin'
import { CompilerAbstract as CompilerAbstractType } from '@remix-project/remix-solidity-ts'
const txFormat = remixLib.execution.txFormat
@ -347,7 +348,7 @@ const getCompiledContracts = (compiler) => {
return contracts
}
export const getSelectedContract = (contractName: string, compiler: CompilerAbstractType) => {
export const getSelectedContract = (contractName: string, compiler: CompilerAbstractType): ContractData => {
if (!contractName) return null
// const compiler = plugin.compilersArtefacts[compilerAtributeName]

@ -1,5 +1,5 @@
import { ContractList } from '../reducers/runTab'
import { ContractData } from '../types'
import { ContractData } from '@remix-project/core-plugin'
export const fetchAccountsListRequest = () => {
return {

@ -1,6 +1,7 @@
// eslint-disable-next-line no-use-before-define
import React, { useEffect, useRef, useState } from 'react'
import { ContractData, ContractDropdownProps, FuncABI } from '../types'
import { ContractDropdownProps } from '../types'
import { ContractData, FuncABI } from '@remix-project/core-plugin'
import * as ethJSUtil from 'ethereumjs-util'
import { ContractGUI } from './contractGUI'

@ -1,6 +1,7 @@
// eslint-disable-next-line no-use-before-define
import React, { useEffect, useState } from 'react'
import { FuncABI, UdappProps } from '../types'
import { UdappProps } from '../types'
import { FuncABI } from '@remix-project/core-plugin'
import { CopyToClipboard } from '@remix-ui/clipboard'
import * as remixLib from '@remix-project/remix-lib'
import * as ethJSUtil from 'ethereumjs-util'

@ -1,5 +1,5 @@
import { CompilerAbstract } from '@remix-project/remix-solidity-ts'
import { ContractData } from '../types'
import { ContractData } from '@remix-project/core-plugin'
interface Action {
type: string
payload: any

@ -7,7 +7,8 @@ import { ContractDropdownUI } from './components/contractDropdownUI'
import { InstanceContainerUI } from './components/instanceContainerUI'
import { RecorderUI } from './components/recorderCardUI'
import { SettingsUI } from './components/settingsUI'
import { ContractData, Modal, Network, RunTabProps, Tx } from './types'
import { Modal, Network, RunTabProps, Tx } from './types'
import { ContractData } from '@remix-project/core-plugin'
import { runTabInitialState, runTabReducer } from './reducers/runTab'
import {
initRunTab, setAccount,

@ -1,4 +1,5 @@
import { CompilerAbstract } from '@remix-project/remix-solidity-ts'
import { ContractData, FuncABI } from '@remix-project/core-plugin'
import { ContractList } from '../reducers/runTab'
import { RunTab } from './run-tab'
export interface RunTabProps {
@ -101,29 +102,6 @@ export interface ValueProps {
sendUnit: string
}
export interface FuncABI {
name: string,
type: string,
inputs: { name: string, type: string }[],
stateMutability: string,
payable: boolean,
constant: any
}
export interface ContractData {
name: string,
contract: any,
compiler: any,
abi: FuncABI[],
bytecodeObject: any,
bytecodeLinkReferences: any,
object: any,
deployedBytecode: any,
getConstructorInterface: () => any,
getConstructorInputs: () => any,
isOverSizeLimit: () => boolean,
metadata: any
}
export interface Tx {
from: string,
to: string,

Loading…
Cancel
Save