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) } diff --git a/docs/paratime.md b/docs/paratime.md index cdfc9b2e..02fbc88c 100644 --- a/docs/paratime.md +++ b/docs/paratime.md @@ -140,6 +140,13 @@ encrypted: ![code](../examples/paratime-show/show-tx-encrypted.out.static) +## Add denominations {#denom-add} + +To add denomination on the specific network and paratime use +`paratime denom add `. + +![code shell](../examples/paratime-denom/00-denom-add.in) + ## Advanced ### Register a New ParaTime {#register} diff --git a/examples/paratime-denom/00-denom-add.in b/examples/paratime-denom/00-denom-add.in new file mode 100644 index 00000000..8162f2a7 --- /dev/null +++ b/examples/paratime-denom/00-denom-add.in @@ -0,0 +1 @@ +oasis paratime denom add mainnet sapphire TEST 16 diff --git a/examples/paratime-denom/00-denom-add.out b/examples/paratime-denom/00-denom-add.out new file mode 100644 index 00000000..e69de29b