feat: changed from SetValidatorAddress to env var

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2024-09-30 10:44:40 +02:00
parent 73e48c4ed7
commit 3c879b1610
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
3 changed files with 17 additions and 21 deletions

View File

@ -2,6 +2,7 @@ package config
import ( import (
"encoding/json" "encoding/json"
"os"
"sync" "sync"
"github.com/planetmint/planetmint-go/lib" "github.com/planetmint/planetmint-go/lib"
@ -25,17 +26,18 @@ issuer-host = "{{ .PlmntConfig.IssuerHost }}"
certs-path = "{{ .PlmntConfig.CertsPath }}" certs-path = "{{ .PlmntConfig.CertsPath }}"
` `
const ValAddr = "VALIDATOR_ADDRESS"
// Config defines Planetmint's top level configuration // Config defines Planetmint's top level configuration
type Config struct { type Config struct {
MqttDomain string `json:"mqtt-domain" mapstructure:"mqtt-domain"` MqttDomain string `json:"mqtt-domain" mapstructure:"mqtt-domain"`
MqttPort int `json:"mqtt-port" mapstructure:"mqtt-port"` MqttPort int `json:"mqtt-port" mapstructure:"mqtt-port"`
MqttUser string `json:"mqtt-user" mapstructure:"mqtt-user"` MqttUser string `json:"mqtt-user" mapstructure:"mqtt-user"`
MqttPassword string `json:"mqtt-password" mapstructure:"mqtt-password"` MqttPassword string `json:"mqtt-password" mapstructure:"mqtt-password"`
ClaimHost string `json:"claim-host" mapstructure:"claim-host"` ClaimHost string `json:"claim-host" mapstructure:"claim-host"`
MqttTLS bool `json:"mqtt-tls" mapstructure:"mqtt-tls"` MqttTLS bool `json:"mqtt-tls" mapstructure:"mqtt-tls"`
IssuerHost string `json:"issuer-host" mapstructure:"issuer-host"` IssuerHost string `json:"issuer-host" mapstructure:"issuer-host"`
CertsPath string `json:"certs-path" mapstructure:"certs-path"` CertsPath string `json:"certs-path" mapstructure:"certs-path"`
validatorAddress string
} }
// cosmos-sdk wide global singleton // cosmos-sdk wide global singleton
@ -78,17 +80,12 @@ func (config *Config) SetPlanetmintConfig(planetmintconfig interface{}) {
} }
} }
func (config *Config) SetValidatorAddress(validatorAddress string) *Config {
config.validatorAddress = validatorAddress
return config
}
func (config *Config) GetValidatorAddress() string { func (config *Config) GetValidatorAddress() string {
libConfig := lib.GetConfig() if os.Getenv(ValAddr) != "" {
if libConfig.GetSerialPort() == "" { return os.Getenv(ValAddr)
return config.validatorAddress
} }
libConfig := lib.GetConfig()
connector, err := trustwallet.NewTrustWalletConnector(libConfig.GetSerialPort()) connector, err := trustwallet.NewTrustWalletConnector(libConfig.GetSerialPort())
if err != nil { if err != nil {
logger.GetLogger(logger.ERROR).Error("msg", err.Error()) logger.GetLogger(logger.ERROR).Error("msg", err.Error())

View File

@ -595,8 +595,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
} }
l.Log("started validator", idx) l.Log("started validator", idx)
if idx == 0 { if idx == 0 {
conf := config.GetConfig() os.Setenv(config.ValAddr, network.Validators[0].Address.String())
conf.SetValidatorAddress(network.Validators[0].Address.String())
// set missing validator client context values for sending txs // set missing validator client context values for sending txs
var output bytes.Buffer var output bytes.Buffer
network.Validators[0].ClientCtx.BroadcastMode = "sync" network.Validators[0].ClientCtx.BroadcastMode = "sync"

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"math/rand" "math/rand"
"os"
"strconv" "strconv"
"sync" "sync"
"testing" "testing"
@ -51,8 +52,7 @@ func TestRegisterNFT(t *testing.T) {
} }
func TestMachineNFTIssuance(t *testing.T) { func TestMachineNFTIssuance(t *testing.T) {
cfg := config.GetConfig() os.Setenv(config.ValAddr, "plmnt10mq5nj8jhh27z7ejnz2ql3nh0qhzjnfvy50877")
cfg.SetValidatorAddress("plmnt10mq5nj8jhh27z7ejnz2ql3nh0qhzjnfvy50877")
ctrl := gomock.NewController(t) ctrl := gomock.NewController(t)
elements.Client = &elementsmocks.MockClient{} elements.Client = &elementsmocks.MockClient{}
shamirMock := clientmocks.NewMockIShamirCoordinatorClient(ctrl) shamirMock := clientmocks.NewMockIShamirCoordinatorClient(ctrl)