Skip to content

Commit

Permalink
Merge pull request #141 from oasisprotocol/kostko/feature/net-set-cha…
Browse files Browse the repository at this point in the history
…in-ctx

feat(cmd/network): Add network set-chain-context subcommand
  • Loading branch information
kostko authored Oct 11, 2023
2 parents d6313ab + 8095301 commit 5870157
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions cmd/network/set_chain_context.go
Original file line number Diff line number Diff line change
@@ -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 <name> <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)
},
}
15 changes: 15 additions & 0 deletions docs/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> <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
Expand Down
1 change: 1 addition & 0 deletions examples/network-governance/list.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions examples/network/05-set-chain-context.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oasis network set-chain-context mainnet_local b11b369e0da5bb230b220127f5e7b242d385ef8c6f54906243f30af63c815535
Empty file.

0 comments on commit 5870157

Please sign in to comment.