aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-11-13 09:36:33 +0800
committerFred Carlsen <fred@sjelfull.no>2018-12-06 19:04:25 +0800
commitb818a62d745b2e91a8808ded9bac279d2dbf8a7e (patch)
treeda2a095d1ee14ea7e1226de8911a5c323229be07 /packages
parente69cdfb7b5b0b4c7517d5439d45888702c6a1b71 (diff)
downloaddexon-sol-tools-b818a62d745b2e91a8808ded9bac279d2dbf8a7e.tar
dexon-sol-tools-b818a62d745b2e91a8808ded9bac279d2dbf8a7e.tar.gz
dexon-sol-tools-b818a62d745b2e91a8808ded9bac279d2dbf8a7e.tar.bz2
dexon-sol-tools-b818a62d745b2e91a8808ded9bac279d2dbf8a7e.tar.lz
dexon-sol-tools-b818a62d745b2e91a8808ded9bac279d2dbf8a7e.tar.xz
dexon-sol-tools-b818a62d745b2e91a8808ded9bac279d2dbf8a7e.tar.zst
dexon-sol-tools-b818a62d745b2e91a8808ded9bac279d2dbf8a7e.zip
Configure linter with --format stylish and fix linter errors
Diffstat (limited to 'packages')
-rw-r--r--packages/pipeline/package.json2
-rw-r--r--packages/pipeline/src/data_sources/contract-wrappers/exchange_events.ts4
-rw-r--r--packages/pipeline/src/data_sources/relayer-registry/index.ts2
-rw-r--r--packages/pipeline/src/data_sources/web3/index.ts4
-rw-r--r--packages/pipeline/src/ormconfig.ts2
-rw-r--r--packages/pipeline/src/parsers/events/index.ts34
-rw-r--r--packages/pipeline/src/parsers/relayer_registry/index.ts4
-rw-r--r--packages/pipeline/src/parsers/sra_orders/index.ts12
-rw-r--r--packages/pipeline/src/parsers/web3/index.ts8
-rw-r--r--packages/pipeline/src/scripts/pull_missing_events.ts1
-rw-r--r--packages/pipeline/src/scripts/update_relayer_info.ts1
-rw-r--r--packages/pipeline/src/utils/index.ts14
12 files changed, 81 insertions, 7 deletions
diff --git a/packages/pipeline/package.json b/packages/pipeline/package.json
index 367296e05..59cf24dc6 100644
--- a/packages/pipeline/package.json
+++ b/packages/pipeline/package.json
@@ -13,7 +13,7 @@
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"clean": "shx rm -rf lib",
- "lint": "tslint --project .",
+ "lint": "tslint --project . --format stylish --exclude ./migrations",
"migrate:run": "yarn typeorm migration:run --config ./lib/src/ormconfig",
"migrate:revert": "yarn typeorm migration:revert --config ./lib/src/ormconfig",
"migrate:create": "yarn typeorm migration:create --config ./lib/src/ormconfig --dir migrations"
diff --git a/packages/pipeline/src/data_sources/contract-wrappers/exchange_events.ts b/packages/pipeline/src/data_sources/contract-wrappers/exchange_events.ts
index 5ce8381cd..e25c6a731 100644
--- a/packages/pipeline/src/data_sources/contract-wrappers/exchange_events.ts
+++ b/packages/pipeline/src/data_sources/contract-wrappers/exchange_events.ts
@@ -8,8 +8,8 @@ const NUM_BLOCKS_PER_QUERY = 100000; // Number of blocks to query for events at
const EXCHANGE_START_BLOCK = 6271590; // Block number when the Exchange contract was deployed to mainnet.
export class ExchangeEventsSource {
- private _exchangeWrapper: ExchangeWrapper;
- private _web3Wrapper: Web3Wrapper;
+ private readonly _exchangeWrapper: ExchangeWrapper;
+ private readonly _web3Wrapper: Web3Wrapper;
constructor(provider: Web3ProviderEngine, networkId: number) {
this._web3Wrapper = new Web3Wrapper(provider);
const contractWrappers = new ContractWrappers(provider, { networkId });
diff --git a/packages/pipeline/src/data_sources/relayer-registry/index.ts b/packages/pipeline/src/data_sources/relayer-registry/index.ts
index 8199dae14..8133f5eae 100644
--- a/packages/pipeline/src/data_sources/relayer-registry/index.ts
+++ b/packages/pipeline/src/data_sources/relayer-registry/index.ts
@@ -20,7 +20,7 @@ export interface RelayerResponseNetwork {
}
export class RelayerRegistrySource {
- private _url: string;
+ private readonly _url: string;
constructor(url: string) {
this._url = url;
diff --git a/packages/pipeline/src/data_sources/web3/index.ts b/packages/pipeline/src/data_sources/web3/index.ts
index 64e909939..45a9ea161 100644
--- a/packages/pipeline/src/data_sources/web3/index.ts
+++ b/packages/pipeline/src/data_sources/web3/index.ts
@@ -3,7 +3,7 @@ import { Web3Wrapper } from '@0x/web3-wrapper';
import { BlockWithoutTransactionData, Transaction } from 'ethereum-types';
export class Web3Source {
- private _web3Wrapper: Web3Wrapper;
+ private readonly _web3Wrapper: Web3Wrapper;
constructor(provider: Web3ProviderEngine) {
this._web3Wrapper = new Web3Wrapper(provider);
}
@@ -11,7 +11,7 @@ export class Web3Source {
public async getBlockInfoAsync(blockNumber: number): Promise<BlockWithoutTransactionData> {
const block = await this._web3Wrapper.getBlockIfExistsAsync(blockNumber);
if (block == null) {
- return Promise.reject(new Error('Could not find block for given block number: ' + blockNumber));
+ return Promise.reject(new Error(`Could not find block for given block number: ${blockNumber}`));
}
return block;
}
diff --git a/packages/pipeline/src/ormconfig.ts b/packages/pipeline/src/ormconfig.ts
index 95c27eeba..2fb6b3d3c 100644
--- a/packages/pipeline/src/ormconfig.ts
+++ b/packages/pipeline/src/ormconfig.ts
@@ -29,4 +29,4 @@ const config: ConnectionOptions = {
migrations: ['./lib/migrations/**/*.js'],
};
-module.exports = config as ConnectionOptions;
+module.exports = config;
diff --git a/packages/pipeline/src/parsers/events/index.ts b/packages/pipeline/src/parsers/events/index.ts
index 7a0ead0d4..d56dc7080 100644
--- a/packages/pipeline/src/parsers/events/index.ts
+++ b/packages/pipeline/src/parsers/events/index.ts
@@ -18,19 +18,38 @@ export const parseExchangeEvents: (
eventLogs: Array<LogWithDecodedArgs<ExchangeEventArgs>>,
) => ExchangeEventEntity[] = R.map(_convertToEntity);
+/**
+ * Converts a raw event log to an Entity. Automatically detects the type of
+ * event and returns the appropriate entity type. Throws for unknown event
+ * types.
+ * @param eventLog Raw event log (e.g. returned from contract-wrappers).
+ */
export function _convertToEntity(eventLog: LogWithDecodedArgs<ExchangeEventArgs>): ExchangeEventEntity {
switch (eventLog.event) {
case 'Fill':
+ // tslint has a false positive here. We need to type assert in order
+ // to change the type argument to the more specific
+ // ExchangeFillEventArgs.
+ // tslint:disable-next-line:no-unnecessary-type-assertion
return _convertToExchangeFillEvent(eventLog as LogWithDecodedArgs<ExchangeFillEventArgs>);
case 'Cancel':
+ // tslint:disable-next-line:no-unnecessary-type-assertion
return _convertToExchangeCancelEvent(eventLog as LogWithDecodedArgs<ExchangeCancelEventArgs>);
case 'CancelUpTo':
+ // tslint:disable-next-line:no-unnecessary-type-assertion
return _convertToExchangeCancelUpToEvent(eventLog as LogWithDecodedArgs<ExchangeCancelUpToEventArgs>);
default:
+ // Another false positive here. We are adding two strings, but
+ // tslint seems confused about the types.
+ // tslint:disable-next-line:restrict-plus-operands
throw new Error('unexpected eventLog.event type: ' + eventLog.event);
}
}
+/**
+ * Converts a raw event log for a fill event into an ExchangeFillEvent entity.
+ * @param eventLog Raw event log (e.g. returned from contract-wrappers).
+ */
export function _convertToExchangeFillEvent(eventLog: LogWithDecodedArgs<ExchangeFillEventArgs>): ExchangeFillEvent {
const makerAssetData = assetDataUtils.decodeAssetDataOrThrow(eventLog.args.makerAssetData);
const makerAssetType = makerAssetData.assetProxyId === AssetProxyId.ERC20 ? 'erc20' : 'erc721';
@@ -55,15 +74,23 @@ export function _convertToExchangeFillEvent(eventLog: LogWithDecodedArgs<Exchang
exchangeFillEvent.makerAssetType = makerAssetType;
exchangeFillEvent.makerAssetProxyId = makerAssetData.assetProxyId;
exchangeFillEvent.makerTokenAddress = makerAssetData.tokenAddress;
+ // tslint has a false positive here. Type assertion is required.
+ // tslint:disable-next-line:no-unnecessary-type-assertion
exchangeFillEvent.makerTokenId = bigNumbertoStringOrNull((makerAssetData as ERC721AssetData).tokenId);
exchangeFillEvent.rawTakerAssetData = eventLog.args.takerAssetData;
exchangeFillEvent.takerAssetType = takerAssetType;
exchangeFillEvent.takerAssetProxyId = takerAssetData.assetProxyId;
exchangeFillEvent.takerTokenAddress = takerAssetData.tokenAddress;
+ // tslint:disable-next-line:no-unnecessary-type-assertion
exchangeFillEvent.takerTokenId = bigNumbertoStringOrNull((takerAssetData as ERC721AssetData).tokenId);
return exchangeFillEvent;
}
+/**
+ * Converts a raw event log for a cancel event into an ExchangeCancelEvent
+ * entity.
+ * @param eventLog Raw event log (e.g. returned from contract-wrappers).
+ */
export function _convertToExchangeCancelEvent(
eventLog: LogWithDecodedArgs<ExchangeCancelEventArgs>,
): ExchangeCancelEvent {
@@ -86,15 +113,22 @@ export function _convertToExchangeCancelEvent(
exchangeCancelEvent.makerAssetType = makerAssetType;
exchangeCancelEvent.makerAssetProxyId = makerAssetData.assetProxyId;
exchangeCancelEvent.makerTokenAddress = makerAssetData.tokenAddress;
+ // tslint:disable-next-line:no-unnecessary-type-assertion
exchangeCancelEvent.makerTokenId = bigNumbertoStringOrNull((makerAssetData as ERC721AssetData).tokenId);
exchangeCancelEvent.rawTakerAssetData = eventLog.args.takerAssetData;
exchangeCancelEvent.takerAssetType = takerAssetType;
exchangeCancelEvent.takerAssetProxyId = takerAssetData.assetProxyId;
exchangeCancelEvent.takerTokenAddress = takerAssetData.tokenAddress;
+ // tslint:disable-next-line:no-unnecessary-type-assertion
exchangeCancelEvent.takerTokenId = bigNumbertoStringOrNull((takerAssetData as ERC721AssetData).tokenId);
return exchangeCancelEvent;
}
+/**
+ * Converts a raw event log for a cancelUpTo event into an
+ * ExchangeCancelUpToEvent entity.
+ * @param eventLog Raw event log (e.g. returned from contract-wrappers).
+ */
export function _convertToExchangeCancelUpToEvent(
eventLog: LogWithDecodedArgs<ExchangeCancelUpToEventArgs>,
): ExchangeCancelUpToEvent {
diff --git a/packages/pipeline/src/parsers/relayer_registry/index.ts b/packages/pipeline/src/parsers/relayer_registry/index.ts
index a61f4e62a..346f570bd 100644
--- a/packages/pipeline/src/parsers/relayer_registry/index.ts
+++ b/packages/pipeline/src/parsers/relayer_registry/index.ts
@@ -3,6 +3,10 @@ import * as R from 'ramda';
import { RelayerResponse, RelayerResponseNetwork } from '../../data_sources/relayer-registry';
import { Relayer } from '../../entities';
+/**
+ * Parses a raw relayer registry response into an array of Relayer entities.
+ * @param rawResp raw response from the relayer-registry json file.
+ */
export function parseRelayers(rawResp: Map<string, RelayerResponse>): Relayer[] {
const parsedAsObject = R.mapObjIndexed(parseRelayer, rawResp);
return R.values(parsedAsObject);
diff --git a/packages/pipeline/src/parsers/sra_orders/index.ts b/packages/pipeline/src/parsers/sra_orders/index.ts
index 4e4bf12ff..3d7f73fca 100644
--- a/packages/pipeline/src/parsers/sra_orders/index.ts
+++ b/packages/pipeline/src/parsers/sra_orders/index.ts
@@ -6,10 +6,19 @@ import * as R from 'ramda';
import { SraOrder } from '../../entities';
import { bigNumbertoStringOrNull } from '../../utils';
+/**
+ * Parses a raw order response from an SRA endpoint and returns an array of
+ * SraOrder entities.
+ * @param rawOrdersResponse A raw order response from an SRA endpoint.
+ */
export function parseSraOrders(rawOrdersResponse: OrdersResponse): SraOrder[] {
return R.map(_convertToEntity, rawOrdersResponse.records);
}
+/**
+ * Converts a single APIOrder into an SraOrder entity.
+ * @param apiOrder A single order from the response from an SRA endpoint.
+ */
export function _convertToEntity(apiOrder: APIOrder): SraOrder {
// TODO(albrow): refactor out common asset data decoding code.
const makerAssetData = assetDataUtils.decodeAssetDataOrThrow(apiOrder.order.makerAssetData);
@@ -41,11 +50,14 @@ export function _convertToEntity(apiOrder: APIOrder): SraOrder {
sraOrder.makerAssetType = makerAssetType;
sraOrder.makerAssetProxyId = makerAssetData.assetProxyId;
sraOrder.makerTokenAddress = makerAssetData.tokenAddress;
+ // tslint has a false positive here. Type assertion is required.
+ // tslint:disable-next-line:no-unnecessary-type-assertion
sraOrder.makerTokenId = bigNumbertoStringOrNull((makerAssetData as ERC721AssetData).tokenId);
sraOrder.rawTakerAssetData = apiOrder.order.takerAssetData;
sraOrder.takerAssetType = takerAssetType;
sraOrder.takerAssetProxyId = takerAssetData.assetProxyId;
sraOrder.takerTokenAddress = takerAssetData.tokenAddress;
+ // tslint:disable-next-line:no-unnecessary-type-assertion
sraOrder.takerTokenId = bigNumbertoStringOrNull((takerAssetData as ERC721AssetData).tokenId);
sraOrder.metadataJson = JSON.stringify(apiOrder.metaData);
diff --git a/packages/pipeline/src/parsers/web3/index.ts b/packages/pipeline/src/parsers/web3/index.ts
index 11571278b..2ead4c0e4 100644
--- a/packages/pipeline/src/parsers/web3/index.ts
+++ b/packages/pipeline/src/parsers/web3/index.ts
@@ -2,6 +2,10 @@ import { BlockWithoutTransactionData, Transaction as EthTransaction } from 'ethe
import { Block, Transaction } from '../../entities';
+/**
+ * Parses a raw block and returns a Block entity.
+ * @param rawBlock a raw block (e.g. returned from web3-wrapper).
+ */
export function parseBlock(rawBlock: BlockWithoutTransactionData): Block {
if (rawBlock.hash == null) {
throw new Error('Tried to parse raw block but hash was null');
@@ -17,6 +21,10 @@ export function parseBlock(rawBlock: BlockWithoutTransactionData): Block {
return block;
}
+/**
+ * Parses a raw transaction and returns a Transaction entity.
+ * @param rawBlock a raw transaction (e.g. returned from web3-wrapper).
+ */
export function parseTransaction(rawTransaction: EthTransaction): Transaction {
if (rawTransaction.blockHash == null) {
throw new Error('Tried to parse raw transaction but blockHash was null');
diff --git a/packages/pipeline/src/scripts/pull_missing_events.ts b/packages/pipeline/src/scripts/pull_missing_events.ts
index e2b312280..bc0eac853 100644
--- a/packages/pipeline/src/scripts/pull_missing_events.ts
+++ b/packages/pipeline/src/scripts/pull_missing_events.ts
@@ -1,3 +1,4 @@
+// tslint:disable:no-console
import { web3Factory } from '@0x/dev-utils';
import { Web3ProviderEngine } from '@0x/subproviders';
import R = require('ramda');
diff --git a/packages/pipeline/src/scripts/update_relayer_info.ts b/packages/pipeline/src/scripts/update_relayer_info.ts
index af9dd726e..f8918728d 100644
--- a/packages/pipeline/src/scripts/update_relayer_info.ts
+++ b/packages/pipeline/src/scripts/update_relayer_info.ts
@@ -1,3 +1,4 @@
+// tslint:disable:no-console
import 'reflect-metadata';
import { Connection, ConnectionOptions, createConnection } from 'typeorm';
diff --git a/packages/pipeline/src/utils/index.ts b/packages/pipeline/src/utils/index.ts
index 4242e0437..a083cd8c9 100644
--- a/packages/pipeline/src/utils/index.ts
+++ b/packages/pipeline/src/utils/index.ts
@@ -1,5 +1,10 @@
import { BigNumber } from '@0x/utils';
+/**
+ * If the given BigNumber is not null, returns the string representation of that
+ * number. Otherwise, returns null.
+ * @param n The number to convert.
+ */
export function bigNumbertoStringOrNull(n: BigNumber): string | null {
if (n == null) {
return null;
@@ -7,15 +12,24 @@ export function bigNumbertoStringOrNull(n: BigNumber): string | null {
return n.toString();
}
+/**
+ * Logs an error by intelligently checking for `message` and `stack` properties.
+ * Intended for use with top-level immediately invoked asynchronous functions.
+ * @param e the error to log.
+ */
export function handleError(e: any): void {
if (e.message != null) {
+ // tslint:disable-next-line:no-console
console.error(e.message);
} else {
+ // tslint:disable-next-line:no-console
console.error('Unknown error');
}
if (e.stack != null) {
+ // tslint:disable-next-line:no-console
console.error(e.stack);
} else {
+ // tslint:disable-next-line:no-console
console.error('(No stack trace)');
}
process.exit(1);