Skip to content

Commit

Permalink
add support for passing in the values.Values type into the contract r…
Browse files Browse the repository at this point in the history
…eaders GetLatestValue and QueryKey methods
  • Loading branch information
ettec committed Sep 19, 2024
1 parent 814538b commit cee0014
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
54 changes: 52 additions & 2 deletions core/services/relay/evm/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"
"github.com/smartcontractkit/chainlink-common/pkg/values"

evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
Expand Down Expand Up @@ -168,7 +169,28 @@ func (cr *chainReader) GetLatestValue(ctx context.Context, readName string, conf
return err
}

return binding.GetLatestValue(ctx, common.HexToAddress(address), confidenceLevel, params, returnVal)
ptrToVal, isValue := returnVal.(*values.Value)
if !isValue {
return binding.GetLatestValue(ctx, common.HexToAddress(address), confidenceLevel, params, returnVal)
}

contractType, err := cr.CreateContractType(readName, false)
if err != nil {
return err
}

if err = cr.GetLatestValue(ctx, readName, confidenceLevel, params, contractType); err != nil {
return err
}

wrapped, err := values.Wrap(contractType)
if err != nil {
return err
}

*ptrToVal = wrapped

return nil
}

func (cr *chainReader) BatchGetLatestValues(ctx context.Context, request commontypes.BatchGetLatestValuesRequest) (commontypes.BatchGetLatestValuesResult, error) {
Expand All @@ -195,7 +217,35 @@ func (cr *chainReader) QueryKey(
return nil, err
}

return binding.QueryKey(ctx, common.HexToAddress(address), filter, limitAndSort, sequenceDataType)
_, isValue := sequenceDataType.(*values.Value)
if !isValue {
return binding.QueryKey(ctx, common.HexToAddress(address), filter, limitAndSort, sequenceDataType)
} else {
dataTypeFromReadIdentifier, err := cr.CreateContractType(contract.ReadIdentifier(filter.Key), false)
if err != nil {
return nil, err
}

sequence, err := binding.QueryKey(ctx, common.HexToAddress(address), filter, limitAndSort, dataTypeFromReadIdentifier)
if err != nil {
return nil, err
}

sequenceOfValues := make([]commontypes.Sequence, len(sequence))
for idx, entry := range sequence {
value, err := values.Wrap(entry.Data)
if err != nil {
return nil, err
}
sequenceOfValues[idx] = commontypes.Sequence{
Cursor: entry.Cursor,
Head: entry.Head,
Data: value,
}
}

return sequenceOfValues, nil
}
}

func (cr *chainReader) CreateContractType(readIdentifier string, forEncoding bool) (any, error) {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/smartcontractkit/chainlink/v2

go 1.22.5

replace github.com/smartcontractkit/chainlink-common => ../chainlink-common

require (
github.com/Depado/ginprom v1.8.0
github.com/Masterminds/semver/v3 v3.2.1
Expand Down

0 comments on commit cee0014

Please sign in to comment.