Skip to content

Commit

Permalink
use xdg
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkatn committed Jan 12, 2024
1 parent 5764da7 commit 7846c35
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 56 deletions.
9 changes: 2 additions & 7 deletions chain/kusama/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ package kusama

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

var (
// defaultName Default node name
defaultName = "Kusama"
// defaultID Default chain ID
defaultID = "ksmcc3"
// defaultBasePath Default node base directory path
defaultBasePath = "~/.gossamer/kusama"
defaultBasePath = xdg.DataHome + "/gossamer/kusama"
// defaultChainSpec is the default chain-spec json path
defaultChainSpec = "./chain/kusama/chain-spec-raw.json"
)
Expand All @@ -22,8 +19,6 @@ var (
func DefaultConfig() *cfg.Config {
config := cfg.DefaultConfig()
config.BasePath = defaultBasePath
config.ID = defaultID
config.Name = defaultName
config.ChainSpec = defaultChainSpec
config.Core.BabeAuthority = false
config.Core.GrandpaAuthority = false
Expand Down
9 changes: 2 additions & 7 deletions chain/paseo/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ package paseo

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

var (
// defaultName Default node name
defaultName = "Paseo"
// defaultID Default chain ID
defaultID = "paseo"
// defaultBasePath Default node base directory path
defaultBasePath = "~/.gossamer/paseo"
defaultBasePath = xdg.DataHome + "/gossamer/paseo"
// defaultChainSpec is the default chain spec configuration path
defaultChainSpec = "./chain/paseo/chain-spec-raw.json"
)
Expand All @@ -22,8 +19,6 @@ var (
func DefaultConfig() *cfg.Config {
config := cfg.DefaultConfig()
config.BasePath = defaultBasePath
config.ID = defaultID
config.Name = defaultName
config.ChainSpec = defaultChainSpec
config.Core.BabeAuthority = false
config.Core.GrandpaAuthority = false
Expand Down
9 changes: 2 additions & 7 deletions chain/polkadot/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ package polkadot

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

var (
// defaultName Default node name
defaultName = "Polkadot"
// defaultID Default chain ID
defaultID = "polkadot"
// defaultBasePath Default node base directory path
defaultBasePath = "~/.gossamer/polkadot"
defaultBasePath = xdg.DataHome + "/gossamer/polkadot"
// defaultChainSpec is the default chain spec configuration path
defaultChainSpec = "./chain/polkadot/chain-spec-raw.json"
)
Expand All @@ -22,8 +19,6 @@ var (
func DefaultConfig() *cfg.Config {
config := cfg.DefaultConfig()
config.BasePath = defaultBasePath
config.ID = defaultID
config.Name = defaultName
config.ChainSpec = defaultChainSpec
config.Core.BabeAuthority = false
config.Core.GrandpaAuthority = false
Expand Down
11 changes: 3 additions & 8 deletions chain/westend-dev/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ package westenddev

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

const (
// defaultName is the default node name
defaultName = "Westend"
// defaultID is the default node ID
defaultID = "westend_dev"
var (
// defaultBasePath is the default basepath for the westend dev node
defaultBasePath = "~/.gossamer/westend-dev"
defaultBasePath = xdg.DataHome + "/gossamer/westend-dev"
// defaultChainSpec is the default chain spec for the westend dev node
defaultChainSpec = "./chain/westend-dev/westend-dev-spec-raw.json"
)
Expand All @@ -22,8 +19,6 @@ const (
func DefaultConfig() *cfg.Config {
config := cfg.DefaultConfig()
config.BasePath = defaultBasePath
config.ID = defaultID
config.Name = defaultName
config.ChainSpec = defaultChainSpec
config.RPC.RPCExternal = true
config.RPC.UnsafeRPC = true
Expand Down
9 changes: 5 additions & 4 deletions chain/westend-local/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package westendlocal

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

const (
var (
// defaultName is the default node name
defaultName = "Westend"
// defaultID is the default node ID
Expand All @@ -16,11 +17,11 @@ const (
defaultChainSpec = "./chain/westend-local/westend-local-spec-raw.json"

// DefaultBasePathAlice is the default basepath for the westend local alice node
DefaultBasePathAlice = "~/.gossamer/westend-local-alice"
DefaultBasePathAlice = xdg.DataHome + "/gossamer/westend-local-alice"
// DefaultBasePathBob is the default basepath for the westend local bob node
DefaultBasePathBob = "~/.gossamer/westend-local-bob"
DefaultBasePathBob = xdg.DataHome + "/gossamer/westend-local-bob"
// DefaultBasePathCharlie is the default basepath for the westend local charlie node
DefaultBasePathCharlie = "~/.gossamer/westend-local-charlie"
DefaultBasePathCharlie = xdg.DataHome + "/gossamer/westend-local-charlie"
)

// DefaultConfig returns a westend local node configuration
Expand Down
9 changes: 2 additions & 7 deletions chain/westend/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ package westend

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

var (
// defaultName Default node name
defaultName = "Westend"
// defaultID Default chain ID
defaultID = "westend2"
// defaultBasePath Default node base directory path
defaultBasePath = "~/.gossamer/westend"
defaultBasePath = xdg.DataHome + "/gossamer/westend"
// defaultChainSpec is the default chain specification path
defaultChainSpec = "./chain/westend/chain-spec-raw.json"
)
Expand All @@ -22,8 +19,6 @@ var (
func DefaultConfig() *cfg.Config {
config := cfg.DefaultConfig()
config.BasePath = defaultBasePath
config.ID = defaultID
config.Name = defaultName
config.ChainSpec = defaultChainSpec
config.Core.BabeAuthority = false
config.Core.GrandpaAuthority = false
Expand Down
17 changes: 4 additions & 13 deletions cmd/gossamer/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
logLevel string

// Base Config
name string
id string
pruning string
telemetryURLs string

Expand Down Expand Up @@ -210,19 +212,8 @@ func addRootFlags(cmd *cobra.Command) error {

// addBaseConfigFlags adds the base config flags to the command
func addBaseConfigFlags(cmd *cobra.Command) error {
if err := addStringFlagBindViper(cmd,
"name",
config.BaseConfig.Name,
"Name of the node",
"Name of the node"); err != nil {
return fmt.Errorf("failed to add --name flag: %s", err)
}
if err := addStringFlagBindViper(cmd,
"id", config.BaseConfig.ID,
"Identifier for the node",
"id"); err != nil {
return fmt.Errorf("failed to add --id flag: %s", err)
}
cmd.Flags().StringVar(&name, "name", "", "Name of the node")
cmd.Flags().StringVar(&id, "id", "", "Identifier for the node")
if err := addBoolFlagBindViper(cmd,
"no-telemetry",
config.BaseConfig.NoTelemetry,
Expand Down
17 changes: 14 additions & 3 deletions cmd/gossamer/commands/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,25 @@ func parseChainSpec(chain string) error {
if err != nil {
return fmt.Errorf("failed to load chain spec: %s", err)
}

config.ID = spec.ID
config.Network.Bootnodes = spec.Bootnodes
config.Network.ProtocolID = spec.ProtocolID

parseIdentity()
return nil
}

// parseIdentity parses the node identity from the command line flags
func parseIdentity() {
if name != "" {
config.Name = name
viper.Set("name", name)
}

if id != "" {
config.ID = id
viper.Set("id", id)
}
}

// configureViper sets up viper to read from the config file and command line flags
func configureViper(basePath string) error {
viper.SetConfigName("config") // name of config file (without extension)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/ChainSafe/gossamer
require (
github.com/ChainSafe/go-schnorrkel v1.1.0
github.com/OneOfOne/xxhash v1.2.8
github.com/adrg/xdg v0.4.0
github.com/btcsuite/btcd/btcutil v1.1.5
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/centrifuge/go-substrate-rpc-client/v4 v4.1.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdII
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
Expand Down Expand Up @@ -870,6 +872,7 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down

0 comments on commit 7846c35

Please sign in to comment.