-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify
indexer
package (#14)
Simplified the indexer package by refactoring contained sub-services location and package names. Signed-off-by: Luca Georges Francois <luca@quartz.technology>
- Loading branch information
1 parent
3149b0d
commit 663aea3
Showing
49 changed files
with
473 additions
and
469 deletions.
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.