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