|
|
@ -1,20 +1,20 @@ |
|
|
|
import React from 'react' // eslint-disable-line
|
|
|
|
import React from 'react' // eslint-disable-line
|
|
|
|
import {fromWei, toBigInt, toWei} from 'web3-utils' |
|
|
|
import { fromWei, toBigInt, toWei } from 'web3-utils' |
|
|
|
import {Plugin} from '@remixproject/engine' |
|
|
|
import { Plugin } from '@remixproject/engine' |
|
|
|
import {toBytes, addHexPrefix} from '@ethereumjs/util' |
|
|
|
import { toBytes, addHexPrefix } from '@ethereumjs/util' |
|
|
|
import {EventEmitter} from 'events' |
|
|
|
import { EventEmitter } from 'events' |
|
|
|
import {format} from 'util' |
|
|
|
import { format } from 'util' |
|
|
|
import {ExecutionContext} from './execution-context' |
|
|
|
import { ExecutionContext } from './execution-context' |
|
|
|
import Config from '../config' |
|
|
|
import Config from '../config' |
|
|
|
import {VMProvider} from './providers/vm' |
|
|
|
import { VMProvider } from './providers/vm' |
|
|
|
import {InjectedProvider} from './providers/injected' |
|
|
|
import { InjectedProvider } from './providers/injected' |
|
|
|
import {NodeProvider} from './providers/node' |
|
|
|
import { NodeProvider } from './providers/node' |
|
|
|
import {execution, EventManager, helpers} from '@remix-project/remix-lib' |
|
|
|
import { execution, EventManager, helpers } from '@remix-project/remix-lib' |
|
|
|
import {etherScanLink} from './helper' |
|
|
|
import { etherScanLink } from './helper' |
|
|
|
import {logBuilder, cancelUpgradeMsg, cancelProxyMsg, addressToString} from '@remix-ui/helper' |
|
|
|
import { logBuilder, cancelUpgradeMsg, cancelProxyMsg, addressToString } from '@remix-ui/helper' |
|
|
|
const {txFormat, txExecution, typeConversion, txListener: Txlistener, TxRunner, TxRunnerWeb3, txHelper} = execution |
|
|
|
const { txFormat, txExecution, typeConversion, txListener: Txlistener, TxRunner, TxRunnerWeb3, txHelper } = execution |
|
|
|
const {txResultHelper} = helpers |
|
|
|
const { txResultHelper } = helpers |
|
|
|
const {resultToRemixTx} = txResultHelper |
|
|
|
const { resultToRemixTx } = txResultHelper |
|
|
|
import * as packageJson from '../../../../package.json' |
|
|
|
import * as packageJson from '../../../../package.json' |
|
|
|
|
|
|
|
|
|
|
|
const _paq = (window._paq = window._paq || []) //eslint-disable-line
|
|
|
|
const _paq = (window._paq = window._paq || []) //eslint-disable-line
|
|
|
@ -91,7 +91,7 @@ export class Blockchain extends Plugin { |
|
|
|
this.txRunner = new TxRunner(web3Runner, {}) |
|
|
|
this.txRunner = new TxRunner(web3Runner, {}) |
|
|
|
|
|
|
|
|
|
|
|
this.networkcallid = 0 |
|
|
|
this.networkcallid = 0 |
|
|
|
this.networkStatus = {network: {name: ' - ', id: ' - '}} |
|
|
|
this.networkStatus = { network: { name: ' - ', id: ' - ' } } |
|
|
|
this.registeredPluginEvents = [] |
|
|
|
this.registeredPluginEvents = [] |
|
|
|
this.setupEvents() |
|
|
|
this.setupEvents() |
|
|
|
this.setupProviders() |
|
|
|
this.setupProviders() |
|
|
@ -110,7 +110,7 @@ export class Blockchain extends Plugin { |
|
|
|
this.registeredPluginEvents.push(plugin.name) |
|
|
|
this.registeredPluginEvents.push(plugin.name) |
|
|
|
this.on(plugin.name, 'chainChanged', () => { |
|
|
|
this.on(plugin.name, 'chainChanged', () => { |
|
|
|
this.detectNetwork((error, network) => { |
|
|
|
this.detectNetwork((error, network) => { |
|
|
|
this.networkStatus = {network, error} |
|
|
|
this.networkStatus = { network, error } |
|
|
|
this._triggerEvent('networkStatus', [this.networkStatus]) |
|
|
|
this._triggerEvent('networkStatus', [this.networkStatus]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -131,7 +131,7 @@ export class Blockchain extends Plugin { |
|
|
|
await this.loadContext(context) |
|
|
|
await this.loadContext(context) |
|
|
|
this._triggerEvent('contextChanged', [context]) |
|
|
|
this._triggerEvent('contextChanged', [context]) |
|
|
|
this.detectNetwork((error, network) => { |
|
|
|
this.detectNetwork((error, network) => { |
|
|
|
this.networkStatus = {network, error} |
|
|
|
this.networkStatus = { network, error } |
|
|
|
this._triggerEvent('networkStatus', [this.networkStatus]) |
|
|
|
this._triggerEvent('networkStatus', [this.networkStatus]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -146,7 +146,7 @@ export class Blockchain extends Plugin { |
|
|
|
|
|
|
|
|
|
|
|
setInterval(() => { |
|
|
|
setInterval(() => { |
|
|
|
this.detectNetwork((error, network) => { |
|
|
|
this.detectNetwork((error, network) => { |
|
|
|
this.networkStatus = {network, error} |
|
|
|
this.networkStatus = { network, error } |
|
|
|
this._triggerEvent('networkStatus', [this.networkStatus]) |
|
|
|
this._triggerEvent('networkStatus', [this.networkStatus]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, 30000) |
|
|
|
}, 30000) |
|
|
@ -189,7 +189,7 @@ export class Blockchain extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
deployContractAndLibraries(selectedContract, args, contractMetadata, compilerContracts, callbacks, confirmationCb) { |
|
|
|
deployContractAndLibraries(selectedContract, args, contractMetadata, compilerContracts, callbacks, confirmationCb) { |
|
|
|
const {continueCb, promptCb, statusCb, finalCb} = callbacks |
|
|
|
const { continueCb, promptCb, statusCb, finalCb } = callbacks |
|
|
|
const constructor = selectedContract.getConstructorInterface() |
|
|
|
const constructor = selectedContract.getConstructorInterface() |
|
|
|
txFormat.buildData( |
|
|
|
txFormat.buildData( |
|
|
|
selectedContract.name, |
|
|
|
selectedContract.name, |
|
|
@ -215,7 +215,7 @@ export class Blockchain extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
deployContractWithLibrary(selectedContract, args, contractMetadata, compilerContracts, callbacks, confirmationCb) { |
|
|
|
deployContractWithLibrary(selectedContract, args, contractMetadata, compilerContracts, callbacks, confirmationCb) { |
|
|
|
const {continueCb, promptCb, statusCb, finalCb} = callbacks |
|
|
|
const { continueCb, promptCb, statusCb, finalCb } = callbacks |
|
|
|
const constructor = selectedContract.getConstructorInterface() |
|
|
|
const constructor = selectedContract.getConstructorInterface() |
|
|
|
txFormat.encodeConstructorCallAndLinkLibraries( |
|
|
|
txFormat.encodeConstructorCallAndLinkLibraries( |
|
|
|
selectedContract.object, |
|
|
|
selectedContract.object, |
|
|
@ -257,7 +257,7 @@ export class Blockchain extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async runProxyTx(proxyData, implementationContractObject) { |
|
|
|
async runProxyTx(proxyData, implementationContractObject) { |
|
|
|
const args = {useCall: false, data: proxyData} |
|
|
|
const args = { useCall: false, data: proxyData } |
|
|
|
let networkInfo |
|
|
|
let networkInfo |
|
|
|
const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => { |
|
|
|
const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => { |
|
|
|
networkInfo = network |
|
|
|
networkInfo = network |
|
|
@ -308,7 +308,7 @@ export class Blockchain extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async runUpgradeTx(proxyAddress, data, newImplementationContractObject) { |
|
|
|
async runUpgradeTx(proxyAddress, data, newImplementationContractObject) { |
|
|
|
const args = {useCall: false, data, to: proxyAddress} |
|
|
|
const args = { useCall: false, data, to: proxyAddress } |
|
|
|
let networkInfo |
|
|
|
let networkInfo |
|
|
|
const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => { |
|
|
|
const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => { |
|
|
|
// continue using original authorization given by user
|
|
|
|
// continue using original authorization given by user
|
|
|
@ -336,7 +336,7 @@ export class Blockchain extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async saveDeployedContractStorageLayout(contractObject, proxyAddress, networkInfo) { |
|
|
|
async saveDeployedContractStorageLayout(contractObject, proxyAddress, networkInfo) { |
|
|
|
const {contractName, implementationAddress} = contractObject |
|
|
|
const { contractName, implementationAddress } = contractObject |
|
|
|
const networkName = networkInfo.name === 'custom' ? networkInfo.name + '-' + networkInfo.id : networkInfo.name |
|
|
|
const networkName = networkInfo.name === 'custom' ? networkInfo.name + '-' + networkInfo.id : networkInfo.name |
|
|
|
const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkName}/UUPS.json`) |
|
|
|
const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkName}/UUPS.json`) |
|
|
|
// TODO: make deploys folder read only.
|
|
|
|
// TODO: make deploys folder read only.
|
|
|
@ -436,7 +436,7 @@ export class Blockchain extends Plugin { |
|
|
|
data.contractABI = selectedContract.abi |
|
|
|
data.contractABI = selectedContract.abi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.runTx({data: data, useCall: false}, confirmationCb, continueCb, promptCb, (error, txResult, address) => { |
|
|
|
this.runTx({ data: data, useCall: false }, confirmationCb, continueCb, promptCb, (error, txResult, address) => { |
|
|
|
if (error) { |
|
|
|
if (error) { |
|
|
|
return finalCb(`creation of ${selectedContract.name} errored: ${error.message ? error.message : error}`) |
|
|
|
return finalCb(`creation of ${selectedContract.name} errored: ${error.message ? error.message : error}`) |
|
|
|
} |
|
|
|
} |
|
|
@ -578,7 +578,7 @@ export class Blockchain extends Plugin { |
|
|
|
data.contract = contract |
|
|
|
data.contract = contract |
|
|
|
} |
|
|
|
} |
|
|
|
const useCall = funABI.stateMutability === 'view' || funABI.stateMutability === 'pure' |
|
|
|
const useCall = funABI.stateMutability === 'view' || funABI.stateMutability === 'pure' |
|
|
|
this.runTx({to: address, data, useCall}, confirmationCb, continueCb, promptCb, (error, txResult, _address, returnValue) => { |
|
|
|
this.runTx({ to: address, data, useCall }, confirmationCb, continueCb, promptCb, (error, txResult, _address, returnValue) => { |
|
|
|
if (error) { |
|
|
|
if (error) { |
|
|
|
return logCallback(`${logMsg} errored: ${error.message ? error.message : error}`) |
|
|
|
return logCallback(`${logMsg} errored: ${error.message ? error.message : error}`) |
|
|
|
} |
|
|
|
} |
|
|
@ -629,13 +629,13 @@ export class Blockchain extends Plugin { |
|
|
|
|
|
|
|
|
|
|
|
async loadContext(context: string) { |
|
|
|
async loadContext(context: string) { |
|
|
|
const saveEvmState = this.config.get('settings/save-evm-state') |
|
|
|
const saveEvmState = this.config.get('settings/save-evm-state') |
|
|
|
|
|
|
|
|
|
|
|
if (saveEvmState) { |
|
|
|
if (saveEvmState) { |
|
|
|
const contextExists = await this.call('fileManager', 'exists', `.states/${context}/state.json`) |
|
|
|
const contextExists = await this.call('fileManager', 'exists', `.states/${context}/state.json`) |
|
|
|
|
|
|
|
|
|
|
|
if (contextExists) { |
|
|
|
if (contextExists) { |
|
|
|
const stateDb = await this.call('fileManager', 'readFile', `.states/${context}/state.json`) |
|
|
|
const stateDb = await this.call('fileManager', 'readFile', `.states/${context}/state.json`) |
|
|
|
|
|
|
|
|
|
|
|
await this.getCurrentProvider().resetEnvironment(stateDb) |
|
|
|
await this.getCurrentProvider().resetEnvironment(stateDb) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
await this.getCurrentProvider().resetEnvironment() |
|
|
|
await this.getCurrentProvider().resetEnvironment() |
|
|
@ -676,7 +676,7 @@ export class Blockchain extends Plugin { |
|
|
|
view on etherscan |
|
|
|
view on etherscan |
|
|
|
</a> |
|
|
|
</a> |
|
|
|
) |
|
|
|
) |
|
|
|
}
|
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.txRunner = new TxRunner(web3Runner, {}) |
|
|
|
this.txRunner = new TxRunner(web3Runner, {}) |
|
|
@ -866,7 +866,7 @@ export class Blockchain extends Plugin { |
|
|
|
const eventName = tx.useCall ? 'callExecuted' : 'transactionExecuted' |
|
|
|
const eventName = tx.useCall ? 'callExecuted' : 'transactionExecuted' |
|
|
|
|
|
|
|
|
|
|
|
this._triggerEvent(eventName, [error, tx.from, tx.to, tx.data, tx.useCall, result, timestamp, payLoad]) |
|
|
|
this._triggerEvent(eventName, [error, tx.from, tx.to, tx.data, tx.useCall, result, timestamp, payLoad]) |
|
|
|
return resolve({result, tx}) |
|
|
|
return resolve({ result, tx }) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} catch (err) { |
|
|
|
} catch (err) { |
|
|
|
return reject(err) |
|
|
|
return reject(err) |
|
|
@ -894,7 +894,7 @@ export class Blockchain extends Plugin { |
|
|
|
this.call('fileManager', 'writeFile', `.states/${this.executionContext.getProvider()}/state.json`, state) |
|
|
|
this.call('fileManager', 'writeFile', `.states/${this.executionContext.getProvider()}/state.json`, state) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
console.error(e) |
|
|
|
console.error(e) |
|
|
|
}
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const hhlogs = await this.web3().remix.getHHLogsForTx(txResult.transactionHash) |
|
|
|
const hhlogs = await this.web3().remix.getHHLogsForTx(txResult.transactionHash) |
|
|
@ -923,7 +923,7 @@ export class Blockchain extends Plugin { |
|
|
|
this.call('terminal', 'logHtml', finalLogs) |
|
|
|
this.call('terminal', 'logHtml', finalLogs) |
|
|
|
} |
|
|
|
} |
|
|
|
execResult = await this.web3().remix.getExecutionResultFromSimulator(txResult.transactionHash) |
|
|
|
execResult = await this.web3().remix.getExecutionResultFromSimulator(txResult.transactionHash) |
|
|
|
|
|
|
|
|
|
|
|
if (execResult) { |
|
|
|
if (execResult) { |
|
|
|
// if it's not the VM, we don't have return value. We only have the transaction, and it does not contain the return value.
|
|
|
|
// if it's not the VM, we don't have return value. We only have the transaction, and it does not contain the return value.
|
|
|
|
returnValue = execResult |
|
|
|
returnValue = execResult |
|
|
@ -959,9 +959,9 @@ export class Blockchain extends Plugin { |
|
|
|
cb((await buildError(errorMessage, errorData)).message) |
|
|
|
cb((await buildError(errorMessage, errorData)).message) |
|
|
|
} else if (error.message || error.data) { |
|
|
|
} else if (error.message || error.data) { |
|
|
|
errorMessage = error.message |
|
|
|
errorMessage = error.message |
|
|
|
errorData = error.data
|
|
|
|
errorData = error.data |
|
|
|
cb((await buildError(errorMessage, errorData)).message) |
|
|
|
cb((await buildError(errorMessage, errorData)).message) |
|
|
|
} else
|
|
|
|
} else |
|
|
|
cb(error) |
|
|
|
cb(error) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|