From d15973b715cd87f672c29910b48fc6bfe2a72a02 Mon Sep 17 00:00:00 2001 From: Daniel T <30197399+danwt@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:35:26 +0100 Subject: [PATCH] fix(code standards): use https://github.com/dymensionxyz/sdk-utils (#968) --- app/ante/handlers.go | 4 +- app/app.go | 2 +- go.mod | 5 ++- go.sum | 10 +++-- utils/ibc/doc.go | 2 - utils/ibc/funcs.go | 43 ------------------- x/denommetadata/keeper/keeper.go | 2 +- x/denommetadata/keeper/keeper_test.go | 2 +- x/eibc/keeper/handler.go | 5 +-- x/rollapp/keeper/authenticate_packet.go | 4 +- x/rollapp/transfergenesis/ante_decorator.go | 11 +++-- x/rollapp/transfergenesis/ibc_module.go | 2 +- .../ibc_module_canonical_channel_hack.go | 10 +++-- 13 files changed, 31 insertions(+), 71 deletions(-) delete mode 100644 utils/ibc/doc.go delete mode 100644 utils/ibc/funcs.go diff --git a/app/ante/handlers.go b/app/ante/handlers.go index 4b0b7c729..e85f9bd15 100644 --- a/app/ante/handlers.go +++ b/app/ante/handlers.go @@ -74,7 +74,7 @@ func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler { ibcante.NewRedundantRelayDecorator(options.IBCKeeper), ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper), - transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper.GetChannelClientState), + transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper), ) } @@ -110,6 +110,6 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler { ibcante.NewRedundantRelayDecorator(options.IBCKeeper), ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper), - transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper.GetChannelClientState), + transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper), ) } diff --git a/app/app.go b/app/app.go index 0cad43ccc..a284cc7e1 100644 --- a/app/app.go +++ b/app/app.go @@ -741,7 +741,7 @@ func New( transferStack = delayedAckMiddleware transferStack = transferinject.NewIBCModule(transferStack, app.RollappKeeper) transferStack = transfergenesis.NewIBCModule(transferStack, app.DelayedAckKeeper, app.RollappKeeper, app.TransferKeeper, app.DenomMetadataKeeper) - transferStack = transfergenesis.NewIBCModuleCanonicalChannelHack(transferStack, app.RollappKeeper, app.IBCKeeper.ChannelKeeper.GetChannelClientState) + transferStack = transfergenesis.NewIBCModuleCanonicalChannelHack(transferStack, app.RollappKeeper, app.IBCKeeper.ChannelKeeper) // Create static IBC router, add transfer route, then set and seal it ibcRouter := ibcporttypes.NewRouter() diff --git a/go.mod b/go.mod index a95e18b9f..43d6f7bbe 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,8 @@ require ( github.com/cosmos/ibc-go/v6 v6.2.1 github.com/decred/dcrd/dcrec/edwards v1.0.0 github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac - github.com/dymensionxyz/gerr-cosmos v0.1.2 + github.com/dymensionxyz/gerr-cosmos v1.0.0 + github.com/dymensionxyz/sdk-utils v0.1.1 github.com/ethereum/go-ethereum v1.10.26 github.com/evmos/ethermint v0.22.0 github.com/gogo/protobuf v1.3.3 @@ -80,7 +81,7 @@ require ( github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect github.com/danieljoos/wincred v1.1.2 // indirect - github.com/danwt/gerr v0.1.5 // indirect + github.com/danwt/gerr v1.0.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set v1.8.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect diff --git a/go.sum b/go.sum index 5444fd2cd..98227cac9 100644 --- a/go.sum +++ b/go.sum @@ -427,8 +427,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= -github.com/danwt/gerr v0.1.5 h1:5s3G3cnftZG7Rq0+k+taMVteTmwKU66/g47kH6hY1js= -github.com/danwt/gerr v0.1.5/go.mod h1:tIj6P8ZPBLAbr64HdWqKHGUXbWJT6HenD08Fn98oAnE= +github.com/danwt/gerr v1.0.0 h1:v3Do0h1r+uctQQVYJfOTCo8uigp8oIaY4OL/wUU8LzI= +github.com/danwt/gerr v1.0.0/go.mod h1:tIj6P8ZPBLAbr64HdWqKHGUXbWJT6HenD08Fn98oAnE= github.com/dave/jennifer v1.2.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -483,12 +483,14 @@ github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQx github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU= github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.4.1 h1:J31ASxmDVm7ytjmk9ToVZeJA4WyAZKO0r2ErwbhEf98= github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.4.1/go.mod h1:O2J61ZwM0Vdms6pRa1fb43pwmCuNRctro3AB90WlOc0= -github.com/dymensionxyz/gerr-cosmos v0.1.2 h1:4NiB9psF6swnWTCDYnHgHKtVEaRHuuNRuqvPGDw1BI8= -github.com/dymensionxyz/gerr-cosmos v0.1.2/go.mod h1:tXIhx3WdryAnYRISC3Weh+2xeXwaf1l4Yb1zjDUsT7k= +github.com/dymensionxyz/gerr-cosmos v1.0.0 h1:oi91rgOkpJWr41oX9JOyjvvBnhGY54tj513x8VlDAEc= +github.com/dymensionxyz/gerr-cosmos v1.0.0/go.mod h1:n+0olxPogzWqFKba45mCpvrHLGmeS8W9UZjggHnWk6c= github.com/dymensionxyz/osmosis/osmomath v0.0.6-dym-v0.0.1 h1:59ZE3Ocrn04MUpb5VJgfi24eDcnQ9VBfCSw0Mx1n7OI= github.com/dymensionxyz/osmosis/osmomath v0.0.6-dym-v0.0.1/go.mod h1:2idySYJxP5YfMAEeSeqD8e7fSchfsI4jn7XFHJgNUsM= github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v1.1.3 h1:8L0sMJfGjIgDmA373Qokoix4kdCrzG1j1lYe//B5kkQ= github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v1.1.3/go.mod h1:BHHGzl86byC0sov3EUfTzyDuIsGY//rcrek6gCOa+fw= +github.com/dymensionxyz/sdk-utils v0.1.1 h1:QX/4S0t+wUhbRlAw34fz2kEF+RP1D+tEVQ/S5QRa5X0= +github.com/dymensionxyz/sdk-utils v0.1.1/go.mod h1:5fmenxP75quS5D1gPynbmh5qE6vla64Kks2O/hM+gi4= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= diff --git a/utils/ibc/doc.go b/utils/ibc/doc.go deleted file mode 100644 index 2020a47e6..000000000 --- a/utils/ibc/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package utilsibc contains ibc utils -package utilsibc diff --git a/utils/ibc/funcs.go b/utils/ibc/funcs.go deleted file mode 100644 index 039a360e1..000000000 --- a/utils/ibc/funcs.go +++ /dev/null @@ -1,43 +0,0 @@ -package utilsibc - -import ( - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - "github.com/cosmos/ibc-go/v6/modules/core/exported" - ibctmtypes "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint/types" - "github.com/dymensionxyz/gerr-cosmos/gerrc" -) - -type GetChannelClientState func(ctx sdk.Context, portID, channelID string) (string, exported.ClientState, error) - -func ChainIDFromPortChannel( - ctx sdk.Context, - getChannelClientState GetChannelClientState, - portID string, - channelID string, -) (string, error) { - _, state, err := getChannelClientState(ctx, portID, channelID) - if err != nil { - return "", errorsmod.Wrap(err, "get channel client state") - } - - tmState, ok := state.(*ibctmtypes.ClientState) - if !ok { - return "", errorsmod.Wrap(gerrc.ErrInvalidArgument, "cast client state to tmtypes client state") - } - - return tmState.ChainId, nil -} - -const ( - ibcPort = "transfer" -) - -func GetForeignDenomTrace(channelId string, denom string) types.DenomTrace { - sourcePrefix := types.GetDenomPrefix(ibcPort, channelId) - // NOTE: sourcePrefix contains the trailing "/" - prefixedDenom := sourcePrefix + denom - // construct the denomination trace from the full raw denomination - return types.ParseDenomTrace(prefixedDenom) -} diff --git a/x/denommetadata/keeper/keeper.go b/x/denommetadata/keeper/keeper.go index 68204aa64..b1e6dedf5 100644 --- a/x/denommetadata/keeper/keeper.go +++ b/x/denommetadata/keeper/keeper.go @@ -34,7 +34,7 @@ func (k *Keeper) HasDenomMetadata(ctx sdk.Context, base string) bool { func (k *Keeper) CreateDenomMetadata(ctx sdk.Context, metadata banktypes.Metadata) error { found := k.HasDenomMetadata(ctx, metadata.Base) if found { - return gerrc.ErrAlreadyExist + return gerrc.ErrAlreadyExists } k.bankKeeper.SetDenomMetaData(ctx, metadata) err := k.hooks.AfterDenomMetadataCreation(ctx, metadata) diff --git a/x/denommetadata/keeper/keeper_test.go b/x/denommetadata/keeper/keeper_test.go index b69cfdc17..31f99787c 100644 --- a/x/denommetadata/keeper/keeper_test.go +++ b/x/denommetadata/keeper/keeper_test.go @@ -64,7 +64,7 @@ func (suite *KeeperTestSuite) TestCreateExistingDenom() { suite.Require().NoError(err) err = keeper.CreateDenomMetadata(suite.Ctx, suite.getDymMetadata()) - suite.Require().True(errorsmod.IsOf(err, gerrc.ErrAlreadyExist)) + suite.Require().True(errorsmod.IsOf(err, gerrc.ErrAlreadyExists)) } func (suite *KeeperTestSuite) TestUpdateMissingDenom() { diff --git a/x/eibc/keeper/handler.go b/x/eibc/keeper/handler.go index 6f161a7b6..323db177f 100644 --- a/x/eibc/keeper/handler.go +++ b/x/eibc/keeper/handler.go @@ -6,12 +6,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" - uibc "github.com/dymensionxyz/dymension/v3/utils/ibc" - "github.com/pkg/errors" - commontypes "github.com/dymensionxyz/dymension/v3/x/common/types" dacktypes "github.com/dymensionxyz/dymension/v3/x/delayedack/types" "github.com/dymensionxyz/dymension/v3/x/eibc/types" + uibc "github.com/dymensionxyz/sdk-utils/utils/uibc" + "github.com/pkg/errors" ) // EIBCDemandOrderHandler handles the eibc packet by creating a demand order from the packet data and saving it in the store. diff --git a/x/rollapp/keeper/authenticate_packet.go b/x/rollapp/keeper/authenticate_packet.go index e7d6495a0..f241b3e3c 100644 --- a/x/rollapp/keeper/authenticate_packet.go +++ b/x/rollapp/keeper/authenticate_packet.go @@ -4,9 +4,9 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - uibc "github.com/dymensionxyz/dymension/v3/utils/ibc" "github.com/dymensionxyz/dymension/v3/x/rollapp/types" "github.com/dymensionxyz/gerr-cosmos/gerrc" + uibc "github.com/dymensionxyz/sdk-utils/utils/uibc" ) /* @@ -69,7 +69,7 @@ func (k Keeper) getRollappByPortChan(ctx sdk.Context, https://github.com/dymensionxyz/dymension/blob/986d51ccd4807d514c91b3a147ac1b8ce5b590a1/x/delayedack/keeper/authenticate_packet.go#L47-L59 for the old implementations of checks */ - chainID, err := uibc.ChainIDFromPortChannel(ctx, k.channelKeeper.GetChannelClientState, raPortOnHub, raChanOnHub) + chainID, err := uibc.ChainIDFromPortChannel(ctx, k.channelKeeper, raPortOnHub, raChanOnHub) if err != nil { return nil, errorsmod.Wrap(err, "chain id from port and channel") } diff --git a/x/rollapp/transfergenesis/ante_decorator.go b/x/rollapp/transfergenesis/ante_decorator.go index 773b88549..41e594547 100644 --- a/x/rollapp/transfergenesis/ante_decorator.go +++ b/x/rollapp/transfergenesis/ante_decorator.go @@ -1,12 +1,11 @@ package transfergenesis import ( - uibc "github.com/dymensionxyz/dymension/v3/utils/ibc" - "github.com/dymensionxyz/gerr-cosmos/gerrc" - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/dymensionxyz/gerr-cosmos/gerrc" + "github.com/dymensionxyz/sdk-utils/utils/uibc" + transferTypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" "github.com/dymensionxyz/dymension/v3/x/rollapp/types" ) @@ -17,10 +16,10 @@ type GetRollapp func(ctx sdk.Context, rollappId string) (val types.Rollapp, foun // the transfer genesis protocol. type TransferEnabledDecorator struct { getRollapp GetRollapp - getChannelClientState uibc.GetChannelClientState + getChannelClientState ChannelKeeper } -func NewTransferEnabledDecorator(getRollapp GetRollapp, getChannelClientState uibc.GetChannelClientState) *TransferEnabledDecorator { +func NewTransferEnabledDecorator(getRollapp GetRollapp, getChannelClientState ChannelKeeper) *TransferEnabledDecorator { return &TransferEnabledDecorator{ getRollapp: getRollapp, getChannelClientState: getChannelClientState, diff --git a/x/rollapp/transfergenesis/ibc_module.go b/x/rollapp/transfergenesis/ibc_module.go index 5ce12d21a..01880a213 100644 --- a/x/rollapp/transfergenesis/ibc_module.go +++ b/x/rollapp/transfergenesis/ibc_module.go @@ -10,7 +10,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - uibc "github.com/dymensionxyz/dymension/v3/utils/ibc" + uibc "github.com/dymensionxyz/sdk-utils/utils/uibc" "github.com/tendermint/tendermint/libs/log" diff --git a/x/rollapp/transfergenesis/ibc_module_canonical_channel_hack.go b/x/rollapp/transfergenesis/ibc_module_canonical_channel_hack.go index e9ede4812..769f11864 100644 --- a/x/rollapp/transfergenesis/ibc_module_canonical_channel_hack.go +++ b/x/rollapp/transfergenesis/ibc_module_canonical_channel_hack.go @@ -5,8 +5,8 @@ import ( channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" "github.com/cosmos/ibc-go/v6/modules/core/exported" - uibc "github.com/dymensionxyz/dymension/v3/utils/ibc" rollappkeeper "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper" + uibc "github.com/dymensionxyz/sdk-utils/utils/uibc" ) /* @@ -17,16 +17,20 @@ TODO: this whole file is temporary See https://github.com/dymensionxyz/research/issues/242 */ +type ChannelKeeper interface { + GetChannelClientState(ctx sdk.Context, portID, channelID string) (string, exported.ClientState, error) // implemented by ibc channel keeper +} + type IBCModuleCanonicalChannelHack struct { porttypes.IBCModule // next one rollappKeeper rollappkeeper.Keeper - channelKeeper uibc.GetChannelClientState + channelKeeper ChannelKeeper } func NewIBCModuleCanonicalChannelHack( next porttypes.IBCModule, rollappKeeper rollappkeeper.Keeper, - channelKeeper uibc.GetChannelClientState, + channelKeeper ChannelKeeper, ) *IBCModuleCanonicalChannelHack { return &IBCModuleCanonicalChannelHack{IBCModule: next, rollappKeeper: rollappKeeper, channelKeeper: channelKeeper} }