diff options
author | Fabio Berger <me@fabioberger.com> | 2018-10-16 23:59:02 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-10-16 23:59:02 +0800 |
commit | c84c92663d1ce0227b755dc861f825c35a3c7999 (patch) | |
tree | 3800297ba0072233fe88839b675e33e6b44f9649 /packages/order-watcher/src | |
parent | 55a3bc8cb6772802672f60f22c5ed5c7e1b2dfdd (diff) | |
parent | c333d093b585fa0250a6973f2d396eb3cf227334 (diff) | |
download | dexon-0x-contracts-c84c92663d1ce0227b755dc861f825c35a3c7999.tar.gz dexon-0x-contracts-c84c92663d1ce0227b755dc861f825c35a3c7999.tar.zst dexon-0x-contracts-c84c92663d1ce0227b755dc861f825c35a3c7999.zip |
Merge branch 'dev-section-redesign' into reSkinReferenceDocs
* dev-section-redesign: (87 commits)
Added note about restriction on `testDirectory`
fix(dev-utils): Make chai a dev dependency since exported interface depends on it
Add changelog entries
fix(subproviders): make web3-provider-engine types a 'dependency' so it's available to users of the library
fix(sra-spec): make @loopback/openapi-v3-types a 'dependency' so it's available to users of the library
fix(sol-cov): make @types/solidity-parser-antlr a 'dependency' so it's available to users of the library
fix(dev-utils): make web3-provider-engine types a 'dependency' so it's available to users of the library
fix(0x.js): make web3-provider-engine types a 'dependency' so it's available to users of the library
fix(monorepo-scripts): Move the creation of the `.installation-test` directory OUTSIDE of the monorepo root, so that the installed packages can't reference the hoisted node_modules folder
Remove ContractNotFound errors in contract-wrappers
Update prettierignore
Update website to use the new unsubscribeAll method in contract-wrappers
In abi-gen-wrappers, ./wrappers -> ./src/generated-wrappers
In contract-wrappers, remove setProvider and add unsubscribeAll method.
take out explicit children definition in props
Update json-schemas for contract-wrappers
Add OrThrow suffix to getContractAddressesForNetwork
remove unused import
Update CHANGELOG.json for all changed packages
Remove ContractAddresses from packages/types (mistake after rebase)
...
Diffstat (limited to 'packages/order-watcher/src')
-rw-r--r-- | packages/order-watcher/src/artifacts.ts | 13 | ||||
-rw-r--r-- | packages/order-watcher/src/globals.d.ts | 6 | ||||
-rw-r--r-- | packages/order-watcher/src/index.ts | 2 | ||||
-rw-r--r-- | packages/order-watcher/src/order_watcher/order_watcher.ts | 25 |
4 files changed, 23 insertions, 23 deletions
diff --git a/packages/order-watcher/src/artifacts.ts b/packages/order-watcher/src/artifacts.ts deleted file mode 100644 index 520066a24..000000000 --- a/packages/order-watcher/src/artifacts.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ContractArtifact } from 'ethereum-types'; - -import * as ERC20Token from './artifacts/ERC20Token.json'; -import * as ERC721Token from './artifacts/ERC721Token.json'; -import * as Exchange from './artifacts/Exchange.json'; -import * as WETH9 from './artifacts/WETH9.json'; - -export const artifacts = { - ERC20Token: (ERC20Token as any) as ContractArtifact, - ERC721Token: (ERC721Token as any) as ContractArtifact, - Exchange: (Exchange as any) as ContractArtifact, - EtherToken: (WETH9 as any) as ContractArtifact, -}; diff --git a/packages/order-watcher/src/globals.d.ts b/packages/order-watcher/src/globals.d.ts deleted file mode 100644 index 94e63a32d..000000000 --- a/packages/order-watcher/src/globals.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -declare module '*.json' { - const json: any; - /* tslint:disable */ - export default json; - /* tslint:enable */ -} diff --git a/packages/order-watcher/src/index.ts b/packages/order-watcher/src/index.ts index d2f91eab1..6e862a427 100644 --- a/packages/order-watcher/src/index.ts +++ b/packages/order-watcher/src/index.ts @@ -7,10 +7,12 @@ export { OrderState, ExchangeContractErrs, OrderRelevantState, + Stats, } from '@0xproject/types'; export { OnOrderStateChangeCallback, OrderWatcherConfig } from './types'; +export { ContractAddresses } from '@0xproject/contract-addresses'; export { SignedOrder } from '@0xproject/types'; export { JSONRPCRequestPayload, diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index f9a63efe3..2f0dd2f2d 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -1,4 +1,6 @@ // tslint:disable:no-unnecessary-type-assertion +import { ContractAddresses } from '@0xproject/contract-addresses'; +import * as artifacts from '@0xproject/contract-artifacts'; import { AssetBalanceAndProxyAllowanceFetcher, ContractWrappers, @@ -30,12 +32,11 @@ import { orderHashUtils, OrderStateUtils, } from '@0xproject/order-utils'; -import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder } from '@0xproject/types'; +import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder, Stats } from '@0xproject/types'; import { errorUtils, intervalUtils } from '@0xproject/utils'; import { BlockParamLiteral, LogEntryEvent, LogWithDecodedArgs, Provider } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts } from '../artifacts'; import { orderWatcherPartialConfigSchema } from '../schemas/order_watcher_partial_config_schema'; import { OnOrderStateChangeCallback, OrderWatcherConfig, OrderWatcherError } from '../types'; import { assert } from '../utils/assert'; @@ -91,11 +92,14 @@ export class OrderWatcher { * Instantiate a new OrderWatcher * @param provider Web3 provider to use for JSON RPC calls * @param networkId NetworkId to watch orders on + * @param contractAddresses Optional contract addresses. Defaults to known + * addresses based on networkId. * @param partialConfig Optional configurations */ constructor( provider: Provider, networkId: number, + contractAddresses?: ContractAddresses, partialConfig: Partial<OrderWatcherConfig> = DEFAULT_ORDER_WATCHER_CONFIG, ) { assert.isWeb3Provider('provider', provider); @@ -110,9 +114,14 @@ export class OrderWatcher { this._collisionResistantAbiDecoder = new CollisionResistanceAbiDecoder( artifacts.ERC20Token.compilerOutput.abi, artifacts.ERC721Token.compilerOutput.abi, - [artifacts.EtherToken.compilerOutput.abi, artifacts.Exchange.compilerOutput.abi], + [artifacts.WETH9.compilerOutput.abi, artifacts.Exchange.compilerOutput.abi], ); - const contractWrappers = new ContractWrappers(provider, { networkId }); + const contractWrappers = new ContractWrappers(provider, { + networkId, + // Note(albrow): We let the contract-wrappers package handle + // default values for contractAddresses. + contractAddresses, + }); this._eventWatcher = new EventWatcher(provider, config.eventPollingIntervalMs, STATE_LAYER, config.isVerbose); const balanceAndProxyAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher( contractWrappers.erc20Token, @@ -213,6 +222,14 @@ export class OrderWatcher { this._expirationWatcher.unsubscribe(); intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists); } + /** + * Gets statistics of the OrderWatcher Instance. + */ + public getStats(): Stats { + return { + orderCount: _.size(this._orderByOrderHash), + }; + } private async _cleanupAsync(): Promise<void> { for (const orderHash of _.keys(this._orderByOrderHash)) { this._cleanupOrderRelatedState(orderHash); |