From fca35fc43533d4432b1308bc8805dd0b87cbeb34 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Mon, 2 May 2022 16:07:27 -0700 Subject: [PATCH] feat(agd): Add install-bundle command --- golang/cosmos/x/swingset/client/cli/tx.go | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/golang/cosmos/x/swingset/client/cli/tx.go b/golang/cosmos/x/swingset/client/cli/tx.go index 09f70697f5bd..7aaad5c4dd39 100644 --- a/golang/cosmos/x/swingset/client/cli/tx.go +++ b/golang/cosmos/x/swingset/client/cli/tx.go @@ -34,6 +34,7 @@ func GetTxCmd(storeKey string) *cobra.Command { swingsetTxCmd.AddCommand( GetCmdDeliver(), GetCmdProvisionOne(), + GetCmdInstallBundle(), ) return swingsetTxCmd @@ -85,6 +86,48 @@ func GetCmdDeliver() *cobra.Command { return cmd } +// GetCmdInstallBundle is the CLI command for constructing or sending an +// InstallBundle message in a transaction. +func GetCmdInstallBundle() *cobra.Command { + cmd := &cobra.Command{ + Use: "install-bundle /@/-", + Args: cobra.ExactArgs(1), + + RunE: func(cmd *cobra.Command, args []string) error { + cctx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + jsonIn := args[0] + if jsonIn[0] == '@' { + fname := args[0][1:] + if fname == "-" { + // Reading from stdin. + if _, err := fmt.Scanln(&jsonIn); err != nil { + return err + } + } else { + jsonBytes, err := ioutil.ReadFile(fname) + if err != nil { + return err + } + jsonIn = string(jsonBytes) + } + } + + msg := types.NewMsgInstallBundle(jsonIn, cctx.GetFromAddress()) + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(cctx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} + // GetCmdProvision is the CLI command for sending a Provision transaction func GetCmdProvisionOne() *cobra.Command { cmd := &cobra.Command{