Skip to content

Commit

Permalink
feat(cmd/paratime/denom): Add cmd denomination add
Browse files Browse the repository at this point in the history
  • Loading branch information
amela committed May 22, 2024
1 parent b1a4a4b commit 233ecf7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cmd/paratime/denom/add.go
Original file line number Diff line number Diff line change
@@ -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 <network> <paratime> <denomination> <number_of_decimals>",
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)
},
}
15 changes: 15 additions & 0 deletions cmd/paratime/denom/denom.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 3 additions & 0 deletions cmd/paratime/paratime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package paratime

import (
"github.com/spf13/cobra"

"github.com/oasisprotocol/cli/cmd/paratime/denom"
)

var Cmd = &cobra.Command{
Expand All @@ -18,4 +20,5 @@ func init() {
Cmd.AddCommand(setDefaultCmd)
Cmd.AddCommand(showCmd)
Cmd.AddCommand(statsCmd)
Cmd.AddCommand(denom.Cmd)
}
7 changes: 7 additions & 0 deletions docs/paratime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <network> <paratime> <denomination> <number_of_decimals>`.

![code shell](../examples/paratime-denom/00-denom-add.in)

## Advanced

### Register a New ParaTime {#register}
Expand Down
1 change: 1 addition & 0 deletions examples/paratime-denom/00-denom-add.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oasis paratime denom add mainnet sapphire TEST 16
Empty file.

0 comments on commit 233ecf7

Please sign in to comment.