From 9bf6ca291418092d2e567539a3626e3ad1776849 Mon Sep 17 00:00:00 2001 From: dheerajkd30 Date: Wed, 22 Jun 2022 17:48:34 +0530 Subject: [PATCH] code inspection error refactor --- app/wasm/message_plugin.go | 4 ++-- app/wasm/queries.go | 4 ++-- cmd/comdex/genwasm.go | 1 - cmd/comdex/main.go | 1 - x/asset/client/cli/flags.go | 1 - x/asset/types/msg.go | 27 --------------------------- x/auction/keeper/dutch.go | 4 ++-- x/auction/keeper/math.go | 8 -------- x/auction/keeper/query_server.go | 2 +- x/auction/types/keys.go | 12 ++++++------ x/collector/keeper/collector.go | 5 +---- x/collector/module.go | 1 - x/lend/client/cli/flags.go | 14 -------------- x/liquidation/client/cli/tx.go | 2 +- x/liquidation/keeper/keeper.go | 10 +++++----- x/liquidation/keeper/msg_server.go | 2 +- x/liquidation/types/codec.go | 1 - x/liquidation/types/msg.go | 2 +- 18 files changed, 22 insertions(+), 79 deletions(-) diff --git a/app/wasm/message_plugin.go b/app/wasm/message_plugin.go index 6fea573c3..e7c7f1019 100644 --- a/app/wasm/message_plugin.go +++ b/app/wasm/message_plugin.go @@ -312,7 +312,7 @@ func (m *CustomMessenger) WhitelistAppIDLiquidation(ctx sdk.Context, contractAdd func MsgWhitelistAppIDLiquidation(liquidationKeeper liquidationkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, a *bindings.MsgWhitelistAppIDLiquidation) error { - err := liquidationKeeper.WasmWhitelistAppIdLiquidation(ctx, a.AppMappingID) + err := liquidationKeeper.WasmWhitelistAppIDLiquidation(ctx, a.AppMappingID) if err != nil { return err } @@ -329,7 +329,7 @@ func (m *CustomMessenger) RemoveWhitelistAppIDLiquidation(ctx sdk.Context, contr func MsgRemoveWhitelistAppIDLiquidation(liquidationKeeper liquidationkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, a *bindings.MsgRemoveWhitelistAppIDLiquidation) error { - err := liquidationKeeper.WasmRemoveWhitelistAppIdLiquidation(ctx, a.AppMappingID) + err := liquidationKeeper.WasmRemoveWhitelistAppIDLiquidation(ctx, a.AppMappingID) if err != nil { return err } diff --git a/app/wasm/queries.go b/app/wasm/queries.go index 2c2679323..1809d9500 100644 --- a/app/wasm/queries.go +++ b/app/wasm/queries.go @@ -126,11 +126,11 @@ func (qp QueryPlugin) WasmRemoveWhitelistAssetLockerQueryCheck(ctx sdk.Context, } func (qp QueryPlugin) WasmWhitelistAppIDLiquidationQueryCheck(ctx sdk.Context, appMappingID uint64) (found bool, err string) { - found, err = qp.liquidationKeeper.WasmWhitelistAppIdLiquidationQuery(ctx, appMappingID) + found, err = qp.liquidationKeeper.WasmWhitelistAppIDLiquidationQuery(ctx, appMappingID) return found, err } func (qp QueryPlugin) WasmRemoveWhitelistAppIDLiquidationQueryCheck(ctx sdk.Context, appMappingID uint64) (found bool, err string) { - found, err = qp.liquidationKeeper.WasmRemoveWhitelistAppIdLiquidationQuery(ctx, appMappingID) + found, err = qp.liquidationKeeper.WasmRemoveWhitelistAppIDLiquidationQuery(ctx, appMappingID) return found, err } diff --git a/cmd/comdex/genwasm.go b/cmd/comdex/genwasm.go index 3b3a6acd2..4b44969e9 100644 --- a/cmd/comdex/genwasm.go +++ b/cmd/comdex/genwasm.go @@ -23,5 +23,4 @@ func AddGenesisWasmMsgCmd(defaultNodeHome string) *cobra.Command { wasmcli.GenesisListCodesCmd(defaultNodeHome, genesisIO), ) return txCmd - } diff --git a/cmd/comdex/main.go b/cmd/comdex/main.go index 357239d90..1b746d1fe 100644 --- a/cmd/comdex/main.go +++ b/cmd/comdex/main.go @@ -10,7 +10,6 @@ import ( ) func main() { - comdex.SetAccountAddressPrefixes() root, _ := NewRootCmd() diff --git a/x/asset/client/cli/flags.go b/x/asset/client/cli/flags.go index ff123e893..7ed710aeb 100644 --- a/x/asset/client/cli/flags.go +++ b/x/asset/client/cli/flags.go @@ -7,7 +7,6 @@ import ( ) const ( - flagLiquidationRatio = "liquidation-ratio" flagName = "name" flagDenom = "denom" flagDecimals = "decimals" diff --git a/x/asset/types/msg.go b/x/asset/types/msg.go index e7a57709f..44574916c 100644 --- a/x/asset/types/msg.go +++ b/x/asset/types/msg.go @@ -11,14 +11,6 @@ var ( _ sdk.Msg = (*MsgAddPairRequest)(nil) ) -func NewMsgAddPairRequest(from sdk.AccAddress, assetIn, assetOut uint64, liquidationRatio sdk.Dec) *MsgAddPairRequest { - return &MsgAddPairRequest{ - From: from.String(), - AssetIn: assetIn, - AssetOut: assetOut, - } -} - func (m *MsgAddPairRequest) ValidateBasic() error { if m.From == "" { return errors.Wrap(ErrorInvalidFrom, "from cannot be empty") @@ -45,15 +37,6 @@ func (m *MsgAddPairRequest) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{from} } -func NewMsgAddAssetRequest(from sdk.AccAddress, name, denom string, decimals int64) *MsgAddAssetRequest { - return &MsgAddAssetRequest{ - From: from.String(), - Name: name, - Denom: denom, - Decimals: decimals, - } -} - func (m *MsgAddAssetRequest) ValidateBasic() error { if m.From == "" { return errors.Wrap(ErrorInvalidFrom, "from cannot be empty") @@ -89,16 +72,6 @@ func (m *MsgAddAssetRequest) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{from} } -func NewMsgUpdateAssetRequest(from sdk.AccAddress, id uint64, name, denom string, decimals int64) *MsgUpdateAssetRequest { - return &MsgUpdateAssetRequest{ - From: from.String(), - Id: id, - Name: name, - Denom: denom, - Decimals: decimals, - } -} - func (m *MsgUpdateAssetRequest) ValidateBasic() error { if m.From == "" { return errors.Wrap(ErrorInvalidFrom, "from cannot be empty") diff --git a/x/auction/keeper/dutch.go b/x/auction/keeper/dutch.go index 07a25bd69..8fc8c077f 100644 --- a/x/auction/keeper/dutch.go +++ b/x/auction/keeper/dutch.go @@ -446,14 +446,14 @@ func (k Keeper) CloseDutchAuction( // //Transfer balance from collector module to auction module // requiredAmount := dutchAuction.InflowTokenTargetAmount.Sub(dutchAuction.InflowTokenCurrentAmount) - // _, err := k.GetAmountFromCollector(ctx, dutchAuction.AppId, dutchAuction.AssetInId, requiredAmount.Amount) + // _, err := k.GetAmountFromCollector(ctx, dutchAuction.appID, dutchAuction.AssetInId, requiredAmount.Amount) // if err != nil { // return err // } // //storing protocol loss - // k.SetProtocolStatistics(ctx, dutchAuction.AppId, dutchAuction.AssetInId, requiredAmount.Amount) + // k.SetProtocolStatistics(ctx, dutchAuction.appID, dutchAuction.AssetInId, requiredAmount.Amount) // // burnToken.Amount = lockedVault.AmountOut // } diff --git a/x/auction/keeper/math.go b/x/auction/keeper/math.go index 78b9367d1..dea4e43e1 100644 --- a/x/auction/keeper/math.go +++ b/x/auction/keeper/math.go @@ -8,14 +8,6 @@ func Multiply(a, b sdk.Dec) sdk.Dec { return a.Mul(b) } -func Add(a, b sdk.Dec) sdk.Dec { - return a.Add(b) -} - -func Sub(a, b sdk.Dec) sdk.Dec { - return a.Sub(b) -} - func (k Keeper) getOutflowTokenInitialPrice(price sdk.Int, buffer sdk.Dec) sdk.Dec { result := buffer.Mul(price.ToDec()) return result diff --git a/x/auction/keeper/query_server.go b/x/auction/keeper/query_server.go index ec83527e7..0382e9774 100644 --- a/x/auction/keeper/query_server.go +++ b/x/auction/keeper/query_server.go @@ -321,7 +321,7 @@ func (q *QueryServer) QueryProtocolStatistics(c context.Context, req *types.Quer key []byte ) - key = types.ProtocolStatisticsAppIdKey(req.AppId) + key = types.ProtocolStatisticsAppIDKey(req.AppId) pagination, err := query.FilteredPaginate( prefix.NewStore(q.Store(ctx), key), diff --git a/x/auction/types/keys.go b/x/auction/types/keys.go index 602ecb81f..647f0b259 100644 --- a/x/auction/types/keys.go +++ b/x/auction/types/keys.go @@ -45,8 +45,8 @@ func AuctionKey(appID uint64, auctionType string, auctionID uint64) []byte { return append(append(append(AuctionKeyPrefix, sdk.Uint64ToBigEndian(appID)...), auctionType...), sdk.Uint64ToBigEndian(auctionID)...) } -func UserKey(bidder string, appID uint64, auctionType string, bidId uint64) []byte { - return append(append(append(append(UserKeyPrefix, bidder...), sdk.Uint64ToBigEndian(appID)...), auctionType...), sdk.Uint64ToBigEndian(bidId)...) +func UserKey(bidder string, appID uint64, auctionType string, bidID uint64) []byte { + return append(append(append(append(UserKeyPrefix, bidder...), sdk.Uint64ToBigEndian(appID)...), auctionType...), sdk.Uint64ToBigEndian(bidID)...) } func UserAuctionTypeKey(bidder string, appID uint64, auctionType string) []byte { @@ -73,12 +73,12 @@ func HistoryAuctionTypeKey(appID uint64, auctionType string) []byte { return append(append(HistoryAuctionKeyPrefix, sdk.Uint64ToBigEndian(appID)...), auctionType...) } -func ProtocolStatisticsKey(appID, assetId uint64) []byte { - return append(append(ProtocolStatisticsPrefixKey, sdk.Uint64ToBigEndian(appID)...), sdk.Uint64ToBigEndian(assetId)...) +func ProtocolStatisticsKey(appID, assetID uint64) []byte { + return append(append(ProtocolStatisticsPrefixKey, sdk.Uint64ToBigEndian(appID)...), sdk.Uint64ToBigEndian(assetID)...) } -func ProtocolStatisticsAppIdKey(appId uint64) []byte { - return append(ProtocolStatisticsPrefixKey, sdk.Uint64ToBigEndian(appId)...) +func ProtocolStatisticsAppIDKey(appID uint64) []byte { + return append(ProtocolStatisticsPrefixKey, sdk.Uint64ToBigEndian(appID)...) } func AuctionParamsKey(id uint64) []byte { diff --git a/x/collector/keeper/collector.go b/x/collector/keeper/collector.go index 77d99f744..b912dfae1 100644 --- a/x/collector/keeper/collector.go +++ b/x/collector/keeper/collector.go @@ -71,7 +71,7 @@ func (k *Keeper) UpdateCollector(ctx sdk.Context, appID, assetID uint64, collect collectorData, found := k.GetAppidToAssetCollectorMapping(ctx, appID) if !found { - //create a new instance of AppId To AssetCollectorMapping + //create a new instance of appID To AssetCollectorMapping var collectorNewData types.AppIdToAssetCollectorMapping collectorNewData.AppId = appID @@ -157,7 +157,6 @@ func (k *Keeper) UpdateCollector(ctx sdk.Context, appID, assetID uint64, collect } } return nil - } // SetAppidToAssetCollectorMapping update collector with app_id and asset @@ -249,7 +248,6 @@ func (k *Keeper) SetCollectorLookupTable(ctx sdk.Context, records ...types.Colle store.Set(key, value) } return nil - } func (k *Keeper) SetCollectorLookupTableForWasm(ctx sdk.Context, records ...types.CollectorLookupTable) error { @@ -276,7 +274,6 @@ func (k *Keeper) SetCollectorLookupTableForWasm(ctx sdk.Context, records ...type } } return nil - } // GetCollectorLookupTable returns collector lookup table diff --git a/x/collector/module.go b/x/collector/module.go index 055d1e458..9d8befe20 100644 --- a/x/collector/module.go +++ b/x/collector/module.go @@ -137,7 +137,6 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd func (am AppModule) RegisterServices(cfg module.Configurator) { //types.RegisterQueryServiceServer(cfg.QueryServer(), am.keeper) types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper)) - } // RegisterInvariants registers the capability module's invariants. diff --git a/x/lend/client/cli/flags.go b/x/lend/client/cli/flags.go index fc4e1b055..27a6428fd 100644 --- a/x/lend/client/cli/flags.go +++ b/x/lend/client/cli/flags.go @@ -22,20 +22,6 @@ func ParseStringFromString(s string, separator string) ([]string, error) { return parsedStrings, nil } -func ParseInt64SliceFromString(s string, separator string) ([]int64, error) { - var parsedInts []int64 - for _, s := range strings.Split(s, separator) { - s = strings.TrimSpace(s) - - parsed, err := strconv.ParseInt(s, 10, 64) - if err != nil { - return []int64{}, err - } - parsedInts = append(parsedInts, parsed) - } - return parsedInts, nil -} - func ParseUint64SliceFromString(s string, separator string) ([]uint64, error) { var parsedInts []uint64 for _, s := range strings.Split(s, separator) { diff --git a/x/liquidation/client/cli/tx.go b/x/liquidation/client/cli/tx.go index 828acb1ac..fd5c89aee 100644 --- a/x/liquidation/client/cli/tx.go +++ b/x/liquidation/client/cli/tx.go @@ -25,7 +25,7 @@ func txWhitelistAppID() *cobra.Command { return err } - msg := types.NewMsgWhitelistAppId( + msg := types.NewMsgWhitelistAppID( appMappingID, ctx.GetFromAddress(), ) diff --git a/x/liquidation/keeper/keeper.go b/x/liquidation/keeper/keeper.go index 682d3ace3..c60254635 100644 --- a/x/liquidation/keeper/keeper.go +++ b/x/liquidation/keeper/keeper.go @@ -75,7 +75,7 @@ func uint64InSlice(a uint64, list []uint64) bool { return false } -func (k Keeper) WhitelistAppId(ctx sdk.Context, appMappingId uint64) error { +func (k Keeper) WhitelistAppID(ctx sdk.Context, appMappingId uint64) error { found := uint64InSlice(appMappingId, k.GetAppIds(ctx).WhitelistedAppMappingIds) if found { return types.ErrAppIDExists @@ -111,7 +111,7 @@ func (k Keeper) RemoveWhitelistAsset(ctx sdk.Context, appMappingID uint64) error //Wasm tx and query binding functions -func (k Keeper) WasmWhitelistAppIdLiquidation(ctx sdk.Context, appMappingId uint64) error { +func (k Keeper) WasmWhitelistAppIDLiquidation(ctx sdk.Context, appMappingId uint64) error { WhitelistedAppIds := append(k.GetAppIds(ctx).WhitelistedAppMappingIds, appMappingId) UpdatedWhitelistedAppIds := types.WhitelistedAppIds{ WhitelistedAppMappingIds: WhitelistedAppIds, @@ -120,7 +120,7 @@ func (k Keeper) WasmWhitelistAppIdLiquidation(ctx sdk.Context, appMappingId uint return nil } -func (k Keeper) WasmWhitelistAppIdLiquidationQuery(ctx sdk.Context, appMappingId uint64) (bool, string) { +func (k Keeper) WasmWhitelistAppIDLiquidationQuery(ctx sdk.Context, appMappingId uint64) (bool, string) { found := uint64InSlice(appMappingId, k.GetAppIds(ctx).WhitelistedAppMappingIds) if found { return false, types.ErrAppIDExists.Error() @@ -128,7 +128,7 @@ func (k Keeper) WasmWhitelistAppIdLiquidationQuery(ctx sdk.Context, appMappingId return true, "" } -func (k Keeper) WasmRemoveWhitelistAppIdLiquidation(ctx sdk.Context, appMappingId uint64) error { +func (k Keeper) WasmRemoveWhitelistAppIDLiquidation(ctx sdk.Context, appMappingId uint64) error { WhitelistedAppIds := k.GetAppIds(ctx).WhitelistedAppMappingIds found := uint64InSlice(appMappingId, k.GetAppIds(ctx).WhitelistedAppMappingIds) if !found { @@ -149,7 +149,7 @@ func (k Keeper) WasmRemoveWhitelistAppIdLiquidation(ctx sdk.Context, appMappingI return nil } -func (k Keeper) WasmRemoveWhitelistAppIdLiquidationQuery(ctx sdk.Context, appMappingId uint64) (bool, string) { +func (k Keeper) WasmRemoveWhitelistAppIDLiquidationQuery(ctx sdk.Context, appMappingId uint64) (bool, string) { found := uint64InSlice(appMappingId, k.GetAppIds(ctx).WhitelistedAppMappingIds) if !found { return false, types.ErrAppIDDoesNotExists.Error() diff --git a/x/liquidation/keeper/msg_server.go b/x/liquidation/keeper/msg_server.go index 087a6eca2..d77ede293 100644 --- a/x/liquidation/keeper/msg_server.go +++ b/x/liquidation/keeper/msg_server.go @@ -19,7 +19,7 @@ var _ types.MsgServer = msgServer{} func (m msgServer) WhitelistApp(goCtx context.Context, id *types.WhitelistAppId) (*types.MsgWhitelistAppIdResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - if err := m.Keeper.WhitelistAppId(ctx, id.AppMappingId); err != nil { + if err := m.Keeper.WhitelistAppID(ctx, id.AppMappingId); err != nil { return nil, err } return &types.MsgWhitelistAppIdResponse{}, nil diff --git a/x/liquidation/types/codec.go b/x/liquidation/types/codec.go index 05889b09c..65a9adfc9 100644 --- a/x/liquidation/types/codec.go +++ b/x/liquidation/types/codec.go @@ -14,7 +14,6 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - registry.RegisterImplementations( (*sdk.Msg)(nil), &WhitelistAppId{}, diff --git a/x/liquidation/types/msg.go b/x/liquidation/types/msg.go index c74af9d07..c36cebbd0 100644 --- a/x/liquidation/types/msg.go +++ b/x/liquidation/types/msg.go @@ -2,7 +2,7 @@ package types import sdk "github.com/cosmos/cosmos-sdk/types" -func NewMsgWhitelistAppId(appMappingId uint64, from sdk.AccAddress) *WhitelistAppId { +func NewMsgWhitelistAppID(appMappingId uint64, from sdk.AccAddress) *WhitelistAppId { return &WhitelistAppId{ AppMappingId: appMappingId, From: from.String(),