diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-13 02:06:25 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-13 09:06:13 +0800 |
commit | a9ae555b88cc36ff2cbd92fdd37a339702860c01 (patch) | |
tree | d42ed590c81683a3f6acd0882d31392a9a97f1ca /src/stores | |
parent | d4dc428124a210cc6b8e1c50527a08e902bfadd0 (diff) | |
download | dexon-sol-tools-a9ae555b88cc36ff2cbd92fdd37a339702860c01.tar dexon-sol-tools-a9ae555b88cc36ff2cbd92fdd37a339702860c01.tar.gz dexon-sol-tools-a9ae555b88cc36ff2cbd92fdd37a339702860c01.tar.bz2 dexon-sol-tools-a9ae555b88cc36ff2cbd92fdd37a339702860c01.tar.lz dexon-sol-tools-a9ae555b88cc36ff2cbd92fdd37a339702860c01.tar.xz dexon-sol-tools-a9ae555b88cc36ff2cbd92fdd37a339702860c01.tar.zst dexon-sol-tools-a9ae555b88cc36ff2cbd92fdd37a339702860c01.zip |
Store number of confirmations in a blockStore
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/balance_proxy_allowance_lazy_store.ts | 8 | ||||
-rw-r--r-- | src/stores/block_store.ts | 15 | ||||
-rw-r--r-- | src/stores/order_filled_cancelled_lazy_store.ts | 8 |
3 files changed, 16 insertions, 15 deletions
diff --git a/src/stores/balance_proxy_allowance_lazy_store.ts b/src/stores/balance_proxy_allowance_lazy_store.ts index ac21c0818..88152e145 100644 --- a/src/stores/balance_proxy_allowance_lazy_store.ts +++ b/src/stores/balance_proxy_allowance_lazy_store.ts @@ -9,7 +9,6 @@ import {BlockStore} from './block_store'; */ export class BalanceAndProxyAllowanceLazyStore { private token: TokenWrapper; - private numConfirmations: number; private blockStore: BlockStore; private balance: { [tokenAddress: string]: { @@ -21,16 +20,15 @@ export class BalanceAndProxyAllowanceLazyStore { [userAddress: string]: BigNumber, }, }; - constructor(token: TokenWrapper, blockStore: BlockStore, numConfirmations: number) { + constructor(token: TokenWrapper, blockStore: BlockStore) { this.token = token; - this.numConfirmations = numConfirmations; this.blockStore = blockStore; this.balance = {}; this.proxyAllowance = {}; } public async getBalanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> { if (_.isUndefined(this.balance[tokenAddress]) || _.isUndefined(this.balance[tokenAddress][userAddress])) { - const defaultBlock = this.blockStore.getBlockNumberWithNConfirmations(this.numConfirmations); + const defaultBlock = this.blockStore.getBlockNumber(); const methodOpts = { defaultBlock, }; @@ -54,7 +52,7 @@ export class BalanceAndProxyAllowanceLazyStore { public async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> { if (_.isUndefined(this.proxyAllowance[tokenAddress]) || _.isUndefined(this.proxyAllowance[tokenAddress][userAddress])) { - const defaultBlock = this.blockStore.getBlockNumberWithNConfirmations(this.numConfirmations); + const defaultBlock = this.blockStore.getBlockNumber(); const methodOpts = { defaultBlock, }; diff --git a/src/stores/block_store.ts b/src/stores/block_store.ts index d1f6c329a..ae9c232bb 100644 --- a/src/stores/block_store.ts +++ b/src/stores/block_store.ts @@ -15,15 +15,17 @@ export class BlockStore { private latestBlockNumber?: number; private intervalId?: NodeJS.Timer; private blockPollingIntervalMs: number; - constructor(web3Wrapper?: Web3Wrapper, blockPollingIntervalMs?: number) { + private numConfirmations: number; + constructor(numConfirmations: number, web3Wrapper?: Web3Wrapper, blockPollingIntervalMs?: number) { + this.numConfirmations = numConfirmations; this.web3Wrapper = web3Wrapper; this.blockPollingIntervalMs = blockPollingIntervalMs || DEFAULT_BLOCK_POLLING_INTERVAL_MS; } - public getBlockNumberWithNConfirmations(numConfirmations: number): Web3.BlockParam { + public getBlockNumber(): Web3.BlockParam { let blockNumber; - if (numConfirmations === 0) { + if (this.numConfirmations === 0) { blockNumber = BlockParamLiteral.Pending; - } else if (numConfirmations === 1) { + } else if (this.numConfirmations === 1) { // HACK: We special-case `numConfirmations === 1` so that we can use this block store without actually // setting `latestBlockNumber` when block number is latest (in order validation) whhich allows us to omit // an async call in a constructor of `ExchangeTransferSimulator` @@ -33,11 +35,14 @@ export class BlockStore { throw new Error(InternalZeroExError.LatestBlockNumberNotSet); } // Latest block already has 1 confirmation - blockNumber = this.latestBlockNumber - numConfirmations + 1; + blockNumber = this.latestBlockNumber - this.numConfirmations + 1; } return blockNumber; } public async startAsync(): Promise<void> { + if (this.numConfirmations === 0 || this.numConfirmations === 1) { + return; // no-op + } await this.updateLatestBlockAsync(); this.intervalId = intervalUtils.setAsyncExcludingInterval( this.updateLatestBlockAsync.bind(this), this.blockPollingIntervalMs, diff --git a/src/stores/order_filled_cancelled_lazy_store.ts b/src/stores/order_filled_cancelled_lazy_store.ts index 5b0dab35c..104a8240e 100644 --- a/src/stores/order_filled_cancelled_lazy_store.ts +++ b/src/stores/order_filled_cancelled_lazy_store.ts @@ -9,7 +9,6 @@ import {BlockStore} from './block_store'; */ export class OrderFilledCancelledLazyStore { private exchange: ExchangeWrapper; - private numConfirmations: number; private blockStore: BlockStore; private filledTakerAmount: { [orderHash: string]: BigNumber, @@ -17,16 +16,15 @@ export class OrderFilledCancelledLazyStore { private cancelledTakerAmount: { [orderHash: string]: BigNumber, }; - constructor(exchange: ExchangeWrapper, blockStore: BlockStore, numConfirmations: number) { + constructor(exchange: ExchangeWrapper, blockStore: BlockStore) { this.exchange = exchange; - this.numConfirmations = numConfirmations; this.blockStore = blockStore; this.filledTakerAmount = {}; this.cancelledTakerAmount = {}; } public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> { if (_.isUndefined(this.filledTakerAmount[orderHash])) { - const defaultBlock = this.blockStore.getBlockNumberWithNConfirmations(this.numConfirmations); + const defaultBlock = this.blockStore.getBlockNumber(); const methodOpts = { defaultBlock, }; @@ -44,7 +42,7 @@ export class OrderFilledCancelledLazyStore { } public async getCancelledTakerAmountAsync(orderHash: string): Promise<BigNumber> { if (_.isUndefined(this.cancelledTakerAmount[orderHash])) { - const defaultBlock = this.blockStore.getBlockNumberWithNConfirmations(this.numConfirmations); + const defaultBlock = this.blockStore.getBlockNumber(); const methodOpts = { defaultBlock, }; |