forked from cerc-io/laconicd-deprecated
migrate: add dxns module
1. add bond,auction, nameserivce module 2. update to v0.12.2 ethermint version 3. fix the test cases 4. add gql server
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/tharsis/ethermint/x/bond/types"
|
||||
)
|
||||
|
||||
// GetQueryCmd returns the cli query commands for this module
|
||||
func GetQueryCmd() *cobra.Command {
|
||||
bondQueryCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Querying commands for the bond module",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
bondQueryCmd.AddCommand(
|
||||
GetQueryParamsCmd(),
|
||||
GetQueryBondLists(),
|
||||
GetBondByIdCmd(),
|
||||
GetBondListByOwnerCmd(),
|
||||
GetBondModuleBalanceCmd(),
|
||||
)
|
||||
|
||||
return bondQueryCmd
|
||||
}
|
||||
|
||||
// GetQueryParamsCmd implements the params query command.
|
||||
func GetQueryParamsCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "params",
|
||||
Args: cobra.NoArgs,
|
||||
Short: "Query the current bond parameters information.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Query values set as bond parameters.
|
||||
|
||||
Example:
|
||||
$ %s query %s params
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
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.Params(cmd.Context(), &types.QueryParamsRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetQueryBondLists implements the bond lists query command.
|
||||
func GetQueryBondLists() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List bonds.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get bond list .
|
||||
|
||||
Example:
|
||||
$ %s query %s list
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(0),
|
||||
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.Bonds(cmd.Context(), &types.QueryGetBondsRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetBondByIdCmd implements the bond info by id query command.
|
||||
func GetBondByIdCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "get [bond Id]",
|
||||
Short: "Get bond.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get bond info by bond id .
|
||||
|
||||
Example:
|
||||
$ %s query bond get {BOND ID}
|
||||
`,
|
||||
version.AppName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
|
||||
id := args[0]
|
||||
|
||||
res, err := queryClient.GetBondById(cmd.Context(), &types.QueryGetBondByIdRequest{Id: id})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetBondListByOwnerCmd queries the bond list by owner.
|
||||
func GetBondListByOwnerCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "by-owner [address]",
|
||||
Short: "Query bonds by owner.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get bond list by owner.
|
||||
|
||||
Example:
|
||||
$ %s query %s query-by-owner [address]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
owner := args[0]
|
||||
res, err := queryClient.GetBondsByOwner(cmd.Context(), &types.QueryGetBondsByOwnerRequest{Owner: owner})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetBondModuleBalanceCmd queries the bond module account balance.
|
||||
func GetBondModuleBalanceCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "balance",
|
||||
Short: "Get bond module account balance.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get bond module balance.
|
||||
|
||||
Example:
|
||||
$ %s query %s balance
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(0),
|
||||
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.GetBondsModuleBalance(cmd.Context(), &types.QueryGetBondModuleBalanceRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/tharsis/ethermint/server/flags"
|
||||
"github.com/tharsis/ethermint/x/bond/types"
|
||||
)
|
||||
|
||||
// NewTxCmd returns a root CLI command handler for all x/bond transaction commands.
|
||||
func NewTxCmd() *cobra.Command {
|
||||
bondTxCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "bond transaction subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
bondTxCmd.AddCommand(
|
||||
NewCreateBondCmd(),
|
||||
RefillBondCmd(),
|
||||
WithdrawBondCmd(),
|
||||
CancelBondCmd(),
|
||||
)
|
||||
|
||||
return bondTxCmd
|
||||
}
|
||||
|
||||
// NewCreateBondCmd is the CLI command for creating a bond.
|
||||
func NewCreateBondCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "create [amount]",
|
||||
Short: "Create bond.",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
coin, err := sdk.ParseCoinNormalized(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := types.NewMsgCreateBond(sdk.NewCoins(coin), clientCtx.GetFromAddress())
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// RefillBondCmd is the CLI command for creating a bond.
|
||||
func RefillBondCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "refill [bond Id] [amount]",
|
||||
Short: "Refill bond.",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bondId := args[0]
|
||||
coin, err := sdk.ParseCoinNormalized(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := types.NewMsgRefillBond(bondId, coin, clientCtx.GetFromAddress())
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// WithdrawBondCmd is the CLI command for withdrawing funds from a bond.
|
||||
func WithdrawBondCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "withdraw [bond Id] [amount]",
|
||||
Short: "Withdraw amount from bond.",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bondId := args[0]
|
||||
coin, err := sdk.ParseCoinNormalized(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := types.NewMsgWithdrawBond(bondId, coin, clientCtx.GetFromAddress())
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// CancelBondCmd is the CLI command for cancelling a bond.
|
||||
func CancelBondCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "cancel [bond Id]",
|
||||
Short: "cancel bond.",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bondId := args[0]
|
||||
msg := types.NewMsgCancelBond(bondId, clientCtx.GetFromAddress())
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
Reference in New Issue
Block a user