From 238e68808b21031f95c7fdb172bc129870b7e25a Mon Sep 17 00:00:00 2001 From: Lorenz Herzberger Date: Wed, 26 Jul 2023 15:44:07 +0200 Subject: [PATCH] add config for watchmen Signed-off-by: Lorenz Herzberger --- config/config.go | 26 +++++++++++++++++++ config/dev_config.json | 4 +++ config/prod_config.json | 4 +++ go.mod | 1 + go.sum | 2 ++ x/machine/keeper/msg_server_attest_machine.go | 8 +++--- 6 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 config/config.go create mode 100644 config/dev_config.json create mode 100644 config/prod_config.json diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..3ee3dc6 --- /dev/null +++ b/config/config.go @@ -0,0 +1,26 @@ +package app + +import ( + "fmt" + + "github.com/tkanos/gonfig" +) + +type Configuration struct { + WATCHMEN_ENDPOINT string + WATCHMEN_PORT uint32 +} + +func GetConfig(params ...string) Configuration { + configuration := Configuration{} + env := "dev" + + if len(params) > 0 { + env = params[0] + } + + filename := fmt.Sprintf("./%s_config.json", env) + gonfig.GetConf(filename, &configuration) + + return configuration +} diff --git a/config/dev_config.json b/config/dev_config.json new file mode 100644 index 0000000..eeb8ad0 --- /dev/null +++ b/config/dev_config.json @@ -0,0 +1,4 @@ +{ + "WATCHMEN_ENDPOINT": "localhost", + "WATCHMEN_PORT": 7401 +} \ No newline at end of file diff --git a/config/prod_config.json b/config/prod_config.json new file mode 100644 index 0000000..eeb8ad0 --- /dev/null +++ b/config/prod_config.json @@ -0,0 +1,4 @@ +{ + "WATCHMEN_ENDPOINT": "localhost", + "WATCHMEN_PORT": 7401 +} \ No newline at end of file diff --git a/go.mod b/go.mod index bcaba53..a7dff93 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.2 + github.com/tkanos/gonfig v0.0.0-20210106201359-53e13348de2f google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 google.golang.org/grpc v1.55.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 8af7b56..7626275 100644 --- a/go.sum +++ b/go.sum @@ -960,6 +960,8 @@ github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2l github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg= github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= +github.com/tkanos/gonfig v0.0.0-20210106201359-53e13348de2f h1:xDFq4NVQD34ekH5UsedBSgfxsBuPU2aZf7v4t0tH2jY= +github.com/tkanos/gonfig v0.0.0-20210106201359-53e13348de2f/go.mod h1:DaZPBuToMc2eezA9R9nDAnmS2RMwL7yEa5YD36ESQdI= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= diff --git a/x/machine/keeper/msg_server_attest_machine.go b/x/machine/keeper/msg_server_attest_machine.go index 92190d6..2d44b94 100644 --- a/x/machine/keeper/msg_server_attest_machine.go +++ b/x/machine/keeper/msg_server_attest_machine.go @@ -4,6 +4,7 @@ import ( "context" "errors" + config "planetmint-go/config" "planetmint-go/x/machine/types" "github.com/btcsuite/btcd/btcutil/hdkeychain" @@ -22,7 +23,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach } if msg.Machine.Reissue { - err := k.reissueMachineNFT(msg.Machine) + err := k.reissueMachine(msg.Machine) if err != nil { return nil, errors.New("an error occured while reissuning the machine") } @@ -43,8 +44,9 @@ func validateIssuerLiquid(issuerLiquid string) bool { return isValidLiquidKey } -func (k msgServer) reissueMachineNFT(machine *types.Machine) error { - client := osc.NewClient("localhost", 8765) +func (k msgServer) reissueMachine(machine *types.Machine) error { + conf := config.GetConfig() + client := osc.NewClient(conf.WATCHMEN_ENDPOINT, int(conf.WATCHMEN_PORT)) msg := osc.NewMessage("/rddl/*") msg.Append(machine.Name) msg.Append(machine.Ticker)