From 3ab8739be9843f53645710726206003a50f6f0b2 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 9 May 2024 15:43:38 +0900 Subject: [PATCH 1/9] feat: change MakeSwapProposal to foundation proposal --- docs/core/proto-docs.md | 33 ++- proto/lbm/fswap/v1/fswap.proto | 7 +- proto/lbm/fswap/v1/tx.proto | 10 + simapp/app.go | 7 +- x/fswap/client/cli/tx.go | 73 +++-- x/fswap/client/proposal_handler.go | 8 - x/fswap/codec/codec.go | 17 -- x/fswap/handler.go | 27 -- x/fswap/keeper/keeper.go | 30 +- x/fswap/keeper/msg_server.go | 14 + x/fswap/proposal_handler_test.go | 40 --- x/fswap/types/codec.go | 33 ++- x/fswap/types/fswap.go | 20 +- x/fswap/types/fswap.pb.go | 228 ++++----------- x/fswap/types/genesis.go | 10 + x/fswap/types/msgs.go | 31 +- x/fswap/types/proposal.go | 54 ---- x/fswap/types/tx.pb.go | 443 +++++++++++++++++++++++++++-- 18 files changed, 668 insertions(+), 417 deletions(-) delete mode 100644 x/fswap/client/proposal_handler.go delete mode 100644 x/fswap/handler.go delete mode 100644 x/fswap/proposal_handler_test.go delete mode 100644 x/fswap/types/proposal.go diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 379b2d65ea..1c7e53f40f 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -973,6 +973,8 @@ - [Query](#lbm.fswap.v1.Query) - [lbm/fswap/v1/tx.proto](#lbm/fswap/v1/tx.proto) + - [MsgMakeSwapProposal](#lbm.fswap.v1.MsgMakeSwapProposal) + - [MsgMakeSwapProposalResponse](#lbm.fswap.v1.MsgMakeSwapProposalResponse) - [MsgSwap](#lbm.fswap.v1.MsgSwap) - [MsgSwapAll](#lbm.fswap.v1.MsgSwapAll) - [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse) @@ -14163,13 +14165,11 @@ Msg defines the foundation Msg service. ### MakeSwapProposal -From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk based on 0.45.10 + | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | | -| `description` | [string](#string) | | | | `swap` | [Swap](#lbm.fswap.v1.Swap) | | | | `to_denom_metadata` | [cosmos.bank.v1beta1.Metadata](#cosmos.bank.v1beta1.Metadata) | | | @@ -14398,6 +14398,32 @@ GenesisState defines the fswap module's genesis state. + + +### MsgMakeSwapProposal + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `authority` | [string](#string) | | authority is the address of the privileged account. | +| `proposal` | [MakeSwapProposal](#lbm.fswap.v1.MakeSwapProposal) | | | + + + + + + + + +### MsgMakeSwapProposalResponse + + + + + + + ### MsgSwap @@ -14467,6 +14493,7 @@ GenesisState defines the fswap module's genesis state. | ----------- | ------------ | ------------- | ------------| ------- | -------- | | `Swap` | [MsgSwap](#lbm.fswap.v1.MsgSwap) | [MsgSwapResponse](#lbm.fswap.v1.MsgSwapResponse) | | | | `SwapAll` | [MsgSwapAll](#lbm.fswap.v1.MsgSwapAll) | [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse) | | | +| `MakeSwapProposal` | [MsgMakeSwapProposal](#lbm.fswap.v1.MsgMakeSwapProposal) | [MsgMakeSwapProposalResponse](#lbm.fswap.v1.MsgMakeSwapProposalResponse) | | | diff --git a/proto/lbm/fswap/v1/fswap.proto b/proto/lbm/fswap/v1/fswap.proto index 13a5c2a006..5d39315b49 100644 --- a/proto/lbm/fswap/v1/fswap.proto +++ b/proto/lbm/fswap/v1/fswap.proto @@ -26,14 +26,11 @@ message SwapStats { int32 swap_count = 1; } -// From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk based on 0.45.10 message MakeSwapProposal { option (gogoproto.goproto_stringer) = false; - string title = 1; - string description = 2; - Swap swap = 3 [(gogoproto.nullable) = false]; - cosmos.bank.v1beta1.Metadata to_denom_metadata = 4 + Swap swap = 1 [(gogoproto.nullable) = false]; + cosmos.bank.v1beta1.Metadata to_denom_metadata = 2 [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false]; } diff --git a/proto/lbm/fswap/v1/tx.proto b/proto/lbm/fswap/v1/tx.proto index 07813f9eab..15771728d7 100644 --- a/proto/lbm/fswap/v1/tx.proto +++ b/proto/lbm/fswap/v1/tx.proto @@ -5,10 +5,12 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types"; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; +import "lbm/fswap/v1/fswap.proto"; service Msg { rpc Swap(MsgSwap) returns (MsgSwapResponse); rpc SwapAll(MsgSwapAll) returns (MsgSwapAllResponse); + rpc MakeSwapProposal(MsgMakeSwapProposal) returns (MsgMakeSwapProposalResponse); } message MsgSwap { @@ -30,3 +32,11 @@ message MsgSwapAll { } message MsgSwapAllResponse {} + +message MsgMakeSwapProposal { + // authority is the address of the privileged account. + string authority = 1; + MakeSwapProposal proposal = 2; +} + +message MsgMakeSwapProposalResponse {} diff --git a/simapp/app.go b/simapp/app.go index 9b064b19b2..ce260e5f29 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -76,7 +76,6 @@ import ( foundationkeeper "github.com/Finschia/finschia-sdk/x/foundation/keeper" foundationmodule "github.com/Finschia/finschia-sdk/x/foundation/module" "github.com/Finschia/finschia-sdk/x/fswap" - fswapclient "github.com/Finschia/finschia-sdk/x/fswap/client" fswapkeeper "github.com/Finschia/finschia-sdk/x/fswap/keeper" fswaptypes "github.com/Finschia/finschia-sdk/x/fswap/types" "github.com/Finschia/finschia-sdk/x/genutil" @@ -134,7 +133,6 @@ var ( upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler, foundationclient.ProposalHandler, - fswapclient.ProposalHandler, ), params.AppModuleBasic{}, crisis.AppModuleBasic{}, @@ -344,7 +342,7 @@ func NewSimApp( app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.BaseApp.MsgServiceRouter()) fswapConfig := fswaptypes.DefaultConfig() - app.FswapKeeper = fswapkeeper.NewKeeper(appCodec, keys[fswaptypes.StoreKey], fswapConfig, app.BankKeeper) + app.FswapKeeper = fswapkeeper.NewKeeper(appCodec, keys[fswaptypes.StoreKey], fswapConfig, fswaptypes.DefaultAuthority().String(), app.BankKeeper) // register the proposal types govRouter := govtypes.NewRouter() @@ -352,8 +350,7 @@ func NewSimApp( AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). - AddRoute(foundation.RouterKey, foundationkeeper.NewFoundationProposalsHandler(app.FoundationKeeper)). - AddRoute(fswaptypes.RouterKey, fswap.NewSwapHandler(app.FswapKeeper)) + AddRoute(foundation.RouterKey, foundationkeeper.NewFoundationProposalsHandler(app.FoundationKeeper)) govKeeper := govkeeper.NewKeeper( appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, diff --git a/x/fswap/client/cli/tx.go b/x/fswap/client/cli/tx.go index 433c8ae33e..0568106f21 100644 --- a/x/fswap/client/cli/tx.go +++ b/x/fswap/client/cli/tx.go @@ -13,8 +13,6 @@ import ( sdkerrors "github.com/Finschia/finschia-sdk/types/errors" bank "github.com/Finschia/finschia-sdk/x/bank/types" "github.com/Finschia/finschia-sdk/x/fswap/types" - govcli "github.com/Finschia/finschia-sdk/x/gov/client/cli" - gov "github.com/Finschia/finschia-sdk/x/gov/types" ) const ( @@ -36,6 +34,7 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand( CmdTxMsgSwap(), CmdTxMsgSwapAll(), + CmdMsgMakeSwapProposal(), ) return cmd @@ -115,21 +114,21 @@ func CmdTxMsgSwapAll() *cobra.Command { return cmd } -// NewCmdMakeSwapProposal implements a command handler for submitting a swap init proposal transaction. -func NewCmdMakeSwapProposal() *cobra.Command { +// CmdMsgMakeSwapProposal implements a command handler for submitting a swap init proposal transaction. +func CmdMsgMakeSwapProposal() *cobra.Command { cmd := &cobra.Command{ - Use: "make-swap [messages-json]", - Args: cobra.ExactArgs(1), - Short: "todo", + Use: "make-swap-proposal [authority] [metadata-json]", + Args: cobra.ExactArgs(2), + Short: "Make swap proposal", Long: ` Parameters: - messages-json: messages in json format that will be executed if the proposal is accepted. + metadata-json: messages in json format that will be executed if the proposal is accepted. -Example of the content of messages-json: +Example of the content of metadata-json: { "metadata": { - "description": "the base coin of Finschia mainnet", + "description": "example of to-denom is finschia cony", "denom_units": [ { "denom": "cony", @@ -152,19 +151,11 @@ Example of the content of messages-json: } `, RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - from := clientCtx.GetFromAddress() - - title, err := cmd.Flags().GetString(govcli.FlagTitle) - if err != nil { + if err := validateGenerateOnly(cmd); err != nil { return err } - description, err := cmd.Flags().GetString(govcli.FlagDescription) + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } @@ -178,10 +169,12 @@ Example of the content of messages-json: if err != nil { return err } + amountCapStr, err := cmd.Flags().GetString(FlagAmountCapForToDenom) if err != nil { return err } + amountCap, ok := sdk.NewIntFromString(amountCapStr) if !ok { return sdkerrors.ErrInvalidRequest.Wrapf("failed to parse %s %s", FlagAmountCapForToDenom, amountCap.String()) @@ -202,42 +195,44 @@ Example of the content of messages-json: SwapRate: swapRateDec, } - toDenomMetadata, err := parseToDenomMetadata(args[0]) - if err != nil { - return err - } - - content := types.NewMakeSwapProposal(title, description, swap, toDenomMetadata) - - depositStr, err := cmd.Flags().GetString(govcli.FlagDeposit) - if err != nil { - return err - } - deposit, err := sdk.ParseCoinsNormalized(depositStr) + authority := args[0] + toDenomMetadata, err := parseToDenomMetadata(args[1]) if err != nil { return err } - msg, err := gov.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err + msg := types.MsgMakeSwapProposal{ + Authority: authority, + Proposal: &types.MakeSwapProposalTmp{ + Swap: swap, + ToDenomMetadata: toDenomMetadata, + }, } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) }, } - cmd.Flags().String(govcli.FlagTitle, "", "title of proposal") - cmd.Flags().String(govcli.FlagDescription, "", "description of proposal") - cmd.Flags().String(govcli.FlagDeposit, "", "deposit of proposal") cmd.Flags().String(FlagFromDenom, "", "cony") cmd.Flags().String(FlagToDenom, "", "PDT") cmd.Flags().String(FlagAmountCapForToDenom, "0", "tbd") cmd.Flags().String(FlagSwapRate, "0", "tbd") + flags.AddTxFlagsToCmd(cmd) return cmd } +func validateGenerateOnly(cmd *cobra.Command) error { + generateOnly, err := cmd.Flags().GetBool(flags.FlagGenerateOnly) + if err != nil { + return err + } + if !generateOnly { + return fmt.Errorf("you must use it with the flag --%s", flags.FlagGenerateOnly) + } + return nil +} + func parseToDenomMetadata(jsonDenomMetadata string) (bank.Metadata, error) { type toDenomMeta struct { Metadata bank.Metadata `json:"metadata"` diff --git a/x/fswap/client/proposal_handler.go b/x/fswap/client/proposal_handler.go deleted file mode 100644 index 72c073b733..0000000000 --- a/x/fswap/client/proposal_handler.go +++ /dev/null @@ -1,8 +0,0 @@ -package client - -import ( - "github.com/Finschia/finschia-sdk/x/fswap/client/cli" - govclient "github.com/Finschia/finschia-sdk/x/gov/client" -) - -var ProposalHandler = govclient.NewProposalHandler(cli.NewCmdMakeSwapProposal) diff --git a/x/fswap/codec/codec.go b/x/fswap/codec/codec.go index 7cbd4f6a69..1fae45a0c8 100644 --- a/x/fswap/codec/codec.go +++ b/x/fswap/codec/codec.go @@ -1,18 +1 @@ package codec - -import ( - "github.com/Finschia/finschia-sdk/codec" - cryptocodec "github.com/Finschia/finschia-sdk/crypto/codec" - sdk "github.com/Finschia/finschia-sdk/types" -) - -var ( - Amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewAminoCodec(Amino) -) - -func init() { - cryptocodec.RegisterCrypto(Amino) - codec.RegisterEvidences(Amino) - sdk.RegisterLegacyAminoCodec(Amino) -} diff --git a/x/fswap/handler.go b/x/fswap/handler.go deleted file mode 100644 index 7bae485c7e..0000000000 --- a/x/fswap/handler.go +++ /dev/null @@ -1,27 +0,0 @@ -package fswap - -import ( - sdk "github.com/Finschia/finschia-sdk/types" - sdkerrors "github.com/Finschia/finschia-sdk/types/errors" - "github.com/Finschia/finschia-sdk/x/fswap/keeper" - "github.com/Finschia/finschia-sdk/x/fswap/types" - govtypes "github.com/Finschia/finschia-sdk/x/gov/types" -) - -// NewSwapHandler creates a governance handler to manage new proposal types. -// It enables Swap to propose a swap init -func NewSwapHandler(k keeper.Keeper) govtypes.Handler { - return func(ctx sdk.Context, content govtypes.Content) error { - switch c := content.(type) { - case *types.MakeSwapProposal: - return handleMakeSwapProposal(ctx, k, c) - - default: - return sdkerrors.ErrUnknownRequest.Wrapf("unrecognized sawp proposal content type: %T", c) - } - } -} - -func handleMakeSwapProposal(ctx sdk.Context, k keeper.Keeper, p *types.MakeSwapProposal) error { - return k.MakeSwap(ctx, p.Swap, p.ToDenomMetadata) -} diff --git a/x/fswap/keeper/keeper.go b/x/fswap/keeper/keeper.go index f21a246cea..9ba08b97f0 100644 --- a/x/fswap/keeper/keeper.go +++ b/x/fswap/keeper/keeper.go @@ -9,23 +9,33 @@ import ( "github.com/Finschia/finschia-sdk/store/prefix" storetypes "github.com/Finschia/finschia-sdk/store/types" sdk "github.com/Finschia/finschia-sdk/types" + sdkerrors "github.com/Finschia/finschia-sdk/types/errors" "github.com/Finschia/finschia-sdk/x/fswap/types" ) type Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - - config types.Config - + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + config types.Config + authority string BankKeeper } -func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, config types.Config, bk BankKeeper) Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, config types.Config, authority string, bk BankKeeper) Keeper { + if _, err := sdk.AccAddressFromBech32(authority); err != nil { + panic("authority is not a valid acc address") + } + + // authority is x/foundation module account for now. + if authority != types.DefaultAuthority().String() { + panic("x/foundation authority must be the module account") + } + return Keeper{ cdc, storeKey, config, + authority, bk, } } @@ -201,3 +211,11 @@ func (k Keeper) setSwapStats(ctx sdk.Context, stats types.SwapStats) error { store.Set(swapStatsKey, bz) return nil } + +func (k Keeper) validateAuthority(authority string) error { + if authority != k.authority { + return sdkerrors.ErrUnauthorized.Wrapf("invalid authority; expected %s, got %s", k.authority, authority) + } + + return nil +} diff --git a/x/fswap/keeper/msg_server.go b/x/fswap/keeper/msg_server.go index 1f3086fc4f..211635669a 100644 --- a/x/fswap/keeper/msg_server.go +++ b/x/fswap/keeper/msg_server.go @@ -60,3 +60,17 @@ func (s MsgServer) SwapAll(ctx context.Context, req *types.MsgSwapAll) (*types.M return &types.MsgSwapAllResponse{}, nil } + +func (s MsgServer) MakeSwapProposal(ctx context.Context, req *types.MsgMakeSwapProposal) (*types.MsgMakeSwapProposalResponse, error) { + c := sdk.UnwrapSDKContext(ctx) + + if err := s.keeper.validateAuthority(req.Authority); err != nil { + return nil, err + } + + if err := s.keeper.MakeSwap(c, req.GetProposal().GetSwap(), req.GetProposal().GetToDenomMetadata()); err != nil { + return nil, err + } + + return &types.MsgMakeSwapProposalResponse{}, nil +} diff --git a/x/fswap/proposal_handler_test.go b/x/fswap/proposal_handler_test.go deleted file mode 100644 index c55bd5a2e4..0000000000 --- a/x/fswap/proposal_handler_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package fswap_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - - "github.com/Finschia/finschia-sdk/simapp" - sdk "github.com/Finschia/finschia-sdk/types" - bank "github.com/Finschia/finschia-sdk/x/bank/types" - "github.com/Finschia/finschia-sdk/x/fswap" - "github.com/Finschia/finschia-sdk/x/fswap/types" -) - -func testProposal(swap types.Swap) *types.MakeSwapProposal { - return types.NewMakeSwapProposal("Test", "description", swap, bank.Metadata{Base: "DUM"}) -} - -func TestProposalHandlerPassed(t *testing.T) { - app := simapp.Setup(false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - forConyRate, err := sdk.NewDecFromStr("148079656000000") - require.NoError(t, err) - swap := types.Swap{ - FromDenom: "aaa", - ToDenom: "bbb", - AmountCapForToDenom: sdk.NewInt(100), - SwapRate: forConyRate, - } - tp := testProposal(swap) - hdlr := fswap.NewSwapHandler(app.FswapKeeper) - require.NoError(t, hdlr(ctx, tp)) - - // todo check contents -} - -// todo check failed -// func TestProposalHandlerFailed(t *testing.T) {} diff --git a/x/fswap/types/codec.go b/x/fswap/types/codec.go index de8865ec57..6a9fce2c25 100644 --- a/x/fswap/types/codec.go +++ b/x/fswap/types/codec.go @@ -4,36 +4,39 @@ import ( "github.com/Finschia/finschia-sdk/codec" "github.com/Finschia/finschia-sdk/codec/legacy" "github.com/Finschia/finschia-sdk/codec/types" + cryptocodec "github.com/Finschia/finschia-sdk/crypto/codec" sdk "github.com/Finschia/finschia-sdk/types" "github.com/Finschia/finschia-sdk/types/msgservice" - fscodec "github.com/Finschia/finschia-sdk/x/fswap/codec" - govcodec "github.com/Finschia/finschia-sdk/x/gov/codec" - govtypes "github.com/Finschia/finschia-sdk/x/gov/types" + fdncodec "github.com/Finschia/finschia-sdk/x/foundation/codec" ) +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(Amino) +) + +func init() { + cryptocodec.RegisterCrypto(Amino) + codec.RegisterEvidences(Amino) + sdk.RegisterLegacyAminoCodec(Amino) + + RegisterLegacyAminoCodec(Amino) + RegisterLegacyAminoCodec(fdncodec.Amino) +} + // RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgSwap{}, "lbm-sdk/MsgSwap") legacy.RegisterAminoMsg(cdc, &MsgSwapAll{}, "lbm-sdk/MsgSwapAll") - - cdc.RegisterConcrete(&MakeSwapProposal{}, "lbm-sdk/MakeSwapProposal", nil) + legacy.RegisterAminoMsg(cdc, &MsgMakeSwapProposal{}, "lbm-sdk/MsgMakeSwapProposal") } func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSwap{}, &MsgSwapAll{}, + &MsgMakeSwapProposal{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) - - registry.RegisterImplementations( - (*govtypes.Content)(nil), - &MakeSwapProposal{}, - ) -} - -func init() { - RegisterLegacyAminoCodec(govcodec.Amino) - RegisterLegacyAminoCodec(fscodec.Amino) } diff --git a/x/fswap/types/fswap.go b/x/fswap/types/fswap.go index c307c826b3..b6f26c0180 100644 --- a/x/fswap/types/fswap.go +++ b/x/fswap/types/fswap.go @@ -69,8 +69,26 @@ func validateCoinAmount(i interface{}) error { return nil } -// String implements the Stringer interface. func (s *Swapped) String() string { out, _ := yaml.Marshal(s) return string(out) } + +func (s *MakeSwapProposalTmp) ValidateBasic() error { + if err := s.Swap.ValidateBasic(); err != nil { + return err + } + if err := s.ToDenomMetadata.Validate(); err != nil { + return err + } + if s.Swap.ToDenom != s.ToDenomMetadata.Base { + return sdkerrors.ErrInvalidRequest.Wrapf("denomination does not match %s != %s", s.Swap.ToDenom, s.ToDenomMetadata.Base) + } + + return nil +} + +func (s *MakeSwapProposalTmp) String() string { + out, _ := yaml.Marshal(s) + return string(out) +} diff --git a/x/fswap/types/fswap.pb.go b/x/fswap/types/fswap.pb.go index 4449b20bec..3799227784 100644 --- a/x/fswap/types/fswap.pb.go +++ b/x/fswap/types/fswap.pb.go @@ -122,25 +122,22 @@ func (m *SwapStats) GetSwapCount() int32 { return 0 } -// From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk based on 0.45.10 -type MakeSwapProposal struct { - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - Swap Swap `protobuf:"bytes,3,opt,name=swap,proto3" json:"swap"` - ToDenomMetadata types.Metadata `protobuf:"bytes,4,opt,name=to_denom_metadata,json=toDenomMetadata,proto3" json:"to_denom_metadata" yaml:"denom_metadata"` +type MakeSwapProposalTmp struct { + Swap Swap `protobuf:"bytes,1,opt,name=swap,proto3" json:"swap"` + ToDenomMetadata types.Metadata `protobuf:"bytes,2,opt,name=to_denom_metadata,json=toDenomMetadata,proto3" json:"to_denom_metadata" yaml:"denom_metadata"` } -func (m *MakeSwapProposal) Reset() { *m = MakeSwapProposal{} } -func (*MakeSwapProposal) ProtoMessage() {} -func (*MakeSwapProposal) Descriptor() ([]byte, []int) { +func (m *MakeSwapProposalTmp) Reset() { *m = MakeSwapProposalTmp{} } +func (*MakeSwapProposalTmp) ProtoMessage() {} +func (*MakeSwapProposalTmp) Descriptor() ([]byte, []int) { return fileDescriptor_42ca60eaf37a2b67, []int{2} } -func (m *MakeSwapProposal) XXX_Unmarshal(b []byte) error { +func (m *MakeSwapProposalTmp) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MakeSwapProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MakeSwapProposalTmp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MakeSwapProposal.Marshal(b, m, deterministic) + return xxx_messageInfo_MakeSwapProposalTmp.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -150,40 +147,26 @@ func (m *MakeSwapProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, er return b[:n], nil } } -func (m *MakeSwapProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_MakeSwapProposal.Merge(m, src) +func (m *MakeSwapProposalTmp) XXX_Merge(src proto.Message) { + xxx_messageInfo_MakeSwapProposalTmp.Merge(m, src) } -func (m *MakeSwapProposal) XXX_Size() int { +func (m *MakeSwapProposalTmp) XXX_Size() int { return m.Size() } -func (m *MakeSwapProposal) XXX_DiscardUnknown() { - xxx_messageInfo_MakeSwapProposal.DiscardUnknown(m) +func (m *MakeSwapProposalTmp) XXX_DiscardUnknown() { + xxx_messageInfo_MakeSwapProposalTmp.DiscardUnknown(m) } -var xxx_messageInfo_MakeSwapProposal proto.InternalMessageInfo +var xxx_messageInfo_MakeSwapProposalTmp proto.InternalMessageInfo -func (m *MakeSwapProposal) GetTitle() string { - if m != nil { - return m.Title - } - return "" -} - -func (m *MakeSwapProposal) GetDescription() string { - if m != nil { - return m.Description - } - return "" -} - -func (m *MakeSwapProposal) GetSwap() Swap { +func (m *MakeSwapProposalTmp) GetSwap() Swap { if m != nil { return m.Swap } return Swap{} } -func (m *MakeSwapProposal) GetToDenomMetadata() types.Metadata { +func (m *MakeSwapProposalTmp) GetToDenomMetadata() types.Metadata { if m != nil { return m.ToDenomMetadata } @@ -244,48 +227,47 @@ func (m *Swapped) GetToCoinAmount() types1.Coin { func init() { proto.RegisterType((*Swap)(nil), "lbm.fswap.v1.Swap") proto.RegisterType((*SwapStats)(nil), "lbm.fswap.v1.SwapStats") - proto.RegisterType((*MakeSwapProposal)(nil), "lbm.fswap.v1.MakeSwapProposal") + proto.RegisterType((*MakeSwapProposalTmp)(nil), "lbm.fswap.v1.MakeSwapProposalTmp") proto.RegisterType((*Swapped)(nil), "lbm.fswap.v1.Swapped") } func init() { proto.RegisterFile("lbm/fswap/v1/fswap.proto", fileDescriptor_42ca60eaf37a2b67) } var fileDescriptor_42ca60eaf37a2b67 = []byte{ - // 539 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xbf, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0xe3, 0x92, 0xd2, 0xe4, 0x52, 0x95, 0x62, 0x8a, 0x48, 0x2b, 0xc5, 0xae, 0x32, 0x21, - 0x7e, 0xd8, 0x4a, 0xca, 0x94, 0x8d, 0xa4, 0xaa, 0x60, 0xa8, 0x40, 0x2e, 0x13, 0x8b, 0x75, 0x76, - 0x2e, 0x89, 0x15, 0xdb, 0xcf, 0xf2, 0xbd, 0xa6, 0xed, 0x1f, 0xc0, 0xce, 0xc8, 0xd8, 0x99, 0xbf, - 0xa4, 0x63, 0x47, 0xc4, 0x10, 0x50, 0xb2, 0x74, 0xe6, 0x1f, 0x00, 0xbd, 0x3b, 0x37, 0x4d, 0xc5, - 0x00, 0x42, 0x62, 0x7b, 0xf7, 0xde, 0xbb, 0xf7, 0xb9, 0xfb, 0x7e, 0xef, 0x58, 0x3d, 0x0e, 0x12, - 0x77, 0x20, 0x4f, 0x78, 0xe6, 0x4e, 0x5a, 0x3a, 0x70, 0xb2, 0x1c, 0x10, 0xcc, 0xf5, 0x38, 0x48, - 0x1c, 0x9d, 0x98, 0xb4, 0x76, 0xb6, 0x86, 0x30, 0x04, 0x55, 0x70, 0x29, 0xd2, 0x3d, 0x3b, 0x56, - 0x08, 0x32, 0x01, 0xe9, 0x06, 0x5c, 0x0a, 0x77, 0xd2, 0x0a, 0x04, 0xf2, 0x96, 0x1b, 0x42, 0x94, - 0xfe, 0x56, 0x4f, 0xc7, 0x8b, 0x3a, 0x2d, 0x74, 0xbd, 0xf9, 0x61, 0x85, 0x95, 0x8f, 0x4e, 0x78, - 0x66, 0x36, 0x18, 0x1b, 0xe4, 0x90, 0xf8, 0x7d, 0x91, 0x42, 0x52, 0x37, 0x76, 0x8d, 0xc7, 0x55, - 0xaf, 0x4a, 0x99, 0x7d, 0x4a, 0x98, 0xdb, 0xac, 0x82, 0x50, 0x14, 0x57, 0x54, 0x71, 0x0d, 0x41, - 0x97, 0x46, 0xec, 0x11, 0x4f, 0xe0, 0x38, 0x45, 0x3f, 0xe4, 0x99, 0x3f, 0x80, 0xdc, 0x5f, 0x74, - 0xde, 0xa1, 0xce, 0x6e, 0xfb, 0x62, 0x6a, 0x97, 0xbe, 0x4e, 0xed, 0x27, 0xc3, 0x08, 0x47, 0xc7, - 0x81, 0x13, 0x42, 0xe2, 0x1e, 0x44, 0xa9, 0x0c, 0x47, 0x11, 0x77, 0x07, 0x45, 0xf0, 0x5c, 0xf6, - 0xc7, 0x2e, 0x9e, 0x65, 0x42, 0x3a, 0xaf, 0x53, 0xf4, 0x1e, 0xe8, 0x91, 0x3d, 0x9e, 0x1d, 0x40, - 0xfe, 0xae, 0x20, 0xbd, 0x61, 0x55, 0x52, 0xc3, 0xcf, 0x39, 0x8a, 0x7a, 0xf9, 0x9f, 0x66, 0xef, - 0x8b, 0xd0, 0xab, 0xd0, 0x10, 0x8f, 0xa3, 0xe8, 0x54, 0x3e, 0x9d, 0xdb, 0xa5, 0xab, 0x73, 0xdb, - 0x68, 0xbe, 0x60, 0x55, 0x92, 0xe1, 0x08, 0x39, 0x4a, 0xd2, 0x42, 0x71, 0x42, 0x3a, 0x82, 0xd2, - 0x62, 0xd5, 0x53, 0xe4, 0x1e, 0x25, 0x96, 0x76, 0x5d, 0x19, 0x6c, 0xf3, 0x90, 0x8f, 0x05, 0x6d, - 0x7d, 0x9b, 0x43, 0x06, 0x92, 0xc7, 0xe6, 0x16, 0x5b, 0xc5, 0x08, 0x63, 0x51, 0x88, 0xa8, 0x17, - 0xe6, 0x2e, 0xab, 0xf5, 0x85, 0x0c, 0xf3, 0x28, 0xc3, 0x08, 0xd2, 0x42, 0xc3, 0xe5, 0x94, 0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2f, 0x11, 0xda, 0xfb, 0x03, 0x00, 0x00, + // 513 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x53, 0xbf, 0x6f, 0xd3, 0x40, + 0x14, 0xb6, 0x83, 0xa1, 0xc9, 0xb5, 0x2a, 0xe0, 0x82, 0x48, 0x2b, 0xc5, 0x46, 0x9e, 0x10, 0x3f, + 0xce, 0x4a, 0xca, 0x94, 0x0d, 0xa7, 0xaa, 0x60, 0xa8, 0x40, 0x6e, 0x27, 0x16, 0xeb, 0xec, 0x5c, + 0x12, 0x2b, 0x39, 0x3f, 0xcb, 0x77, 0x4d, 0xdb, 0x3f, 0x80, 0x9d, 0x91, 0xb1, 0x33, 0x2b, 0xff, + 0x44, 0xc7, 0x8e, 0x88, 0x21, 0xa0, 0x64, 0x61, 0xe6, 0x1f, 0x00, 0xbd, 0xb3, 0x9b, 0xb6, 0x62, + 0x00, 0x21, 0xb1, 0x3d, 0xbf, 0xef, 0x7b, 0xef, 0x7b, 0xfa, 0x3e, 0x1f, 0x69, 0x4e, 0x62, 0xe1, + 0x0f, 0xe4, 0x11, 0xcb, 0xfd, 0x69, 0xbb, 0x2c, 0x68, 0x5e, 0x80, 0x02, 0x7b, 0x6d, 0x12, 0x0b, + 0x5a, 0x36, 0xa6, 0xed, 0xad, 0x7b, 0x43, 0x18, 0x82, 0x06, 0x7c, 0xac, 0x4a, 0xce, 0x96, 0x93, + 0x80, 0x14, 0x20, 0xfd, 0x98, 0x49, 0xee, 0x4f, 0xdb, 0x31, 0x57, 0xac, 0xed, 0x27, 0x90, 0x66, + 0xbf, 0xe1, 0xd9, 0x78, 0x89, 0xe3, 0x47, 0x89, 0x7b, 0xef, 0x6a, 0xc4, 0xda, 0x3f, 0x62, 0xb9, + 0xdd, 0x22, 0x64, 0x50, 0x80, 0x88, 0xfa, 0x3c, 0x03, 0xd1, 0x34, 0x1f, 0x9a, 0x8f,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58, 0x9f, 0x29, 0xa6, 0x4d, 0x5e, 0xed, 0xb4, 0x68, 0x99, 0x1f, 0xd5, 0x91, + 0x55, 0xf9, 0xd1, 0xbd, 0x8a, 0x14, 0xb4, 0x70, 0xcb, 0x8f, 0x99, 0x7b, 0xff, 0x84, 0x89, 0x49, + 0xd7, 0xbb, 0xbe, 0xc2, 0x0b, 0x6f, 0x57, 0x11, 0x5d, 0xf0, 0xbb, 0x16, 0x5e, 0xee, 0xfd, 0x34, + 0xc9, 0x0a, 0x1e, 0x91, 0xf3, 0xbe, 0x7d, 0x4c, 0xee, 0xe8, 0xd8, 0xf1, 0x97, 0x89, 0x4a, 0xcf, + 0xab, 0xab, 0x37, 0x2f, 0xa5, 0x25, 0x5f, 0x4a, 0xf7, 0x20, 0xcd, 0x82, 0x6d, 0x94, 0xfd, 0xf8, + 0xd5, 0x7d, 0xf2, 0x97, 0xa6, 0xe3, 0x50, 0xb8, 0x8e, 0x3a, 0x58, 0xbd, 0xd0, 0x2a, 0xb6, 0x22, + 0xeb, 0x0a, 0xae, 0xe9, 0xd6, 0xfe, 0x8b, 0xee, 0x9a, 0x82, 0x4b, 0xd5, 0xd2, 0x81, 0xe0, 0xe5, + 0xd9, 0xdc, 0x31, 0xcf, 0xe7, 0x8e, 0xf9, 0x6d, 0xee, 0x98, 0xef, 0x17, 0x8e, 0x71, 0xbe, 0x70, + 0x8c, 0xcf, 0x0b, 0xc7, 0x78, 0x4b, 0xff, 0xb8, 0xfa, 0xb8, 0x7a, 0xac, 0x5a, 0x22, 0xbe, 0xa5, + 0x9f, 0xd1, 0xf6, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe0, 0x50, 0x1b, 0xc2, 0xc6, 0x03, 0x00, + 0x00, } func (this *Swap) Equal(that interface{}) bool { @@ -430,7 +412,7 @@ func (m *SwapStats) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MakeSwapProposal) Marshal() (dAtA []byte, err error) { +func (m *MakeSwapProposalTmp) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -440,12 +422,12 @@ func (m *MakeSwapProposal) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MakeSwapProposal) MarshalTo(dAtA []byte) (int, error) { +func (m *MakeSwapProposalTmp) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MakeSwapProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MakeSwapProposalTmp) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -459,7 +441,7 @@ func (m *MakeSwapProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintFswap(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x22 + dAtA[i] = 0x12 { size, err := m.Swap.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -469,21 +451,7 @@ func (m *MakeSwapProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintFswap(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintFswap(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintFswap(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -574,20 +542,12 @@ func (m *SwapStats) Size() (n int) { return n } -func (m *MakeSwapProposal) Size() (n int) { +func (m *MakeSwapProposalTmp) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovFswap(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovFswap(uint64(l)) - } l = m.Swap.Size() n += 1 + l + sovFswap(uint64(l)) l = m.ToDenomMetadata.Size() @@ -865,7 +825,7 @@ func (m *SwapStats) Unmarshal(dAtA []byte) error { } return nil } -func (m *MakeSwapProposal) Unmarshal(dAtA []byte) error { +func (m *MakeSwapProposalTmp) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -888,77 +848,13 @@ func (m *MakeSwapProposal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MakeSwapProposal: wiretype end group for non-group") + return fmt.Errorf("proto: MakeSwapProposalTmp: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MakeSwapProposal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MakeSwapProposalTmp: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFswap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthFswap - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthFswap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFswap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthFswap - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthFswap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Swap", wireType) } @@ -991,7 +887,7 @@ func (m *MakeSwapProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ToDenomMetadata", wireType) } diff --git a/x/fswap/types/genesis.go b/x/fswap/types/genesis.go index 08c1d79338..2c83fa506f 100644 --- a/x/fswap/types/genesis.go +++ b/x/fswap/types/genesis.go @@ -1,5 +1,11 @@ package types +import ( + sdk "github.com/Finschia/finschia-sdk/types" + authtypes "github.com/Finschia/finschia-sdk/x/auth/types" + "github.com/Finschia/finschia-sdk/x/foundation" +) + // DefaultGenesis returns the default Capability genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ @@ -9,6 +15,10 @@ func DefaultGenesis() *GenesisState { } } +func DefaultAuthority() sdk.AccAddress { + return authtypes.NewModuleAddress(foundation.ModuleName) +} + // Validate performs basic genesis state validation returning an error upon any failure. func (gs *GenesisState) Validate() error { for _, swap := range gs.GetSwaps() { diff --git a/x/fswap/types/msgs.go b/x/fswap/types/msgs.go index eae8c6a2c2..eef9698e45 100644 --- a/x/fswap/types/msgs.go +++ b/x/fswap/types/msgs.go @@ -3,10 +3,11 @@ package types import ( sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" - "github.com/Finschia/finschia-sdk/x/fswap/codec" ) var _ sdk.Msg = &MsgSwap{} +var _ sdk.Msg = &MsgSwapAll{} +var _ sdk.Msg = &MsgMakeSwapProposal{} // ValidateBasic Implements Msg. func (m *MsgSwap) ValidateBasic() error { @@ -41,11 +42,9 @@ func (m *MsgSwap) GetSigners() []sdk.AccAddress { // GetSignBytes implements the LegacyMsg.GetSignBytes method. func (m *MsgSwap) GetSignBytes() []byte { - return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(m)) + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) } -var _ sdk.Msg = &MsgSwapAll{} - // ValidateBasic Implements Msg. func (m *MsgSwapAll) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(m.FromAddress) @@ -75,5 +74,27 @@ func (m *MsgSwapAll) GetSigners() []sdk.AccAddress { // GetSignBytes implements the LegacyMsg.GetSignBytes method. func (m *MsgSwapAll) GetSignBytes() []byte { - return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(m)) + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) +} + +func (m *MsgMakeSwapProposal) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", m.Authority) + } + + if err := m.GetProposal().ValidateBasic(); err != nil { + return err + } + + return nil +} + +func (m *MsgMakeSwapProposal) GetSigners() []sdk.AccAddress { + signer := sdk.MustAccAddressFromBech32(m.Authority) + return []sdk.AccAddress{signer} +} + +// GetSignBytes implements the LegacyMsg.GetSignBytes method. +func (m *MsgMakeSwapProposal) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) } diff --git a/x/fswap/types/proposal.go b/x/fswap/types/proposal.go deleted file mode 100644 index 99048caa57..0000000000 --- a/x/fswap/types/proposal.go +++ /dev/null @@ -1,54 +0,0 @@ -package types - -import ( - "gopkg.in/yaml.v2" - - sdkerrors "github.com/Finschia/finschia-sdk/types/errors" - bank "github.com/Finschia/finschia-sdk/x/bank/types" - gov "github.com/Finschia/finschia-sdk/x/gov/types" -) - -const ( - ProposalTypeMakeSwap string = "MakeSwap" -) - -// NewMakeSwapProposal creates a new SwapProposal instance. -// Deprecated: this proposal is considered legacy and is deprecated in favor of -// Msg-based gov proposals. See MakeSwapProposal. -func NewMakeSwapProposal(title, description string, swap Swap, toDenomMetadata bank.Metadata) *MakeSwapProposal { - return &MakeSwapProposal{title, description, swap, toDenomMetadata} -} - -// Implements Proposal Interface -var _ gov.Content = &MakeSwapProposal{} - -func init() { - gov.RegisterProposalType(ProposalTypeMakeSwap) -} - -// ProposalRoute gets the proposal's router key -func (m *MakeSwapProposal) ProposalRoute() string { return RouterKey } - -// ProposalType is "Swap" -func (m *MakeSwapProposal) ProposalType() string { return ProposalTypeMakeSwap } - -// String implements the Stringer interface. -func (m *MakeSwapProposal) String() string { - out, _ := yaml.Marshal(m) - return string(out) -} - -// ValidateBasic validates the proposal -func (m *MakeSwapProposal) ValidateBasic() error { - if err := m.Swap.ValidateBasic(); err != nil { - return err - } - if err := m.ToDenomMetadata.Validate(); err != nil { - return err - } - if m.Swap.ToDenom != m.ToDenomMetadata.Base { - return sdkerrors.ErrInvalidRequest.Wrapf("denomination does not match %s != %s", m.Swap.ToDenom, m.ToDenomMetadata.Base) - } - - return gov.ValidateAbstract(m) -} diff --git a/x/fswap/types/tx.pb.go b/x/fswap/types/tx.pb.go index 288ada4778..ab11cb2400 100644 --- a/x/fswap/types/tx.pb.go +++ b/x/fswap/types/tx.pb.go @@ -224,42 +224,138 @@ func (m *MsgSwapAllResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSwapAllResponse proto.InternalMessageInfo +type MsgMakeSwapProposal struct { + // authority is the address of the privileged account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + Proposal *MakeSwapProposalTmp `protobuf:"bytes,2,opt,name=proposal,proto3" json:"proposal,omitempty"` +} + +func (m *MsgMakeSwapProposal) Reset() { *m = MsgMakeSwapProposal{} } +func (m *MsgMakeSwapProposal) String() string { return proto.CompactTextString(m) } +func (*MsgMakeSwapProposal) ProtoMessage() {} +func (*MsgMakeSwapProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_65c77cf1d9b67323, []int{4} +} +func (m *MsgMakeSwapProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgMakeSwapProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgMakeSwapProposal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgMakeSwapProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgMakeSwapProposal.Merge(m, src) +} +func (m *MsgMakeSwapProposal) XXX_Size() int { + return m.Size() +} +func (m *MsgMakeSwapProposal) XXX_DiscardUnknown() { + xxx_messageInfo_MsgMakeSwapProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgMakeSwapProposal proto.InternalMessageInfo + +func (m *MsgMakeSwapProposal) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgMakeSwapProposal) GetProposal() *MakeSwapProposalTmp { + if m != nil { + return m.Proposal + } + return nil +} + +type MsgMakeSwapProposalResponse struct { +} + +func (m *MsgMakeSwapProposalResponse) Reset() { *m = MsgMakeSwapProposalResponse{} } +func (m *MsgMakeSwapProposalResponse) String() string { return proto.CompactTextString(m) } +func (*MsgMakeSwapProposalResponse) ProtoMessage() {} +func (*MsgMakeSwapProposalResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_65c77cf1d9b67323, []int{5} +} +func (m *MsgMakeSwapProposalResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgMakeSwapProposalResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgMakeSwapProposalResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgMakeSwapProposalResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgMakeSwapProposalResponse.Merge(m, src) +} +func (m *MsgMakeSwapProposalResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgMakeSwapProposalResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgMakeSwapProposalResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgMakeSwapProposalResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgSwap)(nil), "lbm.fswap.v1.MsgSwap") proto.RegisterType((*MsgSwapResponse)(nil), "lbm.fswap.v1.MsgSwapResponse") proto.RegisterType((*MsgSwapAll)(nil), "lbm.fswap.v1.MsgSwapAll") proto.RegisterType((*MsgSwapAllResponse)(nil), "lbm.fswap.v1.MsgSwapAllResponse") + proto.RegisterType((*MsgMakeSwapProposal)(nil), "lbm.fswap.v1.MsgMakeSwapProposal") + proto.RegisterType((*MsgMakeSwapProposalResponse)(nil), "lbm.fswap.v1.MsgMakeSwapProposalResponse") } func init() { proto.RegisterFile("lbm/fswap/v1/tx.proto", fileDescriptor_65c77cf1d9b67323) } var fileDescriptor_65c77cf1d9b67323 = []byte{ - // 387 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xbd, 0x6e, 0xe2, 0x40, - 0x10, 0xc7, 0xbd, 0x70, 0x3a, 0x8e, 0x05, 0xdd, 0x87, 0x05, 0x92, 0xb1, 0x84, 0xe1, 0xa8, 0x90, - 0x4e, 0xb7, 0x2b, 0x43, 0x7b, 0x8d, 0xb9, 0xbb, 0x28, 0x0d, 0x0d, 0xe9, 0xd2, 0x20, 0x7f, 0x61, - 0xac, 0xd8, 0x1e, 0x8b, 0x5d, 0x3e, 0xf2, 0x0a, 0xa9, 0xf2, 0x1c, 0x79, 0x8b, 0x74, 0x94, 0x94, - 0xa9, 0x92, 0x08, 0x5e, 0x24, 0xda, 0xb5, 0xad, 0xa4, 0x20, 0x1f, 0xdd, 0xf8, 0x3f, 0xff, 0x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cb, 0x47, 0x98, 0xf8, 0x2c, 0x85, 0x84, 0xf9, 0xbd, 0x10, 0xe3, - 0x5c, 0xb2, 0xa2, 0xe8, 0x23, 0x83, 0xb5, 0x31, 0x96, 0x96, 0x0c, 0x50, 0x92, 0x86, 0xaa, 0x50, - 0x24, 0xe2, 0x2d, 0x7a, 0x03, 0xab, 0xcf, 0xa8, 0xa2, 0x81, 0xc1, 0x15, 0xc2, 0xe5, 0x31, 0x0b, - 0xd4, 0x3f, 0xf8, 0x93, 0xfc, 0xb7, 0x4d, 0xf2, 0x72, 0x59, 0x24, 0x7f, 0xa1, 0xb7, 0x8f, 0xca, - 0x45, 0x15, 0xf5, 0x3f, 0xae, 0x14, 0x33, 0x68, 0x47, 0x9d, 0x56, 0x14, 0xe9, 0xdd, 0xd7, 0x32, - 0x45, 0x99, 0xd1, 0xe9, 0x76, 0x6f, 0xa0, 0xdd, 0xde, 0x40, 0x8f, 0x7b, 0x03, 0x5d, 0x1f, 0x0c, - 0x65, 0x77, 0x30, 0x94, 0xbb, 0x83, 0xa1, 0x9c, 0x93, 0x77, 0x57, 0xb2, 0xc9, 0x0f, 0x4f, 0xae, - 0xc6, 0xf9, 0x2c, 0xaf, 0x66, 0xf8, 0x14, 0x00, 0x00, 0xff, 0xff, 0xb0, 0x18, 0x17, 0xb0, 0x92, - 0x02, 0x00, 0x00, + // 471 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0x8d, 0x5b, 0x44, 0x9a, 0x69, 0x05, 0x65, 0x69, 0x25, 0xd7, 0x10, 0x37, 0xc9, 0xa9, 0x08, + 0xb1, 0xab, 0xb4, 0x57, 0x38, 0xa4, 0x7c, 0x88, 0x4b, 0x24, 0x14, 0x38, 0x71, 0x09, 0xeb, 0xc4, + 0x71, 0xac, 0xda, 0x9e, 0x95, 0x77, 0x93, 0x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 0xa7, 0x6f, 0x2f, 0xa7, 0xbe, 0x73, 0x35, 0xf5, 0x9d, 0x9f, 0x53, 0xdf, 0xf9, + 0x3c, 0xf3, 0x4b, 0x57, 0x33, 0xbf, 0xf4, 0x6d, 0xe6, 0x97, 0x3e, 0xd2, 0xb5, 0xf7, 0x70, 0x62, + 0x1f, 0x8b, 0xb9, 0x8f, 0xc1, 0x5d, 0xf3, 0x54, 0x4e, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0xdf, + 0xcc, 0x1f, 0xeb, 0xa1, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -276,6 +372,7 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { Swap(ctx context.Context, in *MsgSwap, opts ...grpc.CallOption) (*MsgSwapResponse, error) SwapAll(ctx context.Context, in *MsgSwapAll, opts ...grpc.CallOption) (*MsgSwapAllResponse, error) + MakeSwapProposal(ctx context.Context, in *MsgMakeSwapProposal, opts ...grpc.CallOption) (*MsgMakeSwapProposalResponse, error) } type msgClient struct { @@ -304,10 +401,20 @@ func (c *msgClient) SwapAll(ctx context.Context, in *MsgSwapAll, opts ...grpc.Ca return out, nil } +func (c *msgClient) MakeSwapProposal(ctx context.Context, in *MsgMakeSwapProposal, opts ...grpc.CallOption) (*MsgMakeSwapProposalResponse, error) { + out := new(MsgMakeSwapProposalResponse) + err := c.cc.Invoke(ctx, "/lbm.fswap.v1.Msg/MakeSwapProposal", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { Swap(context.Context, *MsgSwap) (*MsgSwapResponse, error) SwapAll(context.Context, *MsgSwapAll) (*MsgSwapAllResponse, error) + MakeSwapProposal(context.Context, *MsgMakeSwapProposal) (*MsgMakeSwapProposalResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -320,6 +427,9 @@ func (*UnimplementedMsgServer) Swap(ctx context.Context, req *MsgSwap) (*MsgSwap func (*UnimplementedMsgServer) SwapAll(ctx context.Context, req *MsgSwapAll) (*MsgSwapAllResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SwapAll not implemented") } +func (*UnimplementedMsgServer) MakeSwapProposal(ctx context.Context, req *MsgMakeSwapProposal) (*MsgMakeSwapProposalResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method MakeSwapProposal not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -361,6 +471,24 @@ func _Msg_SwapAll_Handler(srv interface{}, ctx context.Context, dec func(interfa return interceptor(ctx, in, info, handler) } +func _Msg_MakeSwapProposal_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgMakeSwapProposal) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).MakeSwapProposal(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lbm.fswap.v1.Msg/MakeSwapProposal", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).MakeSwapProposal(ctx, req.(*MsgMakeSwapProposal)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "lbm.fswap.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -373,6 +501,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "SwapAll", Handler: _Msg_SwapAll_Handler, }, + { + MethodName: "MakeSwapProposal", + Handler: _Msg_MakeSwapProposal_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "lbm/fswap/v1/tx.proto", @@ -515,6 +647,71 @@ func (m *MsgSwapAllResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgMakeSwapProposal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgMakeSwapProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgMakeSwapProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Proposal != nil { + { + size, err := m.Proposal.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgMakeSwapProposalResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgMakeSwapProposalResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgMakeSwapProposalResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -584,6 +781,32 @@ func (m *MsgSwapAllResponse) Size() (n int) { return n } +func (m *MsgMakeSwapProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Proposal != nil { + l = m.Proposal.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgMakeSwapProposalResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -983,6 +1206,174 @@ func (m *MsgSwapAllResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgMakeSwapProposal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgMakeSwapProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgMakeSwapProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proposal", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Proposal == nil { + m.Proposal = &MakeSwapProposalTmp{} + } + if err := m.Proposal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgMakeSwapProposalResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgMakeSwapProposalResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgMakeSwapProposalResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From c40e8e57dc07942dad99a6b2afbfea7b0806cf2a Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 9 May 2024 16:36:16 +0900 Subject: [PATCH 2/9] chore: refactor MsgMakeSwapProposal -> MsgSetSwap --- docs/core/proto-docs.md | 34 +--- proto/lbm/fswap/v1/fswap.proto | 9 - proto/lbm/fswap/v1/tx.proto | 15 +- x/fswap/client/cli/tx.go | 10 +- x/fswap/codec/codec.go | 1 - x/fswap/keeper/msg_server.go | 6 +- x/fswap/types/codec.go | 4 +- x/fswap/types/fswap.go | 19 --- x/fswap/types/fswap.pb.go | 301 ++++----------------------------- x/fswap/types/msgs.go | 23 ++- x/fswap/types/tx.pb.go | 275 +++++++++++++++++------------- 11 files changed, 243 insertions(+), 454 deletions(-) delete mode 100644 x/fswap/codec/codec.go diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 1c7e53f40f..c53e8b33ad 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -954,7 +954,6 @@ - [EventSwapCoins](#lbm.fswap.v1.EventSwapCoins) - [lbm/fswap/v1/fswap.proto](#lbm/fswap/v1/fswap.proto) - - [MakeSwapProposal](#lbm.fswap.v1.MakeSwapProposal) - [Swap](#lbm.fswap.v1.Swap) - [SwapStats](#lbm.fswap.v1.SwapStats) - [Swapped](#lbm.fswap.v1.Swapped) @@ -973,8 +972,8 @@ - [Query](#lbm.fswap.v1.Query) - [lbm/fswap/v1/tx.proto](#lbm/fswap/v1/tx.proto) - - [MsgMakeSwapProposal](#lbm.fswap.v1.MsgMakeSwapProposal) - - [MsgMakeSwapProposalResponse](#lbm.fswap.v1.MsgMakeSwapProposalResponse) + - [MsgSetSwap](#lbm.fswap.v1.MsgSetSwap) + - [MsgSetSwapResponse](#lbm.fswap.v1.MsgSetSwapResponse) - [MsgSwap](#lbm.fswap.v1.MsgSwap) - [MsgSwapAll](#lbm.fswap.v1.MsgSwapAll) - [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse) @@ -14162,22 +14161,6 @@ Msg defines the foundation Msg service. - - -### MakeSwapProposal - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `swap` | [Swap](#lbm.fswap.v1.Swap) | | | -| `to_denom_metadata` | [cosmos.bank.v1beta1.Metadata](#cosmos.bank.v1beta1.Metadata) | | | - - - - - - ### Swap @@ -14398,25 +14381,26 @@ GenesisState defines the fswap module's genesis state. - + -### MsgMakeSwapProposal +### MsgSetSwap | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `authority` | [string](#string) | | authority is the address of the privileged account. | -| `proposal` | [MakeSwapProposal](#lbm.fswap.v1.MakeSwapProposal) | | | +| `swap` | [Swap](#lbm.fswap.v1.Swap) | | | +| `to_denom_metadata` | [cosmos.bank.v1beta1.Metadata](#cosmos.bank.v1beta1.Metadata) | | | - + -### MsgMakeSwapProposalResponse +### MsgSetSwapResponse @@ -14493,7 +14477,7 @@ GenesisState defines the fswap module's genesis state. | ----------- | ------------ | ------------- | ------------| ------- | -------- | | `Swap` | [MsgSwap](#lbm.fswap.v1.MsgSwap) | [MsgSwapResponse](#lbm.fswap.v1.MsgSwapResponse) | | | | `SwapAll` | [MsgSwapAll](#lbm.fswap.v1.MsgSwapAll) | [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse) | | | -| `MakeSwapProposal` | [MsgMakeSwapProposal](#lbm.fswap.v1.MsgMakeSwapProposal) | [MsgMakeSwapProposalResponse](#lbm.fswap.v1.MsgMakeSwapProposalResponse) | | | +| `SetSwap` | [MsgSetSwap](#lbm.fswap.v1.MsgSetSwap) | [MsgSetSwapResponse](#lbm.fswap.v1.MsgSetSwapResponse) | | | diff --git a/proto/lbm/fswap/v1/fswap.proto b/proto/lbm/fswap/v1/fswap.proto index 5d39315b49..4d9e208319 100644 --- a/proto/lbm/fswap/v1/fswap.proto +++ b/proto/lbm/fswap/v1/fswap.proto @@ -5,7 +5,6 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types"; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; -import "cosmos/bank/v1beta1/bank.proto"; message Swap { option (gogoproto.equal) = true; @@ -26,14 +25,6 @@ message SwapStats { int32 swap_count = 1; } -message MakeSwapProposal { - option (gogoproto.goproto_stringer) = false; - - Swap swap = 1 [(gogoproto.nullable) = false]; - cosmos.bank.v1beta1.Metadata to_denom_metadata = 2 - [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false]; -} - message Swapped { option (gogoproto.goproto_stringer) = false; cosmos.base.v1beta1.Coin from_coin_amount = 1 diff --git a/proto/lbm/fswap/v1/tx.proto b/proto/lbm/fswap/v1/tx.proto index 15771728d7..8a0dffcc1e 100644 --- a/proto/lbm/fswap/v1/tx.proto +++ b/proto/lbm/fswap/v1/tx.proto @@ -5,12 +5,13 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types"; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; +import "cosmos/bank/v1beta1/bank.proto"; import "lbm/fswap/v1/fswap.proto"; service Msg { rpc Swap(MsgSwap) returns (MsgSwapResponse); rpc SwapAll(MsgSwapAll) returns (MsgSwapAllResponse); - rpc MakeSwapProposal(MsgMakeSwapProposal) returns (MsgMakeSwapProposalResponse); + rpc SetSwap(MsgSetSwap) returns (MsgSetSwapResponse); } message MsgSwap { @@ -33,10 +34,14 @@ message MsgSwapAll { message MsgSwapAllResponse {} -message MsgMakeSwapProposal { +message MsgSetSwap { + option (gogoproto.goproto_stringer) = false; + // authority is the address of the privileged account. - string authority = 1; - MakeSwapProposal proposal = 2; + string authority = 1; + Swap swap = 2 [(gogoproto.nullable) = false]; + cosmos.bank.v1beta1.Metadata to_denom_metadata = 3 + [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false]; } -message MsgMakeSwapProposalResponse {} +message MsgSetSwapResponse {} diff --git a/x/fswap/client/cli/tx.go b/x/fswap/client/cli/tx.go index 0568106f21..94308d346b 100644 --- a/x/fswap/client/cli/tx.go +++ b/x/fswap/client/cli/tx.go @@ -201,12 +201,10 @@ Example of the content of metadata-json: return err } - msg := types.MsgMakeSwapProposal{ - Authority: authority, - Proposal: &types.MakeSwapProposalTmp{ - Swap: swap, - ToDenomMetadata: toDenomMetadata, - }, + msg := types.MsgSetSwap{ + Authority: authority, + Swap: swap, + ToDenomMetadata: toDenomMetadata, } return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) diff --git a/x/fswap/codec/codec.go b/x/fswap/codec/codec.go deleted file mode 100644 index 1fae45a0c8..0000000000 --- a/x/fswap/codec/codec.go +++ /dev/null @@ -1 +0,0 @@ -package codec diff --git a/x/fswap/keeper/msg_server.go b/x/fswap/keeper/msg_server.go index 211635669a..f5f5ac471d 100644 --- a/x/fswap/keeper/msg_server.go +++ b/x/fswap/keeper/msg_server.go @@ -61,16 +61,16 @@ func (s MsgServer) SwapAll(ctx context.Context, req *types.MsgSwapAll) (*types.M return &types.MsgSwapAllResponse{}, nil } -func (s MsgServer) MakeSwapProposal(ctx context.Context, req *types.MsgMakeSwapProposal) (*types.MsgMakeSwapProposalResponse, error) { +func (s MsgServer) SetSwap(ctx context.Context, req *types.MsgSetSwap) (*types.MsgSetSwapResponse, error) { c := sdk.UnwrapSDKContext(ctx) if err := s.keeper.validateAuthority(req.Authority); err != nil { return nil, err } - if err := s.keeper.MakeSwap(c, req.GetProposal().GetSwap(), req.GetProposal().GetToDenomMetadata()); err != nil { + if err := s.keeper.MakeSwap(c, req.GetSwap(), req.GetToDenomMetadata()); err != nil { return nil, err } - return &types.MsgMakeSwapProposalResponse{}, nil + return &types.MsgSetSwapResponse{}, nil } diff --git a/x/fswap/types/codec.go b/x/fswap/types/codec.go index 6a9fce2c25..77c591743d 100644 --- a/x/fswap/types/codec.go +++ b/x/fswap/types/codec.go @@ -28,14 +28,14 @@ func init() { func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgSwap{}, "lbm-sdk/MsgSwap") legacy.RegisterAminoMsg(cdc, &MsgSwapAll{}, "lbm-sdk/MsgSwapAll") - legacy.RegisterAminoMsg(cdc, &MsgMakeSwapProposal{}, "lbm-sdk/MsgMakeSwapProposal") + legacy.RegisterAminoMsg(cdc, &MsgSetSwap{}, "lbm-sdk/MsgSetSwap") } func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSwap{}, &MsgSwapAll{}, - &MsgMakeSwapProposal{}, + &MsgSetSwap{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/fswap/types/fswap.go b/x/fswap/types/fswap.go index b6f26c0180..743fd1071d 100644 --- a/x/fswap/types/fswap.go +++ b/x/fswap/types/fswap.go @@ -73,22 +73,3 @@ func (s *Swapped) String() string { out, _ := yaml.Marshal(s) return string(out) } - -func (s *MakeSwapProposalTmp) ValidateBasic() error { - if err := s.Swap.ValidateBasic(); err != nil { - return err - } - if err := s.ToDenomMetadata.Validate(); err != nil { - return err - } - if s.Swap.ToDenom != s.ToDenomMetadata.Base { - return sdkerrors.ErrInvalidRequest.Wrapf("denomination does not match %s != %s", s.Swap.ToDenom, s.ToDenomMetadata.Base) - } - - return nil -} - -func (s *MakeSwapProposalTmp) String() string { - out, _ := yaml.Marshal(s) - return string(out) -} diff --git a/x/fswap/types/fswap.pb.go b/x/fswap/types/fswap.pb.go index 3799227784..7290087bf1 100644 --- a/x/fswap/types/fswap.pb.go +++ b/x/fswap/types/fswap.pb.go @@ -6,8 +6,7 @@ package types import ( fmt "fmt" github_com_Finschia_finschia_sdk_types "github.com/Finschia/finschia-sdk/types" - types1 "github.com/Finschia/finschia-sdk/types" - types "github.com/Finschia/finschia-sdk/x/bank/types" + types "github.com/Finschia/finschia-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -122,66 +121,15 @@ func (m *SwapStats) GetSwapCount() int32 { return 0 } -type MakeSwapProposalTmp struct { - Swap Swap `protobuf:"bytes,1,opt,name=swap,proto3" json:"swap"` - ToDenomMetadata types.Metadata `protobuf:"bytes,2,opt,name=to_denom_metadata,json=toDenomMetadata,proto3" json:"to_denom_metadata" yaml:"denom_metadata"` -} - -func (m *MakeSwapProposalTmp) Reset() { *m = MakeSwapProposalTmp{} } -func (*MakeSwapProposalTmp) ProtoMessage() {} -func (*MakeSwapProposalTmp) Descriptor() ([]byte, []int) { - return fileDescriptor_42ca60eaf37a2b67, []int{2} -} -func (m *MakeSwapProposalTmp) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MakeSwapProposalTmp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MakeSwapProposalTmp.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MakeSwapProposalTmp) XXX_Merge(src proto.Message) { - xxx_messageInfo_MakeSwapProposalTmp.Merge(m, src) -} -func (m *MakeSwapProposalTmp) XXX_Size() int { - return m.Size() -} -func (m *MakeSwapProposalTmp) XXX_DiscardUnknown() { - xxx_messageInfo_MakeSwapProposalTmp.DiscardUnknown(m) -} - -var xxx_messageInfo_MakeSwapProposalTmp proto.InternalMessageInfo - -func (m *MakeSwapProposalTmp) GetSwap() Swap { - if m != nil { - return m.Swap - } - return Swap{} -} - -func (m *MakeSwapProposalTmp) GetToDenomMetadata() types.Metadata { - if m != nil { - return m.ToDenomMetadata - } - return types.Metadata{} -} - type Swapped struct { - FromCoinAmount types1.Coin `protobuf:"bytes,1,opt,name=from_coin_amount,json=fromCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"from_coin_amount"` - ToCoinAmount types1.Coin `protobuf:"bytes,2,opt,name=to_coin_amount,json=toCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"to_coin_amount"` + FromCoinAmount types.Coin `protobuf:"bytes,1,opt,name=from_coin_amount,json=fromCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"from_coin_amount"` + ToCoinAmount types.Coin `protobuf:"bytes,2,opt,name=to_coin_amount,json=toCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"to_coin_amount"` } func (m *Swapped) Reset() { *m = Swapped{} } func (*Swapped) ProtoMessage() {} func (*Swapped) Descriptor() ([]byte, []int) { - return fileDescriptor_42ca60eaf37a2b67, []int{3} + return fileDescriptor_42ca60eaf37a2b67, []int{2} } func (m *Swapped) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -210,63 +158,56 @@ func (m *Swapped) XXX_DiscardUnknown() { var xxx_messageInfo_Swapped proto.InternalMessageInfo -func (m *Swapped) GetFromCoinAmount() types1.Coin { +func (m *Swapped) GetFromCoinAmount() types.Coin { if m != nil { return m.FromCoinAmount } - return types1.Coin{} + return types.Coin{} } -func (m *Swapped) GetToCoinAmount() types1.Coin { +func (m *Swapped) GetToCoinAmount() types.Coin { if m != nil { return m.ToCoinAmount } - return types1.Coin{} + return types.Coin{} } func init() { proto.RegisterType((*Swap)(nil), "lbm.fswap.v1.Swap") proto.RegisterType((*SwapStats)(nil), "lbm.fswap.v1.SwapStats") - proto.RegisterType((*MakeSwapProposalTmp)(nil), "lbm.fswap.v1.MakeSwapProposalTmp") proto.RegisterType((*Swapped)(nil), "lbm.fswap.v1.Swapped") } func init() { proto.RegisterFile("lbm/fswap/v1/fswap.proto", fileDescriptor_42ca60eaf37a2b67) } var fileDescriptor_42ca60eaf37a2b67 = []byte{ - // 513 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x53, 0xbf, 0x6f, 0xd3, 0x40, - 0x14, 0xb6, 0x83, 0xa1, 0xc9, 0xb5, 0x2a, 0xe0, 0x82, 0x48, 0x2b, 0xc5, 0x46, 0x9e, 0x10, 0x3f, - 0xce, 0x4a, 0xca, 0x94, 0x0d, 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0x1e, 0x91, 0xf3, 0xbe, 0x7d, 0x4c, 0xee, 0xe8, 0xd8, 0xf1, 0x97, 0x89, 0x4a, 0xcf, - 0xab, 0xab, 0x37, 0x2f, 0xa5, 0x25, 0x5f, 0x4a, 0xf7, 0x20, 0xcd, 0x82, 0x6d, 0x94, 0xfd, 0xf8, - 0xd5, 0x7d, 0xf2, 0x97, 0xa6, 0xe3, 0x50, 0xb8, 0x8e, 0x3a, 0x58, 0xbd, 0xd0, 0x2a, 0xb6, 0x22, - 0xeb, 0x0a, 0xae, 0xe9, 0xd6, 0xfe, 0x8b, 0xee, 0x9a, 0x82, 0x4b, 0xd5, 0xd2, 0x81, 0xe0, 0xe5, - 0xd9, 0xdc, 0x31, 0xcf, 0xe7, 0x8e, 0xf9, 0x6d, 0xee, 0x98, 0xef, 0x17, 0x8e, 0x71, 0xbe, 0x70, - 0x8c, 0xcf, 0x0b, 0xc7, 0x78, 0x4b, 0xff, 0xb8, 0xfa, 0xb8, 0x7a, 0xac, 0x5a, 0x22, 0xbe, 0xa5, - 0x9f, 0xd1, 0xf6, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe0, 0x50, 0x1b, 0xc2, 0xc6, 0x03, 0x00, + // 417 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x92, 0xbd, 0x8e, 0xd3, 0x40, + 0x10, 0xc7, 0xed, 0x10, 0xb8, 0x78, 0x39, 0x9d, 0x90, 0x41, 0x22, 0x77, 0x12, 0x36, 0x4a, 0x85, + 0x40, 0xec, 0xca, 0x09, 0x55, 0x3a, 0x92, 0x28, 0x82, 0x0a, 0xc9, 0xa1, 0xa2, 0xb1, 0xd6, 0xce, + 0x3a, 0xb1, 0x88, 0x3d, 0x96, 0x77, 0xf3, 0xc1, 0x03, 0xd0, 0x53, 0x52, 0xa6, 0xe6, 0x49, 0x52, + 0xa6, 0x44, 0x14, 0x01, 0x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 0x95, 0x68, 0x37, 0xff, 0x69, + 0xf6, 0x48, 0x24, 0x61, 0x0b, 0x87, 0x84, 0x5c, 0x89, 0x7e, 0xeb, 0xfd, 0xd6, 0xb7, 0xbe, 0x6e, + 0x7d, 0xbb, 0xf3, 0x84, 0x38, 0x68, 0xc3, 0x44, 0x71, 0x25, 0xd1, 0x0b, 0xcd, 0x49, 0x70, 0x05, + 0xed, 0xc5, 0xf5, 0x50, 0x93, 0x87, 0x98, 0xf8, 0xa5, 0xeb, 0x9b, 0x4d, 0xce, 0xb0, 0xad, 0x14, + 0x53, 0x77, 0x43, 0x6e, 0x69, 0x03, 0xd1, 0xdc, 0xc8, 0x6c, 0xaf, 0x5b, 0x6f, 0x76, 0x2f, 0xa9, + 0x39, 0x02, 0xc5, 0x23, 0xd0, 0xfa, 0x08, 0x74, 0x08, 0x59, 0x31, 0xe8, 0xe1, 0xfa, 0x1f, 0x3e, + 0xfb, 0x8f, 0xfe, 0x72, 0x7d, 0x6c, 0x0a, 0x2f, 0x90, 0x83, 0xd1, 0x53, 0x4d, 0x71, 0x15, 0xb9, + 0x50, 0xf0, 0x1b, 0xb7, 0xf1, 0x5f, 0xb8, 0xe7, 0x0a, 0x7e, 0x52, 0xfb, 0x4d, 0x74, 0x61, 0xf0, + 0x6c, 0x77, 0xf4, 0xec, 0xfd, 0xd1, 0xb3, 0xbf, 0x1c, 0x3d, 0xfb, 0xdd, 0xc9, 0xb3, 0xf6, 0x27, + 0xcf, 0xfa, 0x78, 0xf2, 0xac, 0x57, 0xf4, 0x8f, 0xa3, 0x37, 0xf5, 0xb7, 0xd6, 0x88, 0xf8, 0x86, + 0xfe, 0x90, 0xbd, 0xef, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe9, 0xf1, 0xe6, 0x57, 0xf0, 0x02, 0x00, 0x00, } @@ -412,49 +353,6 @@ func (m *SwapStats) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MakeSwapProposalTmp) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MakeSwapProposalTmp) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MakeSwapProposalTmp) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.ToDenomMetadata.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFswap(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - { - size, err := m.Swap.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFswap(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - func (m *Swapped) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -542,19 +440,6 @@ func (m *SwapStats) Size() (n int) { return n } -func (m *MakeSwapProposalTmp) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Swap.Size() - n += 1 + l + sovFswap(uint64(l)) - l = m.ToDenomMetadata.Size() - n += 1 + l + sovFswap(uint64(l)) - return n -} - func (m *Swapped) Size() (n int) { if m == nil { return 0 @@ -825,122 +710,6 @@ func (m *SwapStats) Unmarshal(dAtA []byte) error { } return nil } -func (m *MakeSwapProposalTmp) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFswap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MakeSwapProposalTmp: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MakeSwapProposalTmp: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Swap", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFswap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthFswap - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthFswap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Swap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ToDenomMetadata", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFswap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthFswap - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthFswap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.ToDenomMetadata.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipFswap(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthFswap - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *Swapped) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/fswap/types/msgs.go b/x/fswap/types/msgs.go index eef9698e45..67d457e7a5 100644 --- a/x/fswap/types/msgs.go +++ b/x/fswap/types/msgs.go @@ -1,13 +1,15 @@ package types import ( + "gopkg.in/yaml.v2" + sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" ) var _ sdk.Msg = &MsgSwap{} var _ sdk.Msg = &MsgSwapAll{} -var _ sdk.Msg = &MsgMakeSwapProposal{} +var _ sdk.Msg = &MsgSetSwap{} // ValidateBasic Implements Msg. func (m *MsgSwap) ValidateBasic() error { @@ -77,24 +79,35 @@ func (m *MsgSwapAll) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) } -func (m *MsgMakeSwapProposal) ValidateBasic() error { +func (m *MsgSetSwap) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", m.Authority) } - if err := m.GetProposal().ValidateBasic(); err != nil { + if err := m.Swap.ValidateBasic(); err != nil { + return err + } + if err := m.ToDenomMetadata.Validate(); err != nil { return err } + if m.Swap.ToDenom != m.ToDenomMetadata.Base { + return sdkerrors.ErrInvalidRequest.Wrapf("denomination does not match %s != %s", m.Swap.ToDenom, m.ToDenomMetadata.Base) + } return nil } -func (m *MsgMakeSwapProposal) GetSigners() []sdk.AccAddress { +func (m *MsgSetSwap) GetSigners() []sdk.AccAddress { signer := sdk.MustAccAddressFromBech32(m.Authority) return []sdk.AccAddress{signer} } // GetSignBytes implements the LegacyMsg.GetSignBytes method. -func (m *MsgMakeSwapProposal) GetSignBytes() []byte { +func (m *MsgSetSwap) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) } + +func (m *MsgSetSwap) String() string { + out, _ := yaml.Marshal(m) + return string(out) +} diff --git a/x/fswap/types/tx.pb.go b/x/fswap/types/tx.pb.go index ab11cb2400..5e404bb037 100644 --- a/x/fswap/types/tx.pb.go +++ b/x/fswap/types/tx.pb.go @@ -7,6 +7,7 @@ import ( context "context" fmt "fmt" types "github.com/Finschia/finschia-sdk/types" + types1 "github.com/Finschia/finschia-sdk/x/bank/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -224,24 +225,24 @@ func (m *MsgSwapAllResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSwapAllResponse proto.InternalMessageInfo -type MsgMakeSwapProposal struct { +type MsgSetSwap struct { // authority is the address of the privileged account. - Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` - Proposal *MakeSwapProposalTmp `protobuf:"bytes,2,opt,name=proposal,proto3" json:"proposal,omitempty"` + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + Swap Swap `protobuf:"bytes,2,opt,name=swap,proto3" json:"swap"` + ToDenomMetadata types1.Metadata `protobuf:"bytes,3,opt,name=to_denom_metadata,json=toDenomMetadata,proto3" json:"to_denom_metadata" yaml:"denom_metadata"` } -func (m *MsgMakeSwapProposal) Reset() { *m = MsgMakeSwapProposal{} } -func (m *MsgMakeSwapProposal) String() string { return proto.CompactTextString(m) } -func (*MsgMakeSwapProposal) ProtoMessage() {} -func (*MsgMakeSwapProposal) Descriptor() ([]byte, []int) { +func (m *MsgSetSwap) Reset() { *m = MsgSetSwap{} } +func (*MsgSetSwap) ProtoMessage() {} +func (*MsgSetSwap) Descriptor() ([]byte, []int) { return fileDescriptor_65c77cf1d9b67323, []int{4} } -func (m *MsgMakeSwapProposal) XXX_Unmarshal(b []byte) error { +func (m *MsgSetSwap) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgMakeSwapProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgSetSwap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgMakeSwapProposal.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgSetSwap.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -251,47 +252,54 @@ func (m *MsgMakeSwapProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *MsgMakeSwapProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgMakeSwapProposal.Merge(m, src) +func (m *MsgSetSwap) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetSwap.Merge(m, src) } -func (m *MsgMakeSwapProposal) XXX_Size() int { +func (m *MsgSetSwap) XXX_Size() int { return m.Size() } -func (m *MsgMakeSwapProposal) XXX_DiscardUnknown() { - xxx_messageInfo_MsgMakeSwapProposal.DiscardUnknown(m) +func (m *MsgSetSwap) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetSwap.DiscardUnknown(m) } -var xxx_messageInfo_MsgMakeSwapProposal proto.InternalMessageInfo +var xxx_messageInfo_MsgSetSwap proto.InternalMessageInfo -func (m *MsgMakeSwapProposal) GetAuthority() string { +func (m *MsgSetSwap) GetAuthority() string { if m != nil { return m.Authority } return "" } -func (m *MsgMakeSwapProposal) GetProposal() *MakeSwapProposalTmp { +func (m *MsgSetSwap) GetSwap() Swap { if m != nil { - return m.Proposal + return m.Swap } - return nil + return Swap{} +} + +func (m *MsgSetSwap) GetToDenomMetadata() types1.Metadata { + if m != nil { + return m.ToDenomMetadata + } + return types1.Metadata{} } -type MsgMakeSwapProposalResponse struct { +type MsgSetSwapResponse struct { } -func (m *MsgMakeSwapProposalResponse) Reset() { *m = MsgMakeSwapProposalResponse{} } -func (m *MsgMakeSwapProposalResponse) String() string { return proto.CompactTextString(m) } -func (*MsgMakeSwapProposalResponse) ProtoMessage() {} -func (*MsgMakeSwapProposalResponse) Descriptor() ([]byte, []int) { +func (m *MsgSetSwapResponse) Reset() { *m = MsgSetSwapResponse{} } +func (m *MsgSetSwapResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSetSwapResponse) ProtoMessage() {} +func (*MsgSetSwapResponse) Descriptor() ([]byte, []int) { return fileDescriptor_65c77cf1d9b67323, []int{5} } -func (m *MsgMakeSwapProposalResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgSetSwapResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgMakeSwapProposalResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgSetSwapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgMakeSwapProposalResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgSetSwapResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -301,61 +309,64 @@ func (m *MsgMakeSwapProposalResponse) XXX_Marshal(b []byte, deterministic bool) return b[:n], nil } } -func (m *MsgMakeSwapProposalResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgMakeSwapProposalResponse.Merge(m, src) +func (m *MsgSetSwapResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetSwapResponse.Merge(m, src) } -func (m *MsgMakeSwapProposalResponse) XXX_Size() int { +func (m *MsgSetSwapResponse) XXX_Size() int { return m.Size() } -func (m *MsgMakeSwapProposalResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgMakeSwapProposalResponse.DiscardUnknown(m) +func (m *MsgSetSwapResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetSwapResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgMakeSwapProposalResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgSetSwapResponse proto.InternalMessageInfo func init() { proto.RegisterType((*MsgSwap)(nil), "lbm.fswap.v1.MsgSwap") proto.RegisterType((*MsgSwapResponse)(nil), "lbm.fswap.v1.MsgSwapResponse") proto.RegisterType((*MsgSwapAll)(nil), "lbm.fswap.v1.MsgSwapAll") proto.RegisterType((*MsgSwapAllResponse)(nil), "lbm.fswap.v1.MsgSwapAllResponse") - proto.RegisterType((*MsgMakeSwapProposal)(nil), "lbm.fswap.v1.MsgMakeSwapProposal") - proto.RegisterType((*MsgMakeSwapProposalResponse)(nil), "lbm.fswap.v1.MsgMakeSwapProposalResponse") + proto.RegisterType((*MsgSetSwap)(nil), "lbm.fswap.v1.MsgSetSwap") + proto.RegisterType((*MsgSetSwapResponse)(nil), "lbm.fswap.v1.MsgSetSwapResponse") } func init() { proto.RegisterFile("lbm/fswap/v1/tx.proto", fileDescriptor_65c77cf1d9b67323) } var fileDescriptor_65c77cf1d9b67323 = []byte{ - // 471 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x4d, 0x6f, 0xd3, 0x40, - 0x10, 0x8d, 0x5b, 0x44, 0x9a, 0x69, 0x05, 0x65, 0x69, 0x25, 0xd7, 0x10, 0x37, 0xc9, 0xa9, 0x08, - 0xb1, 0xab, 0xb4, 0x57, 0x38, 0xa4, 0x7c, 0x88, 0x4b, 0x24, 0x14, 0x38, 0x71, 0x09, 0xeb, 0xc4, - 0x71, 0xac, 0xda, 0x9e, 0x95, 0x77, 0x93, 0xa6, 0xff, 0x82, 0xdf, 0xc1, 0xbf, 0xe0, 0xd6, 0x63, - 0x8f, 0x9c, 0x00, 0x25, 0x57, 0x7e, 0x04, 0xda, 0xf5, 0x26, 0x85, 0x34, 0x90, 0xde, 0xd6, 0x6f, - 0xde, 0xbc, 0xf7, 0x66, 0xbc, 0x0b, 0xfb, 0x49, 0x90, 0xb2, 0x81, 0x3c, 0xe7, 0x82, 0x8d, 0x9b, - 0x4c, 0x4d, 0xa8, 0xc8, 0x51, 0x21, 0xd9, 0x49, 0x82, 0x94, 0x1a, 0x98, 0x8e, 0x9b, 0xde, 0x5e, - 0x84, 0x11, 0x9a, 0x02, 0xd3, 0xa7, 0x82, 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, 0xe2, 0x7f, 0xee, 0x7b, - 0x40, 0xae, 0xad, 0x16, 0x01, 0x72, 0x78, 0xd8, 0x96, 0x51, 0x9b, 0x9f, 0x85, 0xba, 0xf2, 0x2e, - 0x47, 0x81, 0x92, 0x27, 0xe4, 0x31, 0x54, 0xf8, 0x48, 0x0d, 0x31, 0x8f, 0xd5, 0x85, 0x8d, 0x71, - 0x0d, 0x90, 0x17, 0xb0, 0x25, 0x2c, 0xd3, 0x6e, 0xb5, 0x4e, 0xff, 0xfc, 0xfb, 0x74, 0x59, 0xef, - 0x43, 0x2a, 0x3a, 0x8b, 0x96, 0x46, 0x15, 0x1e, 0xad, 0xf0, 0x9c, 0x47, 0x3a, 0xfe, 0xe5, 0xc0, - 0x66, 0x5b, 0x46, 0xe4, 0x39, 0xdc, 0x31, 0xbf, 0x7b, 0x7f, 0x49, 0xbb, 0x18, 0xc2, 0xab, 0xae, - 0x84, 0xe7, 0x2a, 0xe4, 0x35, 0x94, 0xe7, 0x6b, 0x75, 0x57, 0x32, 0x5b, 0x49, 0xe2, 0xd5, 0xfe, - 0x55, 0x59, 0xc8, 0x7c, 0x82, 0xdd, 0x1b, 0xcb, 0xa9, 0xdf, 0xe8, 0x5a, 0xa6, 0x78, 0x4f, 0xd6, - 0x52, 0xe6, 0x0e, 0xa7, 0x6f, 0x2f, 0xa7, 0xbe, 0x73, 0x35, 0xf5, 0x9d, 0x9f, 0x53, 0xdf, 0xf9, - 0x3c, 0xf3, 0x4b, 0x57, 0x33, 0xbf, 0xf4, 0x6d, 0xe6, 0x97, 0x3e, 0xd2, 0xb5, 0xf7, 0x70, 0x62, - 0x1f, 0x8b, 0xb9, 0x8f, 0xc1, 0x5d, 0xf3, 0x54, 0x4e, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0xdf, - 0xcc, 0x1f, 0xeb, 0xa1, 0x03, 0x00, 0x00, + // 513 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0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, 0xfd, 0x12, 0x92, 0xe9, 0x6e, 0x09, 0x03, 0x43, 0xea, 0x37, 0x55, + 0x97, 0x1f, 0x77, 0xad, 0xfa, 0x8a, 0xb0, 0xf8, 0xda, 0x2d, 0xb6, 0x70, 0xbd, 0x53, 0x13, 0x29, + 0xe7, 0x5f, 0x97, 0x3f, 0x7c, 0x6c, 0x95, 0xf2, 0x80, 0x59, 0x92, 0x3c, 0x60, 0xf7, 0x8b, 0x05, + 0x8e, 0x07, 0x22, 0x84, 0xcf, 0x41, 0x59, 0x27, 0xac, 0x17, 0x5d, 0x9b, 0x91, 0x34, 0x9a, 0x07, + 0xcb, 0x79, 0x17, 0xf8, 0x0a, 0x54, 0xf2, 0x25, 0xd9, 0x07, 0x99, 0xbd, 0x38, 0x6e, 0xb4, 0xff, + 0x84, 0x14, 0xda, 0x98, 0x49, 0x1f, 0x68, 0x93, 0x21, 0x87, 0xda, 0x14, 0x33, 0xf5, 0xdf, 0xac, + 0x37, 0x8e, 0x75, 0xbb, 0x71, 0xac, 0xef, 0x1b, 0xc7, 0x7a, 0xbf, 0x75, 0x4a, 0xb7, 0x5b, 0xa7, + 0xf4, 0x75, 0xeb, 0x94, 0xde, 0xa1, 0x7f, 0x5e, 0xdd, 0xa5, 0x79, 0x5f, 0xfa, 0x0a, 0xfb, 0xf7, + 0xf4, 0xeb, 0xba, 0xfa, 0x19, 0x00, 0x00, 0xff, 0xff, 0x28, 0x4e, 0x64, 0x95, 0xf4, 0x03, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -372,7 +383,7 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { Swap(ctx context.Context, in *MsgSwap, opts ...grpc.CallOption) (*MsgSwapResponse, error) SwapAll(ctx context.Context, in *MsgSwapAll, opts ...grpc.CallOption) (*MsgSwapAllResponse, error) - MakeSwapProposal(ctx context.Context, in *MsgMakeSwapProposal, opts ...grpc.CallOption) (*MsgMakeSwapProposalResponse, error) + SetSwap(ctx context.Context, in *MsgSetSwap, opts ...grpc.CallOption) (*MsgSetSwapResponse, error) } type msgClient struct { @@ -401,9 +412,9 @@ func (c *msgClient) SwapAll(ctx context.Context, in *MsgSwapAll, opts ...grpc.Ca return out, nil } -func (c *msgClient) MakeSwapProposal(ctx context.Context, in *MsgMakeSwapProposal, opts ...grpc.CallOption) (*MsgMakeSwapProposalResponse, error) { - out := new(MsgMakeSwapProposalResponse) - err := c.cc.Invoke(ctx, "/lbm.fswap.v1.Msg/MakeSwapProposal", in, out, opts...) +func (c *msgClient) SetSwap(ctx context.Context, in *MsgSetSwap, opts ...grpc.CallOption) (*MsgSetSwapResponse, error) { + out := new(MsgSetSwapResponse) + err := c.cc.Invoke(ctx, "/lbm.fswap.v1.Msg/SetSwap", in, out, opts...) if err != nil { return nil, err } @@ -414,7 +425,7 @@ func (c *msgClient) MakeSwapProposal(ctx context.Context, in *MsgMakeSwapProposa type MsgServer interface { Swap(context.Context, *MsgSwap) (*MsgSwapResponse, error) SwapAll(context.Context, *MsgSwapAll) (*MsgSwapAllResponse, error) - MakeSwapProposal(context.Context, *MsgMakeSwapProposal) (*MsgMakeSwapProposalResponse, error) + SetSwap(context.Context, *MsgSetSwap) (*MsgSetSwapResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -427,8 +438,8 @@ func (*UnimplementedMsgServer) Swap(ctx context.Context, req *MsgSwap) (*MsgSwap func (*UnimplementedMsgServer) SwapAll(ctx context.Context, req *MsgSwapAll) (*MsgSwapAllResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SwapAll not implemented") } -func (*UnimplementedMsgServer) MakeSwapProposal(ctx context.Context, req *MsgMakeSwapProposal) (*MsgMakeSwapProposalResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method MakeSwapProposal not implemented") +func (*UnimplementedMsgServer) SetSwap(ctx context.Context, req *MsgSetSwap) (*MsgSetSwapResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetSwap not implemented") } func RegisterMsgServer(s grpc1.Server, srv MsgServer) { @@ -471,20 +482,20 @@ func _Msg_SwapAll_Handler(srv interface{}, ctx context.Context, dec func(interfa return interceptor(ctx, in, info, handler) } -func _Msg_MakeSwapProposal_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgMakeSwapProposal) +func _Msg_SetSwap_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSetSwap) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).MakeSwapProposal(ctx, in) + return srv.(MsgServer).SetSwap(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/lbm.fswap.v1.Msg/MakeSwapProposal", + FullMethod: "/lbm.fswap.v1.Msg/SetSwap", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).MakeSwapProposal(ctx, req.(*MsgMakeSwapProposal)) + return srv.(MsgServer).SetSwap(ctx, req.(*MsgSetSwap)) } return interceptor(ctx, in, info, handler) } @@ -502,8 +513,8 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Handler: _Msg_SwapAll_Handler, }, { - MethodName: "MakeSwapProposal", - Handler: _Msg_MakeSwapProposal_Handler, + MethodName: "SetSwap", + Handler: _Msg_SetSwap_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -647,7 +658,7 @@ func (m *MsgSwapAllResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgMakeSwapProposal) Marshal() (dAtA []byte, err error) { +func (m *MsgSetSwap) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -657,28 +668,36 @@ func (m *MsgMakeSwapProposal) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgMakeSwapProposal) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgSetSwap) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgMakeSwapProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgSetSwap) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Proposal != nil { - { - size, err := m.Proposal.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + { + size, err := m.ToDenomMetadata.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x1a + { + size, err := m.Swap.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 if len(m.Authority) > 0 { i -= len(m.Authority) copy(dAtA[i:], m.Authority) @@ -689,7 +708,7 @@ func (m *MsgMakeSwapProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgMakeSwapProposalResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgSetSwapResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -699,12 +718,12 @@ func (m *MsgMakeSwapProposalResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgMakeSwapProposalResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgSetSwapResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgMakeSwapProposalResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgSetSwapResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -781,7 +800,7 @@ func (m *MsgSwapAllResponse) Size() (n int) { return n } -func (m *MsgMakeSwapProposal) Size() (n int) { +func (m *MsgSetSwap) Size() (n int) { if m == nil { return 0 } @@ -791,14 +810,14 @@ func (m *MsgMakeSwapProposal) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if m.Proposal != nil { - l = m.Proposal.Size() - n += 1 + l + sovTx(uint64(l)) - } + l = m.Swap.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.ToDenomMetadata.Size() + n += 1 + l + sovTx(uint64(l)) return n } -func (m *MsgMakeSwapProposalResponse) Size() (n int) { +func (m *MsgSetSwapResponse) Size() (n int) { if m == nil { return 0 } @@ -1206,7 +1225,7 @@ func (m *MsgSwapAllResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgMakeSwapProposal) Unmarshal(dAtA []byte) error { +func (m *MsgSetSwap) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1229,10 +1248,10 @@ func (m *MsgMakeSwapProposal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgMakeSwapProposal: wiretype end group for non-group") + return fmt.Errorf("proto: MsgSetSwap: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgMakeSwapProposal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgSetSwap: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1269,7 +1288,7 @@ func (m *MsgMakeSwapProposal) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Proposal", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Swap", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1296,10 +1315,40 @@ func (m *MsgMakeSwapProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Proposal == nil { - m.Proposal = &MakeSwapProposalTmp{} + if err := m.Swap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ToDenomMetadata", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF } - if err := m.Proposal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.ToDenomMetadata.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1324,7 +1373,7 @@ func (m *MsgMakeSwapProposal) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgMakeSwapProposalResponse) Unmarshal(dAtA []byte) error { +func (m *MsgSetSwapResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1347,10 +1396,10 @@ func (m *MsgMakeSwapProposalResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgMakeSwapProposalResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgSetSwapResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgMakeSwapProposalResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgSetSwapResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: From df3bbd44303f2c5cfb7b90f4102a43949b476592 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 9 May 2024 17:07:58 +0900 Subject: [PATCH 3/9] chore: clean-up --- x/fswap/client/cli/tx.go | 18 ++-- x/fswap/keeper/keeper.go | 155 ++++++++++++++++++++++++++++ x/fswap/keeper/keeper_test.go | 132 +++++++++++++++++++++++- x/fswap/keeper/msg_server.go | 2 +- x/fswap/keeper/msg_server_test.go | 4 +- x/fswap/keeper/proposal.go | 163 ------------------------------ x/fswap/keeper/proposal_test.go | 138 ------------------------- 7 files changed, 298 insertions(+), 314 deletions(-) delete mode 100644 x/fswap/keeper/proposal.go delete mode 100644 x/fswap/keeper/proposal_test.go diff --git a/x/fswap/client/cli/tx.go b/x/fswap/client/cli/tx.go index 94308d346b..61cd359d75 100644 --- a/x/fswap/client/cli/tx.go +++ b/x/fswap/client/cli/tx.go @@ -34,7 +34,7 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand( CmdTxMsgSwap(), CmdTxMsgSwapAll(), - CmdMsgMakeSwapProposal(), + CmdMsgSetSwap(), ) return cmd @@ -114,12 +114,12 @@ func CmdTxMsgSwapAll() *cobra.Command { return cmd } -// CmdMsgMakeSwapProposal implements a command handler for submitting a swap init proposal transaction. -func CmdMsgMakeSwapProposal() *cobra.Command { +// CmdMsgSetSwap implements a command handler for submitting a swap init proposal transaction. +func CmdMsgSetSwap() *cobra.Command { cmd := &cobra.Command{ - Use: "make-swap-proposal [authority] [metadata-json]", + Use: "set-swap [authority] [metadata-json]", Args: cobra.ExactArgs(2), - Short: "Make swap proposal", + Short: "Set a swap", Long: ` Parameters: metadata-json: messages in json format that will be executed if the proposal is accepted. @@ -211,10 +211,10 @@ Example of the content of metadata-json: }, } - cmd.Flags().String(FlagFromDenom, "", "cony") - cmd.Flags().String(FlagToDenom, "", "PDT") - cmd.Flags().String(FlagAmountCapForToDenom, "0", "tbd") - cmd.Flags().String(FlagSwapRate, "0", "tbd") + cmd.Flags().String(FlagFromDenom, "", "set fromDenom string, ex) cony") + cmd.Flags().String(FlagToDenom, "", "set toDenom string, ex) peb") + cmd.Flags().String(FlagAmountCapForToDenom, "0", "set integer value for limit cap for the amount to swap to to-denom, ex 1000000000") + cmd.Flags().String(FlagSwapRate, "0", "set swap rate for swap from fromDenom to toDenom, ex(rate for cony to peb) 148079656000000") flags.AddTxFlagsToCmd(cmd) return cmd diff --git a/x/fswap/keeper/keeper.go b/x/fswap/keeper/keeper.go index 9ba08b97f0..0f21acd3f5 100644 --- a/x/fswap/keeper/keeper.go +++ b/x/fswap/keeper/keeper.go @@ -10,6 +10,7 @@ import ( storetypes "github.com/Finschia/finschia-sdk/store/types" sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" + bank "github.com/Finschia/finschia-sdk/x/bank/types" "github.com/Finschia/finschia-sdk/x/fswap/types" ) @@ -92,6 +93,63 @@ func (k Keeper) Swap(ctx sdk.Context, addr sdk.AccAddress, fromCoinAmount sdk.Co return nil } +func (k Keeper) SetSwap(ctx sdk.Context, swap types.Swap, toDenomMetadata bank.Metadata) error { + isNewSwap := true + if _, err := k.getSwap(ctx, swap.FromDenom, swap.ToDenom); err == nil { + isNewSwap = false + } + + if !isNewSwap && !k.config.UpdateAllowed { + return sdkerrors.ErrInvalidRequest.Wrap("update existing swap not allowed") + } + + if isNewSwap { + if err := k.increaseSwapCount(ctx); err != nil { + return err + } + } + + stats, err := k.getSwapStats(ctx) + if err != nil { + return err + } + + if int(stats.SwapCount) > k.config.MaxSwaps && !k.isUnlimited() { + return types.ErrCanNotHaveMoreSwap.Wrapf("cannot make more swaps, max swaps is %d", k.config.MaxSwaps) + } + + if isNewSwap { + swapped := types.Swapped{ + FromCoinAmount: sdk.Coin{ + Denom: swap.GetFromDenom(), + Amount: sdk.ZeroInt(), + }, + ToCoinAmount: sdk.Coin{ + Denom: swap.GetToDenom(), + Amount: sdk.ZeroInt(), + }, + } + if err := k.setSwapped(ctx, swapped); err != nil { + return err + } + } + + if err := k.setSwap(ctx, swap); err != nil { + return err + } + + existingMetadata, ok := k.GetDenomMetaData(ctx, swap.ToDenom) + if !ok { + k.SetDenomMetaData(ctx, toDenomMetadata) + return nil + } + if !denomMetadataEqual(existingMetadata, toDenomMetadata) { + return sdkerrors.ErrInvalidRequest.Wrap("changing existing metadata not allowed") + } + + return nil +} + func (k Keeper) getAllSwapped(ctx sdk.Context) []types.Swapped { swappedSlice := []types.Swapped{} k.iterateAllSwapped(ctx, func(swapped types.Swapped) bool { @@ -219,3 +277,100 @@ func (k Keeper) validateAuthority(authority string) error { return nil } + +func denomMetadataEqual(metadata, otherMetadata bank.Metadata) bool { + if metadata.Description != otherMetadata.Description { + return false + } + if len(metadata.DenomUnits) != len(otherMetadata.DenomUnits) { + return false + } + for i, unit := range metadata.DenomUnits { + if unit.Denom != otherMetadata.DenomUnits[i].Denom { + return false + } + } + if metadata.Base != otherMetadata.Base { + return false + } + if metadata.Display != otherMetadata.Display { + return false + } + if metadata.Name != otherMetadata.Name { + return false + } + if metadata.Symbol != otherMetadata.Symbol { + return false + } + return true +} + +func (k Keeper) increaseSwapCount(ctx sdk.Context) error { + stats, err := k.getSwapStats(ctx) + if err != nil { + return err + } + + prev := stats.SwapCount + stats.SwapCount += 1 + if stats.SwapCount < prev { + return types.ErrInvalidState.Wrap("overflow detected") + } + + if err := k.setSwapStats(ctx, stats); err != nil { + return err + } + return nil +} + +func (k Keeper) setSwap(ctx sdk.Context, swap types.Swap) error { + key := swapKey(swap.FromDenom, swap.ToDenom) + bz, err := k.cdc.Marshal(&swap) + if err != nil { + return err + } + + store := ctx.KVStore(k.storeKey) + store.Set(key, bz) + return nil +} + +func (k Keeper) getSwap(ctx sdk.Context, fromDenom, toDenom string) (types.Swap, error) { + store := ctx.KVStore(k.storeKey) + key := swapKey(fromDenom, toDenom) + bz := store.Get(key) + if bz == nil { + return types.Swap{}, sdkerrors.ErrNotFound.Wrap("swap not found") + } + + swap := types.Swap{} + if err := k.cdc.Unmarshal(bz, &swap); err != nil { + return types.Swap{}, err + } + + return swap, nil +} + +func (k Keeper) getAllSwaps(ctx sdk.Context) []types.Swap { + swaps := []types.Swap{} + k.iterateAllSwaps(ctx, func(swap types.Swap) bool { + swaps = append(swaps, swap) + return false + }) + return swaps +} + +func (k Keeper) iterateAllSwaps(ctx sdk.Context, cb func(swapped types.Swap) (stop bool)) { + store := ctx.KVStore(k.storeKey) + swapDataStore := prefix.NewStore(store, swapPrefix) + + iterator := swapDataStore.Iterator(nil, nil) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + swap := types.Swap{} + k.cdc.MustUnmarshal(iterator.Value(), &swap) + if cb(swap) { + break + } + } +} diff --git a/x/fswap/keeper/keeper_test.go b/x/fswap/keeper/keeper_test.go index fdf9e95d25..63774bef84 100644 --- a/x/fswap/keeper/keeper_test.go +++ b/x/fswap/keeper/keeper_test.go @@ -172,7 +172,7 @@ func (s *KeeperTestSuite) TestSwap() { for name, tc := range testCases { s.Run(name, func() { ctx, _ := s.ctx.CacheContext() - err := s.keeper.MakeSwap(ctx, s.swap, s.toDenomMetadata) + err := s.keeper.SetSwap(ctx, s.swap, s.toDenomMetadata) s.Require().NoError(err) err = s.keeper.Swap(ctx, tc.from, tc.amountToSwap, tc.toDenom) @@ -187,3 +187,133 @@ func (s *KeeperTestSuite) TestSwap() { }) } } + +func (s *KeeperTestSuite) TestSetSwap() { + testCases := map[string]struct { + swap types.Swap + toDenomMeta bank.Metadata + existingMetadata bool + expectedError error + }{ + "valid": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "toD", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + s.toDenomMetadata, + false, + nil, + }, + "to-denom metadata change not allowed": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "toD", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + bank.Metadata{ + Description: s.toDenomMetadata.Description, + DenomUnits: s.toDenomMetadata.DenomUnits, + Base: "change", + Display: s.toDenomMetadata.Display, + Name: s.toDenomMetadata.Name, + Symbol: s.toDenomMetadata.Symbol, + }, + true, + sdkerrors.ErrInvalidRequest, + }, + } + for name, tc := range testCases { + s.Run(name, func() { + ctx, _ := s.ctx.CacheContext() + err := s.keeper.SetSwap(ctx, tc.swap, s.toDenomMetadata) + if tc.existingMetadata { + err := s.keeper.SetSwap(ctx, tc.swap, s.toDenomMetadata) + s.Require().ErrorIs(err, tc.expectedError) + } else { + s.Require().ErrorIs(err, tc.expectedError) + } + }) + } +} + +func (s *KeeperTestSuite) TestSwapValidateBasic() { + testCases := map[string]struct { + swap types.Swap + shouldThrowError bool + expectedError error + }{ + "valid": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "toD", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + false, + nil, + }, + "invalid empty from-denom": { + types.Swap{ + FromDenom: "", + ToDenom: "toD", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + true, + sdkerrors.ErrInvalidRequest, + }, + "invalid empty to-denom": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + true, + sdkerrors.ErrInvalidRequest, + }, + "invalid zero amount cap for to-denom": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "toD", + AmountCapForToDenom: sdk.ZeroInt(), + SwapRate: sdk.OneDec(), + }, + true, + sdkerrors.ErrInvalidRequest, + }, + "invalid zero swap-rate": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "toD", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.ZeroDec(), + }, + true, + sdkerrors.ErrInvalidRequest, + }, + "invalid the same from-denom and to-denom": { + types.Swap{ + FromDenom: "same", + ToDenom: "same", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + true, + sdkerrors.ErrInvalidRequest, + }, + } + for name, tc := range testCases { + s.Run(name, func() { + err := tc.swap.ValidateBasic() + if tc.shouldThrowError { + s.Require().ErrorIs(err, tc.expectedError) + return + } + s.Require().NoError(err) + }) + } +} diff --git a/x/fswap/keeper/msg_server.go b/x/fswap/keeper/msg_server.go index f5f5ac471d..9f948f1ebf 100644 --- a/x/fswap/keeper/msg_server.go +++ b/x/fswap/keeper/msg_server.go @@ -68,7 +68,7 @@ func (s MsgServer) SetSwap(ctx context.Context, req *types.MsgSetSwap) (*types.M return nil, err } - if err := s.keeper.MakeSwap(c, req.GetSwap(), req.GetToDenomMetadata()); err != nil { + if err := s.keeper.SetSwap(c, req.GetSwap(), req.GetToDenomMetadata()); err != nil { return nil, err } diff --git a/x/fswap/keeper/msg_server_test.go b/x/fswap/keeper/msg_server_test.go index 6e7953ac64..ab8be87e04 100644 --- a/x/fswap/keeper/msg_server_test.go +++ b/x/fswap/keeper/msg_server_test.go @@ -63,7 +63,7 @@ func (s *KeeperTestSuite) TestMsgSwap() { for name, tc := range testCases { s.Run(name, func() { ctx, _ := s.ctx.CacheContext() - err := s.keeper.MakeSwap(ctx, s.swap, s.toDenomMetadata) + err := s.keeper.SetSwap(ctx, s.swap, s.toDenomMetadata) s.Require().NoError(err) swapResponse, err := s.msgServer.Swap(sdk.WrapSDKContext(ctx), tc.request) @@ -115,7 +115,7 @@ func (s *KeeperTestSuite) TestMsgSwapAll() { for name, tc := range testCases { s.Run(name, func() { ctx, _ := s.ctx.CacheContext() - err := s.keeper.MakeSwap(ctx, s.swap, s.toDenomMetadata) + err := s.keeper.SetSwap(ctx, s.swap, s.toDenomMetadata) s.Require().NoError(err) swapResponse, err := s.msgServer.SwapAll(sdk.WrapSDKContext(ctx), tc.request) diff --git a/x/fswap/keeper/proposal.go b/x/fswap/keeper/proposal.go deleted file mode 100644 index 1c726e67a6..0000000000 --- a/x/fswap/keeper/proposal.go +++ /dev/null @@ -1,163 +0,0 @@ -package keeper - -import ( - "github.com/Finschia/finschia-sdk/store/prefix" - sdk "github.com/Finschia/finschia-sdk/types" - "github.com/Finschia/finschia-sdk/types/errors" - bank "github.com/Finschia/finschia-sdk/x/bank/types" - "github.com/Finschia/finschia-sdk/x/fswap/types" -) - -func (k Keeper) MakeSwap(ctx sdk.Context, swap types.Swap, toDenomMetadata bank.Metadata) error { - isNewSwap := true - if _, err := k.getSwap(ctx, swap.FromDenom, swap.ToDenom); err == nil { - isNewSwap = false - } - - if !isNewSwap && !k.config.UpdateAllowed { - return errors.ErrInvalidRequest.Wrap("update existing swap not allowed") - } - - if isNewSwap { - if err := k.increaseSwapCount(ctx); err != nil { - return err - } - } - - stats, err := k.getSwapStats(ctx) - if err != nil { - return err - } - - if int(stats.SwapCount) > k.config.MaxSwaps && !k.isUnlimited() { - return types.ErrCanNotHaveMoreSwap.Wrapf("cannot make more swaps, max swaps is %d", k.config.MaxSwaps) - } - - if isNewSwap { - swapped := types.Swapped{ - FromCoinAmount: sdk.Coin{ - Denom: swap.GetFromDenom(), - Amount: sdk.ZeroInt(), - }, - ToCoinAmount: sdk.Coin{ - Denom: swap.GetToDenom(), - Amount: sdk.ZeroInt(), - }, - } - if err := k.setSwapped(ctx, swapped); err != nil { - return err - } - } - - if err := k.setSwap(ctx, swap); err != nil { - return err - } - - existingMetadata, ok := k.GetDenomMetaData(ctx, swap.ToDenom) - if !ok { - k.SetDenomMetaData(ctx, toDenomMetadata) - return nil - } - if !denomMetadataEqual(existingMetadata, toDenomMetadata) { - return errors.ErrInvalidRequest.Wrap("changing existing metadata not allowed") - } - - return nil -} - -func denomMetadataEqual(metadata, otherMetadata bank.Metadata) bool { - if metadata.Description != otherMetadata.Description { - return false - } - if len(metadata.DenomUnits) != len(otherMetadata.DenomUnits) { - return false - } - for i, unit := range metadata.DenomUnits { - if unit.Denom != otherMetadata.DenomUnits[i].Denom { - return false - } - } - if metadata.Base != otherMetadata.Base { - return false - } - if metadata.Display != otherMetadata.Display { - return false - } - if metadata.Name != otherMetadata.Name { - return false - } - if metadata.Symbol != otherMetadata.Symbol { - return false - } - return true -} - -func (k Keeper) increaseSwapCount(ctx sdk.Context) error { - stats, err := k.getSwapStats(ctx) - if err != nil { - return err - } - - prev := stats.SwapCount - stats.SwapCount += 1 - if stats.SwapCount < prev { - return types.ErrInvalidState.Wrap("overflow detected") - } - - if err := k.setSwapStats(ctx, stats); err != nil { - return err - } - return nil -} - -func (k Keeper) setSwap(ctx sdk.Context, swap types.Swap) error { - key := swapKey(swap.FromDenom, swap.ToDenom) - bz, err := k.cdc.Marshal(&swap) - if err != nil { - return err - } - - store := ctx.KVStore(k.storeKey) - store.Set(key, bz) - return nil -} - -func (k Keeper) getSwap(ctx sdk.Context, fromDenom, toDenom string) (types.Swap, error) { - store := ctx.KVStore(k.storeKey) - key := swapKey(fromDenom, toDenom) - bz := store.Get(key) - if bz == nil { - return types.Swap{}, errors.ErrNotFound.Wrap("swap not found") - } - - swap := types.Swap{} - if err := k.cdc.Unmarshal(bz, &swap); err != nil { - return types.Swap{}, err - } - - return swap, nil -} - -func (k Keeper) getAllSwaps(ctx sdk.Context) []types.Swap { - swaps := []types.Swap{} - k.iterateAllSwaps(ctx, func(swap types.Swap) bool { - swaps = append(swaps, swap) - return false - }) - return swaps -} - -func (k Keeper) iterateAllSwaps(ctx sdk.Context, cb func(swapped types.Swap) (stop bool)) { - store := ctx.KVStore(k.storeKey) - swapDataStore := prefix.NewStore(store, swapPrefix) - - iterator := swapDataStore.Iterator(nil, nil) - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - swap := types.Swap{} - k.cdc.MustUnmarshal(iterator.Value(), &swap) - if cb(swap) { - break - } - } -} diff --git a/x/fswap/keeper/proposal_test.go b/x/fswap/keeper/proposal_test.go deleted file mode 100644 index 4dbe0e63b2..0000000000 --- a/x/fswap/keeper/proposal_test.go +++ /dev/null @@ -1,138 +0,0 @@ -package keeper_test - -import ( - sdk "github.com/Finschia/finschia-sdk/types" - sdkerrors "github.com/Finschia/finschia-sdk/types/errors" - bank "github.com/Finschia/finschia-sdk/x/bank/types" - "github.com/Finschia/finschia-sdk/x/fswap/types" -) - -func (s *KeeperTestSuite) TestMakeSwapProposal() { - testCases := map[string]struct { - swap types.Swap - toDenomMeta bank.Metadata - existingMetadata bool - expectedError error - }{ - "valid": { - types.Swap{ - FromDenom: "fromD", - ToDenom: "toD", - AmountCapForToDenom: sdk.OneInt(), - SwapRate: sdk.OneDec(), - }, - s.toDenomMetadata, - false, - nil, - }, - "to-denom metadata change not allowed": { - types.Swap{ - FromDenom: "fromD", - ToDenom: "toD", - AmountCapForToDenom: sdk.OneInt(), - SwapRate: sdk.OneDec(), - }, - bank.Metadata{ - Description: s.toDenomMetadata.Description, - DenomUnits: s.toDenomMetadata.DenomUnits, - Base: "change", - Display: s.toDenomMetadata.Display, - Name: s.toDenomMetadata.Name, - Symbol: s.toDenomMetadata.Symbol, - }, - true, - sdkerrors.ErrInvalidRequest, - }, - } - for name, tc := range testCases { - s.Run(name, func() { - ctx, _ := s.ctx.CacheContext() - err := s.keeper.MakeSwap(ctx, tc.swap, s.toDenomMetadata) - if tc.existingMetadata { - err := s.keeper.MakeSwap(ctx, tc.swap, s.toDenomMetadata) - s.Require().ErrorIs(err, tc.expectedError) - } else { - s.Require().ErrorIs(err, tc.expectedError) - } - }) - } -} - -func (s *KeeperTestSuite) TestSwapValidateBasic() { - testCases := map[string]struct { - swap types.Swap - shouldThrowError bool - expectedError error - }{ - "valid": { - types.Swap{ - FromDenom: "fromD", - ToDenom: "toD", - AmountCapForToDenom: sdk.OneInt(), - SwapRate: sdk.OneDec(), - }, - false, - nil, - }, - "invalid empty from-denom": { - types.Swap{ - FromDenom: "", - ToDenom: "toD", - AmountCapForToDenom: sdk.OneInt(), - SwapRate: sdk.OneDec(), - }, - true, - sdkerrors.ErrInvalidRequest, - }, - "invalid empty to-denom": { - types.Swap{ - FromDenom: "fromD", - ToDenom: "", - AmountCapForToDenom: sdk.OneInt(), - SwapRate: sdk.OneDec(), - }, - true, - sdkerrors.ErrInvalidRequest, - }, - "invalid zero amount cap for to-denom": { - types.Swap{ - FromDenom: "fromD", - ToDenom: "toD", - AmountCapForToDenom: sdk.ZeroInt(), - SwapRate: sdk.OneDec(), - }, - true, - sdkerrors.ErrInvalidRequest, - }, - "invalid zero swap-rate": { - types.Swap{ - FromDenom: "fromD", - ToDenom: "toD", - AmountCapForToDenom: sdk.OneInt(), - SwapRate: sdk.ZeroDec(), - }, - true, - sdkerrors.ErrInvalidRequest, - }, - "invalid the same from-denom and to-denom": { - types.Swap{ - FromDenom: "same", - ToDenom: "same", - AmountCapForToDenom: sdk.OneInt(), - SwapRate: sdk.OneDec(), - }, - true, - sdkerrors.ErrInvalidRequest, - }, - } - for name, tc := range testCases { - s.Run(name, func() { - err := tc.swap.ValidateBasic() - if tc.shouldThrowError { - s.Require().ErrorIs(err, tc.expectedError) - return - } - s.Require().NoError(err) - }) - } -} From 9ebf967df8098a46a41f9259a5a1d7726849a039 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 9 May 2024 17:37:32 +0900 Subject: [PATCH 4/9] chore: use original proto stringer interface --- proto/lbm/fswap/v1/tx.proto | 2 -- x/fswap/types/msgs.go | 7 ---- x/fswap/types/tx.pb.go | 72 ++++++++++++++++++------------------- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/proto/lbm/fswap/v1/tx.proto b/proto/lbm/fswap/v1/tx.proto index 8a0dffcc1e..eb6154dd81 100644 --- a/proto/lbm/fswap/v1/tx.proto +++ b/proto/lbm/fswap/v1/tx.proto @@ -35,8 +35,6 @@ message MsgSwapAll { message MsgSwapAllResponse {} message MsgSetSwap { - option (gogoproto.goproto_stringer) = false; - // authority is the address of the privileged account. string authority = 1; Swap swap = 2 [(gogoproto.nullable) = false]; diff --git a/x/fswap/types/msgs.go b/x/fswap/types/msgs.go index 67d457e7a5..7ab34e7b05 100644 --- a/x/fswap/types/msgs.go +++ b/x/fswap/types/msgs.go @@ -1,8 +1,6 @@ package types import ( - "gopkg.in/yaml.v2" - sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" ) @@ -106,8 +104,3 @@ func (m *MsgSetSwap) GetSigners() []sdk.AccAddress { func (m *MsgSetSwap) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) } - -func (m *MsgSetSwap) String() string { - out, _ := yaml.Marshal(m) - return string(out) -} diff --git a/x/fswap/types/tx.pb.go b/x/fswap/types/tx.pb.go index 5e404bb037..b4a9922936 100644 --- a/x/fswap/types/tx.pb.go +++ b/x/fswap/types/tx.pb.go @@ -232,8 +232,9 @@ type MsgSetSwap struct { ToDenomMetadata types1.Metadata `protobuf:"bytes,3,opt,name=to_denom_metadata,json=toDenomMetadata,proto3" json:"to_denom_metadata" yaml:"denom_metadata"` } -func (m *MsgSetSwap) Reset() { *m = MsgSetSwap{} } -func (*MsgSetSwap) ProtoMessage() {} +func (m *MsgSetSwap) Reset() { *m = MsgSetSwap{} } +func (m *MsgSetSwap) String() string { return proto.CompactTextString(m) } +func (*MsgSetSwap) ProtoMessage() {} func (*MsgSetSwap) Descriptor() ([]byte, []int) { return fileDescriptor_65c77cf1d9b67323, []int{4} } @@ -333,40 +334,39 @@ func init() { func init() { proto.RegisterFile("lbm/fswap/v1/tx.proto", fileDescriptor_65c77cf1d9b67323) } var fileDescriptor_65c77cf1d9b67323 = []byte{ - // 513 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x3d, 0x8f, 0xda, 0x30, - 0x18, 0x26, 0x77, 0xa8, 0x14, 0x73, 0xea, 0xf5, 0xac, 0x43, 0xca, 0xa1, 0x12, 0x68, 0xa6, 0x93, - 0xda, 0xda, 0x82, 0xdb, 0x4e, 0x5d, 0xa0, 0x1f, 0xea, 0xc2, 0x92, 0x6e, 0x5d, 0x90, 0x43, 0x4c, - 0x88, 0x88, 0xe3, 0x08, 0x1b, 0x0e, 0xfe, 0x45, 0xc7, 0x8e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x12, - 0x11, 0x3c, 0x36, 0x87, 0x67, 0x22, 0x98, 0x62, 0xb9, 0x4a, 0xa9, 0xd0, 0x3f, 0x79, 0x0f, 0x94, - 0x8e, 0x3a, 0xf5, 0xb4, 0x0a, 0xbc, 0x00, 0xf7, 0x25, 0x1f, 0x06, 0x34, 0xe1, 0xcc, 0x3e, 0xd6, - 0xc6, 0x2a, 0x92, 0xbf, 0x54, 0x9f, 0xee, 0x19, 0x38, 0x35, 0x11, 0x3c, 0x2a, 0x52, 0x9e, 0x08, - 0xea, 0x46, 0x00, 0x98, 0x52, 0x2f, 0x8e, 0xff, 0x27, 0x58, 0x13, 0x00, 0x4d, 0xc9, 0x04, 0x8e, - 0x34, 0xa1, 0xaa, 0x2a, 0x5a, 0xe2, 0x6f, 0xea, 0xe7, 0x00, 0xee, 0xa5, 0x76, 0x06, 0xd6, 0x56, - 0xe6, 0x80, 0x4a, 0x3d, 0xda, 0x47, 0xa0, 0x4a, 0xe6, 0x72, 0xc2, 0x67, 0x91, 0x5c, 0x19, 0xf9, - 0x7d, 0x01, 0x3e, 0x05, 0x65, 0xb5, 0x12, 0x33, 0x49, 0x88, 0x7e, 0xbd, 0x11, 0x48, 0xfd, 0xdf, - 0x2f, 0xab, 0x11, 0x7a, 0x9a, 0x05, 0x27, 0xe0, 0x2c, 0xf7, 0x32, 0x64, 0x54, 0x92, 0x80, 0x48, - 0xa2, 0x4d, 0xd5, 0xba, 0xcd, 0xfd, 0x12, 0x92, 0xe9, 0x6e, 0x09, 0x03, 0x43, 0xea, 0x37, 0x55, - 0x97, 0x1f, 0x77, 0xad, 0xfa, 0x8a, 0xb0, 0xf8, 0xda, 0x2d, 0xb6, 0x70, 0xbd, 0x53, 0x13, 0x29, - 0xe7, 0x5f, 0x97, 0x3f, 0x7c, 0x6c, 0x95, 0xf2, 0x80, 0x59, 0x92, 0x3c, 0x60, 0xf7, 0x8b, 0x05, - 0x8e, 0x07, 0x22, 0x84, 0xcf, 0x41, 0x59, 0x27, 0xac, 0x17, 0x5d, 0x9b, 0x91, 0x34, 0x9a, 0x07, - 0xcb, 0x79, 0x17, 0xf8, 0x0a, 0x54, 0xf2, 0x25, 0xd9, 0x07, 0x99, 0xbd, 0x38, 0x6e, 0xb4, 0xff, - 0x84, 0x14, 0xda, 0x98, 0x49, 0x1f, 0x68, 0x93, 0x21, 0x87, 0xda, 0x14, 0x33, 0xf5, 0xdf, 0xac, - 0x37, 0x8e, 0x75, 0xbb, 0x71, 0xac, 0xef, 0x1b, 0xc7, 0x7a, 0xbf, 0x75, 0x4a, 0xb7, 0x5b, 0xa7, - 0xf4, 0x75, 0xeb, 0x94, 0xde, 0xa1, 0x7f, 0x5e, 0xdd, 0xa5, 0x79, 0x5f, 0xfa, 0x0a, 0xfb, 0xf7, - 0xf4, 0xeb, 0xba, 0xfa, 0x19, 0x00, 0x00, 0xff, 0xff, 0x28, 0x4e, 0x64, 0x95, 0xf4, 0x03, 0x00, - 0x00, + // 506 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xcb, 0x8e, 0xda, 0x30, + 0x14, 0xc5, 0x33, 0xa8, 0x14, 0x33, 0xea, 0x74, 0xac, 0x41, 0x62, 0x50, 0x09, 0x34, 0xab, 0x91, + 0xda, 0xda, 0x82, 0xd9, 0x55, 0xdd, 0x40, 0x1f, 0xea, 0x86, 0x4d, 0xba, 0xeb, 0x06, 0x39, 0xc4, + 0x84, 0x88, 0x38, 0x8e, 0xb0, 0x61, 0xe0, 0x2f, 0xfa, 0x1d, 0xfd, 0x8b, 0x76, 0x35, 0xcb, 0xe9, + 0xae, 0xab, 0x69, 0x05, 0x7f, 0xd0, 0x2f, 0xa8, 0xec, 0x38, 0xd0, 0xa8, 0xf4, 0xb1, 0x73, 0xee, + 0x39, 0xb9, 0xe7, 0x9c, 0x7b, 0x6d, 0x58, 0x8f, 0x7d, 0x4e, 0x26, 0xf2, 0x9a, 0xa6, 0x64, 0xd9, + 0x25, 0x6a, 0x85, 0xd3, 0xb9, 0x50, 0x02, 0x9d, 0xc4, 0x3e, 0xc7, 0xa6, 0x8c, 0x97, 0xdd, 0xe6, + 0x79, 0x28, 0x42, 0x61, 0x00, 0xa2, 0x4f, 0x19, 0xa7, 0xe9, 0x8c, 0x85, 0xe4, 0x42, 0x12, 0x9f, + 0x4a, 0x46, 0x96, 0x5d, 0x9f, 0x29, 0xda, 0x25, 0x63, 0x11, 0x25, 0xbf, 0xe1, 0xc9, 0x6c, 0x87, + 0xeb, 0x0f, 0x8b, 0x37, 0x0a, 0xd2, 0x99, 0x98, 0x41, 0xdc, 0x4f, 0x00, 0x56, 0x86, 0x32, 0x7c, + 0x77, 0x4d, 0x53, 0xf4, 0x18, 0x9e, 0x4c, 0xe6, 0x82, 0x8f, 0x68, 0x10, 0xcc, 0x99, 0x94, 0x0d, + 0xd0, 0x01, 0x97, 0x55, 0xaf, 0xa6, 0x6b, 0xfd, 0xac, 0x84, 0x56, 0xf0, 0xa1, 0xa1, 0x68, 0xed, + 0x11, 0xe5, 0x62, 0x91, 0xa8, 0xc6, 0x51, 0x07, 0x5c, 0xd6, 0x7a, 0x17, 0x38, 0xf3, 0x80, 0xb5, + 0x47, 0x6c, 0x3d, 0xe0, 0x97, 0x22, 0x4a, 0x06, 0x57, 0x37, 0x77, 0xed, 0xd2, 0xc7, 0x6f, 0xed, + 0x27, 0x61, 0xa4, 0xa6, 0x0b, 0x1f, 0x8f, 0x05, 0x27, 0x6f, 0xa2, 0x44, 0x8e, 0xa7, 0x11, 0x25, + 0x13, 0x7b, 0x78, 0x26, 0x83, 0x19, 0x51, 0xeb, 0x94, 0x49, 0xf3, 0x93, 0xf7, 0x40, 0xeb, 0xe8, + 0x53, 0xdf, 0xa8, 0xa0, 0x0b, 0x78, 0x5f, 0x89, 0x51, 0xc0, 0x12, 0xc1, 0x1b, 0xc7, 0xc6, 0x58, + 0x45, 0x89, 0x57, 0xfa, 0x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, 0x70, 0xbb, 0x71, 0xc0, 0xf7, + 0x8d, 0x03, 0x3e, 0x6c, 0x9d, 0xd2, 0xed, 0xd6, 0x29, 0x7d, 0xdd, 0x3a, 0xa5, 0xf7, 0xf8, 0x9f, + 0x97, 0x76, 0x65, 0x5f, 0x96, 0xb9, 0xbc, 0xfe, 0x3d, 0xf3, 0xae, 0xae, 0x7e, 0x06, 0x00, 0x00, + 0xff, 0xff, 0xc9, 0xd9, 0x78, 0xc1, 0xee, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. From ecf1345d4623d3733a373654529949b24311ad0c Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 9 May 2024 17:53:36 +0900 Subject: [PATCH 5/9] chore: remove unused proto annotations --- proto/lbm/fswap/v1/fswap.proto | 7 -- x/fswap/types/fswap.go | 18 +---- x/fswap/types/fswap.pb.go | 126 +++++++++------------------------ 3 files changed, 36 insertions(+), 115 deletions(-) diff --git a/proto/lbm/fswap/v1/fswap.proto b/proto/lbm/fswap/v1/fswap.proto index 4d9e208319..5bb9331bbc 100644 --- a/proto/lbm/fswap/v1/fswap.proto +++ b/proto/lbm/fswap/v1/fswap.proto @@ -7,9 +7,6 @@ import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; message Swap { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = false; - string from_denom = 1; string to_denom = 2; string amount_cap_for_to_denom = 3 @@ -19,14 +16,10 @@ message Swap { } message SwapStats { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = false; - int32 swap_count = 1; } message Swapped { - option (gogoproto.goproto_stringer) = false; cosmos.base.v1beta1.Coin from_coin_amount = 1 [(gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin", (gogoproto.nullable) = false]; cosmos.base.v1beta1.Coin to_coin_amount = 2 diff --git a/x/fswap/types/fswap.go b/x/fswap/types/fswap.go index 743fd1071d..7cb476435b 100644 --- a/x/fswap/types/fswap.go +++ b/x/fswap/types/fswap.go @@ -1,8 +1,6 @@ package types import ( - "gopkg.in/yaml.v2" - sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" ) @@ -27,11 +25,7 @@ func (s *Swap) ValidateBasic() error { return nil } -func (s *Swap) String() string { - out, _ := yaml.Marshal(s) - return string(out) -} - +// ValidateBasic validates the set of SwapStats func (s *SwapStats) ValidateBasic() error { if s.SwapCount < 0 { return ErrInvalidState.Wrap("swap count cannot be negative") @@ -39,11 +33,6 @@ func (s *SwapStats) ValidateBasic() error { return nil } -func (s *SwapStats) String() string { - out, _ := yaml.Marshal(s) - return string(out) -} - // ValidateBasic validates the set of Swapped func (s *Swapped) ValidateBasic() error { if err := validateCoinAmount(s.FromCoinAmount); err != nil { @@ -68,8 +57,3 @@ func validateCoinAmount(i interface{}) error { } return nil } - -func (s *Swapped) String() string { - out, _ := yaml.Marshal(s) - return string(out) -} diff --git a/x/fswap/types/fswap.pb.go b/x/fswap/types/fswap.pb.go index 7290087bf1..55bca47046 100644 --- a/x/fswap/types/fswap.pb.go +++ b/x/fswap/types/fswap.pb.go @@ -32,8 +32,9 @@ type Swap struct { SwapRate github_com_Finschia_finschia_sdk_types.Dec `protobuf:"bytes,4,opt,name=swap_rate,json=swapRate,proto3,customtype=github.com/Finschia/finschia-sdk/types.Dec" json:"swap_rate"` } -func (m *Swap) Reset() { *m = Swap{} } -func (*Swap) ProtoMessage() {} +func (m *Swap) Reset() { *m = Swap{} } +func (m *Swap) String() string { return proto.CompactTextString(m) } +func (*Swap) ProtoMessage() {} func (*Swap) Descriptor() ([]byte, []int) { return fileDescriptor_42ca60eaf37a2b67, []int{0} } @@ -82,8 +83,9 @@ type SwapStats struct { SwapCount int32 `protobuf:"varint,1,opt,name=swap_count,json=swapCount,proto3" json:"swap_count,omitempty"` } -func (m *SwapStats) Reset() { *m = SwapStats{} } -func (*SwapStats) ProtoMessage() {} +func (m *SwapStats) Reset() { *m = SwapStats{} } +func (m *SwapStats) String() string { return proto.CompactTextString(m) } +func (*SwapStats) ProtoMessage() {} func (*SwapStats) Descriptor() ([]byte, []int) { return fileDescriptor_42ca60eaf37a2b67, []int{1} } @@ -126,8 +128,9 @@ type Swapped struct { ToCoinAmount types.Coin `protobuf:"bytes,2,opt,name=to_coin_amount,json=toCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"to_coin_amount"` } -func (m *Swapped) Reset() { *m = Swapped{} } -func (*Swapped) ProtoMessage() {} +func (m *Swapped) Reset() { *m = Swapped{} } +func (m *Swapped) String() string { return proto.CompactTextString(m) } +func (*Swapped) ProtoMessage() {} func (*Swapped) Descriptor() ([]byte, []int) { return fileDescriptor_42ca60eaf37a2b67, []int{2} } @@ -181,93 +184,34 @@ func init() { func init() { proto.RegisterFile("lbm/fswap/v1/fswap.proto", fileDescriptor_42ca60eaf37a2b67) } var fileDescriptor_42ca60eaf37a2b67 = []byte{ - // 417 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x92, 0xbd, 0x8e, 0xd3, 0x40, - 0x10, 0xc7, 0xed, 0x10, 0xb8, 0x78, 0x39, 0x9d, 0x90, 0x41, 0x22, 0x77, 0x12, 0x36, 0x4a, 0x85, - 0x40, 0xec, 0xca, 0x09, 0x55, 0x3a, 0x92, 0x28, 0x82, 0x0a, 0xc9, 0xa1, 0xa2, 0xb1, 0xd6, 0xce, - 0x3a, 0xb1, 0x88, 0x3d, 0x96, 0x77, 0xf3, 0xc1, 0x03, 0xd0, 0x53, 0x52, 0xa6, 0xe6, 0x49, 0x52, - 0xa6, 0x44, 0x14, 0x01, 0x25, 0x0d, 0x6f, 0x01, 0x9a, 0x5d, 0x8b, 0x8f, 0x0a, 0x84, 0x44, 0x37, - 0x9a, 0xff, 0xcc, 0xfc, 0x66, 0xff, 0xb3, 0xa4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, 0x6e, - 0x7d, 0xbb, 0xf3, 0x84, 0x38, 0x68, 0xc3, 0x44, 0x71, 0x25, 0xd1, 0x0b, 0xcd, 0x49, 0x70, 0x05, - 0xed, 0xc5, 0xf5, 0x50, 0x93, 0x87, 0x98, 0xf8, 0xa5, 0xeb, 0x9b, 0x4d, 0xce, 0xb0, 0xad, 0x14, - 0x53, 0x77, 0x43, 0x6e, 0x69, 0x03, 0xd1, 0xdc, 0xc8, 0x6c, 0xaf, 0x5b, 0x6f, 0x76, 0x2f, 0xa9, - 0x39, 0x02, 0xc5, 0x23, 0xd0, 0xfa, 0x08, 0x74, 0x08, 0x59, 0x31, 0xe8, 0xe1, 0xfa, 0x1f, 0x3e, - 0xfb, 0x8f, 0xfe, 0x72, 0x7d, 0x6c, 0x0a, 0x2f, 0x90, 0x83, 0xd1, 0x53, 0x4d, 0x71, 0x15, 0xb9, - 0x50, 0xf0, 0x1b, 0xb7, 0xf1, 0x5f, 0xb8, 0xe7, 0x0a, 0x7e, 0x52, 0xfb, 0x4d, 0x74, 0x61, 0xf0, - 0x6c, 0x77, 0xf4, 0xec, 0xfd, 0xd1, 0xb3, 0xbf, 0x1c, 0x3d, 0xfb, 0xdd, 0xc9, 0xb3, 0xf6, 0x27, - 0xcf, 0xfa, 0x78, 0xf2, 0xac, 0x57, 0xf4, 0x8f, 0xa3, 0x37, 0xf5, 0xb7, 0xd6, 0x88, 0xf8, 0x86, - 0xfe, 0x90, 0xbd, 0xef, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe9, 0xf1, 0xe6, 0x57, 0xf0, 0x02, 0x00, - 0x00, -} - -func (this *Swap) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Swap) - if !ok { - that2, ok := that.(Swap) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.FromDenom != that1.FromDenom { - return false - } - if this.ToDenom != that1.ToDenom { - return false - } - if !this.AmountCapForToDenom.Equal(that1.AmountCapForToDenom) { - return false - } - if !this.SwapRate.Equal(that1.SwapRate) { - return false - } - return true + // 397 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x92, 0xcf, 0xae, 0xd2, 0x40, + 0x14, 0xc6, 0x5b, 0x44, 0xa1, 0x23, 0x21, 0xa6, 0x9a, 0x08, 0x24, 0x16, 0xc3, 0xca, 0x60, 0x9c, + 0x49, 0xe1, 0x09, 0x04, 0x42, 0x74, 0x65, 0x52, 0x5c, 0xb9, 0x69, 0xa6, 0x65, 0x0a, 0x8d, 0xb4, + 0xa7, 0xe9, 0x0c, 0x7f, 0x7c, 0x0b, 0x9f, 0xc3, 0x27, 0x61, 0xc9, 0xd2, 0xb8, 0x40, 0x03, 0x4f, + 0x61, 0xdc, 0x98, 0x33, 0xd3, 0x68, 0x5c, 0x79, 0x73, 0x93, 0xbb, 0x3b, 0x39, 0xdf, 0x99, 0xef, + 0x77, 0xe6, 0xcb, 0x21, 0x9d, 0x4d, 0x94, 0xb1, 0x44, 0xee, 0x79, 0xc1, 0x76, 0xbe, 0x29, 0x68, + 0x51, 0x82, 0x02, 0xb7, 0xb5, 0x89, 0x32, 0x6a, 0x1a, 0x3b, 0xbf, 0xf7, 0x64, 0x05, 0x2b, 0xd0, + 0x02, 0xc3, 0xca, 0xcc, 0xf4, 0xbc, 0x18, 0x64, 0x06, 0x92, 0x45, 0x5c, 0x0a, 0xb6, 0xf3, 0x23, + 0xa1, 0xb8, 0xcf, 0x62, 0x48, 0x73, 0xa3, 0x0f, 0x7e, 0xd9, 0xa4, 0xbe, 0xd8, 0xf3, 0xc2, 0x7d, + 0x46, 0x48, 0x52, 0x42, 0x16, 0x2e, 0x45, 0x0e, 0x59, 0xc7, 0x7e, 0x6e, 0xbf, 0x70, 0x02, 0x07, + 0x3b, 0x33, 0x6c, 0xb8, 0x5d, 0xd2, 0x54, 0x50, 0x89, 0x35, 0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 0xb3, + 0x4f, 0x17, 0xcf, 0xfe, 0x71, 0xf1, 0xec, 0xcf, 0x57, 0xcf, 0x3a, 0x5d, 0x3d, 0xeb, 0xeb, 0xd5, + 0xb3, 0x3e, 0xd0, 0xff, 0x9a, 0x1e, 0xaa, 0xe3, 0xd5, 0xe6, 0xd1, 0x03, 0x7d, 0x76, 0xe3, 0xdf, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x53, 0x35, 0xf1, 0x71, 0xd6, 0x02, 0x00, 0x00, } -func (this *SwapStats) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - that1, ok := that.(*SwapStats) - if !ok { - that2, ok := that.(SwapStats) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.SwapCount != that1.SwapCount { - return false - } - return true -} func (m *Swap) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) From 3a5af2b9c4c2cb0bb9c8af584d963b8f76acc00f Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 9 May 2024 17:57:55 +0900 Subject: [PATCH 6/9] chore: allow gov and foundation as authority address --- x/fswap/keeper/keeper.go | 12 ++++++++++++ x/fswap/types/genesis.go | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/x/fswap/keeper/keeper.go b/x/fswap/keeper/keeper.go index 0f21acd3f5..e38fd7282f 100644 --- a/x/fswap/keeper/keeper.go +++ b/x/fswap/keeper/keeper.go @@ -32,6 +32,18 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, config types panic("x/foundation authority must be the module account") } + found := false + for _, addr := range types.AuthorityCandidates() { + if authority == addr.String() { + found = true + break + } + } + + if !found { + panic("x/fswap authority must be ether gov or foundation module account") + } + return Keeper{ cdc, storeKey, diff --git a/x/fswap/types/genesis.go b/x/fswap/types/genesis.go index 2c83fa506f..e12f0dfdf8 100644 --- a/x/fswap/types/genesis.go +++ b/x/fswap/types/genesis.go @@ -4,6 +4,7 @@ import ( sdk "github.com/Finschia/finschia-sdk/types" authtypes "github.com/Finschia/finschia-sdk/x/auth/types" "github.com/Finschia/finschia-sdk/x/foundation" + govtypes "github.com/Finschia/finschia-sdk/x/gov/types" ) // DefaultGenesis returns the default Capability genesis state @@ -19,6 +20,13 @@ func DefaultAuthority() sdk.AccAddress { return authtypes.NewModuleAddress(foundation.ModuleName) } +func AuthorityCandidates() []sdk.AccAddress { + return []sdk.AccAddress{ + authtypes.NewModuleAddress(govtypes.ModuleName), + authtypes.NewModuleAddress(foundation.ModuleName), + } +} + // Validate performs basic genesis state validation returning an error upon any failure. func (gs *GenesisState) Validate() error { for _, swap := range gs.GetSwaps() { From 02f1a9f6e2e1b6015fa77babab9d97125e8ff76e Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 9 May 2024 19:50:58 +0900 Subject: [PATCH 7/9] chore: lint fix --- x/fswap/types/msgs.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x/fswap/types/msgs.go b/x/fswap/types/msgs.go index 346e7a5bca..936aa1cdb4 100644 --- a/x/fswap/types/msgs.go +++ b/x/fswap/types/msgs.go @@ -5,9 +5,11 @@ import ( sdkerrors "github.com/Finschia/finschia-sdk/types/errors" ) -var _ sdk.Msg = &MsgSwap{} -var _ sdk.Msg = &MsgSwapAll{} -var _ sdk.Msg = &MsgSetSwap{} +var ( + _ sdk.Msg = &MsgSwap{} + _ sdk.Msg = &MsgSwapAll{} + _ sdk.Msg = &MsgSetSwap{} +) // ValidateBasic Implements Msg. func (m *MsgSwap) ValidateBasic() error { From 9965ed39baaa22c713de378dda71cd5ccc157e81 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 9 May 2024 19:51:08 +0900 Subject: [PATCH 8/9] chore: remove redundant part --- x/fswap/keeper/keeper.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/fswap/keeper/keeper.go b/x/fswap/keeper/keeper.go index e38fd7282f..6b153150a1 100644 --- a/x/fswap/keeper/keeper.go +++ b/x/fswap/keeper/keeper.go @@ -27,11 +27,6 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, config types panic("authority is not a valid acc address") } - // authority is x/foundation module account for now. - if authority != types.DefaultAuthority().String() { - panic("x/foundation authority must be the module account") - } - found := false for _, addr := range types.AuthorityCandidates() { if authority == addr.String() { From 837cf59fd71af3ab292ec8720776b314c4dd99f5 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 9 May 2024 20:11:49 +0900 Subject: [PATCH 9/9] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 400e0e5534..04ff53deb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/fswap) [\#1363](https://github.com/Finschia/finschia-sdk/pull/1363) introduce new event for MakeSwapProposal * (x/fbridge) [\#1366](https://github.com/Finschia/finschia-sdk/pull/1366) Set target denom as module parameters * (x/fbridge) [\#1369](https://github.com/Finschia/finschia-sdk/pull/1369) Add the event of `SetBridgeStatus` +* (x/fswap) [\#1372](https://github.com/Finschia/finschia-sdk/pull/1372) support message based proposals ### Bug Fixes * chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue