diff options
author | Fabio Berger <me@fabioberger.com> | 2018-07-05 18:35:16 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-07-05 18:35:16 +0800 |
commit | 1c9a657693f324fe9de15fc832398aca715e0727 (patch) | |
tree | 3fc277e4536850a3bea9f83822b33c3e81af9f1d /packages/web3-wrapper/src/web3_wrapper.ts | |
parent | 11747c6cf47a2f75d32953c84ccdf66f6f2f70a3 (diff) | |
download | dexon-0x-contracts-1c9a657693f324fe9de15fc832398aca715e0727.tar dexon-0x-contracts-1c9a657693f324fe9de15fc832398aca715e0727.tar.gz dexon-0x-contracts-1c9a657693f324fe9de15fc832398aca715e0727.tar.bz2 dexon-0x-contracts-1c9a657693f324fe9de15fc832398aca715e0727.tar.lz dexon-0x-contracts-1c9a657693f324fe9de15fc832398aca715e0727.tar.xz dexon-0x-contracts-1c9a657693f324fe9de15fc832398aca715e0727.tar.zst dexon-0x-contracts-1c9a657693f324fe9de15fc832398aca715e0727.zip |
Add schema assertion checks for callData and txData
Diffstat (limited to 'packages/web3-wrapper/src/web3_wrapper.ts')
-rw-r--r-- | packages/web3-wrapper/src/web3_wrapper.ts | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index 5dd1150d7..c21d66d0b 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -1,4 +1,5 @@ import { assert } from '@0xproject/assert'; +import { schemas } from '@0xproject/json-schemas'; import { AbiDecoder, addressUtils, BigNumber, intervalUtils, promisify } from '@0xproject/utils'; import { BlockParam, @@ -456,6 +457,7 @@ export class Web3Wrapper { * @returns Estimated gas cost */ public async estimateGasAsync(txData: Partial<TxData>): Promise<number> { + assert.doesConformToSchema('txData', txData, schemas.txDataSchema, [schemas.addressSchema, schemas.numberSchema, schemas.jsNumber]); const txDataHex = marshaller.marshalTxData(txData); const gasHex = await this._sendRawPayloadAsync<string>({ method: 'eth_estimateGas', params: [txDataHex] }); const gas = utils.convertHexToNumber(gasHex); @@ -468,6 +470,7 @@ export class Web3Wrapper { * @returns The raw call result */ public async callAsync(callData: CallData, defaultBlock?: BlockParam): Promise<string> { + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [schemas.addressSchema, schemas.numberSchema, schemas.jsNumber]); if (!_.isUndefined(defaultBlock)) { Web3Wrapper._assertBlockParam(defaultBlock); } @@ -488,9 +491,7 @@ export class Web3Wrapper { * @returns Transaction hash */ public async sendTransactionAsync(txData: TxData): Promise<string> { - if (_.isUndefined(txData.from)) { - throw new Error(`txData is missing required "from" address.`); - } + assert.doesConformToSchema('txData', txData, schemas.txDataSchema, [schemas.addressSchema, schemas.numberSchema, schemas.jsNumber]); const txDataHex = marshaller.marshalTxData(txData); const txHash = await this._sendRawPayloadAsync<string>({ method: 'eth_sendTransaction', params: [txDataHex] }); return txHash; |