aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-06-06 21:14:53 +0800
committerGitHub <noreply@github.com>2017-06-06 21:14:53 +0800
commit692a0fd965f7c0cfc0eef79112d2abffdf9e90db (patch)
treea3a97eb6522bc887966da6575e4b2ac73560fdcf /src/contract_wrappers
parent2eb99f46f53984c1a54315f87059ef18b9d06349 (diff)
parentf54b513935dbba0dd1922566ed2fd4b4acbf6459 (diff)
downloaddexon-sol-tools-692a0fd965f7c0cfc0eef79112d2abffdf9e90db.tar
dexon-sol-tools-692a0fd965f7c0cfc0eef79112d2abffdf9e90db.tar.gz
dexon-sol-tools-692a0fd965f7c0cfc0eef79112d2abffdf9e90db.tar.bz2
dexon-sol-tools-692a0fd965f7c0cfc0eef79112d2abffdf9e90db.tar.lz
dexon-sol-tools-692a0fd965f7c0cfc0eef79112d2abffdf9e90db.tar.xz
dexon-sol-tools-692a0fd965f7c0cfc0eef79112d2abffdf9e90db.tar.zst
dexon-sol-tools-692a0fd965f7c0cfc0eef79112d2abffdf9e90db.zip
Merge pull request #39 from 0xProject/senderAccount
Make methods accept senderAccount
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts20
-rw-r--r--src/contract_wrappers/token_wrapper.ts9
2 files changed, 12 insertions, 17 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index ee0b2696f..d3a53a9f7 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -57,7 +57,6 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('ecSignature', ecSignature, ecSignatureSchema);
assert.isETHAddressHex('signerAddressHex', signerAddressHex);
- const senderAddress = await this.web3Wrapper.getSenderAddressOrThrowAsync();
const exchangeInstance = await this.getExchangeContractAsync();
const isValidSignature = await exchangeInstance.isValidSignature.call(
@@ -66,9 +65,6 @@ export class ExchangeWrapper extends ContractWrapper {
ecSignature.v,
ecSignature.r,
ecSignature.s,
- {
- from: senderAddress,
- },
);
return isValidSignature;
}
@@ -119,16 +115,16 @@ export class ExchangeWrapper extends ContractWrapper {
* false forgoes this check and causes the smart contract to throw instead.
*/
public async fillOrderAsync(signedOrder: SignedOrder, fillTakerAmount: BigNumber.BigNumber,
- shouldCheckTransfer: boolean): Promise<void> {
+ shouldCheckTransfer: boolean, takerAddress: string): Promise<void> {
assert.doesConformToSchema('signedOrder',
SchemaValidator.convertToJSONSchemaCompatibleObject(signedOrder as object),
signedOrderSchema);
assert.isBigNumber('fillTakerAmount', fillTakerAmount);
assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer);
+ await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper);
- const senderAddress = await this.web3Wrapper.getSenderAddressOrThrowAsync();
const exchangeInstance = await this.getExchangeContractAsync();
- await this.validateFillOrderAndThrowIfInvalidAsync(signedOrder, fillTakerAmount, senderAddress);
+ await this.validateFillOrderAndThrowIfInvalidAsync(signedOrder, fillTakerAmount, takerAddress);
const orderAddresses: OrderAddresses = [
signedOrder.maker,
@@ -154,7 +150,7 @@ export class ExchangeWrapper extends ContractWrapper {
signedOrder.ecSignature.r,
signedOrder.ecSignature.s,
{
- from: senderAddress,
+ from: takerAddress,
},
);
const response: ContractResponse = await exchangeInstance.fill(
@@ -166,7 +162,7 @@ export class ExchangeWrapper extends ContractWrapper {
signedOrder.ecSignature.r,
signedOrder.ecSignature.s,
{
- from: senderAddress,
+ from: takerAddress,
gas,
},
);
@@ -301,12 +297,10 @@ export class ExchangeWrapper extends ContractWrapper {
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 senderAddress = await this.web3Wrapper.getSenderAddressOrThrowAsync();
const isRoundingError = await exchangeInstance.isRoundingError.call(
- takerTokenAmount, fillTakerAmount, makerTokenAmount, {
- from: senderAddress,
- },
+ takerTokenAmount, fillTakerAmount, makerTokenAmount,
);
return isRoundingError;
}
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts
index c8b557d0d..4412b1299 100644
--- a/src/contract_wrappers/token_wrapper.ts
+++ b/src/contract_wrappers/token_wrapper.ts
@@ -25,6 +25,7 @@ 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);
const tokenContract = await this.getTokenContractAsync(tokenAddress);
let balance = await tokenContract.balanceOf.call(ownerAddress);
@@ -38,7 +39,7 @@ export class TokenWrapper extends ContractWrapper {
*/
public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string,
amountInBaseUnits: BigNumber.BigNumber): Promise<void> {
- assert.isETHAddressHex('ownerAddress', ownerAddress);
+ await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this.web3Wrapper);
assert.isETHAddressHex('spenderAddress', spenderAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isBigNumber('amountInBaseUnits', amountInBaseUnits);
@@ -60,6 +61,7 @@ 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);
const tokenContract = await this.getTokenContractAsync(tokenAddress);
let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress);
@@ -97,7 +99,7 @@ export class TokenWrapper extends ContractWrapper {
public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string,
amountInBaseUnits: BigNumber.BigNumber): Promise<void> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
- assert.isETHAddressHex('fromAddress', fromAddress);
+ await assert.isSenderAddressAsync('fromAddress', fromAddress, this.web3Wrapper);
assert.isETHAddressHex('toAddress', toAddress);
assert.isBigNumber('amountInBaseUnits', amountInBaseUnits);
@@ -123,9 +125,8 @@ export class TokenWrapper extends ContractWrapper {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isETHAddressHex('fromAddress', fromAddress);
assert.isETHAddressHex('toAddress', toAddress);
- assert.isETHAddressHex('senderAddress', senderAddress);
+ await assert.isSenderAddressAsync('senderAddress', senderAddress, this.web3Wrapper);
assert.isBigNumber('amountInBaseUnits', amountInBaseUnits);
- await assert.isSenderAddressAvailableAsync(this.web3Wrapper, senderAddress);
const tokenContract = await this.getTokenContractAsync(tokenAddress);