diff --git a/x/gmp/client/cli/query.go b/x/gmp/client/cli/query.go index c8c5f44..5c7ff78 100644 --- a/x/gmp/client/cli/query.go +++ b/x/gmp/client/cli/query.go @@ -2,15 +2,10 @@ package cli import ( "fmt" - // "strings" - - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" - // sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sagaxyz/ssc/x/gmp/types" + "github.com/spf13/cobra" ) // GetQueryCmd returns the cli query commands for this module @@ -27,6 +22,5 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdQueryParams()) // this line is used by starport scaffolding # 1 - return cmd + return cmd } - diff --git a/x/gmp/client/cli/tx.go b/x/gmp/client/cli/tx.go index b10fc9f..2e7b8a7 100644 --- a/x/gmp/client/cli/tx.go +++ b/x/gmp/client/cli/tx.go @@ -7,12 +7,11 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" "github.com/sagaxyz/ssc/x/gmp/types" ) var ( - DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds()) + DefaultRelativePacketTimeoutTimestamp = (time.Duration(10) * time.Minute).Nanoseconds() ) const ( @@ -32,5 +31,5 @@ func GetTxCmd() *cobra.Command { // this line is used by starport scaffolding # 1 - return cmd + return cmd } diff --git a/x/gmp/genesis.go b/x/gmp/genesis.go index aa3e662..50f7f7c 100644 --- a/x/gmp/genesis.go +++ b/x/gmp/genesis.go @@ -8,18 +8,18 @@ import ( // InitGenesis initializes the module's state from a provided genesis state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { - // this line is used by starport scaffolding # genesis/module/init -k.SetPort(ctx, genState.PortId) -// Only try to bind to port if it is not already bound, since we may already own -// port capability from capability InitGenesis -if !k.IsBound(ctx, genState.PortId) { - // module binds to the port on InitChain - // and claims the returned capability - err := k.BindPort(ctx, genState.PortId) - if err != nil { - panic("could not claim port capability: " + err.Error()) + // this line is used by starport scaffolding # genesis/module/init + k.SetPort(ctx, genState.PortId) + // Only try to bind to port if it is not already bound, since we may already own + // port capability from capability InitGenesis + if !k.IsBound(ctx, genState.PortId) { + // module binds to the port on InitChain + // and claims the returned capability + err := k.BindPort(ctx, genState.PortId) + if err != nil { + panic("could not claim port capability: " + err.Error()) + } } -} k.SetParams(ctx, genState.Params) } @@ -27,9 +27,8 @@ if !k.IsBound(ctx, genState.PortId) { func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { genesis := types.DefaultGenesis() genesis.Params = k.GetParams(ctx) + genesis.PortId = k.GetPort(ctx) + // this line is used by starport scaffolding # genesis/module/export - genesis.PortId = k.GetPort(ctx) -// this line is used by starport scaffolding # genesis/module/export - - return genesis + return genesis } diff --git a/x/gmp/genesis_test.go b/x/gmp/genesis_test.go index 64f5663..3cd2857 100644 --- a/x/gmp/genesis_test.go +++ b/x/gmp/genesis_test.go @@ -12,7 +12,7 @@ import ( func TestGenesis(t *testing.T) { genesisState := types.GenesisState{ - Params: types.DefaultParams(), + Params: types.DefaultParams(), PortId: types.PortID, // this line is used by starport scaffolding # genesis/test/state } diff --git a/x/gmp/keeper/msg_server_test.go b/x/gmp/keeper/msg_server_test.go index 0b61048..de0ef60 100644 --- a/x/gmp/keeper/msg_server_test.go +++ b/x/gmp/keeper/msg_server_test.go @@ -5,10 +5,10 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + keepertest "github.com/sagaxyz/ssc/testutil/keeper" + "github.com/sagaxyz/ssc/x/gmp/keeper" + "github.com/sagaxyz/ssc/x/gmp/types" "github.com/stretchr/testify/require" - "github.com/sagaxyz/ssc/x/gmp/types" - "github.com/sagaxyz/ssc/x/gmp/keeper" - keepertest "github.com/sagaxyz/ssc/testutil/keeper" ) func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) { diff --git a/x/gmp/keeper/params.go b/x/gmp/keeper/params.go index 59c1fda..cad6162 100644 --- a/x/gmp/keeper/params.go +++ b/x/gmp/keeper/params.go @@ -1,18 +1,16 @@ package keeper import ( - "github.com/sagaxyz/ssc/x/gmp/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sagaxyz/ssc/x/gmp/types" ) // GetParams get all parameters as types.Params func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams( - ) + return types.NewParams() } // SetParams set the params func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { k.paramstore.SetParamSet(ctx, ¶ms) } - diff --git a/x/gmp/keeper/params_test.go b/x/gmp/keeper/params_test.go index 7b14b53..061d628 100644 --- a/x/gmp/keeper/params_test.go +++ b/x/gmp/keeper/params_test.go @@ -3,9 +3,9 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/require" testkeeper "github.com/sagaxyz/ssc/testutil/keeper" "github.com/sagaxyz/ssc/x/gmp/types" + "github.com/stretchr/testify/require" ) func TestGetParams(t *testing.T) { diff --git a/x/gmp/keeper/query_params_test.go b/x/gmp/keeper/query_params_test.go index 70c16b0..dcc1496 100644 --- a/x/gmp/keeper/query_params_test.go +++ b/x/gmp/keeper/query_params_test.go @@ -4,9 +4,9 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - testkeeper "github.com/sagaxyz/ssc/testutil/keeper" + testkeeper "github.com/sagaxyz/ssc/testutil/keeper" "github.com/sagaxyz/ssc/x/gmp/types" + "github.com/stretchr/testify/require" ) func TestParamsQuery(t *testing.T) { diff --git a/x/gmp/module_ibc.go b/x/gmp/module_ibc.go index 0e80d6b..6fd47eb 100644 --- a/x/gmp/module_ibc.go +++ b/x/gmp/module_ibc.go @@ -24,8 +24,6 @@ type Message struct { Type int64 `json:"type"` } -type MessageType int - const ( // TypeUnrecognized means coin type is unrecognized TypeUnrecognized = iota @@ -130,14 +128,13 @@ func (im IBCModule) OnRecvPacket( // this line is used by starport scaffolding # oracle/packet/module/recv var data transfertypes.FungibleTokenPacketData - var err error if err := types.ModuleCdc.UnmarshalJSON(modulePacket.GetData(), &data); err != nil { ctx.Logger().Debug(fmt.Sprintf("cannot unmarshal ICS-20 transfer packet data: %s", err.Error())) return im.app.OnRecvPacket(ctx, modulePacket, relayer) } var msg Message - if err = json.Unmarshal([]byte(data.GetMemo()), &msg); err != nil { + if err := json.Unmarshal([]byte(data.GetMemo()), &msg); err != nil { ctx.Logger().Debug(fmt.Sprintf("cannot unmarshal memo: %s", err.Error())) return im.app.OnRecvPacket(ctx, modulePacket, relayer) } @@ -148,31 +145,26 @@ func (im IBCModule) OnRecvPacket( switch msg.Type { case TypeGeneralMessage: - ctx.Logger().Info(fmt.Sprintf("Got pure general message: %v", msg)) + ctx.Logger().Debug(fmt.Sprintf("Got pure general message: %v", msg)) return im.app.OnRecvPacket(ctx, modulePacket, relayer) case TypeGeneralMessageWithToken: - ctx.Logger().Info(fmt.Sprintf("Got general message with token: %v", msg)) + ctx.Logger().Debug(fmt.Sprintf("Got general message with token: %v", msg)) payloadType, err := abi.NewType("string", "", nil) if err != nil { ctx.Logger().Info(fmt.Sprintf("failed to create reflection: %s", err.Error())) return channeltypes.NewErrorAcknowledgement(cosmossdkerrors.Wrapf(transfertypes.ErrInvalidMemo, "unable to define new abi type (%s)", err.Error())) } - - // Add 4 bytes to the payload to match the length of the payload otherwise the unpack will fail payloadData := msg.Payload - ctx.Logger().Info(fmt.Sprintf("ABI-encoded data: %v", hex.EncodeToString(payloadData))) + ctx.Logger().Debug(fmt.Sprintf("ABI-encoded data: %v", hex.EncodeToString(payloadData))) + // Add 4 bytes to the payload to match the length of the payload otherwise the unpack will fail payloadData = append(make([]byte, 4), payloadData...) - ctx.Logger().Info(fmt.Sprintf("Padded ABI-encoded data: %v", hex.EncodeToString(payloadData))) - args, err := abi.Arguments{{Type: payloadType}}.Unpack(payloadData) if err != nil { - ctx.Logger().Info(fmt.Sprintf("failed to unpack: %s", err.Error())) + ctx.Logger().Debug(fmt.Sprintf("failed to unpack: %s", err.Error())) return channeltypes.NewErrorAcknowledgement(cosmossdkerrors.Wrapf(transfertypes.ErrInvalidMemo, "unable to unpack payload (%s)", err.Error())) } - ctx.Logger().Info(fmt.Sprintf("Unpacked data: %+v", args)) pfmPayload := args[0].(string) - ctx.Logger().Info(fmt.Sprintf("new memo: %s", pfmPayload)) data.Memo = string(pfmPayload) modulePacket.Data, err = types.ModuleCdc.MarshalJSON(&data) if err != nil { diff --git a/x/gmp/types/codec.go b/x/gmp/types/codec.go index fb6871d..8883bdf 100644 --- a/x/gmp/types/codec.go +++ b/x/gmp/types/codec.go @@ -2,14 +2,15 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + // this line is used by starport scaffolding # 1 "github.com/cosmos/cosmos-sdk/types/msgservice" ) func RegisterCodec(cdc *codec.LegacyAmino) { // this line is used by starport scaffolding # 2 -} +} func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { // this line is used by starport scaffolding # 3 @@ -18,6 +19,6 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { } var ( - Amino = codec.NewLegacyAmino() + Amino = codec.NewLegacyAmino() ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) ) diff --git a/x/gmp/types/errors.go b/x/gmp/types/errors.go index b5c6bc2..2e51288 100644 --- a/x/gmp/types/errors.go +++ b/x/gmp/types/errors.go @@ -8,7 +8,5 @@ import ( // x/gmp module sentinel errors var ( - ErrSample = cosmossdkerrors.Register(ModuleName, 1100, "sample error") - ErrInvalidPacketTimeout = cosmossdkerrors.Register(ModuleName, 1500, "invalid packet timeout") - ErrInvalidVersion = cosmossdkerrors.Register(ModuleName, 1501, "invalid version") + ErrSample = cosmossdkerrors.Register(ModuleName, 1100, "sample error") ) diff --git a/x/gmp/types/events_ibc.go b/x/gmp/types/events_ibc.go index 3caff28..07c66a4 100644 --- a/x/gmp/types/events_ibc.go +++ b/x/gmp/types/events_ibc.go @@ -2,10 +2,10 @@ package types // IBC events const ( - EventTypeTimeout = "timeout" + EventTypeTimeout = "timeout" // this line is used by starport scaffolding # ibc/packet/event - AttributeKeyAckSuccess = "success" - AttributeKeyAck = "acknowledgement" - AttributeKeyAckError = "error" + AttributeKeyAckSuccess = "success" + AttributeKeyAck = "acknowledgement" + AttributeKeyAckError = "error" ) diff --git a/x/gmp/types/genesis_test.go b/x/gmp/types/genesis_test.go index c023235..1846821 100644 --- a/x/gmp/types/genesis_test.go +++ b/x/gmp/types/genesis_test.go @@ -3,39 +3,39 @@ package types_test import ( "testing" - "github.com/stretchr/testify/require" "github.com/sagaxyz/ssc/x/gmp/types" + "github.com/stretchr/testify/require" ) func TestGenesisState_Validate(t *testing.T) { - tests := []struct { - desc string - genState *types.GenesisState - valid bool - } { - { - desc: "default is valid", - genState: types.DefaultGenesis(), - valid: true, - }, - { - desc: "valid genesis state", - genState: &types.GenesisState{ - PortId: types.PortID, - // this line is used by starport scaffolding # types/genesis/validField - }, - valid: true, - }, - // this line is used by starport scaffolding # types/genesis/testcase + tests := []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{ + PortId: types.PortID, + // this line is used by starport scaffolding # types/genesis/validField + }, + valid: true, + }, + // this line is used by starport scaffolding # types/genesis/testcase } for _, tc := range tests { t.Run(tc.desc, func(t *testing.T) { - err := tc.genState.Validate() - if tc.valid { - require.NoError(t, err) - } else { - require.Error(t, err) - } - }) - } -} \ No newline at end of file + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/gmp/types/params.go b/x/gmp/types/params.go index 52a8a05..357196a 100644 --- a/x/gmp/types/params.go +++ b/x/gmp/types/params.go @@ -1,38 +1,30 @@ package types import ( - - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "gopkg.in/yaml.v2" ) var _ paramtypes.ParamSet = (*Params)(nil) - - // ParamKeyTable the param key table for launch module func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } // NewParams creates a new Params instance -func NewParams( -) Params { - return Params{ - } +func NewParams() Params { + return Params{} } // DefaultParams returns a default set of parameters func DefaultParams() Params { - return NewParams( - ) + return NewParams() } // ParamSetPairs get the params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - } + return paramtypes.ParamSetPairs{} } // Validate validates the set of params diff --git a/x/ssc/client/cli/tx.go b/x/ssc/client/cli/tx.go index 5b2d29d..4e7597e 100644 --- a/x/ssc/client/cli/tx.go +++ b/x/ssc/client/cli/tx.go @@ -7,12 +7,11 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" "github.com/sagaxyz/ssc/x/ssc/types" ) var ( - DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds()) + DefaultRelativePacketTimeoutTimestamp = (time.Duration(10) * time.Minute).Nanoseconds() ) const (