Skip to content

Commit

Permalink
ethclient: define a local Client
Browse files Browse the repository at this point in the history
Every package that was using (subnet-evm)ethclient.Client is now using local ethclient.Client
  • Loading branch information
najeal committed May 13, 2024
1 parent f768549 commit 3509048
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ava-labs/awm-relayer/utils"

"github.com/ava-labs/awm-relayer/ethclient"
evmethclient "github.com/ava-labs/subnet-evm/ethclient"
"github.com/ava-labs/subnet-evm/precompile/contracts/warp"

// Force-load precompiles to trigger registration
Expand Down Expand Up @@ -357,7 +356,7 @@ func calculateQuorumNumerator(cfgNumerator uint64) uint64 {
func getWarpQuorum(
subnetID ids.ID,
blockchainID ids.ID,
client evmethclient.Client,
client ethclient.Client,
) (WarpQuorum, error) {
if subnetID == constants.PrimaryNetworkID {
return WarpQuorum{
Expand Down
4 changes: 3 additions & 1 deletion ethclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (

var ErrInvalidEndpoint = errors.New("invalid rpc endpoint")

type Client ethclient.Client

// DialWithContext returns an ethclient.Client with the internal RPC client configured with the provided options.
func DialWithConfig(ctx context.Context, baseURL string, httpHeaders, queryParams map[string]string) (ethclient.Client, error) {
func DialWithConfig(ctx context.Context, baseURL string, httpHeaders, queryParams map[string]string) (Client, error) {
url, err := addQueryParams(baseURL, queryParams)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion messages/off-chain-registry/message_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
warpPayload "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/ethclient"
"github.com/ava-labs/awm-relayer/vms"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/ethclient"
teleporterregistry "github.com/ava-labs/teleporter/abi-bindings/go/Teleporter/upgrades/TeleporterRegistry"
"github.com/ethereum/go-ethereum/common"
"go.uber.org/zap"
Expand Down
2 changes: 1 addition & 1 deletion messages/teleporter/message_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
warpPayload "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/ethclient"
"github.com/ava-labs/awm-relayer/vms"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/ethclient"
teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/Teleporter/TeleporterMessenger"
gasUtils "github.com/ava-labs/teleporter/utils/gas-utils"
teleporterUtils "github.com/ava-labs/teleporter/utils/teleporter-utils"
Expand Down
5 changes: 2 additions & 3 deletions vms/evm/destination_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ava-labs/awm-relayer/ethclient"
"github.com/ava-labs/awm-relayer/vms/evm/signer"
"github.com/ava-labs/subnet-evm/core/types"
evmethclient "github.com/ava-labs/subnet-evm/ethclient"
"github.com/ava-labs/subnet-evm/precompile/contracts/warp"
predicateutils "github.com/ava-labs/subnet-evm/predicate"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -33,12 +32,12 @@ const (

// Client interface wraps the ethclient.Client interface for mocking purposes.
type Client interface {
evmethclient.Client
ethclient.Client
}

// Implements DestinationClient
type destinationClient struct {
client evmethclient.Client
client ethclient.Client
lock *sync.Mutex
destinationBlockchainID ids.ID
signer signer.Signer
Expand Down
5 changes: 2 additions & 3 deletions vms/evm/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ava-labs/awm-relayer/ethclient"
"github.com/ava-labs/awm-relayer/vms/vmtypes"
"github.com/ava-labs/subnet-evm/core/types"
evmethclient "github.com/ava-labs/subnet-evm/ethclient"
"github.com/ava-labs/subnet-evm/interfaces"
"github.com/ava-labs/subnet-evm/precompile/contracts/warp"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -58,7 +57,7 @@ type subscriber struct {
logger logging.Logger

// seams for mock injection:
dial func(ctx context.Context, url string, httpHeaders, queryParams map[string]string) (evmethclient.Client, error)
dial func(ctx context.Context, url string, httpHeaders, queryParams map[string]string) (ethclient.Client, error)
}

// NewSubscriber returns a subscriber
Expand Down Expand Up @@ -184,7 +183,7 @@ func (s *subscriber) ProcessFromHeight(height *big.Int, done chan bool) {
// Since initializationFilterQuery does not modify existing fields of warpFilterQuery,
// we can safely reuse warpFilterQuery with only a shallow copy
func (s *subscriber) processBlockRange(
ethClient evmethclient.Client,
ethClient ethclient.Client,
fromBlock, toBlock *big.Int,
) error {
initializationFilterQuery := interfaces.FilterQuery{
Expand Down
4 changes: 2 additions & 2 deletions vms/evm/subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (

"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/ethclient"
mock_ethclient "github.com/ava-labs/awm-relayer/vms/evm/mocks"
"github.com/ava-labs/subnet-evm/core/types"
evmethclient "github.com/ava-labs/subnet-evm/ethclient"
"github.com/ava-labs/subnet-evm/interfaces"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
Expand All @@ -32,7 +32,7 @@ func makeSubscriberWithMockEthClient(t *testing.T) (*subscriber, *mock_ethclient

mockEthClient := mock_ethclient.NewMockClient(gomock.NewController(t))
subscriber := NewSubscriber(logger, sourceSubnet)
subscriber.dial = func(_ctx context.Context, _url string, _httpHeaders, _queryParams map[string]string) (evmethclient.Client, error) {
subscriber.dial = func(_ctx context.Context, _url string, _httpHeaders, _queryParams map[string]string) (ethclient.Client, error) {
return mockEthClient, nil
}

Expand Down

0 comments on commit 3509048

Please sign in to comment.