forked from cerc-io/ipld-eth-server
Merge pull request #82 from vulcanize/fixup-transactions-syncing
Don't lookup transactions if no log events
This commit is contained in:
commit
9c06e9387c
@ -28,6 +28,9 @@ func NewTransactionsSyncer(db *postgres.DB, blockChain core.BlockChain) Transact
|
|||||||
|
|
||||||
func (syncer TransactionsSyncer) SyncTransactions(headerID int64, logs []types.Log) error {
|
func (syncer TransactionsSyncer) SyncTransactions(headerID int64, logs []types.Log) error {
|
||||||
transactionHashes := getUniqueTransactionHashes(logs)
|
transactionHashes := getUniqueTransactionHashes(logs)
|
||||||
|
if len(transactionHashes) < 1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
transactions, transactionErr := syncer.BlockChain.GetTransactions(transactionHashes)
|
transactions, transactionErr := syncer.BlockChain.GetTransactions(transactionHashes)
|
||||||
if transactionErr != nil {
|
if transactionErr != nil {
|
||||||
return transactionErr
|
return transactionErr
|
||||||
|
@ -24,12 +24,19 @@ var _ = Describe("Transaction syncer", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("fetches transactions for logs", 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(err).NotTo(HaveOccurred())
|
||||||
Expect(blockChain.GetTransactionsCalled).To(BeTrue())
|
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() {
|
It("only fetches transactions with unique hashes", func() {
|
||||||
err := syncer.SyncTransactions(0, []types.Log{{
|
err := syncer.SyncTransactions(0, []types.Log{{
|
||||||
TxHash: fakes.FakeHash,
|
TxHash: fakes.FakeHash,
|
||||||
@ -44,7 +51,7 @@ var _ = Describe("Transaction syncer", func() {
|
|||||||
It("returns error if fetching transactions fails", func() {
|
It("returns error if fetching transactions fails", func() {
|
||||||
blockChain.GetTransactionsError = fakes.FakeError
|
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(HaveOccurred())
|
||||||
Expect(err).To(MatchError(fakes.FakeError))
|
Expect(err).To(MatchError(fakes.FakeError))
|
||||||
@ -55,7 +62,7 @@ var _ = Describe("Transaction syncer", func() {
|
|||||||
mockHeaderRepository := fakes.NewMockHeaderRepository()
|
mockHeaderRepository := fakes.NewMockHeaderRepository()
|
||||||
syncer.Repository = mockHeaderRepository
|
syncer.Repository = mockHeaderRepository
|
||||||
|
|
||||||
err := syncer.SyncTransactions(0, []types.Log{})
|
err := syncer.SyncTransactions(0, []types.Log{{TxHash: fakes.FakeHash}})
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(mockHeaderRepository.CreateTransactionsCalled).To(BeTrue())
|
Expect(mockHeaderRepository.CreateTransactionsCalled).To(BeTrue())
|
||||||
@ -67,7 +74,7 @@ var _ = Describe("Transaction syncer", func() {
|
|||||||
mockHeaderRepository.CreateTransactionsError = fakes.FakeError
|
mockHeaderRepository.CreateTransactionsError = fakes.FakeError
|
||||||
syncer.Repository = mockHeaderRepository
|
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(HaveOccurred())
|
||||||
Expect(err).To(MatchError(fakes.FakeError))
|
Expect(err).To(MatchError(fakes.FakeError))
|
||||||
|
@ -18,7 +18,6 @@ package geth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -122,7 +121,6 @@ func (blockChain *BlockChain) GetTransactions(transactionHashes []common.Hash) (
|
|||||||
|
|
||||||
rpcErr := blockChain.rpcClient.BatchCall(batch)
|
rpcErr := blockChain.rpcClient.BatchCall(batch)
|
||||||
if rpcErr != nil {
|
if rpcErr != nil {
|
||||||
fmt.Println("rpc err")
|
|
||||||
return []core.TransactionModel{}, rpcErr
|
return []core.TransactionModel{}, rpcErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user