aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src/parsers
diff options
context:
space:
mode:
Diffstat (limited to 'packages/pipeline/src/parsers')
-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
4 files changed, 58 insertions, 0 deletions
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');