Skip to content

Commit

Permalink
add secondary blacklist feature (#2825)
Browse files Browse the repository at this point in the history
Co-authored-by: Trajan0x <[email protected]>
  • Loading branch information
trajan0x and trajan0x authored Jun 30, 2024
1 parent 222ffd4 commit d0f1508
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions contrib/screener-api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Config struct {
RiskLevels []string `yaml:"risk-levels"`
// Whitelist is a list of addresses to whitelist
Whitelist []string `yaml:"whitelist"`
// Blacklist is a list of addresses to blacklist
Blacklist []string `yaml:"blacklist"`
}

// DatabaseConfig represents the configuration for the database.
Expand Down
14 changes: 9 additions & 5 deletions contrib/screener-api/screener/screener.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type screenerImpl struct {
cfg config.Config
client chainalysis.Client
whitelist map[string]bool
blacklistCache map[string]bool
blacklist map[string]bool
blacklistCacheMux sync.RWMutex
requestMux mapmutex.StringMapMutex
}
Expand All @@ -74,12 +74,16 @@ func NewScreener(ctx context.Context, cfg config.Config, metricHandler metrics.H

screener.client = chainalysis.NewClient(metricHandler, cfg.RiskLevels, cfg.ChainalysisKey, core.GetEnv("CHAINALYSIS_URL", cfg.ChainalysisURL))

screener.blacklistCache = make(map[string]bool)
screener.blacklist = make(map[string]bool)
screener.whitelist = make(map[string]bool)
for _, item := range cfg.Whitelist {
screener.whitelist[strings.ToLower(item)] = true
}

for _, item := range cfg.Blacklist {
screener.blacklist[strings.ToLower(item)] = true
}

dbType, err := dbcommon.DBTypeFromString(cfg.Database.Type)
if err != nil {
return nil, fmt.Errorf("could not get db type: %w", err)
Expand Down Expand Up @@ -166,7 +170,7 @@ func (s *screenerImpl) fetchBlacklist(ctx context.Context) {
s.blacklistCacheMux.Lock()
defer s.blacklistCacheMux.Unlock()
for _, item := range blacklist {
s.blacklistCache[strings.ToLower(item)] = true
s.blacklist[strings.ToLower(item)] = true
}
}

Expand Down Expand Up @@ -250,7 +254,7 @@ func (s *screenerImpl) isDBBlacklisted(ctx context.Context, address string) (boo
func (s *screenerImpl) isBlacklistedCache(address string) bool {
s.blacklistCacheMux.RLock()
defer s.blacklistCacheMux.RUnlock()
return s.blacklistCache[address]
return s.blacklist[address]
}

// @dev Protected Method
Expand Down Expand Up @@ -298,7 +302,7 @@ func (s *screenerImpl) blacklistAddress(c *gin.Context) {

s.blacklistCacheMux.Lock()
defer s.blacklistCacheMux.Unlock()
s.blacklistCache[blacklistBody.Data.Address] = true
s.blacklist[blacklistBody.Data.Address] = true

switch blacklistBody.Type {
case "create":
Expand Down

0 comments on commit d0f1508

Please sign in to comment.