From a12069f03fb1c1c93884c2e168917d229f7864e9 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 14 Nov 2017 10:56:57 -0500 Subject: Callback for subscribe no longer supports an Async Callback --- packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 3 +-- packages/0x.js/src/index.ts | 2 -- packages/0x.js/src/order_watcher/event_watcher.ts | 2 +- packages/0x.js/src/types.ts | 9 ++------- 4 files changed, 4 insertions(+), 12 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 7997b1647..bd65c8eb3 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -52,8 +52,7 @@ export class ContractWrapper { throw new Error(ZeroExError.SubscriptionNotFound); } if (!_.isUndefined(err)) { - const callback = this._filterCallbacks[filterToken]; - callback(err, undefined); + this._filterCallbacks[filterToken](err, undefined); } delete this._filters[filterToken]; delete this._filterCallbacks[filterToken]; diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 1b3e893ba..e529e2858 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -6,8 +6,6 @@ export { ECSignature, ZeroExError, EventCallback, - EventCallbackAsync, - EventCallbackSync, ExchangeContractErrs, ContractEvent, Token, diff --git a/packages/0x.js/src/order_watcher/event_watcher.ts b/packages/0x.js/src/order_watcher/event_watcher.ts index 81529a98c..c39431f6d 100644 --- a/packages/0x.js/src/order_watcher/event_watcher.ts +++ b/packages/0x.js/src/order_watcher/event_watcher.ts @@ -81,7 +81,7 @@ export class EventWatcher { ...log, }; if (!_.isUndefined(this._intervalIdIfExists)) { - await callback(logEvent); + callback(logEvent); } } } diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 11b5d8569..04dfe3b0d 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -42,13 +42,8 @@ export type OrderValues = [BigNumber, BigNumber, BigNumber, export type LogEvent = Web3.LogEntryEvent; export type DecodedLogEvent = Web3.DecodedLogEntryEvent; -export type EventCallbackAsync = (err: null|Error, log?: DecodedLogEvent) => Promise; -export type EventCallbackSync = (err: null|Error, log?: DecodedLogEvent) => void; -export type EventCallback = EventCallbackSync|EventCallbackAsync; - -export type EventWatcherCallbackSync = (log: LogEvent) => void; -export type EventWatcherCallbackAsync = (log: LogEvent) => Promise; -export type EventWatcherCallback = EventWatcherCallbackSync|EventWatcherCallbackAsync; +export type EventCallback = (err: null|Error, log?: DecodedLogEvent) => void; +export type EventWatcherCallback = (log: LogEvent) => void; export interface ExchangeContract extends Web3.ContractInstance { isValidSignature: { -- cgit v1.2.3 From 8f4be963b2f16351b6f55513e190e1e287328911 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 14 Nov 2017 11:09:37 -0500 Subject: Update changelog --- packages/0x.js/CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index a9362151c..9c795cf5a 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +v0.25.0 - _November 14, 2017_ +------------------------ + * Remove support for Async callback types when used in Subscribe functions + v0.24.0 - _November 13, 2017_ ------------------------ * Standardise on Cancelled over Canceled @@ -7,7 +11,7 @@ v0.24.0 - _November 13, 2017_ v0.23.0 - _November 12, 2017_ ------------------------ * Fixed unhandled promise rejection error in subscribe methods (#209) - * Subscribe callbacks now receive an error object as their first argument + * Subscribe callbacks now receive an error object as their first argument v0.22.6 - _November 10, 2017_ ------------------------ -- cgit v1.2.3 From 752603284de28f8d966fe61a52d0ffe5dd8afd6a Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 14 Nov 2017 11:21:00 -0500 Subject: Remove Async subscribe callbacks from OrderWatcher --- packages/0x.js/src/order_watcher/order_state_watcher.ts | 14 +++++++------- packages/0x.js/src/types.ts | 4 +--- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 2b9d7997e..80f323017 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -52,7 +52,7 @@ interface OrderByOrderHash { export class OrderStateWatcher { private _orderByOrderHash: OrderByOrderHash = {}; private _dependentOrderHashes: DependentOrderHashes = {}; - private _callbackIfExistsAsync?: OnOrderStateChangeCallback; + private _callbackIfExists?: OnOrderStateChangeCallback; private _eventWatcher: EventWatcher; private _web3Wrapper: Web3Wrapper; private _abiDecoder: AbiDecoder; @@ -106,22 +106,22 @@ export class OrderStateWatcher { */ public subscribe(callback: OnOrderStateChangeCallback): void { assert.isFunction('callback', callback); - if (!_.isUndefined(this._callbackIfExistsAsync)) { + if (!_.isUndefined(this._callbackIfExists)) { throw new Error(ZeroExError.SubscriptionAlreadyPresent); } - this._callbackIfExistsAsync = callback; + this._callbackIfExists = callback; this._eventWatcher.subscribe(this._onEventWatcherCallbackAsync.bind(this)); } /** * Ends an orderStateWatcher subscription. */ public unsubscribe(): void { - if (_.isUndefined(this._callbackIfExistsAsync)) { + if (_.isUndefined(this._callbackIfExists)) { throw new Error(ZeroExError.SubscriptionNotFound); } this._balanceAndProxyAllowanceLazyStore.deleteAll(); this._orderFilledCancelledLazyStore.deleteAll(); - delete this._callbackIfExistsAsync; + delete this._callbackIfExists; this._eventWatcher.unsubscribe(); } private async _onEventWatcherCallbackAsync(log: LogEvent): Promise { @@ -204,10 +204,10 @@ export class OrderStateWatcher { // Most of these calls will never reach the network because the data is fetched from stores // and only updated when cache is invalidated const orderState = await this._orderStateUtils.getOrderStateAsync(signedOrder); - if (_.isUndefined(this._callbackIfExistsAsync)) { + if (_.isUndefined(this._callbackIfExists)) { break; // Unsubscribe was called } - await this._callbackIfExistsAsync(orderState); + this._callbackIfExists(orderState); } } private addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string) { diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 04dfe3b0d..91e3c0f20 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -501,9 +501,7 @@ export interface OrderStateInvalid { export type OrderState = OrderStateValid|OrderStateInvalid; -export type OnOrderStateChangeCallbackSync = (orderState: OrderState) => void; -export type OnOrderStateChangeCallbackAsync = (orderState: OrderState) => Promise; -export type OnOrderStateChangeCallback = OnOrderStateChangeCallbackAsync|OnOrderStateChangeCallbackSync; +export type OnOrderStateChangeCallback = (orderState: OrderState) => void; export interface TransactionReceipt { blockHash: string; -- cgit v1.2.3 From 3f39b22a680958988fbd7a8382dcd8d26420307f Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 14 Nov 2017 21:20:31 -0500 Subject: separate assignment and call --- packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index bd65c8eb3..7997b1647 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -52,7 +52,8 @@ export class ContractWrapper { throw new Error(ZeroExError.SubscriptionNotFound); } if (!_.isUndefined(err)) { - this._filterCallbacks[filterToken](err, undefined); + const callback = this._filterCallbacks[filterToken]; + callback(err, undefined); } delete this._filters[filterToken]; delete this._filterCallbacks[filterToken]; -- cgit v1.2.3 From 471abfa76033c4cc6cbea0f0308c5b313303f6b9 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 15 Nov 2017 12:08:12 -0500 Subject: Add and Remove Fee Token with Maker Token --- .../0x.js/src/order_watcher/order_state_watcher.ts | 25 +++++++---- packages/0x.js/test/order_state_watcher_test.ts | 48 +++++++++++++++------- 2 files changed, 50 insertions(+), 23 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index bafd7a994..421524808 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -78,24 +78,27 @@ export class OrderStateWatcher { * signature is verified. * @param signedOrder The order you wish to start watching. */ - public addOrder(signedOrder: SignedOrder): void { + public async addOrder(signedOrder: SignedOrder): Promise { assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema); const orderHash = ZeroEx.getOrderHashHex(signedOrder); assert.isValidSignature(orderHash, signedOrder.ecSignature, signedOrder.maker); this._orderByOrderHash[orderHash] = signedOrder; - this.addToDependentOrderHashes(signedOrder, orderHash); + await this.addToDependentOrderHashes(signedOrder, orderHash); } /** * Removes an order from the orderStateWatcher * @param orderHash The orderHash of the order you wish to stop watching. */ - public removeOrder(orderHash: string): void { + public async removeOrder(orderHash: string): Promise { assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); const signedOrder = this._orderByOrderHash[orderHash]; if (_.isUndefined(signedOrder)) { return; // noop } delete this._orderByOrderHash[orderHash]; + const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper; + const zrxTokenAddress = await exchange.getZRXTokenAddressAsync(); + this.removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash); this.removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash); } /** @@ -210,19 +213,25 @@ export class OrderStateWatcher { await this._callbackIfExistsAsync(orderState); } } - private addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string) { + private async addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string) { if (_.isUndefined(this._dependentOrderHashes[signedOrder.maker])) { this._dependentOrderHashes[signedOrder.maker] = {}; } if (_.isUndefined(this._dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress])) { this._dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress] = new Set(); } + const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper; + const zrxTokenAddress = await exchange.getZRXTokenAddressAsync(); + if (_.isUndefined(this._dependentOrderHashes[signedOrder.maker][zrxTokenAddress])) { + this._dependentOrderHashes[signedOrder.maker][zrxTokenAddress] = new Set(); + } this._dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress].add(orderHash); + this._dependentOrderHashes[signedOrder.maker][zrxTokenAddress].add(orderHash); } - private removeFromDependentOrderHashes(makerAddress: string, makerTokenAddress: string, orderHash: string) { - this._dependentOrderHashes[makerAddress][makerTokenAddress].delete(orderHash); - if (this._dependentOrderHashes[makerAddress][makerTokenAddress].size === 0) { - delete this._dependentOrderHashes[makerAddress][makerTokenAddress]; + private removeFromDependentOrderHashes(makerAddress: string, tokenAddress: string, orderHash: string) { + this._dependentOrderHashes[makerAddress][tokenAddress].delete(orderHash); + if (this._dependentOrderHashes[makerAddress][tokenAddress].size === 0) { + delete this._dependentOrderHashes[makerAddress][tokenAddress]; } if (_.isEmpty(this._dependentOrderHashes[makerAddress])) { delete this._dependentOrderHashes[makerAddress]; diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index a112bac1d..1d47dcdfe 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -73,13 +73,13 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); expect((zeroEx.orderStateWatcher as any)._orderByOrderHash).to.include({ [orderHash]: signedOrder, }); let dependentOrderHashes = (zeroEx.orderStateWatcher as any)._dependentOrderHashes; expect(dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress]).to.have.keys(orderHash); - zeroEx.orderStateWatcher.removeOrder(orderHash); + await zeroEx.orderStateWatcher.removeOrder(orderHash); expect((zeroEx.orderStateWatcher as any)._orderByOrderHash).to.not.include({ [orderHash]: signedOrder, }); @@ -92,7 +92,7 @@ describe('OrderStateWatcher', () => { ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); const nonExistentOrderHash = `0x${orderHash.substr(2).split('').reverse().join('')}`; - zeroEx.orderStateWatcher.removeOrder(nonExistentOrderHash); + await zeroEx.orderStateWatcher.removeOrder(nonExistentOrderHash); }); }); describe('#subscribe', async () => { @@ -109,7 +109,7 @@ describe('OrderStateWatcher', () => { afterEach(async () => { zeroEx.orderStateWatcher.unsubscribe(); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.removeOrder(orderHash); + await zeroEx.orderStateWatcher.removeOrder(orderHash); }); it('should emit orderStateInvalid when maker allowance set to 0 for watched order', (done: DoneCallback) => { (async () => { @@ -117,7 +117,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { expect(orderState.isValid).to.be.false(); const invalidOrderState = orderState as OrderStateInvalid; @@ -135,7 +135,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { throw new Error('OrderState callback fired for irrelevant order'); }); @@ -156,7 +156,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { expect(orderState.isValid).to.be.false(); const invalidOrderState = orderState as OrderStateInvalid; @@ -176,7 +176,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); let eventCount = 0; const callback = reportCallbackErrors(done)((orderState: OrderState) => { @@ -208,7 +208,7 @@ describe('OrderStateWatcher', () => { const fillAmountInBaseUnits = new BigNumber(2); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); let eventCount = 0; const callback = reportCallbackErrors(done)((orderState: OrderState) => { @@ -235,6 +235,24 @@ describe('OrderStateWatcher', () => { ); })().catch(done); }); + it('should callback when Fee Token balance changes', (done: DoneCallback) => { + (async () => { + const makerFee = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18); + const takerFee = ZeroEx.toBaseUnitAmount(new BigNumber(0), 18); + signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync( + makerToken.address, takerToken.address, makerFee, takerFee, maker, taker, fillableAmount, + taker); + const orderHash = ZeroEx.getOrderHashHex(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); + const callback = reportCallbackErrors(done)((orderState: OrderState) => { + const invalidOrderState = orderState as OrderStateInvalid; + expect(invalidOrderState.orderHash).to.be.equal(orderHash); + done(); + }); + zeroEx.orderStateWatcher.subscribe(callback); + await zeroEx.token.setProxyAllowanceAsync(zrxTokenAddress, maker, new BigNumber(0)); + })().catch(done); + }); describe('remainingFillable(M|T)akerTokenAmount', () => { it('should calculate correct remaining fillable', (done: DoneCallback) => { (async () => { @@ -248,7 +266,7 @@ describe('OrderStateWatcher', () => { const takerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, taker); const fillAmountInBaseUnits = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); let eventCount = 0; const callback = reportCallbackErrors(done)((orderState: OrderState) => { eventCount++; @@ -280,7 +298,7 @@ describe('OrderStateWatcher', () => { const makerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, maker); const changedMakerApprovalAmount = ZeroEx.toBaseUnitAmount(new BigNumber(3), 18); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { const validOrderState = orderState as OrderStateValid; @@ -305,7 +323,7 @@ describe('OrderStateWatcher', () => { const remainingAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); const transferAmount = makerBalance.sub(remainingAmount); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { const validOrderState = orderState as OrderStateValid; @@ -328,7 +346,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { expect(orderState.isValid).to.be.false(); @@ -350,7 +368,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { expect(orderState.isValid).to.be.false(); @@ -376,7 +394,7 @@ describe('OrderStateWatcher', () => { const cancelAmountInBaseUnits = new BigNumber(2); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrder(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { expect(orderState.isValid).to.be.true(); -- cgit v1.2.3 From 4c505b647019b02a3080142ee2b89642c4fb4cd8 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 15 Nov 2017 12:09:27 -0500 Subject: Add a pending changelog --- packages/0x.js/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 892a0863e..3b90691a7 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +Pending +------------------------ + * Subscribe to ZRX Token Transfer and Approval events when maker token is different + v0.25.1 - _November 13, 2017_ ------------------------ * Standardise on Cancelled over Canceled -- cgit v1.2.3 From 1e1b14edc575e4daa485692fd4ceea977d3c099c Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 15 Nov 2017 12:12:01 -0500 Subject: test wording --- packages/0x.js/test/order_state_watcher_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index 1d47dcdfe..0823ac837 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -235,7 +235,7 @@ describe('OrderStateWatcher', () => { ); })().catch(done); }); - it('should callback when Fee Token balance changes', (done: DoneCallback) => { + it('should callback when Fee Token transferrable changes', (done: DoneCallback) => { (async () => { const makerFee = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18); const takerFee = ZeroEx.toBaseUnitAmount(new BigNumber(0), 18); -- cgit v1.2.3 From ee8042b4584793aba35c969b74274f60d76c95df Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 15 Nov 2017 14:40:43 -0500 Subject: Add return type --- packages/0x.js/CHANGELOG.md | 2 +- packages/0x.js/src/order_watcher/order_state_watcher.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 3b90691a7..56a1e1ab0 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -2,7 +2,7 @@ Pending ------------------------ - * Subscribe to ZRX Token Transfer and Approval events when maker token is different + * In OrderWatcher subscribe to ZRX Token Transfer and Approval events when maker token is different (#225) v0.25.1 - _November 13, 2017_ ------------------------ diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 421524808..9f756dbc3 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -213,7 +213,7 @@ export class OrderStateWatcher { await this._callbackIfExistsAsync(orderState); } } - private async addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string) { + private async addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string): Promise { if (_.isUndefined(this._dependentOrderHashes[signedOrder.maker])) { this._dependentOrderHashes[signedOrder.maker] = {}; } -- cgit v1.2.3 From a9fbe921a04d2828bd17a60598a3eee0ec63445b Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 15 Nov 2017 15:14:20 -0500 Subject: WIP --- packages/0x.js/package.json | 14 +++++++------- packages/0x.js/scripts/postpublish.js | 32 ++++++++++++++++++++++++++++++++ packages/assert/package.json | 6 +++--- packages/json-schemas/package.json | 4 ++-- packages/tslint-config/package.json | 2 +- 5 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 packages/0x.js/scripts/postpublish.js (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 0204d723f..e2b19a440 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -14,10 +14,8 @@ "scripts": { "prebuild": "npm run clean", "build": "run-p build:umd:prod build:commonjs; exit 0;", - "prepublishOnly": "run-p build", - "postpublish": "run-s release docs:json upload_docs_json", - "release": "publish-release --assets _bundles/index.js,_bundles/index.min.js --tag $(git describe --tags) --owner 0xProject --repo 0x.js", - "upload_docs_json": "aws s3 cp docs/index.json s3://0xjs-docs-jsons/$(git describe --tags).json --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json", + "release": "publish-release --assets _bundles/index.js,_bundles/index.min.js --tag $LATEST_TAG --owner 0xProject --repo 0x.js", + "upload_docs_json": "aws s3 cp docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json", "lint": "tslint src/**/*.ts test/**/*.ts", "test:circleci": "run-s test:coverage report_test_coverage; if [ $CIRCLE_BRANCH = \"development\" ]; then yarn test:umd; fi", "test": "run-s clean test:commonjs", @@ -49,13 +47,14 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.0", + "@0xproject/tslint-config": "^0.1.3", "@types/jsonschema": "^1.1.1", "@types/lodash": "^4.14.64", "@types/mocha": "^2.2.41", "@types/node": "^8.0.1", "@types/sinon": "^2.2.2", "@types/uuid": "^3.4.2", + "async-child-process": "^1.1.1", "awesome-typescript-loader": "^3.1.3", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", @@ -73,6 +72,7 @@ "opn-cli": "^3.1.0", "request": "^2.81.0", "request-promise-native": "^1.0.4", + "semver-sort": "^0.0.4", "shx": "^0.2.2", "sinon": "^4.0.0", "source-map-support": "^0.5.0", @@ -87,8 +87,8 @@ "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "^0.0.4", - "@0xproject/json-schemas": "^0.6.7", + "@0xproject/assert": "^0.0.7", + "@0xproject/json-schemas": "^0.6.10", "bignumber.js": "~4.1.0", "bn.js": "4.11.8", "compare-versions": "^3.0.1", diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js new file mode 100644 index 000000000..c2dffa920 --- /dev/null +++ b/packages/0x.js/scripts/postpublish.js @@ -0,0 +1,32 @@ +const execAsync = require('async-child-process').execAsync; +const semverSort = require('semver-sort'); + +const packagePrefix = '0x.js@'; +const gitTagsCommand = 'git tags -l "' + packagePrefix + '*"'; +let latestTag; +execAsync(gitTagsCommand) + .then(function(result) { + if (result.stderr !== '') { + throw new Error(result.stderr); + } + const tags = result.stdout.trim().split('\n'); + const versions = tags.map(function(tag) { + return tag.slice(packagePrefix.length); + }); + const sortedVersions = semverSort.desc(versions); + latestTag = packagePrefix + sortedVersions[0]; + return execAsync('LATEST_TAG=' + latestTag + ' yarn release'); + }) + .then(function(result) { + if (result.stderr !== '') { + throw new Error(result.stderr); + } + return execAsync('yarn docs:json'); + }) + .then(function(result) { + if (result.stderr !== '') { + throw new Error(result.stderr); + } + const s3Url = 's3://0xjs-docs-jsons/v' + latestTag +'.json'; + return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json'); + }); diff --git a/packages/assert/package.json b/packages/assert/package.json index ed1d2a98b..96f41e552 100644 --- a/packages/assert/package.json +++ b/packages/assert/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/assert", - "version": "0.0.4", + "version": "0.0.7", "description": "Provides a standard way of performing type and schema validation across 0x projects", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/assert/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.1.0", + "@0xproject/tslint-config": "^0.1.3", "@types/lodash": "^4.14.78", "@types/mocha": "^2.2.42", "@types/valid-url": "^1.0.2", @@ -37,7 +37,7 @@ "typescript": "^2.4.2" }, "dependencies": { - "@0xproject/json-schemas": "^0.6.7", + "@0xproject/json-schemas": "^0.6.10", "bignumber.js": "~4.1.0", "ethereum-address": "^0.0.4", "lodash": "^4.17.4", diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index 07ed20551..aa7c5d5d1 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/json-schemas", - "version": "0.6.7", + "version": "0.6.10", "description": "0x-related json schemas", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -28,7 +28,7 @@ "lodash.values": "^4.3.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.0", + "@0xproject/tslint-config": "^0.1.3", "@types/lodash.foreach": "^4.5.3", "@types/lodash.values": "^4.3.3", "@types/mocha": "^2.2.42", diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json index ca46d63fc..50adae56f 100644 --- a/packages/tslint-config/package.json +++ b/packages/tslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/tslint-config", - "version": "0.1.0", + "version": "0.1.3", "description": "Lint rules related to 0xProject for TSLint", "main": "tslint.json", "files": [ -- cgit v1.2.3 From 6096fe75d338a82a614d663f7c32ada6c6c7574f Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 15 Nov 2017 15:14:30 -0500 Subject: WIP --- packages/0x.js/package.json | 2 +- packages/0x.js/scripts/postpublish.js | 76 ++++++++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 19 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index e2b19a440..d09396a84 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -14,7 +14,6 @@ "scripts": { "prebuild": "npm run clean", "build": "run-p build:umd:prod build:commonjs; exit 0;", - "release": "publish-release --assets _bundles/index.js,_bundles/index.min.js --tag $LATEST_TAG --owner 0xProject --repo 0x.js", "upload_docs_json": "aws s3 cp docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json", "lint": "tslint src/**/*.ts test/**/*.ts", "test:circleci": "run-s test:coverage report_test_coverage; if [ $CIRCLE_BRANCH = \"development\" ]; then yarn test:umd; fi", @@ -70,6 +69,7 @@ "npm-run-all": "^4.0.2", "nyc": "^11.0.1", "opn-cli": "^3.1.0", + "prompt": "^1.0.0", "request": "^2.81.0", "request-promise-native": "^1.0.4", "semver-sort": "^0.0.4", diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index c2dffa920..ff425adbb 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -1,32 +1,72 @@ const execAsync = require('async-child-process').execAsync; const semverSort = require('semver-sort'); +const publishRelease = require('publish-release'); +const promisify = require('es6-promisify'); +const prompt = require('prompt'); -const packagePrefix = '0x.js@'; -const gitTagsCommand = 'git tags -l "' + packagePrefix + '*"'; -let latestTag; -execAsync(gitTagsCommand) +const publishReleaseAsync = promisify(publishRelease); +const promptGetAsync = promisify(prompt.get); +const subPackageName = '0x.js'; +const subPackagePrefix = subPackageName + '@'; +const githubPersonalAccessToken = process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS; +let tag; + +getLatestTagAndVersionAsync(subPackageName) .then(function(result) { - if (result.stderr !== '') { - throw new Error(result.stderr); - } - const tags = result.stdout.trim().split('\n'); - const versions = tags.map(function(tag) { - return tag.slice(packagePrefix.length); - }); - const sortedVersions = semverSort.desc(versions); - latestTag = packagePrefix + sortedVersions[0]; - return execAsync('LATEST_TAG=' + latestTag + ' yarn release'); + console.log('POSTPUBLISH: Releasing...'); + tag = result.tag; + const releaseName = subPackageName + ' v' + result.version; + return publishReleaseAsync({ + token: githubPersonalAccessToken, + owner: '0xProject', + repo: '0x.js', + tag: tag, + name: releaseName, + notes: 'TODO', + draft: false, + prerelease: false, + reuseRelease: true, + reuseDraftOnly: false, + assets: ['_bundles/index.js', '_bundles/index.min.js'], + }); }) - .then(function(result) { - if (result.stderr !== '') { - throw new Error(result.stderr); + .then(function(err, release) { + if (err !== null) { + throw err; } + console.log('POSTPUBLISH: Release successful, generating docs...'); return execAsync('yarn docs:json'); }) .then(function(result) { if (result.stderr !== '') { throw new Error(result.stderr); } - const s3Url = 's3://0xjs-docs-jsons/v' + latestTag +'.json'; + console.log('POSTPUBLISH: Doc generation successful, uploading docs...'); + const s3Url = 's3://0xjs-docs-jsons/v' + tag +'.json'; return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json'); }); + + // "release": "publish-release --assets _bundles/index.js,_bundles/index.min.js --tag $LATEST_TAG --owner 0xProject --repo 0x.js --notes TODO --name $RELEASE_NAME", + +function getLatestTagAndVersionAsync(subPackageName) { + const subPackagePrefix = subPackageName + '@'; + const gitTagsCommand = 'git tags -l "' + subPackagePrefix + '*"'; + console.log(gitTagsCommand); + return execAsync(gitTagsCommand) + .then(function(result) { + if (result.stderr !== '') { + throw new Error(result.stderr); + } + const tags = result.stdout.trim().split('\n'); + const versions = tags.map(function(tag) { + return tag.slice(subPackagePrefix.length); + }); + const sortedVersions = semverSort.desc(versions); + const latestVersion = sortedVersions[0]; + const latestTag = subPackagePrefix + latestVersion; + return { + tag: latestTag, + version: latestVersion + }; + }); +} -- cgit v1.2.3 From 88d020f9f2e78a1df76e93aa4d190100414c73cb Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 15 Nov 2017 14:54:56 -0600 Subject: Add initial implementation of expiration watcher --- .../0x.js/src/order_watcher/expiration_watcher.ts | 58 ++++++++++++++ .../0x.js/src/order_watcher/order_state_watcher.ts | 25 +++++- packages/0x.js/src/types.ts | 2 + packages/0x.js/src/utils/heap.ts | 90 ++++++++++++++++++++++ 4 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 packages/0x.js/src/order_watcher/expiration_watcher.ts create mode 100644 packages/0x.js/src/utils/heap.ts (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts new file mode 100644 index 000000000..1a9e9a418 --- /dev/null +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -0,0 +1,58 @@ +import * as _ from 'lodash'; +import {BigNumber} from 'bignumber.js'; +import {utils} from '../utils/utils'; +import {intervalUtils} from '../utils/interval_utils'; +import {SignedOrder} from '../types'; +import {Heap} from '../utils/heap'; +import {ZeroEx} from '../0x'; + +// Order prunning is very fast +const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50; + +/** + * This class includes all the functionality related to prunning expired orders + */ +export class ExpirationWatcher { + private orderHashHeapByExpiration: Heap; + private expiration: {[orderHash: string]: BigNumber}; + private callbackIfExists?: (orderHash: string) => void; + private orderExpirationCheckingIntervalMs: number; + private orderExpirationCheckingIntervalIdIfExists?: NodeJS.Timer; + constructor(orderExpirationCheckingIntervalMs?: number) { + this.orderExpirationCheckingIntervalMs = orderExpirationCheckingIntervalMs || + DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS; + this.expiration = {}; + const scoreFunction = ((orderHash: string) => { + return this.expiration[orderHash].toNumber(); + }).bind(this); + this.orderHashHeapByExpiration = new Heap(scoreFunction); + } + public subscribe(callback: (orderHash: string) => void): void { + this.callbackIfExists = callback; + this.orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( + this.pruneExpiredOrders.bind(this), this.orderExpirationCheckingIntervalMs, + ); + } + public unsubscribe(): void { + intervalUtils.clearAsyncExcludingInterval(this.orderExpirationCheckingIntervalIdIfExists as NodeJS.Timer); + delete this.callbackIfExists; + } + public addOrder(orderHash: string, expirationUnixTimestampSec: BigNumber): void { + this.expiration[orderHash] = expirationUnixTimestampSec; + // We don't remove hashes on order remove because it's slow (linear). + // We just skip them later if the order was already removed from the order watcher. + this.orderHashHeapByExpiration.push(orderHash); + } + private pruneExpiredOrders(): void { + const currentUnixTimestampSec = utils.getCurrentUnixTimestamp(); + while ( + this.orderHashHeapByExpiration.size() !== 0 && + this.expiration[this.orderHashHeapByExpiration.head()].lessThan(currentUnixTimestampSec) && + !_.isUndefined(this.callbackIfExists) + ) { + const orderHash = this.orderHashHeapByExpiration.pop(); + delete this.expiration[orderHash]; + this.callbackIfExists(orderHash); + } + } +} diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 2b9d7997e..f21ad0bbe 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -6,6 +6,7 @@ import {assert} from '../utils/assert'; import {utils} from '../utils/utils'; import {artifacts} from '../artifacts'; import {AbiDecoder} from '../utils/abi_decoder'; +import {intervalUtils} from '../utils/interval_utils'; import {OrderStateUtils} from '../utils/order_state_utils'; import { LogEvent, @@ -24,14 +25,14 @@ import { ExchangeEvents, TokenEvents, ZeroExError, + ExchangeContractErrs, } from '../types'; import {Web3Wrapper} from '../web3_wrapper'; import {TokenWrapper} from '../contract_wrappers/token_wrapper'; import {ExchangeWrapper} from '../contract_wrappers/exchange_wrapper'; import {OrderFilledCancelledLazyStore} from '../stores/order_filled_cancelled_lazy_store'; import {BalanceAndProxyAllowanceLazyStore} from '../stores/balance_proxy_allowance_lazy_store'; - -const DEFAULT_NUM_CONFIRMATIONS = 0; +import {ExpirationWatcher} from './expiration_watcher'; interface DependentOrderHashes { [makerAddress: string]: { @@ -56,6 +57,7 @@ export class OrderStateWatcher { private _eventWatcher: EventWatcher; private _web3Wrapper: Web3Wrapper; private _abiDecoder: AbiDecoder; + private _expirationWatcher: ExpirationWatcher; private _orderStateUtils: OrderStateUtils; private _orderFilledCancelledLazyStore: OrderFilledCancelledLazyStore; private _balanceAndProxyAllowanceLazyStore: BalanceAndProxyAllowanceLazyStore; @@ -72,6 +74,10 @@ export class OrderStateWatcher { this._orderStateUtils = new OrderStateUtils( this._balanceAndProxyAllowanceLazyStore, this._orderFilledCancelledLazyStore, ); + const orderExpirationCheckingIntervalMs = _.isUndefined(config) ? + undefined : + config.orderExpirationCheckingIntervalMs; + this._expirationWatcher = new ExpirationWatcher(orderExpirationCheckingIntervalMs); } /** * Add an order to the orderStateWatcher. Before the order is added, it's @@ -84,6 +90,8 @@ export class OrderStateWatcher { assert.isValidSignature(orderHash, signedOrder.ecSignature, signedOrder.maker); this._orderByOrderHash[orderHash] = signedOrder; this.addToDependentOrderHashes(signedOrder, orderHash); + // We don't remove orders from expirationWatcher because heap removal is linear. We just skip it later + this._expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec); } /** * Removes an order from the orderStateWatcher @@ -111,6 +119,7 @@ export class OrderStateWatcher { } this._callbackIfExistsAsync = callback; this._eventWatcher.subscribe(this._onEventWatcherCallbackAsync.bind(this)); + this._expirationWatcher.subscribe(this._onOrderExpired.bind(this)); } /** * Ends an orderStateWatcher subscription. @@ -123,6 +132,18 @@ export class OrderStateWatcher { this._orderFilledCancelledLazyStore.deleteAll(); delete this._callbackIfExistsAsync; this._eventWatcher.unsubscribe(); + this._expirationWatcher.unsubscribe(); + } + private _onOrderExpired(orderHash: string): void { + const orderState: OrderState = { + isValid: false, + orderHash, + error: ExchangeContractErrs.OrderFillExpired, + }; + if (!_.isUndefined(this._orderByOrderHash[orderHash])) { + // We need this check because we never remove the orders from expiration watcher + (this._callbackIfExistsAsync as OnOrderStateChangeCallback)(orderState); + } } private async _onEventWatcherCallbackAsync(log: LogEvent): Promise { const maybeDecodedLog = this._abiDecoder.tryToDecodeLogOrNoop(log); diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 11b5d8569..45b49e148 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -397,9 +397,11 @@ export interface JSONRPCPayload { } /* + * orderExpirationCheckingIntervalMs: How often to check for expired orders * eventPollingIntervalMs: How often to poll the Ethereum node for new events */ export interface OrderStateWatcherConfig { + orderExpirationCheckingIntervalMs?: number; eventPollingIntervalMs?: number; } diff --git a/packages/0x.js/src/utils/heap.ts b/packages/0x.js/src/utils/heap.ts new file mode 100644 index 000000000..aaa17e719 --- /dev/null +++ b/packages/0x.js/src/utils/heap.ts @@ -0,0 +1,90 @@ +// Based on Original JavaScript Code from Marijn Haverbeke (http://eloquentjavascript.net/1st_edition/appendix2.html) +export class Heap { + private content: T[]; + private scoreFunction: (x: T) => number; + constructor(scoreFunction: (x: T) => number) { + this.content = []; + this.scoreFunction = scoreFunction; + } + public push(element: T) { + this.content.push(element); + this.bubbleUp(this.content.length - 1); + } + public size(): number { + const size = this.content.length; + return size; + } + public head(): T { + const head = this.content[0]; + return head; + } + public pop(): T { + const head = this.content[0]; + const end = this.content.pop(); + if (this.content.length > 0) { + this.content[0] = end as T; + this.sinkDown(0); + } + return head; + } + private bubbleUp(n: number) { + // Fetch the element that has to be moved. + const element = this.content[n]; + const score = this.scoreFunction(element); + // When at 0, an element can not go up any further. + while (n > 0) { + // Compute the parent element's index, and fetch it. + const parentN = Math.floor((n + 1) / 2) - 1; + const parent = this.content[parentN]; + // If the parent has a lesser score, things are in order and we + // are done. + if (score >= this.scoreFunction(parent)) { + break; + } + + // Otherwise, swap the parent with the current element and + // continue. + this.content[parentN] = element; + this.content[n] = parent; + n = parentN; + } + } + + private sinkDown(n: number) { + // Look up the target element and its score. + const length = this.content.length; + const element = this.content[n]; + const elemScore = this.scoreFunction(element); + + while (true) { + // Compute the indices of the child elements. + const child2N = (n + 1) * 2; + const child1N = child2N - 1; + // This is used to store the new position of the element, if any. + let swap = n; + let child1Score; + let child2Score; + // If the first child exists (is inside the array)... + if (child1N < length) { + // Look it up and compute its score. + const child1 = this.content[child1N]; + child1Score = this.scoreFunction(child1); + // If the score is less than our element's, we need to swap. + if (child1Score < elemScore) { + swap = child1N; + } + // Do the same checks for the other child. + if (child2N < length) { + const child2 = this.content[child2N]; + child2Score = this.scoreFunction(child2); + if (child2Score < (swap == null ? elemScore : child1Score)) { + swap = child2N; + } + } + } + this.content[n] = this.content[swap]; + this.content[swap] = element; + n = swap; + } + } +} -- cgit v1.2.3 From 827c2457772bd2203307d87f864214c370383807 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 15 Nov 2017 16:19:33 -0500 Subject: postpublish script fixes --- packages/0x.js/scripts/postpublish.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index ff425adbb..deedee74c 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -10,12 +10,13 @@ const subPackageName = '0x.js'; const subPackagePrefix = subPackageName + '@'; const githubPersonalAccessToken = process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS; let tag; - +let version; getLatestTagAndVersionAsync(subPackageName) .then(function(result) { console.log('POSTPUBLISH: Releasing...'); tag = result.tag; - const releaseName = subPackageName + ' v' + result.version; + version = result.version; + const releaseName = subPackageName + ' v' + result.version; return publishReleaseAsync({ token: githubPersonalAccessToken, owner: '0xProject', @@ -30,24 +31,19 @@ getLatestTagAndVersionAsync(subPackageName) assets: ['_bundles/index.js', '_bundles/index.min.js'], }); }) - .then(function(err, release) { - if (err !== null) { - throw err; - } - console.log('POSTPUBLISH: Release successful, generating docs...'); - return execAsync('yarn docs:json'); + .then(function(release) { + console.log('POSTPUBLISH: Release successful, generating docs...'); + return execAsync('yarn docs:json'); }) .then(function(result) { if (result.stderr !== '') { throw new Error(result.stderr); } - console.log('POSTPUBLISH: Doc generation successful, uploading docs...'); - const s3Url = 's3://0xjs-docs-jsons/v' + tag +'.json'; - return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json'); + console.log('POSTPUBLISH: Doc generation successful, uploading docs...'); + const s3Url = 's3://0xjs-docs-jsons/v' + version +'.json'; + return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json'); }); - // "release": "publish-release --assets _bundles/index.js,_bundles/index.min.js --tag $LATEST_TAG --owner 0xProject --repo 0x.js --notes TODO --name $RELEASE_NAME", - function getLatestTagAndVersionAsync(subPackageName) { const subPackagePrefix = subPackageName + '@'; const gitTagsCommand = 'git tags -l "' + subPackagePrefix + '*"'; -- cgit v1.2.3 From 9a57f71ee6fd7aef73811c18e71179e5dc94a417 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 15 Nov 2017 16:47:35 -0500 Subject: improve script --- packages/0x.js/package.json | 6 +----- packages/0x.js/scripts/postpublish.js | 7 +++---- 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index d09396a84..61039a8c0 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -14,7 +14,6 @@ "scripts": { "prebuild": "npm run clean", "build": "run-p build:umd:prod build:commonjs; exit 0;", - "upload_docs_json": "aws s3 cp docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json", "lint": "tslint src/**/*.ts test/**/*.ts", "test:circleci": "run-s test:coverage report_test_coverage; if [ $CIRCLE_BRANCH = \"development\" ]; then yarn test:umd; fi", "test": "run-s clean test:commonjs", @@ -22,9 +21,6 @@ "test:coverage": "nyc npm run test --all", "report_test_coverage": "nyc report --reporter=text-lcov | coveralls", "update_contracts": "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;", - "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json docs/index.json .", - "docs:generate": "typedoc --out docs .", - "docs:open": "opn docs/index.html", "clean": "shx rm -rf _bundles lib test_temp", "build:umd:dev": "webpack", "build:umd:prod": "NODE_ENV=production webpack", @@ -99,7 +95,7 @@ "find-versions": "^2.0.0", "js-sha3": "^0.6.1", "lodash": "^4.17.4", - "publish-release": "^1.3.3", + "publish-release": "0xproject/publish-release", "uuid": "^3.1.0", "web3": "^0.20.0" } diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index deedee74c..b30c7eb3e 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -28,12 +28,12 @@ getLatestTagAndVersionAsync(subPackageName) prerelease: false, reuseRelease: true, reuseDraftOnly: false, - assets: ['_bundles/index.js', '_bundles/index.min.js'], + assets: [__dirname + '/../_bundles/index.js', __dirname + '/../_bundles/index.min.js'], }); }) .then(function(release) { console.log('POSTPUBLISH: Release successful, generating docs...'); - return execAsync('yarn docs:json'); + return execAsync('typedoc --excludePrivate --excludeExternals --target ES5 --json ' + __dirname + '/../docs/index.json ' + __dirname + '/..'); }) .then(function(result) { if (result.stderr !== '') { @@ -41,13 +41,12 @@ getLatestTagAndVersionAsync(subPackageName) } console.log('POSTPUBLISH: Doc generation successful, uploading docs...'); const s3Url = 's3://0xjs-docs-jsons/v' + version +'.json'; - return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json'); + return execAsync('aws s3 cp ' + __dirname + '/../docs/index.json ' + s3Url + ' --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json'); }); function getLatestTagAndVersionAsync(subPackageName) { const subPackagePrefix = subPackageName + '@'; const gitTagsCommand = 'git tags -l "' + subPackagePrefix + '*"'; - console.log(gitTagsCommand); return execAsync(gitTagsCommand) .then(function(result) { if (result.stderr !== '') { -- cgit v1.2.3 From 85c3b2996d7097f8d390f4b8f6199b983928defb Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 15 Nov 2017 16:48:30 -0500 Subject: vx.x.x --- packages/0x.js/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 9c795cf5a..d5e965ed7 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -v0.25.0 - _November 14, 2017_ +vx.x.x ------------------------ * Remove support for Async callback types when used in Subscribe functions -- cgit v1.2.3 From 1e5cc3b0e53aeb606140d0f735652aa464c2a4e7 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 15 Nov 2017 18:17:41 -0500 Subject: experiment with calling typedoc programatically --- packages/0x.js/scripts/postpublish.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index b30c7eb3e..d68fd8fa0 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -2,12 +2,10 @@ const execAsync = require('async-child-process').execAsync; const semverSort = require('semver-sort'); const publishRelease = require('publish-release'); const promisify = require('es6-promisify'); -const prompt = require('prompt'); +const typedoc = require('typedoc'); const publishReleaseAsync = promisify(publishRelease); -const promptGetAsync = promisify(prompt.get); const subPackageName = '0x.js'; -const subPackagePrefix = subPackageName + '@'; const githubPersonalAccessToken = process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS; let tag; let version; @@ -33,7 +31,23 @@ getLatestTagAndVersionAsync(subPackageName) }) .then(function(release) { console.log('POSTPUBLISH: Release successful, generating docs...'); - return execAsync('typedoc --excludePrivate --excludeExternals --target ES5 --json ' + __dirname + '/../docs/index.json ' + __dirname + '/..'); + + // const rootDir = __dirname + '/../src/index.ts'; + // const typedocApp = new typedoc.Application({ + // excludePrivate: true, + // excludeExternals: true, + // target: 'ES5', + // }); + + // console.log(typedocApp.options); + // typedocApp.options.setValue('excludePrivate', true); + // typedocApp.options.setValue('excludeExternals', true); + // typedocApp.options.setValue('json', true); + // typedocApp.options.setValue('target', 'ES5'); + + + // return typedocApp.generateDocs([rootDir], __dirname + '/../docs/index.json'); + return execAsync('yarn typedoc --excludePrivate --excludeExternals --target ES5 --json ' + __dirname + '/../docs/index.json ' + __dirname + '/..'); }) .then(function(result) { if (result.stderr !== '') { @@ -42,6 +56,8 @@ getLatestTagAndVersionAsync(subPackageName) console.log('POSTPUBLISH: Doc generation successful, uploading docs...'); const s3Url = 's3://0xjs-docs-jsons/v' + version +'.json'; return execAsync('aws s3 cp ' + __dirname + '/../docs/index.json ' + s3Url + ' --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json'); + }).catch (function(error) { + throw error; }); function getLatestTagAndVersionAsync(subPackageName) { -- cgit v1.2.3 From 0bcf7e56c2806d42ed43bf5377386501f582951a Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 15 Nov 2017 19:10:44 -0500 Subject: Change to Async suffix convention --- .../0x.js/src/order_watcher/order_state_watcher.ts | 8 +++--- packages/0x.js/test/order_state_watcher_test.ts | 32 +++++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 9f756dbc3..71dfeaedc 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -78,18 +78,18 @@ export class OrderStateWatcher { * signature is verified. * @param signedOrder The order you wish to start watching. */ - public async addOrder(signedOrder: SignedOrder): Promise { + public async addOrderAsync(signedOrder: SignedOrder): Promise { assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema); const orderHash = ZeroEx.getOrderHashHex(signedOrder); assert.isValidSignature(orderHash, signedOrder.ecSignature, signedOrder.maker); this._orderByOrderHash[orderHash] = signedOrder; - await this.addToDependentOrderHashes(signedOrder, orderHash); + await this.addToDependentOrderHashesAsync(signedOrder, orderHash); } /** * Removes an order from the orderStateWatcher * @param orderHash The orderHash of the order you wish to stop watching. */ - public async removeOrder(orderHash: string): Promise { + public async removeOrderAsync(orderHash: string): Promise { assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); const signedOrder = this._orderByOrderHash[orderHash]; if (_.isUndefined(signedOrder)) { @@ -213,7 +213,7 @@ export class OrderStateWatcher { await this._callbackIfExistsAsync(orderState); } } - private async addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string): Promise { + private async addToDependentOrderHashesAsync(signedOrder: SignedOrder, orderHash: string): Promise { if (_.isUndefined(this._dependentOrderHashes[signedOrder.maker])) { this._dependentOrderHashes[signedOrder.maker] = {}; } diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index 0823ac837..0d8a509e2 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -73,13 +73,13 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); expect((zeroEx.orderStateWatcher as any)._orderByOrderHash).to.include({ [orderHash]: signedOrder, }); let dependentOrderHashes = (zeroEx.orderStateWatcher as any)._dependentOrderHashes; expect(dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress]).to.have.keys(orderHash); - await zeroEx.orderStateWatcher.removeOrder(orderHash); + await zeroEx.orderStateWatcher.removeOrderAsync(orderHash); expect((zeroEx.orderStateWatcher as any)._orderByOrderHash).to.not.include({ [orderHash]: signedOrder, }); @@ -92,7 +92,7 @@ describe('OrderStateWatcher', () => { ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); const nonExistentOrderHash = `0x${orderHash.substr(2).split('').reverse().join('')}`; - await zeroEx.orderStateWatcher.removeOrder(nonExistentOrderHash); + await zeroEx.orderStateWatcher.removeOrderAsync(nonExistentOrderHash); }); }); describe('#subscribe', async () => { @@ -109,7 +109,7 @@ describe('OrderStateWatcher', () => { afterEach(async () => { zeroEx.orderStateWatcher.unsubscribe(); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.removeOrder(orderHash); + await zeroEx.orderStateWatcher.removeOrderAsync(orderHash); }); it('should emit orderStateInvalid when maker allowance set to 0 for watched order', (done: DoneCallback) => { (async () => { @@ -117,7 +117,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { expect(orderState.isValid).to.be.false(); const invalidOrderState = orderState as OrderStateInvalid; @@ -135,7 +135,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { throw new Error('OrderState callback fired for irrelevant order'); }); @@ -156,7 +156,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { expect(orderState.isValid).to.be.false(); const invalidOrderState = orderState as OrderStateInvalid; @@ -176,7 +176,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); let eventCount = 0; const callback = reportCallbackErrors(done)((orderState: OrderState) => { @@ -208,7 +208,7 @@ describe('OrderStateWatcher', () => { const fillAmountInBaseUnits = new BigNumber(2); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); let eventCount = 0; const callback = reportCallbackErrors(done)((orderState: OrderState) => { @@ -243,7 +243,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, makerFee, takerFee, maker, taker, fillableAmount, taker); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { const invalidOrderState = orderState as OrderStateInvalid; expect(invalidOrderState.orderHash).to.be.equal(orderHash); @@ -266,7 +266,7 @@ describe('OrderStateWatcher', () => { const takerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, taker); const fillAmountInBaseUnits = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); let eventCount = 0; const callback = reportCallbackErrors(done)((orderState: OrderState) => { eventCount++; @@ -298,7 +298,7 @@ describe('OrderStateWatcher', () => { const makerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, maker); const changedMakerApprovalAmount = ZeroEx.toBaseUnitAmount(new BigNumber(3), 18); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { const validOrderState = orderState as OrderStateValid; @@ -323,7 +323,7 @@ describe('OrderStateWatcher', () => { const remainingAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); const transferAmount = makerBalance.sub(remainingAmount); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { const validOrderState = orderState as OrderStateValid; @@ -346,7 +346,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { expect(orderState.isValid).to.be.false(); @@ -368,7 +368,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { expect(orderState.isValid).to.be.false(); @@ -394,7 +394,7 @@ describe('OrderStateWatcher', () => { const cancelAmountInBaseUnits = new BigNumber(2); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrder(signedOrder); + await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { expect(orderState.isValid).to.be.true(); -- cgit v1.2.3 From e9a5ae21e0e738082924da24b62bb44a4df84286 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 15 Nov 2017 19:30:18 -0500 Subject: Fix nits --- packages/0x.js/src/order_watcher/order_state_watcher.ts | 2 +- packages/0x.js/test/order_state_watcher_test.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 71dfeaedc..0051aaf5b 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -220,12 +220,12 @@ export class OrderStateWatcher { if (_.isUndefined(this._dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress])) { this._dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress] = new Set(); } + this._dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress].add(orderHash); const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper; const zrxTokenAddress = await exchange.getZRXTokenAddressAsync(); if (_.isUndefined(this._dependentOrderHashes[signedOrder.maker][zrxTokenAddress])) { this._dependentOrderHashes[signedOrder.maker][zrxTokenAddress] = new Set(); } - this._dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress].add(orderHash); this._dependentOrderHashes[signedOrder.maker][zrxTokenAddress].add(orderHash); } private removeFromDependentOrderHashes(makerAddress: string, tokenAddress: string, orderHash: string) { diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index 0d8a509e2..00b290252 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -235,7 +235,7 @@ describe('OrderStateWatcher', () => { ); })().catch(done); }); - it('should callback when Fee Token transferrable changes', (done: DoneCallback) => { + it('should trigger the callback when orders backing ZRX allowance changes', (done: DoneCallback) => { (async () => { const makerFee = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18); const takerFee = ZeroEx.toBaseUnitAmount(new BigNumber(0), 18); @@ -245,8 +245,6 @@ describe('OrderStateWatcher', () => { const orderHash = ZeroEx.getOrderHashHex(signedOrder); await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { - const invalidOrderState = orderState as OrderStateInvalid; - expect(invalidOrderState.orderHash).to.be.equal(orderHash); done(); }); zeroEx.orderStateWatcher.subscribe(callback); -- cgit v1.2.3 From 741774c4a776af719c3a013b35bd9cf4f4c1c169 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 12:13:40 -0500 Subject: Update CHANGELOG.md --- packages/0x.js/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) (limited to 'packages') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 0112ca33f..69fd7661b 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -7,6 +7,7 @@ v0.25.1 - _November 13, 2017_ ------------------------ * Standardise on Cancelled over Canceled * Add missing `DecodedLogEvent` type to exported types + * Normalized the transactionReceipt status to be `null|0|1`, 1 meaning transaction execution successful, 0 unsuccessful and `null` if it is a pre-byzantinium transaction. v0.23.0 - _November 12, 2017_ ------------------------ -- cgit v1.2.3 From 7b61ad639b7410c9157e340a422b431b25dc620d Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 12:23:27 -0500 Subject: small fixes --- packages/0x.js/scripts/postpublish.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index d68fd8fa0..e8ca99db9 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -7,6 +7,7 @@ const typedoc = require('typedoc'); const publishReleaseAsync = promisify(publishRelease); const subPackageName = '0x.js'; const githubPersonalAccessToken = process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS; + let tag; let version; getLatestTagAndVersionAsync(subPackageName) @@ -32,20 +33,6 @@ getLatestTagAndVersionAsync(subPackageName) .then(function(release) { console.log('POSTPUBLISH: Release successful, generating docs...'); - // const rootDir = __dirname + '/../src/index.ts'; - // const typedocApp = new typedoc.Application({ - // excludePrivate: true, - // excludeExternals: true, - // target: 'ES5', - // }); - - // console.log(typedocApp.options); - // typedocApp.options.setValue('excludePrivate', true); - // typedocApp.options.setValue('excludeExternals', true); - // typedocApp.options.setValue('json', true); - // typedocApp.options.setValue('target', 'ES5'); - - // return typedocApp.generateDocs([rootDir], __dirname + '/../docs/index.json'); return execAsync('yarn typedoc --excludePrivate --excludeExternals --target ES5 --json ' + __dirname + '/../docs/index.json ' + __dirname + '/..'); }) @@ -56,8 +43,8 @@ getLatestTagAndVersionAsync(subPackageName) console.log('POSTPUBLISH: Doc generation successful, uploading docs...'); const s3Url = 's3://0xjs-docs-jsons/v' + version +'.json'; return execAsync('aws s3 cp ' + __dirname + '/../docs/index.json ' + s3Url + ' --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json'); - }).catch (function(error) { - throw error; + }).catch (function(err) { + throw err; }); function getLatestTagAndVersionAsync(subPackageName) { -- cgit v1.2.3 From 2e368b50ebb8080bad46412fcf8defbc34eabcef Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 13:24:15 -0500 Subject: print out file name in console --- packages/0x.js/scripts/postpublish.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index e8ca99db9..519973f61 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -40,8 +40,9 @@ getLatestTagAndVersionAsync(subPackageName) if (result.stderr !== '') { throw new Error(result.stderr); } - console.log('POSTPUBLISH: Doc generation successful, uploading docs...'); - const s3Url = 's3://0xjs-docs-jsons/v' + version +'.json'; + const fileName = 'v' + version + '.json'; + console.log('POSTPUBLISH: Doc generation successful, uploading docs... as ', fileName); + const s3Url = 's3://0xjs-docs-jsons/' + fileName; return execAsync('aws s3 cp ' + __dirname + '/../docs/index.json ' + s3Url + ' --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json'); }).catch (function(err) { throw err; -- cgit v1.2.3 From 50dc1d3db34c061fe6836273c1b80bc450b04d69 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 13:24:36 -0500 Subject: specify the current working directory in which to run the `yarn` command --- packages/0x.js/scripts/postpublish.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index 519973f61..3f0502c64 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -34,7 +34,12 @@ getLatestTagAndVersionAsync(subPackageName) console.log('POSTPUBLISH: Release successful, generating docs...'); // return typedocApp.generateDocs([rootDir], __dirname + '/../docs/index.json'); - return execAsync('yarn typedoc --excludePrivate --excludeExternals --target ES5 --json ' + __dirname + '/../docs/index.json ' + __dirname + '/..'); + return execAsync( + 'yarn typedoc --excludePrivate --excludeExternals --target ES5 --json ' + __dirname + '/../docs/index.json ' + __dirname + '/..', + { + cwd: __dirname + '/..', + } + ); }) .then(function(result) { if (result.stderr !== '') { -- cgit v1.2.3 From e70c3976db61bfe2038b0d56ea196412215aae4f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 13:30:26 -0500 Subject: Use `yarn docs:json` command --- packages/0x.js/package.json | 1 + packages/0x.js/scripts/postpublish.js | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 61039a8c0..10ace5529 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -14,6 +14,7 @@ "scripts": { "prebuild": "npm run clean", "build": "run-p build:umd:prod build:commonjs; exit 0;", + "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $1 $2", "lint": "tslint src/**/*.ts test/**/*.ts", "test:circleci": "run-s test:coverage report_test_coverage; if [ $CIRCLE_BRANCH = \"development\" ]; then yarn test:umd; fi", "test": "run-s clean test:commonjs", diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index 3f0502c64..1ec0ac258 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -28,14 +28,13 @@ getLatestTagAndVersionAsync(subPackageName) reuseRelease: true, reuseDraftOnly: false, assets: [__dirname + '/../_bundles/index.js', __dirname + '/../_bundles/index.min.js'], - }); + }); }) .then(function(release) { console.log('POSTPUBLISH: Release successful, generating docs...'); - // return typedocApp.generateDocs([rootDir], __dirname + '/../docs/index.json'); return execAsync( - 'yarn typedoc --excludePrivate --excludeExternals --target ES5 --json ' + __dirname + '/../docs/index.json ' + __dirname + '/..', + 'yarn docs:json ' + __dirname + '/../docs/index.json ' + __dirname + '/..', { cwd: __dirname + '/..', } -- cgit v1.2.3 From b7585318c7015dd81516f498aa59b86ec2ee5671 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 17 Nov 2017 13:02:17 -0600 Subject: Fix heap implementation --- packages/0x.js/src/utils/heap.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'packages') diff --git a/packages/0x.js/src/utils/heap.ts b/packages/0x.js/src/utils/heap.ts index aaa17e719..1135c76b9 100644 --- a/packages/0x.js/src/utils/heap.ts +++ b/packages/0x.js/src/utils/heap.ts @@ -82,6 +82,9 @@ export class Heap { } } } + if (swap === n) { + break; + } this.content[n] = this.content[swap]; this.content[swap] = element; n = swap; -- cgit v1.2.3 From 34926eb66ae6ea105f7f2e029c65c4d44025a655 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 17 Nov 2017 13:02:37 -0600 Subject: Add tests for expirationWatcher --- packages/0x.js/test/expiration_watcher_test.ts | 137 +++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 packages/0x.js/test/expiration_watcher_test.ts (limited to 'packages') diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts new file mode 100644 index 000000000..47071416e --- /dev/null +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -0,0 +1,137 @@ +import 'mocha'; +import * as chai from 'chai'; +import * as _ from 'lodash'; +import * as Sinon from 'sinon'; +import * as Web3 from 'web3'; +import BigNumber from 'bignumber.js'; +import {chaiSetup} from './utils/chai_setup'; +import {web3Factory} from './utils/web3_factory'; +import {utils} from '../src/utils/utils'; +import {Web3Wrapper} from '../src/web3_wrapper'; +import {TokenUtils} from './utils/token_utils'; +import {ExpirationWatcher} from '../src/order_watcher/expiration_watcher'; +import { + ZeroEx, + Token, +} from '../src'; +import {FillScenarios} from './utils/fill_scenarios'; +import {DoneCallback} from '../src/types'; +import {reportCallbackErrors} from './utils/report_callback_errors'; + +chaiSetup.configure(); +const expect = chai.expect; + +describe('ExpirationWatcher', () => { + let web3: Web3; + let zeroEx: ZeroEx; + let tokenUtils: TokenUtils; + let tokens: Token[]; + let userAddresses: string[]; + let zrxTokenAddress: string; + let fillScenarios: FillScenarios; + let exchangeContractAddress: string; + let makerTokenAddress: string; + let takerTokenAddress: string; + let coinbase: string; + let makerAddress: string; + let takerAddress: string; + let feeRecipient: string; + const fillableAmount = new BigNumber(5); + let currentUnixTimestampSec: BigNumber; + let timer: Sinon.SinonFakeTimers; + let expirationWatcher: ExpirationWatcher; + before(async () => { + web3 = web3Factory.create(); + zeroEx = new ZeroEx(web3.currentProvider); + exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync(); + userAddresses = await zeroEx.getAvailableAddressesAsync(); + tokens = await zeroEx.tokenRegistry.getTokensAsync(); + tokenUtils = new TokenUtils(tokens); + zrxTokenAddress = tokenUtils.getProtocolTokenOrThrow().address; + fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens, zrxTokenAddress, exchangeContractAddress); + [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; + tokens = await zeroEx.tokenRegistry.getTokensAsync(); + const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); + makerTokenAddress = makerToken.address; + takerTokenAddress = takerToken.address; + }); + beforeEach(() => { + const sinonTimerConfig = {shouldAdvanceTime: true} as any; + // This constructor has incorrect types + timer = Sinon.useFakeTimers(sinonTimerConfig); + currentUnixTimestampSec = utils.getCurrentUnixTimestamp(); + expirationWatcher = new ExpirationWatcher(); + }); + afterEach(() => { + timer.restore(); + expirationWatcher.unsubscribe(); + }); + it('correctly emits events when order expires', (done: DoneCallback) => { + (async () => { + const orderLifetime = 60; + const expirationUnixTimestampSec = currentUnixTimestampSec.plus(orderLifetime); + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + expirationUnixTimestampSec, + ); + const orderHash = ZeroEx.getOrderHashHex(signedOrder); + expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec); + const callback = reportCallbackErrors(done)((hash: string) => { + expect(hash).to.be.equal(orderHash); + expect(utils.getCurrentUnixTimestamp()).to.be.bignumber.above(expirationUnixTimestampSec); + done(); + }); + expirationWatcher.subscribe(callback); + timer.tick(orderLifetime * 1000); + })().catch(done); + }); + it('doesn\'t emit events before order expires', (done: DoneCallback) => { + (async () => { + const orderLifetime = 60; + const expirationUnixTimestampSec = currentUnixTimestampSec.plus(orderLifetime); + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + expirationUnixTimestampSec, + ); + const orderHash = ZeroEx.getOrderHashHex(signedOrder); + expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec); + const callback = reportCallbackErrors(done)((hash: string) => { + done(new Error('Emited expiration vent before the order actually expired')); + }); + expirationWatcher.subscribe(callback); + const notEnoughTime = orderLifetime - 1; + timer.tick(notEnoughTime * 1000); + done(); + })().catch(done); + }); + it('emits events in correct order', (done: DoneCallback) => { + (async () => { + const order1Lifetime = 60; + const order2Lifetime = 120; + const order1ExpirationUnixTimestampSec = currentUnixTimestampSec.plus(order1Lifetime); + const order2ExpirationUnixTimestampSec = currentUnixTimestampSec.plus(order2Lifetime); + const signedOrder1 = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + order1ExpirationUnixTimestampSec, + ); + const signedOrder2 = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + order2ExpirationUnixTimestampSec, + ); + const orderHash1 = ZeroEx.getOrderHashHex(signedOrder1); + const orderHash2 = ZeroEx.getOrderHashHex(signedOrder2); + expirationWatcher.addOrder(orderHash2, signedOrder2.expirationUnixTimestampSec); + expirationWatcher.addOrder(orderHash1, signedOrder1.expirationUnixTimestampSec); + const expirationOrder = [orderHash1, orderHash2]; + const callback = reportCallbackErrors(done)((hash: string) => { + const orderHash = expirationOrder.shift(); + expect(hash).to.be.equal(orderHash); + if (_.isEmpty(expirationOrder)) { + done(); + } + }); + expirationWatcher.subscribe(callback); + timer.tick(order2Lifetime * 1000); + })().catch(done); + }); +}); -- cgit v1.2.3 From d3e03744cdbc12bd1956fd5d921fc2331e4ee5cf Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 17 Nov 2017 13:06:10 -0600 Subject: Improve the comment --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 1a9e9a418..5153cd8b9 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -10,7 +10,8 @@ import {ZeroEx} from '../0x'; const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50; /** - * This class includes all the functionality related to prunning expired orders + * This class includes the functionality to detect expired orders. + * It stores them in a min heap by expiration time and checks for expired ones every `orderExpirationCheckingIntervalMs` */ export class ExpirationWatcher { private orderHashHeapByExpiration: Heap; -- cgit v1.2.3 From 0402d3de802ba262bb820d582baa157ca9c8ba54 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 13:19:12 -0600 Subject: Move upload_docs_json back to npm script and pass in vars properly. --- packages/0x.js/package.json | 3 ++- packages/0x.js/scripts/postpublish.js | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 10ace5529..e1f0bb93e 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -14,7 +14,8 @@ "scripts": { "prebuild": "npm run clean", "build": "run-p build:umd:prod build:commonjs; exit 0;", - "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $1 $2", + "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR", + "upload_docs_json": "aws s3 cp docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json", "lint": "tslint src/**/*.ts test/**/*.ts", "test:circleci": "run-s test:coverage report_test_coverage; if [ $CIRCLE_BRANCH = \"development\" ]; then yarn test:umd; fi", "test": "run-s clean test:commonjs", diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index 1ec0ac258..b9fe0bc9a 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -4,6 +4,7 @@ const publishRelease = require('publish-release'); const promisify = require('es6-promisify'); const typedoc = require('typedoc'); +const cwd = __dirname + '/..'; const publishReleaseAsync = promisify(publishRelease); const subPackageName = '0x.js'; const githubPersonalAccessToken = process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS; @@ -34,9 +35,9 @@ getLatestTagAndVersionAsync(subPackageName) console.log('POSTPUBLISH: Release successful, generating docs...'); return execAsync( - 'yarn docs:json ' + __dirname + '/../docs/index.json ' + __dirname + '/..', + 'JSON_FILE_PATH=' + __dirname + '/../docs/index.json PROJECT_DIR=' + __dirname + '/.. yarn docs:json', { - cwd: __dirname + '/..', + cwd, } ); }) @@ -47,7 +48,9 @@ getLatestTagAndVersionAsync(subPackageName) const fileName = 'v' + version + '.json'; console.log('POSTPUBLISH: Doc generation successful, uploading docs... as ', fileName); const s3Url = 's3://0xjs-docs-jsons/' + fileName; - return execAsync('aws s3 cp ' + __dirname + '/../docs/index.json ' + s3Url + ' --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json'); + return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json', { + cwd, + }); }).catch (function(err) { throw err; }); -- cgit v1.2.3 From f25b2d9ab9bfc9410e17d1ee7a4bf0074aaa622c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 13:19:33 -0600 Subject: Set prerelease to true so that non of the releases are marked as "latest" --- packages/0x.js/scripts/postpublish.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index b9fe0bc9a..4512fb24c 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -25,7 +25,7 @@ getLatestTagAndVersionAsync(subPackageName) name: releaseName, notes: 'TODO', draft: false, - prerelease: false, + prerelease: true, reuseRelease: true, reuseDraftOnly: false, assets: [__dirname + '/../_bundles/index.js', __dirname + '/../_bundles/index.min.js'], -- cgit v1.2.3 From 5277d4a2666a795d01b7d3d4d018ca6d0e42399f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 14:09:48 -0600 Subject: Move most of code for getting latest tag/version and calling publish_release to postpublish_utils script in top-level dir --- packages/0x.js/package.json | 3 -- packages/0x.js/scripts/postpublish.js | 52 ++++++----------------------------- 2 files changed, 8 insertions(+), 47 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index e1f0bb93e..c381d3898 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -70,7 +70,6 @@ "prompt": "^1.0.0", "request": "^2.81.0", "request-promise-native": "^1.0.4", - "semver-sort": "^0.0.4", "shx": "^0.2.2", "sinon": "^4.0.0", "source-map-support": "^0.5.0", @@ -90,14 +89,12 @@ "bignumber.js": "~4.1.0", "bn.js": "4.11.8", "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", "js-sha3": "^0.6.1", "lodash": "^4.17.4", - "publish-release": "0xproject/publish-release", "uuid": "^3.1.0", "web3": "^0.20.0" } diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index 4512fb24c..e68302b33 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -1,39 +1,25 @@ const execAsync = require('async-child-process').execAsync; -const semverSort = require('semver-sort'); -const publishRelease = require('publish-release'); -const promisify = require('es6-promisify'); -const typedoc = require('typedoc'); +const postpublish_utils = require('../../../scripts/postpublish_utils'); const cwd = __dirname + '/..'; -const publishReleaseAsync = promisify(publishRelease); const subPackageName = '0x.js'; -const githubPersonalAccessToken = process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS; let tag; let version; -getLatestTagAndVersionAsync(subPackageName) +postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { console.log('POSTPUBLISH: Releasing...'); tag = result.tag; version = result.version; - const releaseName = subPackageName + ' v' + result.version; - return publishReleaseAsync({ - token: githubPersonalAccessToken, - owner: '0xProject', - repo: '0x.js', - tag: tag, - name: releaseName, - notes: 'TODO', - draft: false, - prerelease: true, - reuseRelease: true, - reuseDraftOnly: false, - assets: [__dirname + '/../_bundles/index.js', __dirname + '/../_bundles/index.min.js'], - }); + const releaseName = subPackageName + ' v' + version; + const assets = [ + __dirname + '/../_bundles/index.js', + __dirname + '/../_bundles/index.min.js', + ]; + return postpublish_utils.publishReleaseNotes(tag, releaseName, assets); }) .then(function(release) { console.log('POSTPUBLISH: Release successful, generating docs...'); - return execAsync( 'JSON_FILE_PATH=' + __dirname + '/../docs/index.json PROJECT_DIR=' + __dirname + '/.. yarn docs:json', { @@ -54,25 +40,3 @@ getLatestTagAndVersionAsync(subPackageName) }).catch (function(err) { throw err; }); - -function getLatestTagAndVersionAsync(subPackageName) { - const subPackagePrefix = subPackageName + '@'; - const gitTagsCommand = 'git tags -l "' + subPackagePrefix + '*"'; - return execAsync(gitTagsCommand) - .then(function(result) { - if (result.stderr !== '') { - throw new Error(result.stderr); - } - const tags = result.stdout.trim().split('\n'); - const versions = tags.map(function(tag) { - return tag.slice(subPackagePrefix.length); - }); - const sortedVersions = semverSort.desc(versions); - const latestVersion = sortedVersions[0]; - const latestTag = subPackagePrefix + latestVersion; - return { - tag: latestTag, - version: latestVersion - }; - }); -} -- cgit v1.2.3 From 5015f2d7d75974a5ce950e8f05d6a5ab481c488a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 14:10:18 -0600 Subject: Add postpublish scripts for all the subpackages so that they each publish a release to github --- packages/assert/scripts/postpublish.js | 13 +++++++++++++ packages/connect/scripts/postpublish.js | 13 +++++++++++++ packages/json-schemas/scripts/postpublish.js | 13 +++++++++++++ packages/tslint-config/scripts/postpublish.js | 13 +++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 packages/assert/scripts/postpublish.js create mode 100644 packages/connect/scripts/postpublish.js create mode 100644 packages/json-schemas/scripts/postpublish.js create mode 100644 packages/tslint-config/scripts/postpublish.js (limited to 'packages') diff --git a/packages/assert/scripts/postpublish.js b/packages/assert/scripts/postpublish.js new file mode 100644 index 000000000..b583155d2 --- /dev/null +++ b/packages/assert/scripts/postpublish.js @@ -0,0 +1,13 @@ +const postpublish_utils = require('../../../scripts/postpublish_utils'); + +const subPackageName = '0xproject/assert'; + +postpublish_utils.getLatestTagAndVersionAsync(subPackageName) + .then(function(result) { + const releaseName = subPackageName + ' v' + result.version; + const assets = []; + return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets); + }) + .catch (function(err) { + throw err; + }); diff --git a/packages/connect/scripts/postpublish.js b/packages/connect/scripts/postpublish.js new file mode 100644 index 000000000..4323ed5c7 --- /dev/null +++ b/packages/connect/scripts/postpublish.js @@ -0,0 +1,13 @@ +const postpublish_utils = require('../../../scripts/postpublish_utils'); + +const subPackageName = '0xproject/connect'; + +postpublish_utils.getLatestTagAndVersionAsync(subPackageName) + .then(function(result) { + const releaseName = subPackageName + ' v' + result.version; + const assets = []; + return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets); + }) + .catch (function(err) { + throw err; + }); diff --git a/packages/json-schemas/scripts/postpublish.js b/packages/json-schemas/scripts/postpublish.js new file mode 100644 index 000000000..8930521f1 --- /dev/null +++ b/packages/json-schemas/scripts/postpublish.js @@ -0,0 +1,13 @@ +const postpublish_utils = require('../../../scripts/postpublish_utils'); + +const subPackageName = '0xproject/json-schemas'; + +postpublish_utils.getLatestTagAndVersionAsync(subPackageName) + .then(function(result) { + const releaseName = subPackageName + ' v' + result.version; + const assets = []; + return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets); + }) + .catch (function(err) { + throw err; + }); diff --git a/packages/tslint-config/scripts/postpublish.js b/packages/tslint-config/scripts/postpublish.js new file mode 100644 index 000000000..c6e1b3630 --- /dev/null +++ b/packages/tslint-config/scripts/postpublish.js @@ -0,0 +1,13 @@ +const postpublish_utils = require('../../../scripts/postpublish_utils'); + +const subPackageName = '0xproject/tslint-config'; + +postpublish_utils.getLatestTagAndVersionAsync(subPackageName) + .then(function(result) { + const releaseName = subPackageName + ' v' + result.version; + const assets = []; + return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets); + }) + .catch (function(err) { + throw err; + }); -- cgit v1.2.3 From 5042b85d218bd17dcf0ebf9b3127dd30c5bb5962 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 17 Nov 2017 12:32:39 -0800 Subject: Remove clean step from test_umd.sh --- packages/0x.js/scripts/test_umd.sh | 1 - 1 file changed, 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/test_umd.sh b/packages/0x.js/scripts/test_umd.sh index d200c76d0..e3eba088a 100755 --- a/packages/0x.js/scripts/test_umd.sh +++ b/packages/0x.js/scripts/test_umd.sh @@ -3,5 +3,4 @@ # UMD tests should only be run after building the commonjs because they reuse some of the commonjs build artifacts run-s substitute_umd_bundle run_mocha return_code=$? -npm run clean exit $return_code -- cgit v1.2.3 From cd0f6716e817a8b123d2b5203ea838ecf3a5e8d4 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 14:33:28 -0600 Subject: remove unused imports --- packages/0x.js/package.json | 2 -- 1 file changed, 2 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index c381d3898..341df882b 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -51,7 +51,6 @@ "@types/node": "^8.0.1", "@types/sinon": "^2.2.2", "@types/uuid": "^3.4.2", - "async-child-process": "^1.1.1", "awesome-typescript-loader": "^3.1.3", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", @@ -67,7 +66,6 @@ "npm-run-all": "^4.0.2", "nyc": "^11.0.1", "opn-cli": "^3.1.0", - "prompt": "^1.0.0", "request": "^2.81.0", "request-promise-native": "^1.0.4", "shx": "^0.2.2", -- cgit v1.2.3 From 70f4453e3eb2818c883862f609885e077b6bc631 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 14:33:43 -0600 Subject: Get package name from package.json --- packages/0x.js/scripts/postpublish.js | 3 ++- packages/assert/scripts/postpublish.js | 3 ++- packages/connect/scripts/postpublish.js | 3 ++- packages/json-schemas/scripts/postpublish.js | 3 ++- packages/tslint-config/scripts/postpublish.js | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index e68302b33..bf4c63032 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -1,8 +1,9 @@ const execAsync = require('async-child-process').execAsync; const postpublish_utils = require('../../../scripts/postpublish_utils'); +const packageJSON = require('../package.json'); const cwd = __dirname + '/..'; -const subPackageName = '0x.js'; +const subPackageName = packageJSON.name; let tag; let version; diff --git a/packages/assert/scripts/postpublish.js b/packages/assert/scripts/postpublish.js index b583155d2..08458f038 100644 --- a/packages/assert/scripts/postpublish.js +++ b/packages/assert/scripts/postpublish.js @@ -1,6 +1,7 @@ const postpublish_utils = require('../../../scripts/postpublish_utils'); +const packageJSON = require('../package.json'); -const subPackageName = '0xproject/assert'; +const subPackageName = packageJSON.name; postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { diff --git a/packages/connect/scripts/postpublish.js b/packages/connect/scripts/postpublish.js index 4323ed5c7..08458f038 100644 --- a/packages/connect/scripts/postpublish.js +++ b/packages/connect/scripts/postpublish.js @@ -1,6 +1,7 @@ const postpublish_utils = require('../../../scripts/postpublish_utils'); +const packageJSON = require('../package.json'); -const subPackageName = '0xproject/connect'; +const subPackageName = packageJSON.name; postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { diff --git a/packages/json-schemas/scripts/postpublish.js b/packages/json-schemas/scripts/postpublish.js index 8930521f1..08458f038 100644 --- a/packages/json-schemas/scripts/postpublish.js +++ b/packages/json-schemas/scripts/postpublish.js @@ -1,6 +1,7 @@ const postpublish_utils = require('../../../scripts/postpublish_utils'); +const packageJSON = require('../package.json'); -const subPackageName = '0xproject/json-schemas'; +const subPackageName = packageJSON.name; postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { diff --git a/packages/tslint-config/scripts/postpublish.js b/packages/tslint-config/scripts/postpublish.js index c6e1b3630..08458f038 100644 --- a/packages/tslint-config/scripts/postpublish.js +++ b/packages/tslint-config/scripts/postpublish.js @@ -1,6 +1,7 @@ const postpublish_utils = require('../../../scripts/postpublish_utils'); +const packageJSON = require('../package.json'); -const subPackageName = '0xproject/tslint-config'; +const subPackageName = packageJSON.name; postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { -- cgit v1.2.3 From 6a83687f45db37cbb8bdb24a7bb090094a6cae08 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 14:44:44 -0600 Subject: reset all sub-package versions to latest actually published --- packages/0x.js/package.json | 6 +++--- packages/assert/package.json | 6 +++--- packages/json-schemas/package.json | 4 ++-- packages/tslint-config/package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 341df882b..8278a96f6 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -44,7 +44,7 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.3", + "@0xproject/tslint-config": "^0.1.0", "@types/jsonschema": "^1.1.1", "@types/lodash": "^4.14.64", "@types/mocha": "^2.2.41", @@ -82,8 +82,8 @@ "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "^0.0.7", - "@0xproject/json-schemas": "^0.6.10", + "@0xproject/assert": "^0.0.4", + "@0xproject/json-schemas": "^0.6.7", "bignumber.js": "~4.1.0", "bn.js": "4.11.8", "compare-versions": "^3.0.1", diff --git a/packages/assert/package.json b/packages/assert/package.json index 96f41e552..ed1d2a98b 100644 --- a/packages/assert/package.json +++ b/packages/assert/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/assert", - "version": "0.0.7", + "version": "0.0.4", "description": "Provides a standard way of performing type and schema validation across 0x projects", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/assert/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.1.3", + "@0xproject/tslint-config": "^0.1.0", "@types/lodash": "^4.14.78", "@types/mocha": "^2.2.42", "@types/valid-url": "^1.0.2", @@ -37,7 +37,7 @@ "typescript": "^2.4.2" }, "dependencies": { - "@0xproject/json-schemas": "^0.6.10", + "@0xproject/json-schemas": "^0.6.7", "bignumber.js": "~4.1.0", "ethereum-address": "^0.0.4", "lodash": "^4.17.4", diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index aa7c5d5d1..07ed20551 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/json-schemas", - "version": "0.6.10", + "version": "0.6.7", "description": "0x-related json schemas", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -28,7 +28,7 @@ "lodash.values": "^4.3.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.3", + "@0xproject/tslint-config": "^0.1.0", "@types/lodash.foreach": "^4.5.3", "@types/lodash.values": "^4.3.3", "@types/mocha": "^2.2.42", diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json index 50adae56f..ca46d63fc 100644 --- a/packages/tslint-config/package.json +++ b/packages/tslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/tslint-config", - "version": "0.1.3", + "version": "0.1.0", "description": "Lint rules related to 0xProject for TSLint", "main": "tslint.json", "files": [ -- cgit v1.2.3 From 49ba456189bf43149a9f58aa01ecd820baa52082 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 14:49:46 -0600 Subject: Set S3 bucket path to variable --- packages/0x.js/scripts/postpublish.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index bf4c63032..3756b8984 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -4,6 +4,7 @@ const packageJSON = require('../package.json'); const cwd = __dirname + '/..'; const subPackageName = packageJSON.name; +const S3BucketPath = 's3://0xjs-docs-jsons/', let tag; let version; @@ -34,7 +35,7 @@ postpublish_utils.getLatestTagAndVersionAsync(subPackageName) } const fileName = 'v' + version + '.json'; console.log('POSTPUBLISH: Doc generation successful, uploading docs... as ', fileName); - const s3Url = 's3://0xjs-docs-jsons/' + fileName; + const s3Url = S3BucketPath + fileName; return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json', { cwd, }); -- cgit v1.2.3 From abee7d25a4e9bee81fa76d6bc0da31488aed16bc Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 16:43:15 -0600 Subject: Add back promisify --- packages/0x.js/package.json | 1 + 1 file changed, 1 insertion(+) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 8278a96f6..7aa360954 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -87,6 +87,7 @@ "bignumber.js": "~4.1.0", "bn.js": "4.11.8", "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", -- cgit v1.2.3 From 7f595169c1bc02873d47a5b7411dfb7414c19041 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 16:44:56 -0600 Subject: Put release name generation into postpublish_utils --- packages/0x.js/scripts/postpublish.js | 3 +-- packages/assert/scripts/postpublish.js | 2 +- packages/connect/scripts/postpublish.js | 2 +- packages/json-schemas/scripts/postpublish.js | 2 +- packages/tslint-config/scripts/postpublish.js | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index 3756b8984..d2ae86bbd 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -10,10 +10,9 @@ let tag; let version; postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { - console.log('POSTPUBLISH: Releasing...'); tag = result.tag; version = result.version; - const releaseName = subPackageName + ' v' + version; + const releaseName = postpublish_utils.getReleaseName(subPackageName, version); const assets = [ __dirname + '/../_bundles/index.js', __dirname + '/../_bundles/index.min.js', diff --git a/packages/assert/scripts/postpublish.js b/packages/assert/scripts/postpublish.js index 08458f038..7fa452b08 100644 --- a/packages/assert/scripts/postpublish.js +++ b/packages/assert/scripts/postpublish.js @@ -5,7 +5,7 @@ const subPackageName = packageJSON.name; postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { - const releaseName = subPackageName + ' v' + result.version; + const releaseName = postpublish_utils.getReleaseName(subPackageName, result.version); const assets = []; return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets); }) diff --git a/packages/connect/scripts/postpublish.js b/packages/connect/scripts/postpublish.js index 08458f038..7fa452b08 100644 --- a/packages/connect/scripts/postpublish.js +++ b/packages/connect/scripts/postpublish.js @@ -5,7 +5,7 @@ const subPackageName = packageJSON.name; postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { - const releaseName = subPackageName + ' v' + result.version; + const releaseName = postpublish_utils.getReleaseName(subPackageName, result.version); const assets = []; return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets); }) diff --git a/packages/json-schemas/scripts/postpublish.js b/packages/json-schemas/scripts/postpublish.js index 08458f038..7fa452b08 100644 --- a/packages/json-schemas/scripts/postpublish.js +++ b/packages/json-schemas/scripts/postpublish.js @@ -5,7 +5,7 @@ const subPackageName = packageJSON.name; postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { - const releaseName = subPackageName + ' v' + result.version; + const releaseName = postpublish_utils.getReleaseName(subPackageName, result.version); const assets = []; return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets); }) diff --git a/packages/tslint-config/scripts/postpublish.js b/packages/tslint-config/scripts/postpublish.js index 08458f038..7fa452b08 100644 --- a/packages/tslint-config/scripts/postpublish.js +++ b/packages/tslint-config/scripts/postpublish.js @@ -5,7 +5,7 @@ const subPackageName = packageJSON.name; postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { - const releaseName = subPackageName + ' v' + result.version; + const releaseName = postpublish_utils.getReleaseName(subPackageName, result.version); const assets = []; return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets); }) -- cgit v1.2.3 From 37a9b64503edc8fe750dad02a7a45d8303f9ba04 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 17 Nov 2017 17:00:15 -0600 Subject: Small fixes --- packages/0x.js/scripts/postpublish.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index d2ae86bbd..ffc68afb4 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -4,7 +4,7 @@ const packageJSON = require('../package.json'); const cwd = __dirname + '/..'; const subPackageName = packageJSON.name; -const S3BucketPath = 's3://0xjs-docs-jsons/', +const S3BucketPath = 's3://0xjs-docs-jsons/'; let tag; let version; -- cgit v1.2.3 From e755ed927cef8352900187b5487881a3fa4847f1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 17 Nov 2017 17:25:58 -0600 Subject: Remove order on expiration --- packages/0x.js/src/order_watcher/order_state_watcher.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index f21ad0bbe..bc61e415c 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -142,6 +142,7 @@ export class OrderStateWatcher { }; if (!_.isUndefined(this._orderByOrderHash[orderHash])) { // We need this check because we never remove the orders from expiration watcher + this.removeOrder(orderHash); (this._callbackIfExistsAsync as OnOrderStateChangeCallback)(orderState); } } -- cgit v1.2.3 From c4d10a6f2d14f23367500d4eb46de7097b00d209 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 11:05:37 -0600 Subject: Do simple inits inline --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 5153cd8b9..b211ee826 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -15,14 +15,13 @@ const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50; */ export class ExpirationWatcher { private orderHashHeapByExpiration: Heap; - private expiration: {[orderHash: string]: BigNumber}; + private expiration: {[orderHash: string]: BigNumber} = {}; private callbackIfExists?: (orderHash: string) => void; private orderExpirationCheckingIntervalMs: number; private orderExpirationCheckingIntervalIdIfExists?: NodeJS.Timer; constructor(orderExpirationCheckingIntervalMs?: number) { this.orderExpirationCheckingIntervalMs = orderExpirationCheckingIntervalMs || DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS; - this.expiration = {}; const scoreFunction = ((orderHash: string) => { return this.expiration[orderHash].toNumber(); }).bind(this); -- cgit v1.2.3 From 2c193a1244d9f288c7c01142d42e442a687ce114 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 11:06:32 -0600 Subject: Remove redundant bind --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index b211ee826..acc7e7e5d 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -22,9 +22,7 @@ export class ExpirationWatcher { constructor(orderExpirationCheckingIntervalMs?: number) { this.orderExpirationCheckingIntervalMs = orderExpirationCheckingIntervalMs || DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS; - const scoreFunction = ((orderHash: string) => { - return this.expiration[orderHash].toNumber(); - }).bind(this); + const scoreFunction = (orderHash: string) => this.expiration[orderHash].toNumber(); this.orderHashHeapByExpiration = new Heap(scoreFunction); } public subscribe(callback: (orderHash: string) => void): void { -- cgit v1.2.3 From 856a5c3369c0248ec32924b25ec77dce6b4e1071 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 11:10:25 -0600 Subject: Throw when subscription is already present --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index acc7e7e5d..6d9556336 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -2,7 +2,7 @@ import * as _ from 'lodash'; import {BigNumber} from 'bignumber.js'; import {utils} from '../utils/utils'; import {intervalUtils} from '../utils/interval_utils'; -import {SignedOrder} from '../types'; +import {SignedOrder, ZeroExError} from '../types'; import {Heap} from '../utils/heap'; import {ZeroEx} from '../0x'; @@ -26,6 +26,9 @@ export class ExpirationWatcher { this.orderHashHeapByExpiration = new Heap(scoreFunction); } public subscribe(callback: (orderHash: string) => void): void { + if (!_.isUndefined(this.callbackIfExists)) { + throw new Error(ZeroExError.SubscriptionAlreadyPresent); + } this.callbackIfExists = callback; this.orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( this.pruneExpiredOrders.bind(this), this.orderExpirationCheckingIntervalMs, -- cgit v1.2.3 From 20449a0cb293649d9c301781dd89e7c26cc7a6b6 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 11:13:54 -0600 Subject: Throw when subscription is already removed --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 6d9556336..f9c6571db 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -35,7 +35,10 @@ export class ExpirationWatcher { ); } public unsubscribe(): void { - intervalUtils.clearAsyncExcludingInterval(this.orderExpirationCheckingIntervalIdIfExists as NodeJS.Timer); + if (_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists)) { + throw new Error(ZeroExError.SubscriptionNotFound); + } + intervalUtils.clearAsyncExcludingInterval(this.orderExpirationCheckingIntervalIdIfExists); delete this.callbackIfExists; } public addOrder(orderHash: string, expirationUnixTimestampSec: BigNumber): void { -- cgit v1.2.3 From a37f0198065571421eb2772c96241e0d57007bd3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 11:15:01 -0600 Subject: Delete orderExpirationCheckingIntervalIdIfExists --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index f9c6571db..0f73d088a 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -40,6 +40,7 @@ export class ExpirationWatcher { } intervalUtils.clearAsyncExcludingInterval(this.orderExpirationCheckingIntervalIdIfExists); delete this.callbackIfExists; + delete this.orderExpirationCheckingIntervalIdIfExists; } public addOrder(orderHash: string, expirationUnixTimestampSec: BigNumber): void { this.expiration[orderHash] = expirationUnixTimestampSec; -- cgit v1.2.3 From fa2c4160b59e88a6816436855db306c9ce4a8da1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 11:15:48 -0600 Subject: Remove new line --- packages/0x.js/src/utils/heap.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/utils/heap.ts b/packages/0x.js/src/utils/heap.ts index 1135c76b9..e262266d4 100644 --- a/packages/0x.js/src/utils/heap.ts +++ b/packages/0x.js/src/utils/heap.ts @@ -49,7 +49,6 @@ export class Heap { n = parentN; } } - private sinkDown(n: number) { // Look up the target element and its score. const length = this.content.length; -- cgit v1.2.3 From 67ad07020de52eccc27b088ad51094cb319db946 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 11:16:40 -0600 Subject: Remove comment --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 0f73d088a..cd73f1d1f 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -6,7 +6,6 @@ import {SignedOrder, ZeroExError} from '../types'; import {Heap} from '../utils/heap'; import {ZeroEx} from '../0x'; -// Order prunning is very fast const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50; /** -- cgit v1.2.3 From 86d19657b14f7ac7afcb04ae952425f094a02b14 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 11:17:53 -0600 Subject: Improve the comment --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index cd73f1d1f..d699b7a51 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -43,7 +43,7 @@ export class ExpirationWatcher { } public addOrder(orderHash: string, expirationUnixTimestampSec: BigNumber): void { this.expiration[orderHash] = expirationUnixTimestampSec; - // We don't remove hashes on order remove because it's slow (linear). + // We don't remove hashes from the heap on order remove because it's slow (linear). // We just skip them later if the order was already removed from the order watcher. this.orderHashHeapByExpiration.push(orderHash); } -- cgit v1.2.3 From c068ec5231a97752a914eaa0479750c05b5c6342 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 12:49:55 -0600 Subject: Add ifExists suffix --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 4 ++-- packages/0x.js/src/order_watcher/order_state_watcher.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index d699b7a51..cf0222e3c 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -18,8 +18,8 @@ export class ExpirationWatcher { private callbackIfExists?: (orderHash: string) => void; private orderExpirationCheckingIntervalMs: number; private orderExpirationCheckingIntervalIdIfExists?: NodeJS.Timer; - constructor(orderExpirationCheckingIntervalMs?: number) { - this.orderExpirationCheckingIntervalMs = orderExpirationCheckingIntervalMs || + constructor(orderExpirationCheckingIntervalMsIfExists?: number) { + this.orderExpirationCheckingIntervalMs = orderExpirationCheckingIntervalMsIfExists || DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS; const scoreFunction = (orderHash: string) => this.expiration[orderHash].toNumber(); this.orderHashHeapByExpiration = new Heap(scoreFunction); diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index bc61e415c..40007805f 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -74,10 +74,10 @@ export class OrderStateWatcher { this._orderStateUtils = new OrderStateUtils( this._balanceAndProxyAllowanceLazyStore, this._orderFilledCancelledLazyStore, ); - const orderExpirationCheckingIntervalMs = _.isUndefined(config) ? - undefined : - config.orderExpirationCheckingIntervalMs; - this._expirationWatcher = new ExpirationWatcher(orderExpirationCheckingIntervalMs); + const orderExpirationCheckingIntervalMsIfExists = _.isUndefined(config) ? + undefined : + config.orderExpirationCheckingIntervalMs; + this._expirationWatcher = new ExpirationWatcher(orderExpirationCheckingIntervalMsIfExists); } /** * Add an order to the orderStateWatcher. Before the order is added, it's -- cgit v1.2.3 From 49d926013c07d1343ce2d69b413acc7a83bfbe97 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 12:53:16 -0600 Subject: Reference types directly --- packages/0x.js/test/expiration_watcher_test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index 47071416e..629fa7ba6 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -10,10 +10,8 @@ import {utils} from '../src/utils/utils'; import {Web3Wrapper} from '../src/web3_wrapper'; import {TokenUtils} from './utils/token_utils'; import {ExpirationWatcher} from '../src/order_watcher/expiration_watcher'; -import { - ZeroEx, - Token, -} from '../src'; +import {Token} from '../src/types'; +import {ZeroEx} from '../src'; import {FillScenarios} from './utils/fill_scenarios'; import {DoneCallback} from '../src/types'; import {reportCallbackErrors} from './utils/report_callback_errors'; -- cgit v1.2.3 From 83a2abeee4d68020085a5b9f15c806cd6d3b9e20 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 12:53:49 -0600 Subject: Rename orderLifetime to orderLifetimeS --- packages/0x.js/test/expiration_watcher_test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index 629fa7ba6..1b4ba0bf5 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -66,8 +66,8 @@ describe('ExpirationWatcher', () => { }); it('correctly emits events when order expires', (done: DoneCallback) => { (async () => { - const orderLifetime = 60; - const expirationUnixTimestampSec = currentUnixTimestampSec.plus(orderLifetime); + const orderLifetimeS = 60; + const expirationUnixTimestampSec = currentUnixTimestampSec.plus(orderLifetimeS); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationUnixTimestampSec, @@ -80,13 +80,13 @@ describe('ExpirationWatcher', () => { done(); }); expirationWatcher.subscribe(callback); - timer.tick(orderLifetime * 1000); + timer.tick(orderLifetimeS * 1000); })().catch(done); }); it('doesn\'t emit events before order expires', (done: DoneCallback) => { (async () => { - const orderLifetime = 60; - const expirationUnixTimestampSec = currentUnixTimestampSec.plus(orderLifetime); + const orderLifetimeS = 60; + const expirationUnixTimestampSec = currentUnixTimestampSec.plus(orderLifetimeS); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationUnixTimestampSec, @@ -97,7 +97,7 @@ describe('ExpirationWatcher', () => { done(new Error('Emited expiration vent before the order actually expired')); }); expirationWatcher.subscribe(callback); - const notEnoughTime = orderLifetime - 1; + const notEnoughTime = orderLifetimeS - 1; timer.tick(notEnoughTime * 1000); done(); })().catch(done); -- cgit v1.2.3 From 35668fe2259323c84a792b575d99df74702ee620 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 12:54:22 -0600 Subject: Fix typos --- packages/0x.js/test/expiration_watcher_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index 1b4ba0bf5..31e01dba6 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -94,7 +94,7 @@ describe('ExpirationWatcher', () => { const orderHash = ZeroEx.getOrderHashHex(signedOrder); expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec); const callback = reportCallbackErrors(done)((hash: string) => { - done(new Error('Emited expiration vent before the order actually expired')); + done(new Error('Emitted expiration went before the order actually expired')); }); expirationWatcher.subscribe(callback); const notEnoughTime = orderLifetimeS - 1; -- cgit v1.2.3 From a613c3b7e7654728cb56cceb67566ab75313e16f Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 13:02:24 -0600 Subject: Add defaults --- packages/0x.js/src/order_watcher/event_watcher.ts | 10 +++++----- packages/0x.js/src/order_watcher/order_state_watcher.ts | 4 ++-- packages/0x.js/src/types.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/event_watcher.ts b/packages/0x.js/src/order_watcher/event_watcher.ts index 81529a98c..da824bd09 100644 --- a/packages/0x.js/src/order_watcher/event_watcher.ts +++ b/packages/0x.js/src/order_watcher/event_watcher.ts @@ -12,7 +12,7 @@ import {intervalUtils} from '../utils/interval_utils'; import {assert} from '../utils/assert'; import {utils} from '../utils/utils'; -const DEFAULT_EVENT_POLLING_INTERVAL = 200; +const DEFAULT_EVENT_POLLING_INTERVAL_MS = 200; enum LogEventState { Removed, @@ -28,11 +28,11 @@ export class EventWatcher { private _pollingIntervalMs: number; private _intervalIdIfExists?: NodeJS.Timer; private _lastEvents: Web3.LogEntry[] = []; - constructor(web3Wrapper: Web3Wrapper, pollingIntervalMs: undefined|number) { + constructor(web3Wrapper: Web3Wrapper, pollingIntervalIfExistsMs: undefined|number) { this._web3Wrapper = web3Wrapper; - this._pollingIntervalMs = _.isUndefined(pollingIntervalMs) ? - DEFAULT_EVENT_POLLING_INTERVAL : - pollingIntervalMs; + this._pollingIntervalMs = _.isUndefined(pollingIntervalIfExistsMs) ? + DEFAULT_EVENT_POLLING_INTERVAL_MS : + pollingIntervalIfExistsMs; } public subscribe(callback: EventWatcherCallback): void { assert.isFunction('callback', callback); diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 40007805f..27f4c7d29 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -67,8 +67,8 @@ export class OrderStateWatcher { ) { this._abiDecoder = abiDecoder; this._web3Wrapper = web3Wrapper; - const eventPollingIntervalMs = _.isUndefined(config) ? undefined : config.eventPollingIntervalMs; - this._eventWatcher = new EventWatcher(web3Wrapper, eventPollingIntervalMs); + const pollingIntervalIfExistsMs = _.isUndefined(config) ? undefined : config.eventPollingIntervalMs; + this._eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalIfExistsMs); this._balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(token); this._orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(exchange); this._orderStateUtils = new OrderStateUtils( diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 45b49e148..37e80e6bc 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -397,8 +397,8 @@ export interface JSONRPCPayload { } /* - * orderExpirationCheckingIntervalMs: How often to check for expired orders - * eventPollingIntervalMs: How often to poll the Ethereum node for new events + * orderExpirationCheckingIntervalMs: How often to check for expired orders. Default: 50 + * eventPollingIntervalMs: How often to poll the Ethereum node for new events. Defaults: 200 */ export interface OrderStateWatcherConfig { orderExpirationCheckingIntervalMs?: number; -- cgit v1.2.3 From 71475d3ceafd8f1a4a76d1e5b49ff0d186bacd9b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 13:47:09 -0600 Subject: Add expirationMarginMs --- .../0x.js/src/order_watcher/expiration_watcher.ts | 19 +++++++++++++------ .../0x.js/src/order_watcher/order_state_watcher.ts | 10 ++++++++-- packages/0x.js/src/types.ts | 4 ++++ packages/0x.js/src/utils/utils.ts | 7 +++++-- 4 files changed, 30 insertions(+), 10 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index cf0222e3c..71199e75f 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -6,6 +6,7 @@ import {SignedOrder, ZeroExError} from '../types'; import {Heap} from '../utils/heap'; import {ZeroEx} from '../0x'; +const DEFAULT_EXPIRATION_MARGIN_MS = 0; const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50; /** @@ -17,9 +18,13 @@ export class ExpirationWatcher { private expiration: {[orderHash: string]: BigNumber} = {}; private callbackIfExists?: (orderHash: string) => void; private orderExpirationCheckingIntervalMs: number; + private expirationMarginMs: number; private orderExpirationCheckingIntervalIdIfExists?: NodeJS.Timer; - constructor(orderExpirationCheckingIntervalMsIfExists?: number) { - this.orderExpirationCheckingIntervalMs = orderExpirationCheckingIntervalMsIfExists || + constructor(expirationMarginIfExistsMs?: number, + orderExpirationCheckingIntervalIfExistsMs?: number) { + this.expirationMarginMs = expirationMarginIfExistsMs || + DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS; + this.orderExpirationCheckingIntervalMs = expirationMarginIfExistsMs || DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS; const scoreFunction = (orderHash: string) => this.expiration[orderHash].toNumber(); this.orderHashHeapByExpiration = new Heap(scoreFunction); @@ -41,17 +46,19 @@ export class ExpirationWatcher { delete this.callbackIfExists; delete this.orderExpirationCheckingIntervalIdIfExists; } - public addOrder(orderHash: string, expirationUnixTimestampSec: BigNumber): void { - this.expiration[orderHash] = expirationUnixTimestampSec; + public addOrder(orderHash: string, expirationUnixTimestampMs: BigNumber): void { + this.expiration[orderHash] = expirationUnixTimestampMs; // We don't remove hashes from the heap on order remove because it's slow (linear). // We just skip them later if the order was already removed from the order watcher. this.orderHashHeapByExpiration.push(orderHash); } private pruneExpiredOrders(): void { - const currentUnixTimestampSec = utils.getCurrentUnixTimestamp(); + const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs(); while ( this.orderHashHeapByExpiration.size() !== 0 && - this.expiration[this.orderHashHeapByExpiration.head()].lessThan(currentUnixTimestampSec) && + this.expiration[this.orderHashHeapByExpiration.head()].lessThan( + currentUnixTimestampMs.plus(this.expirationMarginMs), + ) && !_.isUndefined(this.callbackIfExists) ) { const orderHash = this.orderHashHeapByExpiration.pop(); diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 27f4c7d29..3659fc6e2 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -77,7 +77,12 @@ export class OrderStateWatcher { const orderExpirationCheckingIntervalMsIfExists = _.isUndefined(config) ? undefined : config.orderExpirationCheckingIntervalMs; - this._expirationWatcher = new ExpirationWatcher(orderExpirationCheckingIntervalMsIfExists); + const expirationMarginIfExistsMs = _.isUndefined(config) ? + undefined : + config.expirationMarginMs; + this._expirationWatcher = new ExpirationWatcher( + expirationMarginIfExistsMs, orderExpirationCheckingIntervalMsIfExists, + ); } /** * Add an order to the orderStateWatcher. Before the order is added, it's @@ -91,7 +96,8 @@ export class OrderStateWatcher { this._orderByOrderHash[orderHash] = signedOrder; this.addToDependentOrderHashes(signedOrder, orderHash); // We don't remove orders from expirationWatcher because heap removal is linear. We just skip it later - this._expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec); + const expirationUnixTimestampMs = signedOrder.expirationUnixTimestampSec.times(1000); + this._expirationWatcher.addOrder(orderHash, expirationUnixTimestampMs); } /** * Removes an order from the orderStateWatcher diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 37e80e6bc..13a46659d 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -396,14 +396,18 @@ export interface JSONRPCPayload { method: string; } +// tslint:disable:max-line-length /* * orderExpirationCheckingIntervalMs: How often to check for expired orders. Default: 50 * eventPollingIntervalMs: How often to poll the Ethereum node for new events. Defaults: 200 + * expirationMarginMs: Amount of time before order expiry that you'd like to be notified of an orders expiration. Defaults: 0 */ export interface OrderStateWatcherConfig { orderExpirationCheckingIntervalMs?: number; eventPollingIntervalMs?: number; + expirationMarginMs?: number; } +// tslint:enable:max-line-length /* * gasPrice: Gas price to use with every transaction diff --git a/packages/0x.js/src/utils/utils.ts b/packages/0x.js/src/utils/utils.ts index 280f3e979..5370c3b4b 100644 --- a/packages/0x.js/src/utils/utils.ts +++ b/packages/0x.js/src/utils/utils.ts @@ -49,7 +49,10 @@ export const utils = { const hashHex = ethUtil.bufferToHex(hashBuff); return hashHex; }, - getCurrentUnixTimestamp(): BigNumber { - return new BigNumber(Date.now() / 1000); + getCurrentUnixTimestampSec(): BigNumber { + return new BigNumber(Date.now() / 1000).round(); + }, + getCurrentUnixTimestampMs(): BigNumber { + return new BigNumber(Date.now()); }, }; -- cgit v1.2.3 From 5788b90c522b63b53f5e8480f2b357ee24bb08a3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 14:40:53 -0600 Subject: Remove custom heap and use bintrees --- packages/0x.js/package.json | 4 +- .../0x.js/src/order_watcher/expiration_watcher.ts | 22 +++--- .../0x.js/src/order_watcher/order_state_watcher.ts | 2 +- packages/0x.js/src/utils/heap.ts | 92 ---------------------- 4 files changed, 17 insertions(+), 103 deletions(-) delete mode 100644 packages/0x.js/src/utils/heap.ts (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 6839e6513..539a78f37 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -49,6 +49,7 @@ "node": ">=6.0.0" }, "devDependencies": { + "@types/bintrees": "^1.0.2", "@types/jsonschema": "^1.1.1", "@types/lodash": "^4.14.64", "@types/mocha": "^2.2.41", @@ -87,9 +88,10 @@ "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "0.0.3", "0x-json-schemas": "^0.6.1", + "@0xproject/assert": "0.0.3", "bignumber.js": "~4.1.0", + "bintrees": "^1.0.2", "compare-versions": "^3.0.1", "es6-promisify": "^5.0.0", "ethereumjs-abi": "^0.6.4", diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 71199e75f..7d6f8df65 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -1,9 +1,9 @@ import * as _ from 'lodash'; import {BigNumber} from 'bignumber.js'; +import {RBTree} from 'bintrees'; import {utils} from '../utils/utils'; import {intervalUtils} from '../utils/interval_utils'; import {SignedOrder, ZeroExError} from '../types'; -import {Heap} from '../utils/heap'; import {ZeroEx} from '../0x'; const DEFAULT_EXPIRATION_MARGIN_MS = 0; @@ -14,7 +14,7 @@ const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50; * It stores them in a min heap by expiration time and checks for expired ones every `orderExpirationCheckingIntervalMs` */ export class ExpirationWatcher { - private orderHashHeapByExpiration: Heap; + private orderHashRBTreeByExpiration: RBTree; private expiration: {[orderHash: string]: BigNumber} = {}; private callbackIfExists?: (orderHash: string) => void; private orderExpirationCheckingIntervalMs: number; @@ -27,7 +27,8 @@ export class ExpirationWatcher { this.orderExpirationCheckingIntervalMs = expirationMarginIfExistsMs || DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS; const scoreFunction = (orderHash: string) => this.expiration[orderHash].toNumber(); - this.orderHashHeapByExpiration = new Heap(scoreFunction); + const comparator = (lhs: string, rhs: string) => scoreFunction(lhs) - scoreFunction(rhs); + this.orderHashRBTreeByExpiration = new RBTree(comparator); } public subscribe(callback: (orderHash: string) => void): void { if (!_.isUndefined(this.callbackIfExists)) { @@ -48,20 +49,23 @@ export class ExpirationWatcher { } public addOrder(orderHash: string, expirationUnixTimestampMs: BigNumber): void { this.expiration[orderHash] = expirationUnixTimestampMs; - // We don't remove hashes from the heap on order remove because it's slow (linear). - // We just skip them later if the order was already removed from the order watcher. - this.orderHashHeapByExpiration.push(orderHash); + this.orderHashRBTreeByExpiration.insert(orderHash); + } + public removeOrder(orderHash: string): void { + this.orderHashRBTreeByExpiration.remove(orderHash); + delete this.expiration[orderHash]; } private pruneExpiredOrders(): void { const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs(); while ( - this.orderHashHeapByExpiration.size() !== 0 && - this.expiration[this.orderHashHeapByExpiration.head()].lessThan( + this.orderHashRBTreeByExpiration.size !== 0 && + this.expiration[this.orderHashRBTreeByExpiration.min()].lessThan( currentUnixTimestampMs.plus(this.expirationMarginMs), ) && !_.isUndefined(this.callbackIfExists) ) { - const orderHash = this.orderHashHeapByExpiration.pop(); + const orderHash = this.orderHashRBTreeByExpiration.min(); + this.orderHashRBTreeByExpiration.remove(orderHash); delete this.expiration[orderHash]; this.callbackIfExists(orderHash); } diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 3659fc6e2..975679f57 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -95,7 +95,6 @@ export class OrderStateWatcher { assert.isValidSignature(orderHash, signedOrder.ecSignature, signedOrder.maker); this._orderByOrderHash[orderHash] = signedOrder; this.addToDependentOrderHashes(signedOrder, orderHash); - // We don't remove orders from expirationWatcher because heap removal is linear. We just skip it later const expirationUnixTimestampMs = signedOrder.expirationUnixTimestampSec.times(1000); this._expirationWatcher.addOrder(orderHash, expirationUnixTimestampMs); } @@ -111,6 +110,7 @@ export class OrderStateWatcher { } delete this._orderByOrderHash[orderHash]; this.removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash); + this._expirationWatcher.removeOrder(orderHash); } /** * Starts an orderStateWatcher subscription. The callback will be called every time a watched order's diff --git a/packages/0x.js/src/utils/heap.ts b/packages/0x.js/src/utils/heap.ts deleted file mode 100644 index e262266d4..000000000 --- a/packages/0x.js/src/utils/heap.ts +++ /dev/null @@ -1,92 +0,0 @@ -// Based on Original JavaScript Code from Marijn Haverbeke (http://eloquentjavascript.net/1st_edition/appendix2.html) -export class Heap { - private content: T[]; - private scoreFunction: (x: T) => number; - constructor(scoreFunction: (x: T) => number) { - this.content = []; - this.scoreFunction = scoreFunction; - } - public push(element: T) { - this.content.push(element); - this.bubbleUp(this.content.length - 1); - } - public size(): number { - const size = this.content.length; - return size; - } - public head(): T { - const head = this.content[0]; - return head; - } - public pop(): T { - const head = this.content[0]; - const end = this.content.pop(); - if (this.content.length > 0) { - this.content[0] = end as T; - this.sinkDown(0); - } - return head; - } - private bubbleUp(n: number) { - // Fetch the element that has to be moved. - const element = this.content[n]; - const score = this.scoreFunction(element); - // When at 0, an element can not go up any further. - while (n > 0) { - // Compute the parent element's index, and fetch it. - const parentN = Math.floor((n + 1) / 2) - 1; - const parent = this.content[parentN]; - // If the parent has a lesser score, things are in order and we - // are done. - if (score >= this.scoreFunction(parent)) { - break; - } - - // Otherwise, swap the parent with the current element and - // continue. - this.content[parentN] = element; - this.content[n] = parent; - n = parentN; - } - } - private sinkDown(n: number) { - // Look up the target element and its score. - const length = this.content.length; - const element = this.content[n]; - const elemScore = this.scoreFunction(element); - - while (true) { - // Compute the indices of the child elements. - const child2N = (n + 1) * 2; - const child1N = child2N - 1; - // This is used to store the new position of the element, if any. - let swap = n; - let child1Score; - let child2Score; - // If the first child exists (is inside the array)... - if (child1N < length) { - // Look it up and compute its score. - const child1 = this.content[child1N]; - child1Score = this.scoreFunction(child1); - // If the score is less than our element's, we need to swap. - if (child1Score < elemScore) { - swap = child1N; - } - // Do the same checks for the other child. - if (child2N < length) { - const child2 = this.content[child2N]; - child2Score = this.scoreFunction(child2); - if (child2Score < (swap == null ? elemScore : child1Score)) { - swap = child2N; - } - } - } - if (swap === n) { - break; - } - this.content[n] = this.content[swap]; - this.content[swap] = element; - n = swap; - } - } -} -- cgit v1.2.3 From 9745d5348c7cbef0d0b16fafa2453acfc6cb2c1f Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 16:14:40 -0600 Subject: Pass callback down --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 7d6f8df65..933cb6f1d 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -16,7 +16,6 @@ const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50; export class ExpirationWatcher { private orderHashRBTreeByExpiration: RBTree; private expiration: {[orderHash: string]: BigNumber} = {}; - private callbackIfExists?: (orderHash: string) => void; private orderExpirationCheckingIntervalMs: number; private expirationMarginMs: number; private orderExpirationCheckingIntervalIdIfExists?: NodeJS.Timer; @@ -31,12 +30,11 @@ export class ExpirationWatcher { this.orderHashRBTreeByExpiration = new RBTree(comparator); } public subscribe(callback: (orderHash: string) => void): void { - if (!_.isUndefined(this.callbackIfExists)) { + if (!_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists)) { throw new Error(ZeroExError.SubscriptionAlreadyPresent); } - this.callbackIfExists = callback; this.orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( - this.pruneExpiredOrders.bind(this), this.orderExpirationCheckingIntervalMs, + this.pruneExpiredOrders.bind(this, callback), this.orderExpirationCheckingIntervalMs, ); } public unsubscribe(): void { @@ -44,7 +42,6 @@ export class ExpirationWatcher { throw new Error(ZeroExError.SubscriptionNotFound); } intervalUtils.clearAsyncExcludingInterval(this.orderExpirationCheckingIntervalIdIfExists); - delete this.callbackIfExists; delete this.orderExpirationCheckingIntervalIdIfExists; } public addOrder(orderHash: string, expirationUnixTimestampMs: BigNumber): void { @@ -55,19 +52,18 @@ export class ExpirationWatcher { this.orderHashRBTreeByExpiration.remove(orderHash); delete this.expiration[orderHash]; } - private pruneExpiredOrders(): void { + private pruneExpiredOrders(callback: (orderHash: string) => void): void { const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs(); while ( this.orderHashRBTreeByExpiration.size !== 0 && this.expiration[this.orderHashRBTreeByExpiration.min()].lessThan( currentUnixTimestampMs.plus(this.expirationMarginMs), - ) && - !_.isUndefined(this.callbackIfExists) + ) ) { const orderHash = this.orderHashRBTreeByExpiration.min(); this.orderHashRBTreeByExpiration.remove(orderHash); delete this.expiration[orderHash]; - this.callbackIfExists(orderHash); + callback(orderHash); } } } -- cgit v1.2.3 From b01a4af99ed246cda6307ea10303ad25d2cadbe0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 16:17:23 -0600 Subject: Rename --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 933cb6f1d..7d6ce6bdd 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -14,7 +14,7 @@ const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50; * It stores them in a min heap by expiration time and checks for expired ones every `orderExpirationCheckingIntervalMs` */ export class ExpirationWatcher { - private orderHashRBTreeByExpiration: RBTree; + private orderHashByExpirationRBTree: RBTree; private expiration: {[orderHash: string]: BigNumber} = {}; private orderExpirationCheckingIntervalMs: number; private expirationMarginMs: number; @@ -27,7 +27,7 @@ export class ExpirationWatcher { DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS; const scoreFunction = (orderHash: string) => this.expiration[orderHash].toNumber(); const comparator = (lhs: string, rhs: string) => scoreFunction(lhs) - scoreFunction(rhs); - this.orderHashRBTreeByExpiration = new RBTree(comparator); + this.orderHashByExpirationRBTree = new RBTree(comparator); } public subscribe(callback: (orderHash: string) => void): void { if (!_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists)) { @@ -46,22 +46,22 @@ export class ExpirationWatcher { } public addOrder(orderHash: string, expirationUnixTimestampMs: BigNumber): void { this.expiration[orderHash] = expirationUnixTimestampMs; - this.orderHashRBTreeByExpiration.insert(orderHash); + this.orderHashByExpirationRBTree.insert(orderHash); } public removeOrder(orderHash: string): void { - this.orderHashRBTreeByExpiration.remove(orderHash); + this.orderHashByExpirationRBTree.remove(orderHash); delete this.expiration[orderHash]; } private pruneExpiredOrders(callback: (orderHash: string) => void): void { const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs(); while ( - this.orderHashRBTreeByExpiration.size !== 0 && - this.expiration[this.orderHashRBTreeByExpiration.min()].lessThan( + this.orderHashByExpirationRBTree.size !== 0 && + this.expiration[this.orderHashByExpirationRBTree.min()].lessThan( currentUnixTimestampMs.plus(this.expirationMarginMs), ) ) { - const orderHash = this.orderHashRBTreeByExpiration.min(); - this.orderHashRBTreeByExpiration.remove(orderHash); + const orderHash = this.orderHashByExpirationRBTree.min(); + this.orderHashByExpirationRBTree.remove(orderHash); delete this.expiration[orderHash]; callback(orderHash); } -- cgit v1.2.3 From 3bc3666215d4fdaa6d9db87e065ca5e762df9b25 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 16:25:51 -0600 Subject: Check if callback exists --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 8 ++++---- packages/0x.js/src/order_watcher/order_state_watcher.ts | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 7d6ce6bdd..efedd3cf8 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -29,12 +29,12 @@ export class ExpirationWatcher { const comparator = (lhs: string, rhs: string) => scoreFunction(lhs) - scoreFunction(rhs); this.orderHashByExpirationRBTree = new RBTree(comparator); } - public subscribe(callback: (orderHash: string) => void): void { + public subscribe(callbackAsync: (orderHash: string) => Promise): void { if (!_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists)) { throw new Error(ZeroExError.SubscriptionAlreadyPresent); } this.orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( - this.pruneExpiredOrders.bind(this, callback), this.orderExpirationCheckingIntervalMs, + this.pruneExpiredOrdersAsync.bind(this, callbackAsync), this.orderExpirationCheckingIntervalMs, ); } public unsubscribe(): void { @@ -52,7 +52,7 @@ export class ExpirationWatcher { this.orderHashByExpirationRBTree.remove(orderHash); delete this.expiration[orderHash]; } - private pruneExpiredOrders(callback: (orderHash: string) => void): void { + private async pruneExpiredOrdersAsync(callbackAsync: (orderHash: string) => Promise): Promise { const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs(); while ( this.orderHashByExpirationRBTree.size !== 0 && @@ -63,7 +63,7 @@ export class ExpirationWatcher { const orderHash = this.orderHashByExpirationRBTree.min(); this.orderHashByExpirationRBTree.remove(orderHash); delete this.expiration[orderHash]; - callback(orderHash); + await callbackAsync(orderHash); } } } diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 579fa388a..84f2128c0 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -128,7 +128,7 @@ export class OrderStateWatcher { } this._callbackIfExists = callback; this._eventWatcher.subscribe(this._onEventWatcherCallbackAsync.bind(this)); - this._expirationWatcher.subscribe(this._onOrderExpired.bind(this)); + this._expirationWatcher.subscribe(this._onOrderExpiredAsync.bind(this)); } /** * Ends an orderStateWatcher subscription. @@ -143,7 +143,7 @@ export class OrderStateWatcher { this._eventWatcher.unsubscribe(); this._expirationWatcher.unsubscribe(); } - private _onOrderExpired(orderHash: string): void { + private async _onOrderExpiredAsync(orderHash: string): Promise { const orderState: OrderState = { isValid: false, orderHash, @@ -151,8 +151,10 @@ export class OrderStateWatcher { }; if (!_.isUndefined(this._orderByOrderHash[orderHash])) { // We need this check because we never remove the orders from expiration watcher - this.removeOrder(orderHash); - (this._callbackIfExistsAsync as OnOrderStateChangeCallback)(orderState); + await this.removeOrderAsync(orderHash); + if (!_.isUndefined(this._callbackIfExists)) { + this._callbackIfExists(orderState); + } } } private async _onEventWatcherCallbackAsync(log: LogEvent): Promise { -- cgit v1.2.3 From 3e0371685fe16b7dc96f5f900c0d4531b16370d4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 16:39:34 -0600 Subject: Fix async callbacks --- packages/0x.js/src/utils/order_validation_utils.ts | 4 ++-- packages/0x.js/test/expiration_watcher_test.ts | 19 +++++++++---------- packages/0x.js/test/utils/report_callback_errors.ts | 6 +++--- 3 files changed, 14 insertions(+), 15 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/utils/order_validation_utils.ts b/packages/0x.js/src/utils/order_validation_utils.ts index f03703c4e..ed723e3d4 100644 --- a/packages/0x.js/src/utils/order_validation_utils.ts +++ b/packages/0x.js/src/utils/order_validation_utils.ts @@ -102,7 +102,7 @@ export class OrderValidationUtils { if (order.takerTokenAmount.eq(unavailableTakerTokenAmount)) { throw new Error(ExchangeContractErrs.OrderAlreadyCancelledOrFilled); } - const currentUnixTimestampSec = utils.getCurrentUnixTimestamp(); + const currentUnixTimestampSec = utils.getCurrentUnixTimestampSec(); if (order.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) { throw new Error(ExchangeContractErrs.OrderCancelExpired); } @@ -150,7 +150,7 @@ export class OrderValidationUtils { } } private validateOrderNotExpiredOrThrow(expirationUnixTimestampSec: BigNumber) { - const currentUnixTimestampSec = utils.getCurrentUnixTimestamp(); + const currentUnixTimestampSec = utils.getCurrentUnixTimestampSec(); if (expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) { throw new Error(ExchangeContractErrs.OrderFillExpired); } diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index 31e01dba6..a384658e7 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -10,10 +10,9 @@ import {utils} from '../src/utils/utils'; import {Web3Wrapper} from '../src/web3_wrapper'; import {TokenUtils} from './utils/token_utils'; import {ExpirationWatcher} from '../src/order_watcher/expiration_watcher'; -import {Token} from '../src/types'; +import {Token, DoneCallback} from '../src/types'; import {ZeroEx} from '../src'; import {FillScenarios} from './utils/fill_scenarios'; -import {DoneCallback} from '../src/types'; import {reportCallbackErrors} from './utils/report_callback_errors'; chaiSetup.configure(); @@ -57,7 +56,7 @@ describe('ExpirationWatcher', () => { const sinonTimerConfig = {shouldAdvanceTime: true} as any; // This constructor has incorrect types timer = Sinon.useFakeTimers(sinonTimerConfig); - currentUnixTimestampSec = utils.getCurrentUnixTimestamp(); + currentUnixTimestampSec = utils.getCurrentUnixTimestampSec(); expirationWatcher = new ExpirationWatcher(); }); afterEach(() => { @@ -74,12 +73,12 @@ describe('ExpirationWatcher', () => { ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec); - const callback = reportCallbackErrors(done)((hash: string) => { + const callbackAsync = reportCallbackErrors(done)(async (hash: string) => { expect(hash).to.be.equal(orderHash); - expect(utils.getCurrentUnixTimestamp()).to.be.bignumber.above(expirationUnixTimestampSec); + expect(utils.getCurrentUnixTimestampSec()).to.be.bignumber.above(expirationUnixTimestampSec); done(); }); - expirationWatcher.subscribe(callback); + expirationWatcher.subscribe(callbackAsync); timer.tick(orderLifetimeS * 1000); })().catch(done); }); @@ -93,10 +92,10 @@ describe('ExpirationWatcher', () => { ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec); - const callback = reportCallbackErrors(done)((hash: string) => { + const callbackAsync = reportCallbackErrors(done)(async (hash: string) => { done(new Error('Emitted expiration went before the order actually expired')); }); - expirationWatcher.subscribe(callback); + expirationWatcher.subscribe(callbackAsync); const notEnoughTime = orderLifetimeS - 1; timer.tick(notEnoughTime * 1000); done(); @@ -121,14 +120,14 @@ describe('ExpirationWatcher', () => { expirationWatcher.addOrder(orderHash2, signedOrder2.expirationUnixTimestampSec); expirationWatcher.addOrder(orderHash1, signedOrder1.expirationUnixTimestampSec); const expirationOrder = [orderHash1, orderHash2]; - const callback = reportCallbackErrors(done)((hash: string) => { + const callbackAsync = reportCallbackErrors(done)(async (hash: string) => { const orderHash = expirationOrder.shift(); expect(hash).to.be.equal(orderHash); if (_.isEmpty(expirationOrder)) { done(); } }); - expirationWatcher.subscribe(callback); + expirationWatcher.subscribe(callbackAsync); timer.tick(order2Lifetime * 1000); })().catch(done); }); diff --git a/packages/0x.js/test/utils/report_callback_errors.ts b/packages/0x.js/test/utils/report_callback_errors.ts index d471b2af2..4f9517704 100644 --- a/packages/0x.js/test/utils/report_callback_errors.ts +++ b/packages/0x.js/test/utils/report_callback_errors.ts @@ -1,10 +1,10 @@ import { DoneCallback } from '../../src/types'; export const reportCallbackErrors = (done: DoneCallback) => { - return (f: (...args: any[]) => void) => { - const wrapped = (...args: any[]) => { + return (fAsync: (...args: any[]) => void|Promise) => { + const wrapped = async (...args: any[]) => { try { - f(...args); + await fAsync(...args); } catch (err) { done(err); } -- cgit v1.2.3 From 3fc8645d92f293fcfd3a10affcabdbd75b8714b5 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 16:52:53 -0600 Subject: Remove old comment --- packages/0x.js/src/order_watcher/order_state_watcher.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 84f2128c0..fd7496699 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -150,7 +150,6 @@ export class OrderStateWatcher { error: ExchangeContractErrs.OrderFillExpired, }; if (!_.isUndefined(this._orderByOrderHash[orderHash])) { - // We need this check because we never remove the orders from expiration watcher await this.removeOrderAsync(orderHash); if (!_.isUndefined(this._callbackIfExists)) { this._callbackIfExists(orderState); -- cgit v1.2.3 From 3ad6020e192e73ce276cc090751cedf2036e6a06 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 16:55:53 -0600 Subject: Address nits --- packages/0x.js/src/types.ts | 5 ++--- packages/0x.js/test/expiration_watcher_test.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 39c60695e..c3aabfd86 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -391,18 +391,17 @@ export interface JSONRPCPayload { method: string; } -// tslint:disable:max-line-length /* * orderExpirationCheckingIntervalMs: How often to check for expired orders. Default: 50 * eventPollingIntervalMs: How often to poll the Ethereum node for new events. Defaults: 200 - * expirationMarginMs: Amount of time before order expiry that you'd like to be notified of an orders expiration. Defaults: 0 + * expirationMarginMs: Amount of time before order expiry that you'd like to be notified + * of an orders expiration. Defaults: 0 */ export interface OrderStateWatcherConfig { orderExpirationCheckingIntervalMs?: number; eventPollingIntervalMs?: number; expirationMarginMs?: number; } -// tslint:enable:max-line-length /* * gasPrice: Gas price to use with every transaction diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index a384658e7..19c08a811 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -11,7 +11,7 @@ import {Web3Wrapper} from '../src/web3_wrapper'; import {TokenUtils} from './utils/token_utils'; import {ExpirationWatcher} from '../src/order_watcher/expiration_watcher'; import {Token, DoneCallback} from '../src/types'; -import {ZeroEx} from '../src'; +import {ZeroEx} from '../src/0x'; import {FillScenarios} from './utils/fill_scenarios'; import {reportCallbackErrors} from './utils/report_callback_errors'; @@ -65,8 +65,8 @@ describe('ExpirationWatcher', () => { }); it('correctly emits events when order expires', (done: DoneCallback) => { (async () => { - const orderLifetimeS = 60; - const expirationUnixTimestampSec = currentUnixTimestampSec.plus(orderLifetimeS); + const orderLifetimeSec = 60; + const expirationUnixTimestampSec = currentUnixTimestampSec.plus(orderLifetimeSec); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationUnixTimestampSec, @@ -79,13 +79,13 @@ describe('ExpirationWatcher', () => { done(); }); expirationWatcher.subscribe(callbackAsync); - timer.tick(orderLifetimeS * 1000); + timer.tick(orderLifetimeSec * 1000); })().catch(done); }); it('doesn\'t emit events before order expires', (done: DoneCallback) => { (async () => { - const orderLifetimeS = 60; - const expirationUnixTimestampSec = currentUnixTimestampSec.plus(orderLifetimeS); + const orderLifetimeSec = 60; + const expirationUnixTimestampSec = currentUnixTimestampSec.plus(orderLifetimeSec); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationUnixTimestampSec, @@ -96,7 +96,7 @@ describe('ExpirationWatcher', () => { done(new Error('Emitted expiration went before the order actually expired')); }); expirationWatcher.subscribe(callbackAsync); - const notEnoughTime = orderLifetimeS - 1; + const notEnoughTime = orderLifetimeSec - 1; timer.tick(notEnoughTime * 1000); done(); })().catch(done); -- cgit v1.2.3 From c4669013abe477e555745c10c16194d47f523f9e Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 17:24:30 -0600 Subject: Check if transactionReceipt exists before normalizing it --- packages/0x.js/src/web3_wrapper.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/web3_wrapper.ts b/packages/0x.js/src/web3_wrapper.ts index c937f9288..12d7caaf8 100644 --- a/packages/0x.js/src/web3_wrapper.ts +++ b/packages/0x.js/src/web3_wrapper.ts @@ -39,7 +39,9 @@ export class Web3Wrapper { } public async getTransactionReceiptAsync(txHash: string): Promise { const transactionReceipt = await promisify(this.web3.eth.getTransactionReceipt)(txHash); - transactionReceipt.status = this.normalizeTxReceiptStatus(transactionReceipt.status); + if (!_.isNull(transactionReceipt)) { + transactionReceipt.status = this.normalizeTxReceiptStatus(transactionReceipt.status); + } return transactionReceipt; } public getCurrentProvider(): Web3.Provider { -- cgit v1.2.3 From cfcbf34305cf1dffeb677761138a93403d9b82be Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 17:46:53 -0600 Subject: Fix test:circleci command --- packages/0x.js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 4fe11a8dc..36c3b8c8e 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -17,7 +17,7 @@ "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR", "upload_docs_json": "aws s3 cp docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json", "lint": "tslint src/**/*.ts test/**/*.ts", - "test:circleci": "run-s test:coverage report_test_coverage; if [ $CIRCLE_BRANCH = \"development\" ]; then yarn test:umd; fi", + "test:circleci": "run-s test:coverage report_test_coverage && if [ $CIRCLE_BRANCH = \"development\" ]; then yarn test:umd; fi", "test": "run-s clean test:commonjs", "test:umd": "./scripts/test_umd.sh", "test:coverage": "nyc npm run test --all", -- cgit v1.2.3 From 4dc1962f9ec2c537b7944246842d934c3aee186d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 11:59:34 -0600 Subject: Fix a typo --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index efedd3cf8..21b239be1 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -22,7 +22,7 @@ export class ExpirationWatcher { constructor(expirationMarginIfExistsMs?: number, orderExpirationCheckingIntervalIfExistsMs?: number) { this.expirationMarginMs = expirationMarginIfExistsMs || - DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS; + DEFAULT_EXPIRATION_MARGIN_MS; this.orderExpirationCheckingIntervalMs = expirationMarginIfExistsMs || DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS; const scoreFunction = (orderHash: string) => this.expiration[orderHash].toNumber(); -- cgit v1.2.3 From 351b7557b65e4cdef2177585d52021ee5a0f3e42 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 12:21:49 -0600 Subject: Fix tests --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 3 ++- packages/0x.js/test/expiration_watcher_test.ts | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 21b239be1..5aa8b3d17 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -58,7 +58,8 @@ export class ExpirationWatcher { this.orderHashByExpirationRBTree.size !== 0 && this.expiration[this.orderHashByExpirationRBTree.min()].lessThan( currentUnixTimestampMs.plus(this.expirationMarginMs), - ) + ) && + !_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists) ) { const orderHash = this.orderHashByExpirationRBTree.min(); this.orderHashByExpirationRBTree.remove(orderHash); diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index 19c08a811..0d5ebb909 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -72,10 +72,10 @@ describe('ExpirationWatcher', () => { expirationUnixTimestampSec, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec); + expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec.times(1000)); const callbackAsync = reportCallbackErrors(done)(async (hash: string) => { expect(hash).to.be.equal(orderHash); - expect(utils.getCurrentUnixTimestampSec()).to.be.bignumber.above(expirationUnixTimestampSec); + expect(utils.getCurrentUnixTimestampSec()).to.be.bignumber.gte(expirationUnixTimestampSec); done(); }); expirationWatcher.subscribe(callbackAsync); @@ -91,7 +91,7 @@ describe('ExpirationWatcher', () => { expirationUnixTimestampSec, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec); + expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec.times(1000)); const callbackAsync = reportCallbackErrors(done)(async (hash: string) => { done(new Error('Emitted expiration went before the order actually expired')); }); @@ -117,8 +117,8 @@ describe('ExpirationWatcher', () => { ); const orderHash1 = ZeroEx.getOrderHashHex(signedOrder1); const orderHash2 = ZeroEx.getOrderHashHex(signedOrder2); - expirationWatcher.addOrder(orderHash2, signedOrder2.expirationUnixTimestampSec); - expirationWatcher.addOrder(orderHash1, signedOrder1.expirationUnixTimestampSec); + expirationWatcher.addOrder(orderHash2, signedOrder2.expirationUnixTimestampSec.times(1000)); + expirationWatcher.addOrder(orderHash1, signedOrder1.expirationUnixTimestampSec.times(1000)); const expirationOrder = [orderHash1, orderHash2]; const callbackAsync = reportCallbackErrors(done)(async (hash: string) => { const orderHash = expirationOrder.shift(); -- cgit v1.2.3 From c8c95b4bd2e57be11bd250c652babbad9d6ffd35 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 13:09:23 -0600 Subject: Add postFormatter for logs --- packages/0x.js/src/web3_wrapper.ts | 34 ++++++++++++++++++++++++++++--- packages/0x.js/test/token_wrapper_test.ts | 2 ++ 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/web3_wrapper.ts b/packages/0x.js/src/web3_wrapper.ts index c937f9288..af96c7650 100644 --- a/packages/0x.js/src/web3_wrapper.ts +++ b/packages/0x.js/src/web3_wrapper.ts @@ -5,6 +5,17 @@ import promisify = require('es6-promisify'); import {ZeroExError, Artifact, TransactionReceipt} from './types'; import {Contract} from './contract'; +interface RawLogEntry { + logIndex: string|null; + transactionIndex: string|null; + transactionHash: string; + blockHash: string|null; + blockNumber: string|null; + address: string; + data: string; + topics: string[]; +} + export class Web3Wrapper { private web3: Web3; private defaults: Partial; @@ -137,8 +148,9 @@ export class Web3Wrapper { method: 'eth_getLogs', params: [serializedFilter], }; - const logs = await this.sendRawPayloadAsync(payload); - return logs; + const rawLogs = await this.sendRawPayloadAsync(payload); + const formattedLogs = _.map(rawLogs, this.formatLog.bind(this)); + return formattedLogs; } private getContractInstance(abi: Web3.ContractAbi, address: string): A { const web3ContractInstance = this.web3.eth.contract(abi).at(address); @@ -149,7 +161,7 @@ export class Web3Wrapper { const networkId = await promisify(this.web3.version.getNetwork)(); return networkId; } - private async sendRawPayloadAsync(payload: Web3.JSONRPCRequestPayload): Promise { + private async sendRawPayloadAsync(payload: Web3.JSONRPCRequestPayload): Promise { const sendAsync = this.web3.currentProvider.sendAsync.bind(this.web3.currentProvider); const response = await promisify(sendAsync)(payload); const result = response.result; @@ -169,4 +181,20 @@ export class Web3Wrapper { return status; } } + private formatLog(rawLog: RawLogEntry): Web3.LogEntry { + const formattedLog = { + ...rawLog, + logIndex: this.toDecimal(rawLog.logIndex), + blockNumber: this.toDecimal(rawLog.blockNumber), + transactionIndex: this.toDecimal(rawLog.transactionIndex), + }; + return formattedLog; + } + private toDecimal(hex: string|null): number|null { + if (_.isNull(hex)) { + return null; + } + const decimal = this.web3.toDecimal(hex); + return decimal; + } } diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index b30762e8c..07276877d 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -361,6 +361,8 @@ describe('TokenWrapper', () => { (async () => { const callback = (err: Error, logEvent: DecodedLogEvent) => { expect(logEvent).to.not.be.undefined(); + expect(logEvent.logIndex).to.be.equal(0); + expect(logEvent.transactionIndex).to.be.equal(0); const args = logEvent.args; expect(args._from).to.be.equal(coinbase); expect(args._to).to.be.equal(addressWithoutFunds); -- cgit v1.2.3 From 173a707a2e1f5667500e1a8ea6eb1a775a584291 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 13:15:05 -0600 Subject: Add PR numbers --- packages/0x.js/CHANGELOG.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 6245308c3..26e5f528b 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -2,18 +2,19 @@ vx.x.x ------------------------ - * Remove support for Async callback types when used in Subscribe functions + * Add post-formatter for logs converting `blockNumber`, `logIndex`, `transactionIndex` from hexes to numbers (#231) + * Remove support for Async callback types when used in Subscribe functions (#222) * In OrderWatcher subscribe to ZRX Token Transfer and Approval events when maker token is different (#225) v0.25.1 - _November 13, 2017_ ------------------------ - * Standardise on Cancelled over Canceled - * Add missing `DecodedLogEvent` type to exported types - * Normalized the transactionReceipt status to be `null|0|1`, 1 meaning transaction execution successful, 0 unsuccessful and `null` if it is a pre-byzantinium transaction. + * Standardise on Cancelled over Canceled (#217) + * Add missing `DecodedLogEvent` type to exported types (#205) + * Normalized the transactionReceipt status to be `null|0|1`, 1 meaning transaction execution successful, 0 unsuccessful and `null` if it is a pre-byzantinium transaction. (#200) v0.23.0 - _November 12, 2017_ ------------------------ - * Fixed unhandled promise rejection error in subscribe methods (#209) + * Fixed unhandled promise rejection error in subscribe methods (#209) * Subscribe callbacks now receive an error object as their first argument v0.22.6 - _November 10, 2017_ -- cgit v1.2.3 From 8d6ba6ee7a73cdc00e089f0c493864cd02e5a833 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 13:16:55 -0600 Subject: Rename toDecimal to hexToDecimal --- packages/0x.js/src/web3_wrapper.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/web3_wrapper.ts b/packages/0x.js/src/web3_wrapper.ts index af96c7650..f6b6ca09a 100644 --- a/packages/0x.js/src/web3_wrapper.ts +++ b/packages/0x.js/src/web3_wrapper.ts @@ -184,13 +184,13 @@ export class Web3Wrapper { private formatLog(rawLog: RawLogEntry): Web3.LogEntry { const formattedLog = { ...rawLog, - logIndex: this.toDecimal(rawLog.logIndex), - blockNumber: this.toDecimal(rawLog.blockNumber), - transactionIndex: this.toDecimal(rawLog.transactionIndex), + logIndex: this.hexToDecimal(rawLog.logIndex), + blockNumber: this.hexToDecimal(rawLog.blockNumber), + transactionIndex: this.hexToDecimal(rawLog.transactionIndex), }; return formattedLog; } - private toDecimal(hex: string|null): number|null { + private hexToDecimal(hex: string|null): number|null { if (_.isNull(hex)) { return null; } -- cgit v1.2.3 From 0747e162fa41a281d1fdce60cad494e265d09bb0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 13:18:29 -0600 Subject: Add instanceOf assertion --- packages/0x.js/test/token_wrapper_test.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages') diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index 07276877d..c32c528e6 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -363,6 +363,7 @@ describe('TokenWrapper', () => { expect(logEvent).to.not.be.undefined(); expect(logEvent.logIndex).to.be.equal(0); expect(logEvent.transactionIndex).to.be.equal(0); + expect(logEvent.blockNumber).to.be.instanceOf(Number); const args = logEvent.args; expect(args._from).to.be.equal(coinbase); expect(args._to).to.be.equal(addressWithoutFunds); -- cgit v1.2.3 From 41315827c145fec564152e2f0cb3e986cb06c696 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 13:27:42 -0600 Subject: Publish - 0x.js@0.26.0 - @0xproject/assert@0.0.5 - @0xproject/connect@0.0.1 - @0xproject/json-schemas@0.6.8 - @0xproject/tslint-config@0.1.1 --- packages/0x.js/package.json | 8 ++++---- packages/assert/package.json | 6 +++--- packages/connect/package.json | 10 +++++----- packages/json-schemas/package.json | 4 ++-- packages/tslint-config/package.json | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 7aa360954..b439a58ef 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,6 +1,6 @@ { "name": "0x.js", - "version": "0.25.1", + "version": "0.26.0", "description": "A javascript library for interacting with the 0x protocol", "keywords": [ "0x.js", @@ -44,7 +44,7 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.0", + "@0xproject/tslint-config": "^0.1.1", "@types/jsonschema": "^1.1.1", "@types/lodash": "^4.14.64", "@types/mocha": "^2.2.41", @@ -82,8 +82,8 @@ "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "^0.0.4", - "@0xproject/json-schemas": "^0.6.7", + "@0xproject/assert": "^0.0.5", + "@0xproject/json-schemas": "^0.6.8", "bignumber.js": "~4.1.0", "bn.js": "4.11.8", "compare-versions": "^3.0.1", diff --git a/packages/assert/package.json b/packages/assert/package.json index ed1d2a98b..d0f40c66e 100644 --- a/packages/assert/package.json +++ b/packages/assert/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/assert", - "version": "0.0.4", + "version": "0.0.5", "description": "Provides a standard way of performing type and schema validation across 0x projects", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/assert/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.1.0", + "@0xproject/tslint-config": "^0.1.1", "@types/lodash": "^4.14.78", "@types/mocha": "^2.2.42", "@types/valid-url": "^1.0.2", @@ -37,7 +37,7 @@ "typescript": "^2.4.2" }, "dependencies": { - "@0xproject/json-schemas": "^0.6.7", + "@0xproject/json-schemas": "^0.6.8", "bignumber.js": "~4.1.0", "ethereum-address": "^0.0.4", "lodash": "^4.17.4", diff --git a/packages/connect/package.json b/packages/connect/package.json index d26594b5d..ff6253fb6 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/connect", - "version": "0.0.0", + "version": "0.0.1", "description": "A javascript library for interacting with the standard relayer api", "keywords": [ "0x-connect", @@ -35,9 +35,9 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/connect/README.md", "dependencies": { - "@0xproject/assert": "0.0.4", - "@0xproject/json-schemas": "0.6.7", - "0x.js": "~0.25.1", + "0x.js": "^0.26.0", + "@0xproject/assert": "^0.0.5", + "@0xproject/json-schemas": "^0.6.8", "bignumber.js": "~4.1.0", "isomorphic-fetch": "^2.2.1", "lodash": "^4.17.4", @@ -45,7 +45,7 @@ "websocket": "^1.0.25" }, "devDependencies": { - "@0xproject/tslint-config": "0.1.0", + "@0xproject/tslint-config": "^0.1.1", "@types/fetch-mock": "^5.12.1", "@types/lodash": "^4.14.77", "@types/mocha": "^2.2.42", diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index 07ed20551..89c0d25f7 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/json-schemas", - "version": "0.6.7", + "version": "0.6.8", "description": "0x-related json schemas", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -28,7 +28,7 @@ "lodash.values": "^4.3.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.0", + "@0xproject/tslint-config": "^0.1.1", "@types/lodash.foreach": "^4.5.3", "@types/lodash.values": "^4.3.3", "@types/mocha": "^2.2.42", diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json index ca46d63fc..7ee3f1f71 100644 --- a/packages/tslint-config/package.json +++ b/packages/tslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/tslint-config", - "version": "0.1.0", + "version": "0.1.1", "description": "Lint rules related to 0xProject for TSLint", "main": "tslint.json", "files": [ -- cgit v1.2.3 From 06cd2f1eb3f1c9a2db578d624eb62ae30838b8c6 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 13:31:47 -0600 Subject: Revert "Publish" This reverts commit 41315827c145fec564152e2f0cb3e986cb06c696. --- packages/0x.js/package.json | 8 ++++---- packages/assert/package.json | 6 +++--- packages/connect/package.json | 10 +++++----- packages/json-schemas/package.json | 4 ++-- packages/tslint-config/package.json | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index b439a58ef..7aa360954 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,6 +1,6 @@ { "name": "0x.js", - "version": "0.26.0", + "version": "0.25.1", "description": "A javascript library for interacting with the 0x protocol", "keywords": [ "0x.js", @@ -44,7 +44,7 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.1", + "@0xproject/tslint-config": "^0.1.0", "@types/jsonschema": "^1.1.1", "@types/lodash": "^4.14.64", "@types/mocha": "^2.2.41", @@ -82,8 +82,8 @@ "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "^0.0.5", - "@0xproject/json-schemas": "^0.6.8", + "@0xproject/assert": "^0.0.4", + "@0xproject/json-schemas": "^0.6.7", "bignumber.js": "~4.1.0", "bn.js": "4.11.8", "compare-versions": "^3.0.1", diff --git a/packages/assert/package.json b/packages/assert/package.json index d0f40c66e..ed1d2a98b 100644 --- a/packages/assert/package.json +++ b/packages/assert/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/assert", - "version": "0.0.5", + "version": "0.0.4", "description": "Provides a standard way of performing type and schema validation across 0x projects", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/assert/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.1.1", + "@0xproject/tslint-config": "^0.1.0", "@types/lodash": "^4.14.78", "@types/mocha": "^2.2.42", "@types/valid-url": "^1.0.2", @@ -37,7 +37,7 @@ "typescript": "^2.4.2" }, "dependencies": { - "@0xproject/json-schemas": "^0.6.8", + "@0xproject/json-schemas": "^0.6.7", "bignumber.js": "~4.1.0", "ethereum-address": "^0.0.4", "lodash": "^4.17.4", diff --git a/packages/connect/package.json b/packages/connect/package.json index ff6253fb6..d26594b5d 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/connect", - "version": "0.0.1", + "version": "0.0.0", "description": "A javascript library for interacting with the standard relayer api", "keywords": [ "0x-connect", @@ -35,9 +35,9 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/connect/README.md", "dependencies": { - "0x.js": "^0.26.0", - "@0xproject/assert": "^0.0.5", - "@0xproject/json-schemas": "^0.6.8", + "@0xproject/assert": "0.0.4", + "@0xproject/json-schemas": "0.6.7", + "0x.js": "~0.25.1", "bignumber.js": "~4.1.0", "isomorphic-fetch": "^2.2.1", "lodash": "^4.17.4", @@ -45,7 +45,7 @@ "websocket": "^1.0.25" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.1", + "@0xproject/tslint-config": "0.1.0", "@types/fetch-mock": "^5.12.1", "@types/lodash": "^4.14.77", "@types/mocha": "^2.2.42", diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index 89c0d25f7..07ed20551 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/json-schemas", - "version": "0.6.8", + "version": "0.6.7", "description": "0x-related json schemas", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -28,7 +28,7 @@ "lodash.values": "^4.3.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.1", + "@0xproject/tslint-config": "^0.1.0", "@types/lodash.foreach": "^4.5.3", "@types/lodash.values": "^4.3.3", "@types/mocha": "^2.2.42", diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json index 7ee3f1f71..ca46d63fc 100644 --- a/packages/tslint-config/package.json +++ b/packages/tslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/tslint-config", - "version": "0.1.1", + "version": "0.1.0", "description": "Lint rules related to 0xProject for TSLint", "main": "tslint.json", "files": [ -- cgit v1.2.3 From 9a2735d03522a5099319409d75a49b75282d64ea Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 13:34:33 -0600 Subject: Publish - 0x.js@0.26.0 - @0xproject/assert@0.0.5 - @0xproject/connect@0.0.1 - @0xproject/json-schemas@0.6.8 - @0xproject/tslint-config@0.1.1 --- packages/0x.js/package.json | 8 ++++---- packages/assert/package.json | 6 +++--- packages/connect/package.json | 10 +++++----- packages/json-schemas/package.json | 4 ++-- packages/tslint-config/package.json | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 7aa360954..b439a58ef 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,6 +1,6 @@ { "name": "0x.js", - "version": "0.25.1", + "version": "0.26.0", "description": "A javascript library for interacting with the 0x protocol", "keywords": [ "0x.js", @@ -44,7 +44,7 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.0", + "@0xproject/tslint-config": "^0.1.1", "@types/jsonschema": "^1.1.1", "@types/lodash": "^4.14.64", "@types/mocha": "^2.2.41", @@ -82,8 +82,8 @@ "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "^0.0.4", - "@0xproject/json-schemas": "^0.6.7", + "@0xproject/assert": "^0.0.5", + "@0xproject/json-schemas": "^0.6.8", "bignumber.js": "~4.1.0", "bn.js": "4.11.8", "compare-versions": "^3.0.1", diff --git a/packages/assert/package.json b/packages/assert/package.json index ed1d2a98b..d0f40c66e 100644 --- a/packages/assert/package.json +++ b/packages/assert/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/assert", - "version": "0.0.4", + "version": "0.0.5", "description": "Provides a standard way of performing type and schema validation across 0x projects", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/assert/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.1.0", + "@0xproject/tslint-config": "^0.1.1", "@types/lodash": "^4.14.78", "@types/mocha": "^2.2.42", "@types/valid-url": "^1.0.2", @@ -37,7 +37,7 @@ "typescript": "^2.4.2" }, "dependencies": { - "@0xproject/json-schemas": "^0.6.7", + "@0xproject/json-schemas": "^0.6.8", "bignumber.js": "~4.1.0", "ethereum-address": "^0.0.4", "lodash": "^4.17.4", diff --git a/packages/connect/package.json b/packages/connect/package.json index d26594b5d..ff6253fb6 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/connect", - "version": "0.0.0", + "version": "0.0.1", "description": "A javascript library for interacting with the standard relayer api", "keywords": [ "0x-connect", @@ -35,9 +35,9 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/connect/README.md", "dependencies": { - "@0xproject/assert": "0.0.4", - "@0xproject/json-schemas": "0.6.7", - "0x.js": "~0.25.1", + "0x.js": "^0.26.0", + "@0xproject/assert": "^0.0.5", + "@0xproject/json-schemas": "^0.6.8", "bignumber.js": "~4.1.0", "isomorphic-fetch": "^2.2.1", "lodash": "^4.17.4", @@ -45,7 +45,7 @@ "websocket": "^1.0.25" }, "devDependencies": { - "@0xproject/tslint-config": "0.1.0", + "@0xproject/tslint-config": "^0.1.1", "@types/fetch-mock": "^5.12.1", "@types/lodash": "^4.14.77", "@types/mocha": "^2.2.42", diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index 07ed20551..89c0d25f7 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/json-schemas", - "version": "0.6.7", + "version": "0.6.8", "description": "0x-related json schemas", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -28,7 +28,7 @@ "lodash.values": "^4.3.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.1.0", + "@0xproject/tslint-config": "^0.1.1", "@types/lodash.foreach": "^4.5.3", "@types/lodash.values": "^4.3.3", "@types/mocha": "^2.2.42", diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json index ca46d63fc..7ee3f1f71 100644 --- a/packages/tslint-config/package.json +++ b/packages/tslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/tslint-config", - "version": "0.1.0", + "version": "0.1.1", "description": "Lint rules related to 0xProject for TSLint", "main": "tslint.json", "files": [ -- cgit v1.2.3 From 66750f7349435dbcdb783a214e21800466ec3ac1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 14:03:32 -0600 Subject: Fix tests --- packages/0x.js/test/token_wrapper_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index c32c528e6..1a7cb9e40 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -363,7 +363,7 @@ describe('TokenWrapper', () => { expect(logEvent).to.not.be.undefined(); expect(logEvent.logIndex).to.be.equal(0); expect(logEvent.transactionIndex).to.be.equal(0); - expect(logEvent.blockNumber).to.be.instanceOf(Number); + expect(logEvent.blockNumber).to.be.a('number'); const args = logEvent.args; expect(args._from).to.be.equal(coinbase); expect(args._to).to.be.equal(addressWithoutFunds); -- cgit v1.2.3 From 3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 11:44:34 -0600 Subject: Refactor while condition --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 5aa8b3d17..862714cc5 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -54,13 +54,19 @@ export class ExpirationWatcher { } private async pruneExpiredOrdersAsync(callbackAsync: (orderHash: string) => Promise): Promise { const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs(); - while ( - this.orderHashByExpirationRBTree.size !== 0 && - this.expiration[this.orderHashByExpirationRBTree.min()].lessThan( + while (true) { + const noOrdersLeft = this.orderHashByExpirationRBTree.size === 0; + if (noOrdersLeft) { + break; + } + const nextOrderHashToExpire = this.orderHashByExpirationRBTree.min(); + const noExpiredOrdersLeft = this.expiration[nextOrderHashToExpire].greaterThan( currentUnixTimestampMs.plus(this.expirationMarginMs), - ) && - !_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists) - ) { + ); + const noActiveSubscription = _.isUndefined(this.orderExpirationCheckingIntervalIdIfExists); + if (noExpiredOrdersLeft || noActiveSubscription) { + break; + } const orderHash = this.orderHashByExpirationRBTree.min(); this.orderHashByExpirationRBTree.remove(orderHash); delete this.expiration[orderHash]; -- cgit v1.2.3 From ac2c723ec9044589ad6495f4fd915db1f9eda3a7 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 11:56:34 -0600 Subject: Last renames --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 862714cc5..717edaad7 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -55,16 +55,16 @@ export class ExpirationWatcher { private async pruneExpiredOrdersAsync(callbackAsync: (orderHash: string) => Promise): Promise { const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs(); while (true) { - const noOrdersLeft = this.orderHashByExpirationRBTree.size === 0; - if (noOrdersLeft) { + const hasTrakedOrders = this.orderHashByExpirationRBTree.size === 0; + if (hasTrakedOrders) { break; } const nextOrderHashToExpire = this.orderHashByExpirationRBTree.min(); - const noExpiredOrdersLeft = this.expiration[nextOrderHashToExpire].greaterThan( + const hasNoExpiredOrders = this.expiration[nextOrderHashToExpire].greaterThan( currentUnixTimestampMs.plus(this.expirationMarginMs), ); - const noActiveSubscription = _.isUndefined(this.orderExpirationCheckingIntervalIdIfExists); - if (noExpiredOrdersLeft || noActiveSubscription) { + const isSubscriptionActive = _.isUndefined(this.orderExpirationCheckingIntervalIdIfExists); + if (hasNoExpiredOrders || isSubscriptionActive) { break; } const orderHash = this.orderHashByExpirationRBTree.min(); -- cgit v1.2.3 From a61a7b688a03590ba0d09d985db53311eb435bfd Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 21 Nov 2017 18:45:02 -0800 Subject: Prepare connect package for publishing --- packages/connect/package.json | 6 ++-- packages/connect/scripts/postpublish.js | 33 +++++++++++++++++++--- packages/connect/src/http_client.ts | 7 ++++- packages/connect/src/index.ts | 4 --- packages/connect/test/ws_orderbook_channel_test.ts | 2 +- 5 files changed, 40 insertions(+), 12 deletions(-) (limited to 'packages') diff --git a/packages/connect/package.json b/packages/connect/package.json index ff6253fb6..180a79eea 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "A javascript library for interacting with the standard relayer api", "keywords": [ - "0x-connect", + "connect", "0xproject", "ethereum", "tokens", @@ -14,9 +14,10 @@ "scripts": { "build": "tsc", "clean": "shx rm -rf _bundles lib test_temp", + "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR", + "upload_docs_json": "aws s3 cp docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type aplication/json", "copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures", "lint": "tslint src/**/*.ts test/**/*.ts", - "prepublishOnly": "run-p build", "run_mocha": "mocha lib/test/**/*_test.js", "test": "run-s clean build copy_test_fixtures run_mocha", "test:circleci": "yarn test" @@ -62,6 +63,7 @@ "npm-run-all": "^4.0.2", "shx": "^0.2.2", "tslint": "5.8.0", + "typedoc": "~0.8.0", "typescript": "~2.6.1", "web3-typescript-typings": "^0.7.1" } diff --git a/packages/connect/scripts/postpublish.js b/packages/connect/scripts/postpublish.js index 7fa452b08..ba0f8507d 100644 --- a/packages/connect/scripts/postpublish.js +++ b/packages/connect/scripts/postpublish.js @@ -1,14 +1,39 @@ +const execAsync = require('async-child-process').execAsync; const postpublish_utils = require('../../../scripts/postpublish_utils'); const packageJSON = require('../package.json'); +const cwd = __dirname + '/..'; const subPackageName = packageJSON.name; +const S3BucketPath = 's3://connect-docs-jsons/'; +let tag; +let version; postpublish_utils.getLatestTagAndVersionAsync(subPackageName) .then(function(result) { - const releaseName = postpublish_utils.getReleaseName(subPackageName, result.version); - const assets = []; - return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets); + tag = result.tag; + version = result.version; + const releaseName = postpublish_utils.getReleaseName(subPackageName, version); + return postpublish_utils.publishReleaseNotes(tag, releaseName); }) - .catch (function(err) { + .then(function(release) { + console.log('POSTPUBLISH: Release successful, generating docs...'); + return execAsync( + 'JSON_FILE_PATH=' + __dirname + '/../docs/index.json PROJECT_DIR=' + __dirname + '/.. yarn docs:json', + { + cwd, + } + ); + }) + .then(function(result) { + if (result.stderr !== '') { + throw new Error(result.stderr); + } + const fileName = 'v' + version + '.json'; + console.log('POSTPUBLISH: Doc generation successful, uploading docs... as ', fileName); + const s3Url = S3BucketPath + fileName; + return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json', { + cwd, + }); + }).catch (function(err) { throw err; }); diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index ab8c6bfa1..3dd0fb55e 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -18,6 +18,10 @@ import { import {schemas as clientSchemas} from './schemas/schemas'; import {typeConverters} from './utils/type_converters'; +BigNumber.config({ + EXPONENTIAL_AT: 1000, +}); + interface RequestOptions { params?: object; payload?: object; @@ -157,9 +161,10 @@ export class HttpClient implements Client { const headers = new Headers({ 'content-type': 'application/json', }); + const response = await fetch(url, { method: requestType, - body: payload, + body: JSON.stringify(payload), headers, }); if (!response.ok) { diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts index 5e97f4f26..c9ebde510 100644 --- a/packages/connect/src/index.ts +++ b/packages/connect/src/index.ts @@ -1,12 +1,8 @@ export {HttpClient} from './http_client'; -export {WebSocketOrderbookChannel} from './ws_orderbook_channel'; export { Client, FeesRequest, FeesResponse, - OrderbookChannel, - OrderbookChannelHandler, - OrderbookChannelSubscriptionOpts, OrderbookRequest, OrderbookResponse, OrdersRequest, diff --git a/packages/connect/test/ws_orderbook_channel_test.ts b/packages/connect/test/ws_orderbook_channel_test.ts index f3dead9ae..e92c6f44a 100644 --- a/packages/connect/test/ws_orderbook_channel_test.ts +++ b/packages/connect/test/ws_orderbook_channel_test.ts @@ -4,7 +4,7 @@ import * as dirtyChai from 'dirty-chai'; import * as chai from 'chai'; import { WebSocketOrderbookChannel, -} from '../src/index'; +} from '../src/ws_orderbook_channel'; chai.config.includeStack = true; chai.use(dirtyChai); -- cgit v1.2.3 From 27ce87f6529087bd511cae68bec5fb2dfa91649d Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 22 Nov 2017 13:26:15 -0800 Subject: Add TODO comment before BigNumber.config() call --- packages/connect/src/http_client.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 3dd0fb55e..85dc83c61 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -18,6 +18,7 @@ import { import {schemas as clientSchemas} from './schemas/schemas'; import {typeConverters} from './utils/type_converters'; +// TODO: move this and bigNumberConfigs in the 0x.js package into one place BigNumber.config({ EXPONENTIAL_AT: 1000, }); -- cgit v1.2.3 From b38142ddb18857d7d2cf36006a2ebcfd0b700cca Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 22 Nov 2017 13:54:07 -0800 Subject: Update connect CHANGELOG.md in preperation for publishing --- packages/connect/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/connect/CHANGELOG.md b/packages/connect/CHANGELOG.md index f3367f4ce..a6e30ed4a 100644 --- a/packages/connect/CHANGELOG.md +++ b/packages/connect/CHANGELOG.md @@ -1,4 +1,5 @@ # CHANGELOG -v0.0.0 - _Nov. 15, 2017_ +v0.0.2 - _November 22, 2017_ ------------------------ + * Provide a HttpClient class for interacting with standard relayer api compliant HTTP urls -- cgit v1.2.3 From c0e17f613666ebe8fdae394694fd065eb4e418f0 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 22 Nov 2017 14:20:45 -0800 Subject: Add blockchainLifecycle management to the ExpirationWatcher test --- packages/0x.js/test/expiration_watcher_test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index 0d5ebb909..0f2470070 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -12,11 +12,13 @@ import {TokenUtils} from './utils/token_utils'; import {ExpirationWatcher} from '../src/order_watcher/expiration_watcher'; import {Token, DoneCallback} from '../src/types'; import {ZeroEx} from '../src/0x'; +import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import {FillScenarios} from './utils/fill_scenarios'; import {reportCallbackErrors} from './utils/report_callback_errors'; chaiSetup.configure(); const expect = chai.expect; +const blockchainLifecycle = new BlockchainLifecycle(); describe('ExpirationWatcher', () => { let web3: Web3; @@ -52,14 +54,16 @@ describe('ExpirationWatcher', () => { makerTokenAddress = makerToken.address; takerTokenAddress = takerToken.address; }); - beforeEach(() => { + beforeEach(async () => { + await blockchainLifecycle.startAsync(); const sinonTimerConfig = {shouldAdvanceTime: true} as any; // This constructor has incorrect types timer = Sinon.useFakeTimers(sinonTimerConfig); currentUnixTimestampSec = utils.getCurrentUnixTimestampSec(); expirationWatcher = new ExpirationWatcher(); }); - afterEach(() => { + afterEach(async () => { + await blockchainLifecycle.revertAsync(); timer.restore(); expirationWatcher.unsubscribe(); }); -- cgit v1.2.3 From c3f24a9cea72b2554e28526f880a646cf7efa69b Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 22 Nov 2017 16:47:24 -0600 Subject: Add actual version to CHANGELOG --- packages/0x.js/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 26e5f528b..235a6eedb 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -vx.x.x +v0.26.0 ------------------------ * Add post-formatter for logs converting `blockNumber`, `logIndex`, `transactionIndex` from hexes to numbers (#231) * Remove support for Async callback types when used in Subscribe functions (#222) -- cgit v1.2.3 From 6a8717b29407b75cd03ca85b890fa8f34527accc Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 22 Nov 2017 16:50:16 -0600 Subject: Publish - 0x.js@0.26.1 - @0xproject/connect@0.1.0 --- packages/0x.js/package.json | 2 +- packages/connect/package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 26f9273db..afca00fe9 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,6 +1,6 @@ { "name": "0x.js", - "version": "0.26.0", + "version": "0.26.1", "description": "A javascript library for interacting with the 0x protocol", "keywords": [ "0x.js", diff --git a/packages/connect/package.json b/packages/connect/package.json index 180a79eea..9131eef14 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/connect", - "version": "0.0.1", + "version": "0.1.0", "description": "A javascript library for interacting with the standard relayer api", "keywords": [ "connect", @@ -36,7 +36,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/connect/README.md", "dependencies": { - "0x.js": "^0.26.0", + "0x.js": "^0.26.1", "@0xproject/assert": "^0.0.5", "@0xproject/json-schemas": "^0.6.8", "bignumber.js": "~4.1.0", -- cgit v1.2.3 From 99f2026ce260915ec9eaf013723f1d618965f008 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 22 Nov 2017 16:51:09 -0600 Subject: Revert "Publish" This reverts commit 6a8717b29407b75cd03ca85b890fa8f34527accc. --- packages/0x.js/package.json | 2 +- packages/connect/package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index afca00fe9..26f9273db 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,6 +1,6 @@ { "name": "0x.js", - "version": "0.26.1", + "version": "0.26.0", "description": "A javascript library for interacting with the 0x protocol", "keywords": [ "0x.js", diff --git a/packages/connect/package.json b/packages/connect/package.json index 9131eef14..180a79eea 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/connect", - "version": "0.1.0", + "version": "0.0.1", "description": "A javascript library for interacting with the standard relayer api", "keywords": [ "connect", @@ -36,7 +36,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/connect/README.md", "dependencies": { - "0x.js": "^0.26.1", + "0x.js": "^0.26.0", "@0xproject/assert": "^0.0.5", "@0xproject/json-schemas": "^0.6.8", "bignumber.js": "~4.1.0", -- cgit v1.2.3 From cd42ca1bbdb77a25fae0c5f0c290050022c5d113 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 22 Nov 2017 15:07:34 -0800 Subject: Publish - 0x.js@0.26.1 - @0xproject/connect@0.1.0 --- packages/0x.js/package.json | 2 +- packages/connect/package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 26f9273db..afca00fe9 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,6 +1,6 @@ { "name": "0x.js", - "version": "0.26.0", + "version": "0.26.1", "description": "A javascript library for interacting with the 0x protocol", "keywords": [ "0x.js", diff --git a/packages/connect/package.json b/packages/connect/package.json index 180a79eea..9131eef14 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/connect", - "version": "0.0.1", + "version": "0.1.0", "description": "A javascript library for interacting with the standard relayer api", "keywords": [ "connect", @@ -36,7 +36,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/connect/README.md", "dependencies": { - "0x.js": "^0.26.0", + "0x.js": "^0.26.1", "@0xproject/assert": "^0.0.5", "@0xproject/json-schemas": "^0.6.8", "bignumber.js": "~4.1.0", -- cgit v1.2.3 From 02aefc40f32e9e2d396b3b7574fdcb7ccb874dca Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 22 Nov 2017 15:10:50 -0800 Subject: Fix connect CHANGELOG version --- packages/connect/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/connect/CHANGELOG.md b/packages/connect/CHANGELOG.md index a6e30ed4a..ec6727a12 100644 --- a/packages/connect/CHANGELOG.md +++ b/packages/connect/CHANGELOG.md @@ -1,5 +1,5 @@ # CHANGELOG -v0.0.2 - _November 22, 2017_ +v0.1.0 - _November 22, 2017_ ------------------------ * Provide a HttpClient class for interacting with standard relayer api compliant HTTP urls -- cgit v1.2.3