diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-10-24 07:03:52 +0800 |
---|---|---|
committer | Alex Browne <stephenalexbrowne@gmail.com> | 2018-12-05 06:24:48 +0800 |
commit | bb440b683a7a4d966694de2b897f51f22dadb31c (patch) | |
tree | 216304717c10083d477898576beb1c4658163a7c /packages/pipeline/src/parsers | |
parent | d959b3e23402840661f45a2b5ecd5ca64dcdabf3 (diff) | |
download | dexon-sol-tools-bb440b683a7a4d966694de2b897f51f22dadb31c.tar dexon-sol-tools-bb440b683a7a4d966694de2b897f51f22dadb31c.tar.gz dexon-sol-tools-bb440b683a7a4d966694de2b897f51f22dadb31c.tar.bz2 dexon-sol-tools-bb440b683a7a4d966694de2b897f51f22dadb31c.tar.lz dexon-sol-tools-bb440b683a7a4d966694de2b897f51f22dadb31c.tar.xz dexon-sol-tools-bb440b683a7a4d966694de2b897f51f22dadb31c.tar.zst dexon-sol-tools-bb440b683a7a4d966694de2b897f51f22dadb31c.zip |
Implement support for getting and parsing blocks and transactions
Diffstat (limited to 'packages/pipeline/src/parsers')
-rw-r--r-- | packages/pipeline/src/parsers/web3/index.ts | 39 |
1 files changed, 39 insertions, 0 deletions
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; +} |