forked from cerc-io/ipld-eth-server
Rename checked_logs => watched_logs
- We're logging that a given log has been included in any fetch calls for checked headers, rather than that we have already checked for that log
This commit is contained in:
@@ -30,10 +30,10 @@ func NewCheckedLogsRepository(db *postgres.DB) CheckedLogsRepository {
|
||||
}
|
||||
|
||||
// Return whether a given address + topic0 has been fetched on a previous run of vDB
|
||||
func (repository CheckedLogsRepository) HaveLogsBeenChecked(addresses []string, topic0 string) (bool, error) {
|
||||
func (repository CheckedLogsRepository) AlreadyWatchingLog(addresses []string, topic0 string) (bool, error) {
|
||||
for _, address := range addresses {
|
||||
var addressExists bool
|
||||
getAddressExistsErr := repository.db.Get(&addressExists, `SELECT EXISTS(SELECT 1 FROM public.checked_logs WHERE contract_address = $1)`, address)
|
||||
getAddressExistsErr := repository.db.Get(&addressExists, `SELECT EXISTS(SELECT 1 FROM public.watched_logs WHERE contract_address = $1)`, address)
|
||||
if getAddressExistsErr != nil {
|
||||
return false, getAddressExistsErr
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (repository CheckedLogsRepository) HaveLogsBeenChecked(addresses []string,
|
||||
}
|
||||
}
|
||||
var topicZeroExists bool
|
||||
getTopicZeroExistsErr := repository.db.Get(&topicZeroExists, `SELECT EXISTS(SELECT 1 FROM public.checked_logs WHERE topic_zero = $1)`, topic0)
|
||||
getTopicZeroExistsErr := repository.db.Get(&topicZeroExists, `SELECT EXISTS(SELECT 1 FROM public.watched_logs WHERE topic_zero = $1)`, topic0)
|
||||
if getTopicZeroExistsErr != nil {
|
||||
return false, getTopicZeroExistsErr
|
||||
}
|
||||
@@ -50,13 +50,13 @@ func (repository CheckedLogsRepository) HaveLogsBeenChecked(addresses []string,
|
||||
}
|
||||
|
||||
// Persist that a given address + topic0 has is being fetched on this run of vDB
|
||||
func (repository CheckedLogsRepository) MarkLogsChecked(addresses []string, topic0 string) error {
|
||||
func (repository CheckedLogsRepository) MarkLogWatched(addresses []string, topic0 string) error {
|
||||
tx, txErr := repository.db.Beginx()
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
for _, address := range addresses {
|
||||
_, insertErr := tx.Exec(`INSERT INTO public.checked_logs (contract_address, topic_zero) VALUES ($1, $2)`, address, topic0)
|
||||
_, insertErr := tx.Exec(`INSERT INTO public.watched_logs (contract_address, topic_zero) VALUES ($1, $2)`, address, topic0)
|
||||
if insertErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
|
||||
@@ -47,12 +47,12 @@ var _ = Describe("Checked logs repository", func() {
|
||||
Expect(closeErr).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
Describe("HaveLogsBeenChecked", func() {
|
||||
Describe("AlreadyWatchingLog", func() {
|
||||
It("returns true if all addresses and the topic0 are already present in the db", func() {
|
||||
_, insertErr := db.Exec(`INSERT INTO public.checked_logs (contract_address, topic_zero) VALUES ($1, $2)`, fakeAddress, fakeTopicZero)
|
||||
_, insertErr := db.Exec(`INSERT INTO public.watched_logs (contract_address, topic_zero) VALUES ($1, $2)`, fakeAddress, fakeTopicZero)
|
||||
Expect(insertErr).NotTo(HaveOccurred())
|
||||
|
||||
hasBeenChecked, err := repository.HaveLogsBeenChecked(fakeAddresses, fakeTopicZero)
|
||||
hasBeenChecked, err := repository.AlreadyWatchingLog(fakeAddresses, fakeTopicZero)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(hasBeenChecked).To(BeTrue())
|
||||
@@ -62,13 +62,13 @@ var _ = Describe("Checked logs repository", func() {
|
||||
anotherFakeAddress := common.HexToAddress("0x" + fakes.RandomString(40)).Hex()
|
||||
anotherFakeTopicZero := common.HexToHash("0x" + fakes.RandomString(64)).Hex()
|
||||
// insert row with matching address but different topic0
|
||||
_, insertOneErr := db.Exec(`INSERT INTO public.checked_logs (contract_address, topic_zero) VALUES ($1, $2)`, fakeAddress, anotherFakeTopicZero)
|
||||
_, insertOneErr := db.Exec(`INSERT INTO public.watched_logs (contract_address, topic_zero) VALUES ($1, $2)`, fakeAddress, anotherFakeTopicZero)
|
||||
Expect(insertOneErr).NotTo(HaveOccurred())
|
||||
// insert row with matching topic0 but different address
|
||||
_, insertTwoErr := db.Exec(`INSERT INTO public.checked_logs (contract_address, topic_zero) VALUES ($1, $2)`, anotherFakeAddress, fakeTopicZero)
|
||||
_, insertTwoErr := db.Exec(`INSERT INTO public.watched_logs (contract_address, topic_zero) VALUES ($1, $2)`, anotherFakeAddress, fakeTopicZero)
|
||||
Expect(insertTwoErr).NotTo(HaveOccurred())
|
||||
|
||||
hasBeenChecked, err := repository.HaveLogsBeenChecked(fakeAddresses, fakeTopicZero)
|
||||
hasBeenChecked, err := repository.AlreadyWatchingLog(fakeAddresses, fakeTopicZero)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(hasBeenChecked).To(BeTrue())
|
||||
@@ -76,10 +76,10 @@ var _ = Describe("Checked logs repository", func() {
|
||||
|
||||
It("returns false if any address has not been checked", func() {
|
||||
anotherFakeAddress := common.HexToAddress("0x" + fakes.RandomString(40)).Hex()
|
||||
_, insertErr := db.Exec(`INSERT INTO public.checked_logs (contract_address, topic_zero) VALUES ($1, $2)`, fakeAddress, fakeTopicZero)
|
||||
_, insertErr := db.Exec(`INSERT INTO public.watched_logs (contract_address, topic_zero) VALUES ($1, $2)`, fakeAddress, fakeTopicZero)
|
||||
Expect(insertErr).NotTo(HaveOccurred())
|
||||
|
||||
hasBeenChecked, err := repository.HaveLogsBeenChecked(append(fakeAddresses, anotherFakeAddress), fakeTopicZero)
|
||||
hasBeenChecked, err := repository.AlreadyWatchingLog(append(fakeAddresses, anotherFakeAddress), fakeTopicZero)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(hasBeenChecked).To(BeFalse())
|
||||
@@ -87,27 +87,27 @@ var _ = Describe("Checked logs repository", func() {
|
||||
|
||||
It("returns false if topic0 has not been checked", func() {
|
||||
anotherFakeTopicZero := common.HexToHash("0x" + fakes.RandomString(64)).Hex()
|
||||
_, insertErr := db.Exec(`INSERT INTO public.checked_logs (contract_address, topic_zero) VALUES ($1, $2)`, fakeAddress, anotherFakeTopicZero)
|
||||
_, insertErr := db.Exec(`INSERT INTO public.watched_logs (contract_address, topic_zero) VALUES ($1, $2)`, fakeAddress, anotherFakeTopicZero)
|
||||
Expect(insertErr).NotTo(HaveOccurred())
|
||||
|
||||
hasBeenChecked, err := repository.HaveLogsBeenChecked(fakeAddresses, fakeTopicZero)
|
||||
hasBeenChecked, err := repository.AlreadyWatchingLog(fakeAddresses, fakeTopicZero)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(hasBeenChecked).To(BeFalse())
|
||||
})
|
||||
})
|
||||
|
||||
Describe("MarkLogsChecked", func() {
|
||||
Describe("MarkLogWatched", func() {
|
||||
It("adds a row for all of transformer's addresses + topic0", func() {
|
||||
anotherFakeAddress := common.HexToAddress("0x" + fakes.RandomString(40)).Hex()
|
||||
err := repository.MarkLogsChecked(append(fakeAddresses, anotherFakeAddress), fakeTopicZero)
|
||||
err := repository.MarkLogWatched(append(fakeAddresses, anotherFakeAddress), fakeTopicZero)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var comboOneExists, comboTwoExists bool
|
||||
getComboOneErr := db.Get(&comboOneExists, `SELECT EXISTS(SELECT 1 FROM public.checked_logs WHERE contract_address = $1 AND topic_zero = $2)`, fakeAddress, fakeTopicZero)
|
||||
getComboOneErr := db.Get(&comboOneExists, `SELECT EXISTS(SELECT 1 FROM public.watched_logs WHERE contract_address = $1 AND topic_zero = $2)`, fakeAddress, fakeTopicZero)
|
||||
Expect(getComboOneErr).NotTo(HaveOccurred())
|
||||
Expect(comboOneExists).To(BeTrue())
|
||||
getComboTwoErr := db.Get(&comboTwoExists, `SELECT EXISTS(SELECT 1 FROM public.checked_logs WHERE contract_address = $1 AND topic_zero = $2)`, anotherFakeAddress, fakeTopicZero)
|
||||
getComboTwoErr := db.Get(&comboTwoExists, `SELECT EXISTS(SELECT 1 FROM public.watched_logs WHERE contract_address = $1 AND topic_zero = $2)`, anotherFakeAddress, fakeTopicZero)
|
||||
Expect(getComboTwoErr).NotTo(HaveOccurred())
|
||||
Expect(comboTwoExists).To(BeTrue())
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user