Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Feb 6, 2025
1 parent 0a862d4 commit 25c59c9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
5 changes: 2 additions & 3 deletions pkg/solana/chainreader/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func doMethodBatchCall(ctx context.Context, client MultipleAccountGetter, bindin
return nil, fmt.Errorf("failed to get address for %s account read: %w", call.ReadName, err)
}

lvBinding, ok := binding.(latestValueBinding)
eBinding, ok := binding.(eventBinding)
if ok {
results[idx] = batchResultWithErr{
address: key.String(),
Expand All @@ -60,8 +60,7 @@ func doMethodBatchCall(ctx context.Context, client MultipleAccountGetter, bindin
returnVal: call.ReturnVal,
}

// is an event read
results[idx].err = lvBinding.GetLatestValue(ctx, call.Params, results[idx].returnVal)
results[idx].err = eBinding.GetLatestValue(ctx, call.Params, results[idx].returnVal)

continue
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/solana/chainreader/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ type readBinding interface {
Decode(context.Context, []byte, any) error
}

type latestValueBinding interface {
type eventBinding interface {
GetLatestValue(_ context.Context, params, returnVal any) error
}

type queryBinding interface {
QueryKey(context.Context, query.KeyFilter, query.LimitAndSort, any) ([]types.Sequence, error)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/solana/chainreader/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,22 @@ func (s *ContractReaderService) QueryKey(ctx context.Context, contract types.Bou
return nil, err
}

qBinding, ok := binding.(queryBinding)
eBinding, ok := binding.(eventBinding)
if !ok {
return nil, fmt.Errorf("%w: invalid binding type for %s", types.ErrInvalidType, contract.Name)
}

_, isValuePtr := sequenceDataType.(*values.Value)
if !isValuePtr {
return qBinding.QueryKey(ctx, filter, limitAndSort, sequenceDataType)
return eBinding.QueryKey(ctx, filter, limitAndSort, sequenceDataType)
}

dataTypeFromReadIdentifier, err := s.CreateContractType(contract.ReadIdentifier(filter.Key), false)
if err != nil {
return nil, err
}

sequence, err := qBinding.QueryKey(ctx, filter, limitAndSort, dataTypeFromReadIdentifier)
sequence, err := eBinding.QueryKey(ctx, filter, limitAndSort, dataTypeFromReadIdentifier)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/solana/chainreader/event_read_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ func (b *eventReadBinding) normalizeParams(value any, itemType string) (any, err
return offChain, nil
}

func (b *eventReadBinding) extractFilterSubkeys(offChainValue any) (query.Expression, error) {
func (b *eventReadBinding) extractFilterSubkeys(offChainParams any) (query.Expression, error) {
var expressions []query.Expression

for offChainKey, idx := range b.indexedSubKeys {
itemType := codec.WrapItemType(true, b.namespace, b.genericName+"."+offChainKey)

onChainValue, err := b.modifier.TransformToOnChain(offChainValue, itemType)
onChainValue, err := b.modifier.TransformToOnChain(offChainParams, itemType)
if err != nil {
return query.Expression{}, fmt.Errorf("%w: failed to apply on-chain transformation for key %s", types.ErrInternal, offChainKey)
}
Expand Down

0 comments on commit 25c59c9

Please sign in to comment.