From bb440b683a7a4d966694de2b897f51f22dadb31c Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 23 Oct 2018 16:03:52 -0700 Subject: Implement support for getting and parsing blocks and transactions --- packages/pipeline/src/parsers/web3/index.ts | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 packages/pipeline/src/parsers/web3/index.ts (limited to 'packages/pipeline/src/parsers/web3/index.ts') diff --git a/packages/pipeline/src/parsers/web3/index.ts b/packages/pipeline/src/parsers/web3/index.ts new file mode 100644 index 000000000..c6647c966 --- /dev/null +++ b/packages/pipeline/src/parsers/web3/index.ts @@ -0,0 +1,39 @@ +import { BlockWithoutTransactionData, Transaction as EthTransaction } from 'ethereum-types'; + +import { Block } from '../../entities/Block'; +import { Transaction } from '../../entities/Transaction'; + +export function parseBlock(rawBlock: BlockWithoutTransactionData): Block { + if (rawBlock.hash == null) { + throw new Error('Tried to parse raw block but hash was null'); + } + if (rawBlock.number == null) { + throw new Error('Tried to parse raw block but number was null'); + } + + const block = new Block(); + block.hash = rawBlock.hash; + block.number = rawBlock.number; + block.unixTimestampSeconds = rawBlock.timestamp; + return block; +} + +export function parseTransaction(rawTransaction: EthTransaction): Transaction { + if (rawTransaction.blockHash == null) { + throw new Error('Tried to parse raw transaction but blockHash was null'); + } + if (rawTransaction.blockNumber == null) { + throw new Error('Tried to parse raw transaction but blockNumber was null'); + } + + const tx = new Transaction(); + tx.transactionHash = rawTransaction.hash; + tx.blockHash = rawTransaction.blockHash; + tx.blockNumber = rawTransaction.blockNumber; + + tx.gasUsed = rawTransaction.gas; + // TODO(albrow) figure out bignum solution. + tx.gasPrice = rawTransaction.gasPrice.toNumber(); + + return tx; +} -- cgit From ccad046eb649a60fdf7319a075fa41490d593ae8 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Thu, 8 Nov 2018 10:15:09 -0800 Subject: Reorganize entities. Make scripts work from any directory. --- packages/pipeline/src/parsers/web3/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'packages/pipeline/src/parsers/web3/index.ts') diff --git a/packages/pipeline/src/parsers/web3/index.ts b/packages/pipeline/src/parsers/web3/index.ts index c6647c966..11571278b 100644 --- a/packages/pipeline/src/parsers/web3/index.ts +++ b/packages/pipeline/src/parsers/web3/index.ts @@ -1,7 +1,6 @@ import { BlockWithoutTransactionData, Transaction as EthTransaction } from 'ethereum-types'; -import { Block } from '../../entities/Block'; -import { Transaction } from '../../entities/Transaction'; +import { Block, Transaction } from '../../entities'; export function parseBlock(rawBlock: BlockWithoutTransactionData): Block { if (rawBlock.hash == null) { -- cgit From 688d277b30b287f66f0dbd49f2a23cab8b256219 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 12 Nov 2018 17:36:33 -0800 Subject: Configure linter with --format stylish and fix linter errors --- packages/pipeline/src/parsers/web3/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'packages/pipeline/src/parsers/web3/index.ts') diff --git a/packages/pipeline/src/parsers/web3/index.ts b/packages/pipeline/src/parsers/web3/index.ts index 11571278b..2ead4c0e4 100644 --- a/packages/pipeline/src/parsers/web3/index.ts +++ b/packages/pipeline/src/parsers/web3/index.ts @@ -2,6 +2,10 @@ import { BlockWithoutTransactionData, Transaction as EthTransaction } from 'ethe import { Block, Transaction } from '../../entities'; +/** + * Parses a raw block and returns a Block entity. + * @param rawBlock a raw block (e.g. returned from web3-wrapper). + */ export function parseBlock(rawBlock: BlockWithoutTransactionData): Block { if (rawBlock.hash == null) { throw new Error('Tried to parse raw block but hash was null'); @@ -17,6 +21,10 @@ export function parseBlock(rawBlock: BlockWithoutTransactionData): Block { return block; } +/** + * Parses a raw transaction and returns a Transaction entity. + * @param rawBlock a raw transaction (e.g. returned from web3-wrapper). + */ export function parseTransaction(rawTransaction: EthTransaction): Transaction { if (rawTransaction.blockHash == null) { throw new Error('Tried to parse raw transaction but blockHash was null'); -- cgit From 9986717671fe8e14c2168f7479bdaffe406bedc0 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 19 Nov 2018 18:38:11 -0800 Subject: Add script for pulling missing block data --- packages/pipeline/src/parsers/web3/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'packages/pipeline/src/parsers/web3/index.ts') diff --git a/packages/pipeline/src/parsers/web3/index.ts b/packages/pipeline/src/parsers/web3/index.ts index 2ead4c0e4..9b5b3b55d 100644 --- a/packages/pipeline/src/parsers/web3/index.ts +++ b/packages/pipeline/src/parsers/web3/index.ts @@ -2,6 +2,8 @@ import { BlockWithoutTransactionData, Transaction as EthTransaction } from 'ethe import { Block, Transaction } from '../../entities'; +const MILLISECONDS_PER_SECOND = 1000; + /** * Parses a raw block and returns a Block entity. * @param rawBlock a raw block (e.g. returned from web3-wrapper). @@ -17,7 +19,8 @@ export function parseBlock(rawBlock: BlockWithoutTransactionData): Block { const block = new Block(); block.hash = rawBlock.hash; block.number = rawBlock.number; - block.unixTimestampSeconds = rawBlock.timestamp; + // Block timestamps are in seconds, but we use milliseconds everywhere else. + block.timestamp = rawBlock.timestamp * MILLISECONDS_PER_SECOND; return block; } -- cgit From 00f86ca0f7871639d2b0be496f6f8c5e0d8d7ffe Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 4 Dec 2018 20:04:08 -0800 Subject: Address PR feedback --- packages/pipeline/src/parsers/web3/index.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/pipeline/src/parsers/web3/index.ts') diff --git a/packages/pipeline/src/parsers/web3/index.ts b/packages/pipeline/src/parsers/web3/index.ts index 9b5b3b55d..86f924151 100644 --- a/packages/pipeline/src/parsers/web3/index.ts +++ b/packages/pipeline/src/parsers/web3/index.ts @@ -42,7 +42,6 @@ export function parseTransaction(rawTransaction: EthTransaction): Transaction { tx.blockNumber = rawTransaction.blockNumber; tx.gasUsed = rawTransaction.gas; - // TODO(albrow) figure out bignum solution. tx.gasPrice = rawTransaction.gasPrice.toNumber(); return tx; -- cgit From e0348f9c044b4909260e4864398b4f50232da620 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 4 Dec 2018 20:20:49 -0800 Subject: Change type of transactions.gas_used and gas_price to BigNumber/numeric --- packages/pipeline/src/parsers/web3/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages/pipeline/src/parsers/web3/index.ts') diff --git a/packages/pipeline/src/parsers/web3/index.ts b/packages/pipeline/src/parsers/web3/index.ts index 86f924151..f986efc59 100644 --- a/packages/pipeline/src/parsers/web3/index.ts +++ b/packages/pipeline/src/parsers/web3/index.ts @@ -1,3 +1,4 @@ +import { BigNumber } from '@0x/utils'; import { BlockWithoutTransactionData, Transaction as EthTransaction } from 'ethereum-types'; import { Block, Transaction } from '../../entities'; @@ -41,8 +42,8 @@ export function parseTransaction(rawTransaction: EthTransaction): Transaction { tx.blockHash = rawTransaction.blockHash; tx.blockNumber = rawTransaction.blockNumber; - tx.gasUsed = rawTransaction.gas; - tx.gasPrice = rawTransaction.gasPrice.toNumber(); + tx.gasUsed = new BigNumber(rawTransaction.gas); + tx.gasPrice = rawTransaction.gasPrice; return tx; } -- cgit