aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/token_wrapper.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-09-05 16:07:16 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-09-05 16:07:16 +0800
commit2b547f94a44dfed029b5559b743344d5998fa3bc (patch)
tree3c5241ba9cadcfad6ee0290b497ed6780cc9fc8b /src/contract_wrappers/token_wrapper.ts
parentc9e490bdaec53e3a93b5da8daaaf0b1d87d9de76 (diff)
downloaddexon-0x-contracts-2b547f94a44dfed029b5559b743344d5998fa3bc.tar
dexon-0x-contracts-2b547f94a44dfed029b5559b743344d5998fa3bc.tar.gz
dexon-0x-contracts-2b547f94a44dfed029b5559b743344d5998fa3bc.tar.bz2
dexon-0x-contracts-2b547f94a44dfed029b5559b743344d5998fa3bc.tar.lz
dexon-0x-contracts-2b547f94a44dfed029b5559b743344d5998fa3bc.tar.xz
dexon-0x-contracts-2b547f94a44dfed029b5559b743344d5998fa3bc.tar.zst
dexon-0x-contracts-2b547f94a44dfed029b5559b743344d5998fa3bc.zip
Change non-exhange contracts to also return txHash
Diffstat (limited to 'src/contract_wrappers/token_wrapper.ts')
-rw-r--r--src/contract_wrappers/token_wrapper.ts43
1 files changed, 29 insertions, 14 deletions
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.