From 2e06ebfec6c2f2020398da1596fcf08feca5daa2 Mon Sep 17 00:00:00 2001 From: Mykola Date: Sat, 10 Mar 2018 19:40:11 -0800 Subject: [PATCH] Don not save to = null for contract creation transaction Fixes https://github.com/TrustWallet/trust-ray/issues/95 --- src/common/TransactionParser.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/common/TransactionParser.ts b/src/common/TransactionParser.ts index 7a0952bd..19ef440e 100644 --- a/src/common/TransactionParser.ts +++ b/src/common/TransactionParser.ts @@ -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); @@ -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) ); @@ -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), @@ -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) => {