Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Don't lookup transactions if no log events #82

Merged
merged 1 commit into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libraries/shared/transactions/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func NewTransactionsSyncer(db *postgres.DB, blockChain core.BlockChain) Transact

func (syncer TransactionsSyncer) SyncTransactions(headerID int64, logs []types.Log) error {
transactionHashes := getUniqueTransactionHashes(logs)
if len(transactionHashes) < 1 {
return nil
}
transactions, transactionErr := syncer.BlockChain.GetTransactions(transactionHashes)
if transactionErr != nil {
return transactionErr
Expand Down
15 changes: 11 additions & 4 deletions libraries/shared/transactions/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ var _ = Describe("Transaction syncer", func() {
})

It("fetches transactions for logs", func() {
err := syncer.SyncTransactions(0, []types.Log{})
err := syncer.SyncTransactions(0, []types.Log{{TxHash: fakes.FakeHash}})

Expect(err).NotTo(HaveOccurred())
Expect(blockChain.GetTransactionsCalled).To(BeTrue())
})

It("does not fetch transactions if no logs", func() {
err := syncer.SyncTransactions(0, []types.Log{})

Expect(err).NotTo(HaveOccurred())
Expect(blockChain.GetTransactionsCalled).To(BeFalse())
})

It("only fetches transactions with unique hashes", func() {
err := syncer.SyncTransactions(0, []types.Log{{
TxHash: fakes.FakeHash,
Expand All @@ -44,7 +51,7 @@ var _ = Describe("Transaction syncer", func() {
It("returns error if fetching transactions fails", func() {
blockChain.GetTransactionsError = fakes.FakeError

err := syncer.SyncTransactions(0, []types.Log{})
err := syncer.SyncTransactions(0, []types.Log{{TxHash: fakes.FakeHash}})

Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(fakes.FakeError))
Expand All @@ -55,7 +62,7 @@ var _ = Describe("Transaction syncer", func() {
mockHeaderRepository := fakes.NewMockHeaderRepository()
syncer.Repository = mockHeaderRepository

err := syncer.SyncTransactions(0, []types.Log{})
err := syncer.SyncTransactions(0, []types.Log{{TxHash: fakes.FakeHash}})

Expect(err).NotTo(HaveOccurred())
Expect(mockHeaderRepository.CreateTransactionsCalled).To(BeTrue())
Expand All @@ -67,7 +74,7 @@ var _ = Describe("Transaction syncer", func() {
mockHeaderRepository.CreateTransactionsError = fakes.FakeError
syncer.Repository = mockHeaderRepository

err := syncer.SyncTransactions(0, []types.Log{})
err := syncer.SyncTransactions(0, []types.Log{{TxHash: fakes.FakeHash}})

Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(fakes.FakeError))
Expand Down
2 changes: 0 additions & 2 deletions pkg/geth/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package geth

import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum"
"math/big"
"strconv"
Expand Down Expand Up @@ -122,7 +121,6 @@ func (blockChain *BlockChain) GetTransactions(transactionHashes []common.Hash) (

rpcErr := blockChain.rpcClient.BatchCall(batch)
if rpcErr != nil {
fmt.Println("rpc err")
return []core.TransactionModel{}, rpcErr
}

Expand Down