diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-11 01:12:47 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-13 09:03:18 +0800 |
commit | dcda8fe538a6db82bed4f036ef63bad5882e681a (patch) | |
tree | 3422b28bd6ec418ddb86f553b9e18f546570fcd2 | |
parent | 6edae865168dc86a5a3b39558158d22a4ff3bd99 (diff) | |
download | dexon-sol-tools-dcda8fe538a6db82bed4f036ef63bad5882e681a.tar dexon-sol-tools-dcda8fe538a6db82bed4f036ef63bad5882e681a.tar.gz dexon-sol-tools-dcda8fe538a6db82bed4f036ef63bad5882e681a.tar.bz2 dexon-sol-tools-dcda8fe538a6db82bed4f036ef63bad5882e681a.tar.lz dexon-sol-tools-dcda8fe538a6db82bed4f036ef63bad5882e681a.tar.xz dexon-sol-tools-dcda8fe538a6db82bed4f036ef63bad5882e681a.tar.zst dexon-sol-tools-dcda8fe538a6db82bed4f036ef63bad5882e681a.zip |
Add store for order filled/cancelled state
-rw-r--r-- | src/stores/order_filled_cancelled_lazy_store.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/stores/order_filled_cancelled_lazy_store.ts b/src/stores/order_filled_cancelled_lazy_store.ts new file mode 100644 index 000000000..beb8fe6d7 --- /dev/null +++ b/src/stores/order_filled_cancelled_lazy_store.ts @@ -0,0 +1,52 @@ +import * as _ from 'lodash'; +import * as Web3 from 'web3'; +import {BigNumber} from 'bignumber.js'; +import {ExchangeWrapper} from '../contract_wrappers/exchange_wrapper'; + +/** + * Copy on read store for filled/cancelled taker amounts + */ +export class OrderFilledCancelledLazyStore { + private exchange: ExchangeWrapper; + private defaultBlock: Web3.BlockParam; + private filledTakerAmount: { + [orderHash: string]: BigNumber, + }; + private cancelledTakerAmount: { + [orderHash: string]: BigNumber, + }; + constructor(exchange: ExchangeWrapper, defaultBlock: Web3.BlockParam) { + this.exchange = exchange; + this.defaultBlock = defaultBlock; + this.filledTakerAmount = {}; + this.cancelledTakerAmount = {}; + } + public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> { + if (_.isUndefined(this.filledTakerAmount[orderHash])) { + const methodOpts = { + defaultBlock: this.defaultBlock, + }; + const filledTakerAmount = await this.exchange.getFilledTakerAmountAsync(orderHash, methodOpts); + this.setFilledTakerAmount(orderHash, filledTakerAmount); + } + const cachedFilled = this.filledTakerAmount[orderHash]; + return cachedFilled; + } + public setFilledTakerAmount(orderHash: string, filledTakerAmount: BigNumber): void { + this.filledTakerAmount[orderHash] = filledTakerAmount; + } + public async getCancelledTakerAmountAsync(orderHash: string): Promise<BigNumber> { + if (_.isUndefined(this.cancelledTakerAmount[orderHash])) { + const methodOpts = { + defaultBlock: this.defaultBlock, + }; + const cancelledTakerAmount = await this.exchange.getCanceledTakerAmountAsync(orderHash, methodOpts); + this.setCancelledTakerAmount(orderHash, cancelledTakerAmount); + } + const cachedCancelled = this.cancelledTakerAmount[orderHash]; + return cachedCancelled; + } + public setCancelledTakerAmount(orderHash: string, cancelledTakerAmount: BigNumber): void { + this.cancelledTakerAmount[orderHash] = cancelledTakerAmount; + } +} |