Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Commit

Permalink
Don not save to = null for contract creation transaction
Browse files Browse the repository at this point in the history
Fixes #95
  • Loading branch information
Mykola committed Mar 11, 2018
1 parent 82738e7 commit 2e06ebf
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/common/TransactionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { TransactionOperation } from "../models/TransactionOperationModel";
import { removeScientificNotationFromNumbString } from "./Utils";
import { Config } from "./Config";
import { Promise } from "bluebird";
import { IDecodedLog, IContract, ITransaction } from "./CommonInterfaces";

import { IDecodedLog, IContract, ITransaction, IBlock, IExtractedTransaction, ISavedTransaction } from "./CommonInterfaces";
const erc20abi = require("./contracts/Erc20Abi");
const erc20ABIDecoder = require("abi-decoder");
erc20ABIDecoder.addABI(erc20abi);
Expand All @@ -23,14 +22,14 @@ export class TransactionParser {
return new Transaction(this.extractTransactionData(block, tx));
});
});
const txIDs = extractedTransactions.map((tx: ITransaction) => tx._id);
const txIDs = extractedTransactions.map((tx: IExtractedTransaction) => tx._id);

return this.fetchTransactionReceipts(txIDs).then((receipts: any) => {
return this.mergeTransactionsAndReceipts(extractedTransactions, receipts);
}).then((transactions: any) => {
const bulkTransactions = Transaction.collection.initializeUnorderedBulkOp();

transactions.forEach((transaction: ITransaction) =>
transactions.forEach((transaction: IExtractedTransaction) =>
bulkTransactions.find({_id: transaction._id}).upsert().replaceOne(transaction)
);

Expand Down Expand Up @@ -68,9 +67,10 @@ export class TransactionParser {
return newTransaction;
}

private extractTransactionData(block: any, transaction: any) {
extractTransactionData(block: IBlock, transaction: ITransaction) {
const from = String(transaction.from).toLowerCase();
const to = String(transaction.to).toLowerCase();
const to: string = transaction.to === null ? "" : String(transaction.to).toLowerCase();
const addresses: string[] = to ? [from, to] : [from];

return {
_id: String(transaction.hash),
Expand All @@ -84,13 +84,13 @@ export class TransactionParser {
gasPrice: String(transaction.gasPrice),
gasUsed: String(0),
input: String(transaction.input),
addresses: [from, to]
addresses
};
}

// ========================== OPERATION PARSING ========================== //

public parseTransactionOperations(transactions: ITransaction[], contracts: IContract[]) {
public parseTransactionOperations(transactions: ISavedTransaction[], contracts: IContract[]) {
if (!transactions || !contracts) return Promise.resolve();

return Promise.map(transactions, (transaction) => {
Expand Down

0 comments on commit 2e06ebf

Please sign in to comment.