From cd18743ad76b0b73c2df63f79636fa6abf3ee043 Mon Sep 17 00:00:00 2001 From: jiujiteiro Date: Thu, 24 Nov 2022 23:11:58 +0000 Subject: [PATCH] genesis and query asset updates --- x/asset/client/cli/query.go | 7 ++---- x/asset/client/cli/query_params.go | 3 ++- x/asset/client/cli/query_tokens.go | 35 ++++++++++++++++++++++++++++++ x/asset/genesis.go | 7 +++++- x/asset/genesis_test.go | 2 +- 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 x/asset/client/cli/query_tokens.go diff --git a/x/asset/client/cli/query.go b/x/asset/client/cli/query.go index f4b85817..9ee1d5f7 100644 --- a/x/asset/client/cli/query.go +++ b/x/asset/client/cli/query.go @@ -2,13 +2,9 @@ package cli import ( "fmt" - // "strings" - - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" - // sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/spf13/cobra" "github.com/realiotech/realio-network/x/asset/types" ) @@ -25,6 +21,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { } cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdQueryTokens()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/asset/client/cli/query_params.go b/x/asset/client/cli/query_params.go index 554fffa1..a744084d 100644 --- a/x/asset/client/cli/query_params.go +++ b/x/asset/client/cli/query_params.go @@ -5,8 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/realiotech/realio-network/x/asset/types" "github.com/spf13/cobra" + + "github.com/realiotech/realio-network/x/asset/types" ) func CmdQueryParams() *cobra.Command { diff --git a/x/asset/client/cli/query_tokens.go b/x/asset/client/cli/query_tokens.go new file mode 100644 index 00000000..3eb6a0fc --- /dev/null +++ b/x/asset/client/cli/query_tokens.go @@ -0,0 +1,35 @@ +package cli + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/realiotech/realio-network/x/asset/types" +) + +func CmdQueryTokens() *cobra.Command { + cmd := &cobra.Command{ + Use: "tokens", + Short: "shows the tokens of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Tokens(context.Background(), &types.QueryTokensRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/asset/genesis.go b/x/asset/genesis.go index c3a71598..35739425 100644 --- a/x/asset/genesis.go +++ b/x/asset/genesis.go @@ -2,20 +2,25 @@ package asset import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/realiotech/realio-network/x/asset/keeper" "github.com/realiotech/realio-network/x/asset/types" ) -// InitGenesis initializes the capability module's state from a provided genesis +// InitGenesis initializes the assets module's state from a provided genesis // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { k.SetParams(ctx, genState.Params) + for _, token := range genState.Tokens { + k.SetToken(ctx, token) + } } // 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) + genesis.Tokens = k.GetAllToken(ctx) // this line is used by starport scaffolding # genesis/module/export return genesis diff --git a/x/asset/genesis_test.go b/x/asset/genesis_test.go index 358d29cd..8ca864e8 100644 --- a/x/asset/genesis_test.go +++ b/x/asset/genesis_test.go @@ -71,5 +71,5 @@ func (suite *GenesisTestSuite) TestGenesis() { got := asset.ExportGenesis(suite.ctx, suite.app.AssetKeeper) suite.Require().NotNil(got) - suite.Require().Equal(suite.genesis.Tokens, got.Tokens) + suite.Require().Equal(len(suite.genesis.Tokens), len(got.Tokens)) }