Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions etherclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package etherclient
import (
"context"
"errors"
"fmt"
"math/big"
"time"

Expand Down Expand Up @@ -83,6 +84,7 @@ type Extras interface {
type etherClient struct {
provider provider.Provider[*ethclient.Client]
retryInterval time.Duration
urls []string
}

var _ EtherClient = &etherClient{}
Expand All @@ -102,6 +104,7 @@ func DialContext(ctx context.Context, rawurls ...string) (*etherClient, error) {
return &etherClient{
provider: provider.NewRingProvider(clients...),
retryInterval: defaultRetryInterval,
urls: rawurls,
}, nil
}

Expand Down Expand Up @@ -509,3 +512,20 @@ func (ec *etherClient) SendTransaction(ctx context.Context, tx *types.Transactio
return ethClient.SendTransaction(ctx, tx)
})
}

// CurrentRPCURL returns the RPC URL of the current provider.
func (ec *etherClient) CurrentRPCURL() (string, error) {
// Get the current client's index in the ring
currentClient := ec.provider.Provide()
p, ok := ec.provider.(*provider.RingProvider[*ethclient.Client])
if !ok {
return "", fmt.Errorf("bad provider type")
}

for i, client := range p.Elements() {
if client == currentClient {
return ec.urls[i], nil
}
}
return "", fmt.Errorf("no active clients")
}
Loading