diff --git a/CHANGELOG.md b/CHANGELOG.md index d83d4ec64e..601ae4e5d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,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 * (x/auth) [#1281](https://github.com/Finschia/finschia-sdk/pull/1281) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. (backport #1274) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 9cbd5f6d61..289208be3d 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -978,7 +978,6 @@ - [Msg](#lbm.foundation.v1.Msg) - [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) @@ -1002,6 +1001,8 @@ - [Query](#lbm.fswap.v1.Query) - [lbm/fswap/v1/tx.proto](#lbm/fswap/v1/tx.proto) + - [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) @@ -14555,24 +14556,6 @@ 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) | | | - - - - - - ### Swap @@ -14856,6 +14839,33 @@ GenesisState defines the fswap module's genesis state. + + +### MsgSetSwap + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `authority` | [string](#string) | | authority is the address of the privileged account. | +| `swap` | [Swap](#lbm.fswap.v1.Swap) | | | +| `to_denom_metadata` | [cosmos.bank.v1beta1.Metadata](#cosmos.bank.v1beta1.Metadata) | | | + + + + + + + + +### MsgSetSwapResponse + + + + + + + ### MsgSwap @@ -14925,6 +14935,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) | | | +| `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 13a5c2a006..5bb9331bbc 100644 --- a/proto/lbm/fswap/v1/fswap.proto +++ b/proto/lbm/fswap/v1/fswap.proto @@ -5,12 +5,8 @@ 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; - option (gogoproto.goproto_stringer) = false; - string from_denom = 1; string to_denom = 2; string amount_cap_for_to_denom = 3 @@ -20,25 +16,10 @@ message Swap { } message SwapStats { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = false; - 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 - [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false]; -} - 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/proto/lbm/fswap/v1/tx.proto b/proto/lbm/fswap/v1/tx.proto index 07813f9eab..eb6154dd81 100644 --- a/proto/lbm/fswap/v1/tx.proto +++ b/proto/lbm/fswap/v1/tx.proto @@ -5,10 +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 SetSwap(MsgSetSwap) returns (MsgSetSwapResponse); } message MsgSwap { @@ -30,3 +33,13 @@ message MsgSwapAll { } message MsgSwapAllResponse {} + +message MsgSetSwap { + // authority is the address of the privileged account. + 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 MsgSetSwapResponse {} diff --git a/simapp/app.go b/simapp/app.go index 4f615af767..f7500fb8fc 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -78,7 +78,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" @@ -139,7 +138,6 @@ var ( upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler, foundationclient.ProposalHandler, - fswapclient.ProposalHandler, ), params.AppModuleBasic{}, crisis.AppModuleBasic{}, @@ -349,7 +347,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() @@ -357,8 +355,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..61cd359d75 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(), + CmdMsgSetSwap(), ) 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 { +// CmdMsgSetSwap implements a command handler for submitting a swap init proposal transaction. +func CmdMsgSetSwap() *cobra.Command { cmd := &cobra.Command{ - Use: "make-swap [messages-json]", - Args: cobra.ExactArgs(1), - Short: "todo", + Use: "set-swap [authority] [metadata-json]", + Args: cobra.ExactArgs(2), + Short: "Set a swap", 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,42 @@ 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.MsgSetSwap{ + Authority: authority, + 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") + 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 } +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 deleted file mode 100644 index 7cbd4f6a69..0000000000 --- a/x/fswap/codec/codec.go +++ /dev/null @@ -1,18 +0,0 @@ -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 6f88495b02..4ea9298703 100644 --- a/x/fswap/keeper/keeper.go +++ b/x/fswap/keeper/keeper.go @@ -9,23 +9,41 @@ 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" + bank "github.com/Finschia/finschia-sdk/x/bank/types" "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") + } + + 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, config, + authority, bk, } } @@ -82,6 +100,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 { @@ -201,3 +276,108 @@ 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 +} + +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 1f3086fc4f..9f948f1ebf 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) 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.SetSwap(c, req.GetSwap(), req.GetToDenomMetadata()); err != nil { + return nil, err + } + + return &types.MsgSetSwapResponse{}, nil +} 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_test.go b/x/fswap/keeper/proposal_test.go deleted file mode 100644 index 65be82d923..0000000000 --- a/x/fswap/keeper/proposal_test.go +++ /dev/null @@ -1,167 +0,0 @@ -package keeper_test - -import ( - abci "github.com/tendermint/tendermint/abci/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" -) - -func (s *KeeperTestSuite) TestMakeSwapProposal() { - testCases := map[string]struct { - swap types.Swap - toDenomMeta bank.Metadata - existingMetadata bool - expectedError error - expectedEvents sdk.Events - }{ - "valid": { - types.Swap{ - FromDenom: "fromD", - ToDenom: "toD", - AmountCapForToDenom: sdk.OneInt(), - SwapRate: sdk.OneDec(), - }, - s.toDenomMetadata, - false, - nil, - sdk.Events{ - sdk.Event{ - Type: "lbm.fswap.v1.EventMakeSwap", - Attributes: []abci.EventAttribute{ - { - Key: []byte("swap"), - Value: []uint8{0x7b, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x44, 0x22, 0x2c, 0x22, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x44, 0x22, 0x2c, 0x22, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x63, 0x61, 0x70, 0x5f, 0x66, 0x6f, 0x72, 0x5f, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x31, 0x22, 0x2c, 0x22, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x22, 0x31, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22, 0x7d}, - Index: false, - }, - }, - }, - sdk.Event{ - Type: "lbm.fswap.v1.EventAddDenomMetadata", - Attributes: []abci.EventAttribute{ - { - Key: []byte("metadata"), - Value: []uint8{0x7b, 0x22, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x2d, 0x63, 0x6f, 0x69, 0x6e, 0x22, 0x2c, 0x22, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x5d, 0x2c, 0x22, 0x62, 0x61, 0x73, 0x65, 0x22, 0x3a, 0x22, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x22, 0x2c, 0x22, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x22, 0x3a, 0x22, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x63, 0x6f, 0x69, 0x6e, 0x22, 0x2c, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x22, 0x44, 0x55, 0x4d, 0x4d, 0x59, 0x22, 0x2c, 0x22, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x22, 0x3a, 0x22, 0x44, 0x55, 0x4d, 0x22, 0x7d}, - Index: false, - }, - }, - }, - }, - }, - "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, - sdk.Events{}, - }, - } - 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) - return - } - - s.Require().ErrorIs(err, tc.expectedError) - events := ctx.EventManager().Events() - s.Require().Equal(tc.expectedEvents, events) - }) - } -} - -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/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..77c591743d 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, &MsgSetSwap{}, "lbm-sdk/MsgSetSwap") } func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSwap{}, &MsgSwapAll{}, + &MsgSetSwap{}, ) 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 f45d2b2d89..85d73dc0c7 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" ) @@ -32,11 +30,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") @@ -44,11 +38,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 { @@ -73,9 +62,3 @@ func validateCoinAmount(i interface{}) error { } return nil } - -// String implements the Stringer interface. -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 4449b20bec..55bca47046 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" @@ -33,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} } @@ -83,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} } @@ -122,83 +123,16 @@ 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"` -} - -func (m *MakeSwapProposal) Reset() { *m = MakeSwapProposal{} } -func (*MakeSwapProposal) ProtoMessage() {} -func (*MakeSwapProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_42ca60eaf37a2b67, []int{2} -} -func (m *MakeSwapProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MakeSwapProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MakeSwapProposal.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 *MakeSwapProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_MakeSwapProposal.Merge(m, src) -} -func (m *MakeSwapProposal) XXX_Size() int { - return m.Size() -} -func (m *MakeSwapProposal) XXX_DiscardUnknown() { - xxx_messageInfo_MakeSwapProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_MakeSwapProposal 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 { - if m != nil { - return m.Swap - } - return Swap{} -} - -func (m *MakeSwapProposal) 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 (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{3} + return fileDescriptor_42ca60eaf37a2b67, []int{2} } func (m *Swapped) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -227,124 +161,57 @@ 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((*MakeSwapProposal)(nil), "lbm.fswap.v1.MakeSwapProposal") 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,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0x6e, 0x95, 0xbe, 0xcc, 0xad, 0xd2, 0x7b, - 0xe7, 0x8f, 0xa3, 0x4f, 0x8b, 0x1f, 0xae, 0x10, 0xc1, 0x5d, 0xf5, 0xf7, 0xf6, 0x7e, 0x05, 0x00, - 0x00, 0xff, 0xff, 0x9d, 0x2f, 0x11, 0xda, 0xfb, 0x03, 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, 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c, 0xb4, 0x49, 0x03, 0x87, 0x0b, + 0xb1, 0x74, 0x0f, 0xe4, 0x91, 0x0e, 0x0b, 0x83, 0x0c, 0xcd, 0xa6, 0xfa, 0xc1, 0xc3, 0x51, 0x97, + 0x9a, 0xc0, 0x29, 0x06, 0x4e, 0xab, 0xc0, 0xe9, 0x14, 0xd2, 0x7c, 0x32, 0xc6, 0x55, 0xbf, 0x7c, + 0xef, 0xbf, 0xbc, 0xe1, 0xaa, 0xf8, 0x28, 0x68, 0x23, 0x07, 0xab, 0xd7, 0x9a, 0xe2, 0x2a, 0xd2, + 0x56, 0xf0, 0x0f, 0xb7, 0x76, 0x27, 0xdc, 0x96, 0x82, 0xbf, 0xd4, 0xc9, 0x9b, 0xe3, 0xc5, 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) @@ -430,63 +297,6 @@ func (m *SwapStats) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MakeSwapProposal) 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 *MakeSwapProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MakeSwapProposal) 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] = 0x22 - { - size, err := m.Swap.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - 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 - } - return len(dAtA) - i, nil -} - func (m *Swapped) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -574,27 +384,6 @@ func (m *SwapStats) Size() (n int) { return n } -func (m *MakeSwapProposal) 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() - n += 1 + l + sovFswap(uint64(l)) - return n -} - func (m *Swapped) Size() (n int) { if m == nil { return 0 @@ -865,186 +654,6 @@ func (m *SwapStats) Unmarshal(dAtA []byte) error { } return nil } -func (m *MakeSwapProposal) 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: MakeSwapProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MakeSwapProposal: 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) - } - 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 4: - 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/genesis.go b/x/fswap/types/genesis.go index 08c1d79338..e12f0dfdf8 100644 --- a/x/fswap/types/genesis.go +++ b/x/fswap/types/genesis.go @@ -1,5 +1,12 @@ 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" + govtypes "github.com/Finschia/finschia-sdk/x/gov/types" +) + // DefaultGenesis returns the default Capability genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ @@ -9,6 +16,17 @@ func DefaultGenesis() *GenesisState { } } +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() { diff --git a/x/fswap/types/msgs.go b/x/fswap/types/msgs.go index f94e123cae..936aa1cdb4 100644 --- a/x/fswap/types/msgs.go +++ b/x/fswap/types/msgs.go @@ -3,10 +3,13 @@ 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 = &MsgSwap{} + _ sdk.Msg = &MsgSwapAll{} + _ sdk.Msg = &MsgSetSwap{} +) // ValidateBasic Implements Msg. func (m *MsgSwap) ValidateBasic() error { @@ -41,11 +44,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 +76,33 @@ 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 *MsgSetSwap) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", m.Authority) + } + + 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 *MsgSetSwap) GetSigners() []sdk.AccAddress { + signer := sdk.MustAccAddressFromBech32(m.Authority) + return []sdk.AccAddress{signer} +} + +// GetSignBytes implements the LegacyMsg.GetSignBytes method. +func (m *MsgSetSwap) 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..b4a9922936 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,42 +225,148 @@ func (m *MsgSwapAllResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSwapAllResponse proto.InternalMessageInfo +type MsgSetSwap struct { + // authority is the address of the privileged account. + 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 *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} +} +func (m *MsgSetSwap) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSetSwap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSetSwap.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 *MsgSetSwap) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetSwap.Merge(m, src) +} +func (m *MsgSetSwap) XXX_Size() int { + return m.Size() +} +func (m *MsgSetSwap) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetSwap.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSetSwap proto.InternalMessageInfo + +func (m *MsgSetSwap) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgSetSwap) GetSwap() Swap { + if m != nil { + return m.Swap + } + return Swap{} +} + +func (m *MsgSetSwap) GetToDenomMetadata() types1.Metadata { + if m != nil { + return m.ToDenomMetadata + } + return types1.Metadata{} +} + +type MsgSetSwapResponse struct { +} + +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 *MsgSetSwapResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSetSwapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSetSwapResponse.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 *MsgSetSwapResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetSwapResponse.Merge(m, src) +} +func (m *MsgSetSwapResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSetSwapResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetSwapResponse.DiscardUnknown(m) +} + +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((*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{ - // 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, 0x9d, - 0xdf, 0x8c, 0x67, 0x70, 0x33, 0x72, 0x62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, 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, + // 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, 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x7a, 0x0d, 0x2b, 0xf9, + 0x7a, 0x1a, 0x07, 0x99, 0xfd, 0x38, 0x6e, 0x76, 0xfe, 0x84, 0x14, 0xda, 0xd8, 0x19, 0x1f, 0x68, + 0x93, 0x21, 0x87, 0xda, 0x14, 0x33, 0x0d, 0xde, 0xde, 0x6c, 0x1c, 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. @@ -276,6 +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) + SetSwap(ctx context.Context, in *MsgSetSwap, opts ...grpc.CallOption) (*MsgSetSwapResponse, error) } type msgClient struct { @@ -304,10 +412,20 @@ func (c *msgClient) SwapAll(ctx context.Context, in *MsgSwapAll, opts ...grpc.Ca return out, nil } +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 + } + 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) + SetSwap(context.Context, *MsgSetSwap) (*MsgSetSwapResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -320,6 +438,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) 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) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -361,6 +482,24 @@ func _Msg_SwapAll_Handler(srv interface{}, ctx context.Context, dec func(interfa return interceptor(ctx, in, info, handler) } +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).SetSwap(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lbm.fswap.v1.Msg/SetSwap", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SetSwap(ctx, req.(*MsgSetSwap)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "lbm.fswap.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -373,6 +512,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "SwapAll", Handler: _Msg_SwapAll_Handler, }, + { + MethodName: "SetSwap", + Handler: _Msg_SetSwap_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "lbm/fswap/v1/tx.proto", @@ -515,6 +658,79 @@ func (m *MsgSwapAllResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgSetSwap) 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 *MsgSetSwap) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSetSwap) 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 = 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) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgSetSwapResponse) 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 *MsgSetSwapResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSetSwapResponse) 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 +800,32 @@ func (m *MsgSwapAllResponse) Size() (n int) { return n } +func (m *MsgSetSwap) 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)) + } + l = m.Swap.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.ToDenomMetadata.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgSetSwapResponse) 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 +1225,204 @@ func (m *MsgSwapAllResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgSetSwap) 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: MsgSetSwap: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetSwap: 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 Swap", 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.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.ToDenomMetadata.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 *MsgSetSwapResponse) 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: MsgSetSwapResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetSwapResponse: 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