From 95ac8307a4fef60c1c38b5797e7aa40ed6ad6776 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 15:55:29 +0900 Subject: [PATCH] feat: add new query to get a swap (backport #1387) (#1389) * feat: add new query to get a swap (#1387) * feat: add new query to get a swap * chore: update changelog * fix: add missing pagination param in cli client * chore: lint fix * chore: add grpc-query test * chore: add descriptive message for invalid QuerySwapRequest * chore: add CLI to query swap (cherry picked from commit 92ad6753032179c706fd525cc6d1444ccd9b9579) # Conflicts: # client/docs/swagger-ui/swagger.yaml * chore: fix conflict --------- Co-authored-by: jaeseung-bae <119839167+jaeseung-bae@users.noreply.github.com> --- CHANGELOG.md | 1 + client/docs/config.json | 3 + client/docs/swagger-ui/swagger.yaml | 432 +++++++++++++++++ docs/core/proto-docs.md | 34 ++ proto/lbm/fswap/v1/query.proto | 12 + x/fswap/client/cli/query.go | 43 +- x/fswap/keeper/grpc_query.go | 17 + x/fswap/keeper/grpc_query_test.go | 121 +++++ x/fswap/testutil/expected_keepers_mocks.go | 25 +- x/fswap/types/msgs.go | 20 + x/fswap/types/msgs_test.go | 52 +++ x/fswap/types/query.pb.go | 514 +++++++++++++++++++-- x/fswap/types/query.pb.gw.go | 80 ++++ 13 files changed, 1299 insertions(+), 55 deletions(-) create mode 100644 x/fswap/keeper/grpc_query_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 86218264bd..3f7d6bc0d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (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 +* (x/fswap) [\#1387](https://github.com/Finschia/finschia-sdk/pull/1387) add new Swap query to get a single swap ### 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/client/docs/config.json b/client/docs/config.json index 97cd452052..ee02885ceb 100644 --- a/client/docs/config.json +++ b/client/docs/config.json @@ -205,6 +205,9 @@ "Vote": "FBridgeVote" } } + }, + { + "url": "./tmp-swagger-gen/lbm/fswap/v1/query.swagger.json" } ] } diff --git a/client/docs/swagger-ui/swagger.yaml b/client/docs/swagger-ui/swagger.yaml index 1a91dd4742..571b868dbd 100644 --- a/client/docs/swagger-ui/swagger.yaml +++ b/client/docs/swagger-ui/swagger.yaml @@ -35312,6 +35312,330 @@ paths: format: byte tags: - Query + /lbm/fswap/v1/swap: + get: + summary: Swap queries a swap + operationId: Swap + responses: + '200': + description: A successful response. + schema: + type: object + properties: + swap: + type: object + properties: + from_denom: + type: string + to_denom: + type: string + amount_cap_for_to_denom: + type: string + swap_rate: + type: string + default: + description: An unexpected error response + schema: + type: object + properties: + error: + type: string + code: + type: integer + format: int32 + message: + type: string + details: + type: array + items: + type: object + properties: + type_url: + type: string + value: + type: string + format: byte + parameters: + - name: fromDenom + in: query + required: false + type: string + - name: toDenom + in: query + required: false + type: string + tags: + - Query + /lbm/fswap/v1/swapped: + get: + summary: >- + Swapped queries the current swapped status that includes a burnt amount + of from-coin and a minted amount of + + to-coin. + operationId: Swapped + responses: + '200': + description: A successful response. + schema: + type: object + properties: + from_coin_amount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. + to_coin_amount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. + default: + description: An unexpected error response + schema: + type: object + properties: + error: + type: string + code: + type: integer + format: int32 + message: + type: string + details: + type: array + items: + type: object + properties: + type_url: + type: string + value: + type: string + format: byte + parameters: + - name: fromDenom + in: query + required: false + type: string + - name: toDenom + in: query + required: false + type: string + tags: + - Query + /lbm/fswap/v1/swaps: + get: + summary: Swaps queries all the swap that registered + operationId: Swaps + responses: + '200': + description: A successful response. + schema: + type: object + properties: + swaps: + type: array + items: + type: object + properties: + from_denom: + type: string + to_denom: + type: string + amount_cap_for_to_denom: + type: string + swap_rate: + type: string + pagination: + type: object + properties: + next_key: + type: string + format: byte + title: |- + next_key is the key to be passed to PageRequest.key to + query the next page most efficiently + total: + type: string + format: uint64 + title: >- + total is total number of results available if + PageRequest.count_total + + was set, its value is undefined otherwise + description: >- + PageResponse is to be embedded in gRPC response messages where + the + + corresponding request message has used PageRequest. + + message SomeResponse { + repeated Bar results = 1; + PageResponse page = 2; + } + default: + description: An unexpected error response + schema: + type: object + properties: + error: + type: string + code: + type: integer + format: int32 + message: + type: string + details: + type: array + items: + type: object + properties: + type_url: + type: string + value: + type: string + format: byte + parameters: + - name: pagination.key + description: |- + key is a value returned in PageResponse.next_key to begin + querying the next page most efficiently. Only one of offset or key + should be set. + in: query + required: false + type: string + format: byte + - name: pagination.offset + description: >- + offset is a numeric offset that can be used when key is unavailable. + + It is less efficient than using key. Only one of offset or key + should + + be set. + in: query + required: false + type: string + format: uint64 + - name: pagination.limit + description: >- + limit is the total number of results to be returned in the result + page. + + If left empty it will default to a value to be set by each app. + in: query + required: false + type: string + format: uint64 + - name: pagination.count_total + description: >- + count_total is set to true to indicate that the result set should + include + + a count of the total number of items available for pagination in + UIs. + + count_total is only respected when offset is used. It is ignored + when key + + is set. + in: query + required: false + type: boolean + format: boolean + - name: pagination.reverse + description: >- + reverse is set to true if results are to be returned in the + descending order. + + + Since: cosmos-sdk 0.43 + in: query + required: false + type: boolean + format: boolean + tags: + - Query + /lbm/fswap/v1/total_swappable_to_coin_amount: + get: + summary: >- + TotalSwappableToCoinAmount queries the current swappable amount for + to-coin. + operationId: TotalSwappableToCoinAmount + responses: + '200': + description: A successful response. + schema: + type: object + properties: + swappable_amount: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. + default: + description: An unexpected error response + schema: + type: object + properties: + error: + type: string + code: + type: integer + format: int32 + message: + type: string + details: + type: array + items: + type: object + properties: + type_url: + type: string + value: + type: string + format: byte + parameters: + - name: fromDenom + in: query + required: false + type: string + - name: toDenom + in: query + required: false + type: string + tags: + - Query definitions: cosmos.auth.v1beta1.Params: type: object @@ -59561,3 +59885,111 @@ definitions: - VOTE_OPTION_UNSPECIFIED: VOTE_OPTION_UNSPECIFIED defines a no-op vote option. - VOTE_OPTION_YES: VOTE_OPTION_YES defines a yes vote option. - VOTE_OPTION_NO: VOTE_OPTION_NO defines a no vote option. + lbm.fswap.v1.QuerySwapResponse: + type: object + properties: + swap: + type: object + properties: + from_denom: + type: string + to_denom: + type: string + amount_cap_for_to_denom: + type: string + swap_rate: + type: string + lbm.fswap.v1.QuerySwappedResponse: + type: object + properties: + from_coin_amount: + type: object + properties: + denom: + type: string + amount: + type: string + description: |- + Coin defines a token with a denomination and an amount. + + NOTE: The amount field is an Int which implements the custom method + signatures required by gogoproto. + to_coin_amount: + type: object + properties: + denom: + type: string + amount: + type: string + description: |- + Coin defines a token with a denomination and an amount. + + NOTE: The amount field is an Int which implements the custom method + signatures required by gogoproto. + lbm.fswap.v1.QuerySwapsResponse: + type: object + properties: + swaps: + type: array + items: + type: object + properties: + from_denom: + type: string + to_denom: + type: string + amount_cap_for_to_denom: + type: string + swap_rate: + type: string + pagination: + type: object + properties: + next_key: + type: string + format: byte + title: |- + next_key is the key to be passed to PageRequest.key to + query the next page most efficiently + total: + type: string + format: uint64 + title: >- + total is total number of results available if + PageRequest.count_total + + was set, its value is undefined otherwise + description: |- + PageResponse is to be embedded in gRPC response messages where the + corresponding request message has used PageRequest. + + message SomeResponse { + repeated Bar results = 1; + PageResponse page = 2; + } + lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse: + type: object + properties: + swappable_amount: + type: object + properties: + denom: + type: string + amount: + type: string + description: |- + Coin defines a token with a denomination and an amount. + + NOTE: The amount field is an Int which implements the custom method + signatures required by gogoproto. + lbm.fswap.v1.Swap: + type: object + properties: + from_denom: + type: string + to_denom: + type: string + amount_cap_for_to_denom: + type: string + swap_rate: + type: string diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 8ac2e922b3..32205add25 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -991,6 +991,8 @@ - [GenesisState](#lbm.fswap.v1.GenesisState) - [lbm/fswap/v1/query.proto](#lbm/fswap/v1/query.proto) + - [QuerySwapRequest](#lbm.fswap.v1.QuerySwapRequest) + - [QuerySwapResponse](#lbm.fswap.v1.QuerySwapResponse) - [QuerySwappedRequest](#lbm.fswap.v1.QuerySwappedRequest) - [QuerySwappedResponse](#lbm.fswap.v1.QuerySwappedResponse) - [QuerySwapsRequest](#lbm.fswap.v1.QuerySwapsRequest) @@ -14717,6 +14719,37 @@ GenesisState defines the fswap module's genesis state. + + +### QuerySwapRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `fromDenom` | [string](#string) | | | +| `toDenom` | [string](#string) | | | + + + + + + + + +### QuerySwapResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `swap` | [Swap](#lbm.fswap.v1.Swap) | | | + + + + + + ### QuerySwappedRequest @@ -14826,6 +14859,7 @@ GenesisState defines the fswap module's genesis state. | ----------- | ------------ | ------------- | ------------| ------- | -------- | | `Swapped` | [QuerySwappedRequest](#lbm.fswap.v1.QuerySwappedRequest) | [QuerySwappedResponse](#lbm.fswap.v1.QuerySwappedResponse) | Swapped queries the current swapped status that includes a burnt amount of from-coin and a minted amount of to-coin. | GET|/lbm/fswap/v1/swapped| | `TotalSwappableToCoinAmount` | [QueryTotalSwappableToCoinAmountRequest](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest) | [QueryTotalSwappableToCoinAmountResponse](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse) | TotalSwappableToCoinAmount queries the current swappable amount for to-coin. | GET|/lbm/fswap/v1/total_swappable_to_coin_amount| +| `Swap` | [QuerySwapRequest](#lbm.fswap.v1.QuerySwapRequest) | [QuerySwapResponse](#lbm.fswap.v1.QuerySwapResponse) | Swap queries a swap | GET|/lbm/fswap/v1/swap| | `Swaps` | [QuerySwapsRequest](#lbm.fswap.v1.QuerySwapsRequest) | [QuerySwapsResponse](#lbm.fswap.v1.QuerySwapsResponse) | Swaps queries all the swap that registered | GET|/lbm/fswap/v1/swaps| diff --git a/proto/lbm/fswap/v1/query.proto b/proto/lbm/fswap/v1/query.proto index a2a88b7093..e5fa09168b 100644 --- a/proto/lbm/fswap/v1/query.proto +++ b/proto/lbm/fswap/v1/query.proto @@ -20,6 +20,10 @@ service Query { returns (QueryTotalSwappableToCoinAmountResponse) { option (google.api.http).get = "/lbm/fswap/v1/total_swappable_to_coin_amount"; } + // Swap queries a swap + rpc Swap(QuerySwapRequest) returns (QuerySwapResponse) { + option (google.api.http).get = "/lbm/fswap/v1/swap"; + } // Swaps queries all the swap that registered rpc Swaps(QuerySwapsRequest) returns (QuerySwapsResponse) { option (google.api.http).get = "/lbm/fswap/v1/swaps"; @@ -46,6 +50,14 @@ message QueryTotalSwappableToCoinAmountResponse { [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; } +message QuerySwapRequest { + string fromDenom = 1; + string toDenom = 2; +} +message QuerySwapResponse { + Swap swap = 1 [(gogoproto.nullable) = false]; +} + message QuerySwapsRequest { cosmos.base.query.v1beta1.PageRequest pagination = 1; } diff --git a/x/fswap/client/cli/query.go b/x/fswap/client/cli/query.go index 46c87aa868..723e5200ec 100644 --- a/x/fswap/client/cli/query.go +++ b/x/fswap/client/cli/query.go @@ -24,6 +24,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand( CmdQuerySwapped(), CmdQueryTotalSwappableAmount(), + CmdQuerySwap(), CmdQuerySwaps(), ) return cmd @@ -86,10 +87,40 @@ func CmdQueryTotalSwappableAmount() *cobra.Command { return cmd } +func CmdQuerySwap() *cobra.Command { + cmd := &cobra.Command{ + Use: "swap [from_denom] [to_denom]", + Short: "shows a swap", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QuerySwapRequest{ + FromDenom: args[0], + ToDenom: args[1], + } + + res, err := queryClient.Swap(cmd.Context(), req) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + func CmdQuerySwaps() *cobra.Command { cmd := &cobra.Command{ Use: "swaps", - Short: "shows the all the swaps that proposed", + Short: "shows the all the swaps", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) @@ -98,7 +129,15 @@ func CmdQuerySwaps() *cobra.Command { } queryClient := types.NewQueryClient(clientCtx) - res, err := queryClient.Swaps(cmd.Context(), &types.QuerySwapsRequest{}) + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + req := &types.QuerySwapsRequest{ + Pagination: pageReq, + } + res, err := queryClient.Swaps(cmd.Context(), req) if err != nil { return err } diff --git a/x/fswap/keeper/grpc_query.go b/x/fswap/keeper/grpc_query.go index 8e2e94a5e2..ba888d6e4d 100644 --- a/x/fswap/keeper/grpc_query.go +++ b/x/fswap/keeper/grpc_query.go @@ -3,6 +3,9 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/Finschia/finschia-sdk/store/prefix" sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" @@ -59,6 +62,20 @@ func (s QueryServer) TotalSwappableToCoinAmount(ctx context.Context, req *types. return &types.QueryTotalSwappableToCoinAmountResponse{SwappableAmount: amount}, nil } +func (s QueryServer) Swap(ctx context.Context, req *types.QuerySwapRequest) (*types.QuerySwapResponse, error) { + if err := req.Validate(); err != nil { + return nil, err + } + + c := sdk.UnwrapSDKContext(ctx) + swap, err := s.Keeper.getSwap(c, req.GetFromDenom(), req.GetToDenom()) + if err != nil { + return nil, status.Error(codes.NotFound, err.Error()) + } + + return &types.QuerySwapResponse{Swap: swap}, nil +} + func (s QueryServer) Swaps(ctx context.Context, req *types.QuerySwapsRequest) (*types.QuerySwapsResponse, error) { c := sdk.UnwrapSDKContext(ctx) diff --git a/x/fswap/keeper/grpc_query_test.go b/x/fswap/keeper/grpc_query_test.go new file mode 100644 index 0000000000..f141459d09 --- /dev/null +++ b/x/fswap/keeper/grpc_query_test.go @@ -0,0 +1,121 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/Finschia/finschia-sdk/baseapp" + "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/keeper" + "github.com/Finschia/finschia-sdk/x/fswap/types" +) + +func TestFSwapQueryTestSuite(t *testing.T) { + suite.Run(t, &FSwapQueryTestSuite{}) +} + +type FSwapQueryTestSuite struct { + suite.Suite + + app *simapp.SimApp + ctx sdk.Context + queryClient types.QueryClient + keeper keeper.Keeper + swap types.Swap + toDenomMetadata bank.Metadata + fromDenom string + toDenom string +} + +func (s *FSwapQueryTestSuite) SetupTest() { + s.app = simapp.Setup(false) + s.ctx = s.app.BaseApp.NewContext(false, tmproto.Header{}) + + queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.app.InterfaceRegistry()) + types.RegisterQueryServer(queryHelper, keeper.NewQueryServer(s.app.FswapKeeper)) + s.queryClient = types.NewQueryClient(queryHelper) + s.keeper = s.app.FswapKeeper + + pebSwapRateForCony, err := sdk.NewDecFromStr("148079656000000") + s.Require().NoError(err) + swapCap := sdk.NewInt(1000) + s.Require().NoError(err) + s.fromDenom = "cony" + s.toDenom = "kei" + s.swap = types.Swap{ + FromDenom: s.fromDenom, + ToDenom: s.toDenom, + AmountCapForToDenom: swapCap, + SwapRate: pebSwapRateForCony, + } + s.toDenomMetadata = bank.Metadata{ + Description: "This is metadata for to-coin", + DenomUnits: []*bank.DenomUnit{ + {Denom: s.swap.ToDenom, Exponent: 0}, + }, + Base: s.toDenom, + Display: "dummycoin", + Name: "DUMMY", + Symbol: "DUM", + } + + err = s.keeper.SetSwap(s.ctx, s.swap, s.toDenomMetadata) + s.Require().NoError(err) +} + +func (s *FSwapQueryTestSuite) TestQuerySwapRequest() { + tests := []struct { + name string + FromDenom string + ToDenom string + wantErr bool + expectedGrpcCode codes.Code + }{ + { + name: "valid", + FromDenom: s.fromDenom, + ToDenom: s.toDenom, + wantErr: false, + expectedGrpcCode: codes.OK, + }, + { + name: "invalid: empty fromDenom", + FromDenom: "", + ToDenom: s.toDenom, + wantErr: true, + expectedGrpcCode: codes.InvalidArgument, + }, + { + name: "invalid: empty toDenom", + FromDenom: s.fromDenom, + ToDenom: "", + wantErr: true, + expectedGrpcCode: codes.InvalidArgument, + }, + { + name: "invalid: the same fromDenom and toDenom", + FromDenom: s.fromDenom, + ToDenom: s.fromDenom, + wantErr: true, + expectedGrpcCode: codes.InvalidArgument, + }, + } + for _, tc := range tests { + s.Run(tc.name, func() { + m := &types.QuerySwapRequest{ + FromDenom: tc.FromDenom, + ToDenom: tc.ToDenom, + } + + _, err := s.queryClient.Swap(s.ctx.Context(), m) + actualGrpcCode := status.Code(err) + s.Require().Equal(tc.expectedGrpcCode, actualGrpcCode, actualGrpcCode.String()) + }) + } +} diff --git a/x/fswap/testutil/expected_keepers_mocks.go b/x/fswap/testutil/expected_keepers_mocks.go index 8718d93937..27cbf452b7 100644 --- a/x/fswap/testutil/expected_keepers_mocks.go +++ b/x/fswap/testutil/expected_keepers_mocks.go @@ -7,9 +7,8 @@ package testutil import ( reflect "reflect" - types "github.com/Finschia/finschia-sdk/snapshots/types" - types0 "github.com/Finschia/finschia-sdk/types" - types1 "github.com/Finschia/finschia-sdk/x/bank/types" + types "github.com/Finschia/finschia-sdk/types" + types0 "github.com/Finschia/finschia-sdk/x/bank/types" gomock "github.com/golang/mock/gomock" ) @@ -37,7 +36,7 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { } // BurnCoins mocks base method. -func (m *MockBankKeeper) BurnCoins(ctx types0.Context, moduleName string, amt types0.Coins) error { +func (m *MockBankKeeper) BurnCoins(ctx types.Context, moduleName string, amt types.Coins) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "BurnCoins", ctx, moduleName, amt) ret0, _ := ret[0].(error) @@ -51,10 +50,10 @@ func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amt interface{} } // GetBalance mocks base method. -func (m *MockBankKeeper) GetBalance(ctx types0.Context, addr types0.AccAddress, denom string) types0.Coin { +func (m *MockBankKeeper) GetBalance(ctx types.Context, addr types.AccAddress, denom string) types.Coin { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetBalance", ctx, addr, denom) - ret0, _ := ret[0].(types0.Coin) + ret0, _ := ret[0].(types.Coin) return ret0 } @@ -65,10 +64,10 @@ func (mr *MockBankKeeperMockRecorder) GetBalance(ctx, addr, denom interface{}) * } // GetDenomMetaData mocks base method. -func (m *MockBankKeeper) GetDenomMetaData(ctx types0.Context, denom string) (types.Metadata, bool) { +func (m *MockBankKeeper) GetDenomMetaData(ctx types.Context, denom string) (types0.Metadata, bool) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDenomMetaData", ctx, denom) - ret0, _ := ret[0].(types.Metadata) + ret0, _ := ret[0].(types0.Metadata) ret1, _ := ret[1].(bool) return ret0, ret1 } @@ -80,7 +79,7 @@ func (mr *MockBankKeeperMockRecorder) GetDenomMetaData(ctx, denom interface{}) * } // IsSendEnabledCoins mocks base method. -func (m *MockBankKeeper) IsSendEnabledCoins(ctx types0.Context, coins ...types0.Coin) error { +func (m *MockBankKeeper) IsSendEnabledCoins(ctx types.Context, coins ...types.Coin) error { m.ctrl.T.Helper() varargs := []interface{}{ctx} for _, a := range coins { @@ -99,7 +98,7 @@ func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoins(ctx interface{}, coins } // MintCoins mocks base method. -func (m *MockBankKeeper) MintCoins(ctx types0.Context, moduleName string, amt types0.Coins) error { +func (m *MockBankKeeper) MintCoins(ctx types.Context, moduleName string, amt types.Coins) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amt) ret0, _ := ret[0].(error) @@ -113,7 +112,7 @@ func (mr *MockBankKeeperMockRecorder) MintCoins(ctx, moduleName, amt interface{} } // SendCoinsFromAccountToModule mocks base method. -func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx types0.Context, senderAddr types0.AccAddress, recipientModule string, amt types0.Coins) error { +func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) ret0, _ := ret[0].(error) @@ -127,7 +126,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAd } // SendCoinsFromModuleToAccount mocks base method. -func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types0.Context, senderModule string, recipientAddr types0.AccAddress, amt types0.Coins) error { +func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) ret0, _ := ret[0].(error) @@ -141,7 +140,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderMo } // SetDenomMetaData mocks base method. -func (m *MockBankKeeper) SetDenomMetaData(ctx types0.Context, denomMetaData types1.Metadata) { +func (m *MockBankKeeper) SetDenomMetaData(ctx types.Context, denomMetaData types0.Metadata) { m.ctrl.T.Helper() m.ctrl.Call(m, "SetDenomMetaData", ctx, denomMetaData) } diff --git a/x/fswap/types/msgs.go b/x/fswap/types/msgs.go index f8ca3407c2..5e71738fa9 100644 --- a/x/fswap/types/msgs.go +++ b/x/fswap/types/msgs.go @@ -1,6 +1,9 @@ package types import ( + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" "github.com/Finschia/finschia-sdk/x/foundation/codec" @@ -141,3 +144,20 @@ func (m *MsgSetSwap) Route() string { func (m *MsgSetSwap) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) } + +func (m *QuerySwapRequest) Validate() error { + if m == nil { + return status.Error(codes.InvalidArgument, "empty QuerySwapRequest is not allowed") + } + if m.GetFromDenom() == m.GetToDenom() { + return status.Error(codes.InvalidArgument, "fromDenom and toDenom cannot be the same") + } + + if m.GetFromDenom() == "" { + return status.Error(codes.InvalidArgument, "from denom is empty") + } + if m.GetToDenom() == "" { + return status.Error(codes.InvalidArgument, "to denom is empty") + } + return nil +} diff --git a/x/fswap/types/msgs_test.go b/x/fswap/types/msgs_test.go index 1ae1c71636..eb5611f858 100644 --- a/x/fswap/types/msgs_test.go +++ b/x/fswap/types/msgs_test.go @@ -4,6 +4,8 @@ import ( "testing" "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" sdk "github.com/Finschia/finschia-sdk/types" "github.com/Finschia/finschia-sdk/x/auth/legacy/legacytx" @@ -83,3 +85,53 @@ func TestAminoJSON(t *testing.T) { }) } } + +func TestQuerySwapRequestValidate(t *testing.T) { + tests := []struct { + name string + FromDenom string + ToDenom string + wantErr bool + expectedGrpcCode codes.Code + }{ + { + name: "valid", + FromDenom: "cony", + ToDenom: "peb", + wantErr: false, + expectedGrpcCode: codes.OK, + }, + { + name: "invalid: empty fromDenom", + FromDenom: "", + ToDenom: "peb", + wantErr: true, + expectedGrpcCode: codes.InvalidArgument, + }, + { + name: "invalid: empty toDenom", + FromDenom: "cony", + ToDenom: "", + wantErr: true, + expectedGrpcCode: codes.InvalidArgument, + }, + { + name: "invalid: the same fromDenom and toDenom", + FromDenom: "cony", + ToDenom: "cony", + wantErr: true, + expectedGrpcCode: codes.InvalidArgument, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + m := &fswaptypes.QuerySwapRequest{ + FromDenom: tc.FromDenom, + ToDenom: tc.ToDenom, + } + err := m.Validate() + actualGrpcCode := status.Code(err) + require.Equal(t, tc.expectedGrpcCode, actualGrpcCode) + }) + } +} diff --git a/x/fswap/types/query.pb.go b/x/fswap/types/query.pb.go index 80beb5195a..7f5685ac75 100644 --- a/x/fswap/types/query.pb.go +++ b/x/fswap/types/query.pb.go @@ -235,6 +235,102 @@ func (m *QueryTotalSwappableToCoinAmountResponse) GetSwappableAmount() types.Coi return types.Coin{} } +type QuerySwapRequest struct { + FromDenom string `protobuf:"bytes,1,opt,name=fromDenom,proto3" json:"fromDenom,omitempty"` + ToDenom string `protobuf:"bytes,2,opt,name=toDenom,proto3" json:"toDenom,omitempty"` +} + +func (m *QuerySwapRequest) Reset() { *m = QuerySwapRequest{} } +func (m *QuerySwapRequest) String() string { return proto.CompactTextString(m) } +func (*QuerySwapRequest) ProtoMessage() {} +func (*QuerySwapRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_01deae9da7816d6a, []int{4} +} +func (m *QuerySwapRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySwapRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySwapRequest.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 *QuerySwapRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySwapRequest.Merge(m, src) +} +func (m *QuerySwapRequest) XXX_Size() int { + return m.Size() +} +func (m *QuerySwapRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySwapRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySwapRequest proto.InternalMessageInfo + +func (m *QuerySwapRequest) GetFromDenom() string { + if m != nil { + return m.FromDenom + } + return "" +} + +func (m *QuerySwapRequest) GetToDenom() string { + if m != nil { + return m.ToDenom + } + return "" +} + +type QuerySwapResponse struct { + Swap Swap `protobuf:"bytes,1,opt,name=swap,proto3" json:"swap"` +} + +func (m *QuerySwapResponse) Reset() { *m = QuerySwapResponse{} } +func (m *QuerySwapResponse) String() string { return proto.CompactTextString(m) } +func (*QuerySwapResponse) ProtoMessage() {} +func (*QuerySwapResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_01deae9da7816d6a, []int{5} +} +func (m *QuerySwapResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySwapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySwapResponse.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 *QuerySwapResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySwapResponse.Merge(m, src) +} +func (m *QuerySwapResponse) XXX_Size() int { + return m.Size() +} +func (m *QuerySwapResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySwapResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySwapResponse proto.InternalMessageInfo + +func (m *QuerySwapResponse) GetSwap() Swap { + if m != nil { + return m.Swap + } + return Swap{} +} + type QuerySwapsRequest struct { Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` } @@ -243,7 +339,7 @@ func (m *QuerySwapsRequest) Reset() { *m = QuerySwapsRequest{} } func (m *QuerySwapsRequest) String() string { return proto.CompactTextString(m) } func (*QuerySwapsRequest) ProtoMessage() {} func (*QuerySwapsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_01deae9da7816d6a, []int{4} + return fileDescriptor_01deae9da7816d6a, []int{6} } func (m *QuerySwapsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -288,7 +384,7 @@ func (m *QuerySwapsResponse) Reset() { *m = QuerySwapsResponse{} } func (m *QuerySwapsResponse) String() string { return proto.CompactTextString(m) } func (*QuerySwapsResponse) ProtoMessage() {} func (*QuerySwapsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_01deae9da7816d6a, []int{5} + return fileDescriptor_01deae9da7816d6a, []int{7} } func (m *QuerySwapsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -336,6 +432,8 @@ func init() { proto.RegisterType((*QuerySwappedResponse)(nil), "lbm.fswap.v1.QuerySwappedResponse") proto.RegisterType((*QueryTotalSwappableToCoinAmountRequest)(nil), "lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest") proto.RegisterType((*QueryTotalSwappableToCoinAmountResponse)(nil), "lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse") + proto.RegisterType((*QuerySwapRequest)(nil), "lbm.fswap.v1.QuerySwapRequest") + proto.RegisterType((*QuerySwapResponse)(nil), "lbm.fswap.v1.QuerySwapResponse") proto.RegisterType((*QuerySwapsRequest)(nil), "lbm.fswap.v1.QuerySwapsRequest") proto.RegisterType((*QuerySwapsResponse)(nil), "lbm.fswap.v1.QuerySwapsResponse") } @@ -343,44 +441,47 @@ func init() { func init() { proto.RegisterFile("lbm/fswap/v1/query.proto", fileDescriptor_01deae9da7816d6a) } var fileDescriptor_01deae9da7816d6a = []byte{ - // 590 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0xcf, 0x6e, 0xd3, 0x4e, - 0x10, 0xc7, 0xe3, 0xf4, 0xd7, 0x5f, 0xd5, 0x6d, 0x55, 0xca, 0xb6, 0x15, 0xc1, 0x14, 0x27, 0xf8, - 0xd0, 0x56, 0xfc, 0xd9, 0x55, 0xd2, 0xf2, 0x00, 0x04, 0x54, 0xb8, 0x20, 0x41, 0xe8, 0x09, 0x0e, - 0x61, 0x9d, 0x6e, 0x5c, 0x8b, 0xd8, 0xe3, 0x66, 0x37, 0x69, 0x73, 0xe5, 0xc0, 0x0d, 0x09, 0x89, - 0x47, 0x80, 0x13, 0x2f, 0xc1, 0xb5, 0xc7, 0x4a, 0x5c, 0x38, 0x01, 0x4a, 0x78, 0x10, 0xb4, 0xeb, - 0x75, 0x63, 0x8b, 0x86, 0x08, 0xa1, 0xde, 0x36, 0x3b, 0xdf, 0x99, 0xef, 0x67, 0x27, 0x33, 0x46, - 0xa5, 0x8e, 0x17, 0xd2, 0xb6, 0x38, 0x62, 0x31, 0xed, 0x57, 0xe9, 0x61, 0x8f, 0x77, 0x07, 0x24, - 0xee, 0x82, 0x04, 0xbc, 0xd8, 0xf1, 0x42, 0xa2, 0x23, 0xa4, 0x5f, 0xb5, 0xd7, 0x7d, 0x00, 0xbf, - 0xc3, 0x29, 0x8b, 0x03, 0xca, 0xa2, 0x08, 0x24, 0x93, 0x01, 0x44, 0x22, 0xd1, 0xda, 0xab, 0x3e, - 0xf8, 0xa0, 0x8f, 0x54, 0x9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xec, 0xa3, 0x59, 0xfd, 0x37, 0xe2, 0xf2, 0x84, 0x6e, 0xa4, 0xe3, 0x63, 0x57, 0x26, 0x0b, - 0x0c, 0xc1, 0x35, 0x4d, 0xb0, 0x86, 0x57, 0x7e, 0x6f, 0x96, 0xa8, 0x3f, 0x3a, 0x19, 0x3a, 0xd6, - 0xe9, 0xd0, 0xb1, 0x7e, 0x0c, 0x1d, 0xeb, 0xdd, 0xc8, 0x29, 0x9c, 0x8e, 0x9c, 0xc2, 0xd7, 0x91, - 0x53, 0x78, 0x4e, 0xa6, 0x8e, 0xfa, 0xb1, 0x29, 0xa6, 0x47, 0xde, 0xfb, 0x5f, 0x7f, 0x44, 0xb7, - 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x4e, 0x87, 0x53, 0x1d, 0x08, 0x06, 0x00, 0x00, + // 630 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x41, 0x6f, 0xd3, 0x30, + 0x18, 0x6d, 0x4a, 0xcb, 0x34, 0x33, 0x8d, 0xe2, 0x75, 0xa2, 0x84, 0x91, 0x96, 0x1c, 0x36, 0x04, + 0xc3, 0x56, 0xb7, 0xf1, 0x03, 0x56, 0xd0, 0x40, 0x48, 0x48, 0x50, 0x76, 0x82, 0x43, 0x71, 0x3a, + 0x37, 0x8b, 0x68, 0xe2, 0xac, 0x76, 0xbb, 0xf5, 0xca, 0x01, 0x71, 0x41, 0x42, 0xe2, 0x2f, 0x70, + 0xe2, 0x4f, 0x70, 0xdd, 0x71, 0x12, 0x17, 0x4e, 0x80, 0x5a, 0x7e, 0x08, 0xb2, 0xe3, 0xac, 0x89, + 0xb6, 0xac, 0x9a, 0xa6, 0xdd, 0xdc, 0x7c, 0xef, 0x7b, 0xef, 0xf9, 0xe9, 0xfb, 0x5c, 0x50, 0xe9, + 0x3a, 0x3e, 0xee, 0xf0, 0x7d, 0x12, 0xe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d, 0x07, 0xb5, + 0x99, 0x8f, 0xb7, 0xbc, 0x80, 0xb7, 0x77, 0x3d, 0x82, 0x3b, 0xfa, 0xf0, 0x90, 0xef, 0xbc, 0xc7, + 0x62, 0x18, 0x52, 0xae, 0x9a, 0x9a, 0xf3, 0x52, 0x47, 0x9e, 0x36, 0x95, 0x0a, 0x14, 0x60, 0x5e, + 0xb0, 0x94, 0x6e, 0xfe, 0x52, 0x74, 0xe7, 0x04, 0x9b, 0xa8, 0xda, 0xef, 0xc0, 0xb2, 0xca, 0x61, + 0x9b, 0x09, 0xd2, 0x55, 0x61, 0x10, 0xa7, 0x4b, 0xb7, 0x13, 0x90, 0x8b, 0x46, 0xfd, 0xcd, 0x00, + 0x2b, 0x53, 0x25, 0x74, 0xfa, 0x43, 0x50, 0xe2, 0x31, 0xe0, 0x72, 0xd3, 0xbf, 0x7e, 0xac, 0xa3, + 0x83, 0x78, 0x0e, 0x4a, 0xc7, 0x03, 0x71, 0xd1, 0x2b, 0x6f, 0x82, 0x1b, 0x09, 0x2e, 0x7d, 0xb7, + 0x55, 0x50, 0x90, 0x9a, 0xfa, 0x3e, 0x10, 0x25, 0x17, 0x0f, 0x49, 0x64, 0xa3, 0x20, 0x2f, 0xd2, + 0x54, 0x28, 0xfb, 0x6d, 0x82, 0x82, 0xc7, 0x7e, 0xb6, 0x00, 0x98, 0xac, 0x94, 0x26, 0x5a, 0x4e, + 0x05, 0x13, 0xad, 0x76, 0x1c, 0xcf, 0x4b, 0xe2, 0x52, 0xdd, 0xdb, 0x4c, 0x74, 0xda, 0x9f, 0x0d, + 0x00, 0x93, 0xec, 0xda, 0x21, 0x02, 0x45, 0xa9, 0xcd, 0x2b, 0x46, 0xed, 0xca, 0x99, 0x16, 0x23, + 0x18, 0x7c, 0x9a, 0xb2, 0x13, 0x4d, 0xeb, 0xca, 0x54, 0x3b, 0x91, 0x58, 0xd2, 0xcf, 0xda, 0xa7, + 0x02, 0x28, 0x2a, 0x3f, 0x90, 0x81, 0x19, 0xbd, 0x91, 0xf0, 0x6e, 0x5a, 0xfe, 0x94, 0xed, 0x37, + 0xed, 0xb3, 0x20, 0x91, 0x8e, 0x7d, 0xe7, 0xc3, 0xcf, 0x7f, 0x5f, 0xf3, 0x37, 0xe1, 0x22, 0x4e, + 0xbd, 0x2d, 0x5c, 0xab, 0xfc, 0x30, 0x80, 0x99, 0x3d, 0x98, 0x70, 0xe3, 0x14, 0x85, 0xa9, 0xab, + 0x62, 0x3e, 0x3a, 0x67, 0x97, 0xb6, 0xba, 0xa1, 0xac, 0x22, 0xb8, 0x9a, 0xb6, 0x2a, 0x64, 0x67, + 0x6b, 0xb2, 0x17, 0xe9, 0x57, 0x02, 0xb6, 0x41, 0x41, 0xd2, 0x42, 0x2b, 0x23, 0x8c, 0xd8, 0x54, + 0x35, 0xb3, 0xae, 0xe5, 0x4d, 0x25, 0x5f, 0x86, 0xf0, 0x64, 0x52, 0xd0, 0x05, 0x45, 0x35, 0x2b, + 0x30, 0x8b, 0x25, 0x9e, 0x51, 0xb3, 0x96, 0x0d, 0xd0, 0x3a, 0xb7, 0x95, 0xce, 0x22, 0x5c, 0x38, + 0xa9, 0xc3, 0x1b, 0xcf, 0x0e, 0x47, 0x96, 0x71, 0x34, 0xb2, 0x8c, 0xbf, 0x23, 0xcb, 0xf8, 0x32, + 0xb6, 0x72, 0x47, 0x63, 0x2b, 0xf7, 0x6b, 0x6c, 0xe5, 0xde, 0xa0, 0xa9, 0xeb, 0x7d, 0xa0, 0xc9, + 0xd4, 0x9a, 0x3b, 0x57, 0xd5, 0x1f, 0xc7, 0xfa, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x92, 0x88, + 0x7c, 0xcc, 0xfc, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -400,6 +501,8 @@ type QueryClient interface { Swapped(ctx context.Context, in *QuerySwappedRequest, opts ...grpc.CallOption) (*QuerySwappedResponse, error) // TotalSwappableToCoinAmount queries the current swappable amount for to-coin. TotalSwappableToCoinAmount(ctx context.Context, in *QueryTotalSwappableToCoinAmountRequest, opts ...grpc.CallOption) (*QueryTotalSwappableToCoinAmountResponse, error) + // Swap queries a swap + Swap(ctx context.Context, in *QuerySwapRequest, opts ...grpc.CallOption) (*QuerySwapResponse, error) // Swaps queries all the swap that registered Swaps(ctx context.Context, in *QuerySwapsRequest, opts ...grpc.CallOption) (*QuerySwapsResponse, error) } @@ -430,6 +533,15 @@ func (c *queryClient) TotalSwappableToCoinAmount(ctx context.Context, in *QueryT return out, nil } +func (c *queryClient) Swap(ctx context.Context, in *QuerySwapRequest, opts ...grpc.CallOption) (*QuerySwapResponse, error) { + out := new(QuerySwapResponse) + err := c.cc.Invoke(ctx, "/lbm.fswap.v1.Query/Swap", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *queryClient) Swaps(ctx context.Context, in *QuerySwapsRequest, opts ...grpc.CallOption) (*QuerySwapsResponse, error) { out := new(QuerySwapsResponse) err := c.cc.Invoke(ctx, "/lbm.fswap.v1.Query/Swaps", in, out, opts...) @@ -446,6 +558,8 @@ type QueryServer interface { Swapped(context.Context, *QuerySwappedRequest) (*QuerySwappedResponse, error) // TotalSwappableToCoinAmount queries the current swappable amount for to-coin. TotalSwappableToCoinAmount(context.Context, *QueryTotalSwappableToCoinAmountRequest) (*QueryTotalSwappableToCoinAmountResponse, error) + // Swap queries a swap + Swap(context.Context, *QuerySwapRequest) (*QuerySwapResponse, error) // Swaps queries all the swap that registered Swaps(context.Context, *QuerySwapsRequest) (*QuerySwapsResponse, error) } @@ -460,6 +574,9 @@ func (*UnimplementedQueryServer) Swapped(ctx context.Context, req *QuerySwappedR func (*UnimplementedQueryServer) TotalSwappableToCoinAmount(ctx context.Context, req *QueryTotalSwappableToCoinAmountRequest) (*QueryTotalSwappableToCoinAmountResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method TotalSwappableToCoinAmount not implemented") } +func (*UnimplementedQueryServer) Swap(ctx context.Context, req *QuerySwapRequest) (*QuerySwapResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Swap not implemented") +} func (*UnimplementedQueryServer) Swaps(ctx context.Context, req *QuerySwapsRequest) (*QuerySwapsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Swaps not implemented") } @@ -504,6 +621,24 @@ func _Query_TotalSwappableToCoinAmount_Handler(srv interface{}, ctx context.Cont return interceptor(ctx, in, info, handler) } +func _Query_Swap_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QuerySwapRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Swap(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lbm.fswap.v1.Query/Swap", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Swap(ctx, req.(*QuerySwapRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _Query_Swaps_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QuerySwapsRequest) if err := dec(in); err != nil { @@ -534,6 +669,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "TotalSwappableToCoinAmount", Handler: _Query_TotalSwappableToCoinAmount_Handler, }, + { + MethodName: "Swap", + Handler: _Query_Swap_Handler, + }, { MethodName: "Swaps", Handler: _Query_Swaps_Handler, @@ -693,6 +832,76 @@ func (m *QueryTotalSwappableToCoinAmountResponse) MarshalToSizedBuffer(dAtA []by return len(dAtA) - i, nil } +func (m *QuerySwapRequest) 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 *QuerySwapRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySwapRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ToDenom) > 0 { + i -= len(m.ToDenom) + copy(dAtA[i:], m.ToDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ToDenom))) + i-- + dAtA[i] = 0x12 + } + if len(m.FromDenom) > 0 { + i -= len(m.FromDenom) + copy(dAtA[i:], m.FromDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.FromDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QuerySwapResponse) 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 *QuerySwapResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySwapResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Swap.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func (m *QuerySwapsRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -846,6 +1055,34 @@ func (m *QueryTotalSwappableToCoinAmountResponse) Size() (n int) { return n } +func (m *QuerySwapRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.FromDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.ToDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QuerySwapResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Swap.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + func (m *QuerySwapsRequest) Size() (n int) { if m == nil { return 0 @@ -1311,6 +1548,203 @@ func (m *QueryTotalSwappableToCoinAmountResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QuerySwapRequest) 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 ErrIntOverflowQuery + } + 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: QuerySwapRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySwapRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FromDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FromDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ToDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ToDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QuerySwapResponse) 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 ErrIntOverflowQuery + } + 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: QuerySwapResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySwapResponse: 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 ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Swap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *QuerySwapsRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/fswap/types/query.pb.gw.go b/x/fswap/types/query.pb.gw.go index 00786290bd..5442d360f7 100644 --- a/x/fswap/types/query.pb.gw.go +++ b/x/fswap/types/query.pb.gw.go @@ -103,6 +103,42 @@ func local_request_Query_TotalSwappableToCoinAmount_0(ctx context.Context, marsh } +var ( + filter_Query_Swap_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Swap_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySwapRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Swap_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Swap(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Swap_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySwapRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Swap_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Swap(ctx, &protoReq) + return msg, metadata, err + +} + var ( filter_Query_Swaps_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) @@ -185,6 +221,26 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_Swap_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Swap_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Swap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("GET", pattern_Query_Swaps_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -286,6 +342,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_Swap_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Swap_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Swap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("GET", pattern_Query_Swaps_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -314,6 +390,8 @@ var ( pattern_Query_TotalSwappableToCoinAmount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"lbm", "fswap", "v1", "total_swappable_to_coin_amount"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Swap_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"lbm", "fswap", "v1", "swap"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Swaps_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"lbm", "fswap", "v1", "swaps"}, "", runtime.AssumeColonVerbOpt(false))) ) @@ -322,5 +400,7 @@ var ( forward_Query_TotalSwappableToCoinAmount_0 = runtime.ForwardResponseMessage + forward_Query_Swap_0 = runtime.ForwardResponseMessage + forward_Query_Swaps_0 = runtime.ForwardResponseMessage )