Skip to content

Commit

Permalink
GetLatestValue with events functional
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Feb 20, 2025
1 parent d5462b9 commit d88aa52
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/prometheus/client_golang v1.20.5
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250206215114-fb6c3c35e8e3
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250220121220-38bb770d2435
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250219182448-627ef4d2dd99
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250211162441-3d6cea220efb
github.com/smartcontractkit/libocr v0.0.0-20241223215956-e5b78d8e3919
github.com/stretchr/testify v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405 h1
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405/go.mod h1:UEnHaxkUsfreeA7rR45LMmua1Uen95tOFUR8/AI9BAo=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250206215114-fb6c3c35e8e3 h1:f4F/7OCuMybsPKKXXvLQz+Q1hGq07I1cfoWy5EA9iRg=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250206215114-fb6c3c35e8e3/go.mod h1:Bmwq4lNb5tE47sydN0TKetcLEGbgl+VxHEWp4S0LI60=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250220121220-38bb770d2435 h1:wRN3tiCGcKljlBvY3C6BLi7xlG2ADP9g3js+EfsW8mc=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250220121220-38bb770d2435/go.mod h1:Z2e1ynSJ4pg83b4Qldbmryc5lmnrI3ojOdg1FUloa68=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250219182448-627ef4d2dd99 h1:mrVHrCLT/bfjhLuizS+w4BLwbqAmzsLh9pe3mLb9LnE=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250219182448-627ef4d2dd99/go.mod h1:Z2e1ynSJ4pg83b4Qldbmryc5lmnrI3ojOdg1FUloa68=
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250211162441-3d6cea220efb h1:LWijSyJ2lhppkFLN19EGsLHZXQ5wen2DEk1cyR0tV+o=
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250211162441-3d6cea220efb/go.mod h1:4JqpgFy01LaqG1yM2iFTzwX3ZgcAvW9WdstBZQgPHzU=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rs/zerolog v1.33.0
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250206215114-fb6c3c35e8e3
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250220121220-38bb770d2435
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250220161312-995ae85d9818
github.com/smartcontractkit/chainlink-solana v1.1.2-0.20250213035259-e727e73f6181
github.com/smartcontractkit/chainlink-testing-framework/lib v1.51.0
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.10
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1104,8 +1104,8 @@ github.com/smartcontractkit/chainlink-ccip v0.0.0-20250212131315-e9b53b05b02a h1
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250212131315-e9b53b05b02a/go.mod h1:Hht/OJq/PxC+gnBCIPyzHt4Otsw6mYwUVsmtOqIvlxo=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250206215114-fb6c3c35e8e3 h1:f4F/7OCuMybsPKKXXvLQz+Q1hGq07I1cfoWy5EA9iRg=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250206215114-fb6c3c35e8e3/go.mod h1:Bmwq4lNb5tE47sydN0TKetcLEGbgl+VxHEWp4S0LI60=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250220121220-38bb770d2435 h1:wRN3tiCGcKljlBvY3C6BLi7xlG2ADP9g3js+EfsW8mc=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250220121220-38bb770d2435/go.mod h1:Z2e1ynSJ4pg83b4Qldbmryc5lmnrI3ojOdg1FUloa68=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250220161312-995ae85d9818 h1:qZHSb2a4lnmqJNxav1rYhIl0+1IRPRXKmgFsd9CagT0=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250220161312-995ae85d9818/go.mod h1:Z2e1ynSJ4pg83b4Qldbmryc5lmnrI3ojOdg1FUloa68=
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250128203428-08031923fbe5 h1:CvDfgWoLoYPapOumE/UZCplfCu5oNmy9BuH+6V6+fJ8=
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250128203428-08031923fbe5/go.mod h1:pDZagSGjs9U+l4YIFhveDznMHqxuuz+5vRxvVgpbdr8=
github.com/smartcontractkit/chainlink-feeds v0.1.1 h1:JzvUOM/OgGQA1sOqTXXl52R6AnNt+Wg64sVG+XSA49c=
Expand Down
27 changes: 22 additions & 5 deletions integration-tests/relayinterface/chain_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ func DisableTests(it *SolanaChainComponentsInterfaceTester[*testing.T]) {
ContractReaderBatchGetLatestValue,
ContractReaderBatchGetLatestValueDifferentParamsResultsRetainOrder,
ContractReaderBatchGetLatestValueDifferentParamsResultsRetainOrderMultipleContracts,
// events not yet supported
ContractReaderGetLatestValueGetsLatestForEvent,

// tests to enable
// ContractReaderQueryKeyNotFound,
// ContractReaderQueryKeyReturnsData,
// ContractReaderGetLatestValueGetsLatestForEvent,
ContractReaderGetLatestValueBasedOnConfidenceLevelForEvent,
ContractReaderGetLatestValueReturnsNotFoundWhenNotTriggeredForEvent,
ContractReaderGetLatestValueWithFilteringForEvent,
// query key not fully implemented yet
ContractReaderQueryKeyReturnsDataAsValuesDotValue,
ContractReaderQueryKeyCanLimitResultsWithCursor,

// QueryKeys not implemented
ContractReaderQueryKeysReturnsDataTwoEventTypes,
ContractReaderQueryKeysNotFound,
ContractReaderQueryKeysReturnsData,
Expand Down Expand Up @@ -1057,6 +1059,21 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T
EventName: {
ChainSpecificName: "TestEvent",
ReadType: config.Event,
InputModifications: commoncodec.ModifiersConfig{
&commoncodec.PropertyExtractorConfig{
FieldName: "Data",
EnablePathTraverse: true,
},
&commoncodec.AddressBytesToStringModifierConfig{
Fields: []string{"AccountStruct.AccountStr"},
EnablePathTraverse: true,
},
&commoncodec.ConstrainedBytesToStringModifierConfig{
Fields: []string{"DifferentField", "NestedDynamicStruct.Inner.S"},
EnablePathTraverse: true,
MaxLen: 32,
},
},
OutputModifications: commoncodec.ModifiersConfig{
&commoncodec.PropertyExtractorConfig{FieldName: "Data"},
&commoncodec.AddressBytesToStringModifierConfig{
Expand Down
7 changes: 7 additions & 0 deletions pkg/solana/chainreader/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func doMethodBatchCall(ctx context.Context, lggr logger.Logger, client MultipleA

// map batch call index to key index (some calls are event reads and will be handled by a different binding)
dataMap := make(map[int]int)
eventMap := make(map[int]struct{})

for idx, batchCall := range batch {
rBinding, err := bdRegistry.GetReader(batchCall.Namespace, batchCall.ReadName)
if err != nil {
Expand All @@ -102,6 +104,7 @@ func doMethodBatchCall(ctx context.Context, lggr logger.Logger, client MultipleA
}

results[idx].err = eBinding.GetLatestValue(ctx, batchCall.Params, results[idx].returnVal)
eventMap[idx] = struct{}{}

continue
}
Expand All @@ -120,6 +123,10 @@ func doMethodBatchCall(ctx context.Context, lggr logger.Logger, client MultipleA

// decode batch call results
for idx, batchCall := range batch {
if _, ok := eventMap[idx]; ok {
continue
}

dataIdx, ok := dataMap[idx]
if !ok {
return nil, fmt.Errorf("%w: unexpected data index state", types.ErrInternal)
Expand Down
6 changes: 5 additions & 1 deletion pkg/solana/chainreader/event_read_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (b *eventReadBinding) extractFilterSubkeys(offChainParams any) ([]query.Exp

fieldVal, err := valueForPath(reflect.ValueOf(offChainParams), offChainKey)
if err != nil {
return nil, fmt.Errorf("%w: no value for path %s", types.ErrInternal, b.genericName+"."+offChainKey)
return nil, fmt.Errorf("%w: no value for path %s; err: %w", types.ErrInternal, b.genericName+"."+offChainKey, err)
}

onChainValue, err := b.modifier.TransformToOnChain(fieldVal, itemType)
Expand Down Expand Up @@ -521,6 +521,10 @@ func valueForPath(from reflect.Value, itemType string) (any, error) {

switch from.Kind() {
case reflect.Pointer:
if from.IsNil() {
from = reflect.New(from.Type().Elem())
}

elem, err := valueForPath(from.Elem(), itemType)
if err != nil {
return nil, err
Expand Down

0 comments on commit d88aa52

Please sign in to comment.