Implement Simple Fetchers

This commit is contained in:
Ara Kevonian
2018-04-13 03:04:51 -07:00
parent bf0ef055fb
commit 38f7c4a0d2
8 changed files with 58 additions and 8 deletions

View File

@@ -13,8 +13,8 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import { artifacts } from '../artifacts';
import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store';
import { OrderFilledCancelledLazyStore } from '../stores/order_filled_cancelled_lazy_store';
import { SimpleBalanceAndAllowanceFetcher } from '../fetchers/simple_balance_and_allowance_fetcher';
import { SimpleOrderFilledCancelledFetcher } from '../fetchers/simple_order_filled_cancelled_fetcher';
import {
BlockRange,
EventCallback,
@@ -881,11 +881,11 @@ export class ExchangeWrapper extends ContractWrapper {
* @param signedOrder The signedOrder
*/
public async getOrderStateAsync(signedOrder: SignedOrder): Promise<OrderState> {
const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
const balanceAndProxyAllowanceLazyStore = new SimpleBalanceAndAllowanceFetcher(
this._tokenWrapper,
BlockParamLiteral.Latest,
);
const orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(this);
const orderFilledCancelledLazyStore = new SimpleOrderFilledCancelledFetcher(this);
const orderStateUtils = new OrderStateUtils(balanceAndProxyAllowanceLazyStore, orderFilledCancelledLazyStore);
return orderStateUtils.getOrderStateAsync(signedOrder);
}

View File

@@ -0,0 +1,26 @@
import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import {BalanceAndAllowanceFetcher} from '../abstract/balance_and_allowance_fetcher';
import {TokenWrapper} from '../contract_wrappers/token_wrapper';
export class SimpleBalanceAndAllowanceFetcher implements BalanceAndAllowanceFetcher {
private _token: TokenWrapper;
private _defaultBlock: BlockParamLiteral;
constructor(token: TokenWrapper, defaultBlock: BlockParamLiteral) {
this._token = token;
this._defaultBlock = defaultBlock;
}
public async getBalanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> {
const methodOpts = {
defaultBlock: this._defaultBlock,
};
return this._token.getBalanceAsync(tokenAddress, userAddress, methodOpts);
}
public async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> {
const methodOpts = {
defaultBlock: this._defaultBlock,
};
return this._token.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts);
}
}

View File

@@ -0,0 +1,24 @@
import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import {OrderFilledCancelledFetcher} from '../abstract/order_filled_cancelled_fetcher';
import {ExchangeWrapper} from '../contract_wrappers/exchange_wrapper';
export class SimpleOrderFilledCancelledFetcher implements OrderFilledCancelledFetcher {
private _exchange: ExchangeWrapper;
constructor(exchange: ExchangeWrapper) {
this._exchange = exchange;
}
public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> {
const methodOpts = {
defaultBlock: BlockParamLiteral.Pending,
};
return this._exchange.getFilledTakerAmountAsync(orderHash, methodOpts);
}
public async getCancelledTakerAmountAsync(orderHash: string): Promise<BigNumber> {
const methodOpts = {
defaultBlock: BlockParamLiteral.Pending,
};
return this._exchange.getCancelledTakerAmountAsync(orderHash, methodOpts);
}
}

View File

@@ -3,7 +3,7 @@ import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import { TokenWrapper } from '../contract_wrappers/token_wrapper';
import { BalanceAndAllowanceFetcher } from '../fetchers/balance_and_allowance_fetcher';
import { BalanceAndAllowanceFetcher } from '../abstract/balance_and_allowance_fetcher';
/**
* Copy on read store for balances/proxyAllowances of tokens/accounts

View File

@@ -3,7 +3,7 @@ import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';
import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_fetcher';
import { OrderFilledCancelledFetcher } from '../abstract/order_filled_cancelled_fetcher';
/**
* Copy on read store for filled/cancelled taker amounts

View File

@@ -4,8 +4,8 @@ import * as _ from 'lodash';
import { ZeroEx } from '../0x';
import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';
import { BalanceAndAllowanceFetcher } from '../fetchers/balance_and_allowance_fetcher';
import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_fetcher';
import { BalanceAndAllowanceFetcher } from '../abstract/balance_and_allowance_fetcher';
import { OrderFilledCancelledFetcher } from '../abstract/order_filled_cancelled_fetcher';
import { RemainingFillableCalculator } from '../order_watcher/remaining_fillable_calculator';
import { ExchangeContractErrs, OrderRelevantState, OrderState, OrderStateInvalid, OrderStateValid } from '../types';