diff options
Diffstat (limited to 'src/web3_wrapper.ts')
-rw-r--r-- | src/web3_wrapper.ts | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index e65f29b56..93203ff38 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -24,11 +24,15 @@ export class Web3Wrapper { return firstAccount; } public async getFirstAddressIfExistsAsync(): Promise<string|undefined> { - const addresses = await promisify(this.web3.eth.getAccounts)(); + const addresses = await this.getAvailableSenderAddressesAsync(); if (_.isEmpty(addresses)) { return undefined; } - return (addresses as string[])[0]; + return addresses[0]; + } + public async isSenderAddressAvailable(senderAddress: string): Promise<boolean> { + const addresses = await this.getAvailableSenderAddressesAsync(); + return _.includes(addresses, senderAddress); } public async getNodeVersionAsync(): Promise<string> { const nodeVersion = await promisify(this.web3.version.getNode)(); @@ -64,6 +68,10 @@ export class Web3Wrapper { const {timestamp} = await promisify(this.web3.eth.getBlock)(blockHash); return timestamp; } + private async getAvailableSenderAddressesAsync(): Promise<string[]> { + const addresses: string[] = await promisify(this.web3.eth.getAccounts)(); + return addresses; + } private async getNetworkAsync(): Promise<number> { const networkId = await promisify(this.web3.version.getNetwork)(); return networkId; |