forked from cerc-io/ipld-eth-server
2d684c5aec
- Replaces directly reading from a CSV - Simplifies testing - Should hopefully make it easier to plug in other sources for storage diffs (e.g. differently formatted CSVs, JSON RPC, etc)
34 lines
790 B
Go
34 lines
790 B
Go
package fetcher
|
|
|
|
import (
|
|
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
|
|
"github.com/vulcanize/vulcanizedb/pkg/fs"
|
|
"strings"
|
|
)
|
|
|
|
type IStorageFetcher interface {
|
|
FetchStorageDiffs(chan<- utils.StorageDiffRow, chan<- error)
|
|
}
|
|
|
|
type CsvTailStorageFetcher struct {
|
|
tailer fs.Tailer
|
|
}
|
|
|
|
func NewCsvTailStorageFetcher(tailer fs.Tailer) CsvTailStorageFetcher {
|
|
return CsvTailStorageFetcher{tailer: tailer}
|
|
}
|
|
|
|
func (storageFetcher CsvTailStorageFetcher) FetchStorageDiffs(out chan<- utils.StorageDiffRow, errs chan<- error) {
|
|
t, tailErr := storageFetcher.tailer.Tail()
|
|
if tailErr != nil {
|
|
errs <- tailErr
|
|
}
|
|
for line := range t.Lines {
|
|
row, parseErr := utils.FromStrings(strings.Split(line.Text, ","))
|
|
if parseErr != nil {
|
|
errs <- parseErr
|
|
}
|
|
out <- row
|
|
}
|
|
}
|