forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client commands for manual upgrades
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
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,92 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
) | ||
|
||
func NewMsgSoftwareUpgrade(from sdk.AccAddress, pln types.Plan) (*types.MsgSoftwareUpgrade, error) { | ||
m := &types.MsgSoftwareUpgrade{ | ||
Authority: from.String(), | ||
Plan: pln, | ||
} | ||
return m, nil | ||
} | ||
|
||
func NewCmdManualUpgrade() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "manual-software-upgrade name height info", | ||
Args: cobra.ExactArgs(3), | ||
Short: "Create a software upgrade", | ||
Long: "Create a software upgrade.\n" + | ||
"Please specify a unique name and height for the upgrade to take effect.\n" + | ||
"You may include info to reference a binary download link, in a format compatible with: https://github.com/cosmos/cosmos-sdk/tree/main/cosmovisor", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
name := args[0] | ||
height := args[1] | ||
info := args[2] | ||
|
||
heightInt, err := strconv.ParseInt(height, 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
pln := types.Plan{ | ||
Name: name, | ||
Height: heightInt, | ||
Info: info, | ||
} | ||
|
||
from := clientCtx.GetFromAddress() | ||
msg, err := NewMsgSoftwareUpgrade(from, pln) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func NewMsgCancelUpgrade(from sdk.AccAddress) (*types.MsgCancelUpgrade, error) { | ||
m := &types.MsgCancelUpgrade{ | ||
Authority: from.String(), | ||
} | ||
return m, nil | ||
} | ||
|
||
func NewCmdManualCancelUpgrade() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "manual-cancel-upgrade", | ||
Args: cobra.ExactArgs(0), | ||
Short: "Cancel the current software upgrade", | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
from := clientCtx.GetFromAddress() | ||
msg, err := NewMsgCancelUpgrade(from) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
return cmd | ||
} |