forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy over gaiacli skeleton to basecli
- Loading branch information
1 parent
e867692
commit 66e6677
Showing
5 changed files
with
292 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package main | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
const ( | ||
// these are needed for every init | ||
flagChainID = "chain-id" | ||
flagNode = "node" | ||
|
||
// one of the following should be provided to verify the connection | ||
flagGenesis = "genesis" | ||
flagCommit = "commit" | ||
flagValHash = "validator-set" | ||
|
||
flagSelect = "select" | ||
flagTags = "tag" | ||
flagAny = "any" | ||
|
||
flagBind = "bind" | ||
flagCORS = "cors" | ||
flagTrustNode = "trust-node" | ||
|
||
// this is for signing | ||
flagName = "name" | ||
) | ||
|
||
var ( | ||
statusCmd = &cobra.Command{ | ||
Use: "status", | ||
Short: "Query remote node for status", | ||
RunE: todoNotImplemented, | ||
} | ||
) | ||
|
||
// AddClientCommands returns a sub-tree of all basic client commands | ||
// | ||
// Call AddGetCommand and AddPostCommand to add custom txs and queries | ||
func AddClientCommands(cmd *cobra.Command) { | ||
cmd.AddCommand( | ||
initClientCommand(), | ||
statusCmd, | ||
blockCommand(), | ||
validatorCommand(), | ||
lineBreak, | ||
txSearchCommand(), | ||
txCommand(), | ||
lineBreak, | ||
) | ||
} | ||
|
||
// GetCommands adds common flags to query commands | ||
func GetCommands(cmds ...*cobra.Command) []*cobra.Command { | ||
for _, c := range cmds { | ||
c.Flags().Bool(flagTrustNode, false, "Don't verify proofs for responses") | ||
} | ||
return cmds | ||
} | ||
|
||
// PostCommands adds common flags for commands to post tx | ||
func PostCommands(cmds ...*cobra.Command) []*cobra.Command { | ||
for _, c := range cmds { | ||
c.Flags().String(flagName, "", "Name of private key with which to sign") | ||
c.Flags().String(flagPassword, "", "Password to use the named private key") | ||
} | ||
return cmds | ||
} | ||
|
||
func initClientCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "init", | ||
Short: "Initialize light client", | ||
RunE: todoNotImplemented, | ||
} | ||
cmd.Flags().StringP(flagChainID, "c", "", "ID of chain we connect to") | ||
cmd.Flags().StringP(flagNode, "n", "tcp://localhost:46657", "Node to connect to") | ||
cmd.Flags().String(flagGenesis, "", "Genesis file to verify header validity") | ||
cmd.Flags().String(flagCommit, "", "File with trusted and signed header") | ||
cmd.Flags().String(flagValHash, "", "Hash of trusted validator set (hex-encoded)") | ||
return cmd | ||
} | ||
|
||
func blockCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "block <height>", | ||
Short: "Get verified data for a the block at given height", | ||
RunE: todoNotImplemented, | ||
} | ||
cmd.Flags().StringSlice(flagSelect, []string{"header", "tx"}, "Fields to return (header|txs|results)") | ||
return cmd | ||
} | ||
|
||
func validatorCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "validatorset <height>", | ||
Short: "Get the full validator set at given height", | ||
RunE: todoNotImplemented, | ||
} | ||
return cmd | ||
} | ||
|
||
func serveCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "serve", | ||
Short: "Start LCD (light-client daemon), a local REST server", | ||
RunE: todoNotImplemented, | ||
} | ||
// TODO: handle unix sockets also? | ||
cmd.Flags().StringP(flagBind, "b", "localhost:1317", "Interface and port that server binds to") | ||
cmd.Flags().String(flagCORS, "", "Set to domains that can make CORS requests (* for all)") | ||
return cmd | ||
} | ||
|
||
func txSearchCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "txs", | ||
Short: "Search for all transactions that match the given tags", | ||
RunE: todoNotImplemented, | ||
} | ||
cmd.Flags().StringSlice(flagTags, nil, "Tags that must match (may provide multiple)") | ||
cmd.Flags().Bool(flagAny, false, "Return transactions that match ANY tag, rather than ALL") | ||
return cmd | ||
} | ||
|
||
func txCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "tx <hash>", | ||
Short: "Matches this txhash over all committed blocks", | ||
RunE: todoNotImplemented, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
flagTo = "to" | ||
flagAmount = "amount" | ||
flagFee = "fee" | ||
) | ||
|
||
func postSendCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "send", | ||
Short: "Create and sign a send tx", | ||
RunE: todoNotImplemented, | ||
} | ||
cmd.Flags().String(flagTo, "", "Address to send coins") | ||
cmd.Flags().String(flagAmount, "", "Amount of coins to send") | ||
cmd.Flags().String(flagFee, "", "Fee to pay along with transaction") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
const ( | ||
flagPassword = "password" | ||
flagNewPassword = "new-password" | ||
flagType = "type" | ||
flagSeed = "seed" | ||
flagDryRun = "dry-run" | ||
) | ||
|
||
var ( | ||
listKeysCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List all locally availably keys", | ||
RunE: todoNotImplemented, | ||
} | ||
|
||
showKeysCmd = &cobra.Command{ | ||
Use: "show <name>", | ||
Short: "Show key info for the given name", | ||
RunE: todoNotImplemented, | ||
} | ||
) | ||
|
||
// KeyCommands registers a sub-tree of commands to interact with | ||
// local private key storage. | ||
func KeyCommands() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "keys", | ||
Short: "Add or view local private keys", | ||
} | ||
cmd.AddCommand( | ||
addKeyCommand(), | ||
listKeysCmd, | ||
showKeysCmd, | ||
lineBreak, | ||
deleteKeyCommand(), | ||
updateKeyCommand(), | ||
) | ||
return cmd | ||
} | ||
|
||
func addKeyCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "add <name>", | ||
Short: "Create a new key, or import from seed", | ||
RunE: todoNotImplemented, | ||
} | ||
cmd.Flags().StringP(flagPassword, "p", "", "Password to encrypt private key") | ||
cmd.Flags().StringP(flagType, "t", "ed25519", "Type of private key (ed25519|secp256k1|ledger)") | ||
cmd.Flags().StringP(flagSeed, "s", "", "Provide seed phrase to recover existing key instead of creating") | ||
cmd.Flags().Bool(flagDryRun, false, "Perform action, but don't add key to local keystore") | ||
return cmd | ||
} | ||
|
||
func updateKeyCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update <name>", | ||
Short: "Change the password used to protect private key", | ||
RunE: todoNotImplemented, | ||
} | ||
cmd.Flags().StringP(flagPassword, "p", "", "Current password to decrypt key") | ||
cmd.Flags().String(flagNewPassword, "", "New password to use to protect key") | ||
return cmd | ||
} | ||
|
||
func deleteKeyCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "delete <name>", | ||
Short: "Delete the given key", | ||
RunE: todoNotImplemented, | ||
} | ||
cmd.Flags().StringP(flagPassword, "p", "", "Password of existing key to delete") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/tendermint/tmlibs/cli" | ||
|
||
"github.com/cosmos/cosmos-sdk/version" | ||
) | ||
|
||
// gaiacliCmd is the entry point for this binary | ||
var ( | ||
basecliCmd = &cobra.Command{ | ||
Use: "basecli", | ||
Short: "Basecoin light-client", | ||
} | ||
|
||
lineBreak = &cobra.Command{Run: func(*cobra.Command, []string) {}} | ||
|
||
getAccountCmd = &cobra.Command{ | ||
Use: "account <address>", | ||
Short: "Query account balance", | ||
RunE: todoNotImplemented, | ||
} | ||
) | ||
|
||
func todoNotImplemented(_ *cobra.Command, _ []string) error { | ||
return errors.New("TODO: Command not yet implemented") | ||
} | ||
|
||
func main() { | ||
// disable sorting | ||
cobra.EnableCommandSorting = false | ||
|
||
// generic client commands | ||
AddClientCommands(basecliCmd) | ||
// query commands (custom to binary) | ||
basecliCmd.AddCommand( | ||
GetCommands(getAccountCmd)...) | ||
// post tx commands (custom to binary) | ||
basecliCmd.AddCommand( | ||
PostCommands(postSendCommand())...) | ||
|
||
// add proxy, version and key info | ||
basecliCmd.AddCommand( | ||
lineBreak, | ||
serveCommand(), | ||
KeyCommands(), | ||
lineBreak, | ||
version.VersionCmd, | ||
) | ||
|
||
// prepare and add flags | ||
executor := cli.PrepareBaseCmd(basecliCmd, "GA", os.ExpandEnv("$HOME/.basecli")) | ||
executor.Execute() | ||
} |