From c57e9aa4379acf17aaa389b364185bc49c68cc39 Mon Sep 17 00:00:00 2001 From: ptrus Date: Fri, 24 Nov 2023 17:18:03 +0100 Subject: [PATCH] cmd/network/governance: Parameter change proposal support --- cmd/network/governance/create.go | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/cmd/network/governance/create.go b/cmd/network/governance/create.go index d6d34dbd..4389ffbf 100644 --- a/cmd/network/governance/create.go +++ b/cmd/network/governance/create.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" + "github.com/oasisprotocol/oasis-core/go/common/cbor" governance "github.com/oasisprotocol/oasis-core/go/governance/api" upgrade "github.com/oasisprotocol/oasis-core/go/upgrade/api" "github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection" @@ -74,6 +75,61 @@ var ( }, } + govCreateProposalParameterChangeCmd = &cobra.Command{ + Use: "parameter-change ", + Short: "Create a parameter change governance proposal", + Args: cobra.ExactArgs(2), + Run: func(cmd *cobra.Command, args []string) { + cfg := cliConfig.Global() + npa := common.GetNPASelection(cfg) + txCfg := common.GetTransactionConfig() + + module := args[0] + changesJSON := args[1] + + if npa.Account == nil { + cobra.CheckErr("no accounts configured in your wallet") + } + + // When not in offline mode, connect to the given network endpoint. + ctx := context.Background() + var conn connection.Connection + if !txCfg.Offline { + var err error + conn, err = connection.Connect(ctx, npa.Network) + cobra.CheckErr(err) + } + + // Load changes json. + rawChanges, err := os.ReadFile(changesJSON) + cobra.CheckErr(err) + + // Parse upgrade descriptor. + var changes map[string]interface{} + if err = json.Unmarshal(rawChanges, &changes); err != nil { + cobra.CheckErr(fmt.Errorf("malformed parameter upgrade proposal: %w", err)) + } + content := &governance.ChangeParametersProposal{ + Module: module, + Changes: cbor.Marshal(changes), + } + if err := content.ValidateBasic(); err != nil { + cobra.CheckErr(fmt.Errorf("invalid parameter upgrade proposal: %w", err)) + } + + // Prepare transaction. + tx := governance.NewSubmitProposalTx(0, nil, &governance.ProposalContent{ + ChangeParameters: content, + }) + + acc := common.LoadAccount(cfg, npa.AccountName) + sigTx, err := common.SignConsensusTransaction(ctx, npa, acc, conn, tx) + cobra.CheckErr(err) + + common.BroadcastOrExportTransaction(ctx, npa.ParaTime, conn, sigTx, nil, nil) + }, + } + govCreateProposalCancelUpgradeCmd = &cobra.Command{ Use: "cancel-upgrade ", Short: "Create a cancel upgrade governance proposal", @@ -121,9 +177,13 @@ func init() { govCreateProposalUpgradeCmd.Flags().AddFlagSet(common.SelectorNAFlags) govCreateProposalUpgradeCmd.Flags().AddFlagSet(common.TxFlags) + govCreateProposalParameterChangeCmd.Flags().AddFlagSet(common.SelectorNAFlags) + govCreateProposalUpgradeCmd.Flags().AddFlagSet(common.TxFlags) + govCreateProposalCancelUpgradeCmd.Flags().AddFlagSet(common.SelectorNAFlags) govCreateProposalCancelUpgradeCmd.Flags().AddFlagSet(common.TxFlags) govCreateProposalCmd.AddCommand(govCreateProposalUpgradeCmd) + govCreateProposalCmd.AddCommand(govCreateProposalParameterChangeCmd) govCreateProposalCmd.AddCommand(govCreateProposalCancelUpgradeCmd) }