Skip to content

Commit 68bb3c2

Browse files
author
gobitfly
committed
Added solidity function call identification and parameter extraction
1 parent faae73a commit 68bb3c2

File tree

4 files changed

+79
-3
lines changed

4 files changed

+79
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"body-parser": "~1.16.0",
1212
"cookie-parser": "~1.4.3",
1313
"debug": "~2.6.0",
14+
"ethereumjs-abi": "git+https://github.com/gobitfly/ethereumjs-abi.git",
1415
"ethereumjs-util": "^5.1.1",
1516
"express": "~4.14.1",
1617
"level": "^1.6.0",

public/stylesheets/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ pre {
1717
white-space: -pre-wrap; /* Opera 4-6 */
1818
white-space: -o-pre-wrap; /* Opera 7 */
1919
word-wrap: break-word; /* Internet Explorer 5.5+ */
20+
}
21+
22+
.parameter-cell {
23+
white-space: pre-wrap; /* Since CSS 2.1 */
24+
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
25+
white-space: -pre-wrap; /* Opera 4-6 */
26+
white-space: -o-pre-wrap; /* Opera 7 */
27+
word-wrap: break-word; /* Internet Explorer 5.5+ */
2028
}

routes/tx.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var router = express.Router();
33

44
var async = require('async');
55
var Web3 = require('web3');
6-
6+
var abi = require('ethereumjs-abi');
77

88

99
router.get('/pending', function(req, res, next) {
@@ -62,6 +62,8 @@ router.get('/:tx', function(req, res, next) {
6262
var web3 = new Web3();
6363
web3.setProvider(config.provider);
6464

65+
var db = req.app.get('db');
66+
6567
async.waterfall([
6668
function(callback) {
6769
web3.eth.getTransaction(req.params.tx, function(err, result) {
@@ -71,12 +73,52 @@ router.get('/:tx', function(req, res, next) {
7173
web3.trace.transaction(result.hash, function(err, traces) {
7274
callback(err, result, traces);
7375
});
76+
}, function(tx, traces, callback) {
77+
db.get(tx.to, function(err, value) {
78+
callback(null, tx, traces, value);
79+
});
7480
}
75-
], function(err, tx, traces) {
81+
], function(err, tx, traces, source) {
7682
if (err) {
7783
return next(err);
7884
}
79-
85+
86+
// Try to match the tx to a solidity function call if the contract source is available
87+
if (source) {
88+
tx.source = JSON.parse(source);
89+
var jsonAbi = JSON.parse(tx.source.abi);
90+
91+
var id = tx.input;
92+
if (id.length > 10) {
93+
id = id.substr(0, 10);
94+
}
95+
96+
jsonAbi.forEach(function(item) {
97+
if (item.type === "function" && !item.constant) {
98+
99+
var functionName = item.name;
100+
var functionParams = [];
101+
var functionParamsFull = [];
102+
item.inputs.forEach(function(input) {
103+
functionParams.push(input.type);
104+
});
105+
106+
var signature = "0x" + abi.methodID(functionName, functionParams).toString('hex')
107+
108+
if (signature === id) {
109+
var pl = tx.input.replace("0x", "");
110+
pl = pl.substr(8, pl.length - 8);
111+
var decoded = abi.rawDecode(functionParams, pl);
112+
113+
for(var i = 0; i < functionParams.length; i++) {
114+
item.inputs[i].result = decoded[i];
115+
}
116+
117+
tx.callInfo = item;
118+
}
119+
}
120+
});
121+
}
80122
tx.traces = [];
81123
tx.failed = false;
82124
tx.gasUsed = 0;

views/tx.pug

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ block content
4141
tr
4242
td Fee:
4343
td #{ethformatter(tx.gasUsed * tx.gasPrice)}
44+
if tx.callInfo
45+
tr
46+
td Function Name:
47+
td #{tx.callInfo.name}
48+
tr
49+
td Parameters:
50+
td
51+
table.table
52+
thead
53+
tr
54+
th Name
55+
th Type
56+
th Value
57+
tbody
58+
for pa in tx.callInfo.inputs
59+
tr
60+
td #{pa.name}
61+
td #{pa.type}
62+
if pa.type === "bytes"
63+
td
64+
pre 0x#{pa.result.toString("hex")}
65+
else if pa.type === "uint256"
66+
td.parameter-cell #{pa.result.toString(10)}
67+
else
68+
td.parameter-cell #{JSON.stringify(pa.result, null, 2)}
4469
tr
4570
td Data:
4671
td

0 commit comments

Comments
 (0)