diff --git a/cmd/eyes/init.go b/cmd/eyes/init.go new file mode 100644 index 000000000..54f424293 --- /dev/null +++ b/cmd/eyes/init.go @@ -0,0 +1,58 @@ +package main + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/spf13/viper" + + tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" + + "github.com/tendermint/basecoin/cmd/basecoin/commands" +) + +// InitCmd - node initialization command +var InitCmd = &cobra.Command{ + Use: "init", + Short: "Initialize eyes abci server", + RunE: initCmd, +} + +//nolint - flags +var ( + FlagChainID = "chain-id" //TODO group with other flags or remove? is this already a flag here? +) + +func init() { + InitCmd.Flags().String(FlagChainID, "eyes_test_id", "Chain ID") +} + +func initCmd(cmd *cobra.Command, args []string) error { + // this will ensure that config.toml is there if not yet created, and create dir + cfg, err := tcmd.ParseConfig() + if err != nil { + return err + } + + genesis := getGenesisJSON(viper.GetString(commands.FlagChainID)) + return commands.CreateGenesisValidatorFiles(cfg, genesis, cmd.Root().Name()) +} + +// TODO: better, auto-generate validator... +func getGenesisJSON(chainID string) string { + return fmt.Sprintf(`{ + "app_hash": "", + "chain_id": "%s", + "genesis_time": "0001-01-01T00:00:00.000Z", + "validators": [ + { + "amount": 10, + "name": "", + "pub_key": { + "type": "ed25519", + "data": "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" + } + } + ] +}`, chainID) +} diff --git a/cmd/eyes/main.go b/cmd/eyes/main.go new file mode 100644 index 000000000..2c92dd487 --- /dev/null +++ b/cmd/eyes/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "os" + + "github.com/tendermint/tmlibs/cli" + + "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/cmd/basecoin/commands" + "github.com/tendermint/basecoin/modules/base" + "github.com/tendermint/basecoin/modules/etc" + "github.com/tendermint/basecoin/stack" +) + +// BuildApp constructs the stack we want to use for this app +func BuildApp() basecoin.Handler { + return stack.New( + base.Logger{}, + stack.Recovery{}, + ). + // We do this to demo real usage, also embeds it under it's own namespace + Dispatch( + stack.WrapHandler(etc.NewHandler()), + ) +} + +func main() { + rt := commands.RootCmd + rt.Short = "eyes" + rt.Long = "A demo app to show key-value store with proofs over abci" + + commands.Handler = BuildApp() + + rt.AddCommand( + // out own init command to not require argument + InitCmd, + commands.StartCmd, + //commands.RelayCmd, + commands.UnsafeResetAllCmd, + commands.VersionCmd, + ) + + cmd := cli.PrepareMainCmd(rt, "EYE", os.ExpandEnv("$HOME/.eyes")) + cmd.Execute() +} diff --git a/cmd/eyescli/main.go b/cmd/eyescli/main.go new file mode 100644 index 000000000..1efa6bfc4 --- /dev/null +++ b/cmd/eyescli/main.go @@ -0,0 +1,67 @@ +package main + +import ( + "os" + + "github.com/spf13/cobra" + + keycmd "github.com/tendermint/go-crypto/cmd" + "github.com/tendermint/tmlibs/cli" + + "github.com/tendermint/basecoin/client/commands" + "github.com/tendermint/basecoin/client/commands/auto" + "github.com/tendermint/basecoin/client/commands/proxy" + "github.com/tendermint/basecoin/client/commands/query" + rpccmd "github.com/tendermint/basecoin/client/commands/rpc" + "github.com/tendermint/basecoin/client/commands/seeds" + txcmd "github.com/tendermint/basecoin/client/commands/txs" + etccmd "github.com/tendermint/basecoin/modules/etc/commands" +) + +// EyesCli - main basecoin client command +var EyesCli = &cobra.Command{ + Use: "eyescli", + Short: "Light client for tendermint", + Long: `EyesCli is the light client for a merkle key-value store (eyes)`, +} + +func main() { + commands.AddBasicFlags(EyesCli) + + // Prepare queries + query.RootCmd.AddCommand( + // These are default parsers, but optional in your app (you can remove key) + query.TxQueryCmd, + query.KeyQueryCmd, + // this is out custom parser + etccmd.EtcQueryCmd, + ) + + // no middleware wrapers + txcmd.Middleware = txcmd.Wrappers{} + // txcmd.Middleware.Register(txcmd.RootCmd.PersistentFlags()) + + // just the etc commands + txcmd.RootCmd.AddCommand( + etccmd.SetTxCmd, + etccmd.RemoveTxCmd, + ) + + // Set up the various commands to use + EyesCli.AddCommand( + // we use out own init command to not require address arg + commands.InitCmd, + commands.ResetCmd, + keycmd.RootCmd, + seeds.RootCmd, + rpccmd.RootCmd, + query.RootCmd, + txcmd.RootCmd, + proxy.RootCmd, + commands.VersionCmd, + auto.AutoCompleteCmd, + ) + + cmd := cli.PrepareMainCmd(EyesCli, "EYE", os.ExpandEnv("$HOME/.eyescli")) + cmd.Execute() +} diff --git a/modules/etc/commands/tx.go b/modules/etc/commands/tx.go index 92a444fa9..492067b24 100644 --- a/modules/etc/commands/tx.go +++ b/modules/etc/commands/tx.go @@ -17,7 +17,7 @@ var SetTxCmd = &cobra.Command{ // RemoveTxCmd is CLI command to remove data var RemoveTxCmd = &cobra.Command{ - Use: "Remove", + Use: "remove", Short: "Removes a key value pair", RunE: commands.RequireInit(removeTxCmd), }