-
Notifications
You must be signed in to change notification settings - Fork 25
Solana: Add GetFiltersNames and proto helpers #1801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
silaslenihan
wants to merge
18
commits into
main
Choose a base branch
from
solana-logtrigger-cap-bump
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
05a8719
add solana devnet to defaults
Unheilbar c7dd5bc
add solana devnet to allowed chains
Unheilbar abda6ce
fix tests
Unheilbar 6c9ccc0
Bump solana capability logtrigger
silaslenihan bdc12ea
replace devnet with testnet selector
Unheilbar fc05c52
run tests
Unheilbar 5c11c19
Merge branch 'main' into PLEX-1920_add_defaults
Unheilbar 465d52f
Merge branch 'main' into solana-logtrigger-cap-bump
silaslenihan 5100fdf
added solana-devnet to allowlist
silaslenihan 2b52746
fix converters
Unheilbar 9346914
Merge branch 'PLEX-1920_add_defaults' into solana-logtrigger-cap-bump
silaslenihan 3d57610
Merge branch 'main' into solana-logtrigger-cap-bump
silaslenihan 1ef6688
bump protos and generate
silaslenihan 03a5a6d
Added GetFiltersNames to solService
silaslenihan 10d0c60
Merge branch 'main' into solana-logtrigger-cap-bump
silaslenihan 6223933
return error on comparator conversion
silaslenihan 9950beb
Merge branch 'main' into solana-logtrigger-cap-bump
silaslenihan 450c52e
throw error on failed cast
silaslenihan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
157 changes: 157 additions & 0 deletions
157
pkg/capabilities/v2/chain-capabilities/solana/proto_helpers.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| package solana | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| chainsolana "github.com/smartcontractkit/chainlink-common/pkg/chains/solana" | ||
| typesolana "github.com/smartcontractkit/chainlink-common/pkg/types/chains/solana" | ||
| "github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives" | ||
| ) | ||
|
|
||
| // ConvertComparisonOperatorFromProto converts a proto ComparisonOperator to primitives.ComparisonOperator | ||
| func ConvertComparisonOperatorFromProto(op ComparisonOperator) (primitives.ComparisonOperator, error) { | ||
| switch op { | ||
| case ComparisonOperator_COMPARISON_OPERATOR_EQ: | ||
| return primitives.Eq, nil | ||
| case ComparisonOperator_COMPARISON_OPERATOR_NEQ: | ||
| return primitives.Neq, nil | ||
| case ComparisonOperator_COMPARISON_OPERATOR_GT: | ||
| return primitives.Gt, nil | ||
| case ComparisonOperator_COMPARISON_OPERATOR_LT: | ||
| return primitives.Lt, nil | ||
| case ComparisonOperator_COMPARISON_OPERATOR_GTE: | ||
| return primitives.Gte, nil | ||
| case ComparisonOperator_COMPARISON_OPERATOR_LTE: | ||
| return primitives.Lte, nil | ||
| default: | ||
| return 0, fmt.Errorf("unknown comparison operator: %s", op) | ||
| } | ||
| } | ||
|
|
||
| // ConvertComparisonOperatorToProto converts a primitives.ComparisonOperator to proto ComparisonOperator | ||
| func ConvertComparisonOperatorToProto(op primitives.ComparisonOperator) (ComparisonOperator, error) { | ||
| switch op { | ||
| case primitives.Eq: | ||
| return ComparisonOperator_COMPARISON_OPERATOR_EQ, nil | ||
| case primitives.Neq: | ||
| return ComparisonOperator_COMPARISON_OPERATOR_NEQ, nil | ||
| case primitives.Gt: | ||
| return ComparisonOperator_COMPARISON_OPERATOR_GT, nil | ||
| case primitives.Lt: | ||
| return ComparisonOperator_COMPARISON_OPERATOR_LT, nil | ||
| case primitives.Gte: | ||
| return ComparisonOperator_COMPARISON_OPERATOR_GTE, nil | ||
| case primitives.Lte: | ||
| return ComparisonOperator_COMPARISON_OPERATOR_LTE, nil | ||
| default: | ||
| return 0, fmt.Errorf("unknown comparison operator: %s", op) | ||
| } | ||
| } | ||
|
|
||
| // ConvertValueComparatorsFromProto converts proto ValueComparator slice to primitives.ValueComparator slice | ||
| func ConvertValueComparatorsFromProto(comparers []*ValueComparator) ([]primitives.ValueComparator, error) { | ||
| if comparers == nil { | ||
| return nil, nil | ||
| } | ||
| result := make([]primitives.ValueComparator, len(comparers)) | ||
| for i, c := range comparers { | ||
| if c != nil { | ||
| operator, err := ConvertComparisonOperatorFromProto(c.Operator) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to convert comparison operator: %w", err) | ||
| } | ||
| result[i] = primitives.ValueComparator{ | ||
| Value: c.Value, // []byte is compatible with any | ||
| Operator: operator, | ||
| } | ||
| } | ||
| } | ||
| return result, nil | ||
| } | ||
|
|
||
| // ConvertValueComparatorsToProto converts primitives.ValueComparator slice to proto ValueComparator slice | ||
| func ConvertValueComparatorsToProto(comparers []primitives.ValueComparator) ([]*ValueComparator, error) { | ||
| if comparers == nil { | ||
| return nil, nil | ||
| } | ||
| result := make([]*ValueComparator, len(comparers)) | ||
| for i, c := range comparers { | ||
| // Handle the Value field which could be any type, convert to []byte if possible | ||
| var valueBytes []byte | ||
| if b, ok := c.Value.([]byte); ok { | ||
| valueBytes = b | ||
| } else { | ||
| return nil, fmt.Errorf("value is not a []byte: %T", c.Value) | ||
| } | ||
| operator, err := ConvertComparisonOperatorToProto(c.Operator) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to convert comparison operator: %w", err) | ||
| } | ||
| result[i] = &ValueComparator{ | ||
| Value: valueBytes, | ||
| Operator: operator, | ||
| } | ||
| } | ||
| return result, nil | ||
| } | ||
|
|
||
| // ConvertLogFromProto converts a proto Log to typesolana.Log | ||
| func ConvertLogFromProto(p *Log) (*typesolana.Log, error) { | ||
| if p == nil { | ||
| return nil, nil | ||
| } | ||
|
|
||
| blockHash, err := chainsolana.ConvertHashFromProto(p.BlockHash) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to convert block hash: %w", err) | ||
| } | ||
|
|
||
| address, err := chainsolana.ConvertPublicKeyFromProto(p.Address) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to convert address: %w", err) | ||
| } | ||
|
|
||
| eventSig, err := chainsolana.ConvertEventSigFromProto(p.EventSig) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to convert event sig: %w", err) | ||
| } | ||
|
|
||
| txHash, err := chainsolana.ConvertSignatureFromProto(p.TxHash) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to convert tx hash: %w", err) | ||
| } | ||
|
|
||
| return &typesolana.Log{ | ||
| ChainID: p.ChainId, | ||
| LogIndex: p.LogIndex, | ||
| BlockHash: blockHash, | ||
| BlockNumber: p.BlockNumber, | ||
| BlockTimestamp: p.BlockTimestamp, | ||
| Address: address, | ||
| EventSig: eventSig, | ||
| TxHash: txHash, | ||
| Data: p.Data, | ||
| SequenceNum: p.SequenceNum, | ||
| Error: p.Error, | ||
| }, nil | ||
| } | ||
|
|
||
| // ConvertLogToProto converts a typesolana.Log to proto Log | ||
| func ConvertLogToProto(l *typesolana.Log) *Log { | ||
| if l == nil { | ||
| return nil | ||
| } | ||
| return &Log{ | ||
| ChainId: l.ChainID, | ||
| LogIndex: l.LogIndex, | ||
| BlockHash: l.BlockHash[:], | ||
| BlockNumber: l.BlockNumber, | ||
| BlockTimestamp: l.BlockTimestamp, | ||
| Address: l.Address[:], | ||
| EventSig: l.EventSig[:], | ||
| TxHash: l.TxHash[:], | ||
| Data: l.Data, | ||
| SequenceNum: l.SequenceNum, | ||
| Error: l.Error, | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.