diff options
author | Fabio Berger <me@fabioberger.com> | 2018-07-19 22:38:33 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-07-19 22:38:33 +0800 |
commit | b6de0bdd43d53204fbbe9a13d44658963a7f2725 (patch) | |
tree | 45a7084ff4de40deab8b79fc689e4718e365e7b2 /packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts | |
parent | a2b62fd8085df2121424fd8a9defee42879971ce (diff) | |
parent | 886a03fdcd4893a57f88fa407de94852cb0a2285 (diff) | |
download | dexon-sol-tools-b6de0bdd43d53204fbbe9a13d44658963a7f2725.tar dexon-sol-tools-b6de0bdd43d53204fbbe9a13d44658963a7f2725.tar.gz dexon-sol-tools-b6de0bdd43d53204fbbe9a13d44658963a7f2725.tar.bz2 dexon-sol-tools-b6de0bdd43d53204fbbe9a13d44658963a7f2725.tar.lz dexon-sol-tools-b6de0bdd43d53204fbbe9a13d44658963a7f2725.tar.xz dexon-sol-tools-b6de0bdd43d53204fbbe9a13d44658963a7f2725.tar.zst dexon-sol-tools-b6de0bdd43d53204fbbe9a13d44658963a7f2725.zip |
Merge branch 'v2-prototype' into update-lerna
* v2-prototype: (48 commits)
Update CHANGELOG
Rename call data schema id to CallData. Check for TypedArray when hashing data in order-utils crypto
Fix broken links in sol-cov documentation
Fix 0x.js ts warnings
Update yarn.lock
Fix 0x.js ts warnings
Fix 0x.js tests on CI
Fix a bad merge
Update package versions
Merge
Update changelogs
Add a test for ERC721 Allowance
Use allowance instead of approval for all in fill-scenarios
Upgrade sha3 to 1.2.2 to work with node v10
Check if the token doesn't exist before minting in fill scenarios
Make downlevelIteration a global config
Fix tests descriptions
DRY up the code in order-watcher collision-resistant abi decoder
Await transactions in fillScenarios
Rename decodeAssetData to decodeAssetDataOrThrow
...
Diffstat (limited to 'packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts')
-rw-r--r-- | packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts b/packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts new file mode 100644 index 000000000..336c6d0ba --- /dev/null +++ b/packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts @@ -0,0 +1,65 @@ +import { BigNumber } from '@0xproject/utils'; +import * as _ from 'lodash'; + +import { AbstractOrderFilledCancelledFetcher } from '../abstract/abstract_order_filled_cancelled_fetcher'; +import { AbstractOrderFilledCancelledLazyStore } from '../abstract/abstract_order_filled_cancelled_lazy_store'; + +/** + * Copy on read store for balances/proxyAllowances of tokens/accounts + */ +export class OrderFilledCancelledLazyStore implements AbstractOrderFilledCancelledLazyStore { + private readonly _orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher; + private _filledTakerAmount: { + [orderHash: string]: BigNumber; + }; + private _isCancelled: { + [orderHash: string]: boolean; + }; + constructor(orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher) { + this._orderFilledCancelledFetcher = orderFilledCancelledFetcher; + this._filledTakerAmount = {}; + this._isCancelled = {}; + } + public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> { + if (_.isUndefined(this._filledTakerAmount[orderHash])) { + const filledTakerAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash); + this.setFilledTakerAmount(orderHash, filledTakerAmount); + } + const cachedFilledTakerAmount = this._filledTakerAmount[orderHash]; + return cachedFilledTakerAmount; + } + public setFilledTakerAmount(orderHash: string, filledTakerAmount: BigNumber): void { + this._filledTakerAmount[orderHash] = filledTakerAmount; + } + public deleteFilledTakerAmount(orderHash: string): void { + delete this._filledTakerAmount[orderHash]; + } + public async getIsCancelledAsync(orderHash: string): Promise<boolean> { + if (_.isUndefined(this._isCancelled[orderHash])) { + const isCancelled = await this._orderFilledCancelledFetcher.isOrderCancelledAsync(orderHash); + this.setIsCancelled(orderHash, isCancelled); + } + const cachedIsCancelled = this._isCancelled[orderHash]; // tslint:disable-line:boolean-naming + return cachedIsCancelled; + } + public setIsCancelled(orderHash: string, isCancelled: boolean): void { + this._isCancelled[orderHash] = isCancelled; + } + public deleteIsCancelled(orderHash: string): void { + delete this._isCancelled[orderHash]; + } + public deleteAll(): void { + this.deleteAllFilled(); + this.deleteAllIsCancelled(); + } + public deleteAllIsCancelled(): void { + this._isCancelled = {}; + } + public deleteAllFilled(): void { + this._filledTakerAmount = {}; + } + public getZRXAssetData(): string { + const zrxAssetData = this._orderFilledCancelledFetcher.getZRXAssetData(); + return zrxAssetData; + } +} |