diff --git a/README.md b/README.md index 4412672..56e7c64 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,10 @@ web3.eth.getTransactionReceipt("0x9199e262aaab0a6ec99558b3e9f42397c07a2bb9c6befb const decodedLogs = abiDecoder.decodeLogs(receipt.logs); }); ``` + +# PR applied +- Decode Logs function : Support tokenId with uint256 #88(https://github.com/Consensys/abi-decoder/pull/88) +- Fix for issue #52 #54(https://github.com/Consensys/abi-decoder/pull/54) +- fix can not decode struct tuple logs #62(https://github.com/Consensys/abi-decoder/pull/62) +- Upgrade deps web3-eth-abi to v1.8.0. #86(https://github.com/Consensys/abi-decoder/pull/86) +- Add support for tuple array #101(https://github.com/Consensys/abi-decoder/pull/101/files) \ No newline at end of file diff --git a/index.js b/index.js index 1c5e5d1..47b25b2 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,9 @@ function _getABIs() { } function _typeToString(input) { + if (input.type === "tuple[]") { + return "(" + input.components.map(_typeToString).join(",") + ")[]"; + } if (input.type === "tuple") { return "(" + input.components.map(_typeToString).join(",") + ")"; } @@ -71,11 +74,18 @@ function _removeABI(abiArray) { } } }); + + // Remove the ABI from state.savedABIs + state.savedABIs = state.savedABIs.filter((savedAbi) => { + return !abiArray.includes(savedAbi); + }); + } else { throw new Error("Expected ABI array, got " + typeof abiArray); } } + function _getMethodIDs() { return state.methodIDs; } @@ -113,7 +123,12 @@ function _decodeMethod(data) { const isArray = Array.isArray(param); if (isArray) { - parsedParam = param.map(_ => _.toLowerCase()); + //parsedParam = param.map(_ => _.toLowerCase()); + if (param[0].constructor === Array) { + parsedParam = eval(param.toString().toLowerCase()); + } else { + parsedParam = param.map(_ => _.toLowerCase()); + } } else { parsedParam = param.toLowerCase(); } @@ -143,7 +158,12 @@ function _decodeLogs(logs) { let dataTypes = []; method.inputs.map(function(input) { if (!input.indexed) { - dataTypes.push(input.type); + //dataTypes.push(input.type); + if(input.type === "tuple") { + dataTypes.push("tuple" + _typeToString(input) ); + } else { + dataTypes.push(input); + } } }); @@ -185,7 +205,7 @@ function _decodeLogs(logs) { ) { // ensure to remove leading 0x for hex numbers if (typeof decodedP.value === "string" && decodedP.value.startsWith("0x")) { - decodedP.value = new BN(decodedP.value.slice(2), 16).toString(10); + decodedP.value = new BN(decodedP.value, 16).toString(10); } else { decodedP.value = new BN(decodedP.value).toString(10); } diff --git a/package.json b/package.json index 48f5cd0..94aa36c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "abi-decoder", - "version": "2.3.0", + "name": "abi-decoder-ex", + "version": "2.3.4", "description": "Nodejs and Javascript library for decoding data params and events from ethereum transactions\"", "main": "index.js", "scripts": { @@ -10,7 +10,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/ConsenSys/abi-decoder.git" + "url": "git+https://github.com/eigenphi/abi-decoder" }, "keywords": [ "ethereum", @@ -20,11 +20,11 @@ "author": "denis@gnosis.pm", "license": "GPL-3.0", "bugs": { - "url": "https://github.com/ConsenSys/abi-decoder/issues" + "url": "https://github.com/eigenphi/abi-decoder/issues" }, - "homepage": "https://github.com/ConsenSys/abi-decoder#readme", + "homepage": "https://github.com/eigenphi/abi-decoder#readme", "dependencies": { - "web3-eth-abi": "^1.2.1", + "web3-eth-abi": "^1.8.0", "web3-utils": "^1.2.1" }, "devDependencies": {