`
return tx
@@ -264,40 +263,13 @@ function context (self, opts) {
var block = data.tx.blockNumber || ''
var i = data.tx.transactionIndex
if (executionContext.getProvider() === 'vm') {
- return yo`[vm] from:${from}, to:${to}, value:${value(val)} wei, data:${input}, ${logs} logs, hash:${hash}`
+ return yo`[vm] from:${from}, to:${to}, value:${typeConversion.hexToInt(val)} wei, data:${input}, ${logs} logs, hash:${hash}`
} else if (executionContext.getProvider() !== 'vm' && data.resolvedData) {
- return yo`[block:${block} txIndex:${i}] from:${from}, to:${to}, value:${value(val)} wei, ${logs} logs, data:${input}, hash:${hash}`
+ return yo`[block:${block} txIndex:${i}] from:${from}, to:${to}, value:${typeConversion.hexToInt(val)} wei, ${logs} logs, data:${input}, 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(val)} wei`
- }
-}
-
-function value (v) {
- try {
- if (v instanceof Array) {
- var ret = []
- for (var k in v) {
- ret.push(value(v[k]))
- }
- return ret
- } else if (BN.isBN(v) || (v.constructor && v.constructor.name === 'BigNumber')) {
- return v.toString(10)
- } else if (v.indexOf && v.indexOf('0x') === 0) {
- return (new BN(v.replace('0x', ''), 16)).toString(10)
- } else if (typeof v === 'object') {
- var retObject = {}
- for (var i in v) {
- retObject[i] = value(v[i])
- }
- return retObject
- } else {
- return v
- }
- } catch (e) {
- console.log(e)
- return v
+ return yo`[block:${block} txIndex:${i}] from:${from}, to:${to}, value:${typeConversion.hexToInt(val)} wei`
}
}
@@ -383,7 +355,7 @@ function createTable (opts) {
var stringified = ' - '
if (opts.logs.decoded) {
- stringified = value(opts.logs.decoded)
+ stringified = typeConversion.stringify(opts.logs.decoded)
}
var logs = yo`
@@ -395,7 +367,7 @@ function createTable (opts) {
`
if (opts.logs) table.appendChild(logs)
- var val = value(opts.val)
+ var val = typeConversion.hexToInt(opts.val)
val = yo`
value
diff --git a/src/lib/typeConversion.js b/src/lib/typeConversion.js
new file mode 100644
index 0000000000..238beca3f0
--- /dev/null
+++ b/src/lib/typeConversion.js
@@ -0,0 +1,37 @@
+'use strict'
+var ethJSUtil = require('ethereumjs-util')
+var BN = ethJSUtil.BN
+
+module.exports = {
+ hexToInt: (h) => {
+ return (new BN(h.replace('0x', ''), 16)).toString(10)
+ },
+ stringify: stringify
+}
+
+function stringify (v) {
+ try {
+ if (v instanceof Array) {
+ var ret = []
+ for (var k in v) {
+ ret.push(stringify(v[k]))
+ }
+ return ret
+ } else if (BN.isBN(v) || (v.constructor && v.constructor.name === 'BigNumber')) {
+ return v.toString(10)
+ } else if (v._isBuffer) {
+ return ethJSUtil.bufferToHex(v)
+ } else if (typeof v === 'object') {
+ var retObject = {}
+ for (var i in v) {
+ retObject[i] = stringify(v[i])
+ }
+ return retObject
+ } else {
+ return v
+ }
+ } catch (e) {
+ console.log(e)
+ return v
+ }
+}