-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Skeleton Implementation of Solana Chain Reader Service #12163
Closed
EasterTheBunny
wants to merge
1
commit into
develop
from
BCF-3013-skeleton-solana-chainreaderservice
Closed
Changes from all commits
Commits
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
This file contains 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,79 @@ | ||
package solana | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
commonservices "github.com/smartcontractkit/chainlink-common/pkg/services" | ||
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
"github.com/smartcontractkit/chainlink/v2/core/services" | ||
) | ||
|
||
const ServiceName = "SolanaChainReader" | ||
|
||
type SolanaChainReaderService struct { | ||
lggr logger.Logger | ||
commonservices.StateMachine | ||
} | ||
|
||
var ( | ||
ErrUnimplemented = errors.New("function unimplemented") | ||
_ services.ServiceCtx = &SolanaChainReaderService{} | ||
_ commontypes.ChainReader = &SolanaChainReaderService{} | ||
) | ||
|
||
// NewChainReaderService is a constructor for a new ChainReaderService for Solana. Returns a nil service on error. | ||
func NewChainReaderService(lggr logger.Logger) (*SolanaChainReaderService, error) { | ||
return &SolanaChainReaderService{ | ||
lggr: lggr.Named(ServiceName), | ||
}, nil | ||
} | ||
|
||
// Name implements the services.ServiceCtx interface and returns the logger service name. | ||
func (s *SolanaChainReaderService) Name() string { | ||
return s.lggr.Name() | ||
} | ||
|
||
// Start implements the services.ServiceCtx interface and starts necessary background services. | ||
// An error is returned if starting any internal services fails. Subsequent calls to Start return | ||
// and error. | ||
func (s *SolanaChainReaderService) Start(_ context.Context) error { | ||
return s.StartOnce(ServiceName, func() error { | ||
return nil | ||
}) | ||
} | ||
|
||
// Close implements the services.ServiceCtx interface and stops all background services and cleans | ||
// up used resources. Subsequent calls to Close return an error. | ||
func (s *SolanaChainReaderService) Close() error { | ||
return s.StopOnce(ServiceName, func() error { | ||
return nil | ||
}) | ||
} | ||
|
||
// Ready implements the services.ServiceCtx interface and returns an error if starting the service | ||
// encountered any errors or if the service is not ready to serve requests. | ||
func (s *SolanaChainReaderService) Ready() error { | ||
return s.StateMachine.Ready() | ||
} | ||
|
||
// HealthReport implements the services.ServiceCtx interface and returns errors for any internal | ||
// function or service that may have failed. | ||
func (s *SolanaChainReaderService) HealthReport() map[string]error { | ||
return map[string]error{s.Name(): s.Healthy()} | ||
} | ||
|
||
// GetLatestValue implements the types.ChainReader interface and requests and parses on-chain | ||
// data named by the provided contract, method, and params. | ||
func (s *SolanaChainReaderService) GetLatestValue(_ context.Context, contractName, method string, params any, returnVal any) error { | ||
return fmt.Errorf("%w: GetLatestValue not available", ErrUnimplemented) | ||
} | ||
|
||
// Bind implements the types.ChainReader interface and allows new contract bindings to be added | ||
// to the service. | ||
func (s *SolanaChainReaderService) Bind(_ context.Context, bindings []commontypes.BoundContract) error { | ||
return fmt.Errorf("%w: Bind not available", ErrUnimplemented) | ||
} |
This file contains 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,36 @@ | ||
package solana_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/test-go/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/relay/solana" | ||
) | ||
|
||
func TestSolanaChainReaderService_ServiceCtx(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := testutils.Context(t) | ||
svc, err := solana.NewChainReaderService(logger.TestLogger(t)) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, svc) | ||
|
||
require.Error(t, svc.Ready()) | ||
require.Len(t, svc.HealthReport(), 1) | ||
require.Contains(t, svc.HealthReport(), solana.ServiceName) | ||
require.Error(t, svc.HealthReport()[solana.ServiceName]) | ||
|
||
require.NoError(t, svc.Start(ctx)) | ||
require.NoError(t, svc.Ready()) | ||
require.Equal(t, map[string]error{solana.ServiceName: nil}, svc.HealthReport()) | ||
|
||
require.Error(t, svc.Start(ctx)) | ||
|
||
require.NoError(t, svc.Close()) | ||
require.Error(t, svc.Ready()) | ||
require.Error(t, svc.Close()) | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a
types.UnimplementedError
type you should be able to import from chainlink-comon.You can use it like:
types.UnimplementedError("custom error message")