diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-04 20:36:57 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-05 20:35:37 +0800 |
commit | e37a3155cd52d35da3eef9a8dc450b9b3df0b888 (patch) | |
tree | de2e57b09c63e734d81f7635d7cd9c2ffe2a46de | |
parent | 542cf7b1cb04cd86da86fc1ff39fdcbd1b9b0403 (diff) | |
download | dexon-sol-tools-e37a3155cd52d35da3eef9a8dc450b9b3df0b888.tar.gz dexon-sol-tools-e37a3155cd52d35da3eef9a8dc450b9b3df0b888.tar.zst dexon-sol-tools-e37a3155cd52d35da3eef9a8dc450b9b3df0b888.zip |
Instantiate logAndBlockStreamer
-rw-r--r-- | package.json | 3 | ||||
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 7 | ||||
-rw-r--r-- | src/web3_wrapper.ts | 8 | ||||
-rw-r--r-- | yarn.lock | 22 |
4 files changed, 37 insertions, 3 deletions
diff --git a/package.json b/package.json index 82bca114d..011e974c0 100644 --- a/package.json +++ b/package.json @@ -89,12 +89,13 @@ "webpack": "^3.1.0" }, "dependencies": { - "@types/bignumber.js": "^4.0.2", "0x-json-schemas": "^0.6.1", + "@types/bignumber.js": "^4.0.2", "bignumber.js": "^4.0.2", "compare-versions": "^3.0.1", "es6-promisify": "^5.0.0", "ethereumjs-abi": "^0.6.4", + "ethereumjs-blockstream": "^2.0.6", "ethereumjs-util": "^5.1.1", "find-versions": "^2.0.0", "lodash": "^4.17.4", diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index 743dfc9b2..927a09b52 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -1,6 +1,7 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import * as ethUtil from 'ethereumjs-util'; +import {BlockAndLogStreamer} from 'ethereumjs-blockstream'; import {Web3Wrapper} from '../web3_wrapper'; import {AbiDecoder} from '../utils/abi_decoder'; import { @@ -19,9 +20,15 @@ const TOPIC_LENGTH = 32; export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; private _abiDecoder?: AbiDecoder; + private _blockAndLogStreamer: BlockAndLogStreamer; constructor(web3Wrapper: Web3Wrapper, abiDecoder?: AbiDecoder) { this._web3Wrapper = web3Wrapper; this._abiDecoder = abiDecoder; + const getBlockAsync = async (hash: string) => this._web3Wrapper.getBlockAsync(hash); + this._blockAndLogStreamer = new BlockAndLogStreamer( + this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper), + this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper), + ); } protected async _getLogsAsync(address: string, eventName: ContractEvents, subscriptionOpts: SubscriptionOpts, indexFilterValues: IndexedFilterValues, diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 7576f3d40..fd9b74b8b 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -94,8 +94,12 @@ export class Web3Wrapper { const signData = await promisify(this.web3.eth.sign)(address, message); return signData; } - public async getBlockTimestampAsync(blockHash: string): Promise<number> { - const {timestamp} = await promisify(this.web3.eth.getBlock)(blockHash); + public async getBlockAsync(blockParam: string|Web3.BlockParam): Promise<Web3.BlockWithoutTransactionData> { + const block = await promisify(this.web3.eth.getBlock)(blockParam); + return block; + } + public async getBlockTimestampAsync(blockParam: string|Web3.BlockParam): Promise<number> { + const {timestamp} = await this.getBlockAsync(blockParam); return timestamp; } public async getAvailableAddressesAsync(): Promise<string[]> { @@ -1675,6 +1675,14 @@ ethereumjs-block@^1.2.2: ethereumjs-util "^5.0.0" merkle-patricia-tree "^2.1.2" +ethereumjs-blockstream@^2.0.6: + version "2.0.6" + resolved "https://registry.yarnpkg.com/ethereumjs-blockstream/-/ethereumjs-blockstream-2.0.6.tgz#12c37ad5ac138d1d0abd60e7f4fa4344739f7e8b" + dependencies: + immutable "3.8.1" + source-map-support "0.4.14" + uuid "3.0.1" + ethereumjs-testrpc@4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/ethereumjs-testrpc/-/ethereumjs-testrpc-4.0.1.tgz#af23babff4c36008418bc6de4c80f81606896cad" @@ -2297,6 +2305,10 @@ immediate@^3.2.3: version "3.2.3" resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.2.3.tgz#d140fa8f614659bd6541233097ddaac25cdd991c" +immutable@3.8.1: + version "3.8.1" + resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.8.1.tgz#200807f11ab0f72710ea485542de088075f68cd2" + imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" @@ -4270,6 +4282,12 @@ source-map-resolve@^0.5.0: source-map-url "^0.4.0" urix "^0.1.0" +source-map-support@0.4.14: + version "0.4.14" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.14.tgz#9d4463772598b86271b4f523f6c1f4e02a7d6aef" + dependencies: + source-map "^0.5.6" + source-map-support@^0.4.15, source-map-support@^0.4.2: version "0.4.15" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.15.tgz#03202df65c06d2bd8c7ec2362a193056fef8d3b1" @@ -4860,6 +4878,10 @@ util@0.10.3, util@^0.10.3: dependencies: inherits "2.0.1" +uuid@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1" + uuid@^2.0.1: version "2.0.3" resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a" |