From 70436fa535f51eca5c1b5951e1218e72f9a767e0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 10 Nov 2017 15:03:53 -0500 Subject: Make stores accept numConfirmations and blockStore instead of defaultBlock --- src/stores/order_filled_cancelled_lazy_store.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/stores/order_filled_cancelled_lazy_store.ts') diff --git a/src/stores/order_filled_cancelled_lazy_store.ts b/src/stores/order_filled_cancelled_lazy_store.ts index cb4c786f3..978de0b18 100644 --- a/src/stores/order_filled_cancelled_lazy_store.ts +++ b/src/stores/order_filled_cancelled_lazy_store.ts @@ -2,29 +2,33 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import {BigNumber} from 'bignumber.js'; import {ExchangeWrapper} from '../contract_wrappers/exchange_wrapper'; +import {BlockStore} from './block_store'; /** * Copy on read store for filled/cancelled taker amounts */ export class OrderFilledCancelledLazyStore { private exchange: ExchangeWrapper; - private defaultBlock: Web3.BlockParam; + private numConfirmations: number; + private blockStore: BlockStore; private filledTakerAmount: { [orderHash: string]: BigNumber, }; private cancelledTakerAmount: { [orderHash: string]: BigNumber, }; - constructor(exchange: ExchangeWrapper, defaultBlock: Web3.BlockParam) { + constructor(exchange: ExchangeWrapper, blockStore: BlockStore, numConfirmations: number) { this.exchange = exchange; - this.defaultBlock = defaultBlock; + this.numConfirmations = numConfirmations; + this.blockStore = blockStore; this.filledTakerAmount = {}; this.cancelledTakerAmount = {}; } public async getFilledTakerAmountAsync(orderHash: string): Promise { if (_.isUndefined(this.filledTakerAmount[orderHash])) { + const defaultBlock = this.blockStore.getBlockNumberWithNConfirmations(this.numConfirmations); const methodOpts = { - defaultBlock: this.defaultBlock, + defaultBlock, }; const filledTakerAmount = await this.exchange.getFilledTakerAmountAsync(orderHash, methodOpts); this.setFilledTakerAmount(orderHash, filledTakerAmount); @@ -40,8 +44,9 @@ export class OrderFilledCancelledLazyStore { } public async getCancelledTakerAmountAsync(orderHash: string): Promise { if (_.isUndefined(this.cancelledTakerAmount[orderHash])) { + const defaultBlock = this.blockStore.getBlockNumberWithNConfirmations(this.numConfirmations); const methodOpts = { - defaultBlock: this.defaultBlock, + defaultBlock, }; const cancelledTakerAmount = await this.exchange.getCanceledTakerAmountAsync(orderHash, methodOpts); this.setCancelledTakerAmount(orderHash, cancelledTakerAmount); -- cgit v1.2.3