-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from oasisprotocol/amela/feat/add-cmd-oasis-p…
…aratime-denom feat(cmd/paratime/denom): Add cmd denomination `set`, `set-native` and `remove`
- Loading branch information
Showing
12 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package denomination | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "denomination", | ||
Short: "Denomination operations", | ||
Aliases: []string{"denom"}, | ||
} | ||
|
||
func init() { | ||
Cmd.AddCommand(setDenomCmd) | ||
Cmd.AddCommand(setNativeDenomCmd) | ||
Cmd.AddCommand(removeDenomCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package denomination | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/config" | ||
|
||
cliConfig "github.com/oasisprotocol/cli/config" | ||
) | ||
|
||
var removeDenomCmd = &cobra.Command{ | ||
Use: "remove <network> <paratime> <denomination>", | ||
Short: "Remove denomination", | ||
Args: cobra.ExactArgs(3), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cfg := cliConfig.Global() | ||
networkArg, ptArg, denomArg := args[0], args[1], args[2] | ||
|
||
if denomArg == config.NativeDenominationKey { | ||
cobra.CheckErr(fmt.Errorf("you cannot delete native denomination")) | ||
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 | ||
} | ||
|
||
denomArg = strings.ToLower(denomArg) | ||
_, ok := pt.Denominations[denomArg] | ||
if ok { | ||
delete(pt.Denominations, denomArg) | ||
} else { | ||
cobra.CheckErr(fmt.Errorf("denomination '%s' does not exist", denomArg)) | ||
return | ||
} | ||
|
||
err := cfg.Save() | ||
cobra.CheckErr(err) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package denomination | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/config" | ||
|
||
cliConfig "github.com/oasisprotocol/cli/config" | ||
) | ||
|
||
var setNativeDenomCmd = &cobra.Command{ | ||
Use: "set-native <network> <paratime> <symbol> <number_of_decimals>", | ||
Short: "Set native 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' cannot 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[config.NativeDenominationKey] = denomInfo | ||
|
||
err = cfg.Save() | ||
cobra.CheckErr(err) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package denomination | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/spf13/cobra" | ||
flag "github.com/spf13/pflag" | ||
|
||
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/config" | ||
|
||
cliConfig "github.com/oasisprotocol/cli/config" | ||
) | ||
|
||
var ( | ||
symbol string | ||
|
||
setDenomCmd = &cobra.Command{ | ||
Use: "set <network> <paratime> <denomination> <number_of_decimals> [--symbol <symbol>]", | ||
Short: "Set denomination", | ||
Args: cobra.ExactArgs(4), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cfg := cliConfig.Global() | ||
networkArg, ptArg, denomArg, decimalsArg := args[0], args[1], args[2], args[3] | ||
|
||
if symbol == "" { | ||
symbol = denomArg | ||
} | ||
|
||
decimalsInt, err := strconv.Atoi(decimalsArg) | ||
if err != nil { | ||
cobra.CheckErr(fmt.Errorf("number of decimals '%s' cannot 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: symbol, | ||
Decimals: uint8(decimalsInt), | ||
} | ||
pt.Denominations[denomArg] = denomInfo | ||
|
||
err = cfg.Save() | ||
cobra.CheckErr(err) | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
symbolFlag := flag.NewFlagSet("", flag.ContinueOnError) | ||
symbolFlag.StringVar(&symbol, "symbol", "", "Denomination symbol") | ||
setDenomCmd.Flags().AddFlagSet(symbolFlag) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
oasis paratime denom set mainnet sapphire TESTTEST 16 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
oasis paratime denom set-native testnet cipher TEST 9 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
oasis paratime denom remove mainnet sapphire TESTTEST |
Empty file.