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
2245d6c9
Commit
2245d6c9
authored
Jul 27, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decodeParam in tx listener
parent
4bf2d990
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
3 deletions
+47
-3
txListener.js
src/app/txListener.js
+47
-3
No files found.
src/app/txListener.js
View file @
2245d6c9
'use strict'
var
async
=
require
(
'async'
)
var
ethJSABI
=
require
(
'ethereumjs-abi'
)
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
EventManager
=
require
(
'ethereum-remix'
).
lib
.
EventManager
var
remix
=
require
(
'ethereum-remix'
)
var
codeUtil
=
remix
.
util
.
code
...
...
@@ -189,13 +191,17 @@ class TxListener {
}
_resolveFunction
(
contractName
,
compiledContracts
,
tx
,
isCtor
)
{
var
abi
=
JSON
.
parse
(
compiledContracts
[
contractName
].
interface
)
var
inputData
=
tx
.
input
.
replace
(
'0x'
,
''
)
if
(
!
isCtor
)
{
for
(
var
fn
in
compiledContracts
[
contractName
].
functionHashes
)
{
if
(
compiledContracts
[
contractName
].
functionHashes
[
fn
]
===
tx
.
input
.
replace
(
'0x'
,
''
)
.
substring
(
0
,
8
))
{
if
(
compiledContracts
[
contractName
].
functionHashes
[
fn
]
===
inputData
.
substring
(
0
,
8
))
{
this
.
_resolvedTransactions
[
tx
.
hash
]
=
{
to
:
tx
.
to
,
fn
:
fn
,
params
:
null
params
:
this
.
_decodeInputParams
(
inputData
.
substring
(
8
),
getFunction
(
abi
,
fn
))
}
return
}
}
// fallback function
...
...
@@ -205,10 +211,15 @@ class TxListener {
params
:
null
}
}
else
{
var
bytecode
=
compiledContracts
[
contractName
].
bytecode
var
params
=
null
if
(
bytecode
&&
bytecode
.
length
)
{
params
=
this
.
_decodeInputParams
(
inputData
.
substring
(
bytecode
.
length
),
getConstructorInterface
(
abi
))
}
this
.
_resolvedTransactions
[
tx
.
hash
]
=
{
to
:
null
,
fn
:
'(constructor)'
,
params
:
null
params
:
params
}
}
}
...
...
@@ -221,6 +232,39 @@ class TxListener {
}
return
null
}
_decodeInputParams
(
data
,
abi
)
{
data
=
ethJSUtil
.
toBuffer
(
'0x'
+
data
)
var
inputTypes
=
[]
for
(
var
i
=
0
;
i
<
abi
.
inputs
.
length
;
i
++
)
{
inputTypes
.
push
(
abi
.
inputs
[
i
].
type
)
}
return
ethJSABI
.
rawDecode
(
inputTypes
,
data
)
}
}
// those function will be duplicate after the merged of the compile and run tabs split
function
getConstructorInterface
(
abi
)
{
var
funABI
=
{
'name'
:
''
,
'inputs'
:
[],
'type'
:
'constructor'
,
'outputs'
:
[]
}
for
(
var
i
=
0
;
i
<
abi
.
length
;
i
++
)
{
if
(
abi
[
i
].
type
===
'constructor'
)
{
funABI
.
inputs
=
abi
[
i
].
inputs
||
[]
break
}
}
return
funABI
}
function
getFunction
(
abi
,
fnName
)
{
fnName
=
fnName
.
split
(
'('
)[
0
]
for
(
var
i
=
0
;
i
<
abi
.
length
;
i
++
)
{
if
(
abi
[
i
].
name
===
fnName
)
{
return
abi
[
i
]
}
}
return
null
}
module
.
exports
=
TxListener
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