Skip to content

Commit

Permalink
fix: error handling on invalid chain for ibc (#145)
Browse files Browse the repository at this point in the history
* fix: error handling on invlaid chain for ibc

* fix: error handling on invalid chain for ibc
  • Loading branch information
shreyasbhat0 authored Aug 28, 2023
1 parent 1049ca1 commit 1898a40
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cli/commands/bridge/relyas/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

var suppottedChainsForBtp = []string{"icon", "eth", "hardhat"}
var supportedChainsForIbc = []string{"archway"}

type Chains struct {
chainA string
Expand Down Expand Up @@ -74,10 +75,20 @@ func (chains *Chains) getServicesResponse() (string, string, error) {

func (chains *Chains) checkForBtpSupportedChains() error {
if !slices.Contains(suppottedChainsForBtp, chains.chainA) {
return fmt.Errorf("Invalid Chain %s", chains.chainA)
return fmt.Errorf("invalid Chain: %s", chains.chainA)
}
if !slices.Contains(suppottedChainsForBtp, chains.chainB) {
return fmt.Errorf("Invalid Chain %s", chains.chainB)
return fmt.Errorf("invalid Chain: %s", chains.chainB)
}
return nil
}

func (chains *Chains) checkForIbcSupportedChains() error {
if !slices.Contains(supportedChainsForIbc, chains.chainA) {
return fmt.Errorf("invalid Chain: %s", chains.chainA)
}
if !slices.Contains(supportedChainsForIbc, chains.chainB) {
return fmt.Errorf("invalid Chain: %s", chains.chainB)
}
return nil
}
5 changes: 5 additions & 0 deletions cli/commands/bridge/relyas/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func stratIbcRelay(diveContext *common.DiveContext, enclaveContext *enclaves.Enc
var starlarkExecutionResponse string
var err error

err = chains.checkForIbcSupportedChains()
if err != nil {
diveContext.FatalError(err.Error(), fmt.Sprintf("Supported chains are %v", supportedChainsForIbc))
}

if chains.chainAServiceName != "" && chains.chainBServiceName != "" {

srcChainServiceResponse, dstChainServiceResponse, err := chains.getServicesResponse()
Expand Down

0 comments on commit 1898a40

Please sign in to comment.