Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
3cce2a17
Commit
3cce2a17
authored
Jul 31, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add event decoder
parent
233c4171
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
16 deletions
+120
-16
app.js
src/app.js
+20
-8
eventsDecoder.js
src/app/listener/eventsDecoder.js
+81
-0
txListener.js
src/app/txListener.js
+19
-8
No files found.
src/app.js
View file @
3cce2a17
...
...
@@ -31,6 +31,7 @@ var RighthandPanel = require('./app/righthand-panel')
var
examples
=
require
(
'./app/example-contracts'
)
var
modalDialogCustom
=
require
(
'./app/modal-dialog-custom'
)
var
Txlistener
=
require
(
'./app/txListener'
)
var
EventsDecoder
=
require
(
'./app/listener/eventsDecoder'
)
var
css
=
csjs
`
html { box-sizing: border-box; }
...
...
@@ -748,18 +749,20 @@ function run () {
node
.
insertBefore
(
staticanalysis
.
render
(),
node
.
childNodes
[
0
])
// ----------------- Tx listener -----------------
// Commented for now. will be used later.
var
compiledContracts
=
function
()
{
if
(
compiler
.
lastCompilationResult
&&
compiler
.
lastCompilationResult
.
data
)
{
return
compiler
.
lastCompilationResult
.
data
.
contracts
}
return
null
}
var
txlistener
=
new
Txlistener
({
api
:
{
web3
:
function
()
{
return
executionContext
.
web3
()
},
isVM
:
function
()
{
return
executionContext
.
isVM
()
},
vm
:
function
()
{
return
executionContext
.
vm
()
},
contracts
:
function
()
{
if
(
compiler
.
lastCompilationResult
&&
compiler
.
lastCompilationResult
.
data
)
{
return
compiler
.
lastCompilationResult
.
data
.
contracts
}
return
null
},
contracts
:
compiledContracts
,
context
:
function
()
{
return
executionContext
.
getProvider
()
}
...
...
@@ -770,6 +773,14 @@ function run () {
}
})
var
eventsDecoder
=
new
EventsDecoder
({
txListener
:
txlistener
})
txlistener
.
event
.
register
(
'txResolved'
,
(
tx
,
resolvedData
)
=>
{
if
(
resolvedData
)
{
eventsDecoder
.
parseLogs
(
tx
,
resolvedData
,
compiledContracts
())
}
})
txlistener
.
startListening
()
txlistener
.
event
.
register
(
'newTransaction'
,
(
tx
)
=>
{
...
...
@@ -781,7 +792,8 @@ function run () {
console
.
log
({
tx
:
tx
,
resolvedContract
:
txlistener
.
resolvedContract
(
address
),
resolvedTransaction
:
resolvedTransaction
resolvedTransaction
:
resolvedTransaction
,
resolvedEvents
:
eventsDecoder
.
eventsOf
(
tx
.
hash
)
})
})
...
...
src/app/listener/eventsDecoder.js
0 → 100644
View file @
3cce2a17
'use strict'
var
$
=
require
(
'jquery'
)
var
ethJSABI
=
require
(
'ethereumjs-abi'
)
/**
* Register to txListener and extract events
*
*/
class
EventsDecoder
{
constructor
(
opt
=
{})
{
this
.
txListener
=
opt
.
txListener
this
.
resolvedEvents
=
{}
}
/**
* use Transaction Receipt to decode logs. assume that the transaction as already been resolved by txListener.
* logs are decoded only if the contract if known by remix.
*
* @param {Object} tx - transaction object
* @param {Function} cb - callback
*/
parseLogs
(
tx
,
resolvedData
,
compiledContracts
)
{
this
.
txListener
.
resolveTransactionReceipt
(
tx
,
(
error
,
receipt
)
=>
{
if
(
error
)
console
.
log
(
error
)
this
.
_decodeLogs
(
tx
,
receipt
,
resolvedData
.
contractName
,
compiledContracts
)
})
}
eventsOf
(
hash
)
{
return
this
.
resolvedEvents
[
hash
]
}
_decodeLogs
(
tx
,
receipt
,
contract
,
contracts
)
{
if
(
!
contract
||
!
receipt
.
logs
)
{
return
}
this
.
_decodeEvents
(
tx
,
receipt
.
logs
,
contract
,
contracts
)
}
_eventABI
(
contractName
,
compiledContracts
)
{
var
contractabi
=
JSON
.
parse
(
compiledContracts
[
contractName
].
interface
)
var
eventABI
=
{}
$
.
each
(
contractabi
,
function
(
i
,
funABI
)
{
if
(
funABI
.
type
!==
'event'
)
{
return
}
var
hash
=
ethJSABI
.
eventID
(
funABI
.
name
,
funABI
.
inputs
.
map
(
function
(
item
)
{
return
item
.
type
}))
eventABI
[
hash
.
toString
(
'hex'
)]
=
{
event
:
funABI
.
name
,
inputs
:
funABI
.
inputs
}
})
return
eventABI
}
_decodeEvents
(
tx
,
logs
,
contractName
,
compiledContracts
)
{
var
eventABI
=
this
.
_eventABI
(
contractName
,
compiledContracts
)
// FIXME: support indexed events
for
(
var
i
in
logs
)
{
// [address, topics, mem]
var
log
=
logs
[
i
]
var
event
var
decoded
try
{
var
abi
=
eventABI
[
log
.
topics
[
0
].
replace
(
'0x'
,
''
)]
event
=
abi
.
event
var
types
=
abi
.
inputs
.
map
(
function
(
item
)
{
return
item
.
type
})
decoded
=
ethJSABI
.
rawDecode
(
types
,
new
Buffer
(
log
.
data
.
replace
(
'0x'
,
''
),
'hex'
))
decoded
=
ethJSABI
.
stringify
(
types
,
decoded
)
}
catch
(
e
)
{
decoded
=
log
.
data
}
if
(
!
this
.
resolvedEvents
[
tx
.
hash
])
{
this
.
resolvedEvents
[
tx
.
hash
]
=
[]
}
this
.
resolvedEvents
[
tx
.
hash
].
push
({
event
:
event
,
args
:
decoded
})
}
}
}
module
.
exports
=
EventsDecoder
src/app/txListener.js
View file @
3cce2a17
...
...
@@ -22,6 +22,7 @@ class TxListener {
this
.
_web3VMProvider
.
setVM
(
opt
.
api
.
vm
())
this
.
_resolvedTransactions
=
{}
this
.
_resolvedContracts
=
{}
this
.
_transactionReceipts
=
{}
this
.
init
()
opt
.
event
.
executionContext
.
register
(
'contextChanged'
,
(
context
)
=>
{
if
(
this
.
loopId
)
{
...
...
@@ -124,8 +125,10 @@ class TxListener {
_resolve
(
block
,
callback
)
{
async
.
each
(
block
.
transactions
,
(
tx
,
cb
)
=>
{
this
.
_resolveTx
(
tx
,
()
=>
{
this
.
_resolveTx
(
tx
,
(
error
,
resolvedData
)
=>
{
if
(
error
)
cb
(
error
)
this
.
event
.
trigger
(
'newTransaction'
,
[
tx
])
if
(
resolvedData
)
this
.
event
.
trigger
(
'txResolved'
,
[
tx
,
resolvedData
])
cb
()
})
},
()
=>
{
...
...
@@ -144,14 +147,15 @@ class TxListener {
var
code
=
tx
.
input
contractName
=
this
.
_tryResolveContract
(
code
,
contracts
,
'bytecode'
)
if
(
contractName
)
{
this
.
_resolveCreationAddress
(
tx
,
(
error
,
address
)
=>
{
this
.
resolveTransactionReceipt
(
tx
,
(
error
,
receipt
)
=>
{
if
(
error
)
return
cb
(
error
)
var
address
=
receipt
.
contractAddress
this
.
_resolvedContracts
[
address
]
=
contractName
this
.
_resolveFunction
(
contractName
,
contracts
,
tx
,
true
)
var
fun
=
this
.
_resolveFunction
(
contractName
,
contracts
,
tx
,
true
)
if
(
this
.
_resolvedTransactions
[
tx
.
hash
])
{
this
.
_resolvedTransactions
[
tx
.
hash
].
contractAddress
=
address
}
return
cb
()
return
cb
(
null
,
{
to
:
null
,
contractName
:
contractName
,
function
:
fun
,
creationAddress
:
address
}
)
})
return
}
...
...
@@ -166,7 +170,8 @@ class TxListener {
var
contractName
=
this
.
_tryResolveContract
(
code
,
contracts
,
'runtimeBytecode'
)
if
(
contractName
)
{
this
.
_resolvedContracts
[
tx
.
to
]
=
contractName
this
.
_resolveFunction
(
contractName
,
contracts
,
tx
,
false
)
var
fun
=
this
.
_resolveFunction
(
contractName
,
contracts
,
tx
,
false
)
return
cb
(
null
,
{
to
:
tx
.
to
,
contractName
:
contractName
,
function
:
fun
})
}
}
return
cb
()
...
...
@@ -174,16 +179,21 @@ class TxListener {
return
}
if
(
contractName
)
{
this
.
_resolveFunction
(
contractName
,
contracts
,
tx
,
false
)
var
fun
=
this
.
_resolveFunction
(
contractName
,
contracts
,
tx
,
false
)
return
cb
(
null
,
{
to
:
tx
.
to
,
contractName
:
contractName
,
function
:
fun
})
}
return
cb
()
}
}
_resolveCreationAddress
(
tx
,
cb
)
{
resolveTransactionReceipt
(
tx
,
cb
)
{
if
(
this
.
_transactionReceipts
[
tx
.
hash
])
{
return
cb
(
null
,
this
.
_transactionReceipts
[
tx
.
hash
])
}
this
.
currentWeb3
().
eth
.
getTransactionReceipt
(
tx
.
hash
,
(
error
,
receipt
)
=>
{
if
(
!
error
)
{
cb
(
null
,
receipt
.
contractAddress
)
this
.
_transactionReceipts
[
tx
.
hash
]
=
receipt
cb
(
null
,
receipt
)
}
else
{
cb
(
error
)
}
...
...
@@ -222,6 +232,7 @@ class TxListener {
params
:
params
}
}
return
this
.
_resolvedTransactions
[
tx
.
hash
]
}
_tryResolveContract
(
codeToResolve
,
compiledContracts
,
type
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment