helpers erc updated

pull/5370/head
aniket-engg 4 years ago committed by Aniket
parent c87be5dbae
commit 74e0d33904
  1. 6
      libs/remix-lib/src/helpers/compilerHelper.ts
  2. 9
      libs/remix-lib/src/helpers/txResultHelper.ts
  3. 142
      libs/remix-lib/src/helpers/uiHelper.ts

@ -1,8 +1,4 @@
module.exports = { export function compilerInput (contracts) {
compilerInput: compilerInput
}
function compilerInput (contracts) {
return JSON.stringify({ return JSON.stringify({
language: 'Solidity', language: 'Solidity',
sources: { sources: {

@ -1,5 +1,6 @@
'use strict' 'use strict'
const { bufferToHex, isHexString } = require('ethereumjs-util') import { bufferToHex } from 'ethereumjs-util'
import { isHexString } from 'ethjs-util'
function convertToPrefixedHex (input) { function convertToPrefixedHex (input) {
if (input === undefined || input === null || isHexString(input)) { if (input === undefined || input === null || isHexString(input)) {
@ -19,7 +20,7 @@ function convertToPrefixedHex (input) {
Also, VM results use BN and Buffers, Node results use hex strings/ints, Also, VM results use BN and Buffers, Node results use hex strings/ints,
So we need to normalize the values to prefixed hex strings So we need to normalize the values to prefixed hex strings
*/ */
function resultToRemixTx (txResult) { export function resultToRemixTx (txResult) {
const { result, transactionHash } = txResult const { result, transactionHash } = txResult
const { status, execResult, gasUsed, createdAddress, contractAddress } = result const { status, execResult, gasUsed, createdAddress, contractAddress } = result
let returnValue, errorMessage let returnValue, errorMessage
@ -40,7 +41,3 @@ function resultToRemixTx (txResult) {
createdAddress: convertToPrefixedHex(createdAddress || contractAddress) createdAddress: convertToPrefixedHex(createdAddress || contractAddress)
} }
} }
module.exports = {
resultToRemixTx
}

@ -1,86 +1,84 @@
'use strict' 'use strict'
module.exports = { export function formatMemory (mem, width) {
formatMemory: function (mem, width) { const ret = {}
const ret = {} if (!mem) {
if (!mem) { return ret
return ret }
}
if (!mem.substr) { if (!mem.substr) {
mem = mem.join('') // geth returns an array, eth return raw string mem = mem.join('') // geth returns an array, eth return raw string
} }
for (let k = 0; k < mem.length; k += (width * 2)) { for (let k = 0; k < mem.length; k += (width * 2)) {
const memory = mem.substr(k, width * 2) const memory = mem.substr(k, width * 2)
const content = this.tryConvertAsciiFormat(memory) const content = this.tryConvertAsciiFormat(memory)
ret['0x' + (k / 2).toString(16)] = content.raw + '\t' + content.ascii ret['0x' + (k / 2).toString(16)] = content.raw + '\t' + content.ascii
} }
return ret return ret
}, }
tryConvertAsciiFormat: function (memorySlot) { export function tryConvertAsciiFormat (memorySlot) {
const ret = { ascii: '', raw: '' } const ret = { ascii: '', raw: '' }
for (let k = 0; k < memorySlot.length; k += 2) { for (let k = 0; k < memorySlot.length; k += 2) {
const raw = memorySlot.substr(k, 2) const raw = memorySlot.substr(k, 2)
let ascii = String.fromCharCode(parseInt(raw, 16)) let ascii = String.fromCharCode(parseInt(raw, 16))
ascii = ascii.replace(/[^\w\s]/, '?') ascii = ascii.replace(/[^\w\s]/, '?')
if (ascii === '') { if (ascii === '') {
ascii = '?' ascii = '?'
}
ret.ascii += ascii
ret.raw += raw
} }
return ret ret.ascii += ascii
}, ret.raw += raw
}
return ret
}
/** /**
* format @args css1, css2, css3 to css inline style * format @args css1, css2, css3 to css inline style
* *
* @param {Object} css1 - css inline declaration * @param {Object} css1 - css inline declaration
* @param {Object} css2 - css inline declaration * @param {Object} css2 - css inline declaration
* @param {Object} css3 - css inline declaration * @param {Object} css3 - css inline declaration
* @param {Object} ... * @param {Object} ...
* @return {String} css inline style * @return {String} css inline style
* if the key start with * the value is direcly appended to the inline style (which should be already inline style formatted) * if the key start with * the value is direcly appended to the inline style (which should be already inline style formatted)
* used if multiple occurences of the same key is needed * used if multiple occurences of the same key is needed
*/ */
formatCss: function (css1, css2) { export function formatCss (css1, css2) {
let ret = '' let ret = ''
for (let arg in arguments) { for (let arg in arguments) {
for (let k in arguments[arg]) { for (let k in arguments[arg]) {
if (arguments[arg][k] && ret.indexOf(k) === -1) { if (arguments[arg][k] && ret.indexOf(k) === -1) {
if (k.indexOf('*') === 0) { if (k.indexOf('*') === 0) {
ret += arguments[arg][k] ret += arguments[arg][k]
} else { } else {
ret += k + ':' + arguments[arg][k] + ';' ret += k + ':' + arguments[arg][k] + ';'
}
} }
} }
} }
return ret }
}, return ret
}
normalizeHex: function (hex) { export function normalizeHex (hex) {
if (hex.indexOf('0x') === 0) { if (hex.indexOf('0x') === 0) {
hex = hex.replace('0x', '') hex = hex.replace('0x', '')
} }
hex = hex.replace(/^0+/, '') hex = hex.replace(/^0+/, '')
return '0x' + hex return '0x' + hex
}, }
normalizeHexAddress: function (hex) { export function normalizeHexAddress (hex) {
if (hex.indexOf('0x') === 0) hex = hex.replace('0x', '') if (hex.indexOf('0x') === 0) hex = hex.replace('0x', '')
if (hex.length >= 40) { if (hex.length >= 40) {
const reg = /(.{40})$/.exec(hex) const reg = /(.{40})$/.exec(hex)
if (reg) { if (reg) {
return '0x' + reg[0] return '0x' + reg[0]
}
} else {
return '0x' + (new Array(40 - hex.length + 1).join('0')) + hex
} }
}, } else {
return '0x' + (new Array(40 - hex.length + 1).join('0')) + hex
runInBrowser: function () {
return typeof window !== 'undefined'
} }
} }
export function runInBrowser () {
return typeof window !== 'undefined'
}

Loading…
Cancel
Save