diff options
author | Fabio Berger <me@fabioberger.com> | 2018-09-25 23:10:13 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-09-25 23:10:13 +0800 |
commit | 9eecf3683b674f0753e508476c4c21eb32625f18 (patch) | |
tree | 7098726b4a8189a29d01295d1f23a0df35ebafdb /packages/order-utils | |
parent | 7570f3db513f1b728e27cdd6273642ab999adbcc (diff) | |
download | dexon-sol-tools-9eecf3683b674f0753e508476c4c21eb32625f18.tar dexon-sol-tools-9eecf3683b674f0753e508476c4c21eb32625f18.tar.gz dexon-sol-tools-9eecf3683b674f0753e508476c4c21eb32625f18.tar.bz2 dexon-sol-tools-9eecf3683b674f0753e508476c4c21eb32625f18.tar.lz dexon-sol-tools-9eecf3683b674f0753e508476c4c21eb32625f18.tar.xz dexon-sol-tools-9eecf3683b674f0753e508476c4c21eb32625f18.tar.zst dexon-sol-tools-9eecf3683b674f0753e508476c4c21eb32625f18.zip |
Add transactionHash to OrderState and emit it from OrderWatcher subscription
Diffstat (limited to 'packages/order-utils')
-rw-r--r-- | packages/order-utils/src/order_state_utils.ts | 4 | ||||
-rw-r--r-- | packages/order-utils/test/order_state_utils_test.ts | 20 |
2 files changed, 23 insertions, 1 deletions
diff --git a/packages/order-utils/src/order_state_utils.ts b/packages/order-utils/src/order_state_utils.ts index 8398776aa..9b21ef6e9 100644 --- a/packages/order-utils/src/order_state_utils.ts +++ b/packages/order-utils/src/order_state_utils.ts @@ -114,7 +114,7 @@ export class OrderStateUtils { * @return State relevant to the signedOrder, as well as whether the signedOrder is "valid". * Validity is defined as a non-zero amount of the order can still be filled. */ - public async getOpenOrderStateAsync(signedOrder: SignedOrder): Promise<OrderState> { + public async getOpenOrderStateAsync(signedOrder: SignedOrder, transactionHash?: string): Promise<OrderState> { const orderRelevantState = await this.getOpenOrderRelevantStateAsync(signedOrder); const orderHash = orderHashUtils.getOrderHashHex(signedOrder); const isOrderCancelled = await this._orderFilledCancelledFetcher.isOrderCancelledAsync(orderHash); @@ -134,6 +134,7 @@ export class OrderStateUtils { isValid: true, orderHash, orderRelevantState, + transactionHash, }; return orderState; } else { @@ -141,6 +142,7 @@ export class OrderStateUtils { isValid: false, orderHash, error: orderValidationResult.error, + transactionHash, }; return orderState; } diff --git a/packages/order-utils/test/order_state_utils_test.ts b/packages/order-utils/test/order_state_utils_test.ts index 91ef23b69..ea88027ae 100644 --- a/packages/order-utils/test/order_state_utils_test.ts +++ b/packages/order-utils/test/order_state_utils_test.ts @@ -120,5 +120,25 @@ describe('OrderStateUtils', () => { const orderState = await orderStateUtils.getOpenOrderStateAsync(signedOrder); expect(orderState.isValid).to.eq(false); }); + it('should include the transactionHash in orderState if supplied in method invocation', async () => { + const makerAssetAmount = new BigNumber(10); + const takerAssetAmount = new BigNumber(10000000000000000); + const takerBalance = takerAssetAmount; + const orderFilledAmount = new BigNumber(0); + const mockBalanceFetcher = buildMockBalanceFetcher(takerBalance); + const mockOrderFilledFetcher = buildMockOrderFilledFetcher(orderFilledAmount); + const [signedOrder] = testOrderFactory.generateTestSignedOrders( + { + makerAssetAmount, + takerAssetAmount, + }, + 1, + ); + + const orderStateUtils = new OrderStateUtils(mockBalanceFetcher, mockOrderFilledFetcher); + const transactionHash = '0xdeadbeef'; + const orderState = await orderStateUtils.getOpenOrderStateAsync(signedOrder, transactionHash); + expect(orderState.transactionHash).to.eq(transactionHash); + }); }); }); |