Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a cli to convert module name to address #1462

Merged
merged 6 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions protocol/x/perpetuals/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdQueryPremiumSamples())
cmd.AddCommand(CmdQueryPremiumVotes())
cmd.AddCommand(CmdQueryAllLiquidityTiers())
cmd.AddCommand(CmdModuleNameToAddress())
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
// this line is used by starport scaffolding # 1

return cmd
Expand Down
20 changes: 20 additions & 0 deletions protocol/x/perpetuals/client/cli/query_perpetual.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package cli

import (
"context"
"fmt"
"strconv"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types"
Expand Down Expand Up @@ -77,3 +80,20 @@ func CmdShowPerpetual() *cobra.Command {

return cmd
}

func CmdModuleNameToAddress() *cobra.Command {
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
cmd := &cobra.Command{
Use: "module-name-to-address [module-name]",
Short: "module name to address",
RunE: func(cmd *cobra.Command, args []string) error {
address := authtypes.NewModuleAddress(args[0])
fmt.Println(address.String())
return nil
},
}

flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
flags.AddQueryFlagsToCmd(cmd)

return cmd
}
5 changes: 3 additions & 2 deletions protocol/x/perpetuals/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,14 @@ func TestAppModuleBasic_GetQueryCmd(t *testing.T) {

cmd := am.GetQueryCmd()
require.Equal(t, "perpetuals", cmd.Use)
require.Equal(t, 6, len(cmd.Commands()))
require.Equal(t, 7, len(cmd.Commands()))
require.Equal(t, "get-all-liquidity-tiers", cmd.Commands()[0].Name())
require.Equal(t, "get-params", cmd.Commands()[1].Name())
require.Equal(t, "get-premium-samples", cmd.Commands()[2].Name())
require.Equal(t, "get-premium-votes", cmd.Commands()[3].Name())
require.Equal(t, "list-perpetual", cmd.Commands()[4].Name())
require.Equal(t, "show-perpetual", cmd.Commands()[5].Name())
require.Equal(t, "module-name-to-address", cmd.Commands()[5].Name())
require.Equal(t, "show-perpetual", cmd.Commands()[6].Name())
}

func TestAppModule_Name(t *testing.T) {
Expand Down
Loading