From 4fa9e93b7d4ca7c0ef38b9e00f43994dbe3d6c26 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Wed, 11 Oct 2023 11:29:59 +0200 Subject: [PATCH 1/2] feat(cmd/network): Add network set-chain-context subcommand --- cmd/network/network.go | 1 + cmd/network/set_chain_context.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 cmd/network/set_chain_context.go diff --git a/cmd/network/network.go b/cmd/network/network.go index dae4b2b9..fd429420 100644 --- a/cmd/network/network.go +++ b/cmd/network/network.go @@ -55,6 +55,7 @@ func init() { Cmd.AddCommand(governance.Cmd) Cmd.AddCommand(listCmd) Cmd.AddCommand(rmCmd) + Cmd.AddCommand(setChainContextCmd) Cmd.AddCommand(setDefaultCmd) Cmd.AddCommand(setRPCCmd) Cmd.AddCommand(showCmd) diff --git a/cmd/network/set_chain_context.go b/cmd/network/set_chain_context.go new file mode 100644 index 00000000..78582aa7 --- /dev/null +++ b/cmd/network/set_chain_context.go @@ -0,0 +1,30 @@ +package network + +import ( + "fmt" + + "github.com/spf13/cobra" + + cliConfig "github.com/oasisprotocol/cli/config" +) + +var setChainContextCmd = &cobra.Command{ + Use: "set-chain-context ", + Short: "Sets the chain context of the given network", + Args: cobra.ExactArgs(2), + Run: func(cmd *cobra.Command, args []string) { + cfg := cliConfig.Global() + name, chainContext := args[0], args[1] + + net := cfg.Networks.All[name] + if net == nil { + cobra.CheckErr(fmt.Errorf("network '%s' does not exist", name)) + return // To make staticcheck happy as it doesn't know CheckErr exits. + } + + net.ChainContext = chainContext + + err := cfg.Save() + cobra.CheckErr(err) + }, +} From 8095301f0f52879eb3593c75bf5cd6d5c9f7eb1a Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Wed, 11 Oct 2023 11:35:07 +0200 Subject: [PATCH 2/2] fix(examples): Update network governance list output --- docs/network.md | 15 +++++++++++++++ examples/network-governance/list.out | 1 + examples/network/05-set-chain-context.in | 1 + examples/network/05-set-chain-context.out | 0 4 files changed, 17 insertions(+) create mode 100644 examples/network/05-set-chain-context.in create mode 100644 examples/network/05-set-chain-context.out diff --git a/docs/network.md b/docs/network.md index 80cf6be2..0b95d24a 100644 --- a/docs/network.md +++ b/docs/network.md @@ -75,6 +75,21 @@ all dependant ParaTimes. ![code shell](../examples/network/01-remove.in) +## Set Network Chain Context {#set-chain-context} + +To change the chain context of a network, use +`network set-chain-context `. + +:::caution + +Chain contexts represent a root of trust in the network, so before changing them +for production networks make sure you have verified them against a trusted +source like the official Oasis documentation. + +::: + +![code shell](../examples/network/05-set-chain-context.in) + ## Set Default Network {#set-default} To change the default network for future Oasis CLI operations, use diff --git a/examples/network-governance/list.out b/examples/network-governance/list.out index 84ec273b..04b1ddfb 100644 --- a/examples/network-governance/list.out +++ b/examples/network-governance/list.out @@ -6,3 +6,4 @@ ID KIND SUBMITTER CREATED AT CL 5 upgrade oasis1qrs2dl6nz6fcxxr3tq37laxlz6hxk6kuscnr6rxj 14869 14881 passed 6 cancel upgrade 5 oasis1qrs2dl6nz6fcxxr3tq37laxlz6hxk6kuscnr6rxj 14895 14907 passed 7 upgrade oasis1qrs2dl6nz6fcxxr3tq37laxlz6hxk6kuscnr6rxj 14982 14994 passed +8 upgrade oasis1qpwaggvmhwq5uk40clase3knt655nn2tdy39nz2f 29493 29505 passed diff --git a/examples/network/05-set-chain-context.in b/examples/network/05-set-chain-context.in new file mode 100644 index 00000000..fef72232 --- /dev/null +++ b/examples/network/05-set-chain-context.in @@ -0,0 +1 @@ +oasis network set-chain-context mainnet_local b11b369e0da5bb230b220127f5e7b242d385ef8c6f54906243f30af63c815535 diff --git a/examples/network/05-set-chain-context.out b/examples/network/05-set-chain-context.out new file mode 100644 index 00000000..e69de29b