Fix gasPrice regression
This commit is contained in:
15
src/0x.ts
15
src/0x.ts
@@ -170,13 +170,16 @@ export class ZeroEx {
|
|||||||
// We re-assign the send method so that Web3@1.0 providers work with 0x.js
|
// We re-assign the send method so that Web3@1.0 providers work with 0x.js
|
||||||
(provider as any).sendAsync = (provider as any).send;
|
(provider as any).sendAsync = (provider as any).send;
|
||||||
}
|
}
|
||||||
this._web3Wrapper = new Web3Wrapper(provider);
|
|
||||||
const gasPrice = _.isUndefined(config) ? undefined : config.gasPrice;
|
const gasPrice = _.isUndefined(config) ? undefined : config.gasPrice;
|
||||||
this.token = new TokenWrapper(this._web3Wrapper, gasPrice);
|
const defaults = {
|
||||||
this.proxy = new TokenTransferProxyWrapper(this._web3Wrapper, gasPrice);
|
gasPrice,
|
||||||
this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token, gasPrice);
|
};
|
||||||
this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper, gasPrice);
|
this._web3Wrapper = new Web3Wrapper(provider, defaults);
|
||||||
this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token, gasPrice);
|
this.token = new TokenWrapper(this._web3Wrapper);
|
||||||
|
this.proxy = new TokenTransferProxyWrapper(this._web3Wrapper);
|
||||||
|
this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token);
|
||||||
|
this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper);
|
||||||
|
this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Sets a new web3 provider for 0x.js. Updating the provider will stop all
|
* Sets a new web3 provider for 0x.js. Updating the provider will stop all
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ export class Contract implements Web3.ContractInstance {
|
|||||||
public address: string;
|
public address: string;
|
||||||
public abi: Web3.ContractAbi;
|
public abi: Web3.ContractAbi;
|
||||||
private contract: Web3.ContractInstance;
|
private contract: Web3.ContractInstance;
|
||||||
|
private defaults: Partial<Web3.TxData>;
|
||||||
[name: string]: any;
|
[name: string]: any;
|
||||||
constructor(web3ContractInstance: Web3.ContractInstance) {
|
constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<Web3.TxData>) {
|
||||||
this.contract = web3ContractInstance;
|
this.contract = web3ContractInstance;
|
||||||
this.address = web3ContractInstance.address;
|
this.address = web3ContractInstance.address;
|
||||||
this.abi = web3ContractInstance.abi;
|
this.abi = web3ContractInstance.abi;
|
||||||
|
this.defaults = defaults;
|
||||||
this.populateEvents();
|
this.populateEvents();
|
||||||
this.populateFunctions();
|
this.populateFunctions();
|
||||||
}
|
}
|
||||||
@@ -18,11 +20,12 @@ export class Contract implements Web3.ContractInstance {
|
|||||||
const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function');
|
const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function');
|
||||||
_.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => {
|
_.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => {
|
||||||
const cbStyleFunction = this.contract[functionAbi.name];
|
const cbStyleFunction = this.contract[functionAbi.name];
|
||||||
this[functionAbi.name] = promisify(cbStyleFunction, this.contract);
|
|
||||||
if (functionAbi.constant) {
|
if (functionAbi.constant) {
|
||||||
|
this[functionAbi.name] = promisify(cbStyleFunction, this.contract);
|
||||||
const cbStyleCallFunction = this.contract[functionAbi.name].call;
|
const cbStyleCallFunction = this.contract[functionAbi.name].call;
|
||||||
this[functionAbi.name].call = promisify(cbStyleCallFunction, this.contract);
|
this[functionAbi.name].call = promisify(cbStyleCallFunction, this.contract);
|
||||||
} else {
|
} else {
|
||||||
|
this[functionAbi.name] = this.promisifyWithDefaultParams(cbStyleFunction);
|
||||||
const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas;
|
const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas;
|
||||||
this[functionAbi.name].estimateGas =
|
this[functionAbi.name].estimateGas =
|
||||||
promisify(cbStyleEstimateGasFunction, this.contract);
|
promisify(cbStyleEstimateGasFunction, this.contract);
|
||||||
@@ -35,4 +38,31 @@ export class Contract implements Web3.ContractInstance {
|
|||||||
this[eventAbi.name] = this.contract[eventAbi.name];
|
this[eventAbi.name] = this.contract[eventAbi.name];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
private promisifyWithDefaultParams(fn: (...args: any[]) => void): (...args: any[]) => Promise<any> {
|
||||||
|
const promisifiedWithDefaultParams = (...args: any[]) => {
|
||||||
|
const promise = new Promise((resolve, reject) => {
|
||||||
|
const lastArg = args[args.length - 1];
|
||||||
|
let txData: Partial<Web3.TxData> = {};
|
||||||
|
if (_.isObject(lastArg) && !_.isArray(lastArg) && !lastArg.isBigNumber) {
|
||||||
|
txData = args.pop();
|
||||||
|
}
|
||||||
|
txData = {
|
||||||
|
...txData,
|
||||||
|
...this.defaults,
|
||||||
|
};
|
||||||
|
const callback = (err: Error, data: any) => {
|
||||||
|
if (_.isNull(err)) {
|
||||||
|
resolve(data);
|
||||||
|
} else {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
args.push(txData);
|
||||||
|
args.push(callback);
|
||||||
|
fn.apply(this.contract, args);
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
|
};
|
||||||
|
return promisifiedWithDefaultParams;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,8 @@ import {utils} from '../utils/utils';
|
|||||||
|
|
||||||
export class ContractWrapper {
|
export class ContractWrapper {
|
||||||
protected _web3Wrapper: Web3Wrapper;
|
protected _web3Wrapper: Web3Wrapper;
|
||||||
private _gasPrice?: BigNumber.BigNumber;
|
constructor(web3Wrapper: Web3Wrapper) {
|
||||||
constructor(web3Wrapper: Web3Wrapper, gasPrice?: BigNumber.BigNumber) {
|
|
||||||
this._web3Wrapper = web3Wrapper;
|
this._web3Wrapper = web3Wrapper;
|
||||||
this._gasPrice = gasPrice;
|
|
||||||
}
|
}
|
||||||
protected async _instantiateContractIfExistsAsync<A extends Web3.ContractInstance>(artifact: Artifact,
|
protected async _instantiateContractIfExistsAsync<A extends Web3.ContractInstance>(artifact: Artifact,
|
||||||
address?: string): Promise<A> {
|
address?: string): Promise<A> {
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import * as EtherTokenArtifacts from '../artifacts/EtherToken.json';
|
|||||||
export class EtherTokenWrapper extends ContractWrapper {
|
export class EtherTokenWrapper extends ContractWrapper {
|
||||||
private _etherTokenContractIfExists?: EtherTokenContract;
|
private _etherTokenContractIfExists?: EtherTokenContract;
|
||||||
private _tokenWrapper: TokenWrapper;
|
private _tokenWrapper: TokenWrapper;
|
||||||
constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, gasPrice?: BigNumber.BigNumber) {
|
constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) {
|
||||||
super(web3Wrapper, gasPrice);
|
super(web3Wrapper);
|
||||||
this._tokenWrapper = tokenWrapper;
|
this._tokenWrapper = tokenWrapper;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
];
|
];
|
||||||
return [orderAddresses, orderValues];
|
return [orderAddresses, orderValues];
|
||||||
}
|
}
|
||||||
constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, gasPrice?: BigNumber.BigNumber) {
|
constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) {
|
||||||
super(web3Wrapper, gasPrice);
|
super(web3Wrapper);
|
||||||
this._tokenWrapper = tokenWrapper;
|
this._tokenWrapper = tokenWrapper;
|
||||||
this._orderValidationUtils = new OrderValidationUtils(tokenWrapper, this);
|
this._orderValidationUtils = new OrderValidationUtils(tokenWrapper, this);
|
||||||
this._exchangeLogEventEmitters = [];
|
this._exchangeLogEventEmitters = [];
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import * as TokenRegistryArtifacts from '../artifacts/TokenRegistry.json';
|
|||||||
*/
|
*/
|
||||||
export class TokenRegistryWrapper extends ContractWrapper {
|
export class TokenRegistryWrapper extends ContractWrapper {
|
||||||
private _tokenRegistryContractIfExists?: TokenRegistryContract;
|
private _tokenRegistryContractIfExists?: TokenRegistryContract;
|
||||||
constructor(web3Wrapper: Web3Wrapper, gasPrice?: BigNumber.BigNumber) {
|
constructor(web3Wrapper: Web3Wrapper) {
|
||||||
super(web3Wrapper, gasPrice);
|
super(web3Wrapper);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Retrieves all the tokens currently listed in the Token Registry smart contract
|
* Retrieves all the tokens currently listed in the Token Registry smart contract
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ export class TokenWrapper extends ContractWrapper {
|
|||||||
public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
|
public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
|
||||||
private _tokenContractsByAddress: {[address: string]: TokenContract};
|
private _tokenContractsByAddress: {[address: string]: TokenContract};
|
||||||
private _tokenLogEventEmitters: ContractEventEmitter[];
|
private _tokenLogEventEmitters: ContractEventEmitter[];
|
||||||
constructor(web3Wrapper: Web3Wrapper, gasPrice?: BigNumber.BigNumber) {
|
constructor(web3Wrapper: Web3Wrapper) {
|
||||||
super(web3Wrapper, gasPrice);
|
super(web3Wrapper);
|
||||||
this._tokenContractsByAddress = {};
|
this._tokenContractsByAddress = {};
|
||||||
this._tokenLogEventEmitters = [];
|
this._tokenLogEventEmitters = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ import {Contract} from './contract';
|
|||||||
|
|
||||||
export class Web3Wrapper {
|
export class Web3Wrapper {
|
||||||
private web3: Web3;
|
private web3: Web3;
|
||||||
|
private defaults: Partial<Web3.TxData>;
|
||||||
private networkIdIfExists?: number;
|
private networkIdIfExists?: number;
|
||||||
constructor(provider: Web3.Provider) {
|
constructor(provider: Web3.Provider, defaults: Partial<Web3.TxData>) {
|
||||||
this.web3 = new Web3();
|
this.web3 = new Web3();
|
||||||
this.web3.setProvider(provider);
|
this.web3.setProvider(provider);
|
||||||
|
this.defaults = defaults;
|
||||||
}
|
}
|
||||||
public setProvider(provider: Web3.Provider) {
|
public setProvider(provider: Web3.Provider) {
|
||||||
delete this.networkIdIfExists;
|
delete this.networkIdIfExists;
|
||||||
@@ -97,7 +99,7 @@ export class Web3Wrapper {
|
|||||||
}
|
}
|
||||||
private getContractInstance<A extends Web3.ContractInstance>(abi: Web3.ContractAbi, address: string): A {
|
private getContractInstance<A extends Web3.ContractInstance>(abi: Web3.ContractAbi, address: string): A {
|
||||||
const web3ContractInstance = this.web3.eth.contract(abi).at(address);
|
const web3ContractInstance = this.web3.eth.contract(abi).at(address);
|
||||||
const contractInstance = new Contract(web3ContractInstance) as any as A;
|
const contractInstance = new Contract(web3ContractInstance, this.defaults) as any as A;
|
||||||
return contractInstance;
|
return contractInstance;
|
||||||
}
|
}
|
||||||
private async getNetworkAsync(): Promise<number> {
|
private async getNetworkAsync(): Promise<number> {
|
||||||
|
|||||||
Reference in New Issue
Block a user