aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-11-11 04:03:53 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-13 09:03:18 +0800
commit70436fa535f51eca5c1b5951e1218e72f9a767e0 (patch)
tree00b092d7fc5b62d72efcf0ab5b89f180ae5c099b /src
parent4921f61e76d2e6f1b2c8718766a7e93e11ad4671 (diff)
downloaddexon-0x-contracts-70436fa535f51eca5c1b5951e1218e72f9a767e0.tar.gz
dexon-0x-contracts-70436fa535f51eca5c1b5951e1218e72f9a767e0.tar.zst
dexon-0x-contracts-70436fa535f51eca5c1b5951e1218e72f9a767e0.zip
Make stores accept numConfirmations and blockStore instead of defaultBlock
Diffstat (limited to 'src')
-rw-r--r--src/stores/balance_proxy_allowance_lazy_store.ts15
-rw-r--r--src/stores/order_filled_cancelled_lazy_store.ts15
2 files changed, 20 insertions, 10 deletions
diff --git a/src/stores/balance_proxy_allowance_lazy_store.ts b/src/stores/balance_proxy_allowance_lazy_store.ts
index 92a6aaa51..a2b8fcf67 100644
--- a/src/stores/balance_proxy_allowance_lazy_store.ts
+++ b/src/stores/balance_proxy_allowance_lazy_store.ts
@@ -2,13 +2,15 @@ import * as _ from 'lodash';
import * as Web3 from 'web3';
import {BigNumber} from 'bignumber.js';
import {TokenWrapper} from '../contract_wrappers/token_wrapper';
+import {BlockStore} from './block_store';
/**
* Copy on read store for balances/proxyAllowances of tokens/accounts
*/
export class BalanceAndProxyAllowanceLazyStore {
private token: TokenWrapper;
- private defaultBlock: Web3.BlockParam;
+ private numConfirmations: number;
+ private blockStore: BlockStore;
private balance: {
[tokenAddress: string]: {
[userAddress: string]: BigNumber,
@@ -19,16 +21,18 @@ export class BalanceAndProxyAllowanceLazyStore {
[userAddress: string]: BigNumber,
},
};
- constructor(token: TokenWrapper, defaultBlock: Web3.BlockParam) {
+ constructor(token: TokenWrapper, blockStore: BlockStore, numConfirmations: number) {
this.token = token;
- this.defaultBlock = defaultBlock;
+ 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 methodOpts = {
- defaultBlock: this.defaultBlock,
+ defaultBlock,
};
const balance = await this.token.getBalanceAsync(tokenAddress, userAddress, methodOpts);
this.setBalance(tokenAddress, userAddress, balance);
@@ -50,8 +54,9 @@ 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 methodOpts = {
- defaultBlock: this.defaultBlock,
+ defaultBlock,
};
const proxyAllowance = await this.token.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts);
this.setProxyAllowance(tokenAddress, userAddress, proxyAllowance);
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<BigNumber> {
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<BigNumber> {
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);