From bf1115d4176805d495ff572ac82bf9d4087985cc Mon Sep 17 00:00:00 2001 From: askeluv Date: Fri, 22 Feb 2019 09:45:25 +0800 Subject: [PATCH] Backfills automatically + prettier --- ...50749543417-CreateEtherscanTransactions.ts | 6 +-- .../src/data_sources/etherscan/index.ts | 3 +- .../src/entities/etherscan_transaction.ts | 1 - ...ll_exchange_transactions_from_etherscan.ts | 4 +- .../test/parsers/etherscan/index_test.ts | 42 ++++++++++--------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/pipeline/migrations/1550749543417-CreateEtherscanTransactions.ts b/packages/pipeline/migrations/1550749543417-CreateEtherscanTransactions.ts index b35f3a6e45..4b0dbd7075 100644 --- a/packages/pipeline/migrations/1550749543417-CreateEtherscanTransactions.ts +++ b/packages/pipeline/migrations/1550749543417-CreateEtherscanTransactions.ts @@ -1,10 +1,10 @@ -import { MigrationInterface, QueryRunner, Table } from "typeorm"; +import { MigrationInterface, QueryRunner, Table } from 'typeorm'; const table = new Table({ name: 'raw.etherscan_transactions', columns: [ { name: 'hash', type: 'varchar', isPrimary: true }, - + { name: 'block_number', type: 'numeric', isNullable: false }, { name: 'timestamp', type: 'numeric', isNullable: false }, { name: 'block_hash', type: 'varchar', isNullable: false }, @@ -22,12 +22,10 @@ const table = new Table({ { name: 'cumulative_gas_used', type: 'numeric', isNullable: false }, { name: 'gas_used', type: 'numeric', isNullable: false }, { name: 'confirmations', type: 'numeric', isNullable: false }, - ], }); export class CreateEtherscanTransactions1550749543417 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { await queryRunner.createTable(table); } diff --git a/packages/pipeline/src/data_sources/etherscan/index.ts b/packages/pipeline/src/data_sources/etherscan/index.ts index 96a5266a92..02d381af84 100644 --- a/packages/pipeline/src/data_sources/etherscan/index.ts +++ b/packages/pipeline/src/data_sources/etherscan/index.ts @@ -32,11 +32,10 @@ export interface EtherscanTransactionResponse { // tslint:disable:prefer-function-over-method // ^ Keep consistency with other sources and help logical organization export class EtherscanSource { - public readonly _urlBase: string; constructor(apiKey: string, startBlock: number, endBlock: number) { - this._urlBase = `http://api.etherscan.io/api?module=account&action=txlist&startblock=${startBlock}&endblock=${endBlock}&sort=desc&apikey=${apiKey}&address=`; + this._urlBase = `http://api.etherscan.io/api?module=account&action=txlist&startblock=${startBlock}&endblock=${endBlock}&sort=asc&apikey=${apiKey}&address=`; } /** diff --git a/packages/pipeline/src/entities/etherscan_transaction.ts b/packages/pipeline/src/entities/etherscan_transaction.ts index 3de6f4977d..c84eddc978 100644 --- a/packages/pipeline/src/entities/etherscan_transaction.ts +++ b/packages/pipeline/src/entities/etherscan_transaction.ts @@ -58,5 +58,4 @@ export class EtherscanTransaction { @Column({ name: 'confirmations', type: 'bigint', transformer: bigNumberTransformer }) public confirmations!: BigNumber; - } diff --git a/packages/pipeline/src/scripts/pull_exchange_transactions_from_etherscan.ts b/packages/pipeline/src/scripts/pull_exchange_transactions_from_etherscan.ts index ac1d0eb8fd..6c93e1ae18 100644 --- a/packages/pipeline/src/scripts/pull_exchange_transactions_from_etherscan.ts +++ b/packages/pipeline/src/scripts/pull_exchange_transactions_from_etherscan.ts @@ -42,7 +42,9 @@ let connection: Connection; const rawTransactions = await etherscanSource.getEtherscanTransactionsForAddressAsync(exchangeContractAddress); const transactions = parseEtherscanTransactions(rawTransactions); logUtils.log(`Saving ${transactions.length} records to database`); - await EtherscanTransactionRepository.save(transactions, { chunk: Math.ceil(transactions.length / BATCH_SAVE_SIZE) }); + await EtherscanTransactionRepository.save(transactions, { + chunk: Math.ceil(transactions.length / BATCH_SAVE_SIZE), + }); logUtils.log('Done'); process.exit(0); })().catch(handleError); diff --git a/packages/pipeline/test/parsers/etherscan/index_test.ts b/packages/pipeline/test/parsers/etherscan/index_test.ts index fc118a2c92..bf7aab4e5a 100644 --- a/packages/pipeline/test/parsers/etherscan/index_test.ts +++ b/packages/pipeline/test/parsers/etherscan/index_test.ts @@ -14,26 +14,28 @@ const expect = chai.expect; describe('etherscan_transactions', () => { describe('parseEtherscanTransactions', () => { it('converts etherscanTransactions to EtherscanTransaction entities', () => { - const response: EtherscanTransactionResponse[] = [{ - blockNumber: '6271590', - timeStamp: '1536083185', - hash: '0x4a03044699c2fbd256e21632a6d8fbfc27655ea711157fa8b2b917f0eb954cea', - nonce: '2', - blockHash: '0xee634af4cebd034ed9e5e3dc873a2b0ecc60fe11bef27f7b92542388869f21ee', - transactionIndex: '3', - from: '0x2d7dc2ef7c6f6a2cbc3dba4db97b2ddb40e20713', - to: '', - value: '0', - gas: '7000000', - gasPrice: '20000000000', - isError: '0', - txreceiptStatus: '1', - input: '0x60806040', // shortened - contractAddress: '0x4f833a24e1f95d70f028921e27040ca56e09ab0b', - cumulativeGasUsed: '6068925', - gasUsed: '6005925', - confirmations: '976529', - }]; + const response: EtherscanTransactionResponse[] = [ + { + blockNumber: '6271590', + timeStamp: '1536083185', + hash: '0x4a03044699c2fbd256e21632a6d8fbfc27655ea711157fa8b2b917f0eb954cea', + nonce: '2', + blockHash: '0xee634af4cebd034ed9e5e3dc873a2b0ecc60fe11bef27f7b92542388869f21ee', + transactionIndex: '3', + from: '0x2d7dc2ef7c6f6a2cbc3dba4db97b2ddb40e20713', + to: '', + value: '0', + gas: '7000000', + gasPrice: '20000000000', + isError: '0', + txreceiptStatus: '1', + input: '0x60806040', // shortened + contractAddress: '0x4f833a24e1f95d70f028921e27040ca56e09ab0b', + cumulativeGasUsed: '6068925', + gasUsed: '6005925', + confirmations: '976529', + }, + ]; const _expected: EtherscanTransaction = { blockNumber: new BigNumber('6271590'),