diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-05 16:07:16 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-05 16:07:16 +0800 |
commit | 2b547f94a44dfed029b5559b743344d5998fa3bc (patch) | |
tree | 3c5241ba9cadcfad6ee0290b497ed6780cc9fc8b /src | |
parent | c9e490bdaec53e3a93b5da8daaaf0b1d87d9de76 (diff) | |
download | dexon-sol-tools-2b547f94a44dfed029b5559b743344d5998fa3bc.tar dexon-sol-tools-2b547f94a44dfed029b5559b743344d5998fa3bc.tar.gz dexon-sol-tools-2b547f94a44dfed029b5559b743344d5998fa3bc.tar.bz2 dexon-sol-tools-2b547f94a44dfed029b5559b743344d5998fa3bc.tar.lz dexon-sol-tools-2b547f94a44dfed029b5559b743344d5998fa3bc.tar.xz dexon-sol-tools-2b547f94a44dfed029b5559b743344d5998fa3bc.tar.zst dexon-sol-tools-2b547f94a44dfed029b5559b743344d5998fa3bc.zip |
Change non-exhange contracts to also return txHash
Diffstat (limited to 'src')
-rw-r--r-- | src/0x.ts | 4 | ||||
-rw-r--r-- | src/contract_wrappers/ether_token_wrapper.ts | 12 | ||||
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 1 | ||||
-rw-r--r-- | src/contract_wrappers/token_wrapper.ts | 43 | ||||
-rw-r--r-- | src/types.ts | 10 |
5 files changed, 44 insertions, 26 deletions
@@ -249,8 +249,8 @@ export class ZeroEx { throw new Error(ZeroExError.InvalidSignature); } - public async awaitTransactionMined(txHash: string, - pollingIntervalMs: number = 500): Promise<Web3.TransactionReceipt> { + public async awaitTransactionMinedAsync(txHash: string, + pollingIntervalMs: number = 500): Promise<Web3.TransactionReceipt> { const txReceiptPromise = new Promise((resolve: (receipt: Web3.TransactionReceipt) => void, reject) => { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts index a2486b15e..ba0cd05d8 100644 --- a/src/contract_wrappers/ether_token_wrapper.ts +++ b/src/contract_wrappers/ether_token_wrapper.ts @@ -23,8 +23,9 @@ export class EtherTokenWrapper extends ContractWrapper { * for ETH. * @param amountInWei Amount of ETH in Wei the caller wishes to deposit. * @param depositor The hex encoded user Ethereum address that would like to make the deposit. + * @return Transaction hash. */ - public async depositAsync(amountInWei: BigNumber.BigNumber, depositor: string): Promise<void> { + public async depositAsync(amountInWei: BigNumber.BigNumber, depositor: string): Promise<string> { assert.isBigNumber('amountInWei', amountInWei); await assert.isSenderAddressAsync('depositor', depositor, this._web3Wrapper); @@ -32,18 +33,20 @@ export class EtherTokenWrapper extends ContractWrapper { assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.InsufficientEthBalanceForDeposit); const wethContract = await this._getEtherTokenContractAsync(); - await wethContract.deposit({ + const txHash = await wethContract.deposit({ from: depositor, value: amountInWei, }); + return txHash; } /** * Withdraw ETH to the withdrawer's address from the wrapped ETH smart contract in exchange for the * equivalent number of wrapped ETH tokens. * @param amountInWei Amount of ETH in Wei the caller wishes to withdraw. * @param withdrawer The hex encoded user Ethereum address that would like to make the withdrawl. + * @return Transaction hash. */ - public async withdrawAsync(amountInWei: BigNumber.BigNumber, withdrawer: string): Promise<void> { + public async withdrawAsync(amountInWei: BigNumber.BigNumber, withdrawer: string): Promise<string> { assert.isBigNumber('amountInWei', amountInWei); await assert.isSenderAddressAsync('withdrawer', withdrawer, this._web3Wrapper); @@ -52,9 +55,10 @@ export class EtherTokenWrapper extends ContractWrapper { assert.assert(WETHBalanceInBaseUnits.gte(amountInWei), ZeroExError.InsufficientWEthBalanceForWithdrawal); const wethContract = await this._getEtherTokenContractAsync(); - await wethContract.withdraw(amountInWei, { + const txHash = await wethContract.withdraw(amountInWei, { from: withdrawer, }); + return txHash; } /** * Retrieves the Wrapped Ether token contract address diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 1196394e9..3b94bb22c 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -21,7 +21,6 @@ import { IndexedFilterValues, CreateContractEvent, ContractEventObj, - ContractResponse, OrderCancellationRequest, OrderFillRequest, LogErrorContractEventArgs, diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index e98744cbc..9c72455f1 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -60,9 +60,10 @@ export class TokenWrapper extends ContractWrapper { * for spenderAddress. * @param spenderAddress The hex encoded user Ethereum address who will be able to spend the set allowance. * @param amountInBaseUnits The allowance amount you would like to set. + * @return Transaction hash. */ public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string, - amountInBaseUnits: BigNumber.BigNumber): Promise<void> { + amountInBaseUnits: BigNumber.BigNumber): Promise<string> { await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this._web3Wrapper); assert.isETHAddressHex('spenderAddress', spenderAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); @@ -74,10 +75,11 @@ export class TokenWrapper extends ContractWrapper { // TODO: Debug issue in testrpc and submit a PR, then remove this hack const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined; - await tokenContract.approve(spenderAddress, amountInBaseUnits, { + const txHash = await tokenContract.approve(spenderAddress, amountInBaseUnits, { from: ownerAddress, gas, }); + return txHash; } /** * Sets the spender's allowance to an unlimited number of baseUnits on behalf of the owner address. @@ -88,12 +90,14 @@ export class TokenWrapper extends ContractWrapper { * @param ownerAddress The hex encoded user Ethereum address who would like to set an allowance * for spenderAddress. * @param spenderAddress The hex encoded user Ethereum address who will be able to spend the set allowance. + * @return Transaction hash. */ public async setUnlimitedAllowanceAsync(tokenAddress: string, ownerAddress: string, - spenderAddress: string): Promise<void> { - await this.setAllowanceAsync( + spenderAddress: string): Promise<string> { + const txHash = await this.setAllowanceAsync( tokenAddress, ownerAddress, spenderAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS, ); + return txHash; } /** * Retrieves the owners allowance in baseUnits set to the spender's address. @@ -102,7 +106,8 @@ export class TokenWrapper extends ContractWrapper { * you would like to retrieve. * @param spenderAddress The hex encoded user Ethereum address who can spend the allowance you are fetching. */ - public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string) { + public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, + spenderAddress: string): Promise<BigNumber.BigNumber> { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); @@ -117,7 +122,7 @@ export class TokenWrapper extends ContractWrapper { * @param tokenAddress The hex encoded contract Ethereum address where the ERC20 token is deployed. * @param ownerAddress The hex encoded user Ethereum address whose proxy contract allowance we are retrieving. */ - public async getProxyAllowanceAsync(tokenAddress: string, ownerAddress: string) { + public async getProxyAllowanceAsync(tokenAddress: string, ownerAddress: string): Promise<BigNumber.BigNumber> { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); @@ -132,15 +137,17 @@ export class TokenWrapper extends ContractWrapper { * @param ownerAddress The hex encoded user Ethereum address who is setting an allowance * for the Proxy contract. * @param amountInBaseUnits The allowance amount specified in baseUnits. + * @return Transaction hash. */ public async setProxyAllowanceAsync(tokenAddress: string, ownerAddress: string, - amountInBaseUnits: BigNumber.BigNumber): Promise<void> { + amountInBaseUnits: BigNumber.BigNumber): Promise<string> { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); const proxyAddress = await this._getProxyAddressAsync(); - await this.setAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits); + const txHash = await this.setAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits); + return txHash; } /** * Sets the 0x proxy contract's allowance to a unlimited number of a tokens' baseUnits on behalf @@ -150,9 +157,13 @@ export class TokenWrapper extends ContractWrapper { * @param tokenAddress The hex encoded contract Ethereum address where the ERC20 token is deployed. * @param ownerAddress The hex encoded user Ethereum address who is setting an allowance * for the Proxy contract. + * @return Transaction hash. */ - public async setUnlimitedProxyAllowanceAsync(tokenAddress: string, ownerAddress: string): Promise<void> { - await this.setProxyAllowanceAsync(tokenAddress, ownerAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); + public async setUnlimitedProxyAllowanceAsync(tokenAddress: string, ownerAddress: string): Promise<string> { + const txHash = await this.setProxyAllowanceAsync( + tokenAddress, ownerAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS, + ); + return txHash; } /** * Transfers `amountInBaseUnits` ERC20 tokens from `fromAddress` to `toAddress`. @@ -160,9 +171,10 @@ export class TokenWrapper extends ContractWrapper { * @param fromAddress The hex encoded user Ethereum address that will send the funds. * @param toAddress The hex encoded user Ethereum address that will receive the funds. * @param amountInBaseUnits The amount (specified in baseUnits) of the token to transfer. + * @return Transaction hash. */ public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string, - amountInBaseUnits: BigNumber.BigNumber): Promise<void> { + amountInBaseUnits: BigNumber.BigNumber): Promise<string> { assert.isETHAddressHex('tokenAddress', tokenAddress); await assert.isSenderAddressAsync('fromAddress', fromAddress, this._web3Wrapper); assert.isETHAddressHex('toAddress', toAddress); @@ -175,9 +187,10 @@ export class TokenWrapper extends ContractWrapper { throw new Error(ZeroExError.InsufficientBalanceForTransfer); } - await tokenContract.transfer(toAddress, amountInBaseUnits, { + const txHash = await tokenContract.transfer(toAddress, amountInBaseUnits, { from: fromAddress, }); + return txHash; } /** * Transfers `amountInBaseUnits` ERC20 tokens from `fromAddress` to `toAddress`. @@ -190,10 +203,11 @@ export class TokenWrapper extends ContractWrapper { * `fromAddress` must have set an allowance to the `senderAddress` * before this call. * @param amountInBaseUnits The amount (specified in baseUnits) of the token to transfer. + * @return Transaction hash. */ public async transferFromAsync(tokenAddress: string, fromAddress: string, toAddress: string, senderAddress: string, amountInBaseUnits: BigNumber.BigNumber): - Promise<void> { + Promise<string> { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('fromAddress', fromAddress); assert.isETHAddressHex('toAddress', toAddress); @@ -212,9 +226,10 @@ export class TokenWrapper extends ContractWrapper { throw new Error(ZeroExError.InsufficientBalanceForTransfer); } - await tokenContract.transferFrom(fromAddress, toAddress, amountInBaseUnits, { + const txHash = await tokenContract.transferFrom(fromAddress, toAddress, amountInBaseUnits, { from: senderAddress, }); + return txHash; } /** * Subscribe to an event type emitted by the Token contract. diff --git a/src/types.ts b/src/types.ts index e90c6fab4..1aabe6e4f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -133,10 +133,10 @@ export interface TokenContract extends Web3.ContractInstance { allowance: { call: (ownerAddress: string, allowedAddress: string) => Promise<BigNumber.BigNumber>; }; - transfer: (toAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise<boolean>; + transfer: (toAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise<string>; transferFrom: (fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber.BigNumber, - txOpts?: TxOpts) => Promise<boolean>; - approve: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise<void>; + txOpts?: TxOpts) => Promise<string>; + approve: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise<string>; } export interface TokenRegistryContract extends Web3.ContractInstance { @@ -161,8 +161,8 @@ export interface TokenRegistryContract extends Web3.ContractInstance { } export interface EtherTokenContract extends Web3.ContractInstance { - deposit: (txOpts: TxOpts) => Promise<void>; - withdraw: (amount: BigNumber.BigNumber, txOpts: TxOpts) => Promise<void>; + deposit: (txOpts: TxOpts) => Promise<string>; + withdraw: (amount: BigNumber.BigNumber, txOpts: TxOpts) => Promise<string>; } export interface TokenTransferProxyContract extends Web3.ContractInstance { |