[
block:${data.block.number} - 0 transactions]
- `
-}
-
-function checkTxStatus (tx, type) {
- if (tx.status === '0x1' || tx.status === true) {
- return yo`
`
- }
- if (type === 'call' || type === 'unknownCall') {
- return yo`
call`
- } else if (tx.status === '0x0' || tx.status === false) {
- return yo`
`
- } else {
- return yo`
`
- }
-}
-
-function context (self, opts, blockchain) {
- var data = opts.data || ''
- var from = opts.from ? helper.shortenHexData(opts.from) : ''
- var to = opts.to
- if (data.tx.to) to = to + ' ' + helper.shortenHexData(data.tx.to)
- var val = data.tx.value
- var hash = data.tx.hash ? helper.shortenHexData(data.tx.hash) : ''
- var input = data.tx.input ? helper.shortenHexData(data.tx.input) : ''
- var logs = data.logs && data.logs.decoded && data.logs.decoded.length ? data.logs.decoded.length : 0
- var block = data.receipt ? data.receipt.blockNumber : data.tx.blockNumber || ''
- var i = data.receipt ? data.receipt.transactionIndex : data.tx.transactionIndex
- var value = val ? typeConversion.toInt(val) : 0
- if (blockchain.getProvider() === 'vm') {
- return yo`
-
-
- [vm]
- from: ${from}
- to: ${to}
- value: ${value} wei
- data: ${input}
- logs: ${logs}
- hash: ${hash}
-
-
`
- } else if (blockchain.getProvider() !== 'vm' && data.resolvedData) {
- return yo`
-
-
- [block:${block} txIndex:${i}]
- from: ${from}
- to: ${to}
- value: ${value} wei
- data: ${input}
- logs: ${logs}
- hash: ${hash}
-
-
`
- } else {
- to = helper.shortenHexData(to)
- hash = helper.shortenHexData(data.tx.blockHash)
- return yo`
-
-
- [block:${block} txIndex:${i}]
- from: ${from}
- to: ${to}
- value: ${value} wei
-
-
`
- }
-}
-
-module.exports = TxLogger
-
-// helpers
-
-function isDescendant (parent, child) {
- var node = child.parentNode
- while (node != null) {
- if (node === parent) {
- return true
- }
- node = node.parentNode
- }
- return false
-}
-
-function txDetails (e, tx, data, obj) {
- const from = obj.from
- const to = obj.to
- const arrowUp = yo`
`
- const arrowDown = yo`
`
-
- let blockElement = e.target
- while (true) { // get the parent block element
- if (blockElement.className.startsWith('block')) break
- else if (blockElement.parentElement) {
- blockElement = blockElement.parentElement
- } else break
- }
-
- const tables = blockElement.querySelectorAll(`#${tx.id} [class^="txTable"]`)
- const logs = blockElement.querySelectorAll(`#${tx.id} [class^='log']`)
- const arrows = blockElement.querySelectorAll(`#${tx.id} [class^='arrow']`)
-
- let table = [...tables].filter((t) => isDescendant(tx, t))[0]
- const log = [...logs].filter((t) => isDescendant(tx, t))[0]
- const arrow = [...arrows].filter((t) => isDescendant(tx, t))[0]
-
- if (table && table.parentNode) {
- tx.removeChild(table)
- log.removeChild(arrow)
- log.appendChild(arrowDown)
- } else {
- log.removeChild(arrow)
- log.appendChild(arrowUp)
- table = createTable({
- hash: data.tx.hash,
- status: data.receipt ? data.receipt.status : null,
- isCall: data.tx.isCall,
- contractAddress: data.tx.contractAddress,
- data: data.tx,
- from,
- to,
- gas: data.tx.gas,
- input: data.tx.input,
- 'decoded input': data.resolvedData && data.resolvedData.params ? JSON.stringify(typeConversion.stringify(data.resolvedData.params), null, '\t') : ' - ',
- 'decoded output': data.resolvedData && data.resolvedData.decodedReturnValue ? JSON.stringify(typeConversion.stringify(data.resolvedData.decodedReturnValue), null, '\t') : ' - ',
- logs: data.logs,
- val: data.tx.value,
- transactionCost: data.tx.transactionCost,
- executionCost: data.tx.executionCost
- })
- tx.appendChild(table)
- }
-}
-
-function createTable (opts) {
- var table = yo`
`
- if (!opts.isCall) {
- var msg = ''
- if (opts.status !== undefined && opts.status !== null) {
- if (opts.status === '0x0' || opts.status === false) {
- msg = ' Transaction mined but execution failed'
- } else if (opts.status === '0x1' || opts.status === true) {
- msg = ' Transaction mined and execution succeed'
- }
- } else {
- msg = ' Status not available at the moment'
- }
- table.appendChild(yo`
-
- status |
- ${opts.status}${msg} |
-
`)
- }
-
- var transactionHash = yo`
-
- transaction hash |
- ${opts.hash}
- ${copyToClipboard(() => opts.hash)}
- |
-
- `
- table.appendChild(transactionHash)
-
- var contractAddress = yo`
-
- contract address |
- ${opts.contractAddress}
- ${copyToClipboard(() => opts.contractAddress)}
- |
-
- `
- if (opts.contractAddress) table.appendChild(contractAddress)
-
- var from = yo`
-
- from |
- ${opts.from}
- ${copyToClipboard(() => opts.from)}
- |
-
- `
- if (opts.from) table.appendChild(from)
-
- var toHash
- var data = opts.data // opts.data = data.tx
- if (data.to) {
- toHash = opts.to + ' ' + data.to
- } else {
- toHash = opts.to
- }
- var to = yo`
-
- to |
- ${toHash}
- ${copyToClipboard(() => data.to ? data.to : toHash)}
- |
-
- `
- if (opts.to) table.appendChild(to)
-
- var gas = yo`
-
- gas |
- ${opts.gas} gas
- ${copyToClipboard(() => opts.gas)}
- |
-
- `
- if (opts.gas) table.appendChild(gas)
-
- var callWarning = ''
- if (opts.isCall) {
- callWarning = '(Cost only applies when called by a contract)'
- }
- if (opts.transactionCost) {
- table.appendChild(yo`
-
- transaction cost |
- ${opts.transactionCost} gas ${callWarning}
- ${copyToClipboard(() => opts.transactionCost)}
- |
-
`)
- }
-
- if (opts.executionCost) {
- table.appendChild(yo`
-
- execution cost |
- ${opts.executionCost} gas ${callWarning}
- ${copyToClipboard(() => opts.executionCost)}
- |
-
`)
- }
-
- var hash = yo`
-
- hash |
- ${opts.hash}
- ${copyToClipboard(() => opts.hash)}
- |
-
- `
- if (opts.hash) table.appendChild(hash)
-
- var input = yo`
-
- input |
- ${helper.shortenHexData(opts.input)}
- ${copyToClipboard(() => opts.input)}
- |
-
- `
- if (opts.input) table.appendChild(input)
-
- if (opts['decoded input']) {
- var inputDecoded = yo`
-
- decoded input |
- ${opts['decoded input']}
- ${copyToClipboard(() => opts['decoded input'])}
- |
-
`
- table.appendChild(inputDecoded)
- }
-
- if (opts['decoded output']) {
- var outputDecoded = yo`
-
- decoded output |
- ${opts['decoded output']}
- ${copyToClipboard(() => opts['decoded output'])}
- |
-
`
- table.appendChild(outputDecoded)
- }
-
- var stringified = ' - '
- if (opts.logs && opts.logs.decoded) {
- stringified = typeConversion.stringify(opts.logs.decoded)
- }
- var logs = yo`
-
- logs |
-
- ${JSON.stringify(stringified, null, '\t')}
- ${copyToClipboard(() => JSON.stringify(stringified, null, '\t'))}
- ${copyToClipboard(() => JSON.stringify(opts.logs.raw || '0'))}
- |
-
- `
- if (opts.logs) table.appendChild(logs)
-
- var val = opts.val != null ? typeConversion.toInt(opts.val) : 0
- val = yo`
-
- value |
- ${val} wei
- ${copyToClipboard(() => `${val} wei`)}
- |
-
- `
- if (opts.val) table.appendChild(val)
-
- return table
-}
diff --git a/apps/remix-ide/src/lib/cmdInterpreterAPI.js b/apps/remix-ide/src/lib/cmdInterpreterAPI.js
deleted file mode 100644
index 82ae4636fe..0000000000
--- a/apps/remix-ide/src/lib/cmdInterpreterAPI.js
+++ /dev/null
@@ -1,132 +0,0 @@
-'use strict'
-import { CompilerImports } from '@remix-project/core-plugin'
-import Registry from '../app/state/registry'
-var yo = require('yo-yo')
-var async = require('async')
-var EventManager = require('../lib/events')
-
-var toolTip = require('../app/ui/tooltip')
-
-class CmdInterpreterAPI {
- constructor (terminal, blockchain) {
- const self = this
- self.event = new EventManager()
- self.blockchain = blockchain
- self._components = {}
- self._components.registry = Registry.getInstance()
- self._components.terminal = terminal
- self._components.fileImport = new CompilerImports()
- self._deps = {
- fileManager: self._components.registry.get('filemanager').api,
- editor: self._components.registry.get('editor').api,
- compilersArtefacts: self._components.registry.get('compilersartefacts').api,
- offsetToLineColumnConverter: self._components.registry.get('offsettolinecolumnconverter').api
- }
- self.commandHelp = {
- 'remix.loadgist(id)': 'Load a gist in the file explorer.',
- 'remix.loadurl(url)': 'Load the given url in the file explorer. The url can be of type github, swarm, ipfs or raw http',
- 'remix.execute(filepath)': 'Run the script specified by file path. If filepath is empty, script currently displayed in the editor is executed.',
- 'remix.exeCurrent()': 'Run the script currently displayed in the editor',
- 'remix.help()': 'Display this help message'
- }
- }
-
- log () { arguments[0] != null ? this._components.terminal.commands.html(arguments[0]) : this._components.terminal.commands.html(arguments[1]) }
- loadgist (id, cb) {
- this._components.terminal.call('gistHandler', 'load', id)
- if (cb) cb()
- }
-
- loadurl (url, cb) {
- const self = this
- self._components.fileImport.import(url,
- (loadingMsg) => { toolTip(loadingMsg) },
- (err, content, cleanUrl, type, url) => {
- if (err) {
- toolTip(`Unable to load ${url}: ${err}`)
- if (cb) cb(err)
- } else {
- self._deps.fileManager.writeFile(type + '/' + cleanUrl, content)
- try {
- content = JSON.parse(content)
- async.eachOfSeries(content.sources, (value, file, callbackSource) => {
- var url = value.urls[0] // @TODO retrieve all other contents ?
- self._components.fileImport.import(url,
- (loadingMsg) => { toolTip(loadingMsg) },
- async (error, content, cleanUrl, type, url) => {
- if (error) {
- toolTip(`Cannot retrieve the content of ${url}: ${error}`)
- return callbackSource(`Cannot retrieve the content of ${url}: ${error}`)
- } else {
- try {
- await self._deps.fileManager.writeFile(type + '/' + cleanUrl, content)
- callbackSource()
- } catch (e) {
- callbackSource(e.message)
- }
- }
- })
- }, (error) => {
- if (cb) cb(error)
- })
- } catch (e) {}
- if (cb) cb()
- }
- })
- }
-
- exeCurrent (cb) {
- return this.execute(undefined, cb)
- }
-
- execute (file, cb) {
- const self = this
-
- function _execute (content, cb) {
- if (!content) {
- toolTip('no content to execute')
- if (cb) cb()
- return
- }
- self._components.terminal.commands.script(content)
- }
-
- if (typeof file === 'undefined') {
- var content = self._deps.editor.currentContent()
- _execute(content, cb)
- return
- }
-
- var provider = self._deps.fileManager.fileProviderOf(file)
-
- if (!provider) {
- toolTip(`provider for path ${file} not found`)
- if (cb) cb()
- return
- }
-
- provider.get(file, (error, content) => {
- if (error) {
- toolTip(error)
- if (cb) cb()
- return
- }
-
- _execute(content, cb)
- })
- }
-
- help (cb) {
- const self = this
- var help = yo`
`
- for (var k in self.commandHelp) {
- help.appendChild(yo`
${k}: ${self.commandHelp[k]}
`)
- help.appendChild(yo`
`)
- }
- self._components.terminal.commands.html(help)
- if (cb) cb()
- return ''
- }
-}
-
-module.exports = CmdInterpreterAPI