From f6ebdd1a3f7a387d099aae3c81b81c38c16c7caa Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 24 Oct 2018 18:34:20 -0700 Subject: Implement fetching and parsing relayer info --- packages/pipeline/package.json | 1 + packages/pipeline/src/entities/Relayer.ts | 22 ++++++++++++++++++++++ packages/pipeline/src/entities/relayer.ts | 21 +++++++++++---------- packages/pipeline/src/index.ts | 29 +++++++++++++++++++++++------ 4 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 packages/pipeline/src/entities/Relayer.ts (limited to 'packages') diff --git a/packages/pipeline/package.json b/packages/pipeline/package.json index abd8f28fd..5b8d7a33e 100644 --- a/packages/pipeline/package.json +++ b/packages/pipeline/package.json @@ -30,6 +30,7 @@ "@0x/tslint-config": "^1.0.9", "@types/axios": "^0.14.0", "@types/ramda": "^0.25.38", + "@types/axios": "^0.14.0", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", "chai-bignumber": "^2.0.2", diff --git a/packages/pipeline/src/entities/Relayer.ts b/packages/pipeline/src/entities/Relayer.ts new file mode 100644 index 000000000..ebdcbf345 --- /dev/null +++ b/packages/pipeline/src/entities/Relayer.ts @@ -0,0 +1,22 @@ +import { Column, Entity, PrimaryColumn } from 'typeorm'; + +@Entity() +export class Relayer { + @PrimaryColumn() public name!: string; + + @Column() public url!: string; + @Column({ nullable: true, type: String }) + public sraHttpEndpoint!: string | null; + @Column({ nullable: true, type: String }) + public sraWsEndpoint!: string | null; + @Column({ nullable: true, type: String }) + public appUrl!: string | null; + + // TODO(albrow): Add exchange contract or protocol version? + // TODO(albrow): Add network ids for addresses? + + @Column({ type: 'varchar', array: true }) + public feeRecipientAddresses!: string[]; + @Column({ type: 'varchar', array: true }) + public takerAddresses!: string[]; +} diff --git a/packages/pipeline/src/entities/relayer.ts b/packages/pipeline/src/entities/relayer.ts index 5af8578b4..ebdcbf345 100644 --- a/packages/pipeline/src/entities/relayer.ts +++ b/packages/pipeline/src/entities/relayer.ts @@ -1,21 +1,22 @@ import { Column, Entity, PrimaryColumn } from 'typeorm'; -@Entity({ name: 'relayers', schema: 'raw' }) +@Entity() export class Relayer { - @PrimaryColumn() public uuid!: string; + @PrimaryColumn() public name!: string; - @Column() public name!: string; - @Column({ name: 'homepage_url', type: 'varchar' }) - public homepageUrl!: string; - @Column({ name: 'sra_http_endpoint', type: 'varchar', nullable: true }) + @Column() public url!: string; + @Column({ nullable: true, type: String }) public sraHttpEndpoint!: string | null; - @Column({ name: 'sra_ws_endpoint', type: 'varchar', nullable: true }) + @Column({ nullable: true, type: String }) public sraWsEndpoint!: string | null; - @Column({ name: 'app_url', type: 'varchar', nullable: true }) + @Column({ nullable: true, type: String }) public appUrl!: string | null; - @Column({ name: 'fee_recipient_addresses', type: 'varchar', array: true }) + // TODO(albrow): Add exchange contract or protocol version? + // TODO(albrow): Add network ids for addresses? + + @Column({ type: 'varchar', array: true }) public feeRecipientAddresses!: string[]; - @Column({ name: 'taker_addresses', type: 'varchar', array: true }) + @Column({ type: 'varchar', array: true }) public takerAddresses!: string[]; } diff --git a/packages/pipeline/src/index.ts b/packages/pipeline/src/index.ts index ad0e4c68f..9483eb257 100644 --- a/packages/pipeline/src/index.ts +++ b/packages/pipeline/src/index.ts @@ -4,27 +4,31 @@ import 'reflect-metadata'; import { Connection, createConnection } from 'typeorm'; import { ExchangeEventsSource } from './data_sources/contract-wrappers/exchange_events'; +import { RelayerRegistrySource } from './data_sources/relayer-registry'; import { Web3Source } from './data_sources/web3'; import { Block } from './entities/Block'; import { ExchangeFillEvent } from './entities/ExchangeFillEvent'; +import { Relayer } from './entities/Relayer'; import { Transaction } from './entities/Transaction'; -import { testConfig } from './ormconfig'; +import { deployConfig } from './ormconfig'; import { parseExchangeEvents } from './parsers/events'; +import { parseRelayers } from './parsers/relayer_registry'; import { parseBlock, parseTransaction } from './parsers/web3'; const EXCHANGE_START_BLOCK = 6271590; // Block number when the Exchange contract was deployed to mainnet. +const RELAYER_REGISTRY_URL = 'https://raw.githubusercontent.com/0xProject/0x-relayer-registry/master/relayers.json'; let connection: Connection; (async () => { - connection = await createConnection(testConfig); + connection = await createConnection(deployConfig); const provider = web3Factory.getRpcProvider({ rpcUrl: 'https://mainnet.infura.io', }); - await getExchangeEventsAsync(provider); - await getBlockAsync(provider); - await getTransactionAsync(provider); - console.log('Exiting process'); + // await getExchangeEventsAsync(provider); + // await getBlockAsync(provider); + // await getTransactionAsync(provider); + await getRelayers(RELAYER_REGISTRY_URL); process.exit(0); })(); @@ -66,3 +70,16 @@ async function getTransactionAsync(provider: Web3ProviderEngine): Promise await txsRepository.save(tx); console.log('Done saving tx.'); } + +async function getRelayers(url: string): Promise { + console.log('Getting relayer info...'); + const relayerRepository = connection.getRepository(Relayer); + const relayerSource = new RelayerRegistrySource(RELAYER_REGISTRY_URL); + const relayersResp = await relayerSource.getRelayerInfoAsync(); + const relayers = parseRelayers(relayersResp); + console.log('Saving relayer info...'); + // for (const relayer of relayers) { + await relayerRepository.save(relayers); + // } + console.log('Done saving relayers.'); +} -- cgit v1.2.3