diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-06-11 19:52:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-11 19:52:54 +0800 |
commit | 4ac0ead5ce931871cf12fdaa83d87597bfc9979d (patch) | |
tree | 0813864d3920321e64acadebdacfd1525ea4e998 /src/contract_wrappers/token_wrapper.ts | |
parent | 4e56c299263cf6a3397a1d7b95fb92a8b61da3c0 (diff) | |
parent | bbe9a811fb28417377ec3d089e0cdd3693480c35 (diff) | |
download | dexon-sol-tools-4ac0ead5ce931871cf12fdaa83d87597bfc9979d.tar dexon-sol-tools-4ac0ead5ce931871cf12fdaa83d87597bfc9979d.tar.gz dexon-sol-tools-4ac0ead5ce931871cf12fdaa83d87597bfc9979d.tar.bz2 dexon-sol-tools-4ac0ead5ce931871cf12fdaa83d87597bfc9979d.tar.lz dexon-sol-tools-4ac0ead5ce931871cf12fdaa83d87597bfc9979d.tar.xz dexon-sol-tools-4ac0ead5ce931871cf12fdaa83d87597bfc9979d.tar.zst dexon-sol-tools-4ac0ead5ce931871cf12fdaa83d87597bfc9979d.zip |
Merge pull request #62 from 0xProject/private
Prefix private vars with _
Diffstat (limited to 'src/contract_wrappers/token_wrapper.ts')
-rw-r--r-- | src/contract_wrappers/token_wrapper.ts | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index bb79cac47..98da6c2cd 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. @@ -27,9 +27,9 @@ export class TokenWrapper extends ContractWrapper { public async getBalanceAsync(tokenAddress: string, ownerAddress: string): Promise<BigNumber.BigNumber> { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); - await assert.isUserAddressAvailableAsync(this.web3Wrapper); + 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); @@ -46,16 +46,16 @@ export class TokenWrapper extends ContractWrapper { */ public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string, amountInBaseUnits: BigNumber.BigNumber): Promise<void> { - await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this._web3Wrapper); assert.isETHAddressHex('spenderAddress', spenderAddress); 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 - const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); + const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined; await tokenContract.approve(spenderAddress, amountInBaseUnits, { from: ownerAddress, @@ -72,9 +72,9 @@ export class TokenWrapper extends ContractWrapper { public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string) { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); - await assert.isUserAddressAvailableAsync(this.web3Wrapper); + 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); } /** @@ -120,11 +120,11 @@ export class TokenWrapper extends ContractWrapper { public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber.BigNumber): Promise<void> { assert.isETHAddressHex('tokenAddress', tokenAddress); - await assert.isSenderAddressAsync('fromAddress', fromAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('fromAddress', fromAddress, this._web3Wrapper); 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)) { @@ -152,10 +152,10 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('fromAddress', fromAddress); assert.isETHAddressHex('toAddress', toAddress); - await assert.isSenderAddressAsync('senderAddress', senderAddress, this.web3Wrapper); + 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,18 +171,18 @@ 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() { - const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); + private async _getProxyAddressAsync() { + const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : (ProxyArtifacts as any).networks[networkIdIfExists]; |