Rename ReceiptRepository -> FullSyncReceiptRepository

This commit is contained in:
Elizabeth Engelman 2019-08-05 10:38:37 -05:00
parent 4e40e892d2
commit 7e38764618
11 changed files with 35 additions and 41 deletions

View File

@ -84,7 +84,7 @@ func coldImport() {
// init cold importer deps // init cold importer deps
blockRepository := repositories.NewBlockRepository(&pgDB) blockRepository := repositories.NewBlockRepository(&pgDB)
receiptRepository := repositories.ReceiptRepository{DB: &pgDB} receiptRepository := repositories.FullSyncReceiptRepository{DB: &pgDB}
transactionConverter := cold_db.NewColdDbTransactionConverter() transactionConverter := cold_db.NewColdDbTransactionConverter()
blockConverter := vulcCommon.NewBlockConverter(transactionConverter) blockConverter := vulcCommon.NewBlockConverter(transactionConverter)

View File

@ -137,7 +137,7 @@ func SetupTusdRepo(vulcanizeLogId *int64, wantedEvents, wantedMethods []string)
}, core.Node{}) }, core.Node{})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
receiptRepository := repositories.ReceiptRepository{DB: db} receiptRepository := repositories.FullSyncReceiptRepository{DB: db}
logRepository := repositories.LogRepository{DB: db} logRepository := repositories.LogRepository{DB: db}
blockRepository := *repositories.NewBlockRepository(db) blockRepository := *repositories.NewBlockRepository(db)
@ -183,7 +183,7 @@ func SetupENSRepo(vulcanizeLogId *int64, wantedEvents, wantedMethods []string) (
}, core.Node{}) }, core.Node{})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
receiptRepository := repositories.ReceiptRepository{DB: db} receiptRepository := repositories.FullSyncReceiptRepository{DB: db}
logRepository := repositories.LogRepository{DB: db} logRepository := repositories.LogRepository{DB: db}
blockRepository := *repositories.NewBlockRepository(db) blockRepository := *repositories.NewBlockRepository(db)

View File

@ -23,7 +23,7 @@ import (
type AddressRepository struct{} 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) stringAddressToCommonAddress := common.HexToAddress(address)
hexAddress := stringAddressToCommonAddress.Hex() hexAddress := stringAddressToCommonAddress.Hex()
@ -37,7 +37,7 @@ func (repo AddressRepository) GetOrCreateAddress(db *postgres.DB, address string
return addressId, getErr 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) stringAddressToCommonAddress := common.HexToAddress(address)
hexAddress := stringAddressToCommonAddress.Hex() hexAddress := stringAddressToCommonAddress.Hex()
@ -51,7 +51,7 @@ func (repo AddressRepository) GetOrCreateAddressInTransaction(tx *sqlx.Tx, addre
return addressId, getErr 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 var address string
getErr := db.Get(&address, `SELECT address FROM public.addresses WHERE id = $1`, id) getErr := db.Get(&address, `SELECT address FROM public.addresses WHERE id = $1`, id)
if getErr != nil { if getErr != nil {

View File

@ -234,8 +234,8 @@ func (blockRepository BlockRepository) createTransaction(tx *sqlx.Tx, blockId in
return err return err
} }
if hasReceipt(transaction) { if hasReceipt(transaction) {
receiptRepo := FullSyncReceiptRepository{}
receiptId, err := receiptRepository().CreateReceipt(blockId, transaction.Receipt, tx) receiptId, err := receiptRepo.CreateFullSyncReceiptInTx(blockId, transaction.Receipt, tx)
if err != nil { if err != nil {
return err return err
} }
@ -249,11 +249,6 @@ func (blockRepository BlockRepository) createTransaction(tx *sqlx.Tx, blockId in
return nil return nil
} }
func receiptRepository() datastore.ReceiptRepository {
//TODO: set db?
return ReceiptRepository{}
}
func hasLogs(transaction core.TransactionModel) bool { func hasLogs(transaction core.TransactionModel) bool {
return len(transaction.Receipt.Logs) > 0 return len(transaction.Receipt.Logs) > 0
} }

View File

@ -26,17 +26,17 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
) )
type ReceiptRepository struct { type FullSyncReceiptRepository struct {
*postgres.DB *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() tx, err := receiptRepository.DB.Beginx()
if err != nil { if err != nil {
return err return err
} }
for _, receipt := range receipts { for _, receipt := range receipts {
receiptId, err := receiptRepository.CreateReceipt(blockId, receipt, tx) receiptId, err := receiptRepository.CreateFullSyncReceiptInTx(blockId, receipt, tx)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -68,8 +68,7 @@ func createLogs(logs []core.Log, receiptId int64, tx *sqlx.Tx) error {
return nil return nil
} }
//TODO: test that creating the address should be in the transaction func (FullSyncReceiptRepository) CreateFullSyncReceiptInTx(blockId int64, receipt core.Receipt, tx *sqlx.Tx) (int64, error) {
func (ReceiptRepository) CreateReceipt(blockId int64, receipt core.Receipt, tx *sqlx.Tx) (int64, error) {
var receiptId int64 var receiptId int64
addressId, getAddressErr := AddressRepository{}.GetOrCreateAddressInTransaction(tx, receipt.ContractAddress) addressId, getAddressErr := AddressRepository{}.GetOrCreateAddressInTransaction(tx, receipt.ContractAddress)
if getAddressErr != nil { if getAddressErr != nil {
@ -90,7 +89,7 @@ func (ReceiptRepository) CreateReceipt(blockId int64, receipt core.Receipt, tx *
return receiptId, nil 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( row := receiptRepository.DB.QueryRow(
`SELECT contract_address_id, `SELECT contract_address_id,
tx_hash, tx_hash,

View File

@ -30,7 +30,7 @@ import (
var _ = Describe("Receipt Repository", func() { var _ = Describe("Receipt Repository", func() {
var blockRepository datastore.BlockRepository var blockRepository datastore.BlockRepository
var logRepository datastore.LogRepository var logRepository datastore.LogRepository
var receiptRepository datastore.ReceiptRepository var receiptRepository datastore.FullSyncReceiptRepository
var db *postgres.DB var db *postgres.DB
var node core.Node var node core.Node
BeforeEach(func() { BeforeEach(func() {
@ -44,7 +44,7 @@ var _ = Describe("Receipt Repository", func() {
test_config.CleanTestDB(db) test_config.CleanTestDB(db)
blockRepository = repositories.NewBlockRepository(db) blockRepository = repositories.NewBlockRepository(db)
logRepository = repositories.LogRepository{DB: db} logRepository = repositories.LogRepository{DB: db}
receiptRepository = repositories.ReceiptRepository{DB: db} receiptRepository = repositories.FullSyncReceiptRepository{DB: db}
}) })
Describe("Saving multiple receipts", func() { Describe("Saving multiple receipts", func() {
@ -84,12 +84,12 @@ var _ = Describe("Receipt Repository", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
persistedReceiptOne, err := receiptRepository.GetReceipt(txHashOne) persistedReceiptOne, err := receiptRepository.GetFullSyncReceipt(txHashOne)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(persistedReceiptOne).NotTo(BeNil()) Expect(persistedReceiptOne).NotTo(BeNil())
Expect(persistedReceiptOne.TxHash).To(Equal(txHashOne)) Expect(persistedReceiptOne.TxHash).To(Equal(txHashOne))
persistedReceiptTwo, err := receiptRepository.GetReceipt(txHashTwo) persistedReceiptTwo, err := receiptRepository.GetFullSyncReceipt(txHashTwo)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(persistedReceiptTwo).NotTo(BeNil()) Expect(persistedReceiptTwo).NotTo(BeNil())
Expect(persistedReceiptTwo.TxHash).To(Equal(txHashTwo)) Expect(persistedReceiptTwo.TxHash).To(Equal(txHashTwo))
@ -124,7 +124,7 @@ var _ = Describe("Receipt Repository", func() {
_, err := blockRepository.CreateOrUpdateBlock(block) _, err := blockRepository.CreateOrUpdateBlock(block)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
receipt, err := receiptRepository.GetReceipt("0xe340558980f89d5f86045ac11e5cc34e4bcec20f9f1e2a427aa39d87114e8223") receipt, err := receiptRepository.GetFullSyncReceipt("0xe340558980f89d5f86045ac11e5cc34e4bcec20f9f1e2a427aa39d87114e8223")
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
//Not currently serializing bloom logs //Not currently serializing bloom logs
Expect(receipt.Bloom).To(Equal(core.Receipt{}.Bloom)) 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() { 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(err).To(HaveOccurred())
Expect(receipt).To(BeZero()) Expect(receipt).To(BeZero())
}) })
@ -154,7 +154,7 @@ var _ = Describe("Receipt Repository", func() {
_, err := blockRepository.CreateOrUpdateBlock(block) _, err := blockRepository.CreateOrUpdateBlock(block)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
_, err = receiptRepository.GetReceipt(receipt.TxHash) _, err = receiptRepository.GetFullSyncReceipt(receipt.TxHash)
Expect(err).To(Not(HaveOccurred())) Expect(err).To(Not(HaveOccurred()))
}) })
}) })

View File

@ -34,7 +34,7 @@ var _ = Describe("Logs Repository", func() {
var db *postgres.DB var db *postgres.DB
var blockRepository datastore.BlockRepository var blockRepository datastore.BlockRepository
var logsRepository datastore.LogRepository var logsRepository datastore.LogRepository
var receiptRepository datastore.ReceiptRepository var receiptRepository datastore.FullSyncReceiptRepository
var node core.Node var node core.Node
BeforeEach(func() { BeforeEach(func() {
@ -48,7 +48,7 @@ var _ = Describe("Logs Repository", func() {
test_config.CleanTestDB(db) test_config.CleanTestDB(db)
blockRepository = repositories.NewBlockRepository(db) blockRepository = repositories.NewBlockRepository(db)
logsRepository = repositories.LogRepository{DB: db} logsRepository = repositories.LogRepository{DB: db}
receiptRepository = repositories.ReceiptRepository{DB: db} receiptRepository = repositories.FullSyncReceiptRepository{DB: db}
}) })
It("returns the log when it exists", func() { 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}) blockId, err := blockRepository.CreateOrUpdateBlock(core.Block{Number: blockNumber})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
tx, _ := db.Beginx() tx, _ := db.Beginx()
receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{}, tx) receiptId, err := receiptRepository.CreateFullSyncReceiptInTx(blockId, core.Receipt{}, tx)
tx.Commit() tx.Commit()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = logsRepository.CreateLogs([]core.Log{{ err = logsRepository.CreateLogs([]core.Log{{
@ -94,7 +94,7 @@ var _ = Describe("Logs Repository", func() {
blockId, err := blockRepository.CreateOrUpdateBlock(core.Block{Number: blockNumber}) blockId, err := blockRepository.CreateOrUpdateBlock(core.Block{Number: blockNumber})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
tx, _ := db.Beginx() tx, _ := db.Beginx()
receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{}, tx) receiptId, err := receiptRepository.CreateFullSyncReceiptInTx(blockId, core.Receipt{}, tx)
tx.Commit() tx.Commit()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())

View File

@ -32,7 +32,7 @@ var _ = Describe("Watched Events Repository", func() {
var blocksRepository datastore.BlockRepository var blocksRepository datastore.BlockRepository
var filterRepository datastore.FilterRepository var filterRepository datastore.FilterRepository
var logRepository datastore.LogRepository var logRepository datastore.LogRepository
var receiptRepository datastore.ReceiptRepository var receiptRepository datastore.FullSyncReceiptRepository
var watchedEventRepository datastore.WatchedEventRepository var watchedEventRepository datastore.WatchedEventRepository
BeforeEach(func() { BeforeEach(func() {
@ -41,7 +41,7 @@ var _ = Describe("Watched Events Repository", func() {
blocksRepository = repositories.NewBlockRepository(db) blocksRepository = repositories.NewBlockRepository(db)
filterRepository = repositories.FilterRepository{DB: db} filterRepository = repositories.FilterRepository{DB: db}
logRepository = repositories.LogRepository{DB: db} logRepository = repositories.LogRepository{DB: db}
receiptRepository = repositories.ReceiptRepository{DB: db} receiptRepository = repositories.FullSyncReceiptRepository{DB: db}
watchedEventRepository = repositories.WatchedEventRepository{DB: db} watchedEventRepository = repositories.WatchedEventRepository{DB: db}
}) })
@ -80,7 +80,7 @@ var _ = Describe("Watched Events Repository", func() {
blockId, err := blocksRepository.CreateOrUpdateBlock(core.Block{}) blockId, err := blocksRepository.CreateOrUpdateBlock(core.Block{})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
tx, _ := db.Beginx() tx, _ := db.Beginx()
receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{}, tx) receiptId, err := receiptRepository.CreateFullSyncReceiptInTx(blockId, core.Receipt{}, tx)
tx.Commit() tx.Commit()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = logRepository.CreateLogs(logs, receiptId) err = logRepository.CreateLogs(logs, receiptId)
@ -139,7 +139,7 @@ var _ = Describe("Watched Events Repository", func() {
blockId, err := blocksRepository.CreateOrUpdateBlock(core.Block{Hash: "Ox123"}) blockId, err := blocksRepository.CreateOrUpdateBlock(core.Block{Hash: "Ox123"})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
tx, _ := db.Beginx() tx, _ := db.Beginx()
receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{}, tx) receiptId, err := receiptRepository.CreateFullSyncReceiptInTx(blockId, core.Receipt{}, tx)
tx.Commit() tx.Commit()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = logRepository.CreateLogs(logs, receiptId) err = logRepository.CreateLogs(logs, receiptId)

View File

@ -56,10 +56,10 @@ type LogRepository interface {
GetLogs(address string, blockNumber int64) ([]core.Log, error) GetLogs(address string, blockNumber int64) ([]core.Log, error)
} }
type ReceiptRepository interface { type FullSyncReceiptRepository interface {
CreateReceiptsAndLogs(blockId int64, receipts []core.Receipt) error CreateReceiptsAndLogs(blockId int64, receipts []core.Receipt) error
CreateReceipt(blockId int64, receipt core.Receipt, tx *sqlx.Tx) (int64, error) //TODO: change the name to CreateReceiptInTransaction CreateFullSyncReceiptInTx(blockId int64, receipt core.Receipt, tx *sqlx.Tx) (int64, error)
GetReceipt(txHash string) (core.Receipt, error) GetFullSyncReceipt(txHash string) (core.Receipt, error)
} }
type WatchedEventRepository interface { type WatchedEventRepository interface {

View File

@ -50,11 +50,11 @@ func (mrr *MockReceiptRepository) CreateReceiptsAndLogs(blockId int64, receipts
return mrr.createReceiptsAndLogsReturnErr 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") panic("implement me")
} }
func (mrr *MockReceiptRepository) GetReceipt(txHash string) (core.Receipt, error) { func (mrr *MockReceiptRepository) GetFullSyncReceipt(txHash string) (core.Receipt, error) {
panic("implement me") panic("implement me")
} }

View File

@ -26,10 +26,10 @@ type ColdImporter struct {
blockRepository datastore.BlockRepository blockRepository datastore.BlockRepository
converter common.BlockConverter converter common.BlockConverter
ethDB ethereum.Database 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{ return &ColdImporter{
blockRepository: blockRepository, blockRepository: blockRepository,
converter: converter, converter: converter,