From 7d603b21430d09bf583f7f60cfb361dbe418e227 Mon Sep 17 00:00:00 2001 From: Ignacio Mazzara Date: Fri, 22 Feb 2019 21:08:31 -0300 Subject: [PATCH] feat: sanitize abi --- package-lock.json | 36 +++++++++++++++------ src/contracts/LANDRegistry.ts | 7 ++-- src/contracts/artifacts/LANDAuction.json | 2 +- src/contracts/artifacts/MortgageHelper.json | 2 +- src/ethereum/abi/Abi.ts | 22 +++++++++++++ 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4b45ff3..10ea0a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2171,17 +2171,10 @@ "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-1.4.2.tgz", "integrity": "sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=", "requires": { + "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#d84a96796079c8595a0c78accd1e7709f2277215", "ethereumjs-util": "^5.1.1" }, "dependencies": { - "ethereumjs-abi": { - "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#d84a96796079c8595a0c78accd1e7709f2277215", - "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git#d84a96796079c8595a0c78accd1e7709f2277215", - "requires": { - "bn.js": "^4.10.0", - "ethereumjs-util": "^5.0.0" - } - }, "ethereumjs-util": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", @@ -2312,6 +2305,30 @@ "resolved": "https://registry.npmjs.org/ethereum-common/-/ethereum-common-0.0.18.tgz", "integrity": "sha1-L9w1dvIykDNYl26znaeDIT/5Uj8=" }, + "ethereumjs-abi": { + "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#d84a96796079c8595a0c78accd1e7709f2277215", + "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git", + "requires": { + "bn.js": "^4.10.0", + "ethereumjs-util": "^5.0.0" + }, + "dependencies": { + "ethereumjs-util": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", + "integrity": "sha512-CJAKdI0wgMbQFLlLRtZKGcy/L6pzVRgelIZqRqNbuVFM3K9VEnyfbcvz0ncWMRNCe4kaHWjwRYQcYMucmwsnWA==", + "requires": { + "bn.js": "^4.11.0", + "create-hash": "^1.1.2", + "ethjs-util": "^0.1.3", + "keccak": "^1.0.2", + "rlp": "^2.0.0", + "safe-buffer": "^5.1.1", + "secp256k1": "^3.0.1" + } + } + } + }, "ethereumjs-account": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/ethereumjs-account/-/ethereumjs-account-2.0.5.tgz", @@ -5963,6 +5980,7 @@ "resolved": "https://registry.npmjs.org/web3/-/web3-0.20.7.tgz", "integrity": "sha512-VU6/DSUX93d1fCzBz7WP/SGCQizO1rKZi4Px9j/3yRyfssHyFcZamMw2/sj4E8TlfMXONvZLoforR8B4bRoyTQ==", "requires": { + "bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", "crypto-js": "^3.1.4", "utf8": "^2.1.1", "xhr2-cookies": "^1.1.0", @@ -5971,7 +5989,7 @@ "dependencies": { "bignumber.js": { "version": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", - "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934" + "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git" } } }, diff --git a/src/contracts/LANDRegistry.ts b/src/contracts/LANDRegistry.ts index 2aefd06..a775dd7 100644 --- a/src/contracts/LANDRegistry.ts +++ b/src/contracts/LANDRegistry.ts @@ -1,5 +1,5 @@ import * as CSV from 'comma-separated-values' -import { Contract } from '../ethereum' +import { Contract, Abi } from '../ethereum' import { fulfillContractMethods } from './verification' const { abi } = require('./artifacts/LANDRegistry.json') @@ -18,8 +18,9 @@ export class LANDRegistry extends Contract { static DataError = DataError constructor(address: string) { - super(address, abi) - fulfillContractMethods(this, abi) + const sanitizedABI = Abi.sanitize(abi) + super(address, sanitizedABI) + fulfillContractMethods(this, sanitizedABI) } static decodeLandData(data = '') { diff --git a/src/contracts/artifacts/LANDAuction.json b/src/contracts/artifacts/LANDAuction.json index 5b32528..698f880 100644 --- a/src/contracts/artifacts/LANDAuction.json +++ b/src/contracts/artifacts/LANDAuction.json @@ -861,4 +861,4 @@ "type": "function" } ] -} +} \ No newline at end of file diff --git a/src/contracts/artifacts/MortgageHelper.json b/src/contracts/artifacts/MortgageHelper.json index 23e4949..3f47af0 100644 --- a/src/contracts/artifacts/MortgageHelper.json +++ b/src/contracts/artifacts/MortgageHelper.json @@ -715,4 +715,4 @@ "type": "event" } ] -} +} \ No newline at end of file diff --git a/src/ethereum/abi/Abi.ts b/src/ethereum/abi/Abi.ts index 71e8978..922b498 100644 --- a/src/ethereum/abi/Abi.ts +++ b/src/ethereum/abi/Abi.ts @@ -43,6 +43,28 @@ const abi = { if (param) { return param.value } + }, + + /** + * Sanitize ABI. + * Web3 0.X.X has "owner" as a reserved word, so if one of the event parameters name is "owner" + * it will break. This method will change every "owner" to "_owner" + * @param {array} ABI + * @return {array} - Sanitized ABI + */ + sanitize(abi) { + return abi.map(prop => { + let inputs = prop.inputs + if (prop.name && prop.type === 'event') { + inputs = prop.inputs.map(input => { + if (input.name === 'owner') { + input.name = '_owner' + } + return input + }) + } + return { ...prop, inputs } + }) } }