diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-09-20 08:30:34 +0800 |
---|---|---|
committer | Alex Browne <stephenalexbrowne@gmail.com> | 2018-12-05 06:24:03 +0800 |
commit | 4e6919a6e58d76766098262664c78f92d888337d (patch) | |
tree | 649bc1c711a498c6718f36994283f65c3e56aba1 /packages/pipeline/src/index.ts | |
parent | d71fa6535987a0f13900f8e31dbb51772c12fc4f (diff) | |
download | dexon-sol-tools-4e6919a6e58d76766098262664c78f92d888337d.tar dexon-sol-tools-4e6919a6e58d76766098262664c78f92d888337d.tar.gz dexon-sol-tools-4e6919a6e58d76766098262664c78f92d888337d.tar.bz2 dexon-sol-tools-4e6919a6e58d76766098262664c78f92d888337d.tar.lz dexon-sol-tools-4e6919a6e58d76766098262664c78f92d888337d.tar.xz dexon-sol-tools-4e6919a6e58d76766098262664c78f92d888337d.tar.zst dexon-sol-tools-4e6919a6e58d76766098262664c78f92d888337d.zip |
Add typeorm and begin inserting database records
Diffstat (limited to 'packages/pipeline/src/index.ts')
-rw-r--r-- | packages/pipeline/src/index.ts | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/packages/pipeline/src/index.ts b/packages/pipeline/src/index.ts index eccb24d18..d70ec3e3e 100644 --- a/packages/pipeline/src/index.ts +++ b/packages/pipeline/src/index.ts @@ -1,13 +1,45 @@ -import { Etherscan } from './data-sources/etherscan'; +import { ExchangeFillEventArgs } from '@0xproject/contract-wrappers'; +import { LogWithDecodedArgs } from 'ethereum-types'; +import 'reflect-metadata'; +import { createConnection } from 'typeorm'; import { artifacts } from './artifacts'; +import { Etherscan } from './data-sources/etherscan'; +import { ExchangeFillEvent } from './entities/ExchangeFillEvent'; +import { config } from './ormconfig'; const etherscan = new Etherscan(process.env.ETHERSCAN_API_KEY as string); (async () => { - const events = await etherscan.getContractEventsAsync( + const connection = await createConnection(config); + const repository = connection.getRepository(ExchangeFillEvent); + console.log(`found ${await repository.count()} existing fill events`); + const eventLogs = await etherscan.getContractEventsAsync( '0x4f833a24e1f95d70f028921e27040ca56e09ab0b', artifacts.Exchange.compilerOutput.abi, ); - console.log(events); + for (const eventLog of eventLogs) { + if (eventLog.event !== 'Fill') { + continue; + } + const fillEventLog = eventLog as LogWithDecodedArgs<ExchangeFillEventArgs>; + const exchangeFillEvent = new ExchangeFillEvent(); + exchangeFillEvent.logIndex = fillEventLog.logIndex as number; + exchangeFillEvent.address = fillEventLog.address as string; + exchangeFillEvent.rawData = fillEventLog.data as string; + exchangeFillEvent.blockNumber = fillEventLog.blockNumber as number; + exchangeFillEvent.makerAddress = fillEventLog.args.makerAddress.toString(); + exchangeFillEvent.takerAddress = fillEventLog.args.takerAddress.toString(); + exchangeFillEvent.feeRecepientAddress = fillEventLog.args.feeRecipientAddress; + exchangeFillEvent.senderAddress = fillEventLog.args.senderAddress; + exchangeFillEvent.makerAssetFilledAmount = fillEventLog.args.makerAssetFilledAmount.toString(); + exchangeFillEvent.takerAssetFilledAmount = fillEventLog.args.takerAssetFilledAmount.toString(); + exchangeFillEvent.makerFeePaid = fillEventLog.args.makerFeePaid.toString(); + exchangeFillEvent.takerFeePaid = fillEventLog.args.takerFeePaid.toString(); + exchangeFillEvent.orderHash = fillEventLog.args.orderHash; + exchangeFillEvent.makerAssetData = fillEventLog.args.makerAssetData; + exchangeFillEvent.takerAssetData = fillEventLog.args.takerAssetData; + await repository.save(exchangeFillEvent); + } + console.log(`now ${await repository.count()} total fill events`); })(); |