aboutsummaryrefslogtreecommitdiffstats
path: root/src/order_watcher
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-11-13 01:53:03 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-13 09:06:13 +0800
commitf5608d2c94bcee05a76ef102f235f5e860820567 (patch)
tree5749dd899f803e4f2357d60cf038a607b1852759 /src/order_watcher
parentbcad937003fa925878d34e5fa83e5a89369d0957 (diff)
downloaddexon-sol-tools-f5608d2c94bcee05a76ef102f235f5e860820567.tar
dexon-sol-tools-f5608d2c94bcee05a76ef102f235f5e860820567.tar.gz
dexon-sol-tools-f5608d2c94bcee05a76ef102f235f5e860820567.tar.bz2
dexon-sol-tools-f5608d2c94bcee05a76ef102f235f5e860820567.tar.lz
dexon-sol-tools-f5608d2c94bcee05a76ef102f235f5e860820567.tar.xz
dexon-sol-tools-f5608d2c94bcee05a76ef102f235f5e860820567.tar.zst
dexon-sol-tools-f5608d2c94bcee05a76ef102f235f5e860820567.zip
Pass blockStore to eventWatcher
Diffstat (limited to 'src/order_watcher')
-rw-r--r--src/order_watcher/event_watcher.ts18
-rw-r--r--src/order_watcher/order_state_watcher.ts13
2 files changed, 16 insertions, 15 deletions
diff --git a/src/order_watcher/event_watcher.ts b/src/order_watcher/event_watcher.ts
index c9e72281c..5303bb651 100644
--- a/src/order_watcher/event_watcher.ts
+++ b/src/order_watcher/event_watcher.ts
@@ -11,6 +11,7 @@ import {AbiDecoder} from '../utils/abi_decoder';
import {intervalUtils} from '../utils/interval_utils';
import {assert} from '../utils/assert';
import {utils} from '../utils/utils';
+import {BlockStore} from '../stores/block_store';
const DEFAULT_EVENT_POLLING_INTERVAL = 200;
@@ -29,8 +30,11 @@ export class EventWatcher {
private _intervalIdIfExists?: NodeJS.Timer;
private _lastEvents: Web3.LogEntry[] = [];
private _numConfirmations: number;
- constructor(web3Wrapper: Web3Wrapper, pollingIntervalMs: undefined|number, numConfirmations: number) {
+ private _blockStore: BlockStore;
+ constructor(web3Wrapper: Web3Wrapper, blockStore: BlockStore, pollingIntervalMs: undefined|number,
+ numConfirmations: number) {
this._web3Wrapper = web3Wrapper;
+ this._blockStore = blockStore;
this._numConfirmations = numConfirmations;
this._pollingIntervalMs = _.isUndefined(pollingIntervalMs) ?
DEFAULT_EVENT_POLLING_INTERVAL :
@@ -67,16 +71,10 @@ export class EventWatcher {
this._lastEvents = pendingEvents;
}
private async _getEventsAsync(): Promise<Web3.LogEntry[]> {
- let latestBlock: BlockParamLiteral|number;
- if (this._numConfirmations === 0) {
- latestBlock = BlockParamLiteral.Pending;
- } else {
- const currentBlock = await this._web3Wrapper.getBlockNumberAsync();
- latestBlock = currentBlock - this._numConfirmations;
- }
+ const blockNumber = this._blockStore.getBlockNumberWithNConfirmations(this._numConfirmations);
const eventFilter = {
- fromBlock: latestBlock,
- toBlock: latestBlock,
+ fromBlock: blockNumber,
+ toBlock: blockNumber,
};
const events = await this._web3Wrapper.getLogsAsync(eventFilter);
return events;
diff --git a/src/order_watcher/order_state_watcher.ts b/src/order_watcher/order_state_watcher.ts
index 59de1cc2f..685d67455 100644
--- a/src/order_watcher/order_state_watcher.ts
+++ b/src/order_watcher/order_state_watcher.ts
@@ -61,7 +61,6 @@ export class OrderStateWatcher {
private _abiDecoder: AbiDecoder;
private _orderStateUtils: OrderStateUtils;
private _blockStore: BlockStore;
- private _numConfirmations: number;
private _orderFilledCancelledLazyStore: OrderFilledCancelledLazyStore;
private _balanceAndProxyAllowanceLazyStore: BalanceAndProxyAllowanceLazyStore;
constructor(
@@ -76,15 +75,18 @@ export class OrderStateWatcher {
this._dependentOrderHashes = {};
const eventPollingIntervalMs = _.isUndefined(config) ? undefined : config.eventPollingIntervalMs;
const blockPollingIntervalMs = _.isUndefined(config) ? undefined : config.blockPollingIntervalMs;
+ const numConfirmations = (_.isUndefined(config) || _.isUndefined(config.numConfirmations)) ?
+ DEFAULT_NUM_CONFIRMATIONS :
+ config.numConfirmations;
+ this._blockStore = new BlockStore(this._web3Wrapper, blockPollingIntervalMs);
this._eventWatcher = new EventWatcher(
- web3Wrapper, eventPollingIntervalMs, this._numConfirmations,
+ web3Wrapper, this._blockStore, eventPollingIntervalMs, numConfirmations,
);
- this._blockStore = new BlockStore(this._web3Wrapper, blockPollingIntervalMs);
this._balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
- this._token, this._blockStore, this._numConfirmations,
+ this._token, this._blockStore, numConfirmations,
);
this._orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(
- this._exchange, this._blockStore, this._numConfirmations,
+ this._exchange, this._blockStore, numConfirmations,
);
this._orderStateUtils = new OrderStateUtils(
this._balanceAndProxyAllowanceLazyStore, this._orderFilledCancelledLazyStore,
@@ -159,6 +161,7 @@ export class OrderStateWatcher {
// Invalidate cache
const args = decodedLog.args as ApprovalContractEventArgs;
this._balanceAndProxyAllowanceLazyStore.deleteProxyAllowance(decodedLog.address, args._owner);
+ // Revalidate orders
makerToken = decodedLog.address;
makerAddress = args._owner;
orderHashesSet = _.get(this._dependentOrderHashes, [makerAddress, makerToken]);