diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-10 21:36:52 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-10 21:36:52 +0800 |
commit | d727bed6ab6fef90717a45845c544b409657e3c2 (patch) | |
tree | 9a232b7764d80726acf5f4dd91d19c0c06ae0439 /src | |
parent | 8b9d8ad1b625967fe264fe87e617af1089e1d0e9 (diff) | |
download | dexon-0x-contracts-d727bed6ab6fef90717a45845c544b409657e3c2.tar dexon-0x-contracts-d727bed6ab6fef90717a45845c544b409657e3c2.tar.gz dexon-0x-contracts-d727bed6ab6fef90717a45845c544b409657e3c2.tar.bz2 dexon-0x-contracts-d727bed6ab6fef90717a45845c544b409657e3c2.tar.lz dexon-0x-contracts-d727bed6ab6fef90717a45845c544b409657e3c2.tar.xz dexon-0x-contracts-d727bed6ab6fef90717a45845c544b409657e3c2.tar.zst dexon-0x-contracts-d727bed6ab6fef90717a45845c544b409657e3c2.zip |
Prefix private vars with _
Diffstat (limited to 'src')
-rw-r--r-- | src/0x.js.ts | 26 | ||||
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 2 | ||||
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 183 | ||||
-rw-r--r-- | src/contract_wrappers/token_registry_wrapper.ts | 18 | ||||
-rw-r--r-- | src/contract_wrappers/token_wrapper.ts | 30 |
5 files changed, 130 insertions, 129 deletions
diff --git a/src/0x.js.ts b/src/0x.js.ts index b1e4e25ff..3a149ae6e 100644 --- a/src/0x.js.ts +++ b/src/0x.js.ts @@ -33,7 +33,7 @@ export class ZeroEx { public exchange: ExchangeWrapper; public tokenRegistry: TokenRegistryWrapper; public token: TokenWrapper; - private web3Wrapper: Web3Wrapper; + private _web3Wrapper: Web3Wrapper; /** * Verifies that the elliptic curve signature `signature` was generated * by signing `dataHex` with the private key corresponding to the `signerAddressHex` address. @@ -128,10 +128,10 @@ export class ZeroEx { * @return An instance of the 0x.js ZeroEx class. */ constructor(web3: Web3) { - this.web3Wrapper = new Web3Wrapper(web3); - this.token = new TokenWrapper(this.web3Wrapper); - this.exchange = new ExchangeWrapper(this.web3Wrapper, this.token); - this.tokenRegistry = new TokenRegistryWrapper(this.web3Wrapper); + this._web3Wrapper = new Web3Wrapper(web3); + this.token = new TokenWrapper(this._web3Wrapper); + this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token); + this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper); } /** * Sets a new provider for the web3 instance used by 0x.js. Updating the provider will stop all @@ -139,7 +139,7 @@ export class ZeroEx { * @param provider The Web3.Provider you would like the 0x.js library to use from now on. */ public async setProviderAsync(provider: Web3.Provider) { - this.web3Wrapper.setProvider(provider); + this._web3Wrapper.setProvider(provider); await this.exchange.invalidateContractInstanceAsync(); this.tokenRegistry.invalidateContractInstance(); this.token.invalidateContractInstances(); @@ -149,7 +149,7 @@ export class ZeroEx { * @return An array of Ethereum addresses available. */ public async getAvailableAddressesAsync(): Promise<string[]> { - const availableAddresses = await this.web3Wrapper.getAvailableAddressesAsync(); + const availableAddresses = await this._web3Wrapper.getAvailableAddressesAsync(); return availableAddresses; } /** @@ -160,7 +160,7 @@ export class ZeroEx { public async getOrderHashHexAsync(order: Order|SignedOrder): Promise<string> { assert.doesConformToSchema('order', order, orderSchema); - const exchangeContractAddr = await this.getExchangeAddressAsync(); + const exchangeContractAddr = await this._getExchangeAddressAsync(); const orderHashHex = utils.getOrderHashHex(order, exchangeContractAddr); return orderHashHex; } @@ -174,10 +174,10 @@ export class ZeroEx { */ public async signOrderHashAsync(orderHashHex: string, signerAddress: string): Promise<ECSignature> { assert.isHexString('orderHashHex', orderHashHex); - await assert.isSenderAddressAsync('signerAddress', signerAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('signerAddress', signerAddress, this._web3Wrapper); let msgHashHex; - const nodeVersion = await this.web3Wrapper.getNodeVersionAsync(); + const nodeVersion = await this._web3Wrapper.getNodeVersionAsync(); const isParityNode = utils.isParityNode(nodeVersion); if (isParityNode) { // Parity node adds the personalMessage prefix itself @@ -188,7 +188,7 @@ export class ZeroEx { msgHashHex = ethUtil.bufferToHex(msgHashBuff); } - const signature = await this.web3Wrapper.signTransactionAsync(signerAddress, msgHashHex); + const signature = await this._web3Wrapper.signTransactionAsync(signerAddress, msgHashHex); let signatureData; const [nodeVersionNumber] = findVersions(nodeVersion); @@ -224,8 +224,8 @@ export class ZeroEx { } return ecSignature; } - private async getExchangeAddressAsync() { - const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); + private async _getExchangeAddressAsync() { + const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const exchangeNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : (ExchangeArtifacts as any).networks[networkIdIfExists]; diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index c3067f613..99cfd97f0 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -9,7 +9,7 @@ export class ContractWrapper { constructor(web3Wrapper: Web3Wrapper) { this.web3Wrapper = web3Wrapper; } - protected async instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise<ContractInstance> { + protected async _instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise<ContractInstance> { const c = await contract(artifact); const providerObj = this.web3Wrapper.getCurrentProvider(); c.setProvider(providerObj); diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 76f86e464..d546a6102 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -37,7 +37,7 @@ import {constants} from '../utils/constants'; import {TokenWrapper} from './token_wrapper'; export class ExchangeWrapper extends ContractWrapper { - private exchangeContractErrCodesToMsg = { + private _exchangeContractErrCodesToMsg = { [ExchangeContractErrCodes.ERROR_FILL_EXPIRED]: ExchangeContractErrs.ORDER_FILL_EXPIRED, [ExchangeContractErrCodes.ERROR_CANCEL_EXPIRED]: ExchangeContractErrs.ORDER_FILL_EXPIRED, [ExchangeContractErrCodes.ERROR_FILL_NO_VALUE]: ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO, @@ -45,10 +45,10 @@ export class ExchangeWrapper extends ContractWrapper { [ExchangeContractErrCodes.ERROR_FILL_TRUNCATION]: ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR, [ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.FILL_BALANCE_ALLOWANCE_ERROR, }; - private exchangeContractIfExists?: ExchangeContract; - private exchangeLogEventObjs: ContractEventObj[]; - private tokenWrapper: TokenWrapper; - private static getOrderAddressesAndValues(order: Order): [OrderAddresses, OrderValues] { + private _exchangeContractIfExists?: ExchangeContract; + private _exchangeLogEventObjs: ContractEventObj[]; + private _tokenWrapper: TokenWrapper; + private static _getOrderAddressesAndValues(order: Order): [OrderAddresses, OrderValues] { const orderAddresses: OrderAddresses = [ order.maker, order.taker, @@ -68,12 +68,12 @@ export class ExchangeWrapper extends ContractWrapper { } constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) { super(web3Wrapper); - this.tokenWrapper = tokenWrapper; - this.exchangeLogEventObjs = []; + this._tokenWrapper = tokenWrapper; + this._exchangeLogEventObjs = []; } public async invalidateContractInstanceAsync(): Promise<void> { - await this.stopWatchingExchangeLogEventsAsync(); - delete this.exchangeContractIfExists; + await this._stopWatchingExchangeLogEventsAsync(); + delete this._exchangeContractIfExists; } /** * Returns the unavailable takerAmount of an order. Unavailable amount is defined as the total @@ -86,7 +86,7 @@ export class ExchangeWrapper extends ContractWrapper { public async getUnavailableTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> { assert.isValidOrderHash('orderHashHex', orderHashHex); - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHashHex); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber unavailableAmountInBaseUnits = new BigNumber(unavailableAmountInBaseUnits); @@ -100,7 +100,7 @@ export class ExchangeWrapper extends ContractWrapper { public async getFilledTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> { assert.isValidOrderHash('orderHashHex', orderHashHex); - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let fillAmountInBaseUnits = await exchangeContract.filled.call(orderHashHex); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber fillAmountInBaseUnits = new BigNumber(fillAmountInBaseUnits); @@ -115,7 +115,7 @@ export class ExchangeWrapper extends ContractWrapper { public async getCanceledTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> { assert.isValidOrderHash('orderHashHex', orderHashHex); - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHashHex); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber cancelledAmountInBaseUnits = new BigNumber(cancelledAmountInBaseUnits); @@ -142,10 +142,10 @@ export class ExchangeWrapper extends ContractWrapper { assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer); await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); - const exchangeInstance = await this.getExchangeContractAsync(); - await this.validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); + const exchangeInstance = await this._getExchangeContractAsync(); + await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); - const [orderAddresses, orderValues] = ExchangeWrapper.getOrderAddressesAndValues(signedOrder); + const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder); const gas = await exchangeInstance.fill.estimateGas( orderAddresses, @@ -172,7 +172,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Sequentially and atomically fills signedOrders up to the specified takerTokenFillAmount. @@ -198,7 +198,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesConformToSchema('signedOrders', signedOrders, signedOrdersSchema); await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); for (const signedOrder of signedOrders) { - await this.validateFillOrderAndThrowIfInvalidAsync( + await this._validateFillOrderAndThrowIfInvalidAsync( signedOrder, takerTokenFillAmount, takerAddress); } if (_.isEmpty(signedOrders)) { @@ -207,7 +207,7 @@ export class ExchangeWrapper extends ContractWrapper { const orderAddressesValuesAndSignatureArray = _.map(signedOrders, signedOrder => { return [ - ...ExchangeWrapper.getOrderAddressesAndValues(signedOrder), + ...ExchangeWrapper._getOrderAddressesAndValues(signedOrder), signedOrder.ecSignature.v, signedOrder.ecSignature.r, signedOrder.ecSignature.s, @@ -218,7 +218,7 @@ export class ExchangeWrapper extends ContractWrapper { orderAddressesValuesAndSignatureArray, ); - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); const gas = await exchangeInstance.fillUpTo.estimateGas( orderAddressesArray, orderValuesArray, @@ -244,7 +244,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Batch version of fillOrderAsync. @@ -265,7 +265,7 @@ export class ExchangeWrapper extends ContractWrapper { await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); assert.doesConformToSchema('orderFillRequests', orderFillRequests, orderFillRequestsSchema); for (const orderFillRequest of orderFillRequests) { - await this.validateFillOrderAndThrowIfInvalidAsync( + await this._validateFillOrderAndThrowIfInvalidAsync( orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount, takerAddress); } if (_.isEmpty(orderFillRequests)) { @@ -274,7 +274,7 @@ export class ExchangeWrapper extends ContractWrapper { const orderAddressesValuesAmountsAndSignatureArray = _.map(orderFillRequests, orderFillRequest => { return [ - ...ExchangeWrapper.getOrderAddressesAndValues(orderFillRequest.signedOrder), + ...ExchangeWrapper._getOrderAddressesAndValues(orderFillRequest.signedOrder), orderFillRequest.takerTokenFillAmount, orderFillRequest.signedOrder.ecSignature.v, orderFillRequest.signedOrder.ecSignature.r, @@ -286,7 +286,7 @@ export class ExchangeWrapper extends ContractWrapper { orderAddressesValuesAmountsAndSignatureArray, ); - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); const gas = await exchangeInstance.batchFill.estimateGas( orderAddressesArray, orderValuesArray, @@ -312,7 +312,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Attempts to fill a specific amount of an order. If the entire amount specified cannot be filled, @@ -329,13 +329,13 @@ export class ExchangeWrapper extends ContractWrapper { assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount); await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); - const exchangeInstance = await this.getExchangeContractAsync(); - await this.validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); + const exchangeInstance = await this._getExchangeContractAsync(); + await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); - await this.validateFillOrKillOrderAndThrowIfInvalidAsync(signedOrder, exchangeInstance.address, + await this._validateFillOrKillOrderAndThrowIfInvalidAsync(signedOrder, exchangeInstance.address, takerTokenFillAmount); - const [orderAddresses, orderValues] = ExchangeWrapper.getOrderAddressesAndValues(signedOrder); + const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder); const gas = await exchangeInstance.fillOrKill.estimateGas( orderAddresses, @@ -360,7 +360,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Batch version of fillOrKill. Allows a taker to specify a batch of orders that will either be atomically @@ -373,15 +373,15 @@ export class ExchangeWrapper extends ContractWrapper { takerAddress: string): Promise<void> { await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); assert.doesConformToSchema('orderFillOrKillRequests', orderFillOrKillRequests, orderFillOrKillRequestsSchema); - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); for (const request of orderFillOrKillRequests) { - await this.validateFillOrKillOrderAndThrowIfInvalidAsync(request.signedOrder, exchangeInstance.address, + await this._validateFillOrKillOrderAndThrowIfInvalidAsync(request.signedOrder, exchangeInstance.address, request.fillTakerAmount); } const orderAddressesValuesAndTakerTokenFillAmounts = _.map(orderFillOrKillRequests, request => { return [ - ...ExchangeWrapper.getOrderAddressesAndValues(request.signedOrder), + ...ExchangeWrapper._getOrderAddressesAndValues(request.signedOrder), request.fillTakerAmount, request.signedOrder.ecSignature.v, request.signedOrder.ecSignature.r, @@ -416,7 +416,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Cancel a given fill amount of an order. Cancellations are cumulative. @@ -430,10 +430,10 @@ export class ExchangeWrapper extends ContractWrapper { assert.isBigNumber('takerTokenCancelAmount', takerTokenCancelAmount); await assert.isSenderAddressAsync('order.maker', order.maker, this.web3Wrapper); - const exchangeInstance = await this.getExchangeContractAsync(); - await this.validateCancelOrderAndThrowIfInvalidAsync(order, takerTokenCancelAmount); + const exchangeInstance = await this._getExchangeContractAsync(); + await this._validateCancelOrderAndThrowIfInvalidAsync(order, takerTokenCancelAmount); - const [orderAddresses, orderValues] = ExchangeWrapper.getOrderAddressesAndValues(order); + const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order); const gas = await exchangeInstance.cancel.estimateGas( orderAddresses, orderValues, @@ -451,7 +451,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Batch version of cancelOrderAsync. Atomically cancels multiple orders in a single transaction. @@ -467,17 +467,17 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesConformToSchema('orderCancellationRequests', orderCancellationRequests, orderCancellationRequestsSchema); for (const cancellationRequest of orderCancellationRequests) { - await this.validateCancelOrderAndThrowIfInvalidAsync( + await this._validateCancelOrderAndThrowIfInvalidAsync( cancellationRequest.order, cancellationRequest.takerTokenCancelAmount, ); } if (_.isEmpty(orderCancellationRequests)) { return; // no-op } - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); const orderAddressesValuesAndTakerTokenCancelAmounts = _.map(orderCancellationRequests, cancellationRequest => { return [ - ...ExchangeWrapper.getOrderAddressesAndValues(cancellationRequest.order), + ...ExchangeWrapper._getOrderAddressesAndValues(cancellationRequest.order), cancellationRequest.takerTokenCancelAmount, ]; }); @@ -501,7 +501,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Subscribe to an event type emitted by the Exchange smart contract @@ -514,7 +514,7 @@ export class ExchangeWrapper extends ContractWrapper { public async subscribeAsync(eventName: ExchangeEvents, subscriptionOpts: SubscriptionOpts, indexFilterValues: IndexFilterValues, callback: EventCallback): Promise<void> { - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let createLogEvent: CreateContractEvent; switch (eventName) { case ExchangeEvents.LogFill: @@ -533,15 +533,15 @@ export class ExchangeWrapper extends ContractWrapper { const logEventObj: ContractEventObj = createLogEvent(indexFilterValues, subscriptionOpts); logEventObj.watch(callback); - this.exchangeLogEventObjs.push(logEventObj); + this._exchangeLogEventObjs.push(logEventObj); } - private async isValidSignatureUsingContractCallAsync(dataHex: string, ecSignature: ECSignature, - signerAddressHex: string): Promise<boolean> { + private async _isValidSignatureUsingContractCallAsync(dataHex: string, ecSignature: ECSignature, + signerAddressHex: string): Promise<boolean> { assert.isHexString('dataHex', dataHex); assert.doesConformToSchema('ecSignature', ecSignature, ecSignatureSchema); assert.isETHAddressHex('signerAddressHex', signerAddressHex); - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); const isValidSignature = await exchangeInstance.isValidSignature.call( signerAddressHex, @@ -552,27 +552,27 @@ export class ExchangeWrapper extends ContractWrapper { ); return isValidSignature; } - private async getOrderHashHexAsync(order: Order|SignedOrder): Promise<string> { - const exchangeInstance = await this.getExchangeContractAsync(); + private async _getOrderHashHexAsync(order: Order|SignedOrder): Promise<string> { + const exchangeInstance = await this._getExchangeContractAsync(); const orderHashHex = utils.getOrderHashHex(order, exchangeInstance.address); return orderHashHex; } - private async getOrderHashHexUsingContractCallAsync(order: Order|SignedOrder): Promise<string> { - const exchangeInstance = await this.getExchangeContractAsync(); - const [orderAddresses, orderValues] = ExchangeWrapper.getOrderAddressesAndValues(order); + private async _getOrderHashHexUsingContractCallAsync(order: Order|SignedOrder): Promise<string> { + const exchangeInstance = await this._getExchangeContractAsync(); + const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order); const orderHashHex = await exchangeInstance.getOrderHash.call(orderAddresses, orderValues); return orderHashHex; } - private async stopWatchingExchangeLogEventsAsync() { - const stopWatchingPromises = _.map(this.exchangeLogEventObjs, logEventObj => { + private async _stopWatchingExchangeLogEventsAsync() { + const stopWatchingPromises = _.map(this._exchangeLogEventObjs, logEventObj => { return promisify(logEventObj.stopWatching, logEventObj)(); }); await Promise.all(stopWatchingPromises); - this.exchangeLogEventObjs = []; + this._exchangeLogEventObjs = []; } - private async validateFillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder, - fillTakerAmount: BigNumber.BigNumber, - senderAddress: string): Promise<void> { + private async _validateFillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder, + fillTakerAmount: BigNumber.BigNumber, + senderAddress: string): Promise<void> { if (fillTakerAmount.eq(0)) { throw new Error(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO); } @@ -583,23 +583,23 @@ export class ExchangeWrapper extends ContractWrapper { if (signedOrder.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) { throw new Error(ExchangeContractErrs.ORDER_FILL_EXPIRED); } - const zrxTokenAddress = await this.getZRXTokenAddressAsync(); - await this.validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder, fillTakerAmount, + const zrxTokenAddress = await this._getZRXTokenAddressAsync(); + await this._validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder, fillTakerAmount, senderAddress, zrxTokenAddress); - const wouldRoundingErrorOccur = await this.isRoundingErrorAsync( + const wouldRoundingErrorOccur = await this._isRoundingErrorAsync( signedOrder.takerTokenAmount, fillTakerAmount, signedOrder.makerTokenAmount, ); if (wouldRoundingErrorOccur) { throw new Error(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR); } } - private async validateCancelOrderAndThrowIfInvalidAsync( + private async _validateCancelOrderAndThrowIfInvalidAsync( order: Order, takerTokenCancelAmount: BigNumber.BigNumber): Promise<void> { if (takerTokenCancelAmount.eq(0)) { throw new Error(ExchangeContractErrs.ORDER_CANCEL_AMOUNT_ZERO); } - const orderHash = await this.getOrderHashHexAsync(order); + const orderHash = await this._getOrderHashHexAsync(order); const unavailableAmount = await this.getUnavailableTakerAmountAsync(orderHash); if (order.takerTokenAmount.minus(unavailableAmount).eq(0)) { throw new Error(ExchangeContractErrs.ORDER_ALREADY_CANCELLED_OR_FILLED); @@ -609,9 +609,9 @@ export class ExchangeWrapper extends ContractWrapper { throw new Error(ExchangeContractErrs.ORDER_CANCEL_EXPIRED); } } - private async validateFillOrKillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder, - exchangeAddress: string, - fillTakerAmount: BigNumber.BigNumber) { + private async _validateFillOrKillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder, + exchangeAddress: string, + fillTakerAmount: BigNumber.BigNumber) { // Check that fillValue available >= fillTakerAmount const orderHashHex = utils.getOrderHashHex(signedOrder, exchangeAddress); const unavailableTakerAmount = await this.getUnavailableTakerAmountAsync(orderHashHex); @@ -629,17 +629,18 @@ export class ExchangeWrapper extends ContractWrapper { * TODO: Throw errors before calling the smart contract for these edge-cases in order to minimize * the callers gas costs. */ - private async validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder: SignedOrder, - fillTakerAmount: BigNumber.BigNumber, - senderAddress: string, - zrxTokenAddress: string): Promise<void> { + private async _validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder: SignedOrder, + fillTakerAmount: BigNumber.BigNumber, + senderAddress: string, + zrxTokenAddress: string, + ): Promise<void> { - const makerBalance = await this.tokenWrapper.getBalanceAsync(signedOrder.makerTokenAddress, + const makerBalance = await this._tokenWrapper.getBalanceAsync(signedOrder.makerTokenAddress, signedOrder.maker); - const takerBalance = await this.tokenWrapper.getBalanceAsync(signedOrder.takerTokenAddress, senderAddress); - const makerAllowance = await this.tokenWrapper.getProxyAllowanceAsync(signedOrder.makerTokenAddress, + const takerBalance = await this._tokenWrapper.getBalanceAsync(signedOrder.takerTokenAddress, senderAddress); + const makerAllowance = await this._tokenWrapper.getProxyAllowanceAsync(signedOrder.makerTokenAddress, signedOrder.maker); - const takerAllowance = await this.tokenWrapper.getProxyAllowanceAsync(signedOrder.takerTokenAddress, + const takerAllowance = await this._tokenWrapper.getProxyAllowanceAsync(signedOrder.takerTokenAddress, senderAddress); // exchangeRate is the price of one maker token denominated in taker tokens @@ -659,12 +660,12 @@ export class ExchangeWrapper extends ContractWrapper { throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_ALLOWANCE); } - const makerFeeBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, + const makerFeeBalance = await this._tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker); - const takerFeeBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, senderAddress); - const makerFeeAllowance = await this.tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, + const takerFeeBalance = await this._tokenWrapper.getBalanceAsync(zrxTokenAddress, senderAddress); + const makerFeeAllowance = await this._tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, signedOrder.maker); - const takerFeeAllowance = await this.tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, + const takerFeeAllowance = await this._tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, senderAddress); if (signedOrder.takerFee.greaterThan(takerFeeBalance)) { @@ -680,34 +681,34 @@ export class ExchangeWrapper extends ContractWrapper { throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_ALLOWANCE); } } - private throwErrorLogsAsErrors(logs: ContractEvent[]): void { + private _throwErrorLogsAsErrors(logs: ContractEvent[]): void { const errEvent = _.find(logs, {event: 'LogError'}); if (!_.isUndefined(errEvent)) { const errCode = errEvent.args.errorId.toNumber(); - const errMessage = this.exchangeContractErrCodesToMsg[errCode]; + const errMessage = this._exchangeContractErrCodesToMsg[errCode]; throw new Error(errMessage); } } - private async isRoundingErrorAsync(takerTokenAmount: BigNumber.BigNumber, - fillTakerAmount: BigNumber.BigNumber, - makerTokenAmount: BigNumber.BigNumber): Promise<boolean> { + private async _isRoundingErrorAsync(takerTokenAmount: BigNumber.BigNumber, + fillTakerAmount: BigNumber.BigNumber, + makerTokenAmount: BigNumber.BigNumber): Promise<boolean> { await assert.isUserAddressAvailableAsync(this.web3Wrapper); - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); const isRoundingError = await exchangeInstance.isRoundingError.call( takerTokenAmount, fillTakerAmount, makerTokenAmount, ); return isRoundingError; } - private async getExchangeContractAsync(): Promise<ExchangeContract> { - if (!_.isUndefined(this.exchangeContractIfExists)) { - return this.exchangeContractIfExists; + private async _getExchangeContractAsync(): Promise<ExchangeContract> { + if (!_.isUndefined(this._exchangeContractIfExists)) { + return this._exchangeContractIfExists; } - const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any)); - this.exchangeContractIfExists = contractInstance as ExchangeContract; - return this.exchangeContractIfExists; + const contractInstance = await this._instantiateContractIfExistsAsync((ExchangeArtifacts as any)); + this._exchangeContractIfExists = contractInstance as ExchangeContract; + return this._exchangeContractIfExists; } - private async getZRXTokenAddressAsync(): Promise<string> { - const exchangeInstance = await this.getExchangeContractAsync(); + private async _getZRXTokenAddressAsync(): Promise<string> { + const exchangeInstance = await this._getExchangeContractAsync(); return exchangeInstance.ZRX.call(); } } diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts index 96346a7a4..ab0218777 100644 --- a/src/contract_wrappers/token_registry_wrapper.ts +++ b/src/contract_wrappers/token_registry_wrapper.ts @@ -6,19 +6,19 @@ import {ContractWrapper} from './contract_wrapper'; import * as TokenRegistryArtifacts from '../artifacts/TokenRegistry.json'; export class TokenRegistryWrapper extends ContractWrapper { - private tokenRegistryContractIfExists?: TokenRegistryContract; + private _tokenRegistryContractIfExists?: TokenRegistryContract; constructor(web3Wrapper: Web3Wrapper) { super(web3Wrapper); } public invalidateContractInstance(): void { - delete this.tokenRegistryContractIfExists; + delete this._tokenRegistryContractIfExists; } /** * Retrieves all the tokens currently listed in the Token Registry smart contract * @return An array of JS objects that conform to the Token interface. */ public async getTokensAsync(): Promise<Token[]> { - const tokenRegistryContract = await this.getTokenRegistryContractAsync(); + const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const addresses = await tokenRegistryContract.getTokenAddresses.call(); const tokenMetadataPromises: Array<Promise<TokenMetadata>> = _.map( @@ -37,12 +37,12 @@ export class TokenRegistryWrapper extends ContractWrapper { }); return tokens; } - private async getTokenRegistryContractAsync(): Promise<TokenRegistryContract> { - if (!_.isUndefined(this.tokenRegistryContractIfExists)) { - return this.tokenRegistryContractIfExists; + private async _getTokenRegistryContractAsync(): Promise<TokenRegistryContract> { + if (!_.isUndefined(this._tokenRegistryContractIfExists)) { + return this._tokenRegistryContractIfExists; } - const contractInstance = await this.instantiateContractIfExistsAsync((TokenRegistryArtifacts as any)); - this.tokenRegistryContractIfExists = contractInstance as TokenRegistryContract; - return this.tokenRegistryContractIfExists; + const contractInstance = await this._instantiateContractIfExistsAsync((TokenRegistryArtifacts as any)); + this._tokenRegistryContractIfExists = contractInstance as TokenRegistryContract; + return this._tokenRegistryContractIfExists; } } diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index bb79cac47..b0101c0da 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -11,13 +11,13 @@ import {TokenContract, ZeroExError} from '../types'; const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 45730; export class TokenWrapper extends ContractWrapper { - private tokenContractsByAddress: {[address: string]: TokenContract}; + private _tokenContractsByAddress: {[address: string]: TokenContract}; constructor(web3Wrapper: Web3Wrapper) { super(web3Wrapper); - this.tokenContractsByAddress = {}; + this._tokenContractsByAddress = {}; } public invalidateContractInstances() { - this.tokenContractsByAddress = {}; + this._tokenContractsByAddress = {}; } /** * Retrieves an owner's ERC20 token balance. @@ -29,7 +29,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); await assert.isUserAddressAvailableAsync(this.web3Wrapper); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); let balance = await tokenContract.balanceOf.call(ownerAddress); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber balance = new BigNumber(balance); @@ -51,7 +51,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); // Hack: for some reason default estimated gas amount causes `base fee exceeds gas limit` exception // on testrpc. Probably related to https://github.com/ethereumjs/testrpc/issues/294 // TODO: Debug issue in testrpc and submit a PR, then remove this hack @@ -74,7 +74,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); await assert.isUserAddressAvailableAsync(this.web3Wrapper); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber allowanceInBaseUnits = new BigNumber(allowanceInBaseUnits); @@ -89,7 +89,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); - const proxyAddress = await this.getProxyAddressAsync(); + const proxyAddress = await this._getProxyAddressAsync(); const allowanceInBaseUnits = await this.getAllowanceAsync(tokenAddress, ownerAddress, proxyAddress); return allowanceInBaseUnits; } @@ -107,7 +107,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const proxyAddress = await this.getProxyAddressAsync(); + const proxyAddress = await this._getProxyAddressAsync(); await this.setAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits); } /** @@ -124,7 +124,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('toAddress', toAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); const fromAddressBalance = await this.getBalanceAsync(tokenAddress, fromAddress); if (fromAddressBalance.lessThan(amountInBaseUnits)) { @@ -155,7 +155,7 @@ export class TokenWrapper extends ContractWrapper { await assert.isSenderAddressAsync('senderAddress', senderAddress, this.web3Wrapper); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); const fromAddressAllowance = await this.getAllowanceAsync(tokenAddress, fromAddress, senderAddress); if (fromAddressAllowance.lessThan(amountInBaseUnits)) { @@ -171,17 +171,17 @@ export class TokenWrapper extends ContractWrapper { from: senderAddress, }); } - private async getTokenContractAsync(tokenAddress: string): Promise<TokenContract> { - let tokenContract = this.tokenContractsByAddress[tokenAddress]; + private async _getTokenContractAsync(tokenAddress: string): Promise<TokenContract> { + let tokenContract = this._tokenContractsByAddress[tokenAddress]; if (!_.isUndefined(tokenContract)) { return tokenContract; } - const contractInstance = await this.instantiateContractIfExistsAsync((TokenArtifacts as any), tokenAddress); + const contractInstance = await this._instantiateContractIfExistsAsync((TokenArtifacts as any), tokenAddress); tokenContract = contractInstance as TokenContract; - this.tokenContractsByAddress[tokenAddress] = tokenContract; + this._tokenContractsByAddress[tokenAddress] = tokenContract; return tokenContract; } - private async getProxyAddressAsync() { + private async _getProxyAddressAsync() { const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : |