From 9789648cc2a65214a6c31880c6bdef3bdb1e3356 Mon Sep 17 00:00:00 2001 From: Edvard Date: Tue, 4 Dec 2018 17:40:39 +0100 Subject: [PATCH] Delegate log chunks to respective transformers --- libraries/shared/watcher.go | 4 +--- pkg/transformers/factories/log_note_transformer.go | 4 ++++ pkg/transformers/factories/transformer.go | 4 ++++ pkg/transformers/shared/repository.go | 1 - pkg/transformers/shared/transformer.go | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libraries/shared/watcher.go b/libraries/shared/watcher.go index 70277cfd..3b1cff20 100644 --- a/libraries/shared/watcher.go +++ b/libraries/shared/watcher.go @@ -71,9 +71,7 @@ func (watcher *Watcher) Execute() error { chunkedLogs := watcher.Chunker.ChunkLogs(logs) for _, transformer := range watcher.Transformers { - // TODO delegate log chunks to respective transformers - // Need to get the transformer name... :/ - logChunk := chunkedLogs["transformerName"] + logChunk := chunkedLogs[transformer.Name()] err = transformer.Execute(logChunk, header) } } diff --git a/pkg/transformers/factories/log_note_transformer.go b/pkg/transformers/factories/log_note_transformer.go index 663b9dc0..849d9619 100644 --- a/pkg/transformers/factories/log_note_transformer.go +++ b/pkg/transformers/factories/log_note_transformer.go @@ -59,3 +59,7 @@ func (transformer LogNoteTransformer) Execute(logs []types.Log, header core.Head } return nil } + +func (transformer LogNoteTransformer) Name() string { + return transformer.Config.TransformerName +} diff --git a/pkg/transformers/factories/transformer.go b/pkg/transformers/factories/transformer.go index 28ed3953..eae4fd7f 100644 --- a/pkg/transformers/factories/transformer.go +++ b/pkg/transformers/factories/transformer.go @@ -66,3 +66,7 @@ func (transformer Transformer) Execute(logs []types.Log, header core.Header) err return nil } + +func (transformer Transformer) Name() string { + return transformer.Config.TransformerName +} diff --git a/pkg/transformers/shared/repository.go b/pkg/transformers/shared/repository.go index a1d5c8db..0380d50a 100644 --- a/pkg/transformers/shared/repository.go +++ b/pkg/transformers/shared/repository.go @@ -26,7 +26,6 @@ func MarkHeaderCheckedInTransaction(headerID int64, tx *sql.Tx, checkedHeadersCo } // Treats a header as missing if it's not in the headers table, or not checked for some log type -// TODO Revisit definition of "checked header func MissingHeaders(startingBlockNumber, endingBlockNumber int64, db *postgres.DB, notCheckedSQL string) ([]core.Header, error) { var result []core.Header var query string diff --git a/pkg/transformers/shared/transformer.go b/pkg/transformers/shared/transformer.go index 8b5c8c49..a5ff5835 100644 --- a/pkg/transformers/shared/transformer.go +++ b/pkg/transformers/shared/transformer.go @@ -24,6 +24,7 @@ import ( type Transformer interface { Execute(logs []types.Log, header core.Header) error + Name() string } type TransformerInitializer func(db *postgres.DB) Transformer