Use multi-primary keys for event and filter null logIndexes
This commit is contained in:
@@ -2,7 +2,7 @@ import { ExchangeCancelEventArgs, ExchangeEventArgs, ExchangeFillEventArgs } fro
|
|||||||
import { assetDataUtils } from '@0xproject/order-utils';
|
import { assetDataUtils } from '@0xproject/order-utils';
|
||||||
import { AssetProxyId, ERC721AssetData } from '@0xproject/types';
|
import { AssetProxyId, ERC721AssetData } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { LogWithDecodedArgs } from 'ethereum-types';
|
import { LogEntry, LogWithDecodedArgs } from 'ethereum-types';
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
|
|
||||||
import { artifacts } from '../../artifacts';
|
import { artifacts } from '../../artifacts';
|
||||||
@@ -22,10 +22,19 @@ export function parseExchangeEvents(rawEventsResponse: EventsResponse): Exchange
|
|||||||
eventResponse => decodeLogEntry<ExchangeEventArgs>(exchangeContractAbi, eventResponse),
|
eventResponse => decodeLogEntry<ExchangeEventArgs>(exchangeContractAbi, eventResponse),
|
||||||
logEntries,
|
logEntries,
|
||||||
);
|
);
|
||||||
const filteredLogEntries = R.filter(logEntry => R.contains(logEntry.event, ['Fill', 'Cancel']), decodedLogEntries);
|
const filteredLogEntries = R.filter(shouldIncludeLogEntry, decodedLogEntries);
|
||||||
return R.map(_convertToEntity, filteredLogEntries);
|
return R.map(_convertToEntity, filteredLogEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shouldIncludeLogEntry(logEntry: LogWithDecodedArgs<ExchangeEventArgs>): boolean {
|
||||||
|
if (!R.contains(logEntry.event, ['Fill', 'Cancel'])) {
|
||||||
|
return false;
|
||||||
|
} else if (logEntry.logIndex == null || isNaN(logEntry.logIndex)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export function _convertToEntity(eventLog: LogWithDecodedArgs<ExchangeEventArgs>): ExchangeEventEntity {
|
export function _convertToEntity(eventLog: LogWithDecodedArgs<ExchangeEventArgs>): ExchangeEventEntity {
|
||||||
switch (eventLog.event) {
|
switch (eventLog.event) {
|
||||||
case 'Fill':
|
case 'Fill':
|
||||||
|
@@ -5,10 +5,10 @@ import { AssetType } from '../types';
|
|||||||
@Entity()
|
@Entity()
|
||||||
export class ExchangeCancelEvent extends BaseEntity {
|
export class ExchangeCancelEvent extends BaseEntity {
|
||||||
@PrimaryColumn() public logIndex!: number;
|
@PrimaryColumn() public logIndex!: number;
|
||||||
|
@PrimaryColumn() public blockNumber!: number;
|
||||||
|
|
||||||
@Column() public address!: string;
|
@Column() public address!: string;
|
||||||
@Column() public rawData!: string;
|
@Column() public rawData!: string;
|
||||||
@Column() public blockNumber!: number;
|
|
||||||
|
|
||||||
@Column() public makerAddress!: string;
|
@Column() public makerAddress!: string;
|
||||||
@Column({ nullable: true, type: String })
|
@Column({ nullable: true, type: String })
|
||||||
|
@@ -5,10 +5,10 @@ import { AssetType } from '../types';
|
|||||||
@Entity()
|
@Entity()
|
||||||
export class ExchangeFillEvent extends BaseEntity {
|
export class ExchangeFillEvent extends BaseEntity {
|
||||||
@PrimaryColumn() public logIndex!: number;
|
@PrimaryColumn() public logIndex!: number;
|
||||||
|
@PrimaryColumn() public blockNumber!: number;
|
||||||
|
|
||||||
@Column() public address!: string;
|
@Column() public address!: string;
|
||||||
@Column() public rawData!: string;
|
@Column() public rawData!: string;
|
||||||
@Column() public blockNumber!: number;
|
|
||||||
|
|
||||||
@Column() public makerAddress!: string;
|
@Column() public makerAddress!: string;
|
||||||
@Column() public takerAddress!: string;
|
@Column() public takerAddress!: string;
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
|
import * as R from 'ramda';
|
||||||
import 'reflect-metadata';
|
import 'reflect-metadata';
|
||||||
import { createConnection } from 'typeorm';
|
import { createConnection } from 'typeorm';
|
||||||
|
|
||||||
import { Etherscan } from './data_sources/etherscan';
|
import { Etherscan } from './data_sources/etherscan';
|
||||||
|
import { parseExchangeEvents } from './data_types/events/exchange_events';
|
||||||
import { ExchangeCancelEvent } from './entities/ExchangeCancelEvent';
|
import { ExchangeCancelEvent } from './entities/ExchangeCancelEvent';
|
||||||
import { ExchangeFillEvent } from './entities/ExchangeFillEvent';
|
import { ExchangeFillEvent } from './entities/ExchangeFillEvent';
|
||||||
import { config } from './ormconfig';
|
import { config } from './ormconfig';
|
||||||
|
|
||||||
import { parseExchangeEvents } from './data_types/events/exchange_events';
|
|
||||||
|
|
||||||
const etherscan = new Etherscan(process.env.ETHERSCAN_API_KEY as string);
|
const etherscan = new Etherscan(process.env.ETHERSCAN_API_KEY as string);
|
||||||
const EXCHANGE_ADDRESS = '0x4f833a24e1f95d70f028921e27040ca56e09ab0b';
|
const EXCHANGE_ADDRESS = '0x4f833a24e1f95d70f028921e27040ca56e09ab0b';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user