Skip to content

Commit

Permalink
Error if L1 and L2 networks are not defined together
Browse files Browse the repository at this point in the history
  • Loading branch information
sudoryan committed Dec 9, 2021
1 parent 49961b2 commit a30faac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ $ resolution --help

### Ethereum Provider

UNS domains are resolved by reading from both the Ethereum mainnet and Polygon L2 network
UNS domains are resolved by reading from both the Ethereum mainnet and Polygon L2 network.

#### L1
If L1 and L2 Ethereum JSON RPC are not defined, default Infura Ethereum Provider Urls for L1 and L2 will be used.

NOTE: L1 and L2 networks must both be defined or none at all.

If no Ethereum JSON RPC ethereum-provider-url is defined, a default Infura Ethereum Provider Url will be used
#### L1

Options for defining a ethereumProviderUrlFlag:

Expand Down
17 changes: 8 additions & 9 deletions resolution/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,26 @@ func initConfig() {
func initNamingServices() {
var err error
ethereumUrl := viper.GetString(ethereumUrlKey)
ethereumL2Url := viper.GetString(ethereumL2ProviderUrlFlag)
ethereumL2Url := viper.GetString(ethereumL2UrlKey)
zilliqaUrl := viper.GetString(zilliqaUrlKey)
unsBuilder := resolution.NewUnsBuilder()
znsBuilder := resolution.NewZnsBuilder()
if ethereumUrl != "" {
if ethereumUrl != "" || ethereumL2Url != "" {
if ethereumUrl == "" || ethereumL2Url == "" {
log.Fatalf("Specify both L1 and L2 ethereum url when defining your own networks")
}
backend, err := ethclient.Dial(ethereumUrl)
if err != nil {
log.Fatalf("Error connecting to Ethereum provider. Provider: %v. Error: %v", ethereumUrl, err.Error())
}
unsBuilder.SetContractBackend(backend)
} else {
unsBuilder.SetEthereumNetwork("mainnet")
}
if ethereumL2Url != "" {
unsBuilder.SetContractBackend(backend).SetEthereumNetwork("mainnet")
backendL2, err := ethclient.Dial(ethereumL2Url)
if err != nil {
log.Fatalf("Error connecting to Ethereum L2 provider. Provider: %v. Error: %v", ethereumL2Url, err.Error())
}
unsBuilder.SetL2ContractBackend(backendL2)
unsBuilder.SetL2ContractBackend(backendL2).SetL2EthereumNetwork("polygon")
} else {
unsBuilder.SetL2EthereumNetwork("polygon")
unsBuilder.SetEthereumNetwork("mainnet").SetL2EthereumNetwork("polygon")
}
unsService, err := unsBuilder.Build()
if err != nil {
Expand Down

0 comments on commit a30faac

Please sign in to comment.