Add getExchangeInstanceOrThrowAsync && getSenderAddressOrThrowAsync
This commit is contained in:
parent
34de598642
commit
7dddf2010e
@ -16,11 +16,8 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
assert.doesConformToSchema('ecSignature', ecSignature, ecSignatureSchema);
|
assert.doesConformToSchema('ecSignature', ecSignature, ecSignatureSchema);
|
||||||
assert.isETHAddressHex('signerAddressHex', signerAddressHex);
|
assert.isETHAddressHex('signerAddressHex', signerAddressHex);
|
||||||
|
|
||||||
const senderAddressIfExists = await this.web3Wrapper.getSenderAddressIfExistsAsync();
|
const senderAddress = await this.web3Wrapper.getSenderAddressOrThrowAsync();
|
||||||
assert.assert(!_.isUndefined(senderAddressIfExists), ZeroExError.USER_HAS_NO_ASSOCIATED_ADDRESSES);
|
const exchangeInstance = await this.getExchangeInstanceOrThrowAsync();
|
||||||
|
|
||||||
const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any));
|
|
||||||
const exchangeInstance = contractInstance as ExchangeContract;
|
|
||||||
|
|
||||||
const isValidSignature = await exchangeInstance.isValidSignature.call(
|
const isValidSignature = await exchangeInstance.isValidSignature.call(
|
||||||
signerAddressHex,
|
signerAddressHex,
|
||||||
@ -29,9 +26,13 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
ecSignature.r,
|
ecSignature.r,
|
||||||
ecSignature.s,
|
ecSignature.s,
|
||||||
{
|
{
|
||||||
from: senderAddressIfExists,
|
from: senderAddress,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return isValidSignature;
|
return isValidSignature;
|
||||||
}
|
}
|
||||||
|
private async getExchangeInstanceOrThrowAsync(): Promise<ExchangeContract> {
|
||||||
|
const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any));
|
||||||
|
return contractInstance as ExchangeContract;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ import * as _ from 'lodash';
|
|||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
import * as BigNumber from 'bignumber.js';
|
import * as BigNumber from 'bignumber.js';
|
||||||
import promisify = require('es6-promisify');
|
import promisify = require('es6-promisify');
|
||||||
|
import {ZeroExError} from "./types";
|
||||||
|
import {assert} from "./utils/assert";
|
||||||
|
|
||||||
export class Web3Wrapper {
|
export class Web3Wrapper {
|
||||||
private web3: Web3;
|
private web3: Web3;
|
||||||
@ -20,6 +22,11 @@ export class Web3Wrapper {
|
|||||||
const firstAccount = await this.getFirstAddressIfExistsAsync();
|
const firstAccount = await this.getFirstAddressIfExistsAsync();
|
||||||
return firstAccount;
|
return firstAccount;
|
||||||
}
|
}
|
||||||
|
public async getSenderAddressOrThrowAsync(): Promise<string> {
|
||||||
|
const senderAddressIfExists = await this.getSenderAddressIfExistsAsync();
|
||||||
|
assert.assert(!_.isUndefined(senderAddressIfExists), ZeroExError.USER_HAS_NO_ASSOCIATED_ADDRESSES);
|
||||||
|
return senderAddressIfExists as string;
|
||||||
|
}
|
||||||
public async getFirstAddressIfExistsAsync(): Promise<string|undefined> {
|
public async getFirstAddressIfExistsAsync(): Promise<string|undefined> {
|
||||||
const addresses = await promisify(this.web3.eth.getAccounts)();
|
const addresses = await promisify(this.web3.eth.getAccounts)();
|
||||||
if (_.isEmpty(addresses)) {
|
if (_.isEmpty(addresses)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user