diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-05 21:29:29 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-05 21:29:29 +0800 |
commit | ee00769be171531db725288f8d485964941af529 (patch) | |
tree | e98d5c4cef11a67d7cb09f86051b8de9b7e243ca /src | |
parent | ec22097efb61d27aa73c979758bc0231cea7d61d (diff) | |
download | dexon-sol-tools-ee00769be171531db725288f8d485964941af529.tar dexon-sol-tools-ee00769be171531db725288f8d485964941af529.tar.gz dexon-sol-tools-ee00769be171531db725288f8d485964941af529.tar.bz2 dexon-sol-tools-ee00769be171531db725288f8d485964941af529.tar.lz dexon-sol-tools-ee00769be171531db725288f8d485964941af529.tar.xz dexon-sol-tools-ee00769be171531db725288f8d485964941af529.tar.zst dexon-sol-tools-ee00769be171531db725288f8d485964941af529.zip |
Use schema validation to distinguish txData argument
Diffstat (limited to 'src')
-rw-r--r-- | src/contract.ts | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/contract.ts b/src/contract.ts index 26da67b62..bd5afc16c 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -1,12 +1,14 @@ import * as Web3 from 'web3'; import * as _ from 'lodash'; import promisify = require('es6-promisify'); +import {SchemaValidator, schemas} from '0x-json-schemas'; export class Contract implements Web3.ContractInstance { public address: string; public abi: Web3.ContractAbi; private contract: Web3.ContractInstance; private defaults: Partial<Web3.TxData>; + private validator: SchemaValidator; // This class instance is going to be populated with functions and events depending on the ABI // and we don't know their types in advance [name: string]: any; @@ -17,6 +19,7 @@ export class Contract implements Web3.ContractInstance { this.defaults = defaults; this.populateEvents(); this.populateFunctions(); + this.validator = new SchemaValidator(); } private populateFunctions(): void { const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function'); @@ -47,7 +50,7 @@ export class Contract implements Web3.ContractInstance { const promise = new Promise((resolve, reject) => { const lastArg = args[args.length - 1]; let txData: Partial<Web3.TxData> = {}; - if (_.isObject(lastArg) && !_.isArray(lastArg) && !lastArg.isBigNumber) { + if (this.isTxData(lastArg)) { txData = args.pop(); } txData = { @@ -69,4 +72,8 @@ export class Contract implements Web3.ContractInstance { }; return promisifiedWithDefaultParams; } + private isTxData(lastArg: any): boolean { + const isValid = this.validator.isValid(lastArg, schemas.txDataSchema); + return isValid; + } } |