Add schema assertion checks for callData and txData
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user