Skip to content

Commit

Permalink
Revert "fix: Wrong chain ID in error message when chain not found"
Browse files Browse the repository at this point in the history
This reverts commit c22ab14.
  • Loading branch information
vitaliy committed Jul 25, 2024
1 parent a9ea9aa commit 2bd07e7
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/chains/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (c *Chains) Get(chainID isc.ChainID) (chain.Chain, error) {

ret, exists := c.allChains.Get(chainID)
if !exists {
return nil, interfaces.NewChainNotFoundError(chainID)
return nil, interfaces.ErrChainNotFound
}
return ret.chain, nil
}
Expand Down
8 changes: 1 addition & 7 deletions packages/isc/chainid.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ func ChainIDFromBytes(data []byte) (ret ChainID, err error) {
}

func ChainIDFromString(bech32 string) (ChainID, error) {
netPrefix, addr, err := iotago.ParseBech32(bech32)
_, addr, err := iotago.ParseBech32(bech32)
if err != nil {
return ChainID{}, err
}
if addr.Type() != iotago.AddressAlias {
return ChainID{}, fmt.Errorf("chainID must be an alias address (%s)", bech32)
}

expectedNetPrefix := parameters.L1().Protocol.Bech32HRP
if netPrefix != expectedNetPrefix {
return ChainID{}, fmt.Errorf("invalid network prefix: %s", netPrefix)
}

return ChainIDFromAddress(addr.(*iotago.AliasAddress)), nil
}

Expand Down
4 changes: 2 additions & 2 deletions packages/webapi/controllers/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c *Controller) getChainInfo(e echo.Context) error {
}

chainInfo, err := c.chainService.GetChainInfoByChainID(chainID, e.QueryParam(params.ParamBlockIndexOrTrieRoot))
if errors.As(err, &interfaces.ChainNotFoundError{}) {
if errors.Is(err, interfaces.ErrChainNotFound) {
return e.NoContent(http.StatusNotFound)
} else if err != nil {
return err
Expand Down Expand Up @@ -97,7 +97,7 @@ func (c *Controller) getChainList(e echo.Context) error {
chainInfo, err := c.chainService.GetChainInfoByChainID(chainID, "")
c.log.Infof("getchaininfo %v", err)

if errors.As(err, &interfaces.ChainNotFoundError{}) {
if errors.Is(err, interfaces.ErrChainNotFound) {
// TODO: Validate this logic here. Is it possible to still get more chain info?
chainList = append(chainList, models.ChainInfoResponse{
IsActive: false,
Expand Down
6 changes: 2 additions & 4 deletions packages/webapi/controllers/corecontracts/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ func (c *Controller) Name() string {
}

func (c *Controller) handleViewCallError(err error, chainID isc.ChainID) error {
var chainNotFound interfaces.ChainNotFoundError
if errors.As(err, &chainNotFound) {
return apierrors.ChainNotFoundError(chainNotFound.ChainID.String())
if errors.Is(err, interfaces.ErrChainNotFound) {
return apierrors.ChainNotFoundError(chainID.String())
}

return apierrors.ContractExecutionError(err)
}

Expand Down
31 changes: 0 additions & 31 deletions packages/webapi/interfaces/errors.go

This file was deleted.

5 changes: 5 additions & 0 deletions packages/webapi/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/iotaledger/wasp/packages/webapi/models"
)

var (
ErrChainNotFound = errors.New("chain not found")
ErrCantDeleteLastUser = errors.New("you can't delete the last user")
)

type APIController interface {
Name() string
RegisterPublic(publicAPI echoswagger.ApiGroup, mocker Mocker)
Expand Down
2 changes: 1 addition & 1 deletion packages/webapi/services/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (c *ChainService) GetChainInfoByChainID(chainID isc.ChainID, blockIndexOrTr

governanceChainInfo, err := corecontracts.GetChainInfo(ch, blockIndexOrTrieRoot)
if err != nil {
if chainRecord != nil && errors.As(err, &interfaces.ChainNotFoundError{}) {
if chainRecord != nil && errors.Is(err, interfaces.ErrChainNotFound) {
return &dto.ChainInfo{ChainID: chainID, IsActive: false}, nil
}

Expand Down

0 comments on commit 2bd07e7

Please sign in to comment.