From 45481348c7b0195281a77e3ca7fd739925c7e1f8 Mon Sep 17 00:00:00 2001 From: amela Date: Mon, 20 May 2024 10:51:11 +0200 Subject: [PATCH] feat(cmd/paratime/denom): Add cmd denomination add --- cmd/paratime/denom/add.go | 49 +++++++++++++++++++++++++++++++++++++ cmd/paratime/denom/denom.go | 15 ++++++++++++ cmd/paratime/paratime.go | 3 +++ 3 files changed, 67 insertions(+) create mode 100644 cmd/paratime/denom/add.go create mode 100644 cmd/paratime/denom/denom.go diff --git a/cmd/paratime/denom/add.go b/cmd/paratime/denom/add.go new file mode 100644 index 00000000..feec299c --- /dev/null +++ b/cmd/paratime/denom/add.go @@ -0,0 +1,49 @@ +package denom + +import ( + "fmt" + "strconv" + + "github.com/spf13/cobra" + + "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config" + + cliConfig "github.com/oasisprotocol/cli/config" +) + +var addDenomCmd = &cobra.Command{ + Use: "add ", + Short: "Add a new denomination", + Args: cobra.ExactArgs(4), + Run: func(cmd *cobra.Command, args []string) { + cfg := cliConfig.Global() + networkArg, ptArg, symbolArg, decimalsArg := args[0], args[1], args[2], args[3] + + decimalsInt, err := strconv.Atoi(decimalsArg) + if err != nil { + cobra.CheckErr(fmt.Errorf("number of decimals '%s' can not be converted to integer", decimalsArg)) + return + } + + net := cfg.Networks.All[networkArg] + if net == nil { + cobra.CheckErr(fmt.Errorf("network '%s' does not exist", networkArg)) + return + } + + pt := net.ParaTimes.All[ptArg] + if pt == nil { + cobra.CheckErr(fmt.Errorf("pratime '%s' does not exist", ptArg)) + return + } + + denomInfo := &config.DenominationInfo{ + Symbol: symbolArg, + Decimals: uint8(decimalsInt), + } + pt.Denominations[symbolArg] = denomInfo + + err = cfg.Save() + cobra.CheckErr(err) + }, +} diff --git a/cmd/paratime/denom/denom.go b/cmd/paratime/denom/denom.go new file mode 100644 index 00000000..2374fb3f --- /dev/null +++ b/cmd/paratime/denom/denom.go @@ -0,0 +1,15 @@ +package denom + +import ( + "github.com/spf13/cobra" +) + +var Cmd = &cobra.Command{ + Use: "denom", + Short: "Denomination operations", + Aliases: []string{"denom"}, +} + +func init() { + Cmd.AddCommand(addDenomCmd) +} diff --git a/cmd/paratime/paratime.go b/cmd/paratime/paratime.go index 73c7f3ee..45b12f5c 100644 --- a/cmd/paratime/paratime.go +++ b/cmd/paratime/paratime.go @@ -2,6 +2,8 @@ package paratime import ( "github.com/spf13/cobra" + + "github.com/oasisprotocol/cli/cmd/paratime/denom" ) var Cmd = &cobra.Command{ @@ -18,4 +20,5 @@ func init() { Cmd.AddCommand(setDefaultCmd) Cmd.AddCommand(showCmd) Cmd.AddCommand(statsCmd) + Cmd.AddCommand(denom.Cmd) }