mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 14:35:47 +00:00
feat: add SetValidatorAddress() and GetValidatorAddress() to config
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
dacd261df4
commit
18dd943f38
@ -3,6 +3,10 @@ package config
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"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 +15,7 @@ const DefaultConfigTemplate = `
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
[planetmint]
|
[planetmint]
|
||||||
validator-address = "{{ .PlmntConfig.ValidatorAddress }}"
|
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 }}"
|
||||||
@ -24,7 +28,6 @@ certs-path = "{{ .PlmntConfig.CertsPath }}"
|
|||||||
|
|
||||||
// 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"`
|
||||||
@ -33,6 +36,7 @@ type Config struct {
|
|||||||
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 `json:"validator-address" mapstructure:"validator-address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// cosmos-sdk wide global singleton
|
// cosmos-sdk wide global singleton
|
||||||
@ -44,7 +48,6 @@ 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",
|
||||||
@ -53,6 +56,7 @@ func DefaultConfig() *Config {
|
|||||||
MqttTLS: true,
|
MqttTLS: true,
|
||||||
IssuerHost: "https://testnet-issuer.rddl.io",
|
IssuerHost: "https://testnet-issuer.rddl.io",
|
||||||
CertsPath: "./certs/",
|
CertsPath: "./certs/",
|
||||||
|
validatorAddress: "plmnt1w5dww335zhh98pzv783hqre355ck3u4w4hjxcx",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,3 +79,29 @@ func (config *Config) SetPlanetmintConfig(planetmintconfig interface{}) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (config *Config) SetValidatorAddress(validatorAddress string) *Config {
|
||||||
|
config.validatorAddress = validatorAddress
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config *Config) GetValidatorAddress() string {
|
||||||
|
libConfig := lib.GetConfig()
|
||||||
|
if libConfig.GetSerialPort() == "" {
|
||||||
|
return config.validatorAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -125,3 +125,7 @@ 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
|
||||||
|
}
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -596,7 +596,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()
|
conf := config.GetConfig()
|
||||||
conf.ValidatorAddress = 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"
|
||||||
|
|||||||
@ -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, proposer string, challenger string, challengee string, blockHeight int64) {
|
func SendInitPoP(goCtx context.Context, proposer string, challenger string, challengee string, blockHeight int64) {
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
|
||||||
msg := daotypes.NewMsgInitPop(sendingValidatorAddress, proposer, challenger, challengee, blockHeight)
|
msg := daotypes.NewMsgInitPop(sendingValidatorAddress, proposer, 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)
|
||||||
|
|||||||
@ -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