From 6c6e03125417c46936e98b256e82e989f251c980 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Sun, 3 Jun 2018 17:10:48 -0400 Subject: [PATCH] Added parseTransaction to interface to detect and parse relevant function and args. --- contracts/interface.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/contracts/interface.js b/contracts/interface.js index b7755756..aa1969d4 100644 --- a/contracts/interface.js +++ b/contracts/interface.js @@ -391,4 +391,23 @@ function Interface(abi) { utils.defineProperty(this, 'deployFunction', deploy); } +utils.defineProperty(Interface.prototype, 'parseTransaction', function(tx) { + var sighash = tx.data.substring(0, 10).toLowerCase(); + for (var name in this.functions) { + if (name.indexOf('(') === -1) { continue; } + var func = this.functions[name]; + if (func.sighash === sighash) { + var result = utils.coder.decode(func.inputs.types, '0x' + tx.data.substring(10)); + return { + args: result, + signature: func.signature, + sighash: func.sighash, + parse: func.parseResult, + value: tx.value, + }; + } + } + return null; +}); + module.exports = Interface;