Skip to content

Commit

Permalink
Remove code that is out of scope for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed Apr 8, 2024
1 parent 52b7e29 commit fd1bf51
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 191 deletions.
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/prometheus/client_golang v1.17.0
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/chainlink-automation v1.0.2
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240404141006-77085a02ce25
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240408142100-c3cca0ebe47e
github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.2 h1:xsfyuswL15q2YBGQT3qn2SBz6fnSKiSW7XZ8IZQLpnI=
github.com/smartcontractkit/chainlink-automation v1.0.2/go.mod h1:RjboV0Qd7YP+To+OrzHGXaxUxoSONveCoAK2TQ1INLU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240404141006-77085a02ce25 h1:fY2wMtlr/VQxPyVVQdi1jFvQHi0VbDnGGVXzLKOZTOY=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240404141006-77085a02ce25/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240408142100-c3cca0ebe47e h1:sx8eSntndvcCIygSL1EybxvMOtV5VdntvUrxBF21+vY=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240408142100-c3cca0ebe47e/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8 h1:I326nw5GwHQHsLKHwtu5Sb9EBLylC8CfUd7BFAS0jtg=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8/go.mod h1:a65NtrK4xZb01mf0dDNghPkN2wXgcqFQ55ADthVBgMc=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand Down
14 changes: 5 additions & 9 deletions core/services/relay/evm/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ package evm
import (
"context"

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

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

type readBinding interface {
GetLatestValue(ctx context.Context, address common.Address, params, returnVal any) error
QueryOne(ctx context.Context, address common.Address, queryFilter query.Filter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]commontypes.Sequence, error)
Bind(ctx context.Context, address common.Address) error
UnBind(ctx context.Context, address common.Address) error
GetLatestValue(ctx context.Context, params, returnVal any) error
QueryOne(ctx context.Context, queryFilter query.Filter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]commontypes.Sequence, error)
Bind(ctx context.Context, binding commontypes.BoundContract) error
SetCodec(codec commontypes.RemoteCodec)
Register(ctx context.Context, address common.Address) error
Unregister(ctx context.Context, address common.Address) error
UnregisterAll(ctx context.Context) error
Register(ctx context.Context) error
Unregister(ctx context.Context) error
}
24 changes: 1 addition & 23 deletions core/services/relay/evm/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,9 @@ func (b contractBindings) Bind(ctx context.Context, boundContracts []commontypes
return fmt.Errorf("%w: no contract named %s", commontypes.ErrInvalidConfig, bc.Name)
}

address, err := validateEthereumAddress(bc.Address)
if err != nil {
if err := rb.Bind(ctx, bc); err != nil {
return err
}

if err = rb.Bind(ctx, address); err != nil {
return err
}
}
return nil
}

func (b contractBindings) UnBind(ctx context.Context, boundContracts []commontypes.BoundContract) error {
for _, bc := range boundContracts {
rb, rbsExist := b[bc.Name]
if rbsExist {
address, err := validateEthereumAddress(bc.Address)
if err != nil {
return err
}
if err := rb.UnBind(ctx, address); err != nil {
return err
}
delete(b, bc.Name)
}
}
return nil
}
Expand Down
69 changes: 21 additions & 48 deletions core/services/relay/evm/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"context"
"fmt"
"reflect"
"regexp"
"strings"
"time"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"

"github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
Expand All @@ -36,9 +35,8 @@ type chainReader struct {
lp logpoller.LogPoller
client evmclient.Client
contractBindings contractBindings
// TODO merge with contract bindings somehow, or leave as a standalone thing?
parsed *parsedTypes
codec commontypes.RemoteCodec
parsed *parsedTypes
codec commontypes.RemoteCodec
commonservices.StateMachine
}

Expand Down Expand Up @@ -75,40 +73,26 @@ func (cr *chainReader) Name() string { return cr.lggr.Name() }

var _ commontypes.ContractTypeProvider = &chainReader{}

func (cr *chainReader) GetLatestValue(ctx context.Context, contract commontypes.BoundContract, method string, params any, returnVal any) error {
b, err := cr.contractBindings.GetReadBinding(formatKey(contract.Name, method))
func (cr *chainReader) GetLatestValue(ctx context.Context, contractName, method string, params any, returnVal any) error {
b, err := cr.contractBindings.GetReadBinding(formatKey(contractName, method))
if err != nil {
return err
}

address, err := validateEthereumAddress(contract.Address)
if err != nil {
return err
}

return b.GetLatestValue(ctx, address, params, returnVal)
return b.GetLatestValue(ctx, params, returnVal)
}

func (cr *chainReader) Bind(ctx context.Context, bindings []commontypes.BoundContract) error {
return cr.contractBindings.Bind(ctx, bindings)
}

func (cr *chainReader) UnBind(ctx context.Context, bindings []commontypes.BoundContract) error {
return cr.contractBindings.Bind(ctx, bindings)
}

func (cr *chainReader) QueryOne(ctx context.Context, contract commontypes.BoundContract, keyFilter query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]commontypes.Sequence, error) {
b, err := cr.contractBindings.GetReadBinding(keyFilter.Key)
func (cr *chainReader) QueryOne(ctx context.Context, contractName string, filter query.Filter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]commontypes.Sequence, error) {
b, err := cr.contractBindings.GetReadBinding(formatKey(contractName, filter.Key))
if err != nil {
return nil, err
}

address, err := validateEthereumAddress(contract.Address)
if err != nil {
return nil, err
}

return b.QueryOne(ctx, address, keyFilter.Filter, limitAndSort, sequenceDataType)
return b.QueryOne(ctx, filter, limitAndSort, sequenceDataType)
}

func (cr *chainReader) init(chainContractReaders map[string]types.ChainContractReader) error {
Expand Down Expand Up @@ -141,17 +125,15 @@ func (cr *chainReader) init(chainContractReaders map[string]types.ChainContractR

func (cr *chainReader) Start(ctx context.Context) error {
return cr.StartOnce("ChainReader", func() error {
// TODO Seems like this is not needed since register requries addresses and addresses are piped through Bind.
//return cr.contractBindings.ForEach(ctx, readBinding.Register)
return nil
return cr.contractBindings.ForEach(ctx, readBinding.Register)
})
}

func (cr *chainReader) Close() error {
return cr.StopOnce("ChainReader", func() error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
return cr.contractBindings.ForEach(ctx, readBinding.UnregisterAll)
return cr.contractBindings.ForEach(ctx, readBinding.Unregister)
})
}

Expand All @@ -160,11 +142,7 @@ func (cr *chainReader) HealthReport() map[string]error {
return map[string]error{cr.Name(): nil}
}

func (cr *chainReader) CreateContractType(contractName, methodName string, forEncoding bool) (any, error) {
return cr.codec.CreateType(wrapItemType(contractName, methodName, forEncoding), forEncoding)
}

func (cr *chainReader) CreateContractTypeByKey(key string, forEncoding bool) (any, error) {
func (cr *chainReader) CreateContractType(key string, forEncoding bool) (any, error) {
rb, err := cr.contractBindings.GetReadBinding(key)
if err != nil {
return nil, err
Expand All @@ -187,7 +165,8 @@ func wrapItemType(contractName, methodName string, isParams bool) string {
}

func (cr *chainReader) addMethod(
contractName, methodName string,
contractName,
methodName string,
abi abi.ABI,
chainReaderDefinition types.ChainReaderDefinition) error {
method, methodExists := abi.Methods[chainReaderDefinition.ChainSpecificName]
Expand Down Expand Up @@ -250,12 +229,10 @@ func (cr *chainReader) addEvent(contractName, eventName string, a abi.ABI, chain
codecTopicInfo: codecTopicInfo,
topicsInfo: make(map[string]topicInfo),
eventDataWords: chainReaderDefinition.GenericDataWordNames,
id: wrapItemType(contractName, eventName, false) + uuid.NewString(),
}

for genericDataWordName := range eb.eventDataWords {
// this way querying by key/s values comparison can find its bindings
cr.contractBindings.AddReadBinding(formatKey(contractName, eventName, genericDataWordName), eb)
}
cr.contractBindings.AddReadBinding(formatKey(contractName, eventName), eb)

// set topic mappings for QueryKeys
for topicIndex, topic := range event.Inputs {
Expand All @@ -270,7 +247,11 @@ func (cr *chainReader) addEvent(contractName, eventName string, a abi.ABI, chain
cr.contractBindings.AddReadBinding(formatKey(contractName, eventName, genericTopicName), eb)
}

cr.contractBindings.AddReadBinding(formatKey(contractName, eventName), eb)
for genericDataWordName := range eb.eventDataWords {
// this way querying by key/s values comparison can find its bindings
cr.contractBindings.AddReadBinding(formatKey(contractName, eventName, genericDataWordName), eb)
}

return cr.addDecoderDef(contractName, eventName, event.Inputs, chainReaderDefinition)
}

Expand Down Expand Up @@ -397,11 +378,3 @@ func setupEventInput(event abi.Event, def types.ChainReaderDefinition) ([]abi.Ar

return filterArgs, types.NewCodecEntry(inputArgs, nil, nil), indexArgNames
}

func validateEthereumAddress(address string) (common.Address, error) {
re := regexp.MustCompile("^0x[0-9a-fA-F]{40}$")
if !re.MatchString(address) {
return common.Address{}, fmt.Errorf("address %s is not a valid ethereum address", address)
}
return common.HexToAddress(address), nil
}
16 changes: 8 additions & 8 deletions core/services/relay/evm/dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ func (f *EventFilter) Accept(visitor query.Visitor) {
}

type EventByIndexFilter struct {
Address common.Address
EventSig common.Hash
Topic uint64
ValueComparators []query.ValueComparator
Address common.Address
EventSig common.Hash
Topic uint64
ValueComparers []query.ValueComparer
}

func NewEventByIndexFilter(address common.Address, eventSig common.Hash, topicIndex uint64, valueComparators []query.ValueComparator) query.Expression {
func NewEventByIndexFilter(address common.Address, eventSig common.Hash, topicIndex uint64, valueComparators []query.ValueComparer) query.Expression {
var eventByIndexFilter *EventByIndexFilter
eventByIndexFilter.Address = address
eventByIndexFilter.EventSig = eventSig
eventByIndexFilter.Topic = topicIndex
eventByIndexFilter.ValueComparators = valueComparators
eventByIndexFilter.ValueComparers = valueComparators

return query.Expression{Primitive: eventByIndexFilter}
}
Expand All @@ -57,10 +57,10 @@ type EventByWordFilter struct {
Address common.Address
EventSig common.Hash
WordIndex uint8
ValueComparators []query.ValueComparator
ValueComparators []query.ValueComparer
}

func NewEventByWordFilter(address common.Address, eventSig common.Hash, wordIndex uint8, valueComparators []query.ValueComparator) query.Expression {
func NewEventByWordFilter(address common.Address, eventSig common.Hash, wordIndex uint8, valueComparators []query.ValueComparer) query.Expression {
var eventByIndexFilter *EventByWordFilter
eventByIndexFilter.Address = address
eventByIndexFilter.EventSig = eventSig
Expand Down
Loading

0 comments on commit fd1bf51

Please sign in to comment.