forked from cerc-io/laconicd-deprecated
rename nameservie to registry (#54)
This commit is contained in:
@@ -0,0 +1,397 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cerc-io/laconicd/x/registry/types"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// GetQueryCmd returns the cli query commands for this module
|
||||
func GetQueryCmd() *cobra.Command {
|
||||
registryQueryCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Querying commands for the registry module",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
registryQueryCmd.AddCommand(
|
||||
GetCmdWhoIs(),
|
||||
GetCmdResolve(),
|
||||
GetCmdLookupCRN(),
|
||||
GetRecordExpiryQueue(),
|
||||
GetAuthorityExpiryQueue(),
|
||||
GetQueryParamsCmd(),
|
||||
GetCmdList(),
|
||||
GetCmdGetResource(),
|
||||
GetCmdQueryByBond(),
|
||||
GetCmdBalance(),
|
||||
GetCmdNames(),
|
||||
)
|
||||
return registryQueryCmd
|
||||
}
|
||||
|
||||
// GetCmdWhoIs queries a whois info for a name.
|
||||
func GetCmdWhoIs() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "whois [name]",
|
||||
Short: "Get name owner info.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get name owner info.
|
||||
Example:
|
||||
$ %s query %s whois [name]
|
||||
`,
|
||||
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)
|
||||
res, err := queryClient.Whois(cmd.Context(), &types.QueryWhoisRequest{Name: args[0]})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdLookupCRN queries naming info for a CRN.
|
||||
func GetCmdLookupCRN() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "lookup [crn]",
|
||||
Short: "Get naming info for CRN.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get naming info for CRN.
|
||||
Example:
|
||||
$ %s query %s lookup [crn]
|
||||
`,
|
||||
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)
|
||||
res, err := queryClient.LookupCrn(cmd.Context(), &types.QueryLookupCrn{Crn: args[0]})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// GetCmdList queries all records.
|
||||
func GetCmdList() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List records.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get the records.
|
||||
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.ListRecords(cmd.Context(), &types.QueryListRecordsRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
recordsList := res.GetRecords()
|
||||
records := make([]types.RecordType, len(recordsList))
|
||||
for i, record := range res.GetRecords() {
|
||||
records[i] = record.ToRecordType()
|
||||
}
|
||||
bytesResult, err := json.Marshal(records)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return clientCtx.PrintBytes(bytesResult)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdGetResource queries a record record.
|
||||
func GetCmdGetResource() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "get [ID]",
|
||||
Short: "Get record.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get the record by id.
|
||||
Example:
|
||||
$ %s query %s get [ID]
|
||||
`,
|
||||
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)
|
||||
record, err := queryClient.GetRecord(cmd.Context(), &types.QueryRecordByIDRequest{Id: args[0]})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return clientCtx.PrintProto(record)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdResolve resolves a CRN to a record.
|
||||
func GetCmdResolve() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "resolve [crn]",
|
||||
Short: "Resolve CRN to record.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Resolve CRN to record.
|
||||
Example:
|
||||
$ %s query %s resolve [crn]
|
||||
`,
|
||||
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)
|
||||
record, err := queryClient.ResolveCrn(cmd.Context(), &types.QueryResolveCrn{Crn: args[0]})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return clientCtx.PrintProto(record)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryByBond queries records by bond ID.
|
||||
func GetCmdQueryByBond() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "query-by-bond [bond-id]",
|
||||
Short: "Query records by bond ID.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get the record by bond id.
|
||||
Example:
|
||||
$ %s query %s query-by-bond [bond id]
|
||||
`,
|
||||
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)
|
||||
|
||||
bondID := args[0]
|
||||
res, err := queryClient.GetRecordByBondID(cmd.Context(), &types.QueryRecordByBondIDRequest{Id: bondID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdBalance queries the bond module account balance.
|
||||
func GetCmdBalance() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "balance",
|
||||
Short: "Get record rent module account balance.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get the record rent module account 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.GetRegistryModuleBalance(cmd.Context(), &types.GetRegistryModuleBalanceRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdNames queries all naming records.
|
||||
func GetCmdNames() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "names",
|
||||
Short: "List name records.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get the names list.
|
||||
Example:
|
||||
$ %s query %s names
|
||||
`,
|
||||
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.ListNameRecords(cmd.Context(), &types.QueryListNameRecordsRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetRecordExpiryQueue gets the record expiry queue.
|
||||
func GetRecordExpiryQueue() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "record-expiry",
|
||||
Short: "Get record expiry queue.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get record expiry queue.
|
||||
Example:
|
||||
$ %s query %s record-expiry
|
||||
`,
|
||||
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.GetRecordExpiryQueue(cmd.Context(), &types.QueryGetRecordExpiryQueue{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetAuthorityExpiryQueue gets the authority expiry queue.
|
||||
func GetAuthorityExpiryQueue() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "authority-expiry",
|
||||
Short: "Get authority expiry queue.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get authority expiry queue.
|
||||
Example:
|
||||
$ %s query %s authority-expiry
|
||||
`,
|
||||
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.GetAuthorityExpiryQueue(cmd.Context(), &types.QueryGetAuthorityExpiryQueue{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,394 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/cerc-io/laconicd/server/flags"
|
||||
"github.com/cerc-io/laconicd/x/registry/types"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// NewTxCmd returns a root CLI command handler for all x/bond transaction commands.
|
||||
func NewTxCmd() *cobra.Command {
|
||||
registryTxCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "registry transaction subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
registryTxCmd.AddCommand(
|
||||
GetCmdSetRecord(),
|
||||
GetCmdRenewRecord(),
|
||||
GetCmdAssociateBond(),
|
||||
GetCmdDissociateBond(),
|
||||
GetCmdDissociateRecords(),
|
||||
GetCmdReAssociateRecords(),
|
||||
GetCmdSetName(),
|
||||
GetCmdReserveName(),
|
||||
GetCmdSetAuthorityBond(),
|
||||
GetCmdDeleteName(),
|
||||
)
|
||||
|
||||
return registryTxCmd
|
||||
}
|
||||
|
||||
// GetCmdSetRecord is the CLI command for creating/updating a record.
|
||||
func GetCmdSetRecord() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "set [payload file path] [bond-id]",
|
||||
Short: "Set record.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Create a new record with payload and bond id.
|
||||
Example:
|
||||
$ %s tx %s set [payload file path] [bond-id]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
payloadType, err := GetPayloadFromFile(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
payload, err := payloadType.ToPayload()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := types.NewMsgSetRecord(payload, args[1], clientCtx.GetFromAddress())
|
||||
err = msg.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd, _ = flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdRenewRecord is the CLI command for renewing an expired record.
|
||||
func GetCmdRenewRecord() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "renew-record [record-id]",
|
||||
Short: "Renew (expired) record.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Renew record.
|
||||
Example:
|
||||
$ %s tx %s renew-record [record-id]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := types.NewMsgRenewRecord(args[0], clientCtx.GetFromAddress())
|
||||
err = msg.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd, _ = flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdAssociateBond is the CLI command for associating a record with a bond.
|
||||
func GetCmdAssociateBond() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "associate-bond [record-id] [bond-id]",
|
||||
Short: "Associate record with bond.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Associate record with bond.
|
||||
Example:
|
||||
$ %s tx %s associate-bond [record-id] [bond-id]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := types.NewMsgAssociateBond(args[0], args[1], clientCtx.GetFromAddress())
|
||||
err = msg.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd, _ = flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdDissociateBond is the CLI command for dissociating a record from a bond.
|
||||
func GetCmdDissociateBond() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "dissociate-bond [record-id]",
|
||||
Short: "Dissociate record from (existing) bond.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Dissociate record from (existing) bond.
|
||||
Example:
|
||||
$ %s tx %s dissociate-bond [record-id]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := types.NewMsgDissociateBond(args[0], clientCtx.GetFromAddress())
|
||||
err = msg.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd, _ = flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdDissociateRecords is the CLI command for dissociating all records from a bond.
|
||||
func GetCmdDissociateRecords() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "dissociate-records [bond-id]",
|
||||
Short: "Dissociate all records from bond.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Dissociate all records from bond.
|
||||
Example:
|
||||
$ %s tx %s dissociate-bond [record-id]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := types.NewMsgDissociateRecords(args[0], clientCtx.GetFromAddress())
|
||||
err = msg.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd, _ = flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdReAssociateRecords is the CLI command for reassociating all records from old to new bond.
|
||||
func GetCmdReAssociateRecords() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "reassociate-records [old-bond-id] [new-bond-id]",
|
||||
Short: "Re-Associates all records from old to new bond.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Re-Associates all records from old to new bond.
|
||||
Example:
|
||||
$ %s tx %s reassociate-records [old-bond-id] [new-bond-id]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := types.NewMsgReAssociateRecords(args[0], args[1], clientCtx.GetFromAddress())
|
||||
err = msg.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd, _ = flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdSetName is the CLI command for mapping a name to a CID.
|
||||
func GetCmdSetName() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "set-name [crn] [cid]",
|
||||
Short: "Set CRN to CID mapping.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Set name with crn and cid.
|
||||
Example:
|
||||
$ %s tx %s set-name [crn] [cid]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := types.NewMsgSetName(args[0], args[1], clientCtx.GetFromAddress())
|
||||
err = msg.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd, _ = flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdReserveName is the CLI command for reserving a name.
|
||||
func GetCmdReserveName() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "reserve-name [name]",
|
||||
Short: "Reserve name.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Reserver name with owner address .
|
||||
Example:
|
||||
$ %s tx %s reserve-name [name] --owner [ownerAddress]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
owner, err := cmd.Flags().GetString("owner")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ownerAddress, err := sdk.AccAddressFromBech32(owner)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := types.NewMsgReserveAuthority(args[0], clientCtx.GetFromAddress(), ownerAddress)
|
||||
err = msg.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String("owner", "", "Owner address, if creating a sub-authority.")
|
||||
|
||||
cmd, _ = flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdSetAuthorityBond is the CLI command for associating a bond with an authority.
|
||||
func GetCmdSetAuthorityBond() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "authority-bond [name] [bond-id]",
|
||||
Short: "Associate authority with bond.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Reserver name with owner address .
|
||||
Example:
|
||||
$ %s tx %s authority-bond [name] [bond-id]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := types.NewMsgSetAuthorityBond(args[0], args[1], clientCtx.GetFromAddress())
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd, _ = flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func GetCmdDeleteName() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "delete-name [crn]",
|
||||
Short: "Delete CRN.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Delete CRN.
|
||||
Example:
|
||||
$ %s tx %s delete-name [crn]
|
||||
`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := types.NewMsgDeleteNameAuthority(args[0], clientCtx.GetFromAddress())
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd, _ = flags.AddTxFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetPayloadFromFile Load payload object from YAML file.
|
||||
func GetPayloadFromFile(filePath string) (*types.PayloadType, error) {
|
||||
var payload types.PayloadType
|
||||
|
||||
data, err := ioutil.ReadFile(filePath) // #nosec G304
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = yaml.Unmarshal(data, &payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &payload, nil
|
||||
}
|
||||
Reference in New Issue
Block a user