planetmint-go/config/config.go
Julian Strobl 1383d0aaa6
Add extended public key as IssuerPlanetmint (#62)
* Fix package and domain name

Signed-off-by: Julian Strobl <jmastr@mailbox.org>

* Add extended public key as `IssuerPlanetmint`

This patch introduces parts of the `chaincfg` for Planetmint and
especially the magic bytes that produces extended keys with the prefix
`pmpr` for a Planetmint extended private key and `pmpb` for a Planetmint
extended public key.

// Closes https://github.com/rddl-network/issues/issues/30

Signed-off-by: Julian Strobl <jmastr@mailbox.org>

* Validate Planetmint extended public key during machine attestation

Signed-off-by: Julian Strobl <jmastr@mailbox.org>

* [lint] Fix error return value is not checked

Signed-off-by: Julian Strobl <jmastr@mailbox.org>

---------

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
2023-08-11 09:14:52 +02:00

60 lines
1.5 KiB
Go

package config
import (
"encoding/json"
"sync"
)
const DefaultConfigTemplate = `
###############################################################################
### Planetmint ###
###############################################################################
[planetmint]
osc-service-port = {{ .PlmntConfig.OSCServicePort }}
watchmen-endpoint = "{{ .PlmntConfig.WatchmenEndpoint }}"
watchmen-port = {{ .PlmntConfig.WatchmenPort }}
`
// Config defines Planetmint's top level configuration
type Config struct {
OSCServicePort int `mapstructure:"osc-service-port" json:"osc-service-port"`
WatchmenEndpoint string `mapstructure:"watchmen-endpoint" json:"watchmen-endpoint"`
WatchmenPort int `mapstructure:"watchmen-port" json:"watchmen-port"`
}
// cosmos-sdk wide global singleton
var (
plmntConfig *Config
initConfig sync.Once
)
// DefaultConfig returns planetmint's default configuration.
func DefaultConfig() *Config {
return &Config{
OSCServicePort: 8766,
WatchmenEndpoint: "lab.r3c.network",
WatchmenPort: 7401,
}
}
// GetConfig returns the config instance for the SDK.
func GetConfig() *Config {
initConfig.Do(func() {
plmntConfig = DefaultConfig()
})
return plmntConfig
}
// SetWatchmenConfig sets Planetmint's configuration
func (config *Config) SetPlanetmintConfig(planetmintconfig interface{}) {
jsonConfig, err := json.Marshal(planetmintconfig)
if err != nil {
panic(err)
}
err = json.Unmarshal(jsonConfig, &config)
if err != nil {
panic(err)
}
}