diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-10-24 07:03:52 +0800 |
---|---|---|
committer | Fred Carlsen <fred@sjelfull.no> | 2018-12-06 19:04:24 +0800 |
commit | 1402a3dfae1be32a346f8b75a4209950bda00b74 (patch) | |
tree | cdd899665634759da68b51a6d4b57e6a7c47a10e /packages/pipeline/src/parsers/web3/index.ts | |
parent | 64865bc10f88f97c3e406bbc1d39e68ca45380ef (diff) | |
download | dexon-0x-contracts-1402a3dfae1be32a346f8b75a4209950bda00b74.tar.gz dexon-0x-contracts-1402a3dfae1be32a346f8b75a4209950bda00b74.tar.zst dexon-0x-contracts-1402a3dfae1be32a346f8b75a4209950bda00b74.zip |
Implement support for getting and parsing blocks and transactions
Diffstat (limited to 'packages/pipeline/src/parsers/web3/index.ts')
-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; +} |