@ -13,6 +13,7 @@ var helper = require('../../lib/helper')
var ethJSUtil = require ( 'ethereumjs-util' )
var BN = ethJSUtil . BN
var executionContext = require ( '../../execution-context' )
var modalDialog = require ( '../ui/modal-dialog-custom' )
var css = csjs `
. log {
@ -74,7 +75,12 @@ class TxLogger {
this . opts = opts
this . logKnownTX = opts . api . editorpanel . registerCommand ( 'knownTransaction' , ( args , cmds , append ) => {
var data = args [ 0 ]
var el = renderKnownTransaction ( this , data )
var el
if ( data . tx . isCall ) {
el = renderCall ( this , data )
} else {
el = renderKnownTransaction ( this , data )
}
append ( el )
} , { activate : true } )
@ -115,6 +121,10 @@ class TxLogger {
opts . events . txListener . register ( 'newTransaction' , ( tx ) => {
log ( this , tx , opts . api )
} )
opts . events . txListener . register ( 'newCall' , ( tx ) => {
log ( this , tx , opts . api )
} )
}
}
@ -139,7 +149,7 @@ function renderKnownTransaction (self, data) {
self . event . trigger ( 'debugRequested' , [ data . tx . hash ] )
}
var tx = yo `
< span class = $ { css . container } id = "tx${data.tx.hash}" >
< span id = "tx${data.tx.hash}" >
< div class = "${css.log}" >
$ { context ( self , { from , to , data } ) }
< div class = $ { css . buttons } >
@ -165,7 +175,7 @@ function renderKnownTransaction (self, data) {
input : data . tx . input ,
'decoded input' : data . resolvedData && data . resolvedData . params ? JSON . stringify ( value ( data . resolvedData . params ) , null , '\t' ) : ' - ' ,
'decoded output' : data . resolvedData && data . resolvedData . decodedReturnValue ? JSON . stringify ( value ( data . resolvedData . decodedReturnValue ) , null , '\t' ) : ' - ' ,
logs : JSON . stringify ( data . logs , null , '\t' ) || '0' ,
logs : data . logs ,
val : data . tx . value
} )
tx . appendChild ( table )
@ -175,6 +185,31 @@ function renderKnownTransaction (self, data) {
return tx
}
function renderCall ( self , data ) {
function debug ( ) {
if ( data . tx . envMode === 'vm' ) {
self . event . trigger ( 'debugRequested' , [ data . tx . hash ] )
} else {
modalDialog . alert ( 'Cannot debug this call. Debugging calls is only possible in JavaScript VM mode.' )
}
}
var to = data . resolvedData . contractName + '.' + data . resolvedData . fn + ' ' + helper . shortenHexData ( data . tx . to )
var from = data . tx . from ? data . tx . from : ' - '
var input = data . tx . input ? helper . shortenHexData ( data . tx . input ) : ''
var tx = yo `
< span id = "tx${data.tx.hash}" >
< div class = "${css.log}" >
< span > < span class = $ { css . tx } > [ call ] < / s p a n > f r o m : $ { f r o m } , t o : $ { t o } , d a t a : $ { i n p u t } , r e t u r n : < / s p a n >
< div class = $ { css . buttons } >
< button class = $ { css . debug } onclick = $ { debug } > Debug < / b u t t o n >
< / d i v >
< / d i v >
< div > $ { JSON . stringify ( value ( data . resolvedData . decodedReturnValue ) , null , '\t' ) } < / d i v >
< / s p a n >
`
return tx
}
function renderUnknownTransaction ( self , data ) {
var from = data . tx . from
var to = data . tx . to
@ -182,7 +217,7 @@ function renderUnknownTransaction (self, data) {
self . event . trigger ( 'debugRequested' , [ data . tx . hash ] )
}
var tx = yo `
< span class = $ { css . container } id = "tx${data.tx.hash}" >
< span id = "tx${data.tx.hash}" >
< div class = "${css.log}" >
$ { context ( self , { from , to , data } ) }
< div class = $ { css . buttons } >
@ -205,7 +240,7 @@ function renderUnknownTransaction (self, data) {
input : data . tx . input ,
hash : data . tx . hash ,
gas : data . tx . gas ,
logs : JSON . stringify ( data . logs ) || '0'
logs : data . logs
} )
tx . appendChild ( table )
}
@ -225,13 +260,13 @@ function context (self, opts) {
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 . length : 0
var logs = data . logs && data . logs . decoded ? data . logs . decoded . length : 0
var block = data . tx . blockNumber || ''
var i = data . tx . transactionIndex
if ( executionContext . getProvider ( ) === 'vm' ) {
return yo ` <span><span class= ${ css . tx } >[vm]</span> from: ${ from } , to: ${ to } , value: ${ value ( val ) } wei, data: ${ input } , ${ logs } logs, hash: ${ hash } </span> `
} else if ( executionContext . getProvider ( ) !== 'vm' && data . resolvedData ) {
return yo ` <span><span class=' ${ css . tx } '>[block: ${ block } txIndex: ${ i } ]</span> from: ${ from } , to: ${ to } , value: ${ value ( val ) } wei</span> `
return yo ` <span><span class=' ${ css . tx } '>[block: ${ block } txIndex: ${ i } ]</span> from: ${ from } , to: ${ to } , value: ${ value ( val ) } wei, ${ logs } logs, data: ${ input } , hash: ${ hash } </span> `
} else {
to = helper . shortenHexData ( to )
hash = helper . shortenHexData ( data . tx . blockHash )
@ -247,7 +282,7 @@ function value (v) {
ret . push ( value ( v [ k ] ) )
}
return ret
} else if ( BN . isBN ( v ) ) {
} 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 )
@ -349,7 +384,9 @@ function createTable (opts) {
var logs = yo `
< tr class = "${css.tr}" >
< td class = "${css.td}" > logs < / t d >
< td class = "${css.td}" > < i class = "fa fa-clipboard ${css.clipboardCopy}" aria - hidden = "true" onclick = $ { function ( ) { copy ( opts . logs || '0' ) } } title = 'Copy to clipboard' > < / i > $ { o p t s . l o g s | | ' 0 ' } < / t d >
< td class = "${css.td}" >
< i class = "fa fa-clipboard ${css.clipboardCopy}" aria - hidden = "true" onclick = $ { function ( ) { copy ( JSON . stringify ( opts . logs . decoded || [ ] , null , '\t' ) ) } } title = 'Copy Logs to clipboard' > < / i >
< i class = "fa fa-clipboard ${css.clipboardCopy}" aria - hidden = "true" onclick = $ { function ( ) { copy ( JSON . stringify ( opts . logs . raw || '0' ) ) } } title = 'Copy Raw Logs to clipboard' > < / i > $ { J S O N . s t r i n g i f y ( o p t s . l o g s . d e c o d e d | | [ ] , n u l l , ' \ t ' ) } < / t d >
< / t r c l a s s = " $ { c s s . t r } " >
`
if ( opts . logs ) table . appendChild ( logs )