From 52f2ee6e797435d887d4ad06955a3ffbf61081ca Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 12 Nov 2018 17:36:33 -0800 Subject: Configure linter with --format stylish and fix linter errors --- packages/pipeline/src/parsers/events/index.ts | 34 +++++++++++++++++++++++ packages/pipeline/src/parsers/sra_orders/index.ts | 12 ++++++++ 2 files changed, 46 insertions(+) (limited to 'packages') 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>, ) => 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): 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); case 'Cancel': + // tslint:disable-next-line:no-unnecessary-type-assertion return _convertToExchangeCancelEvent(eventLog as LogWithDecodedArgs); case 'CancelUpTo': + // tslint:disable-next-line:no-unnecessary-type-assertion return _convertToExchangeCancelUpToEvent(eventLog as LogWithDecodedArgs); 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): 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, ): 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, ): ExchangeCancelUpToEvent { 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); -- cgit v1.2.3