-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor: simplify indexer
package
#14
Merged
Merged
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
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
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,14 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
|
||
client "github.com/attestantio/go-eth2-client" | ||
) | ||
|
||
// BeaconAPI is used to interact with a beacon node. | ||
type BeaconAPI interface { | ||
// SubscribeToHeadEvents is used to create a subscription to new head events and will perform | ||
// the handler's logic. | ||
SubscribeToHeadEvents(ctx context.Context, handler client.EventHandlerFunc) error | ||
} |
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,54 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
|
||
client "github.com/attestantio/go-eth2-client" | ||
"github.com/attestantio/go-eth2-client/http" | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
// DefaultBeaconAPI is the default implementation of the BeaconAPI for agate, | ||
// using the go-eth2-client library to send queries to the beacon node. | ||
type DefaultBeaconAPI struct { | ||
clt *http.Service | ||
} | ||
|
||
// NewDefaultBeaconAPI creates a new and non-initialized DefaultBeaconAPI. | ||
func NewDefaultBeaconAPI() *DefaultBeaconAPI { | ||
return &DefaultBeaconAPI{ | ||
clt: nil, | ||
} | ||
} | ||
|
||
// Init initializes an DefaultBeaconAPI using the beacon API URL to connect to the beacon node. | ||
func (client *DefaultBeaconAPI) Init(ctx context.Context, beaconAPIURL string) error { | ||
var ok bool | ||
|
||
clt, err := http.New( | ||
ctx, | ||
http.WithAddress(beaconAPIURL), | ||
http.WithLogLevel(zerolog.Disabled), | ||
) | ||
if err != nil { | ||
return NewDefaultBeaconAPIServiceInitializationError(err) | ||
} | ||
|
||
client.clt, ok = clt.(*http.Service) | ||
if !ok { | ||
return ErrDefaultBeaconAPIServiceTypeAssertion | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (client *DefaultBeaconAPI) SubscribeToHeadEvents( | ||
ctx context.Context, | ||
handler client.EventHandlerFunc, | ||
) error { | ||
if err := client.clt.Events(ctx, []string{"head"}, handler); err != nil { | ||
return NewDefaultBeaconAPIEventSubscriptionError(err) | ||
} | ||
|
||
return nil | ||
} |
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,20 @@ | ||
package client | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
var ErrDefaultBeaconAPIServiceTypeAssertion = errors.New("failed to type assert beacon API HTTP service") | ||
|
||
// NewDefaultBeaconAPIServiceInitializationError is raised if the client used to connect to the beacon | ||
// node fails to initialize. | ||
func NewDefaultBeaconAPIServiceInitializationError(err error) error { | ||
return fmt.Errorf("failed to initialize default beacon API HTTP service: %w", err) | ||
} | ||
|
||
// NewDefaultBeaconAPIEventSubscriptionError is raised if the client connected to the node fails to create an event | ||
// subscription. | ||
func NewDefaultBeaconAPIEventSubscriptionError(err error) error { | ||
return fmt.Errorf("default beacon API HTTP service failed to create event subscription: %w", err) | ||
} |
6 changes: 3 additions & 3 deletions
6
...r/head_listener/beacon_api_client_test.go → indexer/client/default_beacon_api_test.go
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
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
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,21 @@ | ||
package client | ||
|
||
import "fmt" | ||
|
||
// NewDefaultRelayAPIServiceInitializationError is raised when the DefaultRelayAPI | ||
// initialization has failed because the <redax> SDK could not be initialized. | ||
func NewDefaultRelayAPIServiceInitializationError(err error) error { | ||
return fmt.Errorf("failed to initialize default relay API SDK: %w", err) | ||
} | ||
|
||
// NewDefaultRelayAPIBidsReceivedRetrievalError is raised if the request made to the relay to | ||
// get the bids received for a specific slot has failed. | ||
func NewDefaultRelayAPIBidsReceivedRetrievalError(err error) error { | ||
return fmt.Errorf("default relay API SDK failed to retrieve bids received by relay: %w", err) | ||
} | ||
|
||
// NewDefaultRelayAPIBidsDeliveredRetrievalError is raised if the request made to the relay to | ||
// get the bids delivered for a specific slot has failed. | ||
func NewDefaultRelayAPIBidsDeliveredRetrievalError(err error) error { | ||
return fmt.Errorf("default relay API SDK failed to retrieve bids delivered by relay: %w", err) | ||
} |
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
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,16 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/attestantio/go-eth2-client/spec/phase0" | ||
"github.com/quartz-technology/agate/indexer/common" | ||
) | ||
|
||
// RelayAPI is used to collect data from a relay. | ||
type RelayAPI interface { | ||
// GetRelayDataForSlot retrieves the bids received and delivered to a relay for a specific slot. | ||
GetRelayDataForSlot(ctx context.Context, slot phase0.Slot) (*common.RelayData, error) | ||
// GetRelayAPIURL returns the API URL of the relay this client makes request to. | ||
GetRelayAPIURL() string | ||
} | ||
4 changes: 2 additions & 2 deletions
4
...er/data_preprocessor/preprocessed_data.go → indexer/common/preprocessor_data.go
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
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.
I like that