This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5f6db5f
commit 35b4fab
Showing
23 changed files
with
396 additions
and
106 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
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
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,89 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/base-org/pessimism/internal/core" | ||
"github.com/base-org/pessimism/internal/logging" | ||
indexer_client "github.com/ethereum-optimism/optimism/indexer/client" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// Config ... Client configuration | ||
type Config struct { | ||
L1RpcEndpoint string | ||
L2RpcEndpoint string | ||
|
||
IndexerCfg *indexer_client.Config | ||
} | ||
|
||
// Bundle ... Used to store all client object references | ||
type Bundle struct { | ||
IndexerClient IndexerClient | ||
L1Client EthClient | ||
L2Client EthClient | ||
L2Geth GethClient | ||
} | ||
|
||
// NewBundle ... Construct a new client bundle | ||
func NewBundle(ctx context.Context, cfg *Config) (*Bundle, error) { | ||
logger := logging.WithContext(ctx) | ||
|
||
l1Client, err := NewEthClient(ctx, cfg.L1RpcEndpoint) | ||
if err != nil { | ||
logger.Fatal("Error creating L1 client", zap.Error(err)) | ||
return nil, err | ||
} | ||
|
||
l2Client, err := NewEthClient(ctx, cfg.L2RpcEndpoint) | ||
if err != nil { | ||
logger.Fatal("Error creating L1 client", zap.Error(err)) | ||
return nil, err | ||
} | ||
|
||
l2Geth, err := NewGethClient(cfg.L2RpcEndpoint) | ||
if err != nil { | ||
logger.Fatal("Error creating L2 GETH client", zap.Error(err)) | ||
return nil, err | ||
} | ||
|
||
indexerClient, err := NewIndexerClient(cfg.IndexerCfg) | ||
if err != nil { // Indexer client is optional so we don't want to fatal | ||
logger.Warn("Error creating indexer client", zap.Error(err)) | ||
} | ||
|
||
return &Bundle{ | ||
IndexerClient: indexerClient, | ||
L1Client: l1Client, | ||
L2Client: l2Client, | ||
L2Geth: l2Geth, | ||
}, nil | ||
} | ||
|
||
// FromContext ... Retrieves the client bundle from the context | ||
func FromContext(ctx context.Context) (*Bundle, error) { | ||
b, err := ctx.Value(core.Clients).(*Bundle) | ||
if !err { | ||
return nil, fmt.Errorf("failed to retrieve client bundle from context") | ||
} | ||
|
||
return b, nil | ||
} | ||
|
||
// FromNetwork ... Retrieves an eth client from the context | ||
func FromNetwork(ctx context.Context, n core.Network) (EthClient, error) { | ||
bundle, err := FromContext(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
switch n { | ||
case core.Layer1: | ||
return bundle.L1Client, nil | ||
case core.Layer2: | ||
return bundle.L2Client, nil | ||
default: | ||
return nil, fmt.Errorf("invalid network supplied") | ||
} | ||
} |
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,18 @@ | ||
//go:generate mockgen -package mocks --destination ../mocks/indexer_client.go . IndexerClient | ||
|
||
package client | ||
|
||
import ( | ||
"github.com/ethereum-optimism/optimism/indexer/api/models" | ||
"github.com/ethereum-optimism/optimism/indexer/client" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type IndexerClient interface { | ||
GetAllWithdrawalsByAddress(common.Address) ([]models.WithdrawalItem, error) | ||
} | ||
|
||
// NewIndexerClient ... Construct a new indexer client | ||
func NewIndexerClient(cfg *client.Config, opts ...client.Option) (IndexerClient, error) { | ||
return client.NewClient(cfg, opts...) | ||
} |
Oops, something went wrong.