Skip to content

Commit

Permalink
remove unecessary exports
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Apr 12, 2024
1 parent a979e0d commit 847e26f
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 91 deletions.
2 changes: 1 addition & 1 deletion core/chains/evm/logpoller/disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ func (d disabled) LogsDataWordBetween(ctx context.Context, eventSig common.Hash,
return nil, ErrDisabled
}

func (d disabled) FilteredLogs(_ context.Context, _ query.KeyFilter, _ query.LimitAndSort, _ *EventFilterMapper) ([]Log, error) {
func (d disabled) FilteredLogs(_ context.Context, _ query.KeyFilter, _ query.LimitAndSort, _ EventFilterMapper) ([]Log, error) {
return nil, ErrDisabled
}
47 changes: 24 additions & 23 deletions core/chains/evm/logpoller/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,52 @@ import (
"strings"

"github.com/ethereum/go-ethereum/common"

"github.com/smartcontractkit/chainlink-common/pkg/types/query"
)

type Select struct {
type qSelect struct {
Fields []string
Table string
Limit query.Limit
}

func (s Select) String() string {
func (q qSelect) String() string {
fields := "*"
fieldsOut := s.Fields
fieldsOut := q.Fields

if hasCursorLimit(s.Limit) {
if hasCursorLimit(q.Limit) {
fieldsOut = append(fieldsOut, fmt.Sprintf("%s AS %s", cursorFieldName, cursorFieldAlias))
}

if len(fieldsOut) > 0 {
fields = strings.Join(fieldsOut, ",")
}

return fmt.Sprintf("SELECT %s FROM %s", fields, s.Table)
return fmt.Sprintf("SELECT %s FROM %s", fields, q.Table)
}

type Where struct {
type qWhere struct {
ChainID *big.Int
Address common.Address
Op query.BoolOperator
Expressions []query.Expression
Limit query.Limit
}

func (w Where) String() (string, map[string]any) {
func (q qWhere) String() (string, map[string]any) {
args := newNamedArgs()

segment := fmt.Sprintf(
"WHERE evm_chain_id = %s AND address = %s AND %s",
args.Add("evm_chain_id", w.ChainID.Uint64()),
args.Add("address", w.Address),
makeExpression(w.Op, w.Expressions, args, w.ChainID),
args.Add("evm_chain_id", q.ChainID.Uint64()),
args.Add("address", q.Address),
makeExpression(q.Op, q.Expressions, args, q.ChainID),
)

if hasCursorLimit(w.Limit) {
if hasCursorLimit(q.Limit) {
var op string
switch *w.Limit.CursorDirection {
switch *q.Limit.CursorDirection {
case query.Following:
op = ">"
case query.Previous:
Expand All @@ -64,23 +65,23 @@ func (w Where) String() (string, map[string]any) {
segment,
cursorFieldAlias,
op,
args.Add(cursorFieldAlias, *w.Limit.Cursor),
args.Add(cursorFieldAlias, *q.Limit.Cursor),
)
}

return segment, args.Values()
}

type Order []query.SortBy
type qOrder []query.SortBy

func (o Order) String() string {
if len(o) == 0 {
func (q qOrder) String() string {
if len(q) == 0 {
return ""
}

sort := make([]string, len(o))
sort := make([]string, len(q))

for idx, sorted := range o {
for idx, sorted := range q {
var name string

switch sorted.(type) {
Expand All @@ -98,14 +99,14 @@ func (o Order) String() string {
return fmt.Sprintf("ORDER BY (%s)", strings.Join(sort, ", "))
}

type Limit query.Limit
type qLimit query.Limit

func (l Limit) String() string {
if !hasCursorLimit(query.Limit(l)) && l.Count == 0 {
func (q qLimit) String() string {
if !hasCursorLimit(query.Limit(q)) && q.Count == 0 {
return ""
}

return fmt.Sprintf("LIMIT %d", l.Count)
return fmt.Sprintf("LIMIT %d", q.Count)
}

func hasCursorLimit(limit query.Limit) bool {
Expand All @@ -128,7 +129,7 @@ func makeExpression(op query.BoolOperator, expressions []query.Expression, args

for _, exp := range expressions {
if exp.IsPrimitive() {
v := &PgDSLParser{
v := &pgDSLParser{
chainID: chainID,
args: args,
}
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type LogPoller interface {
LogsDataWordBetween(ctx context.Context, eventSig common.Hash, address common.Address, wordIndexMin, wordIndexMax int, wordValue common.Hash, confs evmtypes.Confirmations) ([]Log, error)

// chainlink-common query filtering
FilteredLogs(ctx context.Context, filter query.KeyFilter, sortAndLimit query.LimitAndSort, mapper *EventFilterMapper) ([]Log, error)
FilteredLogs(ctx context.Context, filter query.KeyFilter, sortAndLimit query.LimitAndSort, mapper EventFilterMapper) ([]Log, error)
}

type LogPollerTest interface {
Expand Down Expand Up @@ -1345,6 +1345,6 @@ func EvmWord(i uint64) common.Hash {
return common.BytesToHash(b)
}

func (lp *logPoller) FilteredLogs(ctx context.Context, queryFilter query.KeyFilter, sortAndLimit query.LimitAndSort, mapper *EventFilterMapper) ([]Log, error) {
func (lp *logPoller) FilteredLogs(ctx context.Context, queryFilter query.KeyFilter, sortAndLimit query.LimitAndSort, mapper EventFilterMapper) ([]Log, error) {
return lp.orm.FilteredLogs(ctx, queryFilter, sortAndLimit, mapper)
}
50 changes: 25 additions & 25 deletions core/chains/evm/logpoller/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (m *EventFilterMapper) remap(filter query.KeyFilter) (query.KeyFilter, erro
}

if addEventSigFilter {
remapped.Expressions = append(remapped.Expressions, NewEventBySigFilter(m.Hash))
remapped.Expressions = append(remapped.Expressions, newEventBySigFilter(m.Hash))
}

return remapped, nil
Expand Down Expand Up @@ -81,97 +81,97 @@ func (m *EventFilterMapper) remapPrimitive(key string, expression query.Expressi
// remap chain agnostic primitives to chain specific
switch primitive := expression.Primitive.(type) {
case *query.ConfirmationsPrimitive:
remapped, err := NewFinalityFilter(primitive)
remapped, err := newFinalityFilter(primitive)

return remapped, false, err
case *query.ComparerPrimitive:
if val, ok := m.EventDataWords[primitive.Name]; ok {
return NewEventByWordFilter(m.Hash, val, primitive.ValueComparers), true, nil
return newEventByWordFilter(m.Hash, val, primitive.ValueComparers), true, nil
}

return NewEventByTopicFilter(m.Hash, m.Topics[key].Index, primitive.ValueComparers), true, nil
return newEventByTopicFilter(m.Hash, m.Topics[key].Index, primitive.ValueComparers), true, nil
default:
return expression, false, nil
}
}

type EventBySigFilter struct {
type eventBySigFilter struct {
EventSig common.Hash
}

func NewEventBySigFilter(eventSig common.Hash) query.Expression {
return query.Expression{Primitive: &EventBySigFilter{
func newEventBySigFilter(eventSig common.Hash) query.Expression {
return query.Expression{Primitive: &eventBySigFilter{
EventSig: eventSig,
}}
}

func (f *EventBySigFilter) Accept(visitor query.Visitor) {
func (f *eventBySigFilter) Accept(visitor query.Visitor) {
switch v := visitor.(type) {
case *PgDSLParser:
case *pgDSLParser:
v.VisitEventBySigFilter(f)
}
}

type FinalityFilter struct {
type finalityFilter struct {
Confs evmtypes.Confirmations
}

func NewFinalityFilter(filter *query.ConfirmationsPrimitive) (query.Expression, error) {
func newFinalityFilter(filter *query.ConfirmationsPrimitive) (query.Expression, error) {
switch filter.ConfirmationLevel {
case query.Finalized:
return query.Expression{Primitive: &FinalityFilter{evmtypes.Finalized}}, nil
return query.Expression{Primitive: &finalityFilter{evmtypes.Finalized}}, nil
case query.Unconfirmed:
return query.Expression{Primitive: &FinalityFilter{evmtypes.Unconfirmed}}, nil
return query.Expression{Primitive: &finalityFilter{evmtypes.Unconfirmed}}, nil
default:
return query.Expression{}, fmt.Errorf("invalid finality confirmations filter value %v", filter.ConfirmationLevel)
}
}

func (f *FinalityFilter) Accept(visitor query.Visitor) {
func (f *finalityFilter) Accept(visitor query.Visitor) {
switch v := visitor.(type) {
case *PgDSLParser:
case *pgDSLParser:
v.VisitFinalityFilter(f)
}
}

type EventByWordFilter struct {
type eventByWordFilter struct {
EventSig common.Hash
WordIndex uint8
ValueComparers []query.ValueComparer
}

func NewEventByWordFilter(eventSig common.Hash, wordIndex uint8, valueComparers []query.ValueComparer) query.Expression {
return query.Expression{Primitive: &EventByWordFilter{
func newEventByWordFilter(eventSig common.Hash, wordIndex uint8, valueComparers []query.ValueComparer) query.Expression {
return query.Expression{Primitive: &eventByWordFilter{
EventSig: eventSig,
WordIndex: wordIndex,
ValueComparers: valueComparers,
}}
}

func (f *EventByWordFilter) Accept(visitor query.Visitor) {
func (f *eventByWordFilter) Accept(visitor query.Visitor) {
switch v := visitor.(type) {
case *PgDSLParser:
case *pgDSLParser:
v.VisitEventByWordFilter(f)
}
}

type EventByTopicFilter struct {
type eventByTopicFilter struct {
EventSig common.Hash
Topic uint64
ValueComparers []query.ValueComparer
}

func NewEventByTopicFilter(eventSig common.Hash, topicIndex uint64, valueComparers []query.ValueComparer) query.Expression {
return query.Expression{Primitive: &EventByTopicFilter{
func newEventByTopicFilter(eventSig common.Hash, topicIndex uint64, valueComparers []query.ValueComparer) query.Expression {
return query.Expression{Primitive: &eventByTopicFilter{
EventSig: eventSig,
Topic: topicIndex,
ValueComparers: valueComparers,
}}
}

func (f *EventByTopicFilter) Accept(visitor query.Visitor) {
func (f *eventByTopicFilter) Accept(visitor query.Visitor) {
switch v := visitor.(type) {
case *PgDSLParser:
case *pgDSLParser:
v.VisitEventTopicsByValueFilter(f)
}
}
8 changes: 4 additions & 4 deletions core/chains/evm/logpoller/mocks/log_poller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 11 additions & 18 deletions core/chains/evm/logpoller/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package logpoller
import (
"context"
"database/sql"
"errors"
"fmt"
"math/big"
"strings"
Expand Down Expand Up @@ -63,7 +62,7 @@ type ORM interface {
SelectLogsDataWordBetween(ctx context.Context, address common.Address, eventSig common.Hash, wordIndexMin int, wordIndexMax int, wordValue common.Hash, confs evmtypes.Confirmations) ([]Log, error)

// FilteredLogs accepts chainlink-common filtering DSL.
FilteredLogs(ctx context.Context, filter query.KeyFilter, sortAndLimit query.LimitAndSort, mapper *EventFilterMapper) ([]Log, error)
FilteredLogs(ctx context.Context, filter query.KeyFilter, sortAndLimit query.LimitAndSort, mapper EventFilterMapper) ([]Log, error)
}

type DbORM struct {
Expand Down Expand Up @@ -973,21 +972,15 @@ func (o *DbORM) SelectIndexedLogsWithSigsExcluding(ctx context.Context, sigA, si
return logs, nil
}

func (o *DbORM) FilteredLogs(ctx context.Context, filter query.KeyFilter, limit query.LimitAndSort, mapper *EventFilterMapper) ([]Log, error) {
if mapper == nil {
return nil, errors.New("mapper required for setting contract address")
}

if mapper != nil {
newFilter, err := mapper.remap(filter)
if err != nil {
return nil, err
}
func (o *DbORM) FilteredLogs(ctx context.Context, filter query.KeyFilter, limit query.LimitAndSort, mapper EventFilterMapper) ([]Log, error) {
var err error

filter = newFilter
filter, err = mapper.remap(filter)
if err != nil {
return nil, err
}

where := Where{
where := qWhere{
ChainID: o.chainID,
Address: mapper.Address,
Op: query.AND,
Expand All @@ -998,21 +991,21 @@ func (o *DbORM) FilteredLogs(ctx context.Context, filter query.KeyFilter, limit
whereSegment, args := where.String()
qs := fmt.Sprintf(
"%s %s %s %s",
Select{
qSelect{
Table: evmLogsTableName,
Limit: limit.Limit,
},
whereSegment,
Order(limit.SortBy),
Limit(limit.Limit),
qOrder(limit.SortBy),
qLimit(limit.Limit),
)

var logs []Log
query, sqlArgs, err := o.db.BindNamed(qs, args)
if err != nil {
return nil, err
}

var logs []Log
if err := o.db.SelectContext(ctx, &logs, query, sqlArgs...); err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 847e26f

Please sign in to comment.