From ccad046eb649a60fdf7319a075fa41490d593ae8 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Thu, 8 Nov 2018 10:15:09 -0800 Subject: Reorganize entities. Make scripts work from any directory. --- .../pipeline/src/entities/ExchangeCancelEvent.ts | 35 ------------------ .../src/entities/ExchangeCancelUpToEvent.ts | 16 --------- .../pipeline/src/entities/ExchangeFillEvent.ts | 38 -------------------- packages/pipeline/src/entities/SraOrder.ts | 41 ---------------------- .../pipeline/src/entities/exchange_cancel_event.ts | 35 ++++++++++++++++++ .../src/entities/exchange_cancel_up_to_event.ts | 16 +++++++++ .../pipeline/src/entities/exchange_fill_event.ts | 38 ++++++++++++++++++++ packages/pipeline/src/entities/index.ts | 7 ++++ packages/pipeline/src/entities/sra_order.ts | 41 ++++++++++++++++++++++ packages/pipeline/src/ormconfig.ts | 24 +++++++++++-- packages/pipeline/src/parsers/events/index.ts | 4 +-- .../pipeline/src/parsers/relayer_registry/index.ts | 2 +- packages/pipeline/src/parsers/sra_orders/index.ts | 2 +- packages/pipeline/src/parsers/web3/index.ts | 3 +- packages/pipeline/src/scripts/merge_v2_events.ts | 2 +- .../pipeline/src/scripts/pull_missing_events.ts | 2 +- .../pipeline/src/scripts/update_relayer_info.ts | 2 +- .../pipeline/test/parsers/events/index_test.ts | 2 +- .../pipeline/test/parsers/sra_orders/index_test.ts | 2 +- 19 files changed, 168 insertions(+), 144 deletions(-) delete mode 100644 packages/pipeline/src/entities/ExchangeCancelEvent.ts delete mode 100644 packages/pipeline/src/entities/ExchangeCancelUpToEvent.ts delete mode 100644 packages/pipeline/src/entities/ExchangeFillEvent.ts delete mode 100644 packages/pipeline/src/entities/SraOrder.ts create mode 100644 packages/pipeline/src/entities/exchange_cancel_event.ts create mode 100644 packages/pipeline/src/entities/exchange_cancel_up_to_event.ts create mode 100644 packages/pipeline/src/entities/exchange_fill_event.ts create mode 100644 packages/pipeline/src/entities/index.ts create mode 100644 packages/pipeline/src/entities/sra_order.ts diff --git a/packages/pipeline/src/entities/ExchangeCancelEvent.ts b/packages/pipeline/src/entities/ExchangeCancelEvent.ts deleted file mode 100644 index 698b9e2ec..000000000 --- a/packages/pipeline/src/entities/ExchangeCancelEvent.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -import { AssetType } from '../types'; - -@Entity() -export class ExchangeCancelEvent { - @PrimaryColumn() public contractAddress!: string; - @PrimaryColumn() public logIndex!: number; - @PrimaryColumn() public blockNumber!: number; - - @Column() public rawData!: string; - - // TODO(albrow): Include transaction hash - @Column() public makerAddress!: string; - @Column({ nullable: true, type: String }) - public takerAddress!: string; - @Column() public feeRecepientAddress!: string; - @Column() public senderAddress!: string; - @Column() public orderHash!: string; - - @Column() public rawMakerAssetData!: string; - @Column() public makerAssetType!: AssetType; - @Column() public makerAssetProxyId!: string; - @Column() public makerTokenAddress!: string; - @Column({ nullable: true, type: String }) - public makerTokenId!: string | null; - @Column() public rawTakerAssetData!: string; - @Column() public takerAssetType!: AssetType; - @Column() public takerAssetProxyId!: string; - @Column() public takerTokenAddress!: string; - @Column({ nullable: true, type: String }) - public takerTokenId!: string | null; - - // TODO(albrow): Include topics? -} diff --git a/packages/pipeline/src/entities/ExchangeCancelUpToEvent.ts b/packages/pipeline/src/entities/ExchangeCancelUpToEvent.ts deleted file mode 100644 index 3ca75ccf7..000000000 --- a/packages/pipeline/src/entities/ExchangeCancelUpToEvent.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity() -export class ExchangeCancelUpToEvent { - @PrimaryColumn() public contractAddress!: string; - @PrimaryColumn() public logIndex!: number; - @PrimaryColumn() public blockNumber!: number; - - // TODO(albrow): Include transaction hash - @Column() public rawData!: string; - - @Column() public makerAddress!: string; - @Column() public senderAddress!: string; - @Column() public orderEpoch!: string; - // TODO(albrow): Include topics? -} diff --git a/packages/pipeline/src/entities/ExchangeFillEvent.ts b/packages/pipeline/src/entities/ExchangeFillEvent.ts deleted file mode 100644 index 6e549af93..000000000 --- a/packages/pipeline/src/entities/ExchangeFillEvent.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -import { AssetType } from '../types'; - -@Entity() -export class ExchangeFillEvent { - @PrimaryColumn() public contractAddress!: string; - @PrimaryColumn() public logIndex!: number; - @PrimaryColumn() public blockNumber!: number; - - @Column() public rawData!: string; - - @Column() public transactionHash!: string; - @Column() public makerAddress!: string; - @Column() public takerAddress!: string; - @Column() public feeRecipientAddress!: string; - @Column() public senderAddress!: string; - @Column() public makerAssetFilledAmount!: string; - @Column() public takerAssetFilledAmount!: string; - @Column() public makerFeePaid!: string; - @Column() public takerFeePaid!: string; - @Column() public orderHash!: string; - - @Column() public rawMakerAssetData!: string; - @Column() public makerAssetType!: AssetType; - @Column() public makerAssetProxyId!: string; - @Column() public makerTokenAddress!: string; - @Column({ nullable: true, type: String }) - public makerTokenId!: string | null; - @Column() public rawTakerAssetData!: string; - @Column() public takerAssetType!: AssetType; - @Column() public takerAssetProxyId!: string; - @Column() public takerTokenAddress!: string; - @Column({ nullable: true, type: String }) - public takerTokenId!: string | null; - - // TODO(albrow): Include topics? -} diff --git a/packages/pipeline/src/entities/SraOrder.ts b/packages/pipeline/src/entities/SraOrder.ts deleted file mode 100644 index a22f7c4e5..000000000 --- a/packages/pipeline/src/entities/SraOrder.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -import { AssetType } from '../types'; - -@Entity() -export class SraOrder { - @PrimaryColumn() public exchangeAddress!: string; - @PrimaryColumn() public orderHashHex!: string; - - @Column() public sourceUrl!: string; - @Column() public lastUpdatedTimestamp!: number; - @Column() public firstSeenTimestamp!: number; - - @Column() public makerAddress!: string; - @Column() public takerAddress!: string; - @Column() public feeRecipientAddress!: string; - @Column() public senderAddress!: string; - @Column() public makerAssetAmount!: string; - @Column() public takerAssetAmount!: string; - @Column() public makerFee!: string; - @Column() public takerFee!: string; - @Column() public expirationTimeSeconds!: string; - @Column() public salt!: string; - @Column() public signature!: string; - - @Column() public rawMakerAssetData!: string; - @Column() public makerAssetType!: AssetType; - @Column() public makerAssetProxyId!: string; - @Column() public makerTokenAddress!: string; - @Column({ nullable: true, type: String }) - public makerTokenId!: string | null; - @Column() public rawTakerAssetData!: string; - @Column() public takerAssetType!: AssetType; - @Column() public takerAssetProxyId!: string; - @Column() public takerTokenAddress!: string; - @Column({ nullable: true, type: String }) - public takerTokenId!: string | null; - - // TODO(albrow): Make this optional? - @Column() public metaDataJson!: string; -} diff --git a/packages/pipeline/src/entities/exchange_cancel_event.ts b/packages/pipeline/src/entities/exchange_cancel_event.ts new file mode 100644 index 000000000..698b9e2ec --- /dev/null +++ b/packages/pipeline/src/entities/exchange_cancel_event.ts @@ -0,0 +1,35 @@ +import { Column, Entity, PrimaryColumn } from 'typeorm'; + +import { AssetType } from '../types'; + +@Entity() +export class ExchangeCancelEvent { + @PrimaryColumn() public contractAddress!: string; + @PrimaryColumn() public logIndex!: number; + @PrimaryColumn() public blockNumber!: number; + + @Column() public rawData!: string; + + // TODO(albrow): Include transaction hash + @Column() public makerAddress!: string; + @Column({ nullable: true, type: String }) + public takerAddress!: string; + @Column() public feeRecepientAddress!: string; + @Column() public senderAddress!: string; + @Column() public orderHash!: string; + + @Column() public rawMakerAssetData!: string; + @Column() public makerAssetType!: AssetType; + @Column() public makerAssetProxyId!: string; + @Column() public makerTokenAddress!: string; + @Column({ nullable: true, type: String }) + public makerTokenId!: string | null; + @Column() public rawTakerAssetData!: string; + @Column() public takerAssetType!: AssetType; + @Column() public takerAssetProxyId!: string; + @Column() public takerTokenAddress!: string; + @Column({ nullable: true, type: String }) + public takerTokenId!: string | null; + + // TODO(albrow): Include topics? +} diff --git a/packages/pipeline/src/entities/exchange_cancel_up_to_event.ts b/packages/pipeline/src/entities/exchange_cancel_up_to_event.ts new file mode 100644 index 000000000..3ca75ccf7 --- /dev/null +++ b/packages/pipeline/src/entities/exchange_cancel_up_to_event.ts @@ -0,0 +1,16 @@ +import { Column, Entity, PrimaryColumn } from 'typeorm'; + +@Entity() +export class ExchangeCancelUpToEvent { + @PrimaryColumn() public contractAddress!: string; + @PrimaryColumn() public logIndex!: number; + @PrimaryColumn() public blockNumber!: number; + + // TODO(albrow): Include transaction hash + @Column() public rawData!: string; + + @Column() public makerAddress!: string; + @Column() public senderAddress!: string; + @Column() public orderEpoch!: string; + // TODO(albrow): Include topics? +} diff --git a/packages/pipeline/src/entities/exchange_fill_event.ts b/packages/pipeline/src/entities/exchange_fill_event.ts new file mode 100644 index 000000000..6e549af93 --- /dev/null +++ b/packages/pipeline/src/entities/exchange_fill_event.ts @@ -0,0 +1,38 @@ +import { Column, Entity, PrimaryColumn } from 'typeorm'; + +import { AssetType } from '../types'; + +@Entity() +export class ExchangeFillEvent { + @PrimaryColumn() public contractAddress!: string; + @PrimaryColumn() public logIndex!: number; + @PrimaryColumn() public blockNumber!: number; + + @Column() public rawData!: string; + + @Column() public transactionHash!: string; + @Column() public makerAddress!: string; + @Column() public takerAddress!: string; + @Column() public feeRecipientAddress!: string; + @Column() public senderAddress!: string; + @Column() public makerAssetFilledAmount!: string; + @Column() public takerAssetFilledAmount!: string; + @Column() public makerFeePaid!: string; + @Column() public takerFeePaid!: string; + @Column() public orderHash!: string; + + @Column() public rawMakerAssetData!: string; + @Column() public makerAssetType!: AssetType; + @Column() public makerAssetProxyId!: string; + @Column() public makerTokenAddress!: string; + @Column({ nullable: true, type: String }) + public makerTokenId!: string | null; + @Column() public rawTakerAssetData!: string; + @Column() public takerAssetType!: AssetType; + @Column() public takerAssetProxyId!: string; + @Column() public takerTokenAddress!: string; + @Column({ nullable: true, type: String }) + public takerTokenId!: string | null; + + // TODO(albrow): Include topics? +} diff --git a/packages/pipeline/src/entities/index.ts b/packages/pipeline/src/entities/index.ts new file mode 100644 index 000000000..4cd8d9da2 --- /dev/null +++ b/packages/pipeline/src/entities/index.ts @@ -0,0 +1,7 @@ +export { Block } from './block'; +export { ExchangeCancelEvent } from './exchange_cancel_event'; +export { ExchangeCancelUpToEvent } from './exchange_cancel_up_to_event'; +export { ExchangeFillEvent } from './exchange_fill_event'; +export { Relayer } from './relayer'; +export { SraOrder } from './sra_order'; +export { Transaction } from './transaction'; diff --git a/packages/pipeline/src/entities/sra_order.ts b/packages/pipeline/src/entities/sra_order.ts new file mode 100644 index 000000000..a22f7c4e5 --- /dev/null +++ b/packages/pipeline/src/entities/sra_order.ts @@ -0,0 +1,41 @@ +import { Column, Entity, PrimaryColumn } from 'typeorm'; + +import { AssetType } from '../types'; + +@Entity() +export class SraOrder { + @PrimaryColumn() public exchangeAddress!: string; + @PrimaryColumn() public orderHashHex!: string; + + @Column() public sourceUrl!: string; + @Column() public lastUpdatedTimestamp!: number; + @Column() public firstSeenTimestamp!: number; + + @Column() public makerAddress!: string; + @Column() public takerAddress!: string; + @Column() public feeRecipientAddress!: string; + @Column() public senderAddress!: string; + @Column() public makerAssetAmount!: string; + @Column() public takerAssetAmount!: string; + @Column() public makerFee!: string; + @Column() public takerFee!: string; + @Column() public expirationTimeSeconds!: string; + @Column() public salt!: string; + @Column() public signature!: string; + + @Column() public rawMakerAssetData!: string; + @Column() public makerAssetType!: AssetType; + @Column() public makerAssetProxyId!: string; + @Column() public makerTokenAddress!: string; + @Column({ nullable: true, type: String }) + public makerTokenId!: string | null; + @Column() public rawTakerAssetData!: string; + @Column() public takerAssetType!: AssetType; + @Column() public takerAssetProxyId!: string; + @Column() public takerTokenAddress!: string; + @Column({ nullable: true, type: String }) + public takerTokenId!: string | null; + + // TODO(albrow): Make this optional? + @Column() public metaDataJson!: string; +} diff --git a/packages/pipeline/src/ormconfig.ts b/packages/pipeline/src/ormconfig.ts index eaafeb7d5..39b496ace 100644 --- a/packages/pipeline/src/ormconfig.ts +++ b/packages/pipeline/src/ormconfig.ts @@ -1,11 +1,31 @@ import { ConnectionOptions } from 'typeorm'; +import { + Block, + ExchangeCancelEvent, + ExchangeCancelUpToEvent, + ExchangeFillEvent, + Relayer, + SraOrder, + Transaction, +} from './entities'; + +const entities = [ + Block, + ExchangeCancelEvent, + ExchangeCancelUpToEvent, + ExchangeFillEvent, + Relayer, + SraOrder, + Transaction, +]; + export const testConfig: ConnectionOptions = { type: 'sqlite', database: 'database.sqlite', synchronize: true, logging: false, - entities: ['./lib/src/entities/**/*.js'], + entities, migrations: ['./lib/src/migrations/**/*.js'], cli: { entitiesDir: 'lib/src/entities', @@ -18,7 +38,7 @@ export const deployConfig: ConnectionOptions = { url: process.env.ZEROEX_DATA_PIPELINE_DB_URL, synchronize: true, logging: false, - entities: ['./lib/src/entities/**/*.js'], + entities, migrations: ['./lib/src/migrations/**/*.js'], cli: { entitiesDir: 'lib/src/entities', diff --git a/packages/pipeline/src/parsers/events/index.ts b/packages/pipeline/src/parsers/events/index.ts index abfb7ddb6..7211eed76 100644 --- a/packages/pipeline/src/parsers/events/index.ts +++ b/packages/pipeline/src/parsers/events/index.ts @@ -9,9 +9,7 @@ import { AssetProxyId, ERC721AssetData } from '@0x/types'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as R from 'ramda'; -import { ExchangeCancelEvent } from '../../entities/ExchangeCancelEvent'; -import { ExchangeCancelUpToEvent } from '../../entities/ExchangeCancelUpToEvent'; -import { ExchangeFillEvent } from '../../entities/ExchangeFillEvent'; +import { ExchangeCancelEvent, ExchangeCancelUpToEvent, ExchangeFillEvent } from '../../entities'; import { bigNumbertoStringOrNull } from '../../utils'; export type ExchangeEventEntity = ExchangeFillEvent | ExchangeCancelEvent | ExchangeCancelUpToEvent; diff --git a/packages/pipeline/src/parsers/relayer_registry/index.ts b/packages/pipeline/src/parsers/relayer_registry/index.ts index 50fd12443..a61f4e62a 100644 --- a/packages/pipeline/src/parsers/relayer_registry/index.ts +++ b/packages/pipeline/src/parsers/relayer_registry/index.ts @@ -1,7 +1,7 @@ import * as R from 'ramda'; import { RelayerResponse, RelayerResponseNetwork } from '../../data_sources/relayer-registry'; -import { Relayer } from '../../entities/Relayer'; +import { Relayer } from '../../entities'; export function parseRelayers(rawResp: Map): Relayer[] { const parsedAsObject = R.mapObjIndexed(parseRelayer, rawResp); diff --git a/packages/pipeline/src/parsers/sra_orders/index.ts b/packages/pipeline/src/parsers/sra_orders/index.ts index 39c222afd..5cd19b08a 100644 --- a/packages/pipeline/src/parsers/sra_orders/index.ts +++ b/packages/pipeline/src/parsers/sra_orders/index.ts @@ -3,7 +3,7 @@ import { assetDataUtils, orderHashUtils } from '@0x/order-utils'; import { AssetProxyId, ERC721AssetData } from '@0x/types'; import * as R from 'ramda'; -import { SraOrder } from '../../entities/SraOrder'; +import { SraOrder } from '../../entities'; import { bigNumbertoStringOrNull } from '../../utils'; export function parseSraOrders(rawOrdersResponse: OrdersResponse): SraOrder[] { diff --git a/packages/pipeline/src/parsers/web3/index.ts b/packages/pipeline/src/parsers/web3/index.ts index c6647c966..11571278b 100644 --- a/packages/pipeline/src/parsers/web3/index.ts +++ b/packages/pipeline/src/parsers/web3/index.ts @@ -1,7 +1,6 @@ import { BlockWithoutTransactionData, Transaction as EthTransaction } from 'ethereum-types'; -import { Block } from '../../entities/Block'; -import { Transaction } from '../../entities/Transaction'; +import { Block, Transaction } from '../../entities'; export function parseBlock(rawBlock: BlockWithoutTransactionData): Block { if (rawBlock.hash == null) { diff --git a/packages/pipeline/src/scripts/merge_v2_events.ts b/packages/pipeline/src/scripts/merge_v2_events.ts index 227ece121..99a76aa61 100644 --- a/packages/pipeline/src/scripts/merge_v2_events.ts +++ b/packages/pipeline/src/scripts/merge_v2_events.ts @@ -3,7 +3,7 @@ import 'reflect-metadata'; import { Connection, createConnection } from 'typeorm'; import { ExchangeEventsSource } from '../data_sources/contract-wrappers/exchange_events'; -import { ExchangeFillEvent } from '../entities/ExchangeFillEvent'; +import { ExchangeFillEvent } from '../entities'; import { deployConfig } from '../ormconfig'; import { parseExchangeEvents } from '../parsers/events'; diff --git a/packages/pipeline/src/scripts/pull_missing_events.ts b/packages/pipeline/src/scripts/pull_missing_events.ts index 1f71722a3..a108f012f 100644 --- a/packages/pipeline/src/scripts/pull_missing_events.ts +++ b/packages/pipeline/src/scripts/pull_missing_events.ts @@ -5,7 +5,7 @@ import 'reflect-metadata'; import { Connection, createConnection, Repository } from 'typeorm'; import { ExchangeEventsSource } from '../data_sources/contract-wrappers/exchange_events'; -import { ExchangeFillEvent } from '../entities/ExchangeFillEvent'; +import { ExchangeFillEvent } from '../entities'; import { deployConfig } from '../ormconfig'; import { parseExchangeEvents } from '../parsers/events'; diff --git a/packages/pipeline/src/scripts/update_relayer_info.ts b/packages/pipeline/src/scripts/update_relayer_info.ts index 05e045ff4..f54e16b6c 100644 --- a/packages/pipeline/src/scripts/update_relayer_info.ts +++ b/packages/pipeline/src/scripts/update_relayer_info.ts @@ -2,7 +2,7 @@ import 'reflect-metadata'; import { Connection, createConnection } from 'typeorm'; import { RelayerRegistrySource } from '../data_sources/relayer-registry'; -import { Relayer } from '../entities/Relayer'; +import { Relayer } from '../entities'; import { deployConfig } from '../ormconfig'; import { parseRelayers } from '../parsers/relayer_registry'; diff --git a/packages/pipeline/test/parsers/events/index_test.ts b/packages/pipeline/test/parsers/events/index_test.ts index 451988f8e..fdd07f246 100644 --- a/packages/pipeline/test/parsers/events/index_test.ts +++ b/packages/pipeline/test/parsers/events/index_test.ts @@ -4,7 +4,7 @@ import * as chai from 'chai'; import { LogWithDecodedArgs } from 'ethereum-types'; import 'mocha'; -import { ExchangeFillEvent } from '../../../src/entities/ExchangeFillEvent'; +import { ExchangeFillEvent } from '../../../src/entities'; import { _convertToEntity } from '../../../src/parsers/events'; import { chaiSetup } from '../../utils/chai_setup'; diff --git a/packages/pipeline/test/parsers/sra_orders/index_test.ts b/packages/pipeline/test/parsers/sra_orders/index_test.ts index eb181ece5..fee32a0a7 100644 --- a/packages/pipeline/test/parsers/sra_orders/index_test.ts +++ b/packages/pipeline/test/parsers/sra_orders/index_test.ts @@ -3,7 +3,7 @@ import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import 'mocha'; -import { SraOrder } from '../../../src/entities/SraOrder'; +import { SraOrder } from '../../../src/entities'; import { _convertToEntity } from '../../../src/parsers/sra_orders'; import { chaiSetup } from '../../utils/chai_setup'; -- cgit v1.2.3