From 7e387646186a1fa759a2104232b922cb6ad615f1 Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman Date: Mon, 5 Aug 2019 10:38:37 -0500 Subject: [PATCH] Rename ReceiptRepository -> FullSyncReceiptRepository --- cmd/coldImport.go | 2 +- .../shared/helpers/test_helpers/database.go | 4 ++-- .../postgres/repositories/address_repository.go | 6 +++--- .../postgres/repositories/block_repository.go | 9 ++------- ...pository.go => full_sync_receipt_repository.go} | 11 +++++------ ...est.go => full_sync_receipt_repository_test.go} | 14 +++++++------- .../postgres/repositories/logs_repository_test.go | 8 ++++---- .../repositories/watched_events_repository_test.go | 8 ++++---- pkg/datastore/repository.go | 6 +++--- pkg/fakes/mock_receipt_repository.go | 4 ++-- pkg/geth/cold_import/importer.go | 4 ++-- 11 files changed, 35 insertions(+), 41 deletions(-) rename pkg/datastore/postgres/repositories/{receipt_repository.go => full_sync_receipt_repository.go} (88%) rename pkg/datastore/postgres/repositories/{receipt_repository_test.go => full_sync_receipt_repository_test.go} (90%) diff --git a/cmd/coldImport.go b/cmd/coldImport.go index 134d47ca..ddd1048b 100644 --- a/cmd/coldImport.go +++ b/cmd/coldImport.go @@ -84,7 +84,7 @@ func coldImport() { // init cold importer deps blockRepository := repositories.NewBlockRepository(&pgDB) - receiptRepository := repositories.ReceiptRepository{DB: &pgDB} + receiptRepository := repositories.FullSyncReceiptRepository{DB: &pgDB} transactionConverter := cold_db.NewColdDbTransactionConverter() blockConverter := vulcCommon.NewBlockConverter(transactionConverter) diff --git a/pkg/contract_watcher/shared/helpers/test_helpers/database.go b/pkg/contract_watcher/shared/helpers/test_helpers/database.go index c274fda1..294a74c6 100644 --- a/pkg/contract_watcher/shared/helpers/test_helpers/database.go +++ b/pkg/contract_watcher/shared/helpers/test_helpers/database.go @@ -137,7 +137,7 @@ func SetupTusdRepo(vulcanizeLogId *int64, wantedEvents, wantedMethods []string) }, core.Node{}) Expect(err).NotTo(HaveOccurred()) - receiptRepository := repositories.ReceiptRepository{DB: db} + receiptRepository := repositories.FullSyncReceiptRepository{DB: db} logRepository := repositories.LogRepository{DB: db} blockRepository := *repositories.NewBlockRepository(db) @@ -183,7 +183,7 @@ func SetupENSRepo(vulcanizeLogId *int64, wantedEvents, wantedMethods []string) ( }, core.Node{}) Expect(err).NotTo(HaveOccurred()) - receiptRepository := repositories.ReceiptRepository{DB: db} + receiptRepository := repositories.FullSyncReceiptRepository{DB: db} logRepository := repositories.LogRepository{DB: db} blockRepository := *repositories.NewBlockRepository(db) diff --git a/pkg/datastore/postgres/repositories/address_repository.go b/pkg/datastore/postgres/repositories/address_repository.go index 1b04681c..da25bda6 100644 --- a/pkg/datastore/postgres/repositories/address_repository.go +++ b/pkg/datastore/postgres/repositories/address_repository.go @@ -23,7 +23,7 @@ import ( type AddressRepository struct{} -func (repo AddressRepository) GetOrCreateAddress(db *postgres.DB, address string) (int, error) { +func (AddressRepository) GetOrCreateAddress(db *postgres.DB, address string) (int, error) { stringAddressToCommonAddress := common.HexToAddress(address) hexAddress := stringAddressToCommonAddress.Hex() @@ -37,7 +37,7 @@ func (repo AddressRepository) GetOrCreateAddress(db *postgres.DB, address string return addressId, getErr } -func (repo AddressRepository) GetOrCreateAddressInTransaction(tx *sqlx.Tx, address string) (int, error) { +func (AddressRepository) GetOrCreateAddressInTransaction(tx *sqlx.Tx, address string) (int, error) { stringAddressToCommonAddress := common.HexToAddress(address) hexAddress := stringAddressToCommonAddress.Hex() @@ -51,7 +51,7 @@ func (repo AddressRepository) GetOrCreateAddressInTransaction(tx *sqlx.Tx, addre return addressId, getErr } -func (repo AddressRepository) GetAddressById(db *postgres.DB, id int) (string, error) { +func (AddressRepository) GetAddressById(db *postgres.DB, id int) (string, error) { var address string getErr := db.Get(&address, `SELECT address FROM public.addresses WHERE id = $1`, id) if getErr != nil { diff --git a/pkg/datastore/postgres/repositories/block_repository.go b/pkg/datastore/postgres/repositories/block_repository.go index db2af9c8..2242efef 100644 --- a/pkg/datastore/postgres/repositories/block_repository.go +++ b/pkg/datastore/postgres/repositories/block_repository.go @@ -234,8 +234,8 @@ func (blockRepository BlockRepository) createTransaction(tx *sqlx.Tx, blockId in return err } if hasReceipt(transaction) { - - receiptId, err := receiptRepository().CreateReceipt(blockId, transaction.Receipt, tx) + receiptRepo := FullSyncReceiptRepository{} + receiptId, err := receiptRepo.CreateFullSyncReceiptInTx(blockId, transaction.Receipt, tx) if err != nil { return err } @@ -249,11 +249,6 @@ func (blockRepository BlockRepository) createTransaction(tx *sqlx.Tx, blockId in return nil } -func receiptRepository() datastore.ReceiptRepository { - //TODO: set db? - return ReceiptRepository{} -} - func hasLogs(transaction core.TransactionModel) bool { return len(transaction.Receipt.Logs) > 0 } diff --git a/pkg/datastore/postgres/repositories/receipt_repository.go b/pkg/datastore/postgres/repositories/full_sync_receipt_repository.go similarity index 88% rename from pkg/datastore/postgres/repositories/receipt_repository.go rename to pkg/datastore/postgres/repositories/full_sync_receipt_repository.go index 59099578..71a345f6 100644 --- a/pkg/datastore/postgres/repositories/receipt_repository.go +++ b/pkg/datastore/postgres/repositories/full_sync_receipt_repository.go @@ -26,17 +26,17 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" ) -type ReceiptRepository struct { +type FullSyncReceiptRepository struct { *postgres.DB } -func (receiptRepository ReceiptRepository) CreateReceiptsAndLogs(blockId int64, receipts []core.Receipt) error { +func (receiptRepository FullSyncReceiptRepository) CreateReceiptsAndLogs(blockId int64, receipts []core.Receipt) error { tx, err := receiptRepository.DB.Beginx() if err != nil { return err } for _, receipt := range receipts { - receiptId, err := receiptRepository.CreateReceipt(blockId, receipt, tx) + receiptId, err := receiptRepository.CreateFullSyncReceiptInTx(blockId, receipt, tx) if err != nil { tx.Rollback() return err @@ -68,8 +68,7 @@ func createLogs(logs []core.Log, receiptId int64, tx *sqlx.Tx) error { return nil } -//TODO: test that creating the address should be in the transaction -func (ReceiptRepository) CreateReceipt(blockId int64, receipt core.Receipt, tx *sqlx.Tx) (int64, error) { +func (FullSyncReceiptRepository) CreateFullSyncReceiptInTx(blockId int64, receipt core.Receipt, tx *sqlx.Tx) (int64, error) { var receiptId int64 addressId, getAddressErr := AddressRepository{}.GetOrCreateAddressInTransaction(tx, receipt.ContractAddress) if getAddressErr != nil { @@ -90,7 +89,7 @@ func (ReceiptRepository) CreateReceipt(blockId int64, receipt core.Receipt, tx * return receiptId, nil } -func (receiptRepository ReceiptRepository) GetReceipt(txHash string) (core.Receipt, error) { +func (receiptRepository FullSyncReceiptRepository) GetFullSyncReceipt(txHash string) (core.Receipt, error) { row := receiptRepository.DB.QueryRow( `SELECT contract_address_id, tx_hash, diff --git a/pkg/datastore/postgres/repositories/receipt_repository_test.go b/pkg/datastore/postgres/repositories/full_sync_receipt_repository_test.go similarity index 90% rename from pkg/datastore/postgres/repositories/receipt_repository_test.go rename to pkg/datastore/postgres/repositories/full_sync_receipt_repository_test.go index 76d1516b..0232cc99 100644 --- a/pkg/datastore/postgres/repositories/receipt_repository_test.go +++ b/pkg/datastore/postgres/repositories/full_sync_receipt_repository_test.go @@ -30,7 +30,7 @@ import ( var _ = Describe("Receipt Repository", func() { var blockRepository datastore.BlockRepository var logRepository datastore.LogRepository - var receiptRepository datastore.ReceiptRepository + var receiptRepository datastore.FullSyncReceiptRepository var db *postgres.DB var node core.Node BeforeEach(func() { @@ -44,7 +44,7 @@ var _ = Describe("Receipt Repository", func() { test_config.CleanTestDB(db) blockRepository = repositories.NewBlockRepository(db) logRepository = repositories.LogRepository{DB: db} - receiptRepository = repositories.ReceiptRepository{DB: db} + receiptRepository = repositories.FullSyncReceiptRepository{DB: db} }) Describe("Saving multiple receipts", func() { @@ -84,12 +84,12 @@ var _ = Describe("Receipt Repository", func() { Expect(err).NotTo(HaveOccurred()) - persistedReceiptOne, err := receiptRepository.GetReceipt(txHashOne) + persistedReceiptOne, err := receiptRepository.GetFullSyncReceipt(txHashOne) Expect(err).NotTo(HaveOccurred()) Expect(persistedReceiptOne).NotTo(BeNil()) Expect(persistedReceiptOne.TxHash).To(Equal(txHashOne)) - persistedReceiptTwo, err := receiptRepository.GetReceipt(txHashTwo) + persistedReceiptTwo, err := receiptRepository.GetFullSyncReceipt(txHashTwo) Expect(err).NotTo(HaveOccurred()) Expect(persistedReceiptTwo).NotTo(BeNil()) Expect(persistedReceiptTwo.TxHash).To(Equal(txHashTwo)) @@ -124,7 +124,7 @@ var _ = Describe("Receipt Repository", func() { _, err := blockRepository.CreateOrUpdateBlock(block) Expect(err).NotTo(HaveOccurred()) - receipt, err := receiptRepository.GetReceipt("0xe340558980f89d5f86045ac11e5cc34e4bcec20f9f1e2a427aa39d87114e8223") + receipt, err := receiptRepository.GetFullSyncReceipt("0xe340558980f89d5f86045ac11e5cc34e4bcec20f9f1e2a427aa39d87114e8223") Expect(err).ToNot(HaveOccurred()) //Not currently serializing bloom logs Expect(receipt.Bloom).To(Equal(core.Receipt{}.Bloom)) @@ -136,7 +136,7 @@ var _ = Describe("Receipt Repository", func() { }) It("returns ErrReceiptDoesNotExist when receipt does not exist", func() { - receipt, err := receiptRepository.GetReceipt("DOES NOT EXIST") + receipt, err := receiptRepository.GetFullSyncReceipt("DOES NOT EXIST") Expect(err).To(HaveOccurred()) Expect(receipt).To(BeZero()) }) @@ -154,7 +154,7 @@ var _ = Describe("Receipt Repository", func() { _, err := blockRepository.CreateOrUpdateBlock(block) Expect(err).NotTo(HaveOccurred()) - _, err = receiptRepository.GetReceipt(receipt.TxHash) + _, err = receiptRepository.GetFullSyncReceipt(receipt.TxHash) Expect(err).To(Not(HaveOccurred())) }) }) diff --git a/pkg/datastore/postgres/repositories/logs_repository_test.go b/pkg/datastore/postgres/repositories/logs_repository_test.go index f2f4c27b..c6544aa4 100644 --- a/pkg/datastore/postgres/repositories/logs_repository_test.go +++ b/pkg/datastore/postgres/repositories/logs_repository_test.go @@ -34,7 +34,7 @@ var _ = Describe("Logs Repository", func() { var db *postgres.DB var blockRepository datastore.BlockRepository var logsRepository datastore.LogRepository - var receiptRepository datastore.ReceiptRepository + var receiptRepository datastore.FullSyncReceiptRepository var node core.Node BeforeEach(func() { @@ -48,7 +48,7 @@ var _ = Describe("Logs Repository", func() { test_config.CleanTestDB(db) blockRepository = repositories.NewBlockRepository(db) logsRepository = repositories.LogRepository{DB: db} - receiptRepository = repositories.ReceiptRepository{DB: db} + receiptRepository = repositories.FullSyncReceiptRepository{DB: db} }) It("returns the log when it exists", func() { @@ -56,7 +56,7 @@ var _ = Describe("Logs Repository", func() { blockId, err := blockRepository.CreateOrUpdateBlock(core.Block{Number: blockNumber}) Expect(err).NotTo(HaveOccurred()) tx, _ := db.Beginx() - receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{}, tx) + receiptId, err := receiptRepository.CreateFullSyncReceiptInTx(blockId, core.Receipt{}, tx) tx.Commit() Expect(err).NotTo(HaveOccurred()) err = logsRepository.CreateLogs([]core.Log{{ @@ -94,7 +94,7 @@ var _ = Describe("Logs Repository", func() { blockId, err := blockRepository.CreateOrUpdateBlock(core.Block{Number: blockNumber}) Expect(err).NotTo(HaveOccurred()) tx, _ := db.Beginx() - receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{}, tx) + receiptId, err := receiptRepository.CreateFullSyncReceiptInTx(blockId, core.Receipt{}, tx) tx.Commit() Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/datastore/postgres/repositories/watched_events_repository_test.go b/pkg/datastore/postgres/repositories/watched_events_repository_test.go index f30a85f5..6e170e89 100644 --- a/pkg/datastore/postgres/repositories/watched_events_repository_test.go +++ b/pkg/datastore/postgres/repositories/watched_events_repository_test.go @@ -32,7 +32,7 @@ var _ = Describe("Watched Events Repository", func() { var blocksRepository datastore.BlockRepository var filterRepository datastore.FilterRepository var logRepository datastore.LogRepository - var receiptRepository datastore.ReceiptRepository + var receiptRepository datastore.FullSyncReceiptRepository var watchedEventRepository datastore.WatchedEventRepository BeforeEach(func() { @@ -41,7 +41,7 @@ var _ = Describe("Watched Events Repository", func() { blocksRepository = repositories.NewBlockRepository(db) filterRepository = repositories.FilterRepository{DB: db} logRepository = repositories.LogRepository{DB: db} - receiptRepository = repositories.ReceiptRepository{DB: db} + receiptRepository = repositories.FullSyncReceiptRepository{DB: db} watchedEventRepository = repositories.WatchedEventRepository{DB: db} }) @@ -80,7 +80,7 @@ var _ = Describe("Watched Events Repository", func() { blockId, err := blocksRepository.CreateOrUpdateBlock(core.Block{}) Expect(err).NotTo(HaveOccurred()) tx, _ := db.Beginx() - receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{}, tx) + receiptId, err := receiptRepository.CreateFullSyncReceiptInTx(blockId, core.Receipt{}, tx) tx.Commit() Expect(err).NotTo(HaveOccurred()) err = logRepository.CreateLogs(logs, receiptId) @@ -139,7 +139,7 @@ var _ = Describe("Watched Events Repository", func() { blockId, err := blocksRepository.CreateOrUpdateBlock(core.Block{Hash: "Ox123"}) Expect(err).NotTo(HaveOccurred()) tx, _ := db.Beginx() - receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{}, tx) + receiptId, err := receiptRepository.CreateFullSyncReceiptInTx(blockId, core.Receipt{}, tx) tx.Commit() Expect(err).NotTo(HaveOccurred()) err = logRepository.CreateLogs(logs, receiptId) diff --git a/pkg/datastore/repository.go b/pkg/datastore/repository.go index c1883ecc..5e94f7d9 100644 --- a/pkg/datastore/repository.go +++ b/pkg/datastore/repository.go @@ -56,10 +56,10 @@ type LogRepository interface { GetLogs(address string, blockNumber int64) ([]core.Log, error) } -type ReceiptRepository interface { +type FullSyncReceiptRepository interface { CreateReceiptsAndLogs(blockId int64, receipts []core.Receipt) error - CreateReceipt(blockId int64, receipt core.Receipt, tx *sqlx.Tx) (int64, error) //TODO: change the name to CreateReceiptInTransaction - GetReceipt(txHash string) (core.Receipt, error) + CreateFullSyncReceiptInTx(blockId int64, receipt core.Receipt, tx *sqlx.Tx) (int64, error) + GetFullSyncReceipt(txHash string) (core.Receipt, error) } type WatchedEventRepository interface { diff --git a/pkg/fakes/mock_receipt_repository.go b/pkg/fakes/mock_receipt_repository.go index 3aad1a57..80236393 100644 --- a/pkg/fakes/mock_receipt_repository.go +++ b/pkg/fakes/mock_receipt_repository.go @@ -50,11 +50,11 @@ func (mrr *MockReceiptRepository) CreateReceiptsAndLogs(blockId int64, receipts return mrr.createReceiptsAndLogsReturnErr } -func (mrr *MockReceiptRepository) CreateReceipt(blockId int64, receipt core.Receipt, tx *sqlx.Tx) (int64, error) { +func (mrr *MockReceiptRepository) CreateFullSyncReceiptInTx(blockId int64, receipt core.Receipt, tx *sqlx.Tx) (int64, error) { panic("implement me") } -func (mrr *MockReceiptRepository) GetReceipt(txHash string) (core.Receipt, error) { +func (mrr *MockReceiptRepository) GetFullSyncReceipt(txHash string) (core.Receipt, error) { panic("implement me") } diff --git a/pkg/geth/cold_import/importer.go b/pkg/geth/cold_import/importer.go index e29bfd22..280ed15a 100644 --- a/pkg/geth/cold_import/importer.go +++ b/pkg/geth/cold_import/importer.go @@ -26,10 +26,10 @@ type ColdImporter struct { blockRepository datastore.BlockRepository converter common.BlockConverter ethDB ethereum.Database - receiptRepository datastore.ReceiptRepository + receiptRepository datastore.FullSyncReceiptRepository } -func NewColdImporter(ethDB ethereum.Database, blockRepository datastore.BlockRepository, receiptRepository datastore.ReceiptRepository, converter common.BlockConverter) *ColdImporter { +func NewColdImporter(ethDB ethereum.Database, blockRepository datastore.BlockRepository, receiptRepository datastore.FullSyncReceiptRepository, converter common.BlockConverter) *ColdImporter { return &ColdImporter{ blockRepository: blockRepository, converter: converter,