cic-chain-events/internal/filter/address_filter.go
Mohammed Sohail 2bbc05bb45
major refactor: sig ch, remove conf settings, jetstream pub, ci
* This is a major refactor and includes general improvements around

- context cancellation
- build settings
- jetstream pub sub
- logging
- docker builds
- conf loading
2023-03-08 14:30:40 +00:00

44 lines
803 B
Go

package filter
import (
"context"
"sync"
"github.com/grassrootseconomics/cic-chain-events/pkg/fetch"
"github.com/zerodha/logf"
)
type (
AddressFilterOpts struct {
Cache *sync.Map
Logg logf.Logger
SystemAddress string
}
AddressFilter struct {
cache *sync.Map
logg logf.Logger
systemAddress string
}
)
func NewAddressFilter(o AddressFilterOpts) Filter {
return &AddressFilter{
cache: o.Cache,
logg: o.Logg,
systemAddress: o.SystemAddress,
}
}
func (f *AddressFilter) Execute(_ context.Context, transaction fetch.Transaction) (bool, error) {
if transaction.From.Address == f.systemAddress {
return true, nil
}
if _, found := f.cache.Load(transaction.To.Address); found {
return true, nil
}
return false, nil
}