Skip to content

Commit

Permalink
genesis and query asset updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jiujiteiro committed Nov 24, 2022
1 parent c02ae47 commit cd18743
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
7 changes: 2 additions & 5 deletions x/asset/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion x/asset/client/cli/query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions x/asset/client/cli/query_tokens.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 6 additions & 1 deletion x/asset/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/asset/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit cd18743

Please sign in to comment.