Skip to content

Commit

Permalink
cmd/network/governance: Parameter change proposal support
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Nov 24, 2023
1 parent a63db76 commit bc3bf44
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
60 changes: 60 additions & 0 deletions cmd/network/governance/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -74,6 +75,61 @@ var (
},
}

govCreateProposalParameterChangeCmd = &cobra.Command{
Use: "parameter-change <module> <changes.json>",
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 {

Check failure on line 116 in cmd/network/governance/create.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 104 (govet)
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 <proposal-id>",
Short: "Create a cancel upgrade governance proposal",
Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions cmd/network/governance/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var govListCmd = &cobra.Command{
kind = "upgrade"
case proposal.Content.CancelUpgrade != nil:
kind = fmt.Sprintf("cancel upgrade %d", proposal.Content.CancelUpgrade.ProposalID)
case proposal.Content.ChangeParameters != nil:
kind = fmt.Sprintf("change parameters (%s)", proposal.Content.ChangeParameters.Module)
default:
kind = "unknown"
}
Expand Down

0 comments on commit bc3bf44

Please sign in to comment.