Skip to content

Commit

Permalink
building pyloncli
Browse files Browse the repository at this point in the history
  • Loading branch information
girishramnani authored and antstalepresh committed May 27, 2020
1 parent 6568b3e commit 02d1f9f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN go install ./cmd/pylonscli
RUN GO111MODULE=on make unit_tests

# Basic installation for daemon and cli
RUN ./pylonsd init --chain-id pylonschain
RUN ./pylonsd init masternode --chain-id pylonschain
RUN make init_accounts
RUN pylonscli config chain-id pylonschain
RUN pylonscli config output json
Expand Down
76 changes: 40 additions & 36 deletions cmd/pylonscli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ import (
"path"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/lcd"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/spf13/cobra"
"github.com/spf13/viper"
amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/libs/cli"

app "github.com/Pylons-tech/pylons/app"
plnclient "github.com/Pylons-tech/pylons/x/pylons/client"
plnrest "github.com/Pylons-tech/pylons/x/pylons/client/rest"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
auth "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
)

const (
Expand All @@ -43,17 +42,13 @@ func main() {
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
config.Seal()

mc := []sdk.ModuleClients{
plnclient.NewModuleClient(storeNS, cdc),
}

rootCmd := &cobra.Command{
Use: "plncli",
Short: "The Pylons Client",
}

// Add --chain-id to persistent flags and mark it required
rootCmd.PersistentFlags().String(client.FlagChainID, "", "Chain ID of tendermint node")
rootCmd.PersistentFlags().String(flags.FlagChainID, "", "Chain ID of tendermint node")
rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {
return initConfig(rootCmd)
}
Expand All @@ -62,13 +57,13 @@ func main() {
rootCmd.AddCommand(
rpc.StatusCommand(),
client.ConfigCmd(defaultCLIHome),
queryCmd(cdc, mc),
txCmd(cdc, mc),
client.LineBreak,
queryCmd(cdc),
txCmd(cdc),
flags.LineBreak,
lcd.ServeCommand(cdc, registerRoutes),
client.LineBreak,
flags.LineBreak,
keys.Commands(),
client.LineBreak,
flags.LineBreak,
)

executor := cli.PrepareMainCmd(rootCmd, "NS", defaultCLIHome)
Expand All @@ -79,55 +74,64 @@ func main() {
}

func registerRoutes(rs *lcd.RestServer) {
rs.CliCtx = rs.CliCtx.WithAccountDecoder(rs.Cdc)
rpc.RegisterRoutes(rs.CliCtx, rs.Mux)
tx.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, storeAcc)
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
plnrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, storeNS)
client.RegisterRoutes(rs.CliCtx, rs.Mux)
authrest.RegisterTxRoutes(rs.CliCtx, rs.Mux)
app.ModuleBasics.RegisterRESTRoutes(rs.CliCtx, rs.Mux)
}

func queryCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command {
func queryCmd(cdc *amino.Codec) *cobra.Command {
queryCmd := &cobra.Command{
Use: "query",
Aliases: []string{"q"},
Short: "Querying subcommands",
}

queryCmd.AddCommand(
authcmd.GetAccountCmd(cdc),
flags.LineBreak,
rpc.ValidatorCommand(cdc),
rpc.BlockCommand(),
tx.SearchTxCmd(cdc),
tx.QueryTxCmd(cdc),
client.LineBreak,
authcmd.GetAccountCmd(storeAcc, cdc),
authcmd.QueryTxCmd(cdc),
authcmd.QueryTxCmd(cdc),
flags.LineBreak,
)

for _, m := range mc {
queryCmd.AddCommand(m.GetQueryCmd())
}
app.ModuleBasics.AddQueryCommands(queryCmd, cdc)

return queryCmd
}

func txCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command {
func txCmd(cdc *amino.Codec) *cobra.Command {
txCmd := &cobra.Command{
Use: "tx",
Short: "Transactions subcommands",
}

txCmd.AddCommand(
bankcmd.SendTxCmd(cdc),
client.LineBreak,
flags.LineBreak,
authcmd.GetSignCommand(cdc),
tx.GetBroadcastCommand(cdc),
client.LineBreak,
authcmd.GetMultiSignCommand(cdc),
flags.LineBreak,
authcmd.GetBroadcastCommand(cdc),
authcmd.GetEncodeCommand(cdc),
authcmd.GetDecodeCommand(cdc),
flags.LineBreak,
)
// add modules' tx commands
app.ModuleBasics.AddTxCommands(txCmd, cdc)

for _, m := range mc {
txCmd.AddCommand(m.GetTxCmd())
// remove auth and bank commands as they're mounted under the root tx command
var cmdsToRemove []*cobra.Command

for _, cmd := range txCmd.Commands() {
if cmd.Use == auth.ModuleName || cmd.Use == bank.ModuleName {
cmdsToRemove = append(cmdsToRemove, cmd)
}
}

txCmd.RemoveCommand(cmdsToRemove...)

return txCmd
}

Expand All @@ -145,7 +149,7 @@ func initConfig(cmd *cobra.Command) error {
return err
}
}
if err := viper.BindPFlag(client.FlagChainID, cmd.PersistentFlags().Lookup(client.FlagChainID)); err != nil {
if err := viper.BindPFlag(flags.FlagChainID, cmd.PersistentFlags().Lookup(flags.FlagChainID)); err != nil {
return err
}
if err := viper.BindPFlag(cli.EncodingFlag, cmd.PersistentFlags().Lookup(cli.EncodingFlag)); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/pylons/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (

const (
// ModuleName is the name of the module
ModuleName = "pylons"
ModuleName = "Pylons"

// StoreKey to be used when creating the KVStore
StoreKey = ModuleName
Expand Down

0 comments on commit 02d1f9f

Please sign in to comment.