From 7dddf2010e16167260f7ffbb7c7d2fd83609d8a0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 29 May 2017 22:14:18 +0200 Subject: Add getExchangeInstanceOrThrowAsync && getSenderAddressOrThrowAsync --- src/web3_wrapper.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/web3_wrapper.ts') diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 3b460e4da..72daabe6f 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; @@ -20,6 +22,11 @@ export class Web3Wrapper { const firstAccount = await this.getFirstAddressIfExistsAsync(); return firstAccount; } + public async getSenderAddressOrThrowAsync(): Promise { + const senderAddressIfExists = await this.getSenderAddressIfExistsAsync(); + assert.assert(!_.isUndefined(senderAddressIfExists), ZeroExError.USER_HAS_NO_ASSOCIATED_ADDRESSES); + return senderAddressIfExists as string; + } public async getFirstAddressIfExistsAsync(): Promise { const addresses = await promisify(this.web3.eth.getAccounts)(); if (_.isEmpty(addresses)) { -- cgit v1.2.3 From 1955e90bbbfeb7d2aeebfd84132f684d20e17400 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 31 May 2017 16:15:16 +0200 Subject: Fix linter errors --- src/web3_wrapper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/web3_wrapper.ts') diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 361f28476..79fd166ec 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -2,8 +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"; +import {ZeroExError} from './types'; +import {assert} from './utils/assert'; export class Web3Wrapper { private web3: Web3; -- cgit v1.2.3 From f450f538a0af0b4c85eefdd81c4983f40d230a33 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 1 Jun 2017 11:07:36 +0200 Subject: Add setDefaultAccount --- src/web3_wrapper.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/web3_wrapper.ts') diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 79fd166ec..70e77dbe3 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -17,6 +17,9 @@ export class Web3Wrapper { public isAddress(address: string): boolean { return this.web3.isAddress(address); } + public setDefaultAccount(address: string): void { + this.web3.eth.defaultAccount = address; + } public async getSenderAddressIfExistsAsync(): Promise { const defaultAccount = this.web3.eth.defaultAccount; if (!_.isUndefined(defaultAccount)) { -- cgit v1.2.3 From a1041348d5695ee3b84433e9874176e85543a4e0 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 1 Jun 2017 16:07:43 +0200 Subject: Get getSenderAddressOrThrowAsync everywhere where we throw if the senderAddress doesn't exist --- src/web3_wrapper.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/web3_wrapper.ts') diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 70e77dbe3..c1263222a 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -20,14 +20,6 @@ export class Web3Wrapper { public setDefaultAccount(address: string): void { this.web3.eth.defaultAccount = address; } - public async getSenderAddressIfExistsAsync(): Promise { - const defaultAccount = this.web3.eth.defaultAccount; - if (!_.isUndefined(defaultAccount)) { - return defaultAccount; - } - const firstAccount = await this.getFirstAddressIfExistsAsync(); - return firstAccount; - } public async getSenderAddressOrThrowAsync(): Promise { const senderAddressIfExists = await this.getSenderAddressIfExistsAsync(); assert.assert(!_.isUndefined(senderAddressIfExists), ZeroExError.USER_HAS_NO_ASSOCIATED_ADDRESSES); @@ -74,6 +66,14 @@ export class Web3Wrapper { const {timestamp} = await promisify(this.web3.eth.getBlock)(blockHash); return timestamp; } + private async getSenderAddressIfExistsAsync(): Promise { + const defaultAccount = this.web3.eth.defaultAccount; + if (!_.isUndefined(defaultAccount)) { + return defaultAccount; + } + const firstAccount = await this.getFirstAddressIfExistsAsync(); + return firstAccount; + } private async getNetworkAsync(): Promise { const networkId = await promisify(this.web3.version.getNetwork)(); return networkId; -- cgit v1.2.3 From a740498c8061bc7a3dafae82929b358e61bac2d4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 2 Jun 2017 11:23:39 +0200 Subject: Introduce coinBase account Add makerAccount parameter Adjust tests Add more assertions to success test --- src/web3_wrapper.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/web3_wrapper.ts') diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index c1263222a..900c127d5 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -17,6 +17,9 @@ export class Web3Wrapper { public isAddress(address: string): boolean { return this.web3.isAddress(address); } + public getDefaultAccount(): string { + return this.web3.eth.defaultAccount; + } public setDefaultAccount(address: string): void { this.web3.eth.defaultAccount = address; } -- cgit v1.2.3 From fc7592d73f1613b11e4b48904bfb041cccca5800 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 2 Jun 2017 12:15:50 +0200 Subject: Fix getTransactionSenderAccountIfExistsAsync to return true senderAddress or undefined if non available --- src/web3_wrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/web3_wrapper.ts') diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 900c127d5..49bd8b67d 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -69,7 +69,7 @@ export class Web3Wrapper { const {timestamp} = await promisify(this.web3.eth.getBlock)(blockHash); return timestamp; } - private async getSenderAddressIfExistsAsync(): Promise { + public async getSenderAddressIfExistsAsync(): Promise { const defaultAccount = this.web3.eth.defaultAccount; if (!_.isUndefined(defaultAccount)) { return defaultAccount; -- cgit v1.2.3