From bd3f101ab8735f97646d1031126fb9e55b67a93d Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 10:06:34 -0400 Subject: Added orderWatchCount to return total count of orders watched. --- .../order-watcher/src/order_watcher/order_watcher.ts | 3 +++ packages/order-watcher/test/order_watcher_test.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index f9a63efe3..9b2999285 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -213,6 +213,9 @@ export class OrderWatcher { this._expirationWatcher.unsubscribe(); intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists); } + public getWatchCount(): number { + return _.size(this._orderByOrderHash); + } private async _cleanupAsync(): Promise { for (const orderHash of _.keys(this._orderByOrderHash)) { this._cleanupOrderRelatedState(orderHash); diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index 60d9069e8..f504dda8e 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -140,6 +140,23 @@ describe('OrderWatcher', () => { expect(() => orderWatcher.subscribe(_.noop.bind(_))).to.throw(OrderWatcherError.SubscriptionAlreadyPresent); }); }); + describe('#getWatchCount', async () => { + it('should increment and decrement order counts', async() => { + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerAssetData, + takerAssetData, + makerAddress, + takerAddress, + fillableAmount, + ); + const orderHash = orderHashUtils.getOrderHashHex(signedOrder); + expect(orderWatcher.getWatchCount()).to.be.eq(0); + await orderWatcher.addOrderAsync(signedOrder); + expect(orderWatcher.getWatchCount()).to.be.eq(1); + orderWatcher.removeOrder(orderHash); + expect(orderWatcher.getWatchCount()).to.be.eq(0); + }); + }); describe('tests with cleanup', async () => { afterEach(async () => { orderWatcher.unsubscribe(); -- cgit v1.2.3 From c833b4f49448dacade229f9af4530020dc30a57a Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 10:23:16 -0400 Subject: Added comments to new getWatchCounts function --- packages/order-watcher/src/order_watcher/order_watcher.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index 9b2999285..ac811a4c4 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -213,6 +213,10 @@ export class OrderWatcher { this._expirationWatcher.unsubscribe(); intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists); } + /** + * Gets number of orderHashes currently being watched by the order watcher instance. + * @returns {number} + */ public getWatchCount(): number { return _.size(this._orderByOrderHash); } -- cgit v1.2.3 From ee0f2e46ee0b7c62225e09b54a3e13607214ae20 Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 10:32:07 -0400 Subject: Update order-watcher changelog --- packages/order-watcher/CHANGELOG.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index ce56e492c..6d1256d9e 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "2.1.2", + "changes": [ + { + "note": "Added getWatchCounts function" + } + ], + "timestamp": 1538836030 + }, { "version": "2.1.1", "changes": [ -- cgit v1.2.3 From d0fed1ae464301cb26df16053991e667598b640e Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 10:43:36 -0400 Subject: Fixed linting issue --- packages/order-watcher/src/order_watcher/order_watcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index ac811a4c4..5ddfdd047 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -215,7 +215,7 @@ export class OrderWatcher { } /** * Gets number of orderHashes currently being watched by the order watcher instance. - * @returns {number} + * @returns {number} Number of hashes in _orderByOrderHash */ public getWatchCount(): number { return _.size(this._orderByOrderHash); -- cgit v1.2.3 From 9171f9ec600b04134e0f86741e60a973618839b5 Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 11:04:48 -0400 Subject: Fix lint issues --- packages/order-watcher/src/order_watcher/order_watcher.ts | 1 - packages/order-watcher/test/order_watcher_test.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index 5ddfdd047..e59b56b90 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -215,7 +215,6 @@ export class OrderWatcher { } /** * Gets number of orderHashes currently being watched by the order watcher instance. - * @returns {number} Number of hashes in _orderByOrderHash */ public getWatchCount(): number { return _.size(this._orderByOrderHash); diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index f504dda8e..f1dbe9b2f 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -141,7 +141,7 @@ describe('OrderWatcher', () => { }); }); describe('#getWatchCount', async () => { - it('should increment and decrement order counts', async() => { + it('should increment and decrement order counts', async () => { signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerAssetData, takerAssetData, -- cgit v1.2.3 From 2e1222556ff8bd3923a5e91174f7d6bd92d6a02c Mon Sep 17 00:00:00 2001 From: amaurer Date: Sun, 7 Oct 2018 12:24:42 -0400 Subject: Changed getWatchedOrders to getStats and returns Stats object --- packages/order-watcher/CHANGELOG.json | 2 +- packages/order-watcher/src/order_watcher/order_watcher.ts | 12 +++++++++--- packages/order-watcher/test/order_watcher_test.ts | 10 +++++----- packages/types/src/index.ts | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index 6d1256d9e..7b8416428 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -3,7 +3,7 @@ "version": "2.1.2", "changes": [ { - "note": "Added getWatchCounts function" + "note": "Added getStats function and returns a Stats object" } ], "timestamp": 1538836030 diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index e59b56b90..4401b3f7e 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -57,6 +57,10 @@ interface OrderStateByOrderHash { [orderHash: string]: OrderState; } +export interface Stats { + orderCount: number; +} + const DEFAULT_ORDER_WATCHER_CONFIG: OrderWatcherConfig = { orderExpirationCheckingIntervalMs: 50, eventPollingIntervalMs: 200, @@ -214,10 +218,12 @@ export class OrderWatcher { intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists); } /** - * Gets number of orderHashes currently being watched by the order watcher instance. + * Gets statistics of the OrderWatcher Instance. */ - public getWatchCount(): number { - return _.size(this._orderByOrderHash); + public getStats(): Stats { + return { + orderCount : _.size(this._orderByOrderHash), + }; } private async _cleanupAsync(): Promise { for (const orderHash of _.keys(this._orderByOrderHash)) { diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index f1dbe9b2f..4545f84bf 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -140,8 +140,8 @@ describe('OrderWatcher', () => { expect(() => orderWatcher.subscribe(_.noop.bind(_))).to.throw(OrderWatcherError.SubscriptionAlreadyPresent); }); }); - describe('#getWatchCount', async () => { - it('should increment and decrement order counts', async () => { + describe('#getStats', async () => { + it('orderCount should increment and decrement with order additions and removals', async () => { signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerAssetData, takerAssetData, @@ -150,11 +150,11 @@ describe('OrderWatcher', () => { fillableAmount, ); const orderHash = orderHashUtils.getOrderHashHex(signedOrder); - expect(orderWatcher.getWatchCount()).to.be.eq(0); + expect(orderWatcher.getStats().orderCount).to.be.eq(0); await orderWatcher.addOrderAsync(signedOrder); - expect(orderWatcher.getWatchCount()).to.be.eq(1); + expect(orderWatcher.getStats().orderCount).to.be.eq(1); orderWatcher.removeOrder(orderHash); - expect(orderWatcher.getWatchCount()).to.be.eq(0); + expect(orderWatcher.getStats().orderCount).to.be.eq(0); }); }); describe('tests with cleanup', async () => { diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 3ae0536d5..0ea7d433a 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -598,4 +598,4 @@ export interface Metadata { exportPathOrder: string[]; externalTypeToLink: ExternalTypeToLink; externalExportToLink: ExternalExportToLink; -} +} \ No newline at end of file -- cgit v1.2.3 From e5192507ab6597a93c45526cca092896641610f0 Mon Sep 17 00:00:00 2001 From: amaurer Date: Sun, 7 Oct 2018 12:31:51 -0400 Subject: Fixed accidental carriage return removal in index.ts --- packages/types/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 0ea7d433a..3ae0536d5 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -598,4 +598,4 @@ export interface Metadata { exportPathOrder: string[]; externalTypeToLink: ExternalTypeToLink; externalExportToLink: ExternalExportToLink; -} \ No newline at end of file +} -- cgit v1.2.3 From cd04a21e29cc5713c1932b754d9a8f5c5172f960 Mon Sep 17 00:00:00 2001 From: amaurer Date: Fri, 12 Oct 2018 11:55:31 -0400 Subject: Fixes per converstaion, stats interface to pub --- packages/order-watcher/CHANGELOG.json | 6 +++--- packages/order-watcher/src/order_watcher/order_watcher.ts | 8 ++------ packages/types/src/index.ts | 4 ++++ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index 7b8416428..feebb9d69 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -3,10 +3,10 @@ "version": "2.1.2", "changes": [ { - "note": "Added getStats function and returns a Stats object" + "note": "Added getStats function and returns a Stats object", + "pr": 1118 } - ], - "timestamp": 1538836030 + ] }, { "version": "2.1.1", diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index 4401b3f7e..eb37bd617 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -30,7 +30,7 @@ import { orderHashUtils, OrderStateUtils, } from '@0xproject/order-utils'; -import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder } from '@0xproject/types'; +import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder, Stats } from '@0xproject/types'; import { errorUtils, intervalUtils } from '@0xproject/utils'; import { BlockParamLiteral, LogEntryEvent, LogWithDecodedArgs, Provider } from 'ethereum-types'; import * as _ from 'lodash'; @@ -57,10 +57,6 @@ interface OrderStateByOrderHash { [orderHash: string]: OrderState; } -export interface Stats { - orderCount: number; -} - const DEFAULT_ORDER_WATCHER_CONFIG: OrderWatcherConfig = { orderExpirationCheckingIntervalMs: 50, eventPollingIntervalMs: 200, @@ -222,7 +218,7 @@ export class OrderWatcher { */ public getStats(): Stats { return { - orderCount : _.size(this._orderByOrderHash), + orderCount: _.size(this._orderByOrderHash), }; } private async _cleanupAsync(): Promise { diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 3ae0536d5..6f539fc1f 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -599,3 +599,7 @@ export interface Metadata { externalTypeToLink: ExternalTypeToLink; externalExportToLink: ExternalExportToLink; } + +export interface Stats { + orderCount: number; +} -- cgit v1.2.3 From dc56ce454967d2bf0d5e8c93389c0fa71a9d1cc5 Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 13 Oct 2018 08:47:37 -0400 Subject: Exported Stats in OW package --- packages/order-watcher/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/order-watcher/src/index.ts b/packages/order-watcher/src/index.ts index d7ad4fba7..4a1b5012b 100644 --- a/packages/order-watcher/src/index.ts +++ b/packages/order-watcher/src/index.ts @@ -7,6 +7,7 @@ export { OrderState, ExchangeContractErrs, OrderRelevantState, + Stats, } from '@0xproject/types'; export { OnOrderStateChangeCallback, OrderWatcherConfig } from './types'; -- cgit v1.2.3