Skip to content

Commit

Permalink
avoid copy-pasting errros
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Jun 2, 2023
1 parent 44ce150 commit af7146f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 48 deletions.
7 changes: 6 additions & 1 deletion state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"time"

sdkErrors "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/api/tendermint/abci"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdktypes "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -177,7 +178,11 @@ func (ca *CoreAccessor) SubmitPayForBlob(
ca.lastPayForBlob = time.Now().UnixMilli()
ca.payForBlobCount++
}
return response, codeToError(response.Code)

if response.Code != 0 {
err = sdkErrors.ABCIError(response.Codespace, response.Code, response.Logs.String())
}
return response, err
}

func (ca *CoreAccessor) AccountAddress(context.Context) (Address, error) {
Expand Down
51 changes: 4 additions & 47 deletions state/helpers.go
Original file line number Diff line number Diff line change
@@ -1,64 +1,21 @@
package state

import (
"fmt"

sdk_errors "github.com/cosmos/cosmos-sdk/types/errors"
sdk_abci "github.com/tendermint/tendermint/abci/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func sdkErrorToGRPCError(resp sdk_abci.ResponseQuery) error {
switch codeToError(resp.Code) {
case sdk_errors.ErrInvalidRequest:
switch resp.Code {
case sdk_errors.ErrInvalidRequest.ABCICode():
return status.Error(codes.InvalidArgument, resp.Log)
case sdk_errors.ErrUnauthorized:
case sdk_errors.ErrUnauthorized.ABCICode():
return status.Error(codes.Unauthenticated, resp.Log)
case sdk_errors.ErrKeyNotFound:
case sdk_errors.ErrKeyNotFound.ABCICode():
return status.Error(codes.NotFound, resp.Log)
default:
return status.Error(codes.Unknown, resp.Log)
}
}

func codeToError(code uint32) error {
switch code {
case 0:
return nil
case sdk_errors.ErrTxDecode.ABCICode():
return sdk_errors.ErrTxDecode
case sdk_errors.ErrUnauthorized.ABCICode():
return sdk_errors.ErrUnauthorized
case sdk_errors.ErrInsufficientFunds.ABCICode():
return sdk_errors.ErrInsufficientFunds
case sdk_errors.ErrInvalidAddress.ABCICode():
return sdk_errors.ErrInvalidAddress
case sdk_errors.ErrUnknownAddress.ABCICode():
return sdk_errors.ErrUnknownAddress
case sdk_errors.ErrInvalidCoins.ABCICode():
return sdk_errors.ErrInvalidCoins
case sdk_errors.ErrOutOfGas.ABCICode():
return sdk_errors.ErrOutOfGas
case sdk_errors.ErrInsufficientFee.ABCICode():
return sdk_errors.ErrInsufficientFee
case sdk_errors.ErrJSONMarshal.ABCICode():
return sdk_errors.ErrJSONMarshal
case sdk_errors.ErrJSONUnmarshal.ABCICode():
return sdk_errors.ErrJSONUnmarshal
case sdk_errors.ErrTxTooLarge.ABCICode():
return sdk_errors.ErrTxTooLarge
case sdk_errors.ErrorInvalidGasAdjustment.ABCICode():
return sdk_errors.ErrorInvalidGasAdjustment
case sdk_errors.ErrLogic.ABCICode():
return sdk_errors.ErrLogic
case sdk_errors.ErrNotFound.ABCICode():
return sdk_errors.ErrNotFound
case sdk_errors.ErrIO.ABCICode():
return sdk_errors.ErrIO
case sdk_errors.ErrInvalidGasLimit.ABCICode():
return sdk_errors.ErrInvalidGasLimit
default:
return fmt.Errorf("unknown error code received: %d", code)
}
}

0 comments on commit af7146f

Please sign in to comment.