Verify ZeroExConfig

This commit is contained in:
Leonid Logvinov
2017-09-19 14:13:06 +02:00
parent 4aeb6226d5
commit 903e2f4f8a
2 changed files with 14 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ import {
TransactionReceiptWithDecodedLogs,
LogWithDecodedArgs,
} from './types';
import {zeroExConfigSchema} from './schemas/zero_ex_config_schema';
// Customize our BigNumber instances
bigNumberConfigs.configure();
@@ -180,6 +181,9 @@ export class ZeroEx {
*/
constructor(provider: Web3Provider, config?: ZeroExConfig) {
assert.isWeb3Provider('provider', provider);
if (!_.isUndefined(config)) {
assert.doesConformToSchema('config', config, zeroExConfigSchema);
}
if (_.isUndefined((provider as any).sendAsync)) {
// Web3@1.0 provider doesn't support synchronous http requests,
// so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x`

View File

@@ -0,0 +1,10 @@
export const zeroExConfigSchema = {
id: '/ZeroExConfig',
properties: {
gasPrice: {$ref: '/Number'},
exchangeContractAddress: {$ref: '/Address'},
tokenRegistryContractAddress: {$ref: '/Address'},
etherTokenContractAddress: {$ref: '/Address'},
},
type: 'object',
};