diff options
author | Fabio Berger <me@fabioberger.com> | 2017-06-02 00:14:17 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-06-02 00:14:17 +0800 |
commit | acb8a6c55ee2c97db5d738621929feea759465b3 (patch) | |
tree | 57cfa925d645cb11bb1731381be56d0f66f8f0f1 /src/web3_wrapper.ts | |
parent | ecf92a4ad786a324d4c8ce9dba926f377766a144 (diff) | |
parent | 389c18e98e2b5663b1732d7c34f9b21afef66e44 (diff) | |
download | dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar.gz dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar.bz2 dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar.lz dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar.xz dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar.zst dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.zip |
Merge branch 'fillOrderAsync' into unavailableFilledCancelled
# Conflicts:
# src/contract_wrappers/exchange_wrapper.ts
# src/types.ts
# src/utils/assert.ts
Diffstat (limited to 'src/web3_wrapper.ts')
-rw-r--r-- | src/web3_wrapper.ts | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index e65f29b56..c1263222a 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -2,6 +2,8 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import * as BigNumber from 'bignumber.js'; import promisify = require('es6-promisify'); +import {ZeroExError} from './types'; +import {assert} from './utils/assert'; export class Web3Wrapper { private web3: Web3; @@ -15,13 +17,13 @@ export class Web3Wrapper { public isAddress(address: string): boolean { return this.web3.isAddress(address); } - public async getSenderAddressIfExistsAsync(): Promise<string|undefined> { - const defaultAccount = this.web3.eth.defaultAccount; - if (!_.isUndefined(defaultAccount)) { - return defaultAccount; - } - const firstAccount = await this.getFirstAddressIfExistsAsync(); - return firstAccount; + public setDefaultAccount(address: string): void { + this.web3.eth.defaultAccount = address; + } + 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> { const addresses = await promisify(this.web3.eth.getAccounts)(); @@ -64,6 +66,14 @@ export class Web3Wrapper { const {timestamp} = await promisify(this.web3.eth.getBlock)(blockHash); return timestamp; } + private async getSenderAddressIfExistsAsync(): Promise<string|undefined> { + const defaultAccount = this.web3.eth.defaultAccount; + if (!_.isUndefined(defaultAccount)) { + return defaultAccount; + } + const firstAccount = await this.getFirstAddressIfExistsAsync(); + return firstAccount; + } private async getNetworkAsync(): Promise<number> { const networkId = await promisify(this.web3.version.getNetwork)(); return networkId; |