diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-03-02 05:04:55 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-03-02 05:04:55 +0800 |
commit | 0c16f0ea221d65e66942c27a69dda1c54f49e775 (patch) | |
tree | 5530d18fcd6e6c5e15272de3cb915fc2025c01bf /packages/utils | |
parent | 003d43b03ae373ca24d6d728ffa6b0f2dfcda79a (diff) | |
parent | 451a0dacbe85d7a0d16ef007c1eb945a4c1977cb (diff) | |
download | dexon-sol-tools-0c16f0ea221d65e66942c27a69dda1c54f49e775.tar dexon-sol-tools-0c16f0ea221d65e66942c27a69dda1c54f49e775.tar.gz dexon-sol-tools-0c16f0ea221d65e66942c27a69dda1c54f49e775.tar.bz2 dexon-sol-tools-0c16f0ea221d65e66942c27a69dda1c54f49e775.tar.lz dexon-sol-tools-0c16f0ea221d65e66942c27a69dda1c54f49e775.tar.xz dexon-sol-tools-0c16f0ea221d65e66942c27a69dda1c54f49e775.tar.zst dexon-sol-tools-0c16f0ea221d65e66942c27a69dda1c54f49e775.zip |
Merge branch 'development' into feature/sra-reporter
* development: (71 commits)
Set max to 2 ETH/2 ZRX
Add missing types from website
Add dependencies
Update the README
Move BaseContract to its own package
Upgrate prettier
remove unused import
Move more configs into docsInfo and remove logic that does not belong there elsewhere
Fix a bug with displaying solidity functions returning multiple return values
Add ethers-contracts as a dependency
Include types for ethers-contracts
Fix the version
Include types for ethers-contracts
Rename idx to i
Remove tslint disable
Move BaseContract to web3Wrapper
Merge ifs
Fix an option description
Add link to the docs
Improve CHANGELOG entry
...
Diffstat (limited to 'packages/utils')
-rw-r--r-- | packages/utils/CHANGELOG.md | 4 | ||||
-rw-r--r-- | packages/utils/package.json | 4 | ||||
-rw-r--r-- | packages/utils/src/abi_decoder.ts | 27 | ||||
-rw-r--r-- | packages/utils/src/globals.d.ts | 3 | ||||
-rw-r--r-- | packages/utils/tsconfig.json | 6 |
5 files changed, 26 insertions, 18 deletions
diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md index 19ee80e4f..81792bee8 100644 --- a/packages/utils/CHANGELOG.md +++ b/packages/utils/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v0.4.0 - _TBD, 2018_ + + * Use `ethers-contracts` as a backend to decode event args (#413) + ## v0.3.2 - _February 9, 2018_ * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) diff --git a/packages/utils/package.json b/packages/utils/package.json index 750ecaa2f..4f63aa4ce 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -21,16 +21,18 @@ "homepage": "https://github.com/0xProject/0x.js/packages/utils/README.md", "devDependencies": { "@0xproject/tslint-config": "^0.4.9", - "@0xproject/types": "^0.2.3", "@types/lodash": "^4.14.86", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "tslint": "5.8.0", "typescript": "2.7.1", + "ethers-typescript-typings": "^0.0.1", "web3-typescript-typings": "^0.9.11" }, "dependencies": { + "@0xproject/types": "^0.2.3", "bignumber.js": "~4.1.0", + "ethers-contracts": "^2.2.1", "js-sha3": "^0.7.0", "lodash": "^4.17.4", "web3": "^0.20.0" diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index 368973b1b..2b496eb17 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -1,7 +1,7 @@ import { AbiType, DecodedLogArgs, LogWithDecodedArgs, RawLog, SolidityTypes } from '@0xproject/types'; +import * as ethersContracts from 'ethers-contracts'; import * as _ from 'lodash'; import * as Web3 from 'web3'; -import * as SolidityCoder from 'web3/lib/solidity/coder'; import { BigNumber } from './configured_bignumber'; @@ -27,31 +27,29 @@ export class AbiDecoder { if (_.isUndefined(event)) { return log; } + const ethersInterface = new ethersContracts.Interface([event]); const logData = log.data; const decodedParams: DecodedLogArgs = {}; - let dataIndex = 0; let topicsIndex = 1; const nonIndexedInputs = _.filter(event.inputs, input => !input.indexed); const dataTypes = _.map(nonIndexedInputs, input => input.type); - const decodedData = SolidityCoder.decodeParams(dataTypes, logData.slice('0x'.length)); + const decodedData = ethersInterface.events[event.name].parse(log.data); let failedToDecode = false; - _.forEach(event.inputs, (param: Web3.EventParameter) => { + _.forEach(event.inputs, (param: Web3.EventParameter, i: number) => { // Indexed parameters are stored in topics. Non-indexed ones in decodedData - let value: BigNumber | string = param.indexed ? log.topics[topicsIndex++] : decodedData[dataIndex++]; + let value: BigNumber | string | number = param.indexed ? log.topics[topicsIndex++] : decodedData[i]; if (_.isUndefined(value)) { failedToDecode = true; return; } if (param.type === SolidityTypes.Address) { value = AbiDecoder._padZeros(new BigNumber(value).toString(16)); - } else if ( - param.type === SolidityTypes.Uint256 || - param.type === SolidityTypes.Uint8 || - param.type === SolidityTypes.Uint - ) { + } else if (param.type === SolidityTypes.Uint256 || param.type === SolidityTypes.Uint) { value = new BigNumber(value); + } else if (param.type === SolidityTypes.Uint8) { + value = new BigNumber(value).toNumber(); } decodedParams[param.name] = value; }); @@ -67,11 +65,14 @@ export class AbiDecoder { } } private _addABI(abiArray: Web3.AbiDefinition[]): void { + if (_.isUndefined(abiArray)) { + return; + } + const ethersInterface = new ethersContracts.Interface(abiArray); _.map(abiArray, (abi: Web3.AbiDefinition) => { if (abi.type === AbiType.Event) { - const signature = `${abi.name}(${_.map(abi.inputs, input => input.type).join(',')})`; - const signatureHash = new Web3().sha3(signature); - this._methodIds[signatureHash] = abi; + const topic = ethersInterface.events[abi.name].topic; + this._methodIds[topic] = abi; } }); this._savedABIs = this._savedABIs.concat(abiArray); diff --git a/packages/utils/src/globals.d.ts b/packages/utils/src/globals.d.ts deleted file mode 100644 index ade9e59db..000000000 --- a/packages/utils/src/globals.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -declare module 'web3/lib/solidity/coder' { - const decodeParams: (types: string[], data: string) => any[]; -} diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json index 3d967d05f..8114d99cd 100644 --- a/packages/utils/tsconfig.json +++ b/packages/utils/tsconfig.json @@ -3,5 +3,9 @@ "compilerOptions": { "outDir": "lib" }, - "include": ["./src/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"] + "include": [ + "./src/**/*", + "../../node_modules/web3-typescript-typings/index.d.ts", + "../../node_modules/ethers-typescript-typings/index.d.ts" + ] } |