From 956d7a622e55569e5d65e6973feb7cda6f2c4819 Mon Sep 17 00:00:00 2001 From: 170210 <85928898+170210@users.noreply.github.com> Date: Fri, 3 May 2024 22:15:44 +0900 Subject: [PATCH] feat: fswap module's basic functionality(MsgSwap, MsgSwapAll, Query, Proposal) (#1345) * refactor: fswap module's proto Signed-off-by: 170210 * refactor: remove config¶ms and modify genesis Signed-off-by: 170210 * refactor: use gov/proposal to change fswapInit Signed-off-by: 170210 * chore: fix simulation Signed-off-by: 170210 * chore: correct query cli Signed-off-by: 170210 * chore: add query for test Signed-off-by: 170210 * chore: lint fix * chore: fix for tx cli * chore: update proto * chore: update genesis logic * chore: add basic tx and queries * chore: rename fswap to swap * chore: change old/new to from/to * chore: clean-up * chore: clean errors and rename * chore: update proto * chore: clean unnecessary member variables * chore: update proto, introduce config, clean code * chore: remove redundant denom validation * chore: remove cache-like operation, rename swap proposal in proto, errors start with number 2 * chore: apply feedbacks * chore: fix some * chore: fix for initGenesis * chore: apply feedbacks * chore: update changelog * chore: remove redundant logic * chore: update error doc * chore: update proto and logic to accept bank.Metadata * chore: add query to get all the swaps * chore: change swap_multiple to swap_rate * chore: disallow updating existing denom metadata with different values * chore: fix for calcSwap logic * chore: extract CalcSwap to function * chore: add missing query cmd * chore: fix for proposal cli * chore: fix for init timing * chore: fix query cli * chore: fix to prevent generating swap more than MaxSwaps * fix: add missing call validateBasic for proposal * fix: * chore: change error type for temporal test-pass * chore: fix for make-swap-proposal update * chore: fix to check swap count after increase in order not to make more than limit * chore: prevent any proposal with different denom * chore: change amount cap type * chore: fix codec-related parts * chore: minor change for convert to-coin-amount-cap --------- Signed-off-by: 170210 Co-authored-by: jaeseung.bae --- CHANGELOG.md | 1 + docs/core/proto-docs.md | 164 +++- proto/lbm/fswap/v1/event.proto | 8 +- proto/lbm/fswap/v1/fswap.proto | 40 +- proto/lbm/fswap/v1/genesis.proto | 6 +- proto/lbm/fswap/v1/params.proto | 12 - proto/lbm/fswap/v1/query.proto | 39 +- proto/lbm/fswap/v1/tx.proto | 15 +- simapp/app.go | 15 +- x/ERRORS.md | 7 +- x/fswap/client/cli/query.go | 47 +- x/fswap/client/cli/tx.go | 190 +++- x/fswap/client/proposal_handler.go | 8 + x/fswap/codec/codec.go | 18 + x/fswap/handler.go | 29 +- x/fswap/keeper/calc.go | 7 + x/fswap/keeper/calc_test.go | 65 ++ x/fswap/keeper/expected_keepers.go | 19 + x/fswap/keeper/fswap.go | 30 - x/fswap/keeper/genesis.go | 52 +- x/fswap/keeper/genesis_test.go | 18 +- x/fswap/keeper/grpc_query.go | 65 +- x/fswap/keeper/grpc_query_params_test.go | 1 - x/fswap/keeper/keeper.go | 203 ++++- x/fswap/keeper/keeper_test.go | 176 +++- x/fswap/keeper/keys.go | 19 + x/fswap/keeper/msg_server.go | 59 +- x/fswap/keeper/msg_server_test.go | 134 +++ x/fswap/keeper/params.go | 35 - x/fswap/keeper/proposal.go | 163 ++++ x/fswap/keeper/proposal_test.go | 138 +++ x/fswap/keeper/query_params_test.go | 1 - x/fswap/module.go | 68 +- x/fswap/module_simulation.go | 5 +- x/fswap/proposal_handler_test.go | 40 + x/fswap/simulation/genesis.go | 64 -- x/fswap/simulation/genesis_test.go | 77 -- x/fswap/spec/README.md | 16 + x/fswap/testutil/expected_keepers_mocks.go | 152 ++-- x/fswap/types/codec.go | 36 +- x/fswap/types/config.go | 19 +- x/fswap/types/errors.go | 7 +- x/fswap/types/event.pb.go | 71 +- x/fswap/types/expected_keepers.go | 19 - x/fswap/types/fswap.go | 77 +- x/fswap/types/fswap.pb.go | 956 ++++++++++++++++++++- x/fswap/types/genesis.go | 42 +- x/fswap/types/genesis.pb.go | 144 +++- x/fswap/types/genesis_test.go | 68 +- x/fswap/types/keys.go | 12 - x/fswap/types/msgs.go | 67 +- x/fswap/types/params.go | 35 - x/fswap/types/params.pb.go | 317 ------- x/fswap/types/proposal.go | 54 ++ x/fswap/types/query.pb.go | 899 ++++++++++++++++--- x/fswap/types/query.pb.gw.go | 144 +++- x/fswap/types/tx.pb.go | 334 +++++-- x/fswap/types/types.go | 1 - 58 files changed, 4137 insertions(+), 1371 deletions(-) delete mode 100644 proto/lbm/fswap/v1/params.proto create mode 100644 x/fswap/client/proposal_handler.go create mode 100644 x/fswap/codec/codec.go create mode 100644 x/fswap/keeper/calc.go create mode 100644 x/fswap/keeper/calc_test.go create mode 100644 x/fswap/keeper/expected_keepers.go delete mode 100644 x/fswap/keeper/fswap.go delete mode 100644 x/fswap/keeper/grpc_query_params_test.go create mode 100644 x/fswap/keeper/keys.go delete mode 100644 x/fswap/keeper/params.go create mode 100644 x/fswap/keeper/proposal.go create mode 100644 x/fswap/keeper/proposal_test.go delete mode 100644 x/fswap/keeper/query_params_test.go create mode 100644 x/fswap/proposal_handler_test.go create mode 100644 x/fswap/spec/README.md delete mode 100644 x/fswap/types/expected_keepers.go delete mode 100644 x/fswap/types/params.go delete mode 100644 x/fswap/types/params.pb.go create mode 100644 x/fswap/types/proposal.go delete mode 100644 x/fswap/types/types.go diff --git a/CHANGELOG.md b/CHANGELOG.md index fdb019c12f..1e2c15134a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/fbridge) [\#1340](https://github.com/Finschia/finschia-sdk/pull/1340) Initialize fbridge module * (x/fbridge) [\#1347](https://github.com/Finschia/finschia-sdk/pull/1347) Implement bridge transfer feature (sending side) * (x/fbridge) [\#1351](https://github.com/Finschia/finschia-sdk/pull/1351) Map a sequence to block number for every bridge request (sending side) +* (x/fswap) [\#1345](https://github.com/Finschia/finschia-sdk/pull/1345) Implement fswap's basic functionality(MsgSwap, MsgSwapAll, Query, Proposal) ### Improvements * (docs) [\#1120](https://github.com/Finschia/finschia-sdk/pull/1120) Update links in x/foundation README.md diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 736b4ac62b..56d2cf5fd1 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -943,26 +943,28 @@ - [EventSwapCoins](#lbm.fswap.v1.EventSwapCoins) - [lbm/fswap/v1/fswap.proto](#lbm/fswap/v1/fswap.proto) + - [MakeSwapProposal](#lbm.fswap.v1.MakeSwapProposal) + - [Swap](#lbm.fswap.v1.Swap) + - [SwapStats](#lbm.fswap.v1.SwapStats) - [Swapped](#lbm.fswap.v1.Swapped) -- [lbm/fswap/v1/params.proto](#lbm/fswap/v1/params.proto) - - [Params](#lbm.fswap.v1.Params) - - [lbm/fswap/v1/genesis.proto](#lbm/fswap/v1/genesis.proto) - [GenesisState](#lbm.fswap.v1.GenesisState) - [lbm/fswap/v1/query.proto](#lbm/fswap/v1/query.proto) - [QuerySwappedRequest](#lbm.fswap.v1.QuerySwappedRequest) - [QuerySwappedResponse](#lbm.fswap.v1.QuerySwappedResponse) - - [QueryTotalSwappableAmountRequest](#lbm.fswap.v1.QueryTotalSwappableAmountRequest) - - [QueryTotalSwappableAmountResponse](#lbm.fswap.v1.QueryTotalSwappableAmountResponse) + - [QuerySwapsRequest](#lbm.fswap.v1.QuerySwapsRequest) + - [QuerySwapsResponse](#lbm.fswap.v1.QuerySwapsResponse) + - [QueryTotalSwappableToCoinAmountRequest](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest) + - [QueryTotalSwappableToCoinAmountResponse](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse) - [Query](#lbm.fswap.v1.Query) - [lbm/fswap/v1/tx.proto](#lbm/fswap/v1/tx.proto) - - [MsgSwapAllRequest](#lbm.fswap.v1.MsgSwapAllRequest) + - [MsgSwap](#lbm.fswap.v1.MsgSwap) + - [MsgSwapAll](#lbm.fswap.v1.MsgSwapAll) - [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse) - - [MsgSwapRequest](#lbm.fswap.v1.MsgSwapRequest) - [MsgSwapResponse](#lbm.fswap.v1.MsgSwapResponse) - [Msg](#lbm.fswap.v1.Msg) @@ -13928,8 +13930,8 @@ Msg defines the foundation Msg service. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `address` | [string](#string) | | holder's address | -| `old_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the old currency | -| `new_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the new currency | +| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | from-coin amount | +| `to_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | to-coin amount | @@ -13952,47 +13954,67 @@ Msg defines the foundation Msg service. - + -### Swapped +### 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 | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `old_coin_amount` | [string](#string) | | | -| `new_coin_amount` | [string](#string) | | | +| `from_denom` | [string](#string) | | | +| `to_denom` | [string](#string) | | | +| `amount_cap_for_to_denom` | [string](#string) | | | +| `swap_rate` | [string](#string) | | | - - + - +### SwapStats - +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `swap_count` | [int32](#int32) | | | - -

Top

-## lbm/fswap/v1/params.proto - -### Params -Params defines the parameters for the module. + + +### Swapped + | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `swappable_new_coin_amount` | [string](#string) | | | +| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `to_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | @@ -14023,8 +14045,9 @@ GenesisState defines the fswap module's genesis state. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#lbm.fswap.v1.Params) | | | -| `swapped` | [Swapped](#lbm.fswap.v1.Swapped) | | | +| `swaps` | [Swap](#lbm.fswap.v1.Swap) | repeated | | +| `swap_stats` | [SwapStats](#lbm.fswap.v1.SwapStats) | | | +| `swappeds` | [Swapped](#lbm.fswap.v1.Swapped) | repeated | | @@ -14053,6 +14076,12 @@ GenesisState defines the fswap module's genesis state. +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `fromDenom` | [string](#string) | | | +| `toDenom` | [string](#string) | | | + + @@ -14065,33 +14094,70 @@ GenesisState defines the fswap module's genesis state. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `old_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | -| `new_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `to_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | + + + + + + + + +### QuerySwapsRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | | + + + + + + + + +### QuerySwapsResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `swaps` | [Swap](#lbm.fswap.v1.Swap) | repeated | | +| `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | | - + -### QueryTotalSwappableAmountRequest +### QueryTotalSwappableToCoinAmountRequest +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `fromDenom` | [string](#string) | | | +| `toDenom` | [string](#string) | | | + - -### QueryTotalSwappableAmountResponse + + +### QueryTotalSwappableToCoinAmountResponse | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `swappable_new_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `swappable_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | @@ -14111,8 +14177,9 @@ GenesisState defines the fswap module's genesis state. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Swapped` | [QuerySwappedRequest](#lbm.fswap.v1.QuerySwappedRequest) | [QuerySwappedResponse](#lbm.fswap.v1.QuerySwappedResponse) | | GET|/lbm/fswap/v1/swapped| -| `TotalNewCurrencySwapLimit` | [QueryTotalSwappableAmountRequest](#lbm.fswap.v1.QueryTotalSwappableAmountRequest) | [QueryTotalSwappableAmountResponse](#lbm.fswap.v1.QueryTotalSwappableAmountResponse) | | GET|/lbm/fswap/v1/swappable_new_coin_amount| +| `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| +| `Swaps` | [QuerySwapsRequest](#lbm.fswap.v1.QuerySwapsRequest) | [QuerySwapsResponse](#lbm.fswap.v1.QuerySwapsResponse) | Swaps queries all the swap that registered | GET|/lbm/fswap/v1/swaps| @@ -14125,41 +14192,44 @@ GenesisState defines the fswap module's genesis state. - + -### MsgSwapAllRequest +### MsgSwap | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `from_address` | [string](#string) | | holder's address | +| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | from-coin amount | +| `to_denom` | [string](#string) | | | - + -### MsgSwapAllResponse +### MsgSwapAll +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `from_address` | [string](#string) | | holder's address | +| `from_denom` | [string](#string) | | | +| `to_denom` | [string](#string) | | | - -### MsgSwapRequest + +### MsgSwapAllResponse -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `from_address` | [string](#string) | | holder's address | -| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of old currency | @@ -14189,8 +14259,8 @@ GenesisState defines the fswap module's genesis state. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Swap` | [MsgSwapRequest](#lbm.fswap.v1.MsgSwapRequest) | [MsgSwapResponse](#lbm.fswap.v1.MsgSwapResponse) | | | -| `SwapAll` | [MsgSwapAllRequest](#lbm.fswap.v1.MsgSwapAllRequest) | [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse) | | | +| `Swap` | [MsgSwap](#lbm.fswap.v1.MsgSwap) | [MsgSwapResponse](#lbm.fswap.v1.MsgSwapResponse) | | | +| `SwapAll` | [MsgSwapAll](#lbm.fswap.v1.MsgSwapAll) | [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse) | | | diff --git a/proto/lbm/fswap/v1/event.proto b/proto/lbm/fswap/v1/event.proto index 2fea28e9d0..6834da7654 100644 --- a/proto/lbm/fswap/v1/event.proto +++ b/proto/lbm/fswap/v1/event.proto @@ -9,10 +9,10 @@ import "cosmos/base/v1beta1/coin.proto"; message EventSwapCoins { // holder's address string address = 1; - // amount of the old currency - cosmos.base.v1beta1.Coin old_coin = 2 + // from-coin amount + cosmos.base.v1beta1.Coin from_coin_amount = 2 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; - // amount of the new currency - cosmos.base.v1beta1.Coin new_coin = 3 + // to-coin amount + cosmos.base.v1beta1.Coin to_coin_amount = 3 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; } diff --git a/proto/lbm/fswap/v1/fswap.proto b/proto/lbm/fswap/v1/fswap.proto index 14315e32d0..13a5c2a006 100644 --- a/proto/lbm/fswap/v1/fswap.proto +++ b/proto/lbm/fswap/v1/fswap.proto @@ -4,9 +4,43 @@ package lbm.fswap.v1; 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 Swapped { +message Swap { + option (gogoproto.equal) = true; option (gogoproto.goproto_stringer) = false; - string old_coin_amount = 1 [(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Int", (gogoproto.nullable) = false]; - string new_coin_amount = 2 [(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Int", (gogoproto.nullable) = false]; + + string from_denom = 1; + string to_denom = 2; + string amount_cap_for_to_denom = 3 + [(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Int", (gogoproto.nullable) = false]; + string swap_rate = 4 + [(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Dec", (gogoproto.nullable) = false]; +} + +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 + [(gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin", (gogoproto.nullable) = false]; } diff --git a/proto/lbm/fswap/v1/genesis.proto b/proto/lbm/fswap/v1/genesis.proto index 43b639a341..c001741269 100644 --- a/proto/lbm/fswap/v1/genesis.proto +++ b/proto/lbm/fswap/v1/genesis.proto @@ -5,10 +5,10 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types"; import "gogoproto/gogo.proto"; import "lbm/fswap/v1/fswap.proto"; -import "lbm/fswap/v1/params.proto"; // GenesisState defines the fswap module's genesis state. message GenesisState { - Params params = 1 [(gogoproto.nullable) = false]; - Swapped swapped = 2 [(gogoproto.nullable) = false]; + repeated Swap swaps = 1 [(gogoproto.nullable) = false]; + SwapStats swap_stats = 2 [(gogoproto.nullable) = false]; + repeated Swapped swappeds = 3 [(gogoproto.nullable) = false]; } diff --git a/proto/lbm/fswap/v1/params.proto b/proto/lbm/fswap/v1/params.proto deleted file mode 100644 index bc5535afb4..0000000000 --- a/proto/lbm/fswap/v1/params.proto +++ /dev/null @@ -1,12 +0,0 @@ -syntax = "proto3"; -package lbm.fswap.v1; - -option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types"; - -import "gogoproto/gogo.proto"; - -// Params defines the parameters for the module. -message Params { - option (gogoproto.goproto_stringer) = false; - string swappable_new_coin_amount = 1 [(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Int", (gogoproto.nullable) = false]; -} \ No newline at end of file diff --git a/proto/lbm/fswap/v1/query.proto b/proto/lbm/fswap/v1/query.proto index 5b2e0d02e9..a2a88b7093 100644 --- a/proto/lbm/fswap/v1/query.proto +++ b/proto/lbm/fswap/v1/query.proto @@ -5,28 +5,51 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types"; import "google/api/annotations.proto"; import "gogoproto/gogo.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; import "cosmos/base/v1beta1/coin.proto"; import "lbm/fswap/v1/fswap.proto"; service Query { + // Swapped queries the current swapped status that includes a burnt amount of from-coin and a minted amount of + // to-coin. rpc Swapped(QuerySwappedRequest) returns (QuerySwappedResponse) { option (google.api.http).get = "/lbm/fswap/v1/swapped"; } - rpc TotalNewCurrencySwapLimit(QueryTotalSwappableAmountRequest) returns (QueryTotalSwappableAmountResponse) { - option (google.api.http).get = "/lbm/fswap/v1/swappable_new_coin_amount"; + // TotalSwappableToCoinAmount queries the current swappable amount for to-coin. + rpc TotalSwappableToCoinAmount(QueryTotalSwappableToCoinAmountRequest) + returns (QueryTotalSwappableToCoinAmountResponse) { + option (google.api.http).get = "/lbm/fswap/v1/total_swappable_to_coin_amount"; + } + // Swaps queries all the swap that registered + rpc Swaps(QuerySwapsRequest) returns (QuerySwapsResponse) { + option (google.api.http).get = "/lbm/fswap/v1/swaps"; } } -message QuerySwappedRequest {} +message QuerySwappedRequest { + string fromDenom = 1; + string toDenom = 2; +} message QuerySwappedResponse { - cosmos.base.v1beta1.Coin old_coin = 1 + cosmos.base.v1beta1.Coin from_coin_amount = 1 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; - cosmos.base.v1beta1.Coin new_coin = 2 + cosmos.base.v1beta1.Coin to_coin_amount = 2 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; } -message QueryTotalSwappableAmountRequest {} -message QueryTotalSwappableAmountResponse { - cosmos.base.v1beta1.Coin swappable_new_coin = 1 +message QueryTotalSwappableToCoinAmountRequest { + string fromDenom = 1; + string toDenom = 2; +} +message QueryTotalSwappableToCoinAmountResponse { + cosmos.base.v1beta1.Coin swappable_amount = 1 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; } + +message QuerySwapsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} +message QuerySwapsResponse { + repeated Swap swaps = 1 [(gogoproto.nullable) = false]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} \ No newline at end of file diff --git a/proto/lbm/fswap/v1/tx.proto b/proto/lbm/fswap/v1/tx.proto index c9b3c171bc..07813f9eab 100644 --- a/proto/lbm/fswap/v1/tx.proto +++ b/proto/lbm/fswap/v1/tx.proto @@ -7,23 +7,26 @@ import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; service Msg { - rpc Swap(MsgSwapRequest) returns (MsgSwapResponse); - rpc SwapAll(MsgSwapAllRequest) returns (MsgSwapAllResponse); + rpc Swap(MsgSwap) returns (MsgSwapResponse); + rpc SwapAll(MsgSwapAll) returns (MsgSwapAllResponse); } -message MsgSwapRequest { +message MsgSwap { // holder's address string from_address = 1; - // amount of old currency - cosmos.base.v1beta1.Coin amount = 2 + // from-coin amount + cosmos.base.v1beta1.Coin from_coin_amount = 2 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; + string to_denom = 3; } message MsgSwapResponse {} -message MsgSwapAllRequest { +message MsgSwapAll { // holder's address string from_address = 1; + string from_denom = 2; + string to_denom = 3; } message MsgSwapAllResponse {} diff --git a/simapp/app.go b/simapp/app.go index f6ce763cdd..7bb68f2e01 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -76,6 +76,7 @@ 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" @@ -133,6 +134,7 @@ var ( upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler, foundationclient.ProposalHandler, + fswapclient.ProposalHandler, ), params.AppModuleBasic{}, crisis.AppModuleBasic{}, @@ -159,6 +161,7 @@ var ( stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, govtypes.ModuleName: {authtypes.Burner}, fbridgetypes.ModuleName: {authtypes.Burner}, + fswaptypes.ModuleName: {authtypes.Burner, authtypes.Minter}, } // module accounts that are allowed to receive tokens @@ -340,13 +343,17 @@ 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) + // register the proposal types govRouter := govtypes.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). 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(foundation.RouterKey, foundationkeeper.NewFoundationProposalsHandler(app.FoundationKeeper)). + AddRoute(fswaptypes.RouterKey, fswap.NewSwapHandler(app.FswapKeeper)) govKeeper := govkeeper.NewKeeper( appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, @@ -366,10 +373,6 @@ func NewSimApp( // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper - /**** Phase 1 ****/ - fswapConfig := fswaptypes.DefaultConfig() - app.FswapKeeper = fswapkeeper.NewKeeper(appCodec, keys[fswaptypes.StoreKey], app.AccountKeeper, app.BankKeeper, fswapConfig) - app.FbridgeKeeper = fbridgekeeper.NewKeeper(appCodec, keys[fbridgetypes.StoreKey], app.AccountKeeper, app.BankKeeper, "stake", authtypes.NewModuleAddress(govtypes.ModuleName).String()) /**** Module Options ****/ @@ -403,7 +406,7 @@ func NewSimApp( tokenmodule.NewAppModule(appCodec, app.TokenKeeper), collectionmodule.NewAppModule(appCodec, app.CollectionKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - fswap.NewAppModule(appCodec, app.FswapKeeper, app.AccountKeeper, app.BankKeeper), + fswap.NewAppModule(appCodec, app.FswapKeeper, app.BankKeeper), fbridgemodule.NewAppModule(appCodec, app.FbridgeKeeper), ) diff --git a/x/ERRORS.md b/x/ERRORS.md index 8ed09149f9..dcf56afb65 100644 --- a/x/ERRORS.md +++ b/x/ERRORS.md @@ -177,9 +177,10 @@ |Error Name|Codespace|Code|Description| |:-|:-|:-|:-| -|ErrParamsNotFound|fswap|1100|params does not exist| -|ErrSwappedNotFound|fswap|1101|swapped does not exist| -|ErrExceedSwappable|fswap|1102|exceed swappable coin amount| +|ErrInvalidState|fswap|2|swap module invalid state| +|ErrCanNotHaveMoreSwap|fswap|3|no more swap allowed| +|ErrSwappedNotFound|fswap|4|swapped does not exist| +|ErrExceedSwappableToCoinAmount|fswap|5|exceed swappable to-coin amount| >You can also find detailed information in the following Errors.go files: * [fswap/types/errors.go](fswap/types/errors.go) diff --git a/x/fswap/client/cli/query.go b/x/fswap/client/cli/query.go index 55ec1d2bd1..46c87aa868 100644 --- a/x/fswap/client/cli/query.go +++ b/x/fswap/client/cli/query.go @@ -14,7 +14,7 @@ import ( func GetQueryCmd(queryRoute string) *cobra.Command { // Group fswap queries under a subcommand cmd := &cobra.Command{ - Use: types.ModuleName, + Use: queryRoute, Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, @@ -24,23 +24,27 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand( CmdQuerySwapped(), CmdQueryTotalSwappableAmount(), + CmdQuerySwaps(), ) return cmd } func CmdQuerySwapped() *cobra.Command { cmd := &cobra.Command{ - Use: "fswap swapped", + Use: "swapped [from_denom] [to_denom]", Short: "shows the current swap status, including both old and new coin amount", - Args: cobra.NoArgs, + 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) - - res, err := queryClient.Swapped(cmd.Context(), &types.QuerySwappedRequest{}) + req := &types.QuerySwappedRequest{ + FromDenom: args[0], + ToDenom: args[1], + } + res, err := queryClient.Swapped(cmd.Context(), req) if err != nil { return err } @@ -55,8 +59,37 @@ func CmdQuerySwapped() *cobra.Command { func CmdQueryTotalSwappableAmount() *cobra.Command { cmd := &cobra.Command{ - Use: "fswap total-swappable-amount", + Use: "total-swappable-amount [from_denom] [to_denom]", Short: "shows the current total amount of new coin that're swappable", + 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.QueryTotalSwappableToCoinAmountRequest{ + FromDenom: args[0], + ToDenom: args[1], + } + res, err := queryClient.TotalSwappableToCoinAmount(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", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) @@ -65,7 +98,7 @@ func CmdQueryTotalSwappableAmount() *cobra.Command { } queryClient := types.NewQueryClient(clientCtx) - res, err := queryClient.TotalNewCurrencySwapLimit(cmd.Context(), &types.QueryTotalSwappableAmountRequest{}) + res, err := queryClient.Swaps(cmd.Context(), &types.QuerySwapsRequest{}) if err != nil { return err } diff --git a/x/fswap/client/cli/tx.go b/x/fswap/client/cli/tx.go index 9b2f915ab7..433c8ae33e 100644 --- a/x/fswap/client/cli/tx.go +++ b/x/fswap/client/cli/tx.go @@ -1,8 +1,8 @@ package cli import ( + "encoding/json" "fmt" - "time" "github.com/spf13/cobra" @@ -10,10 +10,19 @@ import ( "github.com/Finschia/finschia-sdk/client/flags" "github.com/Finschia/finschia-sdk/client/tx" 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" + govcli "github.com/Finschia/finschia-sdk/x/gov/client/cli" + gov "github.com/Finschia/finschia-sdk/x/gov/types" ) -var DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds()) +const ( + FlagFromDenom = "from-denom" + FlagToDenom = "to-denom" + FlagAmountCapForToDenom = "to-coin-amount-cap" + FlagSwapRate = "swap-rate" +) // GetTxCmd returns the transaction commands for this module func GetTxCmd() *cobra.Command { @@ -34,26 +43,31 @@ func GetTxCmd() *cobra.Command { func CmdTxMsgSwap() *cobra.Command { cmd := &cobra.Command{ - Use: "fswap swap [address] [fnsa_amount]", - Short: "swap amounts of old coin to new coin. Note, the'--from' flag is ignored as it is implied from [address].", - Args: cobra.ExactArgs(2), + Use: "swap [from] [from_coin_amount] [to_denom]", + Short: "swap amount of from-coin to to-coin", + Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { - if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil { + from := args[0] + if err := cmd.Flags().Set(flags.FlagFrom, from); err != nil { return err } + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } - coin, err := sdk.ParseCoinNormalized(args[2]) + amount, err := sdk.ParseCoinNormalized(args[1]) if err != nil { return err } - msg := &types.MsgSwapRequest{ - FromAddress: clientCtx.GetFromAddress().String(), - Amount: coin, + toDenom := args[2] + + msg := &types.MsgSwap{ + FromAddress: from, + FromCoinAmount: amount, + ToDenom: toDenom, } if err := msg.ValidateBasic(); err != nil { return err @@ -68,24 +82,31 @@ func CmdTxMsgSwap() *cobra.Command { func CmdTxMsgSwapAll() *cobra.Command { cmd := &cobra.Command{ - Use: "fswap swap-all [address]", - Short: "swap all the old coins. Note, the'--from' flag is ignored as it is implied from [address].", - Args: cobra.ExactArgs(1), + Use: "swap-all [from_address] [from_denom] [to_denom]", + Short: "swap all the from-coin to to-coin", + Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { - if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil { + from := args[0] + if err := cmd.Flags().Set(flags.FlagFrom, from); err != nil { return err } + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } - msg := &types.MsgSwapAllRequest{ + fromDenom := args[1] + toDenom := args[2] + msg := &types.MsgSwapAll{ FromAddress: clientCtx.GetFromAddress().String(), + FromDenom: fromDenom, + ToDenom: toDenom, } if err := msg.ValidateBasic(); err != nil { return err } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } @@ -93,3 +114,142 @@ func CmdTxMsgSwapAll() *cobra.Command { flags.AddTxFlagsToCmd(cmd) return cmd } + +// NewCmdMakeSwapProposal implements a command handler for submitting a swap init proposal transaction. +func NewCmdMakeSwapProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "make-swap [messages-json]", + Args: cobra.ExactArgs(1), + Short: "todo", + Long: ` +Parameters: + messages-json: messages in json format that will be executed if the proposal is accepted. + +Example of the content of messages-json: + +{ + "metadata": { + "description": "the base coin of Finschia mainnet", + "denom_units": [ + { + "denom": "cony", + "exponent": 0, + "aliases": [ + "microfinschia" + ] + }, + { + "denom": "finschia", + "exponent": 6, + "aliases": [] + } + ], + "base": "cony", + "display": "finschia", + "name": "FINSCHIA", + "symbol": "FNSA" + } +} +`, + 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 { + return err + } + + description, err := cmd.Flags().GetString(govcli.FlagDescription) + if err != nil { + return err + } + + fromDenom, err := cmd.Flags().GetString(FlagFromDenom) + if err != nil { + return err + } + + toDenom, err := cmd.Flags().GetString(FlagToDenom) + 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()) + } + + swapRate, err := cmd.Flags().GetString(FlagSwapRate) + if err != nil { + return err + } + swapRateDec, err := sdk.NewDecFromStr(swapRate) + if err != nil { + return err + } + swap := types.Swap{ + FromDenom: fromDenom, + ToDenom: toDenom, + AmountCapForToDenom: amountCap, + 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) + if err != nil { + return err + } + + msg, err := gov.NewMsgSubmitProposal(content, deposit, from) + if err != nil { + return err + } + + 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") + + return cmd +} + +func parseToDenomMetadata(jsonDenomMetadata string) (bank.Metadata, error) { + type toDenomMeta struct { + Metadata bank.Metadata `json:"metadata"` + } + denomMeta := toDenomMeta{} + if err := json.Unmarshal([]byte(jsonDenomMetadata), &denomMeta); err != nil { + return bank.Metadata{}, err + } + + if err := denomMeta.Metadata.Validate(); err != nil { + return bank.Metadata{}, err + } + + return denomMeta.Metadata, nil +} diff --git a/x/fswap/client/proposal_handler.go b/x/fswap/client/proposal_handler.go new file mode 100644 index 0000000000..72c073b733 --- /dev/null +++ b/x/fswap/client/proposal_handler.go @@ -0,0 +1,8 @@ +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 new file mode 100644 index 0000000000..7cbd4f6a69 --- /dev/null +++ b/x/fswap/codec/codec.go @@ -0,0 +1,18 @@ +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 index 2e3dae3f45..7bae485c7e 100644 --- a/x/fswap/handler.go +++ b/x/fswap/handler.go @@ -1,26 +1,27 @@ package fswap import ( - "fmt" - 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" ) -// NewHandler ... -func NewHandler(k keeper.Keeper) sdk.Handler { - // this line is used by starport scaffolding # handler/msgServer - - return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - // ctx = ctx.WithEventManager(sdk.NewEventManager()) +// 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) - // switch msg := msg.(type) { - // this line is used by starport scaffolding # 1 - // default: - errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) - // } + 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/calc.go b/x/fswap/keeper/calc.go new file mode 100644 index 0000000000..930bfdbf43 --- /dev/null +++ b/x/fswap/keeper/calc.go @@ -0,0 +1,7 @@ +package keeper + +import "github.com/Finschia/finschia-sdk/types" + +func CalcSwap(swapRate types.Dec, fromCoinAmount types.Int) types.Int { + return swapRate.MulTruncate(types.NewDecFromBigInt(fromCoinAmount.BigInt())).TruncateInt() +} diff --git a/x/fswap/keeper/calc_test.go b/x/fswap/keeper/calc_test.go new file mode 100644 index 0000000000..ed8cece9f5 --- /dev/null +++ b/x/fswap/keeper/calc_test.go @@ -0,0 +1,65 @@ +package keeper + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + sdk "github.com/Finschia/finschia-sdk/types" +) + +func TestCalcSwap(t *testing.T) { + rateDot5, err := sdk.NewDecFromStr("0.5") + require.NoError(t, err) + rateDot3maxPrecision, err := sdk.NewDecFromStr("0.333333333333333333") + require.NoError(t, err) + + finschiaSwapRate, err := sdk.NewDecFromStr("148.079656") + require.NoError(t, err) + conySwapRate := finschiaSwapRate.Mul(sdk.NewDec(1000000)) + pebSwapRateForCony, err := sdk.NewDecFromStr("148079656000000") + require.NoError(t, err) + testCases := map[string]struct { + fromAmount sdk.Int + expectedAmount sdk.Int + swapRate sdk.Dec + }{ + "swapRate 0.5": { + fromAmount: sdk.ZeroInt(), + swapRate: rateDot5, + expectedAmount: sdk.ZeroInt(), + }, + "swapRate 0.333333333333333333": { + fromAmount: sdk.NewInt(3), + swapRate: rateDot3maxPrecision, + expectedAmount: sdk.ZeroInt(), + }, + "swapRate conySwapRate(148.079656 * 10^6) fromAmount(1)": { + fromAmount: sdk.NewInt(1), + swapRate: conySwapRate, + expectedAmount: sdk.NewInt(148079656), + }, + "swapRate conySwapRate(148.079656 * 10^6) fromAmount(3)": { + fromAmount: sdk.NewInt(3), + swapRate: conySwapRate, + expectedAmount: sdk.NewInt(444238968), + }, + "pebSwapRateForCony pebSwapRateForCony(148.079656 * 10^12) fromAmount(1)": { + fromAmount: sdk.NewInt(1), + swapRate: pebSwapRateForCony, + expectedAmount: sdk.NewInt(148079656000000), + }, + "pebSwapRateForCony pebSwapRateForCony(148.079656 * 10^12) fromAmount(3)": { + fromAmount: sdk.NewInt(3), + swapRate: pebSwapRateForCony, + expectedAmount: sdk.NewInt(444238968000000), + }, + } + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + actualAmount := CalcSwap(tc.swapRate, tc.fromAmount) + require.Equal(t, tc.expectedAmount, actualAmount, fmt.Sprintf("tc.expectedAmount = %v, actualAmount = %v", tc.expectedAmount, actualAmount)) + }) + } +} diff --git a/x/fswap/keeper/expected_keepers.go b/x/fswap/keeper/expected_keepers.go new file mode 100644 index 0000000000..08934e1c3c --- /dev/null +++ b/x/fswap/keeper/expected_keepers.go @@ -0,0 +1,19 @@ +package keeper + +import ( + sdk "github.com/Finschia/finschia-sdk/types" + banktypes "github.com/Finschia/finschia-sdk/x/bank/types" +) + +type ( + BankKeeper interface { + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error + GetDenomMetaData(ctx sdk.Context, denom string) (banktypes.Metadata, bool) + SetDenomMetaData(ctx sdk.Context, denomMetaData banktypes.Metadata) + MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error + BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error + } +) diff --git a/x/fswap/keeper/fswap.go b/x/fswap/keeper/fswap.go deleted file mode 100644 index 6100dfa111..0000000000 --- a/x/fswap/keeper/fswap.go +++ /dev/null @@ -1,30 +0,0 @@ -package keeper - -import ( - sdk "github.com/Finschia/finschia-sdk/types" - "github.com/Finschia/finschia-sdk/x/fswap/types" -) - -// GetSwapped get all parameters as types.Swapped -func (k Keeper) GetSwapped(ctx sdk.Context) types.Swapped { - store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte{types.SwappedKey}) - var swapped types.Swapped - - if bz == nil { - panic(types.ErrSwappedNotFound) - } - k.cdc.MustUnmarshal(bz, &swapped) - return swapped -} - -// SetSwapped set the types.Swapped -func (k Keeper) SetSwapped(ctx sdk.Context, swapped types.Swapped) error { - store := ctx.KVStore(k.storeKey) - bz, err := k.cdc.Marshal(&swapped) - if err != nil { - return err - } - store.Set([]byte{types.SwappedKey}, bz) - return nil -} diff --git a/x/fswap/keeper/genesis.go b/x/fswap/keeper/genesis.go index 4cb0edd5e6..d27c80785a 100644 --- a/x/fswap/keeper/genesis.go +++ b/x/fswap/keeper/genesis.go @@ -5,21 +5,53 @@ import ( "github.com/Finschia/finschia-sdk/x/fswap/types" ) -// InitGenesis initializes the module's state from a provided genesis -// state. -func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { - if err := k.SetParams(ctx, genState.Params); err != nil { - panic(err) +// InitGenesis initializes the module's state from a provided genesis state. +func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) error { + if err := genState.Validate(); err != nil { + return err } - if err := k.SetSwapped(ctx, genState.Swapped); err != nil { - panic(err) + + if len(genState.GetSwaps()) > k.config.MaxSwaps && !k.isUnlimited() { + return types.ErrCanNotHaveMoreSwap.Wrapf("cannot initialize genesis state, there are more than %d swaps", k.config.MaxSwaps) + } + + if len(genState.GetSwappeds()) > k.config.MaxSwaps && !k.isUnlimited() { + return types.ErrCanNotHaveMoreSwap.Wrapf("cannot initialize genesis state, there are more than %d swapped", k.config.MaxSwaps) + } + + if err := k.setSwapStats(ctx, genState.GetSwapStats()); err != nil { + return err + } + + for _, swap := range genState.GetSwaps() { + if err := k.setSwap(ctx, swap); err != nil { + panic(err) + } + } + + for _, swapped := range genState.GetSwappeds() { + err := k.setSwapped(ctx, swapped) + if err != nil { + return err + } } + + return nil } -// ExportGenesis returns the capability module's exported genesis. +func (k Keeper) isUnlimited() bool { + return k.config.MaxSwaps == 0 +} + +// ExportGenesis returns the module's exported genesis. func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + stats, err := k.getSwapStats(ctx) + if err != nil { + panic(err) + } return &types.GenesisState{ - Params: k.GetParams(ctx), - Swapped: k.GetSwapped(ctx), + Swaps: k.getAllSwaps(ctx), + SwapStats: stats, + Swappeds: k.getAllSwapped(ctx), } } diff --git a/x/fswap/keeper/genesis_test.go b/x/fswap/keeper/genesis_test.go index ae0e07e275..c4fa1a0e99 100644 --- a/x/fswap/keeper/genesis_test.go +++ b/x/fswap/keeper/genesis_test.go @@ -1,13 +1,21 @@ package keeper_test import ( + "fmt" + "github.com/Finschia/finschia-sdk/x/fswap/types" ) func (s *KeeperTestSuite) TestInitAndExportGenesis() { - s.keeper.InitGenesis(s.sdkCtx, *types.DefaultGenesis()) - got := s.keeper.ExportGenesis(s.sdkCtx) - s.Require().NotNil(got) - s.Require().Equal(types.DefaultParams(), got.Params) - s.Require().Equal(types.DefaultSwapped(), got.Swapped) + ctx, _ := s.ctx.CacheContext() + defaultGenesis := types.DefaultGenesis() + err := s.keeper.InitGenesis(ctx, defaultGenesis) + s.Require().NoError(err) + + exportGenesis := s.keeper.ExportGenesis(ctx) + fmt.Println(len(exportGenesis.GetSwaps())) + s.Require().Equal(defaultGenesis, exportGenesis) + s.Require().Equal(defaultGenesis.GetSwaps(), exportGenesis.GetSwaps()) + s.Require().Equal(defaultGenesis.GetSwapStats(), exportGenesis.GetSwapStats()) + s.Require().Equal(defaultGenesis.GetSwappeds(), exportGenesis.GetSwappeds()) } diff --git a/x/fswap/keeper/grpc_query.go b/x/fswap/keeper/grpc_query.go index b55b7c1155..def3ee5ffb 100644 --- a/x/fswap/keeper/grpc_query.go +++ b/x/fswap/keeper/grpc_query.go @@ -3,17 +3,68 @@ package keeper import ( "context" + "github.com/Finschia/finschia-sdk/store/prefix" + sdk "github.com/Finschia/finschia-sdk/types" + "github.com/Finschia/finschia-sdk/types/query" "github.com/Finschia/finschia-sdk/x/fswap/types" ) -var _ types.QueryServer = Keeper{} +var _ types.QueryServer = QueryServer{} -// Swapped implements types.QueryServer. -func (k Keeper) Swapped(context.Context, *types.QuerySwappedRequest) (*types.QuerySwappedResponse, error) { - panic("unimplemented") +type QueryServer struct { + Keeper } -// TotalNewCurrencySwapLimit implements types.QueryServer. -func (k Keeper) TotalNewCurrencySwapLimit(context.Context, *types.QueryTotalSwappableAmountRequest) (*types.QueryTotalSwappableAmountResponse, error) { - panic("unimplemented") +func NewQueryServer(keeper Keeper) *QueryServer { + return &QueryServer{ + keeper, + } +} + +func (s QueryServer) Swapped(ctx context.Context, req *types.QuerySwappedRequest) (*types.QuerySwappedResponse, error) { + c := sdk.UnwrapSDKContext(ctx) + + swapped, err := s.Keeper.getSwapped(c, req.GetFromDenom(), req.GetToDenom()) + if err != nil { + return nil, err + } + + return &types.QuerySwappedResponse{ + FromCoinAmount: swapped.GetFromCoinAmount(), + ToCoinAmount: swapped.GetToCoinAmount(), + }, nil +} + +func (s QueryServer) TotalSwappableToCoinAmount(ctx context.Context, req *types.QueryTotalSwappableToCoinAmountRequest) (*types.QueryTotalSwappableToCoinAmountResponse, error) { + c := sdk.UnwrapSDKContext(ctx) + + amount, err := s.Keeper.getSwappableNewCoinAmount(c, req.GetFromDenom(), req.GetToDenom()) + if err != nil { + return &types.QueryTotalSwappableToCoinAmountResponse{}, err + } + + return &types.QueryTotalSwappableToCoinAmountResponse{SwappableAmount: amount}, nil +} + +func (s QueryServer) Swaps(ctx context.Context, req *types.QuerySwapsRequest) (*types.QuerySwapsResponse, error) { + c := sdk.UnwrapSDKContext(ctx) + + swaps := []types.Swap{} + store := c.KVStore(s.storeKey) + swapStore := prefix.NewStore(store, swapPrefix) + pageResponse, err := query.Paginate(swapStore, req.Pagination, func(key, value []byte) error { + swap := types.Swap{} + if err := s.Keeper.cdc.Unmarshal(value, &swap); err != nil { + return err + } + swaps = append(swaps, swap) + return nil + }) + if err != nil { + return nil, err + } + return &types.QuerySwapsResponse{ + Swaps: swaps, + Pagination: pageResponse, + }, nil } diff --git a/x/fswap/keeper/grpc_query_params_test.go b/x/fswap/keeper/grpc_query_params_test.go deleted file mode 100644 index 9429264902..0000000000 --- a/x/fswap/keeper/grpc_query_params_test.go +++ /dev/null @@ -1 +0,0 @@ -package keeper_test diff --git a/x/fswap/keeper/keeper.go b/x/fswap/keeper/keeper.go index 3036a079e2..f21a246cea 100644 --- a/x/fswap/keeper/keeper.go +++ b/x/fswap/keeper/keeper.go @@ -6,37 +6,198 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/Finschia/finschia-sdk/codec" + "github.com/Finschia/finschia-sdk/store/prefix" storetypes "github.com/Finschia/finschia-sdk/store/types" sdk "github.com/Finschia/finschia-sdk/types" "github.com/Finschia/finschia-sdk/x/fswap/types" ) -type ( - Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - config types.Config - } -) +type Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + + config types.Config + + BankKeeper +} -func NewKeeper( - cdc codec.BinaryCodec, - storeKey storetypes.StoreKey, - ak types.AccountKeeper, - bk types.BankKeeper, - config types.Config, -) Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, config types.Config, bk BankKeeper) Keeper { return Keeper{ - cdc: cdc, - storeKey: storeKey, - accountKeeper: ak, - bankKeeper: bk, - config: config, + cdc, + storeKey, + config, + bk, } } func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } + +func (k Keeper) Swap(ctx sdk.Context, addr sdk.AccAddress, fromCoinAmount sdk.Coin, toDenom string) error { + swap, err := k.getSwap(ctx, fromCoinAmount.Denom, toDenom) + if err != nil { + return err + } + + newCoinAmountInt := CalcSwap(swap.SwapRate, fromCoinAmount.Amount) + newCoinAmount := sdk.NewCoin(toDenom, newCoinAmountInt) + swapped, err := k.getSwapped(ctx, swap.GetFromDenom(), swap.GetToDenom()) + if err != nil { + return err + } + + updateSwapped, err := k.updateSwapped(ctx, swapped, fromCoinAmount, newCoinAmount) + if err != nil { + return err + } + + if err := k.checkSwapCap(swap, updateSwapped); err != nil { + return err + } + + if err := k.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, sdk.NewCoins(fromCoinAmount)); err != nil { + return err + } + + if err := k.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(fromCoinAmount)); err != nil { + return err + } + + if err := k.MintCoins(ctx, types.ModuleName, sdk.NewCoins(newCoinAmount)); err != nil { + return err + } + + if err := k.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr, sdk.NewCoins(newCoinAmount)); err != nil { + return err + } + + if err := ctx.EventManager().EmitTypedEvent(&types.EventSwapCoins{ + Address: addr.String(), + FromCoinAmount: fromCoinAmount, + ToCoinAmount: newCoinAmount, + }); err != nil { + return err + } + return nil +} + +func (k Keeper) getAllSwapped(ctx sdk.Context) []types.Swapped { + swappedSlice := []types.Swapped{} + k.iterateAllSwapped(ctx, func(swapped types.Swapped) bool { + swappedSlice = append(swappedSlice, swapped) + return false + }) + return swappedSlice +} + +func (k Keeper) iterateAllSwapped(ctx sdk.Context, cb func(swapped types.Swapped) (stop bool)) { + store := ctx.KVStore(k.storeKey) + swappedDataStore := prefix.NewStore(store, swappedKeyPrefix) + + iterator := swappedDataStore.Iterator(nil, nil) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + swapped := types.Swapped{} + k.cdc.MustUnmarshal(iterator.Value(), &swapped) + if cb(swapped) { + break + } + } +} + +func (k Keeper) getSwapped(ctx sdk.Context, fromDenom, toDenom string) (types.Swapped, error) { + store := ctx.KVStore(k.storeKey) + key := swappedKey(fromDenom, toDenom) + bz := store.Get(key) + if bz == nil { + return types.Swapped{}, types.ErrSwappedNotFound + } + + swapped := types.Swapped{} + if err := k.cdc.Unmarshal(bz, &swapped); err != nil { + return types.Swapped{}, err + } + return swapped, nil +} + +func (k Keeper) setSwapped(ctx sdk.Context, swapped types.Swapped) error { + key := swappedKey(swapped.FromCoinAmount.Denom, swapped.ToCoinAmount.Denom) + bz, err := k.cdc.Marshal(&swapped) + if err != nil { + return err + } + + store := ctx.KVStore(k.storeKey) + store.Set(key, bz) + return nil +} + +func (k Keeper) getSwappableNewCoinAmount(ctx sdk.Context, fromDenom, toDenom string) (sdk.Coin, error) { + swap, err := k.getSwap(ctx, fromDenom, toDenom) + if err != nil { + return sdk.Coin{}, err + } + + swapped, err := k.getSwapped(ctx, fromDenom, toDenom) + if err != nil { + return sdk.Coin{}, err + } + + swapCap := swap.AmountCapForToDenom + remainingAmount := swapCap.Sub(swapped.GetToCoinAmount().Amount) + + return sdk.NewCoin(toDenom, remainingAmount), nil +} + +func (k Keeper) updateSwapped(ctx sdk.Context, curSwapped types.Swapped, fromAmount, toAmount sdk.Coin) (types.Swapped, error) { + updatedSwapped := types.Swapped{ + FromCoinAmount: fromAmount.Add(curSwapped.FromCoinAmount), + ToCoinAmount: toAmount.Add(curSwapped.ToCoinAmount), + } + + key := swappedKey(fromAmount.Denom, toAmount.Denom) + bz, err := k.cdc.Marshal(&updatedSwapped) + if err != nil { + return types.Swapped{}, err + } + + store := ctx.KVStore(k.storeKey) + store.Set(key, bz) + return updatedSwapped, nil +} + +func (k Keeper) checkSwapCap(swap types.Swap, swapped types.Swapped) error { + swapCap := swap.AmountCapForToDenom + if swapCap.LT(swapped.ToCoinAmount.Amount) { + return types.ErrExceedSwappableToCoinAmount + } + return nil +} + +func (k Keeper) getSwapStats(ctx sdk.Context) (types.SwapStats, error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(swapStatsKey) + if bz == nil { + return types.SwapStats{}, nil + } + + stats := types.SwapStats{} + err := k.cdc.Unmarshal(bz, &stats) + if err != nil { + return types.SwapStats{}, err + } + return stats, nil +} + +func (k Keeper) setSwapStats(ctx sdk.Context, stats types.SwapStats) error { + bz, err := k.cdc.Marshal(&stats) + if err != nil { + return err + } + + store := ctx.KVStore(k.storeKey) + store.Set(swapStatsKey, bz) + return nil +} diff --git a/x/fswap/keeper/keeper_test.go b/x/fswap/keeper/keeper_test.go index dc87a7e267..fdf9e95d25 100644 --- a/x/fswap/keeper/keeper_test.go +++ b/x/fswap/keeper/keeper_test.go @@ -4,40 +4,186 @@ import ( "context" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/Finschia/finschia-sdk/crypto/keys/secp256k1" "github.com/Finschia/finschia-sdk/simapp" + "github.com/Finschia/finschia-sdk/testutil/testdata" 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/keeper" - "github.com/Finschia/finschia-sdk/x/fswap/testutil" "github.com/Finschia/finschia-sdk/x/fswap/types" + minttypes "github.com/Finschia/finschia-sdk/x/mint/types" ) type KeeperTestSuite struct { suite.Suite - sdkCtx sdk.Context - goCtx context.Context - keeper keeper.Keeper - bankKeeper types.BankKeeper - msgServer types.MsgServer + ctx sdk.Context + goCtx context.Context + keeper keeper.Keeper + queryServer types.QueryServer + msgServer types.MsgServer + + accWithFromCoin sdk.AccAddress + accWithToCoin sdk.AccAddress + initBalance sdk.Int + + swap types.Swap + toDenomMetadata bank.Metadata } -func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(KeeperTestSuite)) +func (s *KeeperTestSuite) createRandomAccounts(n int) []sdk.AccAddress { + seenAddresses := make(map[string]bool, n) + addresses := make([]sdk.AccAddress, n) + for i := range addresses { + var address sdk.AccAddress + for { + pk := secp256k1.GenPrivKey().PubKey() + address = sdk.AccAddress(pk.Address()) + if !seenAddresses[address.String()] { + seenAddresses[address.String()] = true + break + } + } + addresses[i] = address + } + return addresses } func (s *KeeperTestSuite) SetupTest() { - ctrl := gomock.NewController(s.T()) - bankKeeper := testutil.NewMockBankKeeper(ctrl) - s.bankKeeper = bankKeeper checkTx := false app := simapp.Setup(checkTx) - s.sdkCtx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) - s.goCtx = sdk.WrapSDKContext(s.sdkCtx) + testdata.RegisterInterfaces(app.InterfaceRegistry()) + testdata.RegisterMsgServer(app.MsgServiceRouter(), testdata.MsgServerImpl{}) + s.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) + s.goCtx = sdk.WrapSDKContext(s.ctx) s.keeper = app.FswapKeeper + s.queryServer = keeper.NewQueryServer(s.keeper) + s.msgServer = keeper.NewMsgServer(s.keeper) + + numAcc := int64(2) + s.initBalance = sdk.NewInt(123456789) + pebSwapRateForCony, err := sdk.NewDecFromStr("148079656000000") + s.Require().NoError(err) + swapCap := sdk.NewIntFromBigInt(pebSwapRateForCony.Mul(s.initBalance.ToDec()).BigInt()) + swapCap = swapCap.Mul(sdk.NewInt(numAcc)) + s.Require().NoError(err) + s.swap = types.Swap{ + FromDenom: "fromdenom", + ToDenom: "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: "dummy", + Display: "dummycoin", + Name: "DUMMY", + Symbol: "DUM", + } + s.createAccountsWithInitBalance(app) + app.AccountKeeper.GetModuleAccount(s.ctx, types.ModuleName) +} + +func (s *KeeperTestSuite) createAccountsWithInitBalance(app *simapp.SimApp) { + addresses := []*sdk.AccAddress{ + &s.accWithFromCoin, + &s.accWithToCoin, + } + for i, address := range s.createRandomAccounts(len(addresses)) { + *addresses[i] = address + } + minter := app.AccountKeeper.GetModuleAccount(s.ctx, minttypes.ModuleName).GetAddress() + fromAmount := sdk.NewCoins(sdk.NewCoin(s.swap.GetFromDenom(), s.initBalance)) + s.Require().NoError(app.BankKeeper.MintCoins(s.ctx, minttypes.ModuleName, fromAmount)) + s.Require().NoError(app.BankKeeper.SendCoins(s.ctx, minter, s.accWithFromCoin, fromAmount)) + + toAmount := sdk.NewCoins(sdk.NewCoin(s.swap.GetToDenom(), s.initBalance)) + s.Require().NoError(app.BankKeeper.MintCoins(s.ctx, minttypes.ModuleName, toAmount)) + s.Require().NoError(app.BankKeeper.SendCoins(s.ctx, minter, s.accWithToCoin, toAmount)) +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, &KeeperTestSuite{}) +} + +func (s *KeeperTestSuite) TestSwap() { + swap2ExpectedAmount, ok := sdk.NewIntFromString("296159312000000") + s.Require().True(ok) + swap100ExpectedAmount, ok := sdk.NewIntFromString("14807965600000000") + s.Require().True(ok) + swapAllExpectedBalance, ok := sdk.NewIntFromString("18281438845984584000000") + s.Require().True(ok) + testCases := map[string]struct { + from sdk.AccAddress + amountToSwap sdk.Coin + toDenom string + expectedAmount sdk.Int + shouldThrowError bool + expectedError error + }{ + "swap 2 from-denom": { + s.accWithFromCoin, + sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(2)), + s.swap.GetToDenom(), + swap2ExpectedAmount, + false, + nil, + }, + "swap some": { + s.accWithFromCoin, + sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(100)), + s.swap.GetToDenom(), + swap100ExpectedAmount, + false, + nil, + }, + "swap all the balance": { + s.accWithFromCoin, + sdk.NewCoin(s.swap.GetFromDenom(), s.initBalance), + s.swap.GetToDenom(), + swapAllExpectedBalance, + false, + nil, + }, + "swap without holding enough balance": { + s.accWithFromCoin, + sdk.NewCoin(s.swap.GetFromDenom(), sdk.OneInt().Add(s.initBalance)), + s.swap.GetToDenom(), + sdk.ZeroInt(), + true, + sdkerrors.ErrInsufficientFunds, + }, + "account holding new coin only": { + s.accWithToCoin, + sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(100)), + s.swap.GetToDenom(), + sdk.ZeroInt(), + true, + sdkerrors.ErrInsufficientFunds, + }, + } + for name, tc := range testCases { + s.Run(name, func() { + ctx, _ := s.ctx.CacheContext() + err := s.keeper.MakeSwap(ctx, s.swap, s.toDenomMetadata) + s.Require().NoError(err) + + err = s.keeper.Swap(ctx, tc.from, tc.amountToSwap, tc.toDenom) + if tc.shouldThrowError { + s.Require().ErrorIs(err, tc.expectedError) + return + } + s.Require().NoError(err) - s.msgServer = keeper.NewMsgServerImpl(s.keeper) + actualAmount := s.keeper.GetBalance(ctx, tc.from, s.swap.GetToDenom()).Amount + s.Require().Equal(tc.expectedAmount, actualAmount) + }) + } } diff --git a/x/fswap/keeper/keys.go b/x/fswap/keeper/keys.go new file mode 100644 index 0000000000..04e36660f8 --- /dev/null +++ b/x/fswap/keeper/keys.go @@ -0,0 +1,19 @@ +package keeper + +var ( + swapPrefix = []byte{0x01} + swapStatsKey = []byte{0x02} + swappedKeyPrefix = []byte{0x03} +) + +// swapKey key(prefix + fromDenom + toDenom) +func swapKey(fromDenom, toDenom string) []byte { + key := append(swapPrefix, fromDenom...) + return append(key, toDenom...) +} + +// swappedKey key(prefix + fromDenom + toDenom) +func swappedKey(fromDenom, toDenom string) []byte { + key := append(swappedKeyPrefix, fromDenom...) + return append(key, toDenom...) +} diff --git a/x/fswap/keeper/msg_server.go b/x/fswap/keeper/msg_server.go index 41b76b832a..1f3086fc4f 100644 --- a/x/fswap/keeper/msg_server.go +++ b/x/fswap/keeper/msg_server.go @@ -3,27 +3,60 @@ package keeper import ( "context" + sdk "github.com/Finschia/finschia-sdk/types" + sdkerrors "github.com/Finschia/finschia-sdk/types/errors" "github.com/Finschia/finschia-sdk/x/fswap/types" ) -type msgServer struct { - Keeper +var _ types.MsgServer = MsgServer{} + +type MsgServer struct { + keeper Keeper } -// NewMsgServerImpl returns an implementation of the MsgServer interface -// for the provided Keeper. -func NewMsgServerImpl(keeper Keeper) types.MsgServer { - return &msgServer{Keeper: keeper} +func NewMsgServer(keeper Keeper) *MsgServer { + return &MsgServer{keeper} } -var _ types.MsgServer = msgServer{} +func (s MsgServer) Swap(ctx context.Context, req *types.MsgSwap) (*types.MsgSwapResponse, error) { + c := sdk.UnwrapSDKContext(ctx) + + from, err := sdk.AccAddressFromBech32(req.FromAddress) + if err != nil { + return nil, err + } + + if err := s.keeper.IsSendEnabledCoins(c, req.GetFromCoinAmount()); err != nil { + return &types.MsgSwapResponse{}, err + } -// Swap implements types.MsgServer. -func (m msgServer) Swap(context.Context, *types.MsgSwapRequest) (*types.MsgSwapResponse, error) { - panic("unimplemented") + if err := s.keeper.Swap(c, from, req.GetFromCoinAmount(), req.GetToDenom()); err != nil { + return nil, err + } + + return &types.MsgSwapResponse{}, nil } -// SwapAll implements types.MsgServer. -func (m msgServer) SwapAll(context.Context, *types.MsgSwapAllRequest) (*types.MsgSwapAllResponse, error) { - panic("unimplemented") +func (s MsgServer) SwapAll(ctx context.Context, req *types.MsgSwapAll) (*types.MsgSwapAllResponse, error) { + c := sdk.UnwrapSDKContext(ctx) + + from, err := sdk.AccAddressFromBech32(req.FromAddress) + if err != nil { + return nil, err + } + + balance := s.keeper.GetBalance(c, from, req.FromDenom) + if balance.IsZero() { + return nil, sdkerrors.ErrInsufficientFunds + } + + if err := s.keeper.IsSendEnabledCoins(c, balance); err != nil { + return nil, err + } + + if err := s.keeper.Swap(c, from, balance, req.GetToDenom()); err != nil { + return nil, err + } + + return &types.MsgSwapAllResponse{}, nil } diff --git a/x/fswap/keeper/msg_server_test.go b/x/fswap/keeper/msg_server_test.go index 9429264902..6e7953ac64 100644 --- a/x/fswap/keeper/msg_server_test.go +++ b/x/fswap/keeper/msg_server_test.go @@ -1 +1,135 @@ package keeper_test + +import ( + sdk "github.com/Finschia/finschia-sdk/types" + sdkerrors "github.com/Finschia/finschia-sdk/types/errors" + "github.com/Finschia/finschia-sdk/x/fswap/types" +) + +func (s *KeeperTestSuite) TestMsgSwap() { + swap2ExpectedAmount, ok := sdk.NewIntFromString("296159312000000") + s.Require().True(ok) + swap100ExpectedAmount, ok := sdk.NewIntFromString("14807965600000000") + s.Require().True(ok) + swapAllExpectedBalance, ok := sdk.NewIntFromString("18281438845984584000000") + s.Require().True(ok) + testCases := map[string]struct { + request *types.MsgSwap + expectedAmount sdk.Int + shouldThrowError bool + expectedError error + }{ + "swap 2 from-denom": { + &types.MsgSwap{ + FromAddress: s.accWithFromCoin.String(), + FromCoinAmount: sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(2)), + ToDenom: s.swap.GetToDenom(), + }, + swap2ExpectedAmount, + false, + nil, + }, + "swap some": { + &types.MsgSwap{ + FromAddress: s.accWithFromCoin.String(), + FromCoinAmount: sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(100)), + ToDenom: s.swap.GetToDenom(), + }, + swap100ExpectedAmount, + false, + nil, + }, + "swap all the balance": { + &types.MsgSwap{ + FromAddress: s.accWithFromCoin.String(), + FromCoinAmount: sdk.NewCoin(s.swap.GetFromDenom(), s.initBalance), + ToDenom: s.swap.GetToDenom(), + }, + swapAllExpectedBalance, + false, + nil, + }, + "account holding to-coin only": { + &types.MsgSwap{ + FromAddress: s.accWithToCoin.String(), + FromCoinAmount: sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(100)), + ToDenom: s.swap.GetToDenom(), + }, + sdk.ZeroInt(), + true, + sdkerrors.ErrInsufficientFunds, + }, + } + for name, tc := range testCases { + s.Run(name, func() { + ctx, _ := s.ctx.CacheContext() + err := s.keeper.MakeSwap(ctx, s.swap, s.toDenomMetadata) + s.Require().NoError(err) + + swapResponse, err := s.msgServer.Swap(sdk.WrapSDKContext(ctx), tc.request) + if tc.shouldThrowError { + s.Require().ErrorIs(err, tc.expectedError) + return + } + s.Require().NotNil(swapResponse) + s.Require().NoError(err) + + from, err := sdk.AccAddressFromBech32(tc.request.FromAddress) + s.Require().NoError(err) + actualAmount := s.keeper.GetBalance(ctx, from, tc.request.GetToDenom()).Amount + s.Require().Equal(tc.expectedAmount, actualAmount) + }) + } +} + +func (s *KeeperTestSuite) TestMsgSwapAll() { + swapAllExpectedBalance, ok := sdk.NewIntFromString("18281438845984584000000") + s.Require().True(ok) + testCases := map[string]struct { + request *types.MsgSwapAll + expectedAmount sdk.Int + shouldThrowError bool + expectedError error + }{ + "swapAll": { + &types.MsgSwapAll{ + FromAddress: s.accWithFromCoin.String(), + FromDenom: s.swap.GetFromDenom(), + ToDenom: s.swap.GetToDenom(), + }, + swapAllExpectedBalance, + false, + nil, + }, + "account holding to-coin only": { + &types.MsgSwapAll{ + FromAddress: s.accWithToCoin.String(), + FromDenom: s.swap.GetFromDenom(), + ToDenom: s.swap.GetToDenom(), + }, + s.initBalance, + true, + sdkerrors.ErrInsufficientFunds, + }, + } + for name, tc := range testCases { + s.Run(name, func() { + ctx, _ := s.ctx.CacheContext() + err := s.keeper.MakeSwap(ctx, s.swap, s.toDenomMetadata) + s.Require().NoError(err) + + swapResponse, err := s.msgServer.SwapAll(sdk.WrapSDKContext(ctx), tc.request) + if tc.shouldThrowError { + s.Require().ErrorIs(err, tc.expectedError) + return + } + s.Require().NotNil(swapResponse) + s.Require().NoError(err) + + from, err := sdk.AccAddressFromBech32(tc.request.FromAddress) + s.Require().NoError(err) + actualAmount := s.keeper.GetBalance(ctx, from, tc.request.GetToDenom()).Amount + s.Require().Equal(tc.expectedAmount, actualAmount) + }) + } +} diff --git a/x/fswap/keeper/params.go b/x/fswap/keeper/params.go deleted file mode 100644 index 5578a6d760..0000000000 --- a/x/fswap/keeper/params.go +++ /dev/null @@ -1,35 +0,0 @@ -package keeper - -import ( - sdk "github.com/Finschia/finschia-sdk/types" - sdkerrors "github.com/Finschia/finschia-sdk/types/errors" - "github.com/Finschia/finschia-sdk/x/fswap/types" -) - -// GetParams get all parameters as types.Params -func (k Keeper) GetParams(ctx sdk.Context) types.Params { - store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte{types.ParamsKey}) - var params types.Params - if bz == nil { - panic(sdkerrors.ErrNotFound) - } - k.cdc.MustUnmarshal(bz, ¶ms) - return params -} - -// SetParams set the params -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { - store := ctx.KVStore(k.storeKey) - bz, err := k.cdc.Marshal(¶ms) - if err != nil { - return err - } - store.Set([]byte{types.ParamsKey}, bz) - return nil -} - -func (k Keeper) SwappableNewCoinAmount(ctx sdk.Context) sdk.Int { - params := k.GetParams(ctx) - return params.SwappableNewCoinAmount -} diff --git a/x/fswap/keeper/proposal.go b/x/fswap/keeper/proposal.go new file mode 100644 index 0000000000..1c726e67a6 --- /dev/null +++ b/x/fswap/keeper/proposal.go @@ -0,0 +1,163 @@ +package keeper + +import ( + "github.com/Finschia/finschia-sdk/store/prefix" + sdk "github.com/Finschia/finschia-sdk/types" + "github.com/Finschia/finschia-sdk/types/errors" + bank "github.com/Finschia/finschia-sdk/x/bank/types" + "github.com/Finschia/finschia-sdk/x/fswap/types" +) + +func (k Keeper) MakeSwap(ctx sdk.Context, swap types.Swap, toDenomMetadata bank.Metadata) error { + isNewSwap := true + if _, err := k.getSwap(ctx, swap.FromDenom, swap.ToDenom); err == nil { + isNewSwap = false + } + + if !isNewSwap && !k.config.UpdateAllowed { + return errors.ErrInvalidRequest.Wrap("update existing swap not allowed") + } + + if isNewSwap { + if err := k.increaseSwapCount(ctx); err != nil { + return err + } + } + + stats, err := k.getSwapStats(ctx) + if err != nil { + return err + } + + if int(stats.SwapCount) > k.config.MaxSwaps && !k.isUnlimited() { + return types.ErrCanNotHaveMoreSwap.Wrapf("cannot make more swaps, max swaps is %d", k.config.MaxSwaps) + } + + if isNewSwap { + swapped := types.Swapped{ + FromCoinAmount: sdk.Coin{ + Denom: swap.GetFromDenom(), + Amount: sdk.ZeroInt(), + }, + ToCoinAmount: sdk.Coin{ + Denom: swap.GetToDenom(), + Amount: sdk.ZeroInt(), + }, + } + if err := k.setSwapped(ctx, swapped); err != nil { + return err + } + } + + if err := k.setSwap(ctx, swap); err != nil { + return err + } + + existingMetadata, ok := k.GetDenomMetaData(ctx, swap.ToDenom) + if !ok { + k.SetDenomMetaData(ctx, toDenomMetadata) + return nil + } + if !denomMetadataEqual(existingMetadata, toDenomMetadata) { + return errors.ErrInvalidRequest.Wrap("changing existing metadata not allowed") + } + + return nil +} + +func denomMetadataEqual(metadata, otherMetadata bank.Metadata) bool { + if metadata.Description != otherMetadata.Description { + return false + } + if len(metadata.DenomUnits) != len(otherMetadata.DenomUnits) { + return false + } + for i, unit := range metadata.DenomUnits { + if unit.Denom != otherMetadata.DenomUnits[i].Denom { + return false + } + } + if metadata.Base != otherMetadata.Base { + return false + } + if metadata.Display != otherMetadata.Display { + return false + } + if metadata.Name != otherMetadata.Name { + return false + } + if metadata.Symbol != otherMetadata.Symbol { + return false + } + return true +} + +func (k Keeper) increaseSwapCount(ctx sdk.Context) error { + stats, err := k.getSwapStats(ctx) + if err != nil { + return err + } + + prev := stats.SwapCount + stats.SwapCount += 1 + if stats.SwapCount < prev { + return types.ErrInvalidState.Wrap("overflow detected") + } + + if err := k.setSwapStats(ctx, stats); err != nil { + return err + } + return nil +} + +func (k Keeper) setSwap(ctx sdk.Context, swap types.Swap) error { + key := swapKey(swap.FromDenom, swap.ToDenom) + bz, err := k.cdc.Marshal(&swap) + if err != nil { + return err + } + + store := ctx.KVStore(k.storeKey) + store.Set(key, bz) + return nil +} + +func (k Keeper) getSwap(ctx sdk.Context, fromDenom, toDenom string) (types.Swap, error) { + store := ctx.KVStore(k.storeKey) + key := swapKey(fromDenom, toDenom) + bz := store.Get(key) + if bz == nil { + return types.Swap{}, errors.ErrNotFound.Wrap("swap not found") + } + + swap := types.Swap{} + if err := k.cdc.Unmarshal(bz, &swap); err != nil { + return types.Swap{}, err + } + + return swap, nil +} + +func (k Keeper) getAllSwaps(ctx sdk.Context) []types.Swap { + swaps := []types.Swap{} + k.iterateAllSwaps(ctx, func(swap types.Swap) bool { + swaps = append(swaps, swap) + return false + }) + return swaps +} + +func (k Keeper) iterateAllSwaps(ctx sdk.Context, cb func(swapped types.Swap) (stop bool)) { + store := ctx.KVStore(k.storeKey) + swapDataStore := prefix.NewStore(store, swapPrefix) + + iterator := swapDataStore.Iterator(nil, nil) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + swap := types.Swap{} + k.cdc.MustUnmarshal(iterator.Value(), &swap) + if cb(swap) { + break + } + } +} diff --git a/x/fswap/keeper/proposal_test.go b/x/fswap/keeper/proposal_test.go new file mode 100644 index 0000000000..4dbe0e63b2 --- /dev/null +++ b/x/fswap/keeper/proposal_test.go @@ -0,0 +1,138 @@ +package keeper_test + +import ( + sdk "github.com/Finschia/finschia-sdk/types" + sdkerrors "github.com/Finschia/finschia-sdk/types/errors" + bank "github.com/Finschia/finschia-sdk/x/bank/types" + "github.com/Finschia/finschia-sdk/x/fswap/types" +) + +func (s *KeeperTestSuite) TestMakeSwapProposal() { + testCases := map[string]struct { + swap types.Swap + toDenomMeta bank.Metadata + existingMetadata bool + expectedError error + }{ + "valid": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "toD", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + s.toDenomMetadata, + false, + nil, + }, + "to-denom metadata change not allowed": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "toD", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + bank.Metadata{ + Description: s.toDenomMetadata.Description, + DenomUnits: s.toDenomMetadata.DenomUnits, + Base: "change", + Display: s.toDenomMetadata.Display, + Name: s.toDenomMetadata.Name, + Symbol: s.toDenomMetadata.Symbol, + }, + true, + sdkerrors.ErrInvalidRequest, + }, + } + for name, tc := range testCases { + s.Run(name, func() { + ctx, _ := s.ctx.CacheContext() + err := s.keeper.MakeSwap(ctx, tc.swap, s.toDenomMetadata) + if tc.existingMetadata { + err := s.keeper.MakeSwap(ctx, tc.swap, s.toDenomMetadata) + s.Require().ErrorIs(err, tc.expectedError) + } else { + s.Require().ErrorIs(err, tc.expectedError) + } + }) + } +} + +func (s *KeeperTestSuite) TestSwapValidateBasic() { + testCases := map[string]struct { + swap types.Swap + shouldThrowError bool + expectedError error + }{ + "valid": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "toD", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + false, + nil, + }, + "invalid empty from-denom": { + types.Swap{ + FromDenom: "", + ToDenom: "toD", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + true, + sdkerrors.ErrInvalidRequest, + }, + "invalid empty to-denom": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + true, + sdkerrors.ErrInvalidRequest, + }, + "invalid zero amount cap for to-denom": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "toD", + AmountCapForToDenom: sdk.ZeroInt(), + SwapRate: sdk.OneDec(), + }, + true, + sdkerrors.ErrInvalidRequest, + }, + "invalid zero swap-rate": { + types.Swap{ + FromDenom: "fromD", + ToDenom: "toD", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.ZeroDec(), + }, + true, + sdkerrors.ErrInvalidRequest, + }, + "invalid the same from-denom and to-denom": { + types.Swap{ + FromDenom: "same", + ToDenom: "same", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.OneDec(), + }, + true, + sdkerrors.ErrInvalidRequest, + }, + } + for name, tc := range testCases { + s.Run(name, func() { + err := tc.swap.ValidateBasic() + if tc.shouldThrowError { + s.Require().ErrorIs(err, tc.expectedError) + return + } + s.Require().NoError(err) + }) + } +} diff --git a/x/fswap/keeper/query_params_test.go b/x/fswap/keeper/query_params_test.go deleted file mode 100644 index 9429264902..0000000000 --- a/x/fswap/keeper/query_params_test.go +++ /dev/null @@ -1 +0,0 @@ -package keeper_test diff --git a/x/fswap/module.go b/x/fswap/module.go index 724b883a9e..d561bbe296 100644 --- a/x/fswap/module.go +++ b/x/fswap/module.go @@ -28,7 +28,7 @@ var ( // AppModuleBasic // ---------------------------------------------------------------------------- -// AppModuleBasic implements the AppModuleBasic interface for the capability module. +// AppModuleBasic implements the AppModuleBasic interface for the fswap module. type AppModuleBasic struct { cdc codec.BinaryCodec } @@ -37,31 +37,25 @@ func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { return AppModuleBasic{cdc: cdc} } -// Name returns the capability module's name. +// Name returns the fswap module's name. func (AppModuleBasic) Name() string { return types.ModuleName } -func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { - types.RegisterCodec(cdc) -} - -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - types.RegisterCodec(cdc) -} +func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {} // RegisterInterfaces registers the module's interface types func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { types.RegisterInterfaces(reg) } -// DefaultGenesis returns the capability module's default genesis state. +// DefaultGenesis returns the fswap module's default genesis state. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { return cdc.MustMarshalJSON(types.DefaultGenesis()) } -// ValidateGenesis performs genesis state validation for the capability module. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { +// ValidateGenesis performs genesis state validation for the fswap module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { var genState types.GenesisState if err := cdc.UnmarshalJSON(bz, &genState); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) @@ -74,12 +68,12 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r // this line is used by starport scaffolding # 2 } -// GetTxCmd returns the capability module's root tx command. +// GetTxCmd returns the fswap module's root tx command. func (a AppModuleBasic) GetTxCmd() *cobra.Command { return cli.GetTxCmd() } -// GetQueryCmd returns the capability module's root query command. +// GetQueryCmd returns the fswap module's root query command. func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd(types.StoreKey) } @@ -88,69 +82,65 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { // AppModule // ---------------------------------------------------------------------------- -// AppModule implements the AppModule interface for the capability module. +// AppModule implements the AppModule interface for the fswap module. type AppModule struct { AppModuleBasic - keeper keeper.Keeper - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper + keeper keeper.Keeper + bankKeeper keeper.BankKeeper } func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, - accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, + bankKeeper keeper.BankKeeper, ) AppModule { return AppModule{ AppModuleBasic: NewAppModuleBasic(cdc), keeper: keeper, - accountKeeper: accountKeeper, bankKeeper: bankKeeper, } } -// Name returns the capability module's name. +// Name returns the fswap module's name. func (am AppModule) Name() string { return am.AppModuleBasic.Name() } -// Route returns the capability module's message routing key. -func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) -} +// Route returns the fswap module's message routing key. +func (AppModule) Route() sdk.Route { return sdk.Route{} } -// QuerierRoute returns the capability module's query routing key. +// QuerierRoute returns the fswap module's query routing key. func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQuerierHandler returns the capability module's Querier. -func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { +// LegacyQuerierHandler returns the fswap module's Querier. +func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { return nil } // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper)) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServer(am.keeper)) } -// RegisterInvariants registers the capability module's invariants. +// RegisterInvariants registers the fswap module's invariants. func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} -// InitGenesis performs the capability module's genesis initialization It returns +// InitGenesis performs the fswap module's genesis initialization It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { - var genState types.GenesisState + genState := types.GenesisState{} // Initialize global index to index in genesis state cdc.MustUnmarshalJSON(gs, &genState) - - am.keeper.InitGenesis(ctx, genState) - + if err := am.keeper.InitGenesis(ctx, &genState); err != nil { + panic(err) + } return []abci.ValidatorUpdate{} } -// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. +// ExportGenesis returns the fswap module's exported genesis state as raw JSON bytes. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { genState := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(genState) @@ -159,10 +149,10 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } -// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +// BeginBlock executes all ABCI BeginBlock logic respective to the fswap module. func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} -// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// EndBlock executes all ABCI EndBlock logic respective to the fswap module. It // returns no validator updates. func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} diff --git a/x/fswap/module_simulation.go b/x/fswap/module_simulation.go index 4748931d47..1a4d90d6be 100644 --- a/x/fswap/module_simulation.go +++ b/x/fswap/module_simulation.go @@ -6,14 +6,15 @@ import ( sdk "github.com/Finschia/finschia-sdk/types" "github.com/Finschia/finschia-sdk/types/module" simtypes "github.com/Finschia/finschia-sdk/types/simulation" - "github.com/Finschia/finschia-sdk/x/fswap/simulation" + "github.com/Finschia/finschia-sdk/x/fswap/types" ) var _ module.AppModuleSimulation = AppModule{} // GenerateGenesisState creates a randomized GenState of the module. func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - simulation.RandomizedGenState(simState) + fswapGenesis := types.DefaultGenesis() + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(fswapGenesis) } // RegisterStoreDecoder registers a decoder. diff --git a/x/fswap/proposal_handler_test.go b/x/fswap/proposal_handler_test.go new file mode 100644 index 0000000000..c55bd5a2e4 --- /dev/null +++ b/x/fswap/proposal_handler_test.go @@ -0,0 +1,40 @@ +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/simulation/genesis.go b/x/fswap/simulation/genesis.go index f84ff0b243..02eddda2ba 100644 --- a/x/fswap/simulation/genesis.go +++ b/x/fswap/simulation/genesis.go @@ -1,65 +1 @@ package simulation - -import ( - "encoding/json" - "fmt" - "math/rand" - - sdk "github.com/Finschia/finschia-sdk/types" - "github.com/Finschia/finschia-sdk/types/module" - "github.com/Finschia/finschia-sdk/x/fswap/types" -) - -// Simulation parameter constants -const ( - OldCoinAmount = "old_coin_amount" - NewCoinAmount = "new_coin_amount" - SwappableNewCoinAmount = "swappable_new_coin_amount" -) - -// GenOldCoinAmount randomized oldCoinAmount -func GenOldCoinAmount(r *rand.Rand) sdk.Int { - return sdk.NewInt(int64(r.Intn(1001) + 1000)) -} - -// GenNewCoinAmount randomized oldCoinAmount -func GenNewCoinAmount(r *rand.Rand) sdk.Int { - return sdk.NewInt(int64(r.Intn(100001) + 100000)) -} - -// GenSwappableNewCoinAmount randomized swappableNewCoinAmount -func GenSwappableNewCoinAmount(r *rand.Rand) sdk.Int { - return sdk.NewInt(int64(r.Intn(100001) + 200000)) -} - -// RandomizedGenState generates a random GenesisState for fswap -func RandomizedGenState(simState *module.SimulationState) { - var oldCoinAmount sdk.Int - simState.AppParams.GetOrGenerate( - simState.Cdc, OldCoinAmount, &oldCoinAmount, simState.Rand, - func(r *rand.Rand) { oldCoinAmount = GenOldCoinAmount(r) }, - ) - - var newCoinAmount sdk.Int - simState.AppParams.GetOrGenerate( - simState.Cdc, NewCoinAmount, &newCoinAmount, simState.Rand, - func(r *rand.Rand) { newCoinAmount = GenNewCoinAmount(r) }, - ) - - var swappableNewCoinAmount sdk.Int - simState.AppParams.GetOrGenerate( - simState.Cdc, SwappableNewCoinAmount, &swappableNewCoinAmount, simState.Rand, - func(r *rand.Rand) { swappableNewCoinAmount = GenSwappableNewCoinAmount(r) }, - ) - - fswapParams := types.NewParams(swappableNewCoinAmount) - fswapSwapped := types.NewSwapped(oldCoinAmount, newCoinAmount) - fswapGenesis := types.NewGenesisState(fswapParams, fswapSwapped) - - bz, err := json.MarshalIndent(&fswapGenesis, "", " ") - if err != nil { - panic(err) - } - fmt.Printf("Selected randomly generated fswap parameters:\n%s\n", bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(fswapGenesis) -} diff --git a/x/fswap/simulation/genesis_test.go b/x/fswap/simulation/genesis_test.go index 00ac1852d7..5c6452f9a0 100644 --- a/x/fswap/simulation/genesis_test.go +++ b/x/fswap/simulation/genesis_test.go @@ -1,78 +1 @@ package simulation_test - -import ( - "encoding/json" - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/Finschia/finschia-sdk/codec" - codectypes "github.com/Finschia/finschia-sdk/codec/types" - sdk "github.com/Finschia/finschia-sdk/types" - "github.com/Finschia/finschia-sdk/types/module" - simtypes "github.com/Finschia/finschia-sdk/types/simulation" - "github.com/Finschia/finschia-sdk/x/fswap/simulation" - "github.com/Finschia/finschia-sdk/x/fswap/types" -) - -// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState. -// Abonormal scenarios are not tested here. -func TestRandomizedGenState(t *testing.T) { - interfaceRegistry := codectypes.NewInterfaceRegistry() - cdc := codec.NewProtoCodec(interfaceRegistry) - - s := rand.NewSource(1) - r := rand.New(s) - - simState := module.SimulationState{ - AppParams: make(simtypes.AppParams), - Cdc: cdc, - Rand: r, - NumBonded: 3, - Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, - GenState: make(map[string]json.RawMessage), - } - - simulation.RandomizedGenState(&simState) - - var fswapGenesis types.GenesisState - - int1 := sdk.NewInt(296839) - int2 := sdk.NewInt(1754) - int3 := sdk.NewInt(138374) - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &fswapGenesis) - require.Equal(t, int1, fswapGenesis.Params.SwappableNewCoinAmount) - require.Equal(t, int2, fswapGenesis.Swapped.OldCoinAmount) - require.Equal(t, int3, fswapGenesis.Swapped.NewCoinAmount) -} - -// TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState. -func TestRandomizedGenState1(t *testing.T) { - interfaceRegistry := codectypes.NewInterfaceRegistry() - cdc := codec.NewProtoCodec(interfaceRegistry) - - s := rand.NewSource(1) - r := rand.New(s) - // all these tests will panic - tests := []struct { - simState module.SimulationState - panicMsg string - }{ - { // panic => reason: incomplete initialization of the simState - module.SimulationState{}, "invalid memory address or nil pointer dereference"}, - { // panic => reason: incomplete initialization of the simState - module.SimulationState{ - AppParams: make(simtypes.AppParams), - Cdc: cdc, - Rand: r, - }, "assignment to entry in nil map"}, - } - - for _, tt := range tests { - tt := tt - - require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) - } -} diff --git a/x/fswap/spec/README.md b/x/fswap/spec/README.md new file mode 100644 index 0000000000..ee7423f27c --- /dev/null +++ b/x/fswap/spec/README.md @@ -0,0 +1,16 @@ +``` +make build +make install +zsh init_node.sh sim 1 +``` + +open the `./.simapp/simapp0/config/genesis.json` change the value of `voting_params.voting_period` to `10s` +``` +simd start --home ~/.simapp/simapp0 +simd tx gov submit-proposal swap-init --title "test" --description "test" --from link146asaycmtydq45kxc8evntqfgepagygelel00h --from-denom "cony" --to-denom "PDT" --swap-rate 123 --amount-limit 1000 --deposit 10000000stake --chain-id=sim --keyring-backend=test --gas-prices 1000stake --gas 10000000 --gas-adjustment 1.5 --home ~/.simapp/simapp0 -b block -y +simd tx gov vote 1 yes --from link146asaycmtydq45kxc8evntqfgepagygelel00h --chain-id=sim --keyring-backend=test --home ~/.simapp/simapp0 -b block -y +``` + +``` +simd query fswap swapped --chain-id=sim +``` \ No newline at end of file diff --git a/x/fswap/testutil/expected_keepers_mocks.go b/x/fswap/testutil/expected_keepers_mocks.go index 21bb92feaf..8718d93937 100644 --- a/x/fswap/testutil/expected_keepers_mocks.go +++ b/x/fswap/testutil/expected_keepers_mocks.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: x/fswap/types/expected_keepers.go +// Source: x/fswap/keeper/expected_keepers.go // Package testutil is a generated GoMock package. package testutil @@ -7,95 +7,147 @@ package testutil import ( reflect "reflect" - types "github.com/Finschia/finschia-sdk/types" - types0 "github.com/Finschia/finschia-sdk/x/auth/types" + types "github.com/Finschia/finschia-sdk/snapshots/types" + types0 "github.com/Finschia/finschia-sdk/types" + types1 "github.com/Finschia/finschia-sdk/x/bank/types" gomock "github.com/golang/mock/gomock" ) -// MockAccountKeeper is a mock of AccountKeeper interface. -type MockAccountKeeper struct { +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { ctrl *gomock.Controller - recorder *MockAccountKeeperMockRecorder + recorder *MockBankKeeperMockRecorder } -// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. -type MockAccountKeeperMockRecorder struct { - mock *MockAccountKeeper +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper } -// NewMockAccountKeeper creates a new mock instance. -func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { - mock := &MockAccountKeeper{ctrl: ctrl} - mock.recorder = &MockAccountKeeperMockRecorder{mock} +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { return m.recorder } -// GetAccount mocks base method. -func (m *MockAccountKeeper) GetAccount(ctx types.Context, addr types.AccAddress) types0.AccountI { +// BurnCoins mocks base method. +func (m *MockBankKeeper) BurnCoins(ctx types0.Context, moduleName string, amt types0.Coins) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAccount", ctx, addr) - ret0, _ := ret[0].(types0.AccountI) + ret := m.ctrl.Call(m, "BurnCoins", ctx, moduleName, amt) + ret0, _ := ret[0].(error) return ret0 } -// GetAccount indicates an expected call of GetAccount. -func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call { +// BurnCoins indicates an expected call of BurnCoins. +func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amt interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), ctx, moduleName, amt) } -// MockBankKeeper is a mock of BankKeeper interface. -type MockBankKeeper struct { - ctrl *gomock.Controller - recorder *MockBankKeeperMockRecorder +// GetBalance mocks base method. +func (m *MockBankKeeper) GetBalance(ctx types0.Context, addr types0.AccAddress, denom string) types0.Coin { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBalance", ctx, addr, denom) + ret0, _ := ret[0].(types0.Coin) + return ret0 } -// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. -type MockBankKeeperMockRecorder struct { - mock *MockBankKeeper +// GetBalance indicates an expected call of GetBalance. +func (mr *MockBankKeeperMockRecorder) GetBalance(ctx, addr, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBalance", reflect.TypeOf((*MockBankKeeper)(nil).GetBalance), ctx, addr, denom) } -// NewMockBankKeeper creates a new mock instance. -func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { - mock := &MockBankKeeper{ctrl: ctrl} - mock.recorder = &MockBankKeeperMockRecorder{mock} - return mock +// GetDenomMetaData mocks base method. +func (m *MockBankKeeper) GetDenomMetaData(ctx types0.Context, denom string) (types.Metadata, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDenomMetaData", ctx, denom) + ret0, _ := ret[0].(types.Metadata) + ret1, _ := ret[1].(bool) + return ret0, ret1 } -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { - return m.recorder +// GetDenomMetaData indicates an expected call of GetDenomMetaData. +func (mr *MockBankKeeperMockRecorder) GetDenomMetaData(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDenomMetaData", reflect.TypeOf((*MockBankKeeper)(nil).GetDenomMetaData), ctx, denom) } -// GetSupply mocks base method. -func (m *MockBankKeeper) GetSupply(ctx types.Context, denom string) types.Coin { +// IsSendEnabledCoins mocks base method. +func (m *MockBankKeeper) IsSendEnabledCoins(ctx types0.Context, coins ...types0.Coin) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSupply", ctx, denom) - ret0, _ := ret[0].(types.Coin) + varargs := []interface{}{ctx} + for _, a := range coins { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "IsSendEnabledCoins", varargs...) + ret0, _ := ret[0].(error) return ret0 } -// GetSupply indicates an expected call of GetSupply. -func (mr *MockBankKeeperMockRecorder) GetSupply(ctx, denom interface{}) *gomock.Call { +// IsSendEnabledCoins indicates an expected call of IsSendEnabledCoins. +func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoins(ctx interface{}, coins ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSupply", reflect.TypeOf((*MockBankKeeper)(nil).GetSupply), ctx, denom) + varargs := append([]interface{}{ctx}, coins...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSendEnabledCoins", reflect.TypeOf((*MockBankKeeper)(nil).IsSendEnabledCoins), varargs...) } -// SpendableCoins mocks base method. -func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins { +// MintCoins mocks base method. +func (m *MockBankKeeper) MintCoins(ctx types0.Context, moduleName string, amt types0.Coins) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr) - ret0, _ := ret[0].(types.Coins) + ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amt) + ret0, _ := ret[0].(error) return ret0 } -// SpendableCoins indicates an expected call of SpendableCoins. -func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call { +// MintCoins indicates an expected call of MintCoins. +func (mr *MockBankKeeperMockRecorder) MintCoins(ctx, moduleName, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MintCoins", reflect.TypeOf((*MockBankKeeper)(nil).MintCoins), ctx, moduleName, amt) +} + +// SendCoinsFromAccountToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx types0.Context, senderAddr types0.AccAddress, recipientModule string, amt types0.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) +} + +// SendCoinsFromModuleToAccount mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types0.Context, senderModule string, recipientAddr types0.AccAddress, amt types0.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt) +} + +// SetDenomMetaData mocks base method. +func (m *MockBankKeeper) SetDenomMetaData(ctx types0.Context, denomMetaData types1.Metadata) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetDenomMetaData", ctx, denomMetaData) +} + +// SetDenomMetaData indicates an expected call of SetDenomMetaData. +func (mr *MockBankKeeperMockRecorder) SetDenomMetaData(ctx, denomMetaData interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDenomMetaData", reflect.TypeOf((*MockBankKeeper)(nil).SetDenomMetaData), ctx, denomMetaData) } diff --git a/x/fswap/types/codec.go b/x/fswap/types/codec.go index 72003233c5..de8865ec57 100644 --- a/x/fswap/types/codec.go +++ b/x/fswap/types/codec.go @@ -2,22 +2,38 @@ package types import ( "github.com/Finschia/finschia-sdk/codec" - cdctypes "github.com/Finschia/finschia-sdk/codec/types" - // this line is used by starport scaffolding # 1 + "github.com/Finschia/finschia-sdk/codec/legacy" + "github.com/Finschia/finschia-sdk/codec/types" + 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" ) -func RegisterCodec(cdc *codec.LegacyAmino) { - // this line is used by starport scaffolding # 2 +// 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) } -func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - // this line is used by starport scaffolding # 3 +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgSwap{}, + &MsgSwapAll{}, + ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) + + registry.RegisterImplementations( + (*govtypes.Content)(nil), + &MakeSwapProposal{}, + ) } -var ( - Amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) -) +func init() { + RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(fscodec.Amino) +} diff --git a/x/fswap/types/config.go b/x/fswap/types/config.go index d2e57a05aa..071a0cab1f 100644 --- a/x/fswap/types/config.go +++ b/x/fswap/types/config.go @@ -1,24 +1,13 @@ package types -import ( - sdk "github.com/Finschia/finschia-sdk/types" -) - -// Config is a config struct used for intialising the fswap module to avoid using globals. type Config struct { - // OldCoinDenom defines the old coin denom. - OldCoinDenom string - // NewCoinDenom defines the new coin denom. - NewCoinDenom string - // SwapRate defines the swap rate. - SwapRate sdk.Int + MaxSwaps int + UpdateAllowed bool } -// DefaultConfig returns the default config for fswap. func DefaultConfig() Config { return Config{ - OldCoinDenom: "cony", - NewCoinDenom: "PDT", - SwapRate: sdk.NewInt(148079656000000), + MaxSwaps: 1, + UpdateAllowed: false, } } diff --git a/x/fswap/types/errors.go b/x/fswap/types/errors.go index 3a18f66f20..24e0fa6c11 100644 --- a/x/fswap/types/errors.go +++ b/x/fswap/types/errors.go @@ -8,7 +8,8 @@ import ( // x/fswap module sentinel errors var ( - ErrParamsNotFound = sdkerrors.Register(ModuleName, 1100, "params does not exist") - ErrSwappedNotFound = sdkerrors.Register(ModuleName, 1101, "swapped does not exist") - ErrExceedSwappable = sdkerrors.Register(ModuleName, 1102, "exceed swappable coin amount") + ErrInvalidState = sdkerrors.Register(ModuleName, 2, "swap module invalid state") + ErrCanNotHaveMoreSwap = sdkerrors.Register(ModuleName, 3, "no more swap allowed") + ErrSwappedNotFound = sdkerrors.Register(ModuleName, 4, "swapped does not exist") + ErrExceedSwappableToCoinAmount = sdkerrors.Register(ModuleName, 5, "exceed swappable to-coin amount") ) diff --git a/x/fswap/types/event.pb.go b/x/fswap/types/event.pb.go index d3e5284230..6461787a83 100644 --- a/x/fswap/types/event.pb.go +++ b/x/fswap/types/event.pb.go @@ -27,10 +27,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type EventSwapCoins struct { // holder's address Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - // amount of the old currency - OldCoin types.Coin `protobuf:"bytes,2,opt,name=old_coin,json=oldCoin,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"old_coin"` - // amount of the new currency - NewCoin types.Coin `protobuf:"bytes,3,opt,name=new_coin,json=newCoin,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"new_coin"` + // from-coin amount + FromCoinAmount types.Coin `protobuf:"bytes,2,opt,name=from_coin_amount,json=fromCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"from_coin_amount"` + // to-coin amount + ToCoinAmount types.Coin `protobuf:"bytes,3,opt,name=to_coin_amount,json=toCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"to_coin_amount"` } func (m *EventSwapCoins) Reset() { *m = EventSwapCoins{} } @@ -73,16 +73,16 @@ func (m *EventSwapCoins) GetAddress() string { return "" } -func (m *EventSwapCoins) GetOldCoin() types.Coin { +func (m *EventSwapCoins) GetFromCoinAmount() types.Coin { if m != nil { - return m.OldCoin + return m.FromCoinAmount } return types.Coin{} } -func (m *EventSwapCoins) GetNewCoin() types.Coin { +func (m *EventSwapCoins) GetToCoinAmount() types.Coin { if m != nil { - return m.NewCoin + return m.ToCoinAmount } return types.Coin{} } @@ -94,25 +94,26 @@ func init() { func init() { proto.RegisterFile("lbm/fswap/v1/event.proto", fileDescriptor_92d5edbd64a725af) } var fileDescriptor_92d5edbd64a725af = []byte{ - // 278 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x91, 0xb1, 0x4e, 0xc3, 0x30, - 0x10, 0x86, 0xe3, 0x22, 0x51, 0x08, 0x88, 0xa1, 0x62, 0x08, 0x1d, 0xdc, 0x8a, 0xa9, 0x12, 0xc2, - 0x56, 0xe8, 0x1b, 0x80, 0x40, 0xcc, 0x65, 0x63, 0x41, 0x76, 0xe2, 0xa6, 0x16, 0x89, 0x2f, 0xea, - 0x99, 0x04, 0x36, 0x1e, 0x81, 0xe7, 0xe0, 0x49, 0x3a, 0x76, 0x64, 0x02, 0x94, 0xbc, 0x08, 0xb2, - 0x13, 0x66, 0x26, 0xb6, 0xff, 0xf4, 0xdf, 0xff, 0xfd, 0xd2, 0x5d, 0x18, 0xe5, 0xb2, 0xe0, 0x4b, - 0xac, 0x45, 0xc9, 0xab, 0x98, 0xab, 0x4a, 0x19, 0xcb, 0xca, 0x35, 0x58, 0x18, 0x1d, 0xe6, 0xb2, - 0x60, 0xde, 0x61, 0x55, 0x3c, 0x3e, 0xce, 0x20, 0x03, 0x6f, 0x70, 0xa7, 0xba, 0x9d, 0x31, 0x4d, - 0x00, 0x0b, 0x40, 0x2e, 0x05, 0x2a, 0x5e, 0xc5, 0x52, 0x59, 0x11, 0xf3, 0x04, 0xb4, 0xe9, 0xfc, - 0xd3, 0xd7, 0x41, 0x78, 0x74, 0xed, 0x98, 0x77, 0xb5, 0x28, 0xaf, 0x40, 0x1b, 0x1c, 0x45, 0xe1, - 0x50, 0xa4, 0xe9, 0x5a, 0x21, 0x46, 0x64, 0x4a, 0x66, 0xfb, 0x8b, 0xdf, 0x71, 0xa4, 0xc3, 0x3d, - 0xc8, 0xd3, 0x07, 0x17, 0x8f, 0x06, 0x53, 0x32, 0x3b, 0xb8, 0x38, 0x61, 0x1d, 0x9f, 0x39, 0x3e, - 0xeb, 0xf9, 0xcc, 0x71, 0x2e, 0xe7, 0x9b, 0xcf, 0x49, 0xf0, 0xfe, 0x35, 0x39, 0xcb, 0xb4, 0x5d, - 0x3d, 0x49, 0x96, 0x40, 0xc1, 0x6f, 0xb4, 0xc1, 0x64, 0xa5, 0x05, 0x5f, 0xf6, 0xe2, 0x1c, 0xd3, - 0x47, 0x6e, 0x5f, 0x4a, 0x85, 0x3e, 0xb4, 0x18, 0x42, 0x9e, 0x3a, 0xe1, 0xaa, 0x8c, 0xaa, 0xbb, - 0xaa, 0x9d, 0xff, 0xa9, 0x32, 0xaa, 0xf6, 0xe9, 0xdb, 0x4d, 0x43, 0xc9, 0xb6, 0xa1, 0xe4, 0xbb, - 0xa1, 0xe4, 0xad, 0xa5, 0xc1, 0xb6, 0xa5, 0xc1, 0x47, 0x4b, 0x83, 0x7b, 0xf6, 0x27, 0xef, 0xb9, - 0xff, 0x8c, 0xe7, 0xca, 0x5d, 0x7f, 0xd3, 0xf9, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb7, 0x1e, - 0x90, 0x67, 0xb3, 0x01, 0x00, 0x00, + // 289 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x91, 0xc1, 0x4a, 0xc3, 0x30, + 0x1c, 0xc6, 0x9b, 0x09, 0x8a, 0x75, 0x14, 0x29, 0x1e, 0xea, 0x0e, 0xd9, 0xf0, 0x34, 0x10, 0x13, + 0xea, 0x9e, 0xc0, 0x89, 0xe2, 0x79, 0xde, 0xbc, 0x8c, 0xa4, 0x4d, 0xbb, 0xe2, 0xd2, 0x7f, 0x69, + 0xb2, 0x6e, 0xbe, 0x85, 0x67, 0x1f, 0xc1, 0x27, 0xd9, 0x71, 0x47, 0x4f, 0x2a, 0xed, 0x8b, 0x48, + 0xd2, 0x8a, 0x78, 0xf2, 0xe4, 0xed, 0x0b, 0x5f, 0xbe, 0xdf, 0x0f, 0x12, 0x37, 0x58, 0x72, 0x49, + 0x13, 0xb5, 0x66, 0x05, 0xad, 0x42, 0x2a, 0x2a, 0x91, 0x6b, 0x52, 0x94, 0xa0, 0xc1, 0xef, 0x2f, + 0xb9, 0x24, 0xb6, 0x21, 0x55, 0x38, 0x38, 0x49, 0x21, 0x05, 0x5b, 0x50, 0x93, 0xda, 0x3b, 0x03, + 0x1c, 0x81, 0x92, 0xa0, 0x28, 0x67, 0x4a, 0xd0, 0x2a, 0xe4, 0x42, 0xb3, 0x90, 0x46, 0x90, 0xe5, + 0x6d, 0x7f, 0xf6, 0xd2, 0x73, 0xbd, 0x1b, 0xc3, 0xbc, 0x5f, 0xb3, 0xe2, 0x1a, 0xb2, 0x5c, 0xf9, + 0x81, 0x7b, 0xc0, 0xe2, 0xb8, 0x14, 0x4a, 0x05, 0x68, 0x84, 0xc6, 0x87, 0xb3, 0xef, 0xa3, 0xbf, + 0x71, 0x8f, 0x93, 0x12, 0xe4, 0xdc, 0xec, 0xe7, 0x4c, 0xc2, 0x2a, 0xd7, 0x41, 0x6f, 0x84, 0xc6, + 0x47, 0x97, 0xa7, 0xa4, 0xf5, 0x10, 0xe3, 0x21, 0x9d, 0x87, 0x18, 0xde, 0x74, 0xb2, 0x7d, 0x1f, + 0x3a, 0xaf, 0x1f, 0xc3, 0xf3, 0x34, 0xd3, 0x8b, 0x15, 0x27, 0x11, 0x48, 0x7a, 0x9b, 0xe5, 0x2a, + 0x5a, 0x64, 0x8c, 0x26, 0x5d, 0xb8, 0x50, 0xf1, 0x23, 0xd5, 0x4f, 0x85, 0x50, 0x76, 0x34, 0xf3, + 0x8c, 0xc7, 0xa4, 0x2b, 0x6b, 0xf1, 0xb5, 0xeb, 0x69, 0xf8, 0xe5, 0xdd, 0xfb, 0x17, 0x6f, 0x5f, + 0xc3, 0x8f, 0x75, 0x7a, 0xb7, 0xad, 0x31, 0xda, 0xd5, 0x18, 0x7d, 0xd6, 0x18, 0x3d, 0x37, 0xd8, + 0xd9, 0x35, 0xd8, 0x79, 0x6b, 0xb0, 0xf3, 0x40, 0xfe, 0x84, 0x6e, 0xba, 0x3f, 0xb3, 0x70, 0xbe, + 0x6f, 0x5f, 0x7b, 0xf2, 0x15, 0x00, 0x00, 0xff, 0xff, 0xe2, 0xc5, 0x6e, 0x30, 0xcd, 0x01, 0x00, + 0x00, } func (m *EventSwapCoins) Marshal() (dAtA []byte, err error) { @@ -136,7 +137,7 @@ func (m *EventSwapCoins) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size, err := m.NewCoin.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.ToCoinAmount.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -146,7 +147,7 @@ func (m *EventSwapCoins) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1a { - size, err := m.OldCoin.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.FromCoinAmount.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -186,9 +187,9 @@ func (m *EventSwapCoins) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - l = m.OldCoin.Size() + l = m.FromCoinAmount.Size() n += 1 + l + sovEvent(uint64(l)) - l = m.NewCoin.Size() + l = m.ToCoinAmount.Size() n += 1 + l + sovEvent(uint64(l)) return n } @@ -262,7 +263,7 @@ func (m *EventSwapCoins) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field OldCoin", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field FromCoinAmount", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -289,13 +290,13 @@ func (m *EventSwapCoins) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.OldCoin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.FromCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NewCoin", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ToCoinAmount", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -322,7 +323,7 @@ func (m *EventSwapCoins) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.NewCoin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.ToCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/fswap/types/expected_keepers.go b/x/fswap/types/expected_keepers.go deleted file mode 100644 index 195cd89bdc..0000000000 --- a/x/fswap/types/expected_keepers.go +++ /dev/null @@ -1,19 +0,0 @@ -package types - -import ( - sdk "github.com/Finschia/finschia-sdk/types" - "github.com/Finschia/finschia-sdk/x/auth/types" -) - -// AccountKeeper defines the expected account keeper used for simulations (noalias) -type AccountKeeper interface { - GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI - // Methods imported from account should be defined here -} - -// BankKeeper defines the expected interface needed to retrieve account balances. -type BankKeeper interface { - SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - // Methods imported from bank should be defined here - GetSupply(ctx sdk.Context, denom string) sdk.Coin -} diff --git a/x/fswap/types/fswap.go b/x/fswap/types/fswap.go index 76803ed5f3..c307c826b3 100644 --- a/x/fswap/types/fswap.go +++ b/x/fswap/types/fswap.go @@ -1,59 +1,76 @@ package types import ( - fmt "fmt" - "gopkg.in/yaml.v2" sdk "github.com/Finschia/finschia-sdk/types" + sdkerrors "github.com/Finschia/finschia-sdk/types/errors" ) -// NewSwapped creates a new Swapped instance -func NewSwapped( - oldCoinAmount sdk.Int, - newCoinAmount sdk.Int, -) Swapped { - return Swapped{ - OldCoinAmount: oldCoinAmount, - NewCoinAmount: newCoinAmount, +// ValidateBasic validates the set of Swap +func (s *Swap) ValidateBasic() error { + if s.FromDenom == "" { + return sdkerrors.ErrInvalidRequest.Wrap("from denomination cannot be empty") + } + if s.ToDenom == "" { + return sdkerrors.ErrInvalidRequest.Wrap("to denomination cannot be empty") + } + if s.FromDenom == s.ToDenom { + return sdkerrors.ErrInvalidRequest.Wrap("from denomination cannot be equal to to denomination") + } + if s.AmountCapForToDenom.LT(sdk.OneInt()) { + return sdkerrors.ErrInvalidRequest.Wrap("amount cannot be less than one") } + if s.SwapRate.IsZero() { + return sdkerrors.ErrInvalidRequest.Wrap("swap rate cannot be zero") + } + return nil } -// DefaultSwapped returns an initial Swapped object -func DefaultSwapped() Swapped { - return NewSwapped(sdk.ZeroInt(), sdk.ZeroInt()) +func (s *Swap) String() string { + out, _ := yaml.Marshal(s) + return string(out) } -func validateCoinAmount(i interface{}) error { - v, ok := i.(sdk.Int) - if !ok { - return fmt.Errorf("invalid coin amount: %T", i) +func (s *SwapStats) ValidateBasic() error { + if s.SwapCount < 0 { + return ErrInvalidState.Wrap("swap count cannot be negative") } + return nil +} - if v.IsNil() { - return fmt.Errorf("coin amount must be not nil") - } +func (s *SwapStats) String() string { + out, _ := yaml.Marshal(s) + return string(out) +} - if v.LT(sdk.ZeroInt()) { - return fmt.Errorf("coin amount cannot be lower than 0") +// ValidateBasic validates the set of Swapped +func (s *Swapped) ValidateBasic() error { + if err := validateCoinAmount(s.FromCoinAmount); err != nil { + return err + } + if err := validateCoinAmount(s.ToCoinAmount); err != nil { + return err } - return nil } -// Validate validates the set of swapped -func (s Swapped) Validate() error { - if err := validateCoinAmount(s.OldCoinAmount); err != nil { - return err +func validateCoinAmount(i interface{}) error { + v, ok := i.(sdk.Coin) + if !ok { + return sdkerrors.ErrInvalidCoins.Wrapf("invalid coin amount: %T", i) } - if err := validateCoinAmount(s.NewCoinAmount); err != nil { - return err + if v.IsNil() { + return sdkerrors.ErrInvalidCoins.Wrap("coin amount must be not nil") + } + if err := v.Validate(); err != nil { + return sdkerrors.ErrInvalidCoins.Wrap(err.Error()) } return nil } // String implements the Stringer interface. -func (s Swapped) String() string { +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 1923c31269..4449b20bec 100644 --- a/x/fswap/types/fswap.pb.go +++ b/x/fswap/types/fswap.pb.go @@ -6,6 +6,8 @@ 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" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -24,15 +26,179 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type Swap struct { + FromDenom string `protobuf:"bytes,1,opt,name=from_denom,json=fromDenom,proto3" json:"from_denom,omitempty"` + ToDenom string `protobuf:"bytes,2,opt,name=to_denom,json=toDenom,proto3" json:"to_denom,omitempty"` + AmountCapForToDenom github_com_Finschia_finschia_sdk_types.Int `protobuf:"bytes,3,opt,name=amount_cap_for_to_denom,json=amountCapForToDenom,proto3,customtype=github.com/Finschia/finschia-sdk/types.Int" json:"amount_cap_for_to_denom"` + 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 (*Swap) Descriptor() ([]byte, []int) { + return fileDescriptor_42ca60eaf37a2b67, []int{0} +} +func (m *Swap) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Swap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Swap.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 *Swap) XXX_Merge(src proto.Message) { + xxx_messageInfo_Swap.Merge(m, src) +} +func (m *Swap) XXX_Size() int { + return m.Size() +} +func (m *Swap) XXX_DiscardUnknown() { + xxx_messageInfo_Swap.DiscardUnknown(m) +} + +var xxx_messageInfo_Swap proto.InternalMessageInfo + +func (m *Swap) GetFromDenom() string { + if m != nil { + return m.FromDenom + } + return "" +} + +func (m *Swap) GetToDenom() string { + if m != nil { + return m.ToDenom + } + return "" +} + +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 (*SwapStats) Descriptor() ([]byte, []int) { + return fileDescriptor_42ca60eaf37a2b67, []int{1} +} +func (m *SwapStats) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SwapStats) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SwapStats.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 *SwapStats) XXX_Merge(src proto.Message) { + xxx_messageInfo_SwapStats.Merge(m, src) +} +func (m *SwapStats) XXX_Size() int { + return m.Size() +} +func (m *SwapStats) XXX_DiscardUnknown() { + xxx_messageInfo_SwapStats.DiscardUnknown(m) +} + +var xxx_messageInfo_SwapStats proto.InternalMessageInfo + +func (m *SwapStats) GetSwapCount() int32 { + if m != nil { + return m.SwapCount + } + 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 { - OldCoinAmount github_com_Finschia_finschia_sdk_types.Int `protobuf:"bytes,1,opt,name=old_coin_amount,json=oldCoinAmount,proto3,customtype=github.com/Finschia/finschia-sdk/types.Int" json:"old_coin_amount"` - NewCoinAmount github_com_Finschia_finschia_sdk_types.Int `protobuf:"bytes,2,opt,name=new_coin_amount,json=newCoinAmount,proto3,customtype=github.com/Finschia/finschia-sdk/types.Int" json:"new_coin_amount"` + 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"` } func (m *Swapped) Reset() { *m = Swapped{} } func (*Swapped) ProtoMessage() {} func (*Swapped) Descriptor() ([]byte, []int) { - return fileDescriptor_42ca60eaf37a2b67, []int{0} + return fileDescriptor_42ca60eaf37a2b67, []int{3} } func (m *Swapped) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -61,29 +227,264 @@ func (m *Swapped) XXX_DiscardUnknown() { var xxx_messageInfo_Swapped proto.InternalMessageInfo +func (m *Swapped) GetFromCoinAmount() types1.Coin { + if m != nil { + return m.FromCoinAmount + } + return types1.Coin{} +} + +func (m *Swapped) GetToCoinAmount() types1.Coin { + if m != nil { + return m.ToCoinAmount + } + return types1.Coin{} +} + func init() { + proto.RegisterType((*Swap)(nil), "lbm.fswap.v1.Swap") + proto.RegisterType((*SwapStats)(nil), "lbm.fswap.v1.SwapStats") + proto.RegisterType((*MakeSwapProposal)(nil), "lbm.fswap.v1.MakeSwapProposal") proto.RegisterType((*Swapped)(nil), "lbm.fswap.v1.Swapped") } func init() { proto.RegisterFile("lbm/fswap/v1/fswap.proto", fileDescriptor_42ca60eaf37a2b67) } var fileDescriptor_42ca60eaf37a2b67 = []byte{ - // 230 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xc8, 0x49, 0xca, 0xd5, - 0x4f, 0x2b, 0x2e, 0x4f, 0x2c, 0xd0, 0x2f, 0x33, 0x84, 0x30, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, - 0x85, 0x78, 0x72, 0x92, 0x72, 0xf5, 0x20, 0x02, 0x65, 0x86, 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, - 0x60, 0x09, 0x7d, 0x10, 0x0b, 0xa2, 0x46, 0xe9, 0x38, 0x23, 0x17, 0x7b, 0x70, 0x79, 0x62, 0x41, - 0x41, 0x6a, 0x8a, 0x50, 0x14, 0x17, 0x7f, 0x7e, 0x4e, 0x4a, 0x7c, 0x72, 0x7e, 0x66, 0x5e, 0x7c, - 0x62, 0x6e, 0x7e, 0x69, 0x5e, 0x89, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xa7, 0x93, 0xd1, 0x89, 0x7b, - 0xf2, 0x0c, 0xb7, 0xee, 0xc9, 0x6b, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, - 0xea, 0xbb, 0x65, 0xe6, 0x15, 0x27, 0x67, 0x64, 0x26, 0xea, 0xa7, 0x41, 0x19, 0xba, 0xc5, 0x29, - 0xd9, 0xfa, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x7a, 0x9e, 0x79, 0x25, 0x41, 0xbc, 0xf9, 0x39, 0x29, - 0xce, 0xf9, 0x99, 0x79, 0x8e, 0x60, 0x83, 0x40, 0x66, 0xe7, 0xa5, 0x96, 0xa3, 0x98, 0xcd, 0x44, - 0xbe, 0xd9, 0x79, 0xa9, 0xe5, 0x08, 0xb3, 0xad, 0x58, 0x66, 0x2c, 0x90, 0x67, 0x70, 0xf2, 0x38, - 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, - 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x3d, 0x82, 0x46, 0x57, 0x40, 0x03, - 0x10, 0x6c, 0x45, 0x12, 0x1b, 0x38, 0x68, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x82, 0xb7, - 0x84, 0x0e, 0x5a, 0x01, 0x00, 0x00, + // 539 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xbf, 0x6f, 0xd3, 0x40, + 0x14, 0xc7, 0xe3, 0x92, 0xd2, 0xe4, 0x52, 0x95, 0x62, 0x8a, 0x48, 0x2b, 0xc5, 0xae, 0x32, 0x21, + 0x7e, 0xd8, 0x4a, 0xca, 0x94, 0x8d, 0xa4, 0xaa, 0x60, 0xa8, 0x40, 0x2e, 0x13, 0x8b, 0x75, 0x76, + 0x2e, 0x89, 0x15, 0xdb, 0xcf, 0xf2, 0xbd, 0xa6, 0xed, 0x1f, 0xc0, 0xce, 0xc8, 0xd8, 0x99, 0xbf, + 0xa4, 0x63, 0x47, 0xc4, 0x10, 0x50, 0xb2, 0x74, 0xe6, 0x1f, 0x00, 0xbd, 0x3b, 0x37, 0x4d, 0xc5, + 0x00, 0x42, 0x62, 0x7b, 0xf7, 0xde, 0xbb, 0xf7, 0xb9, 0xfb, 0x7e, 0xef, 0x58, 0x3d, 0x0e, 0x12, + 0x77, 0x20, 0x4f, 0x78, 0xe6, 0x4e, 0x5a, 0x3a, 0x70, 0xb2, 0x1c, 0x10, 0xcc, 0xf5, 0x38, 0x48, + 0x1c, 0x9d, 0x98, 0xb4, 0x76, 0xb6, 0x86, 0x30, 0x04, 0x55, 0x70, 0x29, 0xd2, 0x3d, 0x3b, 0x56, + 0x08, 0x32, 0x01, 0xe9, 0x06, 0x5c, 0x0a, 0x77, 0xd2, 0x0a, 0x04, 0xf2, 0x96, 0x1b, 0x42, 0x94, + 0xfe, 0x56, 0x4f, 0xc7, 0x8b, 0x3a, 0x2d, 0x74, 0xbd, 0xf9, 0x61, 0x85, 0x95, 0x8f, 0x4e, 0x78, + 0x66, 0x36, 0x18, 0x1b, 0xe4, 0x90, 0xf8, 0x7d, 0x91, 0x42, 0x52, 0x37, 0x76, 0x8d, 0xc7, 0x55, + 0xaf, 0x4a, 0x99, 0x7d, 0x4a, 0x98, 0xdb, 0xac, 0x82, 0x50, 0x14, 0x57, 0x54, 0x71, 0x0d, 0x41, + 0x97, 0x46, 0xec, 0x11, 0x4f, 0xe0, 0x38, 0x45, 0x3f, 0xe4, 0x99, 0x3f, 0x80, 0xdc, 0x5f, 0x74, + 0xde, 0xa1, 0xce, 0x6e, 0xfb, 0x62, 0x6a, 0x97, 0xbe, 0x4e, 0xed, 0x27, 0xc3, 0x08, 0x47, 0xc7, + 0x81, 0x13, 0x42, 0xe2, 0x1e, 0x44, 0xa9, 0x0c, 0x47, 0x11, 0x77, 0x07, 0x45, 0xf0, 0x5c, 0xf6, + 0xc7, 0x2e, 0x9e, 0x65, 0x42, 0x3a, 0xaf, 0x53, 0xf4, 0x1e, 0xe8, 0x91, 0x3d, 0x9e, 0x1d, 0x40, + 0xfe, 0xae, 0x20, 0xbd, 0x61, 0x55, 0x52, 0xc3, 0xcf, 0x39, 0x8a, 0x7a, 0xf9, 0x9f, 0x66, 0xef, + 0x8b, 0xd0, 0xab, 0xd0, 0x10, 0x8f, 0xa3, 0xe8, 0x54, 0x3e, 0x9d, 0xdb, 0xa5, 0xab, 0x73, 0xdb, + 0x68, 0xbe, 0x60, 0x55, 0x92, 0xe1, 0x08, 0x39, 0x4a, 0xd2, 0x42, 0x71, 0x42, 0x3a, 0x82, 0xd2, + 0x62, 0xd5, 0x53, 0xe4, 0x1e, 0x25, 0x96, 0x76, 0x5d, 0x19, 0x6c, 0xf3, 0x90, 0x8f, 0x05, 0x6d, + 0x7d, 0x9b, 0x43, 0x06, 0x92, 0xc7, 0xe6, 0x16, 0x5b, 0xc5, 0x08, 0x63, 0x51, 0x88, 0xa8, 0x17, + 0xe6, 0x2e, 0xab, 0xf5, 0x85, 0x0c, 0xf3, 0x28, 0xc3, 0x08, 0xd2, 0x42, 0xc3, 0xe5, 0x94, 0xf9, + 0x8c, 0x95, 0x89, 0xa1, 0x44, 0xab, 0xb5, 0x4d, 0x67, 0xd9, 0x7d, 0x87, 0x08, 0xdd, 0x32, 0x5d, + 0xd6, 0x53, 0x5d, 0xe6, 0x88, 0xdd, 0xbf, 0x96, 0xd9, 0x4f, 0x04, 0xf2, 0x3e, 0x47, 0xae, 0x34, + 0xa9, 0xb5, 0x1b, 0x8e, 0x36, 0xdd, 0x51, 0x3e, 0x17, 0xa6, 0x3b, 0x87, 0x45, 0x53, 0xb7, 0x41, + 0x53, 0x7e, 0x4c, 0xed, 0x87, 0x67, 0x3c, 0x89, 0x3b, 0xcd, 0xdb, 0x23, 0x9a, 0xde, 0xbd, 0xc2, + 0xd7, 0xeb, 0xfe, 0x4e, 0x99, 0xae, 0xdb, 0xfc, 0x69, 0xb0, 0x35, 0x3a, 0x44, 0x26, 0xfa, 0xe6, + 0x29, 0xdb, 0x54, 0x6f, 0x85, 0xde, 0x99, 0xaf, 0x8d, 0x52, 0x97, 0xad, 0xb5, 0xb7, 0x6f, 0xd0, + 0x52, 0x2c, 0xd0, 0x3d, 0x88, 0xd2, 0xee, 0x1e, 0x61, 0x3f, 0x7f, 0xb3, 0x9f, 0xfe, 0xa5, 0x53, + 0xb4, 0xc9, 0xdb, 0x20, 0x0e, 0x45, 0x2f, 0x15, 0xc5, 0x44, 0xb6, 0x81, 0x70, 0x8b, 0xbb, 0xf2, + 0x5f, 0xb8, 0xeb, 0x08, 0x37, 0x54, 0xad, 0x40, 0xf7, 0xd5, 0xc5, 0xcc, 0x32, 0x2e, 0x67, 0x96, + 0xf1, 0x7d, 0x66, 0x19, 0x1f, 0xe7, 0x56, 0xe9, 0x72, 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 +} +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) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Swap) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Swap) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.SwapRate.Size() + i -= size + if _, err := m.SwapRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintFswap(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size := m.AmountCapForToDenom.Size() + i -= size + if _, err := m.AmountCapForToDenom.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintFswap(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ToDenom) > 0 { + i -= len(m.ToDenom) + copy(dAtA[i:], m.ToDenom) + i = encodeVarintFswap(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 = encodeVarintFswap(dAtA, i, uint64(len(m.FromDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SwapStats) 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 *SwapStats) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SwapStats) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SwapCount != 0 { + i = encodeVarintFswap(dAtA, i, uint64(m.SwapCount)) + i-- + dAtA[i] = 0x8 + } + 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) { @@ -107,21 +508,21 @@ func (m *Swapped) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size := m.NewCoinAmount.Size() - i -= size - if _, err := m.NewCoinAmount.MarshalTo(dAtA[i:]); err != nil { + size, err := m.ToCoinAmount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { return 0, err } + i -= size i = encodeVarintFswap(dAtA, i, uint64(size)) } i-- dAtA[i] = 0x12 { - size := m.OldCoinAmount.Size() - i -= size - if _, err := m.OldCoinAmount.MarshalTo(dAtA[i:]); err != nil { + size, err := m.FromCoinAmount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { return 0, err } + i -= size i = encodeVarintFswap(dAtA, i, uint64(size)) } i-- @@ -140,15 +541,69 @@ func encodeVarintFswap(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *Swap) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.FromDenom) + if l > 0 { + n += 1 + l + sovFswap(uint64(l)) + } + l = len(m.ToDenom) + if l > 0 { + n += 1 + l + sovFswap(uint64(l)) + } + l = m.AmountCapForToDenom.Size() + n += 1 + l + sovFswap(uint64(l)) + l = m.SwapRate.Size() + n += 1 + l + sovFswap(uint64(l)) + return n +} + +func (m *SwapStats) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SwapCount != 0 { + n += 1 + sovFswap(uint64(m.SwapCount)) + } + 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 } var l int _ = l - l = m.OldCoinAmount.Size() + l = m.FromCoinAmount.Size() n += 1 + l + sovFswap(uint64(l)) - l = m.NewCoinAmount.Size() + l = m.ToCoinAmount.Size() n += 1 + l + sovFswap(uint64(l)) return n } @@ -159,7 +614,7 @@ func sovFswap(x uint64) (n int) { func sozFswap(x uint64) (n int) { return sovFswap(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *Swapped) Unmarshal(dAtA []byte) error { +func (m *Swap) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -182,15 +637,15 @@ func (m *Swapped) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Swapped: wiretype end group for non-group") + return fmt.Errorf("proto: Swap: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Swapped: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Swap: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field OldCoinAmount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field FromDenom", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -218,13 +673,11 @@ func (m *Swapped) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.OldCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.FromDenom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NewCoinAmount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ToDenom", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -252,7 +705,438 @@ func (m *Swapped) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.NewCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ToDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AmountCapForToDenom", 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 + } + if err := m.AmountCapForToDenom.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SwapRate", 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 + } + if err := m.SwapRate.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 *SwapStats) 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: SwapStats: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SwapStats: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SwapCount", wireType) + } + m.SwapCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFswap + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SwapCount |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 *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 + 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: Swapped: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Swapped: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FromCoinAmount", 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.FromCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ToCoinAmount", 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.ToCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/fswap/types/genesis.go b/x/fswap/types/genesis.go index 816ef241d0..08c1d79338 100644 --- a/x/fswap/types/genesis.go +++ b/x/fswap/types/genesis.go @@ -1,29 +1,39 @@ package types -// NewGenesis creates a new genesis state -func NewGenesisState(params Params, swapped Swapped) *GenesisState { +// DefaultGenesis returns the default Capability genesis state +func DefaultGenesis() *GenesisState { return &GenesisState{ - Params: params, - Swapped: swapped, + Swaps: []Swap{}, + SwapStats: SwapStats{}, + Swappeds: []Swapped{}, } } -// DefaultGenesis returns the default Capability genesis state -func DefaultGenesis() *GenesisState { - return NewGenesisState(DefaultParams(), DefaultSwapped()) -} +// Validate performs basic genesis state validation returning an error upon any failure. +func (gs *GenesisState) Validate() error { + for _, swap := range gs.GetSwaps() { + if err := swap.ValidateBasic(); err != nil { + return err + } + } -// Validate performs basic genesis state validation returning an error upon any -// failure. -func (gs GenesisState) Validate() error { - if err := gs.Params.Validate(); err != nil { + if err := gs.SwapStats.ValidateBasic(); err != nil { return err } - if err := gs.Swapped.Validate(); err != nil { - return err + + for _, swapped := range gs.GetSwappeds() { + if err := swapped.ValidateBasic(); err != nil { + return err + } + } + + if len(gs.GetSwaps()) != len(gs.GetSwappeds()) { + return ErrInvalidState.Wrap("number of swaps does not match number of Swappeds") } - if gs.Params.SwappableNewCoinAmount.LT(gs.Swapped.NewCoinAmount) { - return ErrExceedSwappable + + if len(gs.GetSwaps()) != int(gs.GetSwapStats().SwapCount) { + return ErrInvalidState.Wrap("number of swaps does not match swap count in SwapStats") } + return nil } diff --git a/x/fswap/types/genesis.pb.go b/x/fswap/types/genesis.pb.go index 5b76f03a14..89415e9484 100644 --- a/x/fswap/types/genesis.pb.go +++ b/x/fswap/types/genesis.pb.go @@ -25,8 +25,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the fswap module's genesis state. type GenesisState struct { - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - Swapped Swapped `protobuf:"bytes,2,opt,name=swapped,proto3" json:"swapped"` + Swaps []Swap `protobuf:"bytes,1,rep,name=swaps,proto3" json:"swaps"` + SwapStats SwapStats `protobuf:"bytes,2,opt,name=swap_stats,json=swapStats,proto3" json:"swap_stats"` + Swappeds []Swapped `protobuf:"bytes,3,rep,name=swappeds,proto3" json:"swappeds"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -62,18 +63,25 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetParams() Params { +func (m *GenesisState) GetSwaps() []Swap { if m != nil { - return m.Params + return m.Swaps } - return Params{} + return nil } -func (m *GenesisState) GetSwapped() Swapped { +func (m *GenesisState) GetSwapStats() SwapStats { if m != nil { - return m.Swapped + return m.SwapStats } - return Swapped{} + return SwapStats{} +} + +func (m *GenesisState) GetSwappeds() []Swapped { + if m != nil { + return m.Swappeds + } + return nil } func init() { @@ -83,22 +91,23 @@ func init() { func init() { proto.RegisterFile("lbm/fswap/v1/genesis.proto", fileDescriptor_94e309cb1db27661) } var fileDescriptor_94e309cb1db27661 = []byte{ - // 230 bytes of a gzipped FileDescriptorProto + // 255 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xca, 0x49, 0xca, 0xd5, 0x4f, 0x2b, 0x2e, 0x4f, 0x2c, 0xd0, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xc9, 0x49, 0xca, 0xd5, 0x03, 0xcb, 0xe9, 0x95, 0x19, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x25, 0xf4, 0x41, 0x2c, 0x88, 0x1a, 0x29, 0x09, - 0x14, 0xfd, 0x10, 0xc5, 0x10, 0x19, 0x49, 0x14, 0x99, 0x82, 0xc4, 0xa2, 0xc4, 0x5c, 0xa8, 0xc1, - 0x4a, 0x95, 0x5c, 0x3c, 0xee, 0x10, 0x9b, 0x82, 0x4b, 0x12, 0x4b, 0x52, 0x85, 0x8c, 0xb8, 0xd8, - 0x20, 0xf2, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0x22, 0x7a, 0xc8, 0x36, 0xeb, 0x05, 0x80, - 0xe5, 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0xaa, 0x14, 0x32, 0xe5, 0x62, 0x07, 0xc9, - 0x17, 0xa4, 0xa6, 0x48, 0x30, 0x81, 0x35, 0x89, 0xa2, 0x6a, 0x0a, 0x86, 0x48, 0x42, 0x75, 0xc1, - 0xd4, 0x3a, 0x79, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, - 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x5e, 0x7a, - 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0xbe, 0x5b, 0x66, 0x5e, 0x71, 0x72, 0x46, - 0x66, 0xa2, 0x7e, 0x1a, 0x94, 0xa1, 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x01, 0xf5, 0x4e, 0x49, 0x65, - 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x2f, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xcb, 0xd0, - 0xcc, 0x0f, 0x42, 0x01, 0x00, 0x00, + 0x14, 0xfd, 0x10, 0xc5, 0x60, 0x19, 0xa5, 0xad, 0x8c, 0x5c, 0x3c, 0xee, 0x10, 0xf3, 0x82, 0x4b, + 0x12, 0x4b, 0x52, 0x85, 0xf4, 0xb8, 0x58, 0x41, 0xd2, 0xc5, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0xdc, + 0x46, 0x42, 0x7a, 0xc8, 0xc6, 0xeb, 0x05, 0x97, 0x27, 0x16, 0x38, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, + 0x10, 0x04, 0x51, 0x26, 0x64, 0xc3, 0xc5, 0x05, 0x62, 0xc4, 0x17, 0x97, 0x24, 0x96, 0x14, 0x4b, + 0x30, 0x29, 0x30, 0x6a, 0x70, 0x1b, 0x89, 0x63, 0x6a, 0x02, 0x19, 0x5e, 0x0c, 0xd5, 0xc9, 0x59, + 0x0c, 0x13, 0x10, 0x32, 0xe7, 0xe2, 0x00, 0x71, 0x0a, 0x52, 0x53, 0x8a, 0x25, 0x98, 0xc1, 0x16, + 0x8a, 0x62, 0xea, 0x2d, 0x48, 0x4d, 0x81, 0xea, 0x84, 0x2b, 0x76, 0xf2, 0x38, 0xf1, 0x48, 0x8e, + 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, + 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xbd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, + 0xfc, 0x5c, 0x7d, 0xb7, 0xcc, 0xbc, 0xe2, 0xe4, 0x8c, 0xcc, 0x44, 0xfd, 0x34, 0x28, 0x43, 0xb7, + 0x38, 0x25, 0x5b, 0xbf, 0x02, 0x1a, 0x14, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x80, + 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x4f, 0x1a, 0xa2, 0xb3, 0x64, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -121,8 +130,22 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Swappeds) > 0 { + for iNdEx := len(m.Swappeds) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Swappeds[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } { - size, err := m.Swapped.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.SwapStats.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -131,16 +154,20 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { } i-- dAtA[i] = 0x12 - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.Swaps) > 0 { + for iNdEx := len(m.Swaps) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Swaps[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -161,10 +188,20 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l - l = m.Params.Size() - n += 1 + l + sovGenesis(uint64(l)) - l = m.Swapped.Size() + if len(m.Swaps) > 0 { + for _, e := range m.Swaps { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + l = m.SwapStats.Size() n += 1 + l + sovGenesis(uint64(l)) + if len(m.Swappeds) > 0 { + for _, e := range m.Swappeds { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -205,7 +242,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Swaps", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -232,13 +269,47 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Swaps = append(m.Swaps, Swap{}) + if err := m.Swaps[len(m.Swaps)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Swapped", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SwapStats", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SwapStats.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Swappeds", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -265,7 +336,8 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Swapped.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Swappeds = append(m.Swappeds, Swapped{}) + if err := m.Swappeds[len(m.Swappeds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/fswap/types/genesis_test.go b/x/fswap/types/genesis_test.go index 15394d1ac0..29308ea519 100644 --- a/x/fswap/types/genesis_test.go +++ b/x/fswap/types/genesis_test.go @@ -5,10 +5,10 @@ import ( "github.com/stretchr/testify/require" - sdk "github.com/Finschia/finschia-sdk/types" "github.com/Finschia/finschia-sdk/x/fswap/types" ) +// todo: add tests func TestGenesisStateValidate(t *testing.T) { for _, tc := range []struct { desc string @@ -20,72 +20,6 @@ func TestGenesisStateValidate(t *testing.T) { genState: types.DefaultGenesis(), valid: true, }, - { - desc: "empty genesisState", - genState: &types.GenesisState{}, - valid: false, - }, - { - desc: "empty params", - genState: &types.GenesisState{ - Swapped: types.DefaultSwapped(), - }, - valid: false, - }, - { - desc: "empty swapped", - genState: &types.GenesisState{ - Params: types.DefaultParams(), - }, - valid: false, - }, - { - desc: "empty swappableNewCoinAmount in params", - genState: &types.GenesisState{ - Params: types.Params{}, - Swapped: types.DefaultSwapped(), - }, - valid: false, - }, - { - desc: "empty oldCoin in Swapped", - genState: &types.GenesisState{ - Params: types.DefaultParams(), - Swapped: types.Swapped{ - NewCoinAmount: sdk.ZeroInt(), - }, - }, - valid: false, - }, - { - desc: "empty newCoin in Swapped", - genState: &types.GenesisState{ - Params: types.DefaultParams(), - Swapped: types.Swapped{ - OldCoinAmount: sdk.ZeroInt(), - }, - }, - valid: false, - }, - { - desc: "coinAmount is negative", - genState: &types.GenesisState{ - Params: types.DefaultParams(), - Swapped: types.Swapped{ - NewCoinAmount: sdk.ZeroInt(), - OldCoinAmount: sdk.NewInt(-1), - }, - }, - valid: false, - }, - { - desc: "swappable coin exceed", - genState: &types.GenesisState{ - Params: types.NewParams(sdk.NewInt(1000)), - Swapped: types.NewSwapped(sdk.NewInt(1000), sdk.NewInt(100000)), - }, - valid: false, - }, } { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() diff --git a/x/fswap/types/keys.go b/x/fswap/types/keys.go index a13045fad7..d69f08c9e0 100644 --- a/x/fswap/types/keys.go +++ b/x/fswap/types/keys.go @@ -12,16 +12,4 @@ const ( // QuerierRoute defines the module's query routing key QuerierRoute = ModuleName - - // MemStoreKey defines the in-memory store key - MemStoreKey = "mem_fswap" -) - -var ( - ParamsKey = byte(0x00) - SwappedKey = byte(0x01) ) - -func KeyPrefix(p string) []byte { - return []byte(p) -} diff --git a/x/fswap/types/msgs.go b/x/fswap/types/msgs.go index 4f4ad81cb5..eae8c6a2c2 100644 --- a/x/fswap/types/msgs.go +++ b/x/fswap/types/msgs.go @@ -3,68 +3,77 @@ 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 = &MsgSwapRequest{} - -// NewMsgSwapRequest - construct a msg to swap amounts of old coin to new coin -// -//nolint:interfacer -func NewMsgSwapRequest(fromAddr, toAddr sdk.AccAddress, amount sdk.Coin) *MsgSwapRequest { - return &MsgSwapRequest{FromAddress: fromAddr.String(), Amount: amount} -} +var _ sdk.Msg = &MsgSwap{} // ValidateBasic Implements Msg. -func (msg MsgSwapRequest) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(msg.FromAddress) +func (m *MsgSwap) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(m.FromAddress) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid address (%s)", err) + return sdkerrors.ErrInvalidAddress.Wrapf("Invalid address (%s)", err) + } + + if !m.FromCoinAmount.IsValid() { + return sdkerrors.ErrInvalidCoins.Wrap(m.FromCoinAmount.String()) } - if !msg.Amount.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.Amount.String()) + if !m.FromCoinAmount.IsPositive() { + return sdkerrors.ErrInvalidCoins.Wrap(m.FromCoinAmount.String()) } - if !msg.Amount.IsPositive() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.Amount.String()) + if len(m.GetToDenom()) == 0 { + return sdkerrors.ErrInvalidRequest.Wrap("invalid denom (empty denom)") } return nil } // GetSigners Implements Msg. -func (msg MsgSwapRequest) GetSigners() []sdk.AccAddress { - from, err := sdk.AccAddressFromBech32(msg.FromAddress) +func (m *MsgSwap) GetSigners() []sdk.AccAddress { + from, err := sdk.AccAddressFromBech32(m.FromAddress) if err != nil { panic(err) } return []sdk.AccAddress{from} } -var _ sdk.Msg = &MsgSwapAllRequest{} - -// NewMsgSwapRequest - construct a msg to swap all old coin to new coin -// -//nolint:interfacer -func NewMsgSwapAllRequest(fromAddr, toAddr sdk.AccAddress) *MsgSwapAllRequest { - return &MsgSwapAllRequest{FromAddress: fromAddr.String()} +// GetSignBytes implements the LegacyMsg.GetSignBytes method. +func (m *MsgSwap) GetSignBytes() []byte { + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(m)) } +var _ sdk.Msg = &MsgSwapAll{} + // ValidateBasic Implements Msg. -func (msg MsgSwapAllRequest) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(msg.FromAddress) +func (m *MsgSwapAll) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(m.FromAddress) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid address (%s)", err) + return sdkerrors.ErrInvalidAddress.Wrapf("Invalid address (%s)", err) + } + + if len(m.GetFromDenom()) == 0 { + return sdkerrors.ErrInvalidRequest.Wrap("invalid denom (empty denom)") + } + + if len(m.GetToDenom()) == 0 { + return sdkerrors.ErrInvalidRequest.Wrap("invalid denom (empty denom)") } return nil } // GetSigners Implements Msg. -func (msg MsgSwapAllRequest) GetSigners() []sdk.AccAddress { - from, err := sdk.AccAddressFromBech32(msg.FromAddress) +func (m *MsgSwapAll) GetSigners() []sdk.AccAddress { + from, err := sdk.AccAddressFromBech32(m.FromAddress) if err != nil { panic(err) } return []sdk.AccAddress{from} } + +// GetSignBytes implements the LegacyMsg.GetSignBytes method. +func (m *MsgSwapAll) GetSignBytes() []byte { + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(m)) +} diff --git a/x/fswap/types/params.go b/x/fswap/types/params.go deleted file mode 100644 index fbfedf3534..0000000000 --- a/x/fswap/types/params.go +++ /dev/null @@ -1,35 +0,0 @@ -package types - -import ( - "gopkg.in/yaml.v2" - - sdk "github.com/Finschia/finschia-sdk/types" -) - -// NewParams creates a new Params instance -func NewParams( - swappableNewCoinAmount sdk.Int, -) Params { - return Params{ - SwappableNewCoinAmount: swappableNewCoinAmount, - } -} - -// DefaultParams returns a default set of parameters -func DefaultParams() Params { - return NewParams(sdk.ZeroInt()) -} - -// Validate validates the set of params -func (p Params) Validate() error { - if err := validateCoinAmount(p.SwappableNewCoinAmount); err != nil { - return err - } - return nil -} - -// String implements the Stringer interface. -func (p Params) String() string { - out, _ := yaml.Marshal(p) - return string(out) -} diff --git a/x/fswap/types/params.pb.go b/x/fswap/types/params.pb.go deleted file mode 100644 index 8e9887228b..0000000000 --- a/x/fswap/types/params.pb.go +++ /dev/null @@ -1,317 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: lbm/fswap/v1/params.proto - -package types - -import ( - fmt "fmt" - github_com_Finschia_finschia_sdk_types "github.com/Finschia/finschia-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// Params defines the parameters for the module. -type Params struct { - SwappableNewCoinAmount github_com_Finschia_finschia_sdk_types.Int `protobuf:"bytes,1,opt,name=swappable_new_coin_amount,json=swappableNewCoinAmount,proto3,customtype=github.com/Finschia/finschia-sdk/types.Int" json:"swappable_new_coin_amount"` -} - -func (m *Params) Reset() { *m = Params{} } -func (*Params) ProtoMessage() {} -func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_15e620b81032c44d, []int{0} -} -func (m *Params) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { - xxx_messageInfo_Params.Merge(m, src) -} -func (m *Params) XXX_Size() int { - return m.Size() -} -func (m *Params) XXX_DiscardUnknown() { - xxx_messageInfo_Params.DiscardUnknown(m) -} - -var xxx_messageInfo_Params proto.InternalMessageInfo - -func init() { - proto.RegisterType((*Params)(nil), "lbm.fswap.v1.Params") -} - -func init() { proto.RegisterFile("lbm/fswap/v1/params.proto", fileDescriptor_15e620b81032c44d) } - -var fileDescriptor_15e620b81032c44d = []byte{ - // 225 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0x49, 0xca, 0xd5, - 0x4f, 0x2b, 0x2e, 0x4f, 0x2c, 0xd0, 0x2f, 0x33, 0xd4, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xc9, 0x49, 0xca, 0xd5, 0x03, 0x4b, 0xe9, 0x95, 0x19, - 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x25, 0xf4, 0x41, 0x2c, 0x88, 0x1a, 0xa5, 0x5a, 0x2e, - 0xb6, 0x00, 0xb0, 0x1e, 0xa1, 0x5c, 0x2e, 0x49, 0x90, 0xd2, 0x82, 0xc4, 0xa4, 0x9c, 0xd4, 0xf8, - 0xbc, 0xd4, 0xf2, 0xf8, 0xe4, 0xfc, 0xcc, 0xbc, 0xf8, 0xc4, 0xdc, 0xfc, 0xd2, 0xbc, 0x12, 0x09, - 0x46, 0x05, 0x46, 0x0d, 0x4e, 0x27, 0xa3, 0x13, 0xf7, 0xe4, 0x19, 0x6e, 0xdd, 0x93, 0xd7, 0x4a, - 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x77, 0xcb, 0xcc, 0x2b, 0x4e, 0xce, - 0xc8, 0x4c, 0xd4, 0x4f, 0x83, 0x32, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, - 0xf5, 0x3c, 0xf3, 0x4a, 0x82, 0xc4, 0xe0, 0x86, 0xfa, 0xa5, 0x96, 0x3b, 0xe7, 0x67, 0xe6, 0x39, - 0x82, 0x4d, 0xb4, 0x62, 0x99, 0xb1, 0x40, 0x9e, 0xc1, 0xc9, 0xe3, 0xc4, 0x23, 0x39, 0xc6, 0x0b, - 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, - 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xf4, 0x08, 0xda, 0x51, 0x01, 0xf5, 0x36, 0xd8, 0xae, 0x24, 0x36, - 0xb0, 0x7f, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x53, 0xb6, 0x13, 0xee, 0x10, 0x01, 0x00, - 0x00, -} - -func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.SwappableNewCoinAmount.Size() - i -= size - if _, err := m.SwappableNewCoinAmount.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintParams(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func encodeVarintParams(dAtA []byte, offset int, v uint64) int { - offset -= sovParams(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Params) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.SwappableNewCoinAmount.Size() - n += 1 + l + sovParams(uint64(l)) - return n -} - -func sovParams(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozParams(x uint64) (n int) { - return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Params) 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 ErrIntOverflowParams - } - 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: Params: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SwappableNewCoinAmount", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - 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 ErrInvalidLengthParams - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthParams - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.SwappableNewCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipParams(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthParams - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipParams(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowParams - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowParams - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowParams - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthParams - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupParams - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthParams - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/fswap/types/proposal.go b/x/fswap/types/proposal.go new file mode 100644 index 0000000000..99048caa57 --- /dev/null +++ b/x/fswap/types/proposal.go @@ -0,0 +1,54 @@ +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/query.pb.go b/x/fswap/types/query.pb.go index 67643e704b..80beb5195a 100644 --- a/x/fswap/types/query.pb.go +++ b/x/fswap/types/query.pb.go @@ -7,6 +7,7 @@ import ( context "context" fmt "fmt" types "github.com/Finschia/finschia-sdk/types" + query "github.com/Finschia/finschia-sdk/types/query" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -31,6 +32,8 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type QuerySwappedRequest 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 *QuerySwappedRequest) Reset() { *m = QuerySwappedRequest{} } @@ -66,9 +69,23 @@ func (m *QuerySwappedRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QuerySwappedRequest proto.InternalMessageInfo +func (m *QuerySwappedRequest) GetFromDenom() string { + if m != nil { + return m.FromDenom + } + return "" +} + +func (m *QuerySwappedRequest) GetToDenom() string { + if m != nil { + return m.ToDenom + } + return "" +} + type QuerySwappedResponse struct { - OldCoin types.Coin `protobuf:"bytes,1,opt,name=old_coin,json=oldCoin,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"old_coin"` - NewCoin types.Coin `protobuf:"bytes,2,opt,name=new_coin,json=newCoin,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"new_coin"` + 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 *QuerySwappedResponse) Reset() { *m = QuerySwappedResponse{} } @@ -104,35 +121,39 @@ func (m *QuerySwappedResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QuerySwappedResponse proto.InternalMessageInfo -func (m *QuerySwappedResponse) GetOldCoin() types.Coin { +func (m *QuerySwappedResponse) GetFromCoinAmount() types.Coin { if m != nil { - return m.OldCoin + return m.FromCoinAmount } return types.Coin{} } -func (m *QuerySwappedResponse) GetNewCoin() types.Coin { +func (m *QuerySwappedResponse) GetToCoinAmount() types.Coin { if m != nil { - return m.NewCoin + return m.ToCoinAmount } return types.Coin{} } -type QueryTotalSwappableAmountRequest struct { +type QueryTotalSwappableToCoinAmountRequest 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 *QueryTotalSwappableAmountRequest) Reset() { *m = QueryTotalSwappableAmountRequest{} } -func (m *QueryTotalSwappableAmountRequest) String() string { return proto.CompactTextString(m) } -func (*QueryTotalSwappableAmountRequest) ProtoMessage() {} -func (*QueryTotalSwappableAmountRequest) Descriptor() ([]byte, []int) { +func (m *QueryTotalSwappableToCoinAmountRequest) Reset() { + *m = QueryTotalSwappableToCoinAmountRequest{} +} +func (m *QueryTotalSwappableToCoinAmountRequest) String() string { return proto.CompactTextString(m) } +func (*QueryTotalSwappableToCoinAmountRequest) ProtoMessage() {} +func (*QueryTotalSwappableToCoinAmountRequest) Descriptor() ([]byte, []int) { return fileDescriptor_01deae9da7816d6a, []int{2} } -func (m *QueryTotalSwappableAmountRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryTotalSwappableToCoinAmountRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryTotalSwappableAmountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryTotalSwappableToCoinAmountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryTotalSwappableAmountRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryTotalSwappableToCoinAmountRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -142,34 +163,50 @@ func (m *QueryTotalSwappableAmountRequest) XXX_Marshal(b []byte, deterministic b return b[:n], nil } } -func (m *QueryTotalSwappableAmountRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryTotalSwappableAmountRequest.Merge(m, src) +func (m *QueryTotalSwappableToCoinAmountRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTotalSwappableToCoinAmountRequest.Merge(m, src) } -func (m *QueryTotalSwappableAmountRequest) XXX_Size() int { +func (m *QueryTotalSwappableToCoinAmountRequest) XXX_Size() int { return m.Size() } -func (m *QueryTotalSwappableAmountRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryTotalSwappableAmountRequest.DiscardUnknown(m) +func (m *QueryTotalSwappableToCoinAmountRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTotalSwappableToCoinAmountRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryTotalSwappableAmountRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryTotalSwappableToCoinAmountRequest proto.InternalMessageInfo + +func (m *QueryTotalSwappableToCoinAmountRequest) GetFromDenom() string { + if m != nil { + return m.FromDenom + } + return "" +} + +func (m *QueryTotalSwappableToCoinAmountRequest) GetToDenom() string { + if m != nil { + return m.ToDenom + } + return "" +} -type QueryTotalSwappableAmountResponse struct { - SwappableNewCoin types.Coin `protobuf:"bytes,1,opt,name=swappable_new_coin,json=swappableNewCoin,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"swappable_new_coin"` +type QueryTotalSwappableToCoinAmountResponse struct { + SwappableAmount types.Coin `protobuf:"bytes,1,opt,name=swappable_amount,json=swappableAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"swappable_amount"` } -func (m *QueryTotalSwappableAmountResponse) Reset() { *m = QueryTotalSwappableAmountResponse{} } -func (m *QueryTotalSwappableAmountResponse) String() string { return proto.CompactTextString(m) } -func (*QueryTotalSwappableAmountResponse) ProtoMessage() {} -func (*QueryTotalSwappableAmountResponse) Descriptor() ([]byte, []int) { +func (m *QueryTotalSwappableToCoinAmountResponse) Reset() { + *m = QueryTotalSwappableToCoinAmountResponse{} +} +func (m *QueryTotalSwappableToCoinAmountResponse) String() string { return proto.CompactTextString(m) } +func (*QueryTotalSwappableToCoinAmountResponse) ProtoMessage() {} +func (*QueryTotalSwappableToCoinAmountResponse) Descriptor() ([]byte, []int) { return fileDescriptor_01deae9da7816d6a, []int{3} } -func (m *QueryTotalSwappableAmountResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryTotalSwappableToCoinAmountResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryTotalSwappableAmountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryTotalSwappableToCoinAmountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryTotalSwappableAmountResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryTotalSwappableToCoinAmountResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -179,65 +216,171 @@ func (m *QueryTotalSwappableAmountResponse) XXX_Marshal(b []byte, deterministic return b[:n], nil } } -func (m *QueryTotalSwappableAmountResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryTotalSwappableAmountResponse.Merge(m, src) +func (m *QueryTotalSwappableToCoinAmountResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTotalSwappableToCoinAmountResponse.Merge(m, src) } -func (m *QueryTotalSwappableAmountResponse) XXX_Size() int { +func (m *QueryTotalSwappableToCoinAmountResponse) XXX_Size() int { return m.Size() } -func (m *QueryTotalSwappableAmountResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryTotalSwappableAmountResponse.DiscardUnknown(m) +func (m *QueryTotalSwappableToCoinAmountResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTotalSwappableToCoinAmountResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryTotalSwappableAmountResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryTotalSwappableToCoinAmountResponse proto.InternalMessageInfo -func (m *QueryTotalSwappableAmountResponse) GetSwappableNewCoin() types.Coin { +func (m *QueryTotalSwappableToCoinAmountResponse) GetSwappableAmount() types.Coin { if m != nil { - return m.SwappableNewCoin + return m.SwappableAmount } return types.Coin{} } +type QuerySwapsRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +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} +} +func (m *QuerySwapsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySwapsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySwapsRequest.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 *QuerySwapsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySwapsRequest.Merge(m, src) +} +func (m *QuerySwapsRequest) XXX_Size() int { + return m.Size() +} +func (m *QuerySwapsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySwapsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySwapsRequest proto.InternalMessageInfo + +func (m *QuerySwapsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QuerySwapsResponse struct { + Swaps []Swap `protobuf:"bytes,1,rep,name=swaps,proto3" json:"swaps"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +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} +} +func (m *QuerySwapsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySwapsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySwapsResponse.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 *QuerySwapsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySwapsResponse.Merge(m, src) +} +func (m *QuerySwapsResponse) XXX_Size() int { + return m.Size() +} +func (m *QuerySwapsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySwapsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySwapsResponse proto.InternalMessageInfo + +func (m *QuerySwapsResponse) GetSwaps() []Swap { + if m != nil { + return m.Swaps + } + return nil +} + +func (m *QuerySwapsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + func init() { proto.RegisterType((*QuerySwappedRequest)(nil), "lbm.fswap.v1.QuerySwappedRequest") proto.RegisterType((*QuerySwappedResponse)(nil), "lbm.fswap.v1.QuerySwappedResponse") - proto.RegisterType((*QueryTotalSwappableAmountRequest)(nil), "lbm.fswap.v1.QueryTotalSwappableAmountRequest") - proto.RegisterType((*QueryTotalSwappableAmountResponse)(nil), "lbm.fswap.v1.QueryTotalSwappableAmountResponse") + proto.RegisterType((*QueryTotalSwappableToCoinAmountRequest)(nil), "lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest") + proto.RegisterType((*QueryTotalSwappableToCoinAmountResponse)(nil), "lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse") + proto.RegisterType((*QuerySwapsRequest)(nil), "lbm.fswap.v1.QuerySwapsRequest") + proto.RegisterType((*QuerySwapsResponse)(nil), "lbm.fswap.v1.QuerySwapsResponse") } func init() { proto.RegisterFile("lbm/fswap/v1/query.proto", fileDescriptor_01deae9da7816d6a) } var fileDescriptor_01deae9da7816d6a = []byte{ - // 449 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xc1, 0x6a, 0xd4, 0x40, - 0x18, 0xc7, 0x33, 0x0b, 0x5a, 0x19, 0x3d, 0xc8, 0xd8, 0x62, 0x1b, 0x34, 0x6d, 0x73, 0x51, 0x11, - 0x67, 0x48, 0xfb, 0x04, 0x56, 0x10, 0x0f, 0x22, 0x58, 0x3d, 0x79, 0x59, 0x26, 0xc9, 0x34, 0x1d, - 0x4c, 0xe6, 0x4b, 0x33, 0x93, 0x8d, 0x05, 0x4f, 0x3e, 0x81, 0xe0, 0x13, 0x78, 0x13, 0xc1, 0xf7, - 0xe8, 0xb1, 0xe0, 0xc5, 0x93, 0xca, 0xae, 0x47, 0x1f, 0x42, 0x66, 0x32, 0x5d, 0x0c, 0x2c, 0xab, - 0x97, 0xbd, 0x7d, 0xe4, 0xfb, 0x66, 0x7e, 0xff, 0xef, 0xff, 0x9f, 0xe0, 0xcd, 0x32, 0xad, 0xd8, - 0x91, 0xee, 0x78, 0xcd, 0x26, 0x09, 0x3b, 0x69, 0x45, 0x73, 0x4a, 0xeb, 0x06, 0x0c, 0x90, 0x6b, - 0x65, 0x5a, 0x51, 0xd7, 0xa1, 0x93, 0x24, 0xbc, 0x55, 0x00, 0x14, 0xa5, 0x60, 0xbc, 0x96, 0x8c, - 0x2b, 0x05, 0x86, 0x1b, 0x09, 0x4a, 0xf7, 0xb3, 0xe1, 0x7a, 0x01, 0x05, 0xb8, 0x92, 0xd9, 0xca, - 0x7f, 0x8d, 0x32, 0xd0, 0x15, 0x68, 0x96, 0x72, 0x2d, 0xd8, 0x24, 0x49, 0x85, 0xe1, 0x09, 0xcb, - 0x40, 0x2a, 0xdf, 0x1f, 0xb2, 0x7b, 0x94, 0xeb, 0xc4, 0x1b, 0xf8, 0xc6, 0x73, 0x2b, 0xe5, 0x45, - 0xc7, 0xeb, 0x5a, 0xe4, 0x87, 0xe2, 0xa4, 0x15, 0xda, 0xc4, 0xbf, 0x11, 0x5e, 0x1f, 0x7e, 0xd7, - 0x35, 0x28, 0x2d, 0x88, 0xc4, 0x57, 0xa0, 0xcc, 0xc7, 0xf6, 0xee, 0x4d, 0xb4, 0x83, 0xee, 0x5e, - 0xdd, 0xdb, 0xa2, 0x3d, 0x9c, 0x5a, 0x38, 0xf5, 0x70, 0xfa, 0x08, 0xa4, 0x3a, 0xd8, 0x3f, 0xfb, - 0xbe, 0x1d, 0x7c, 0xfe, 0xb1, 0x7d, 0xbf, 0x90, 0xe6, 0xb8, 0x4d, 0x69, 0x06, 0x15, 0x7b, 0x2c, - 0x95, 0xce, 0x8e, 0x25, 0x67, 0x47, 0xbe, 0x78, 0xa0, 0xf3, 0xd7, 0xcc, 0x9c, 0xd6, 0x42, 0xbb, - 0x43, 0x87, 0x6b, 0x50, 0xe6, 0xb6, 0xb0, 0x28, 0x25, 0xba, 0x1e, 0x35, 0x5a, 0x0d, 0x4a, 0x89, - 0xce, 0x16, 0x71, 0x8c, 0x77, 0xdc, 0xb6, 0x2f, 0xc1, 0xf0, 0xd2, 0xad, 0xcc, 0xd3, 0x52, 0x3c, - 0xac, 0xa0, 0x55, 0xe6, 0xc2, 0x92, 0x8f, 0x08, 0xef, 0x2e, 0x19, 0xf2, 0xfe, 0xbc, 0xc5, 0x44, - 0x5f, 0xb4, 0xc6, 0x73, 0xf9, 0xab, 0x71, 0xea, 0xfa, 0x9c, 0xf4, 0xac, 0xdf, 0x63, 0xef, 0xd3, - 0x08, 0x5f, 0x72, 0x1a, 0x09, 0xe0, 0x35, 0x1f, 0x1d, 0xd9, 0xa5, 0x7f, 0xbf, 0x2f, 0xba, 0x20, - 0xee, 0x30, 0x5e, 0x36, 0xd2, 0x6f, 0x16, 0xdf, 0x7e, 0xf7, 0xf5, 0xd7, 0x87, 0xd1, 0x4d, 0xb2, - 0xc1, 0x06, 0x8f, 0x49, 0x7b, 0xca, 0x17, 0x84, 0xb7, 0x9c, 0x33, 0x56, 0x4b, 0xdb, 0x34, 0x42, - 0x65, 0xee, 0x8a, 0xa7, 0xb2, 0x92, 0x86, 0xd0, 0x05, 0x80, 0x25, 0x66, 0x87, 0xec, 0xbf, 0xe7, - 0xbd, 0x3a, 0xe6, 0xd4, 0xdd, 0x23, 0x77, 0x16, 0xa8, 0x1b, 0x64, 0x31, 0xe6, 0xee, 0xe0, 0xc1, - 0x93, 0xb3, 0x69, 0x84, 0xce, 0xa7, 0x11, 0xfa, 0x39, 0x8d, 0xd0, 0xfb, 0x59, 0x14, 0x9c, 0xcf, - 0xa2, 0xe0, 0xdb, 0x2c, 0x0a, 0x5e, 0xd1, 0x7f, 0x66, 0xf0, 0xc6, 0x03, 0x5c, 0x16, 0xe9, 0x65, - 0xf7, 0x27, 0xed, 0xff, 0x09, 0x00, 0x00, 0xff, 0xff, 0x91, 0x66, 0x98, 0xa4, 0xe1, 0x03, 0x00, - 0x00, + // 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, 0x9d, 0xcc, 0xed, 0xcd, 0x16, 0x88, 0x10, 0x04, 0xf5, 0x98, 0xe0, 0x49, + 0x69, 0xda, 0xaf, 0x7a, 0x5c, 0xb2, 0x2a, 0x8d, 0x99, 0x1f, 0x44, 0xba, 0x84, 0xd1, 0x3a, 0x59, + 0x6d, 0xaa, 0x6a, 0x41, 0x90, 0xc6, 0xf3, 0x9c, 0x09, 0x96, 0x8e, 0xb8, 0x8f, 0xd1, 0xca, 0x53, + 0x55, 0xfb, 0xd9, 0x11, 0x8b, 0x63, 0xbe, 0xdf, 0xe0, 0x87, 0x3d, 0x2e, 0x24, 0x5e, 0x47, 0xf3, + 0xed, 0x2e, 0x84, 0x0f, 0x78, 0x04, 0x61, 0xc9, 0xaa, 0x58, 0x5b, 0xf3, 0x8d, 0xf1, 0x05, 0x2e, + 0xa1, 0x39, 0x09, 0x49, 0xac, 0xa8, 0x63, 0xe9, 0x4f, 0xf7, 0x4d, 0x11, 0xad, 0xe6, 0xeb, 0x89, + 0x18, 0x22, 0xc1, 0xf1, 0x31, 0x5a, 0x56, 0xf9, 0x4d, 0x05, 0xd5, 0x64, 0x21, 0xf4, 0x22, 0xa9, + 0xeb, 0x2e, 0xd4, 0xae, 0x92, 0x04, 0x9e, 0x28, 0x78, 0x62, 0xe0, 0xc9, 0x7d, 0x08, 0xa2, 0xfa, + 0xf6, 0xc9, 0xb7, 0x72, 0xe1, 0xd3, 0xf7, 0xf2, 0x2d, 0x3f, 0x90, 0x07, 0x3d, 0x8f, 0xb4, 0x20, + 0xa4, 0xbb, 0x41, 0x24, 0x5a, 0x07, 0x01, 0xa3, 0x6d, 0x73, 0xb8, 0x23, 0xf6, 0x5f, 0x51, 0x39, + 0x88, 0xb9, 0xd0, 0x49, 0x8d, 0x25, 0xe5, 0xa3, 0x4e, 0xf7, 0xb4, 0x0b, 0x96, 0x68, 0x49, 0x42, + 0xce, 0xb7, 0x78, 0x21, 0xbe, 0x8b, 0x12, 0xc6, 0xae, 0xee, 0x4b, 0xb4, 0xa1, 0xfb, 0xb0, 0x07, + 0x92, 0x75, 0x74, 0x33, 0x98, 0xd7, 0xe1, 0x7b, 0x19, 0xc9, 0xbf, 0xb6, 0xfa, 0xa3, 0x85, 0x36, + 0xa7, 0x5a, 0x98, 0xee, 0x0f, 0xd0, 0xb2, 0x48, 0x05, 0x17, 0xdb, 0xfd, 0x4b, 0x67, 0x3e, 0xa6, + 0x11, 0x2f, 0xd0, 0xe5, 0xb3, 0x81, 0x10, 0xe9, 0x9b, 0x77, 0x11, 0x1a, 0xcf, 0xb0, 0x21, 0xd9, + 0xc8, 0x91, 0x24, 0xbb, 0x94, 0xf2, 0x3c, 0x61, 0x3e, 0x37, 0xb9, 0x8d, 0x4c, 0xa6, 0xfb, 0xd6, + 0x42, 0x38, 0x5b, 0xdd, 0x3c, 0x97, 0xa0, 0x59, 0x85, 0x21, 0x4a, 0x56, 0x65, 0x66, 0x6b, 0xa1, + 0x86, 0x49, 0x76, 0x19, 0x89, 0xd2, 0xd6, 0xff, 0x53, 0x8f, 0x6b, 0x24, 0x32, 0xfc, 0x30, 0x87, + 0x93, 0x8c, 0xc7, 0xe6, 0x54, 0x9c, 0xc4, 0x2c, 0xcb, 0x53, 0xfb, 0x30, 0x83, 0x66, 0x35, 0x0f, + 0x06, 0x34, 0x67, 0x56, 0x00, 0xdf, 0xc8, 0xdb, 0x9f, 0xb3, 0x6e, 0xb6, 0xfb, 0x27, 0x49, 0xe2, + 0xe3, 0x5e, 0x7f, 0xfd, 0xe5, 0xe7, 0xfb, 0xe2, 0x15, 0xbc, 0x46, 0x73, 0xcb, 0x2c, 0x8c, 0xcb, + 0x67, 0x0b, 0xd9, 0x93, 0x27, 0x01, 0xef, 0x9c, 0xe3, 0x30, 0x75, 0x36, 0xed, 0xbb, 0x7f, 0x99, + 0x65, 0x50, 0x77, 0x34, 0x2a, 0xc1, 0xb7, 0xf3, 0xa8, 0x52, 0x65, 0x36, 0xc7, 0x83, 0x98, 0x5f, + 0x4b, 0xec, 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, } // Reference imports to suppress errors if they are not otherwise used. @@ -252,8 +395,13 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { + // Swapped queries the current swapped status that includes a burnt amount of from-coin and a minted amount of + // to-coin. Swapped(ctx context.Context, in *QuerySwappedRequest, opts ...grpc.CallOption) (*QuerySwappedResponse, error) - TotalNewCurrencySwapLimit(ctx context.Context, in *QueryTotalSwappableAmountRequest, opts ...grpc.CallOption) (*QueryTotalSwappableAmountResponse, error) + // TotalSwappableToCoinAmount queries the current swappable amount for to-coin. + TotalSwappableToCoinAmount(ctx context.Context, in *QueryTotalSwappableToCoinAmountRequest, opts ...grpc.CallOption) (*QueryTotalSwappableToCoinAmountResponse, error) + // Swaps queries all the swap that registered + Swaps(ctx context.Context, in *QuerySwapsRequest, opts ...grpc.CallOption) (*QuerySwapsResponse, error) } type queryClient struct { @@ -273,9 +421,18 @@ func (c *queryClient) Swapped(ctx context.Context, in *QuerySwappedRequest, opts return out, nil } -func (c *queryClient) TotalNewCurrencySwapLimit(ctx context.Context, in *QueryTotalSwappableAmountRequest, opts ...grpc.CallOption) (*QueryTotalSwappableAmountResponse, error) { - out := new(QueryTotalSwappableAmountResponse) - err := c.cc.Invoke(ctx, "/lbm.fswap.v1.Query/TotalNewCurrencySwapLimit", in, out, opts...) +func (c *queryClient) TotalSwappableToCoinAmount(ctx context.Context, in *QueryTotalSwappableToCoinAmountRequest, opts ...grpc.CallOption) (*QueryTotalSwappableToCoinAmountResponse, error) { + out := new(QueryTotalSwappableToCoinAmountResponse) + err := c.cc.Invoke(ctx, "/lbm.fswap.v1.Query/TotalSwappableToCoinAmount", 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...) if err != nil { return nil, err } @@ -284,8 +441,13 @@ func (c *queryClient) TotalNewCurrencySwapLimit(ctx context.Context, in *QueryTo // QueryServer is the server API for Query service. type QueryServer interface { + // Swapped queries the current swapped status that includes a burnt amount of from-coin and a minted amount of + // to-coin. Swapped(context.Context, *QuerySwappedRequest) (*QuerySwappedResponse, error) - TotalNewCurrencySwapLimit(context.Context, *QueryTotalSwappableAmountRequest) (*QueryTotalSwappableAmountResponse, error) + // TotalSwappableToCoinAmount queries the current swappable amount for to-coin. + TotalSwappableToCoinAmount(context.Context, *QueryTotalSwappableToCoinAmountRequest) (*QueryTotalSwappableToCoinAmountResponse, error) + // Swaps queries all the swap that registered + Swaps(context.Context, *QuerySwapsRequest) (*QuerySwapsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -295,8 +457,11 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Swapped(ctx context.Context, req *QuerySwappedRequest) (*QuerySwappedResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Swapped not implemented") } -func (*UnimplementedQueryServer) TotalNewCurrencySwapLimit(ctx context.Context, req *QueryTotalSwappableAmountRequest) (*QueryTotalSwappableAmountResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method TotalNewCurrencySwapLimit not implemented") +func (*UnimplementedQueryServer) TotalSwappableToCoinAmount(ctx context.Context, req *QueryTotalSwappableToCoinAmountRequest) (*QueryTotalSwappableToCoinAmountResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TotalSwappableToCoinAmount not implemented") +} +func (*UnimplementedQueryServer) Swaps(ctx context.Context, req *QuerySwapsRequest) (*QuerySwapsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Swaps not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -321,20 +486,38 @@ func _Query_Swapped_Handler(srv interface{}, ctx context.Context, dec func(inter return interceptor(ctx, in, info, handler) } -func _Query_TotalNewCurrencySwapLimit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryTotalSwappableAmountRequest) +func _Query_TotalSwappableToCoinAmount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryTotalSwappableToCoinAmountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).TotalSwappableToCoinAmount(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lbm.fswap.v1.Query/TotalSwappableToCoinAmount", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).TotalSwappableToCoinAmount(ctx, req.(*QueryTotalSwappableToCoinAmountRequest)) + } + 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 { return nil, err } if interceptor == nil { - return srv.(QueryServer).TotalNewCurrencySwapLimit(ctx, in) + return srv.(QueryServer).Swaps(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/lbm.fswap.v1.Query/TotalNewCurrencySwapLimit", + FullMethod: "/lbm.fswap.v1.Query/Swaps", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).TotalNewCurrencySwapLimit(ctx, req.(*QueryTotalSwappableAmountRequest)) + return srv.(QueryServer).Swaps(ctx, req.(*QuerySwapsRequest)) } return interceptor(ctx, in, info, handler) } @@ -348,8 +531,12 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_Swapped_Handler, }, { - MethodName: "TotalNewCurrencySwapLimit", - Handler: _Query_TotalNewCurrencySwapLimit_Handler, + MethodName: "TotalSwappableToCoinAmount", + Handler: _Query_TotalSwappableToCoinAmount_Handler, + }, + { + MethodName: "Swaps", + Handler: _Query_Swaps_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -376,6 +563,20 @@ func (m *QuerySwappedRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = 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 } @@ -400,7 +601,7 @@ func (m *QuerySwappedResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size, err := m.NewCoin.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.ToCoinAmount.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -410,7 +611,7 @@ func (m *QuerySwappedResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 { - size, err := m.OldCoin.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.FromCoinAmount.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -422,7 +623,7 @@ func (m *QuerySwappedResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryTotalSwappableAmountRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryTotalSwappableToCoinAmountRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -432,20 +633,34 @@ func (m *QueryTotalSwappableAmountRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryTotalSwappableAmountRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryTotalSwappableToCoinAmountRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryTotalSwappableAmountRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryTotalSwappableToCoinAmountRequest) 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 *QueryTotalSwappableAmountResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryTotalSwappableToCoinAmountResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -455,18 +670,18 @@ func (m *QueryTotalSwappableAmountResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryTotalSwappableAmountResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryTotalSwappableToCoinAmountResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryTotalSwappableAmountResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryTotalSwappableToCoinAmountResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l { - size, err := m.SwappableNewCoin.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.SwappableAmount.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -478,6 +693,90 @@ func (m *QueryTotalSwappableAmountResponse) MarshalToSizedBuffer(dAtA []byte) (i return len(dAtA) - i, nil } +func (m *QuerySwapsRequest) 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 *QuerySwapsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySwapsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.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 *QuerySwapsResponse) 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 *QuerySwapsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySwapsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Swaps) > 0 { + for iNdEx := len(m.Swaps) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Swaps[iNdEx].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 encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -495,6 +794,14 @@ func (m *QuerySwappedRequest) Size() (n int) { } 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 } @@ -504,33 +811,73 @@ func (m *QuerySwappedResponse) Size() (n int) { } var l int _ = l - l = m.OldCoin.Size() + l = m.FromCoinAmount.Size() n += 1 + l + sovQuery(uint64(l)) - l = m.NewCoin.Size() + l = m.ToCoinAmount.Size() n += 1 + l + sovQuery(uint64(l)) return n } -func (m *QueryTotalSwappableAmountRequest) Size() (n int) { +func (m *QueryTotalSwappableToCoinAmountRequest) 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 *QueryTotalSwappableAmountResponse) Size() (n int) { +func (m *QueryTotalSwappableToCoinAmountResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = m.SwappableNewCoin.Size() + l = m.SwappableAmount.Size() n += 1 + l + sovQuery(uint64(l)) return n } +func (m *QuerySwapsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QuerySwapsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Swaps) > 0 { + for _, e := range m.Swaps { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -566,6 +913,70 @@ func (m *QuerySwappedRequest) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: QuerySwappedRequest: 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:]) @@ -618,7 +1029,40 @@ func (m *QuerySwappedResponse) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field OldCoin", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field FromCoinAmount", 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.FromCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ToCoinAmount", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -645,13 +1089,177 @@ func (m *QuerySwappedResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.OldCoin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.ToCoinAmount.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 *QueryTotalSwappableToCoinAmountRequest) 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: QueryTotalSwappableToCoinAmountRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTotalSwappableToCoinAmountRequest: 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 NewCoin", wireType) + 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 *QueryTotalSwappableToCoinAmountResponse) 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: QueryTotalSwappableToCoinAmountResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTotalSwappableToCoinAmountResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SwappableAmount", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -678,7 +1286,7 @@ func (m *QuerySwappedResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.NewCoin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.SwappableAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -703,7 +1311,7 @@ func (m *QuerySwappedResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryTotalSwappableAmountRequest) Unmarshal(dAtA []byte) error { +func (m *QuerySwapsRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -726,12 +1334,48 @@ func (m *QueryTotalSwappableAmountRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryTotalSwappableAmountRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QuerySwapsRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryTotalSwappableAmountRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QuerySwapsRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -753,7 +1397,7 @@ func (m *QueryTotalSwappableAmountRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryTotalSwappableAmountResponse) Unmarshal(dAtA []byte) error { +func (m *QuerySwapsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -776,15 +1420,49 @@ func (m *QueryTotalSwappableAmountResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryTotalSwappableAmountResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QuerySwapsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryTotalSwappableAmountResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QuerySwapsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SwappableNewCoin", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Swaps", 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 + } + m.Swaps = append(m.Swaps, Swap{}) + if err := m.Swaps[len(m.Swaps)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -811,7 +1489,10 @@ func (m *QueryTotalSwappableAmountResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.SwappableNewCoin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/fswap/types/query.pb.gw.go b/x/fswap/types/query.pb.gw.go index 5a63817f6a..00786290bd 100644 --- a/x/fswap/types/query.pb.gw.go +++ b/x/fswap/types/query.pb.gw.go @@ -31,10 +31,21 @@ var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var ( + filter_Query_Swapped_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + func request_Query_Swapped_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QuerySwappedRequest 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_Swapped_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.Swapped(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -44,25 +55,86 @@ func local_request_Query_Swapped_0(ctx context.Context, marshaler runtime.Marsha var protoReq QuerySwappedRequest 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_Swapped_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Swapped(ctx, &protoReq) return msg, metadata, err } -func request_Query_TotalNewCurrencySwapLimit_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryTotalSwappableAmountRequest +var ( + filter_Query_TotalSwappableToCoinAmount_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_TotalSwappableToCoinAmount_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTotalSwappableToCoinAmountRequest + 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_TotalSwappableToCoinAmount_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.TotalSwappableToCoinAmount(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_TotalSwappableToCoinAmount_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTotalSwappableToCoinAmountRequest var metadata runtime.ServerMetadata - msg, err := client.TotalNewCurrencySwapLimit(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TotalSwappableToCoinAmount_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.TotalSwappableToCoinAmount(ctx, &protoReq) return msg, metadata, err } -func local_request_Query_TotalNewCurrencySwapLimit_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryTotalSwappableAmountRequest +var ( + filter_Query_Swaps_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Swaps_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySwapsRequest var metadata runtime.ServerMetadata - msg, err := server.TotalNewCurrencySwapLimit(ctx, &protoReq) + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Swaps_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Swaps(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Swaps_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySwapsRequest + 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_Swaps_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Swaps(ctx, &protoReq) return msg, metadata, err } @@ -93,7 +165,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_TotalNewCurrencySwapLimit_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_TotalSwappableToCoinAmount_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) @@ -102,14 +174,34 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_TotalNewCurrencySwapLimit_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_TotalSwappableToCoinAmount_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_TotalNewCurrencySwapLimit_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_TotalSwappableToCoinAmount_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() + 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_Swaps_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_Swaps_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -174,7 +266,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_TotalNewCurrencySwapLimit_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_TotalSwappableToCoinAmount_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) @@ -183,14 +275,34 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_TotalNewCurrencySwapLimit_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_TotalSwappableToCoinAmount_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_TotalNewCurrencySwapLimit_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_TotalSwappableToCoinAmount_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() + 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_Swaps_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_Swaps_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -200,11 +312,15 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie var ( pattern_Query_Swapped_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"lbm", "fswap", "v1", "swapped"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_TotalNewCurrencySwapLimit_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"lbm", "fswap", "v1", "swappable_new_coin_amount"}, "", runtime.AssumeColonVerbOpt(false))) + 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_Swaps_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"lbm", "fswap", "v1", "swaps"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Swapped_0 = runtime.ForwardResponseMessage - forward_Query_TotalNewCurrencySwapLimit_0 = runtime.ForwardResponseMessage + forward_Query_TotalSwappableToCoinAmount_0 = runtime.ForwardResponseMessage + + forward_Query_Swaps_0 = runtime.ForwardResponseMessage ) diff --git a/x/fswap/types/tx.pb.go b/x/fswap/types/tx.pb.go index 682ec7260b..288ada4778 100644 --- a/x/fswap/types/tx.pb.go +++ b/x/fswap/types/tx.pb.go @@ -29,25 +29,26 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type MsgSwapRequest struct { +type MsgSwap struct { // holder's address FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"` - // amount of old currency - Amount types.Coin `protobuf:"bytes,2,opt,name=amount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"amount"` + // from-coin amount + FromCoinAmount types.Coin `protobuf:"bytes,2,opt,name=from_coin_amount,json=fromCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"from_coin_amount"` + ToDenom string `protobuf:"bytes,3,opt,name=to_denom,json=toDenom,proto3" json:"to_denom,omitempty"` } -func (m *MsgSwapRequest) Reset() { *m = MsgSwapRequest{} } -func (m *MsgSwapRequest) String() string { return proto.CompactTextString(m) } -func (*MsgSwapRequest) ProtoMessage() {} -func (*MsgSwapRequest) Descriptor() ([]byte, []int) { +func (m *MsgSwap) Reset() { *m = MsgSwap{} } +func (m *MsgSwap) String() string { return proto.CompactTextString(m) } +func (*MsgSwap) ProtoMessage() {} +func (*MsgSwap) Descriptor() ([]byte, []int) { return fileDescriptor_65c77cf1d9b67323, []int{0} } -func (m *MsgSwapRequest) XXX_Unmarshal(b []byte) error { +func (m *MsgSwap) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgSwapRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgSwap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgSwapRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgSwap.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -57,32 +58,39 @@ func (m *MsgSwapRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, erro return b[:n], nil } } -func (m *MsgSwapRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgSwapRequest.Merge(m, src) +func (m *MsgSwap) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSwap.Merge(m, src) } -func (m *MsgSwapRequest) XXX_Size() int { +func (m *MsgSwap) XXX_Size() int { return m.Size() } -func (m *MsgSwapRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgSwapRequest.DiscardUnknown(m) +func (m *MsgSwap) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSwap.DiscardUnknown(m) } -var xxx_messageInfo_MsgSwapRequest proto.InternalMessageInfo +var xxx_messageInfo_MsgSwap proto.InternalMessageInfo -func (m *MsgSwapRequest) GetFromAddress() string { +func (m *MsgSwap) GetFromAddress() string { if m != nil { return m.FromAddress } return "" } -func (m *MsgSwapRequest) GetAmount() types.Coin { +func (m *MsgSwap) GetFromCoinAmount() types.Coin { if m != nil { - return m.Amount + return m.FromCoinAmount } return types.Coin{} } +func (m *MsgSwap) GetToDenom() string { + if m != nil { + return m.ToDenom + } + return "" +} + type MsgSwapResponse struct { } @@ -119,23 +127,25 @@ func (m *MsgSwapResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSwapResponse proto.InternalMessageInfo -type MsgSwapAllRequest struct { +type MsgSwapAll struct { // holder's address FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"` + FromDenom string `protobuf:"bytes,2,opt,name=from_denom,json=fromDenom,proto3" json:"from_denom,omitempty"` + ToDenom string `protobuf:"bytes,3,opt,name=to_denom,json=toDenom,proto3" json:"to_denom,omitempty"` } -func (m *MsgSwapAllRequest) Reset() { *m = MsgSwapAllRequest{} } -func (m *MsgSwapAllRequest) String() string { return proto.CompactTextString(m) } -func (*MsgSwapAllRequest) ProtoMessage() {} -func (*MsgSwapAllRequest) Descriptor() ([]byte, []int) { +func (m *MsgSwapAll) Reset() { *m = MsgSwapAll{} } +func (m *MsgSwapAll) String() string { return proto.CompactTextString(m) } +func (*MsgSwapAll) ProtoMessage() {} +func (*MsgSwapAll) Descriptor() ([]byte, []int) { return fileDescriptor_65c77cf1d9b67323, []int{2} } -func (m *MsgSwapAllRequest) XXX_Unmarshal(b []byte) error { +func (m *MsgSwapAll) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgSwapAllRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgSwapAll) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgSwapAllRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgSwapAll.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -145,25 +155,39 @@ func (m *MsgSwapAllRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *MsgSwapAllRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgSwapAllRequest.Merge(m, src) +func (m *MsgSwapAll) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSwapAll.Merge(m, src) } -func (m *MsgSwapAllRequest) XXX_Size() int { +func (m *MsgSwapAll) XXX_Size() int { return m.Size() } -func (m *MsgSwapAllRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgSwapAllRequest.DiscardUnknown(m) +func (m *MsgSwapAll) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSwapAll.DiscardUnknown(m) } -var xxx_messageInfo_MsgSwapAllRequest proto.InternalMessageInfo +var xxx_messageInfo_MsgSwapAll proto.InternalMessageInfo -func (m *MsgSwapAllRequest) GetFromAddress() string { +func (m *MsgSwapAll) GetFromAddress() string { if m != nil { return m.FromAddress } return "" } +func (m *MsgSwapAll) GetFromDenom() string { + if m != nil { + return m.FromDenom + } + return "" +} + +func (m *MsgSwapAll) GetToDenom() string { + if m != nil { + return m.ToDenom + } + return "" +} + type MsgSwapAllResponse struct { } @@ -201,38 +225,41 @@ func (m *MsgSwapAllResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSwapAllResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgSwapRequest)(nil), "lbm.fswap.v1.MsgSwapRequest") + proto.RegisterType((*MsgSwap)(nil), "lbm.fswap.v1.MsgSwap") proto.RegisterType((*MsgSwapResponse)(nil), "lbm.fswap.v1.MsgSwapResponse") - proto.RegisterType((*MsgSwapAllRequest)(nil), "lbm.fswap.v1.MsgSwapAllRequest") + proto.RegisterType((*MsgSwapAll)(nil), "lbm.fswap.v1.MsgSwapAll") proto.RegisterType((*MsgSwapAllResponse)(nil), "lbm.fswap.v1.MsgSwapAllResponse") } func init() { proto.RegisterFile("lbm/fswap/v1/tx.proto", fileDescriptor_65c77cf1d9b67323) } var fileDescriptor_65c77cf1d9b67323 = []byte{ - // 348 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xcd, 0x4a, 0xf3, 0x40, - 0x14, 0xcd, 0x7c, 0x9f, 0x54, 0x9c, 0x16, 0xa5, 0x43, 0x85, 0x1a, 0x34, 0xad, 0x59, 0x15, 0xc4, - 0x19, 0xd2, 0x82, 0xfb, 0xb6, 0x20, 0x2e, 0xec, 0xa6, 0xee, 0xdc, 0x48, 0x92, 0x4e, 0xd2, 0x60, - 0x92, 0x89, 0xbd, 0xd3, 0x1f, 0xdf, 0xc2, 0xa5, 0xe0, 0x1b, 0xf8, 0x24, 0x5d, 0x76, 0xe9, 0x4a, - 0xa5, 0x7d, 0x11, 0x49, 0x26, 0x68, 0x05, 0x8b, 0xee, 0x2e, 0xe7, 0xdc, 0x7b, 0xce, 0xe1, 0xcc, - 0xe0, 0xfd, 0xd0, 0x89, 0x98, 0x07, 0x53, 0x3b, 0x61, 0x13, 0x8b, 0xc9, 0x19, 0x4d, 0x46, 0x42, - 0x0a, 0x52, 0x0a, 0x9d, 0x88, 0x66, 0x30, 0x9d, 0x58, 0x7a, 0xc5, 0x17, 0xbe, 0xc8, 0x08, 0x96, - 0x4e, 0x6a, 0x47, 0x37, 0x5c, 0x01, 0x91, 0x00, 0xe6, 0xd8, 0xc0, 0xd9, 0xc4, 0x72, 0xb8, 0xb4, - 0x2d, 0xe6, 0x8a, 0x20, 0x56, 0xbc, 0xf9, 0x84, 0xf0, 0x6e, 0x0f, 0xfc, 0xab, 0xa9, 0x9d, 0xf4, - 0xf9, 0xdd, 0x98, 0x83, 0x24, 0xc7, 0xb8, 0xe4, 0x8d, 0x44, 0x74, 0x63, 0x0f, 0x06, 0x23, 0x0e, - 0x50, 0x45, 0x75, 0xd4, 0xd8, 0xe9, 0x17, 0x53, 0xac, 0xad, 0x20, 0xe2, 0xe1, 0x82, 0x1d, 0x89, - 0x71, 0x2c, 0xab, 0xff, 0xea, 0xa8, 0x51, 0x6c, 0x1e, 0x50, 0x65, 0x43, 0x53, 0x1b, 0x9a, 0xdb, - 0xd0, 0xae, 0x08, 0xe2, 0x4e, 0x6b, 0xfe, 0x5a, 0xd3, 0x9e, 0xdf, 0x6a, 0x27, 0x7e, 0x20, 0x87, - 0x63, 0x87, 0xba, 0x22, 0x62, 0xe7, 0x41, 0x0c, 0xee, 0x30, 0xb0, 0x99, 0x97, 0x0f, 0xa7, 0x30, - 0xb8, 0x65, 0xf2, 0x3e, 0xe1, 0x90, 0x1d, 0xf5, 0x73, 0x75, 0xb3, 0x8c, 0xf7, 0x3e, 0xc3, 0x41, - 0x22, 0x62, 0xe0, 0xe6, 0x19, 0x2e, 0xe7, 0x50, 0x3b, 0x0c, 0xff, 0x1e, 0xd9, 0xac, 0x60, 0xb2, - 0x7e, 0xa7, 0xd4, 0x9a, 0x8f, 0x08, 0xff, 0xef, 0x81, 0x4f, 0xba, 0x78, 0x2b, 0xa5, 0xc8, 0x21, - 0x5d, 0xef, 0x94, 0x7e, 0x6f, 0x46, 0x3f, 0xda, 0xc0, 0x2a, 0x31, 0x72, 0x89, 0xb7, 0x73, 0x7d, - 0x52, 0xfb, 0x71, 0xf3, 0x2b, 0xb1, 0x5e, 0xdf, 0xbc, 0xa0, 0xd4, 0x3a, 0x17, 0xf3, 0xa5, 0x81, - 0x16, 0x4b, 0x03, 0xbd, 0x2f, 0x0d, 0xf4, 0xb0, 0x32, 0xb4, 0xc5, 0xca, 0xd0, 0x5e, 0x56, 0x86, - 0x76, 0x4d, 0x7f, 0xad, 0x72, 0x96, 0xff, 0x96, 0xac, 0x52, 0xa7, 0x90, 0x3d, 0x75, 0xeb, 0x23, - 0x00, 0x00, 0xff, 0xff, 0xf1, 0x37, 0x1c, 0xc2, 0x47, 0x02, 0x00, 0x00, + // 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, 0x3a, 0x63, 0x6b, 0x3b, 0xa5, 0x2b, 0x93, 0xf2, 0x0d, + 0x49, 0x17, 0xc0, 0x41, 0xad, 0x47, 0x4e, 0x4c, 0xa4, 0x4c, 0x56, 0xa6, 0xde, 0x08, 0x20, 0x00, + 0x99, 0xa0, 0x22, 0xca, 0x3c, 0xba, 0xe1, 0x02, 0x8b, 0x81, 0x51, 0xc7, 0x66, 0x3e, 0x5d, 0x99, + 0x8e, 0xcf, 0x6d, 0x93, 0xba, 0x10, 0x26, 0x59, 0xbe, 0x77, 0x8b, 0x70, 0x65, 0xcc, 0x82, 0xb3, + 0xb5, 0x9d, 0xaa, 0x3f, 0x71, 0x7d, 0xb6, 0x80, 0x78, 0x6a, 0x7b, 0xde, 0xc2, 0x67, 0x4c, 0x43, + 0x5d, 0xd4, 0xaf, 0x4e, 0x6a, 0x42, 0xb3, 0x32, 0x49, 0xdd, 0xe0, 0xef, 0xd2, 0x22, 0x2a, 0x4c, + 0xed, 0x18, 0x96, 0x09, 0xd7, 0x4a, 0x5d, 0xd4, 0xaf, 0x0d, 0x5a, 0x24, 0x23, 0x11, 0x41, 0x22, + 0x39, 0x89, 0xfc, 0x85, 0x30, 0x19, 0x0d, 0xb7, 0xf7, 0x1d, 0xe5, 0xe6, 0xa1, 0xf3, 0x2b, 0x08, + 0xf9, 0x7c, 0xe9, 0x10, 0x17, 0x62, 0x7a, 0x12, 0x26, 0xcc, 0x9d, 0x87, 0x36, 0x9d, 0xe5, 0xc1, + 0x6f, 0xe6, 0x5d, 0x50, 0x7e, 0x99, 0xfa, 0x4c, 0x3e, 0x9a, 0x7c, 0x15, 0x1c, 0x11, 0x59, 0x92, + 0xa2, 0xb6, 0xf0, 0x17, 0x0e, 0x53, 0xcf, 0x4f, 0x20, 0xd6, 0xca, 0xb2, 0xb1, 0x0a, 0x87, 0x7f, + 0xe2, 0xb3, 0xf7, 0x03, 0x7f, 0xcb, 0x47, 0x98, 0xf8, 0x2c, 0x85, 0x84, 0xf9, 0xbd, 0x10, 0xe3, + 0x5c, 0xb2, 0xa2, 0xe8, 0x23, 0x83, 0xb5, 0x31, 0x96, 0x96, 0x0c, 0x50, 0x92, 0x86, 0xaa, 0x50, + 0x24, 0xe2, 0x2d, 0x7a, 0x03, 0xab, 0xcf, 0xa8, 0xa2, 0x81, 0xc1, 0x15, 0xc2, 0xe5, 0x31, 0x0b, + 0xd4, 0x3f, 0xf8, 0x93, 0xfc, 0xb7, 0x4d, 0xf2, 0x72, 0x59, 0x24, 0x7f, 0xa1, 0xb7, 0x8f, 0xca, + 0x45, 0x15, 0xf5, 0x3f, 0xae, 0x14, 0x33, 0x68, 0x47, 0x9d, 0x56, 0x14, 0xe9, 0xdd, 0xd7, 0x32, + 0x45, 0x99, 0xd1, 0xe9, 0x76, 0x6f, 0xa0, 0xdd, 0xde, 0x40, 0x8f, 0x7b, 0x03, 0x5d, 0x1f, 0x0c, + 0x65, 0x77, 0x30, 0x94, 0xbb, 0x83, 0xa1, 0x9c, 0x93, 0x77, 0x57, 0xb2, 0xc9, 0x0f, 0x4f, 0xae, + 0xc6, 0xf9, 0x2c, 0xaf, 0x66, 0xf8, 0x14, 0x00, 0x00, 0xff, 0xff, 0xb0, 0x18, 0x17, 0xb0, 0x92, + 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -247,8 +274,8 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { - Swap(ctx context.Context, in *MsgSwapRequest, opts ...grpc.CallOption) (*MsgSwapResponse, error) - SwapAll(ctx context.Context, in *MsgSwapAllRequest, opts ...grpc.CallOption) (*MsgSwapAllResponse, error) + Swap(ctx context.Context, in *MsgSwap, opts ...grpc.CallOption) (*MsgSwapResponse, error) + SwapAll(ctx context.Context, in *MsgSwapAll, opts ...grpc.CallOption) (*MsgSwapAllResponse, error) } type msgClient struct { @@ -259,7 +286,7 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) Swap(ctx context.Context, in *MsgSwapRequest, opts ...grpc.CallOption) (*MsgSwapResponse, error) { +func (c *msgClient) Swap(ctx context.Context, in *MsgSwap, opts ...grpc.CallOption) (*MsgSwapResponse, error) { out := new(MsgSwapResponse) err := c.cc.Invoke(ctx, "/lbm.fswap.v1.Msg/Swap", in, out, opts...) if err != nil { @@ -268,7 +295,7 @@ func (c *msgClient) Swap(ctx context.Context, in *MsgSwapRequest, opts ...grpc.C return out, nil } -func (c *msgClient) SwapAll(ctx context.Context, in *MsgSwapAllRequest, opts ...grpc.CallOption) (*MsgSwapAllResponse, error) { +func (c *msgClient) SwapAll(ctx context.Context, in *MsgSwapAll, opts ...grpc.CallOption) (*MsgSwapAllResponse, error) { out := new(MsgSwapAllResponse) err := c.cc.Invoke(ctx, "/lbm.fswap.v1.Msg/SwapAll", in, out, opts...) if err != nil { @@ -279,18 +306,18 @@ func (c *msgClient) SwapAll(ctx context.Context, in *MsgSwapAllRequest, opts ... // MsgServer is the server API for Msg service. type MsgServer interface { - Swap(context.Context, *MsgSwapRequest) (*MsgSwapResponse, error) - SwapAll(context.Context, *MsgSwapAllRequest) (*MsgSwapAllResponse, error) + Swap(context.Context, *MsgSwap) (*MsgSwapResponse, error) + SwapAll(context.Context, *MsgSwapAll) (*MsgSwapAllResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) Swap(ctx context.Context, req *MsgSwapRequest) (*MsgSwapResponse, error) { +func (*UnimplementedMsgServer) Swap(ctx context.Context, req *MsgSwap) (*MsgSwapResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Swap not implemented") } -func (*UnimplementedMsgServer) SwapAll(ctx context.Context, req *MsgSwapAllRequest) (*MsgSwapAllResponse, error) { +func (*UnimplementedMsgServer) SwapAll(ctx context.Context, req *MsgSwapAll) (*MsgSwapAllResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SwapAll not implemented") } @@ -299,7 +326,7 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { } func _Msg_Swap_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgSwapRequest) + in := new(MsgSwap) if err := dec(in); err != nil { return nil, err } @@ -311,13 +338,13 @@ func _Msg_Swap_Handler(srv interface{}, ctx context.Context, dec func(interface{ FullMethod: "/lbm.fswap.v1.Msg/Swap", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).Swap(ctx, req.(*MsgSwapRequest)) + return srv.(MsgServer).Swap(ctx, req.(*MsgSwap)) } return interceptor(ctx, in, info, handler) } func _Msg_SwapAll_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgSwapAllRequest) + in := new(MsgSwapAll) if err := dec(in); err != nil { return nil, err } @@ -329,7 +356,7 @@ func _Msg_SwapAll_Handler(srv interface{}, ctx context.Context, dec func(interfa FullMethod: "/lbm.fswap.v1.Msg/SwapAll", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).SwapAll(ctx, req.(*MsgSwapAllRequest)) + return srv.(MsgServer).SwapAll(ctx, req.(*MsgSwapAll)) } return interceptor(ctx, in, info, handler) } @@ -351,7 +378,7 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Metadata: "lbm/fswap/v1/tx.proto", } -func (m *MsgSwapRequest) Marshal() (dAtA []byte, err error) { +func (m *MsgSwap) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -361,18 +388,25 @@ func (m *MsgSwapRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgSwapRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgSwap) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgSwapRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgSwap) 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 = encodeVarintTx(dAtA, i, uint64(len(m.ToDenom))) + i-- + dAtA[i] = 0x1a + } { - size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.FromCoinAmount.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -414,7 +448,7 @@ func (m *MsgSwapResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgSwapAllRequest) Marshal() (dAtA []byte, err error) { +func (m *MsgSwapAll) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -424,16 +458,30 @@ func (m *MsgSwapAllRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgSwapAllRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgSwapAll) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgSwapAllRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgSwapAll) 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 = encodeVarintTx(dAtA, i, uint64(len(m.ToDenom))) + i-- + dAtA[i] = 0x1a + } + if len(m.FromDenom) > 0 { + i -= len(m.FromDenom) + copy(dAtA[i:], m.FromDenom) + i = encodeVarintTx(dAtA, i, uint64(len(m.FromDenom))) + i-- + dAtA[i] = 0x12 + } if len(m.FromAddress) > 0 { i -= len(m.FromAddress) copy(dAtA[i:], m.FromAddress) @@ -478,7 +526,7 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgSwapRequest) Size() (n int) { +func (m *MsgSwap) Size() (n int) { if m == nil { return 0 } @@ -488,8 +536,12 @@ func (m *MsgSwapRequest) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = m.Amount.Size() + l = m.FromCoinAmount.Size() n += 1 + l + sovTx(uint64(l)) + l = len(m.ToDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -502,7 +554,7 @@ func (m *MsgSwapResponse) Size() (n int) { return n } -func (m *MsgSwapAllRequest) Size() (n int) { +func (m *MsgSwapAll) Size() (n int) { if m == nil { return 0 } @@ -512,6 +564,14 @@ func (m *MsgSwapAllRequest) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.FromDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ToDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -530,7 +590,7 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MsgSwapRequest) Unmarshal(dAtA []byte) error { +func (m *MsgSwap) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -553,10 +613,10 @@ func (m *MsgSwapRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgSwapRequest: wiretype end group for non-group") + return fmt.Errorf("proto: MsgSwap: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgSwapRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgSwap: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -593,7 +653,7 @@ func (m *MsgSwapRequest) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field FromCoinAmount", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -620,10 +680,42 @@ func (m *MsgSwapRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.FromCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex + case 3: + 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 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.ToDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -695,7 +787,7 @@ func (m *MsgSwapResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgSwapAllRequest) Unmarshal(dAtA []byte) error { +func (m *MsgSwapAll) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -718,10 +810,10 @@ func (m *MsgSwapAllRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgSwapAllRequest: wiretype end group for non-group") + return fmt.Errorf("proto: MsgSwapAll: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgSwapAllRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgSwapAll: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -756,6 +848,70 @@ func (m *MsgSwapAllRequest) Unmarshal(dAtA []byte) error { } m.FromAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + 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 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.FromDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + 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 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.ToDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/x/fswap/types/types.go b/x/fswap/types/types.go deleted file mode 100644 index ab1254f4c2..0000000000 --- a/x/fswap/types/types.go +++ /dev/null @@ -1 +0,0 @@ -package types