-
Notifications
You must be signed in to change notification settings - Fork 208
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: litt3 <102969658+litt3@users.noreply.github.com>
- Loading branch information
Showing
16 changed files
with
260 additions
and
349 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package relay | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/Layr-Labs/eigenda/common" | ||
relayRegistryBindings "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDARelayRegistry" | ||
v2 "github.com/Layr-Labs/eigenda/core/v2" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
gethcommon "github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// DefaultRelayUrlProvider provides relay URL strings, based on relay key. | ||
type DefaultRelayUrlProvider struct { | ||
relayRegistryCaller *relayRegistryBindings.ContractEigenDARelayRegistryCaller | ||
} | ||
|
||
var _ RelayUrlProvider = &DefaultRelayUrlProvider{} | ||
|
||
// NewDefaultRelayUrlProvider constructs a DefaultRelayUrlProvider | ||
func NewDefaultRelayUrlProvider( | ||
ethClient common.EthClient, | ||
relayRegistryAddress gethcommon.Address, | ||
) (*DefaultRelayUrlProvider, error) { | ||
relayRegistryContractCaller, err := relayRegistryBindings.NewContractEigenDARelayRegistryCaller( | ||
relayRegistryAddress, | ||
ethClient) | ||
if err != nil { | ||
return nil, fmt.Errorf("NewContractEigenDARelayRegistryCaller: %w", err) | ||
} | ||
|
||
return &DefaultRelayUrlProvider{ | ||
relayRegistryCaller: relayRegistryContractCaller, | ||
}, nil | ||
} | ||
|
||
// GetRelayUrl gets the URL string for a given relayKey | ||
func (rup *DefaultRelayUrlProvider) GetRelayUrl(ctx context.Context, relayKey v2.RelayKey) (string, error) { | ||
relayUrl, err := rup.relayRegistryCaller.RelayKeyToUrl(&bind.CallOpts{Context: ctx}, relayKey) | ||
if err != nil { | ||
return "", fmt.Errorf("fetch relay key (%d) URL from EigenDARelayRegistry contract: %w", relayKey, err) | ||
} | ||
|
||
return relayUrl, nil | ||
} | ||
|
||
// GetRelayCount gets the number of relays that exist in the registry | ||
func (rup *DefaultRelayUrlProvider) GetRelayCount(ctx context.Context) (uint32, error) { | ||
relayCount, err := rup.relayRegistryCaller.NextRelayKey(&bind.CallOpts{Context: ctx}) | ||
if err != nil { | ||
return 0, fmt.Errorf("get next relay key from EigenDARelayRegistry contract: %w", err) | ||
} | ||
|
||
return relayCount, 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,15 @@ | ||
package relay | ||
|
||
import ( | ||
"context" | ||
|
||
v2 "github.com/Layr-Labs/eigenda/core/v2" | ||
) | ||
|
||
// RelayUrlProvider provides relay URL strings, based on relay key | ||
type RelayUrlProvider interface { | ||
// GetRelayUrl gets the URL string for a given relayKey | ||
GetRelayUrl(ctx context.Context, relayKey v2.RelayKey) (string, error) | ||
// GetRelayCount returns the number of relays in the registry | ||
GetRelayCount(ctx context.Context) (uint32, 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,28 @@ | ||
package relay | ||
|
||
import ( | ||
"context" | ||
|
||
v2 "github.com/Layr-Labs/eigenda/core/v2" | ||
) | ||
|
||
// TestRelayUrlProvider implements RelayUrlProvider, for test cases | ||
// | ||
// NOT SAFE for concurrent use | ||
type TestRelayUrlProvider struct { | ||
urlMap map[v2.RelayKey]string | ||
} | ||
|
||
var _ RelayUrlProvider = &TestRelayUrlProvider{} | ||
|
||
func (rup *TestRelayUrlProvider) GetRelayUrl(_ context.Context, relayKey v2.RelayKey) (string, error) { | ||
return rup.urlMap[relayKey], nil | ||
} | ||
|
||
func (rup *TestRelayUrlProvider) GetRelayCount(_ context.Context) (uint32, error) { | ||
return uint32(len(rup.urlMap)), nil | ||
} | ||
|
||
func (rup *TestRelayUrlProvider) StoreRelayUrl(relayKey v2.RelayKey, url string) { | ||
rup.urlMap[relayKey] = url | ||
} |
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
Oops, something went wrong.