mirror of
https://github.com/grassrootseconomics/cic-chain-events.git
synced 2024-12-22 19:57:31 +01:00
refactor: pass struct through pipeline fllters
This commit is contained in:
parent
85ef2ffaac
commit
4b2eb7b018
@ -25,7 +25,7 @@ func NewAddressFilter(o AddressFilterOpts) Filter {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *AddressFilter) Execute(_ context.Context, transaction *fetch.Transaction) (bool, error) {
|
||||
func (f *AddressFilter) Execute(_ context.Context, transaction fetch.Transaction) (bool, error) {
|
||||
if _, found := f.cache.Load(transaction.To.Address); found {
|
||||
return true, nil
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func (s *AddressFilterSuite) TestAddresses() {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
next, err := s.filter.Execute(context.Background(), &test.transactionData)
|
||||
next, err := s.filter.Execute(context.Background(), test.transactionData)
|
||||
s.NoError(err)
|
||||
s.Equal(test.want, next)
|
||||
}
|
||||
|
@ -8,5 +8,5 @@ import (
|
||||
|
||||
// Filter defines a read only filter which must return next as true/false or an error
|
||||
type Filter interface {
|
||||
Execute(ctx context.Context, inputTransaction *fetch.Transaction) (next bool, err error)
|
||||
Execute(ctx context.Context, inputTransaction fetch.Transaction) (next bool, err error)
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func NewGasFilter(o GasFilterOpts) Filter {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *GasFilter) Execute(_ context.Context, transaction *fetch.Transaction) (bool, error) {
|
||||
func (f *GasFilter) Execute(_ context.Context, transaction fetch.Transaction) (bool, error) {
|
||||
switch transaction.InputData[:10] {
|
||||
case "0x63e4bff4":
|
||||
var (
|
||||
|
@ -46,7 +46,7 @@ func NewTransferFilter(o TransferFilterOpts) Filter {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *TransferFilter) Execute(_ context.Context, transaction *fetch.Transaction) (bool, error) {
|
||||
func (f *TransferFilter) Execute(_ context.Context, transaction fetch.Transaction) (bool, error) {
|
||||
switch transaction.InputData[:10] {
|
||||
case "0xa9059cbb":
|
||||
var (
|
||||
|
@ -66,7 +66,7 @@ func (s *TransferFilterSuite) TestTranfserInputs() {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
next, err := s.filter.Execute(context.Background(), &test.transactionData)
|
||||
next, err := s.filter.Execute(context.Background(), test.transactionData)
|
||||
s.NoError(err)
|
||||
s.Equal(test.want, next)
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func (md *Pipeline) Run(ctx context.Context, blockNumber uint64) error {
|
||||
|
||||
for _, tx := range fetchResp.Data.Block.Transactions {
|
||||
for _, filter := range md.filters {
|
||||
next, err := filter.Execute(ctx, &tx)
|
||||
next, err := filter.Execute(ctx, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user