feat: refactor historical syncer

This commit is contained in:
2024-04-19 16:46:23 +08:00
parent f981007e71
commit 9782b3c9c5
9 changed files with 80 additions and 58 deletions

View File

@@ -10,7 +10,7 @@ import (
"github.com/grassrootseconomics/w3-celo/module/eth"
)
func bootstrapAllGESmartContracts(ctx context.Context, registries []string, chain *chain.Chain, cache Cache) (WatchableIndex, error) {
func bootstrapGESmartContracts(ctx context.Context, registries []string, chain *chain.Chain, cache Cache) (WatchableIndex, error) {
var (
watchableIndex = make(WatchableIndex)
)

View File

@@ -25,6 +25,7 @@ type (
CacheType string
Registries []string
Blacklist []string
Watchlist []string
}
WatchableIndex map[string]bool
@@ -47,7 +48,7 @@ func New(o CacheOpts) (Cache, error) {
cache = NewMapCache()
}
watchableIndex, err := bootstrapAllGESmartContracts(
watchableIndex, err := bootstrapGESmartContracts(
context.Background(),
o.Registries,
o.Chain,
@@ -56,12 +57,16 @@ func New(o CacheOpts) (Cache, error) {
if err != nil {
return nil, err
}
// We only watch the token and pool indexes
// If at some point we want to eatch the user index, this line should be removed
cache.SetWatchableIndex(watchableIndex)
for _, address := range o.Watchlist {
cache.Add(address)
}
for _, address := range o.Blacklist {
cache.Remove(address)
}
o.Logg.Debug("cache bootstrap complete", "cached_addresses", cache.Size())
return cache, nil