mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-07-01 02:12:30 +00:00
447 add validatoraddress getter to config (#449)
* feat: add GetValidatorAddress() to config * feat: add GetDefaultValidatorRecord() to libConfig --------- Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
72df3de139
commit
2a5b7c49c8
@ -2,7 +2,12 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/planetmint/planetmint-go/lib"
|
||||||
|
"github.com/planetmint/planetmint-go/lib/trustwallet"
|
||||||
|
"github.com/rddl-network/go-utils/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultConfigTemplate = `
|
const DefaultConfigTemplate = `
|
||||||
@ -11,7 +16,6 @@ const DefaultConfigTemplate = `
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
[planetmint]
|
[planetmint]
|
||||||
validator-address = "{{ .PlmntConfig.ValidatorAddress }}"
|
|
||||||
mqtt-domain = "{{ .PlmntConfig.MqttDomain }}"
|
mqtt-domain = "{{ .PlmntConfig.MqttDomain }}"
|
||||||
mqtt-port = {{ .PlmntConfig.MqttPort }}
|
mqtt-port = {{ .PlmntConfig.MqttPort }}
|
||||||
mqtt-user = "{{ .PlmntConfig.MqttUser }}"
|
mqtt-user = "{{ .PlmntConfig.MqttUser }}"
|
||||||
@ -22,17 +26,19 @@ issuer-host = "{{ .PlmntConfig.IssuerHost }}"
|
|||||||
certs-path = "{{ .PlmntConfig.CertsPath }}"
|
certs-path = "{{ .PlmntConfig.CertsPath }}"
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// ValAddr to be reomved see: https://github.com/planetmint/planetmint-go/issues/454
|
||||||
|
const ValAddr = "VALIDATOR_ADDRESS"
|
||||||
|
|
||||||
// Config defines Planetmint's top level configuration
|
// Config defines Planetmint's top level configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ValidatorAddress string `json:"validator-address" mapstructure:"validator-address"`
|
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cosmos-sdk wide global singleton
|
// cosmos-sdk wide global singleton
|
||||||
@ -44,15 +50,14 @@ var (
|
|||||||
// DefaultConfig returns planetmint's default configuration.
|
// DefaultConfig returns planetmint's default configuration.
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
ValidatorAddress: "plmnt1w5dww335zhh98pzv783hqre355ck3u4w4hjxcx",
|
MqttDomain: "testnet-mqtt.rddl.io",
|
||||||
MqttDomain: "testnet-mqtt.rddl.io",
|
MqttPort: 1886,
|
||||||
MqttPort: 1886,
|
MqttUser: "user",
|
||||||
MqttUser: "user",
|
MqttPassword: "password",
|
||||||
MqttPassword: "password",
|
ClaimHost: "https://testnet-p2r.rddl.io",
|
||||||
ClaimHost: "https://testnet-p2r.rddl.io",
|
MqttTLS: true,
|
||||||
MqttTLS: true,
|
IssuerHost: "https://testnet-issuer.rddl.io",
|
||||||
IssuerHost: "https://testnet-issuer.rddl.io",
|
CertsPath: "./certs/",
|
||||||
CertsPath: "./certs/",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,3 +80,43 @@ func (config *Config) SetPlanetmintConfig(planetmintconfig interface{}) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (config *Config) GetValidatorAddress() string {
|
||||||
|
// Case: testing
|
||||||
|
if os.Getenv(ValAddr) != "" {
|
||||||
|
return os.Getenv(ValAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
libConfig := lib.GetConfig()
|
||||||
|
|
||||||
|
// Case: No Trust Wallet connected
|
||||||
|
if libConfig.GetSerialPort() == "" {
|
||||||
|
defaultRecord, err := libConfig.GetDefaultValidatorRecord()
|
||||||
|
if err != nil {
|
||||||
|
logger.GetLogger(logger.ERROR).Error("msg", err.Error())
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
addr, err := defaultRecord.GetAddress()
|
||||||
|
if err != nil {
|
||||||
|
logger.GetLogger(logger.ERROR).Error("msg", err.Error())
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return addr.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Case: Trust Wallet connected
|
||||||
|
connector, err := trustwallet.NewTrustWalletConnector(libConfig.GetSerialPort())
|
||||||
|
if err != nil {
|
||||||
|
logger.GetLogger(logger.ERROR).Error("msg", err.Error())
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
keys, err := connector.GetPlanetmintKeys()
|
||||||
|
if err != nil {
|
||||||
|
logger.GetLogger(logger.ERROR).Error("msg", err.Error())
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys.PlanetmintAddress
|
||||||
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package lib
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/planetmint/planetmint-go/lib/params"
|
"github.com/planetmint/planetmint-go/lib/params"
|
||||||
)
|
)
|
||||||
@ -125,3 +127,25 @@ func (config *Config) SetSerialPort(port string) *Config {
|
|||||||
config.serialPort = port
|
config.serialPort = port
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (config *Config) GetSerialPort() string {
|
||||||
|
return config.serialPort
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config *Config) getLibKeyring() (keyring.Keyring, error) {
|
||||||
|
return keyring.New("lib", keyring.BackendTest, config.rootDir, os.Stdin, config.encodingConfig.Marshaler, []keyring.Option{}...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config *Config) GetDefaultValidatorRecord() (*keyring.Record, error) {
|
||||||
|
keyring, err := config.getLibKeyring()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
records, err := keyring.List()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return records[0], nil
|
||||||
|
}
|
||||||
|
@ -96,7 +96,7 @@ func getClientContext(fromAddress sdk.AccAddress) (clientCtx client.Context, err
|
|||||||
codec := encodingConfig.Marshaler
|
codec := encodingConfig.Marshaler
|
||||||
keyringOptions := []keyring.Option{}
|
keyringOptions := []keyring.Option{}
|
||||||
|
|
||||||
keyring, err := keyring.New("lib", keyring.BackendTest, rootDir, input, codec, keyringOptions...)
|
keyring, err := GetConfig().getLibKeyring()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (mms *MqttMonitor) setNumDBElements(numElements int64) {
|
|||||||
|
|
||||||
func getClientID() string {
|
func getClientID() string {
|
||||||
conf := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
return "monitor-" + conf.ValidatorAddress
|
return "monitor-" + conf.GetValidatorAddress()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mms *MqttMonitor) lazyLoadMonitorMQTTClient() util.MQTTClientI {
|
func (mms *MqttMonitor) lazyLoadMonitorMQTTClient() util.MQTTClientI {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package monitor_test
|
package monitor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
// Use MQTT mock client
|
// Use MQTT mock client
|
||||||
monitor.MonitorMQTTClient = &mocks.MockMQTTClient{}
|
monitor.MonitorMQTTClient = &mocks.MockMQTTClient{}
|
||||||
|
os.Setenv(config.ValAddr, "plmnt10mq5nj8jhh27z7ejnz2ql3nh0qhzjnfvy50877")
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -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.ValidatorAddress = 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"
|
||||||
|
@ -51,7 +51,7 @@ func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingV
|
|||||||
|
|
||||||
func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64,
|
func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64,
|
||||||
firstIncludedPop int64, lastIncludedPop int64) {
|
firstIncludedPop int64, lastIncludedPop int64) {
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
|
||||||
msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight,
|
msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight,
|
||||||
firstIncludedPop, lastIncludedPop)
|
firstIncludedPop, lastIncludedPop)
|
||||||
loggingContext := "reissuance proposal"
|
loggingContext := "reissuance proposal"
|
||||||
@ -59,14 +59,14 @@ func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigne
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SendReissuanceResult(goCtx context.Context, proposerAddress string, txID string, blockHeight int64) {
|
func SendReissuanceResult(goCtx context.Context, proposerAddress string, txID string, blockHeight int64) {
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
|
||||||
msg := daotypes.NewMsgReissueRDDLResult(sendingValidatorAddress, proposerAddress, txID, blockHeight)
|
msg := daotypes.NewMsgReissueRDDLResult(sendingValidatorAddress, proposerAddress, txID, blockHeight)
|
||||||
loggingContext := "reissuance result"
|
loggingContext := "reissuance result"
|
||||||
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendDistributionRequest(goCtx context.Context, distribution daotypes.DistributionOrder) {
|
func SendDistributionRequest(goCtx context.Context, distribution daotypes.DistributionOrder) {
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
|
||||||
msg := daotypes.NewMsgDistributionRequest(sendingValidatorAddress, &distribution)
|
msg := daotypes.NewMsgDistributionRequest(sendingValidatorAddress, &distribution)
|
||||||
loggingContext := "distribution request"
|
loggingContext := "distribution request"
|
||||||
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
||||||
@ -74,35 +74,35 @@ func SendDistributionRequest(goCtx context.Context, distribution daotypes.Distri
|
|||||||
|
|
||||||
func SendDistributionResult(goCtx context.Context, lastPoP int64, daoTxID string, invTxID string,
|
func SendDistributionResult(goCtx context.Context, lastPoP int64, daoTxID string, invTxID string,
|
||||||
popTxID string, earlyInvestorTxID string, strategicTxID string) {
|
popTxID string, earlyInvestorTxID string, strategicTxID string) {
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
|
||||||
msg := daotypes.NewMsgDistributionResult(sendingValidatorAddress, lastPoP, daoTxID, invTxID, popTxID, earlyInvestorTxID, strategicTxID)
|
msg := daotypes.NewMsgDistributionResult(sendingValidatorAddress, lastPoP, daoTxID, invTxID, popTxID, earlyInvestorTxID, strategicTxID)
|
||||||
loggingContext := "distribution result"
|
loggingContext := "distribution result"
|
||||||
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendLiquidAssetRegistration(goCtx context.Context, notarizedAsset machinetypes.LiquidAsset) {
|
func SendLiquidAssetRegistration(goCtx context.Context, notarizedAsset machinetypes.LiquidAsset) {
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
|
||||||
msg := machinetypes.NewMsgNotarizeLiquidAsset(sendingValidatorAddress, ¬arizedAsset)
|
msg := machinetypes.NewMsgNotarizeLiquidAsset(sendingValidatorAddress, ¬arizedAsset)
|
||||||
loggingContext := "notarize liquid asset"
|
loggingContext := "notarize liquid asset"
|
||||||
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendInitPoP(goCtx context.Context, challenger string, challengee string, blockHeight int64) {
|
func SendInitPoP(goCtx context.Context, challenger string, challengee string, blockHeight int64) {
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
|
||||||
msg := daotypes.NewMsgInitPop(sendingValidatorAddress, sendingValidatorAddress, challenger, challengee, blockHeight)
|
msg := daotypes.NewMsgInitPop(sendingValidatorAddress, sendingValidatorAddress, challenger, challengee, blockHeight)
|
||||||
loggingContext := "PoP"
|
loggingContext := "PoP"
|
||||||
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendUpdateRedeemClaim(goCtx context.Context, beneficiary string, id uint64, txID string) {
|
func SendUpdateRedeemClaim(goCtx context.Context, beneficiary string, id uint64, txID string) {
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
|
||||||
msg := daotypes.NewMsgUpdateRedeemClaim(sendingValidatorAddress, beneficiary, txID, id)
|
msg := daotypes.NewMsgUpdateRedeemClaim(sendingValidatorAddress, beneficiary, txID, id)
|
||||||
loggingContext := "redeem claim"
|
loggingContext := "redeem claim"
|
||||||
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendTokens(goCtx context.Context, beneficiary sdk.AccAddress, amount uint64, denominator string) {
|
func SendTokens(goCtx context.Context, beneficiary sdk.AccAddress, amount uint64, denominator string) {
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
|
||||||
|
|
||||||
coin := sdk.NewCoin(denominator, sdk.NewIntFromUint64(amount))
|
coin := sdk.NewCoin(denominator, sdk.NewIntFromUint64(amount))
|
||||||
coins := sdk.NewCoins(coin)
|
coins := sdk.NewCoins(coin)
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/planetmint/planetmint-go/clients"
|
"github.com/planetmint/planetmint-go/clients"
|
||||||
|
"github.com/planetmint/planetmint-go/config"
|
||||||
"github.com/planetmint/planetmint-go/testutil/keeper"
|
"github.com/planetmint/planetmint-go/testutil/keeper"
|
||||||
clientmocks "github.com/planetmint/planetmint-go/testutil/mocks"
|
clientmocks "github.com/planetmint/planetmint-go/testutil/mocks"
|
||||||
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||||
@ -50,6 +51,7 @@ func TestRegisterNFT(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMachineNFTIssuance(t *testing.T) {
|
func TestMachineNFTIssuance(t *testing.T) {
|
||||||
|
t.Setenv(config.ValAddr, "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)
|
||||||
|
@ -49,7 +49,7 @@ func LazyLoadMQTTClient() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
opts := mqtt.NewClientOptions().AddBroker(uri)
|
opts := mqtt.NewClientOptions().AddBroker(uri)
|
||||||
opts.SetClientID(conf.ValidatorAddress)
|
opts.SetClientID(conf.GetValidatorAddress())
|
||||||
opts.SetUsername(conf.MqttUser)
|
opts.SetUsername(conf.MqttUser)
|
||||||
opts.SetPassword(conf.MqttPassword)
|
opts.SetPassword(conf.MqttPassword)
|
||||||
if conf.MqttTLS {
|
if conf.MqttTLS {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user