diff --git a/CHANGELOG.md b/CHANGELOG.md index a88a6c5ca3..8d2bc136b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features * (consensus) [\#1178](https://github.com/Finschia/finschia-sdk/pull/1178) change the consensus from Ostracon to Tendermint v0.34.24 * (x/fswap) [\#1336](https://github.com/Finschia/finschia-sdk/pull/1336) Initialize fswap module +* (x/fswap) [\#1339](https://github.com/Finschia/finschia-sdk/pull/1339) Implement fswap module's genesis ### Improvements * (docs) [\#1120](https://github.com/Finschia/finschia-sdk/pull/1120) Update links in x/foundation README.md diff --git a/Makefile b/Makefile index 039bdefc1d..fdd954145c 100644 --- a/Makefile +++ b/Makefile @@ -144,6 +144,7 @@ mocks: $(MOCKS_DIR) mockgen -package mocks -destination tests/mocks/grpc_server.go github.com/gogo/protobuf/grpc Server mockgen -package mocks -destination tests/mocks/tendermint_tendermint_libs_log_DB.go github.com/tendermint/tendermint/libs/log Logger mockgen -source=x/stakingplus/expected_keepers.go -package testutil -destination x/stakingplus/testutil/expected_keepers_mocks.go + mockgen -source=x/fswap/types/expected_keepers.go -package testutil -destination x/fswap/testutil/expected_keepers_mocks.go .PHONY: mocks $(MOCKS_DIR): diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index e9718495d8..7d6e8b010d 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -12727,8 +12727,8 @@ Msg defines the foundation Msg service. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `address` | [string](#string) | | holder's address | -| `old_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the old currency | -| `new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the new currency | +| `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 | @@ -12759,8 +12759,8 @@ Msg defines the foundation Msg service. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `old_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | -| `new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `old_coin_amount` | [string](#string) | | | +| `new_coin_amount` | [string](#string) | | | @@ -12791,7 +12791,7 @@ Params defines the parameters for the module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `new_coin_denom` | [string](#string) | | new denomination for new coin after swap | +| `swappable_new_coin_amount` | [string](#string) | | | @@ -12864,7 +12864,8 @@ GenesisState defines the fswap module's genesis state. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `swapped` | [Swapped](#lbm.fswap.v1.Swapped) | | | +| `old_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `new_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | @@ -12889,7 +12890,7 @@ GenesisState defines the fswap module's genesis state. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `swappable_new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `swappable_new_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | diff --git a/proto/lbm/fswap/v1/event.proto b/proto/lbm/fswap/v1/event.proto index 374447f7c3..2fea28e9d0 100644 --- a/proto/lbm/fswap/v1/event.proto +++ b/proto/lbm/fswap/v1/event.proto @@ -10,9 +10,9 @@ message EventSwapCoins { // holder's address string address = 1; // amount of the old currency - cosmos.base.v1beta1.Coin old_coin_amount = 2 + cosmos.base.v1beta1.Coin old_coin = 2 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; // amount of the new currency - cosmos.base.v1beta1.Coin new_coin_amount = 3 + cosmos.base.v1beta1.Coin new_coin = 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 827f5f3e32..14315e32d0 100644 --- a/proto/lbm/fswap/v1/fswap.proto +++ b/proto/lbm/fswap/v1/fswap.proto @@ -4,11 +4,9 @@ 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"; -message Swapped{ - cosmos.base.v1beta1.Coin old_coin_amount = 1 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; - cosmos.base.v1beta1.Coin new_coin_amount = 2 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; +message Swapped { + 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]; } diff --git a/proto/lbm/fswap/v1/genesis.proto b/proto/lbm/fswap/v1/genesis.proto index ae0a9ade75..43b639a341 100644 --- a/proto/lbm/fswap/v1/genesis.proto +++ b/proto/lbm/fswap/v1/genesis.proto @@ -4,11 +4,11 @@ package lbm.fswap.v1; option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types"; import "gogoproto/gogo.proto"; -import "lbm/fswap/v1/params.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]; + Params params = 1 [(gogoproto.nullable) = false]; + Swapped swapped = 2 [(gogoproto.nullable) = false]; } diff --git a/proto/lbm/fswap/v1/params.proto b/proto/lbm/fswap/v1/params.proto index da236c9373..bc5535afb4 100644 --- a/proto/lbm/fswap/v1/params.proto +++ b/proto/lbm/fswap/v1/params.proto @@ -8,6 +8,5 @@ import "gogoproto/gogo.proto"; // Params defines the parameters for the module. message Params { option (gogoproto.goproto_stringer) = false; - // new denomination for new coin after swap - string new_coin_denom = 1; -} + 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 f5d92c7bfc..5b2e0d02e9 100644 --- a/proto/lbm/fswap/v1/query.proto +++ b/proto/lbm/fswap/v1/query.proto @@ -19,11 +19,14 @@ service Query { message QuerySwappedRequest {} message QuerySwappedResponse { - Swapped swapped = 1 [(gogoproto.nullable) = false]; + cosmos.base.v1beta1.Coin old_coin = 1 + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; + cosmos.base.v1beta1.Coin new_coin = 2 + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; } message QueryTotalSwappableAmountRequest {} message QueryTotalSwappableAmountResponse { - cosmos.base.v1beta1.Coin swappable_new_coin_amount = 1 + cosmos.base.v1beta1.Coin swappable_new_coin = 1 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; } diff --git a/simapp/app.go b/simapp/app.go index a86dd1c611..148cdbc50c 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -72,6 +72,9 @@ import ( foundationclient "github.com/Finschia/finschia-sdk/x/foundation/client" 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" + 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" genutiltypes "github.com/Finschia/finschia-sdk/x/genutil/types" "github.com/Finschia/finschia-sdk/x/gov" @@ -138,6 +141,7 @@ var ( vesting.AppModuleBasic{}, tokenmodule.AppModuleBasic{}, collectionmodule.AppModuleBasic{}, + fswap.AppModuleBasic{}, ) // module account permissions @@ -197,6 +201,7 @@ type SimApp struct { ClassKeeper classkeeper.Keeper TokenKeeper tokenkeeper.Keeper CollectionKeeper collectionkeeper.Keeper + FswapKeeper fswapkeeper.Keeper // the module manager mm *module.Manager @@ -250,6 +255,7 @@ func NewSimApp( token.StoreKey, collection.StoreKey, authzkeeper.StoreKey, + fswaptypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) // NOTE: The testingkey is just mounted for testing purposes. Actual applications should @@ -352,6 +358,10 @@ 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) + /**** Module Options ****/ // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment @@ -383,6 +393,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), ) // During begin block slashing happens after distr.BeginBlocker so that @@ -410,6 +421,7 @@ func NewSimApp( vestingtypes.ModuleName, token.ModuleName, collection.ModuleName, + fswaptypes.ModuleName, ) app.mm.SetOrderEndBlockers( crisistypes.ModuleName, @@ -431,6 +443,7 @@ func NewSimApp( foundation.ModuleName, token.ModuleName, collection.ModuleName, + fswaptypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -458,6 +471,7 @@ func NewSimApp( vestingtypes.ModuleName, token.ModuleName, collection.ModuleName, + fswaptypes.ModuleName, ) // Uncomment if you want to set a custom migration order here. diff --git a/x/ERRORS.md b/x/ERRORS.md index c324c8315c..8ed09149f9 100644 --- a/x/ERRORS.md +++ b/x/ERRORS.md @@ -177,7 +177,9 @@ |Error Name|Codespace|Code|Description| |:-|:-|:-|:-| -|ErrSample|fswap|1100|sample error| +|ErrParamsNotFound|fswap|1100|params does not exist| +|ErrSwappedNotFound|fswap|1101|swapped does not exist| +|ErrExceedSwappable|fswap|1102|exceed swappable 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/genesis.go b/x/fswap/genesis.go deleted file mode 100644 index af232aad36..0000000000 --- a/x/fswap/genesis.go +++ /dev/null @@ -1,24 +0,0 @@ -package fswap - -import ( - sdk "github.com/Finschia/finschia-sdk/types" - "github.com/Finschia/finschia-sdk/x/fswap/keeper" - "github.com/Finschia/finschia-sdk/x/fswap/types" -) - -// InitGenesis initializes the capability module's state from a provided genesis -// state. -func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { - // this line is used by starport scaffolding # genesis/module/init - k.SetParams(ctx, genState.Params) -} - -// ExportGenesis returns the capability module's exported genesis. -func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { - genesis := types.DefaultGenesis() - genesis.Params = k.GetParams(ctx) - - // this line is used by starport scaffolding # genesis/module/export - - return genesis -} diff --git a/x/fswap/genesis_test.go b/x/fswap/genesis_test.go deleted file mode 100644 index 43bc7afc7c..0000000000 --- a/x/fswap/genesis_test.go +++ /dev/null @@ -1 +0,0 @@ -package fswap_test diff --git a/x/fswap/keeper/fswap.go b/x/fswap/keeper/fswap.go new file mode 100644 index 0000000000..6100dfa111 --- /dev/null +++ b/x/fswap/keeper/fswap.go @@ -0,0 +1,30 @@ +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 new file mode 100644 index 0000000000..4cb0edd5e6 --- /dev/null +++ b/x/fswap/keeper/genesis.go @@ -0,0 +1,25 @@ +package keeper + +import ( + sdk "github.com/Finschia/finschia-sdk/types" + "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) + } + if err := k.SetSwapped(ctx, genState.Swapped); err != nil { + panic(err) + } +} + +// ExportGenesis returns the capability module's exported genesis. +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + return &types.GenesisState{ + Params: k.GetParams(ctx), + Swapped: k.GetSwapped(ctx), + } +} diff --git a/x/fswap/keeper/genesis_test.go b/x/fswap/keeper/genesis_test.go new file mode 100644 index 0000000000..ae0e07e275 --- /dev/null +++ b/x/fswap/keeper/genesis_test.go @@ -0,0 +1,13 @@ +package keeper_test + +import ( + "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) +} diff --git a/x/fswap/keeper/keeper.go b/x/fswap/keeper/keeper.go index 329b87cf80..3036a079e2 100644 --- a/x/fswap/keeper/keeper.go +++ b/x/fswap/keeper/keeper.go @@ -14,23 +14,26 @@ import ( type ( Keeper struct { cdc codec.BinaryCodec + storeKey storetypes.StoreKey accountKeeper types.AccountKeeper bankKeeper types.BankKeeper - storeKey storetypes.StoreKey + config types.Config } ) func NewKeeper( cdc codec.BinaryCodec, + storeKey storetypes.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, - storeKey storetypes.StoreKey, + config types.Config, ) Keeper { return Keeper{ cdc: cdc, + storeKey: storeKey, accountKeeper: ak, bankKeeper: bk, - storeKey: storeKey, + config: config, } } diff --git a/x/fswap/keeper/keeper_test.go b/x/fswap/keeper/keeper_test.go new file mode 100644 index 0000000000..dc87a7e267 --- /dev/null +++ b/x/fswap/keeper/keeper_test.go @@ -0,0 +1,43 @@ +package keeper_test + +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/simapp" + sdk "github.com/Finschia/finschia-sdk/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" +) + +type KeeperTestSuite struct { + suite.Suite + sdkCtx sdk.Context + goCtx context.Context + keeper keeper.Keeper + bankKeeper types.BankKeeper + + msgServer types.MsgServer +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} + +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) + s.keeper = app.FswapKeeper + + s.msgServer = keeper.NewMsgServerImpl(s.keeper) +} diff --git a/x/fswap/keeper/params.go b/x/fswap/keeper/params.go index 5a539d551a..5578a6d760 100644 --- a/x/fswap/keeper/params.go +++ b/x/fswap/keeper/params.go @@ -2,15 +2,34 @@ 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 { - return types.NewParams() + 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) { - // k.paramstore.SetParamSet(ctx, ¶ms) +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/params_test.go b/x/fswap/keeper/params_test.go deleted file mode 100644 index 9429264902..0000000000 --- a/x/fswap/keeper/params_test.go +++ /dev/null @@ -1 +0,0 @@ -package keeper_test diff --git a/x/fswap/module.go b/x/fswap/module.go index 0e60e1d03d..724b883a9e 100644 --- a/x/fswap/module.go +++ b/x/fswap/module.go @@ -19,8 +19,9 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.EndBlockAppModule = AppModule{} ) // ---------------------------------------------------------------------------- @@ -144,14 +145,14 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra // Initialize global index to index in genesis state cdc.MustUnmarshalJSON(gs, &genState) - InitGenesis(ctx, am.keeper, genState) + am.keeper.InitGenesis(ctx, genState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - genState := ExportGenesis(ctx, am.keeper) + genState := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(genState) } diff --git a/x/fswap/module_simulation.go b/x/fswap/module_simulation.go index 48b26e84a0..4748931d47 100644 --- a/x/fswap/module_simulation.go +++ b/x/fswap/module_simulation.go @@ -1 +1,39 @@ package fswap + +import ( + "math/rand" + + 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" +) + +var _ module.AppModuleSimulation = AppModule{} + +// GenerateGenesisState creates a randomized GenState of the module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// RegisterStoreDecoder registers a decoder. +func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} + +// ProposalContents doesn't return any content functions for governance proposals. +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + operations := make([]simtypes.WeightedOperation, 0) + + // this line is used by starport scaffolding # simapp/module/operation + + return operations +} + +// RandomizedParams creates randomized slashing param changes for the simulator. +func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { + return nil +} diff --git a/x/fswap/simulation/genesis.go b/x/fswap/simulation/genesis.go new file mode 100644 index 0000000000..f84ff0b243 --- /dev/null +++ b/x/fswap/simulation/genesis.go @@ -0,0 +1,65 @@ +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 new file mode 100644 index 0000000000..00ac1852d7 --- /dev/null +++ b/x/fswap/simulation/genesis_test.go @@ -0,0 +1,78 @@ +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/simulation/simap.go b/x/fswap/simulation/simap.go deleted file mode 100644 index 1b74bcd04c..0000000000 --- a/x/fswap/simulation/simap.go +++ /dev/null @@ -1,15 +0,0 @@ -package simulation - -import ( - sdk "github.com/Finschia/finschia-sdk/types" - simtypes "github.com/Finschia/finschia-sdk/types/simulation" -) - -// FindAccount find a specific address from an account list -func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { - creator, err := sdk.AccAddressFromBech32(address) - if err != nil { - panic(err) - } - return simtypes.FindAccount(accs, creator) -} diff --git a/x/fswap/testutil/expected_keepers_mocks.go b/x/fswap/testutil/expected_keepers_mocks.go new file mode 100644 index 0000000000..21bb92feaf --- /dev/null +++ b/x/fswap/testutil/expected_keepers_mocks.go @@ -0,0 +1,101 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: x/fswap/types/expected_keepers.go + +// Package testutil is a generated GoMock package. +package testutil + +import ( + reflect "reflect" + + types "github.com/Finschia/finschia-sdk/types" + types0 "github.com/Finschia/finschia-sdk/x/auth/types" + gomock "github.com/golang/mock/gomock" +) + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetAccount mocks base method. +func (m *MockAccountKeeper) GetAccount(ctx types.Context, addr types.AccAddress) types0.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccount", ctx, addr) + ret0, _ := ret[0].(types0.AccountI) + return ret0 +} + +// GetAccount indicates an expected call of GetAccount. +func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) +} + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// 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 *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// GetSupply mocks base method. +func (m *MockBankKeeper) GetSupply(ctx types.Context, denom string) types.Coin { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSupply", ctx, denom) + ret0, _ := ret[0].(types.Coin) + return ret0 +} + +// GetSupply indicates an expected call of GetSupply. +func (mr *MockBankKeeperMockRecorder) GetSupply(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSupply", reflect.TypeOf((*MockBankKeeper)(nil).GetSupply), ctx, denom) +} + +// SpendableCoins mocks base method. +func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// SpendableCoins indicates an expected call of SpendableCoins. +func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) +} diff --git a/x/fswap/types/config.go b/x/fswap/types/config.go new file mode 100644 index 0000000000..d2e57a05aa --- /dev/null +++ b/x/fswap/types/config.go @@ -0,0 +1,24 @@ +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 +} + +// DefaultConfig returns the default config for fswap. +func DefaultConfig() Config { + return Config{ + OldCoinDenom: "cony", + NewCoinDenom: "PDT", + SwapRate: sdk.NewInt(148079656000000), + } +} diff --git a/x/fswap/types/errors.go b/x/fswap/types/errors.go index c0b627de88..3a18f66f20 100644 --- a/x/fswap/types/errors.go +++ b/x/fswap/types/errors.go @@ -8,5 +8,7 @@ import ( // x/fswap module sentinel errors var ( - ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error") + 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") ) diff --git a/x/fswap/types/event.pb.go b/x/fswap/types/event.pb.go index 5808cc6e7f..d3e5284230 100644 --- a/x/fswap/types/event.pb.go +++ b/x/fswap/types/event.pb.go @@ -28,9 +28,9 @@ type EventSwapCoins struct { // holder's address Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` // amount of the old currency - OldCoinAmount types.Coin `protobuf:"bytes,2,opt,name=old_coin_amount,json=oldCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"old_coin_amount"` + 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 - NewCoinAmount types.Coin `protobuf:"bytes,3,opt,name=new_coin_amount,json=newCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"new_coin_amount"` + NewCoin types.Coin `protobuf:"bytes,3,opt,name=new_coin,json=newCoin,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"new_coin"` } func (m *EventSwapCoins) Reset() { *m = EventSwapCoins{} } @@ -73,16 +73,16 @@ func (m *EventSwapCoins) GetAddress() string { return "" } -func (m *EventSwapCoins) GetOldCoinAmount() types.Coin { +func (m *EventSwapCoins) GetOldCoin() types.Coin { if m != nil { - return m.OldCoinAmount + return m.OldCoin } return types.Coin{} } -func (m *EventSwapCoins) GetNewCoinAmount() types.Coin { +func (m *EventSwapCoins) GetNewCoin() types.Coin { if m != nil { - return m.NewCoinAmount + return m.NewCoin } return types.Coin{} } @@ -94,25 +94,25 @@ func init() { func init() { proto.RegisterFile("lbm/fswap/v1/event.proto", fileDescriptor_92d5edbd64a725af) } var fileDescriptor_92d5edbd64a725af = []byte{ - // 288 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x91, 0x3f, 0x4e, 0xc3, 0x30, - 0x1c, 0x85, 0xe3, 0x22, 0x81, 0x08, 0xff, 0xa4, 0x88, 0x21, 0x74, 0x70, 0x2b, 0xa6, 0x4a, 0x08, - 0x5b, 0xa1, 0x27, 0xa0, 0x08, 0xc4, 0x5c, 0x36, 0x96, 0xca, 0x4e, 0xdc, 0x34, 0x22, 0xf1, 0x2f, - 0xaa, 0x5d, 0x07, 0x6e, 0xc1, 0xcc, 0x11, 0x38, 0x49, 0xc7, 0x8e, 0x4c, 0x80, 0x92, 0x8b, 0x20, - 0x3b, 0x41, 0x88, 0x89, 0x89, 0xed, 0x59, 0xcf, 0xef, 0xfb, 0x24, 0xdb, 0x0f, 0x73, 0x5e, 0xd0, - 0xb9, 0xaa, 0x58, 0x49, 0x4d, 0x44, 0x85, 0x11, 0x52, 0x93, 0x72, 0x09, 0x1a, 0x82, 0xfd, 0x9c, - 0x17, 0xc4, 0x35, 0xc4, 0x44, 0xfd, 0xe3, 0x14, 0x52, 0x70, 0x05, 0xb5, 0xa9, 0xbd, 0xd3, 0xc7, - 0x31, 0xa8, 0x02, 0x14, 0xe5, 0x4c, 0x09, 0x6a, 0x22, 0x2e, 0x34, 0x8b, 0x68, 0x0c, 0x99, 0x6c, - 0xfb, 0xd3, 0x97, 0x9e, 0x7f, 0x78, 0x6d, 0x99, 0x77, 0x15, 0x2b, 0xaf, 0x20, 0x93, 0x2a, 0x08, - 0xfd, 0x1d, 0x96, 0x24, 0x4b, 0xa1, 0x54, 0x88, 0x86, 0x68, 0xb4, 0x3b, 0xfd, 0x3e, 0x06, 0xc6, - 0x3f, 0x82, 0x3c, 0x99, 0xd9, 0xf9, 0x8c, 0x15, 0xb0, 0x92, 0x3a, 0xec, 0x0d, 0xd1, 0x68, 0xef, - 0xe2, 0x84, 0xb4, 0x1a, 0x62, 0x35, 0xa4, 0xd3, 0x10, 0x8b, 0x9b, 0x8c, 0xd7, 0xef, 0x03, 0xef, - 0xf5, 0x63, 0x70, 0x96, 0x66, 0x7a, 0xb1, 0xe2, 0x24, 0x86, 0x82, 0xde, 0x64, 0x52, 0xc5, 0x8b, - 0x8c, 0xd1, 0x79, 0x17, 0xce, 0x55, 0xf2, 0x40, 0xf5, 0x53, 0x29, 0x94, 0x1b, 0x4d, 0x0f, 0x20, - 0x4f, 0x6c, 0xb8, 0x74, 0x12, 0xeb, 0x95, 0xa2, 0xfa, 0xe5, 0xdd, 0xfa, 0x1f, 0xaf, 0x14, 0xd5, - 0x8f, 0x77, 0x72, 0xbb, 0xae, 0x31, 0xda, 0xd4, 0x18, 0x7d, 0xd6, 0x18, 0x3d, 0x37, 0xd8, 0xdb, - 0x34, 0xd8, 0x7b, 0x6b, 0xb0, 0x77, 0x4f, 0xfe, 0xa4, 0x3e, 0x76, 0x7f, 0xe6, 0xe8, 0x7c, 0xdb, - 0xbd, 0xf6, 0xf8, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x2b, 0x08, 0x6b, 0x7c, 0xcd, 0x01, 0x00, 0x00, + // 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, 0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, 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, } func (m *EventSwapCoins) Marshal() (dAtA []byte, err error) { @@ -136,7 +136,7 @@ func (m *EventSwapCoins) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size, err := m.NewCoinAmount.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.NewCoin.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -146,7 +146,7 @@ func (m *EventSwapCoins) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1a { - size, err := m.OldCoinAmount.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.OldCoin.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -186,9 +186,9 @@ func (m *EventSwapCoins) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - l = m.OldCoinAmount.Size() + l = m.OldCoin.Size() n += 1 + l + sovEvent(uint64(l)) - l = m.NewCoinAmount.Size() + l = m.NewCoin.Size() n += 1 + l + sovEvent(uint64(l)) return n } @@ -262,7 +262,7 @@ func (m *EventSwapCoins) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field OldCoinAmount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field OldCoin", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -289,13 +289,13 @@ func (m *EventSwapCoins) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.OldCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.OldCoin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NewCoinAmount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NewCoin", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -322,7 +322,7 @@ func (m *EventSwapCoins) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.NewCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.NewCoin.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 index 6134a117d7..195cd89bdc 100644 --- a/x/fswap/types/expected_keepers.go +++ b/x/fswap/types/expected_keepers.go @@ -15,4 +15,5 @@ type AccountKeeper interface { 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 new file mode 100644 index 0000000000..76803ed5f3 --- /dev/null +++ b/x/fswap/types/fswap.go @@ -0,0 +1,59 @@ +package types + +import ( + fmt "fmt" + + "gopkg.in/yaml.v2" + + sdk "github.com/Finschia/finschia-sdk/types" +) + +// NewSwapped creates a new Swapped instance +func NewSwapped( + oldCoinAmount sdk.Int, + newCoinAmount sdk.Int, +) Swapped { + return Swapped{ + OldCoinAmount: oldCoinAmount, + NewCoinAmount: newCoinAmount, + } +} + +// DefaultSwapped returns an initial Swapped object +func DefaultSwapped() Swapped { + return NewSwapped(sdk.ZeroInt(), sdk.ZeroInt()) +} + +func validateCoinAmount(i interface{}) error { + v, ok := i.(sdk.Int) + if !ok { + return fmt.Errorf("invalid coin amount: %T", i) + } + + if v.IsNil() { + return fmt.Errorf("coin amount must be not nil") + } + + if v.LT(sdk.ZeroInt()) { + return fmt.Errorf("coin amount cannot be lower than 0") + } + + return nil +} + +// Validate validates the set of swapped +func (s Swapped) Validate() error { + if err := validateCoinAmount(s.OldCoinAmount); err != nil { + return err + } + if err := validateCoinAmount(s.NewCoinAmount); err != nil { + return err + } + return nil +} + +// String implements the Stringer interface. +func (s Swapped) String() string { + out, _ := yaml.Marshal(s) + return string(out) +} diff --git a/x/fswap/types/fswap.pb.go b/x/fswap/types/fswap.pb.go index f53d058797..1923c31269 100644 --- a/x/fswap/types/fswap.pb.go +++ b/x/fswap/types/fswap.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - types "github.com/Finschia/finschia-sdk/types" + 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" @@ -25,13 +25,12 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Swapped struct { - OldCoinAmount types.Coin `protobuf:"bytes,1,opt,name=old_coin_amount,json=oldCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"old_coin_amount"` - NewCoinAmount types.Coin `protobuf:"bytes,2,opt,name=new_coin_amount,json=newCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"new_coin_amount"` + 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"` } -func (m *Swapped) Reset() { *m = Swapped{} } -func (m *Swapped) String() string { return proto.CompactTextString(m) } -func (*Swapped) ProtoMessage() {} +func (m *Swapped) Reset() { *m = Swapped{} } +func (*Swapped) ProtoMessage() {} func (*Swapped) Descriptor() ([]byte, []int) { return fileDescriptor_42ca60eaf37a2b67, []int{0} } @@ -62,20 +61,6 @@ func (m *Swapped) XXX_DiscardUnknown() { var xxx_messageInfo_Swapped proto.InternalMessageInfo -func (m *Swapped) GetOldCoinAmount() types.Coin { - if m != nil { - return m.OldCoinAmount - } - return types.Coin{} -} - -func (m *Swapped) GetNewCoinAmount() types.Coin { - if m != nil { - return m.NewCoinAmount - } - return types.Coin{} -} - func init() { proto.RegisterType((*Swapped)(nil), "lbm.fswap.v1.Swapped") } @@ -83,24 +68,22 @@ func init() { func init() { proto.RegisterFile("lbm/fswap/v1/fswap.proto", fileDescriptor_42ca60eaf37a2b67) } var fileDescriptor_42ca60eaf37a2b67 = []byte{ - // 262 bytes of a gzipped FileDescriptorProto + // 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, 0x4a, 0x2e, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x58, 0x3f, - 0x29, 0xb1, 0x38, 0x55, 0xbf, 0xcc, 0x30, 0x29, 0xb5, 0x24, 0xd1, 0x50, 0x3f, 0x39, 0x3f, 0x33, - 0x0f, 0x22, 0xaf, 0xf4, 0x93, 0x91, 0x8b, 0x3d, 0xb8, 0x3c, 0xb1, 0xa0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7b, 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, } func (m *Swapped) Marshal() (dAtA []byte, err error) { @@ -124,21 +107,21 @@ func (m *Swapped) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size, err := m.NewCoinAmount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { + size := m.NewCoinAmount.Size() + i -= size + if _, err := m.NewCoinAmount.MarshalTo(dAtA[i:]); err != nil { return 0, err } - i -= size i = encodeVarintFswap(dAtA, i, uint64(size)) } i-- dAtA[i] = 0x12 { - size, err := m.OldCoinAmount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { + size := m.OldCoinAmount.Size() + i -= size + if _, err := m.OldCoinAmount.MarshalTo(dAtA[i:]); err != nil { return 0, err } - i -= size i = encodeVarintFswap(dAtA, i, uint64(size)) } i-- @@ -209,7 +192,7 @@ func (m *Swapped) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field OldCoinAmount", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowFswap @@ -219,15 +202,16 @@ func (m *Swapped) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthFswap } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthFswap } @@ -242,7 +226,7 @@ func (m *Swapped) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field NewCoinAmount", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowFswap @@ -252,15 +236,16 @@ func (m *Swapped) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthFswap } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthFswap } diff --git a/x/fswap/types/genesis.go b/x/fswap/types/genesis.go index 8df94bae23..816ef241d0 100644 --- a/x/fswap/types/genesis.go +++ b/x/fswap/types/genesis.go @@ -1,24 +1,29 @@ package types -import ( -// this line is used by starport scaffolding # genesis/types/import -) - -// DefaultIndex is the default capability global index -const DefaultIndex uint64 = 1 +// NewGenesis creates a new genesis state +func NewGenesisState(params Params, swapped Swapped) *GenesisState { + return &GenesisState{ + Params: params, + Swapped: swapped, + } +} // DefaultGenesis returns the default Capability genesis state func DefaultGenesis() *GenesisState { - return &GenesisState{ - // this line is used by starport scaffolding # genesis/types/default - Params: DefaultParams(), - } + return NewGenesisState(DefaultParams(), DefaultSwapped()) } // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { - // this line is used by starport scaffolding # genesis/types/validate - - return gs.Params.Validate() + if err := gs.Params.Validate(); err != nil { + return err + } + if err := gs.Swapped.Validate(); err != nil { + return err + } + if gs.Params.SwappableNewCoinAmount.LT(gs.Swapped.NewCoinAmount) { + return ErrExceedSwappable + } + return nil } diff --git a/x/fswap/types/genesis.pb.go b/x/fswap/types/genesis.pb.go index af2475beea..5b76f03a14 100644 --- a/x/fswap/types/genesis.pb.go +++ b/x/fswap/types/genesis.pb.go @@ -83,22 +83,22 @@ func init() { func init() { proto.RegisterFile("lbm/fswap/v1/genesis.proto", fileDescriptor_94e309cb1db27661) } var fileDescriptor_94e309cb1db27661 = []byte{ - // 231 bytes of a gzipped FileDescriptorProto + // 230 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, 0x49, - 0x14, 0xfd, 0x05, 0x89, 0x45, 0x89, 0xb9, 0x50, 0xed, 0x52, 0x12, 0x28, 0x52, 0x10, 0x73, 0xc0, - 0x32, 0x4a, 0x95, 0x5c, 0x3c, 0xee, 0x10, 0x9b, 0x82, 0x4b, 0x12, 0x4b, 0x52, 0x85, 0x8c, 0xb8, - 0xd8, 0x20, 0x3a, 0x25, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x44, 0xf4, 0x90, 0x6d, 0xd6, 0x0b, - 0x00, 0xcb, 0x39, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0x55, 0x29, 0x64, 0xca, 0xc5, 0x0e, - 0x92, 0x2f, 0x48, 0x4d, 0x91, 0x60, 0x02, 0x6b, 0x12, 0x45, 0xd5, 0x14, 0x0c, 0x91, 0x84, 0xea, - 0x82, 0xa9, 0x75, 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, 0xea, 0x9b, 0x92, - 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x5f, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x23, - 0x15, 0x87, 0x48, 0x42, 0x01, 0x00, 0x00, + 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, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { diff --git a/x/fswap/types/genesis_test.go b/x/fswap/types/genesis_test.go index e4fa429dc8..15394d1ac0 100644 --- a/x/fswap/types/genesis_test.go +++ b/x/fswap/types/genesis_test.go @@ -5,10 +5,11 @@ import ( "github.com/stretchr/testify/require" + sdk "github.com/Finschia/finschia-sdk/types" "github.com/Finschia/finschia-sdk/x/fswap/types" ) -func TestGenesisState_Validate(t *testing.T) { +func TestGenesisStateValidate(t *testing.T) { for _, tc := range []struct { desc string genState *types.GenesisState @@ -20,14 +21,71 @@ func TestGenesisState_Validate(t *testing.T) { valid: true, }, { - desc: "valid genesis state", + desc: "empty genesisState", + genState: &types.GenesisState{}, + valid: false, + }, + { + desc: "empty params", genState: &types.GenesisState{ - - // this line is used by starport scaffolding # types/genesis/validField + 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: true, + valid: false, }, - // this line is used by starport scaffolding # types/genesis/testcase } { 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 18047ccfb2..a13045fad7 100644 --- a/x/fswap/types/keys.go +++ b/x/fswap/types/keys.go @@ -17,6 +17,11 @@ const ( MemStoreKey = "mem_fswap" ) +var ( + ParamsKey = byte(0x00) + SwappedKey = byte(0x01) +) + func KeyPrefix(p string) []byte { return []byte(p) } diff --git a/x/fswap/types/params.go b/x/fswap/types/params.go index f4b9ae24dc..fbfedf3534 100644 --- a/x/fswap/types/params.go +++ b/x/fswap/types/params.go @@ -2,20 +2,29 @@ package types import ( "gopkg.in/yaml.v2" + + sdk "github.com/Finschia/finschia-sdk/types" ) // NewParams creates a new Params instance -func NewParams() Params { - return Params{} +func NewParams( + swappableNewCoinAmount sdk.Int, +) Params { + return Params{ + SwappableNewCoinAmount: swappableNewCoinAmount, + } } // DefaultParams returns a default set of parameters func DefaultParams() Params { - return NewParams() + 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 } diff --git a/x/fswap/types/params.pb.go b/x/fswap/types/params.pb.go index fd779ed5a6..8e9887228b 100644 --- a/x/fswap/types/params.pb.go +++ b/x/fswap/types/params.pb.go @@ -5,6 +5,7 @@ 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" @@ -25,8 +26,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { - // new denomination for new coin after swap - NewCoinDenom string `protobuf:"bytes,1,opt,name=new_coin_denom,json=newCoinDenom,proto3" json:"new_coin_denom,omitempty"` + 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{} } @@ -61,13 +61,6 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo -func (m *Params) GetNewCoinDenom() string { - if m != nil { - return m.NewCoinDenom - } - return "" -} - func init() { proto.RegisterType((*Params)(nil), "lbm.fswap.v1.Params") } @@ -75,20 +68,22 @@ func init() { func init() { proto.RegisterFile("lbm/fswap/v1/params.proto", fileDescriptor_15e620b81032c44d) } var fileDescriptor_15e620b81032c44d = []byte{ - // 194 bytes of a gzipped FileDescriptorProto + // 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, 0x25, 0x13, 0x2e, - 0xb6, 0x00, 0xb0, 0x1e, 0x21, 0x15, 0x2e, 0xbe, 0xbc, 0xd4, 0xf2, 0xf8, 0xe4, 0xfc, 0xcc, 0xbc, - 0xf8, 0x94, 0xd4, 0xbc, 0xfc, 0x5c, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, 0x9e, 0xbc, 0xd4, - 0x72, 0xe7, 0xfc, 0xcc, 0x3c, 0x17, 0x90, 0x98, 0x15, 0xcb, 0x8c, 0x05, 0xf2, 0x0c, 0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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) { @@ -111,13 +106,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.NewCoinDenom) > 0 { - i -= len(m.NewCoinDenom) - copy(dAtA[i:], m.NewCoinDenom) - i = encodeVarintParams(dAtA, i, uint64(len(m.NewCoinDenom))) - i-- - dAtA[i] = 0xa + { + 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 } @@ -138,10 +136,8 @@ func (m *Params) Size() (n int) { } var l int _ = l - l = len(m.NewCoinDenom) - if l > 0 { - n += 1 + l + sovParams(uint64(l)) - } + l = m.SwappableNewCoinAmount.Size() + n += 1 + l + sovParams(uint64(l)) return n } @@ -182,7 +178,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NewCoinDenom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SwappableNewCoinAmount", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -210,7 +206,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.NewCoinDenom = string(dAtA[iNdEx:postIndex]) + if err := m.SwappableNewCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/fswap/types/query.pb.go b/x/fswap/types/query.pb.go index b3635cf9ad..67643e704b 100644 --- a/x/fswap/types/query.pb.go +++ b/x/fswap/types/query.pb.go @@ -67,7 +67,8 @@ func (m *QuerySwappedRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QuerySwappedRequest proto.InternalMessageInfo type QuerySwappedResponse struct { - Swapped Swapped `protobuf:"bytes,1,opt,name=swapped,proto3" json:"swapped"` + 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"` } func (m *QuerySwappedResponse) Reset() { *m = QuerySwappedResponse{} } @@ -103,11 +104,18 @@ func (m *QuerySwappedResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QuerySwappedResponse proto.InternalMessageInfo -func (m *QuerySwappedResponse) GetSwapped() Swapped { +func (m *QuerySwappedResponse) GetOldCoin() types.Coin { if m != nil { - return m.Swapped + return m.OldCoin } - return Swapped{} + return types.Coin{} +} + +func (m *QuerySwappedResponse) GetNewCoin() types.Coin { + if m != nil { + return m.NewCoin + } + return types.Coin{} } type QueryTotalSwappableAmountRequest struct { @@ -147,7 +155,7 @@ func (m *QueryTotalSwappableAmountRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryTotalSwappableAmountRequest proto.InternalMessageInfo type QueryTotalSwappableAmountResponse struct { - SwappableNewCoinAmount types.Coin `protobuf:"bytes,1,opt,name=swappable_new_coin_amount,json=swappableNewCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"swappable_new_coin_amount"` + 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"` } func (m *QueryTotalSwappableAmountResponse) Reset() { *m = QueryTotalSwappableAmountResponse{} } @@ -183,9 +191,9 @@ func (m *QueryTotalSwappableAmountResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryTotalSwappableAmountResponse proto.InternalMessageInfo -func (m *QueryTotalSwappableAmountResponse) GetSwappableNewCoinAmount() types.Coin { +func (m *QueryTotalSwappableAmountResponse) GetSwappableNewCoin() types.Coin { if m != nil { - return m.SwappableNewCoinAmount + return m.SwappableNewCoin } return types.Coin{} } @@ -200,35 +208,36 @@ func init() { func init() { proto.RegisterFile("lbm/fswap/v1/query.proto", fileDescriptor_01deae9da7816d6a) } var fileDescriptor_01deae9da7816d6a = []byte{ - // 441 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x8b, 0xd3, 0x40, - 0x14, 0xc7, 0x33, 0x8b, 0xba, 0x30, 0x7a, 0x1a, 0xb7, 0xba, 0x0d, 0x9a, 0xdd, 0xcd, 0x45, 0x45, - 0x9c, 0x21, 0xbb, 0xf8, 0x01, 0xac, 0x20, 0x1e, 0x54, 0xb0, 0x7a, 0xf2, 0x52, 0x26, 0xd9, 0xd9, - 0xec, 0x60, 0x32, 0x2f, 0xcd, 0x4c, 0x1a, 0x7b, 0xf5, 0xe6, 0x4d, 0xf0, 0x4b, 0x88, 0x20, 0x7e, - 0x8d, 0x1e, 0x0b, 0x5e, 0x3c, 0xa9, 0xb4, 0x7e,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x8d, 0x67, 0x4f, 0x03, 0x00, 0x00, + // 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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8f, 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, } // Reference imports to suppress errors if they are not otherwise used. @@ -391,7 +400,17 @@ func (m *QuerySwappedResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size, err := m.Swapped.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.NewCoin.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.OldCoin.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -447,7 +466,7 @@ func (m *QueryTotalSwappableAmountResponse) MarshalToSizedBuffer(dAtA []byte) (i var l int _ = l { - size, err := m.SwappableNewCoinAmount.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.SwappableNewCoin.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -485,7 +504,9 @@ func (m *QuerySwappedResponse) Size() (n int) { } var l int _ = l - l = m.Swapped.Size() + l = m.OldCoin.Size() + n += 1 + l + sovQuery(uint64(l)) + l = m.NewCoin.Size() n += 1 + l + sovQuery(uint64(l)) return n } @@ -505,7 +526,7 @@ func (m *QueryTotalSwappableAmountResponse) Size() (n int) { } var l int _ = l - l = m.SwappableNewCoinAmount.Size() + l = m.SwappableNewCoin.Size() n += 1 + l + sovQuery(uint64(l)) return n } @@ -597,7 +618,40 @@ func (m *QuerySwappedResponse) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Swapped", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field OldCoin", 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.OldCoin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewCoin", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -624,7 +678,7 @@ func (m *QuerySwappedResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Swapped.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.NewCoin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -730,7 +784,7 @@ func (m *QueryTotalSwappableAmountResponse) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SwappableNewCoinAmount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SwappableNewCoin", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -757,7 +811,7 @@ func (m *QueryTotalSwappableAmountResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.SwappableNewCoinAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.SwappableNewCoin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex