aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--package.json2
-rw-r--r--src/contract.ts9
-rw-r--r--yarn.lock6
3 files changed, 12 insertions, 5 deletions
diff --git a/package.json b/package.json
index 2f4bf41ee..50f54e1c4 100644
--- a/package.json
+++ b/package.json
@@ -90,7 +90,7 @@
"webpack": "^3.1.0"
},
"dependencies": {
- "0x-json-schemas": "^0.4.0",
+ "0x-json-schemas": "^0.5.0",
"bignumber.js": "^4.0.2",
"compare-versions": "^3.0.1",
"es6-promisify": "^5.0.0",
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;
+ }
}
diff --git a/yarn.lock b/yarn.lock
index 30487b0af..949f0b5a0 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2,9 +2,9 @@
# yarn lockfile v1
-"0x-json-schemas@^0.4.0":
- version "0.4.0"
- resolved "https://registry.yarnpkg.com/0x-json-schemas/-/0x-json-schemas-0.4.0.tgz#93cfa771c6418b3ce67f97595beff3e4b67bc28b"
+"0x-json-schemas@^0.5.0":
+ version "0.5.0"
+ resolved "https://registry.yarnpkg.com/0x-json-schemas/-/0x-json-schemas-0.5.0.tgz#36b1315480deb01dc0363ada949640e26f24a1d2"
dependencies:
jsonschema "^1.2.0"