Add eyes and eyescli main commands
Note how the all framework commands can be reused with a bit of configurations. And one can add the custom query and tx commands.
This commit is contained in:
parent
6e38609e3f
commit
6bc5fa3876
|
@ -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)
|
||||
}
|
|
@ -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()
|
||||
}
|
|
@ -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()
|
||||
}
|
|
@ -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),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue