diff --git a/libraries/shared/watcher.go b/libraries/shared/watcher.go index ff138dfc..70277cfd 100644 --- a/libraries/shared/watcher.go +++ b/libraries/shared/watcher.go @@ -74,7 +74,7 @@ func (watcher *Watcher) Execute() error { // TODO delegate log chunks to respective transformers // Need to get the transformer name... :/ logChunk := chunkedLogs["transformerName"] - err = transformer.Execute(logChunk, missingHeaders) + err = transformer.Execute(logChunk, header) } } return err diff --git a/pkg/transformers/factories/log_note_transformer.go b/pkg/transformers/factories/log_note_transformer.go index 453d72b0..663b9dc0 100644 --- a/pkg/transformers/factories/log_note_transformer.go +++ b/pkg/transformers/factories/log_note_transformer.go @@ -34,32 +34,28 @@ func (transformer LogNoteTransformer) NewLogNoteTransformer(db *postgres.DB) sha return transformer } -func (transformer LogNoteTransformer) Execute(logs []types.Log, missingHeaders []core.Header) error { +func (transformer LogNoteTransformer) Execute(logs []types.Log, header core.Header) error { transformerName := transformer.Config.TransformerName - for _, header := range missingHeaders { - // No matching logs, mark the header as checked for this type of logs - if len(logs) < 1 { - err := transformer.Repository.MarkHeaderChecked(header.Id) - if err != nil { - log.Printf("Error marking header as checked in %v: %v", transformerName, err) - return err - } - // Continue with the next header; nothing to persist - continue - } - - models, err := transformer.Converter.ToModels(logs) + // No matching logs, mark the header as checked for this type of logs + if len(logs) < 1 { + err := transformer.Repository.MarkHeaderChecked(header.Id) if err != nil { - log.Printf("Error converting logs in %v: %v", transformerName, err) - return err - } - - err = transformer.Repository.Create(header.Id, models) - if err != nil { - log.Printf("Error persisting %v record: %v", transformerName, err) + log.Printf("Error marking header as checked in %v: %v", transformerName, err) return err } } + + models, err := transformer.Converter.ToModels(logs) + if err != nil { + log.Printf("Error converting logs in %v: %v", transformerName, err) + return err + } + + err = transformer.Repository.Create(header.Id, models) + if err != nil { + log.Printf("Error persisting %v record: %v", transformerName, err) + return err + } return nil } diff --git a/pkg/transformers/factories/transformer.go b/pkg/transformers/factories/transformer.go index 6c1a8a4f..28ed3953 100644 --- a/pkg/transformers/factories/transformer.go +++ b/pkg/transformers/factories/transformer.go @@ -34,39 +34,34 @@ func (transformer Transformer) NewTransformer(db *postgres.DB) shared.Transforme return transformer } -func (transformer Transformer) Execute(logs []types.Log, missingHeaders []core.Header) error { +func (transformer Transformer) Execute(logs []types.Log, header core.Header) error { transformerName := transformer.Config.TransformerName config := transformer.Config - for _, header := range missingHeaders { - if len(logs) < 1 { - err := transformer.Repository.MarkHeaderChecked(header.Id) - if err != nil { - log.Printf("Error marking header as checked in %v: %v", transformerName, err) - return err - } - - continue - } - - entities, err := transformer.Converter.ToEntities(config.ContractAbi, logs) + if len(logs) < 1 { + err := transformer.Repository.MarkHeaderChecked(header.Id) if err != nil { - log.Printf("Error converting logs to entities in %v: %v", transformerName, err) + log.Printf("Error marking header as checked in %v: %v", transformerName, err) return err } + } - models, err := transformer.Converter.ToModels(entities) - if err != nil { - log.Printf("Error converting entities to models in %v: %v", transformerName, err) - return err - } + entities, err := transformer.Converter.ToEntities(config.ContractAbi, logs) + if err != nil { + log.Printf("Error converting logs to entities in %v: %v", transformerName, err) + return err + } - err = transformer.Repository.Create(header.Id, models) - if err != nil { - log.Printf("Error persisting %v record: %v", transformerName, err) - return err - } + models, err := transformer.Converter.ToModels(entities) + if err != nil { + log.Printf("Error converting entities to models in %v: %v", transformerName, err) + return err + } + err = transformer.Repository.Create(header.Id, models) + if err != nil { + log.Printf("Error persisting %v record: %v", transformerName, err) + return err } return nil diff --git a/pkg/transformers/shared/transformer.go b/pkg/transformers/shared/transformer.go index 0e5a3f9e..8b5c8c49 100644 --- a/pkg/transformers/shared/transformer.go +++ b/pkg/transformers/shared/transformer.go @@ -23,7 +23,7 @@ import ( ) type Transformer interface { - Execute(logs []types.Log, missingHeaders []core.Header) error + Execute(logs []types.Log, header core.Header) error } type TransformerInitializer func(db *postgres.DB) Transformer