aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src/parsers/web3
diff options
context:
space:
mode:
Diffstat (limited to 'packages/pipeline/src/parsers/web3')
-rw-r--r--packages/pipeline/src/parsers/web3/index.ts39
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;
+}