From 86fdfffe7e9f42cf03a7694c0a5a31d9e4edc9f2 Mon Sep 17 00:00:00 2001 From: Pablo Deymonnaz Date: Mon, 11 Nov 2024 18:03:38 -0300 Subject: [PATCH] Read config fixed --- cli/actions/deposit_into_strategy.go | 3 ++- cli/actions/print_operator_status.go | 3 ++- cli/actions/register_operator_with_avs.go | 3 ++- .../register_operator_with_eigenlayer.go | 3 ++- {cli/actions => common}/read_config.go | 17 ++++++++++++++++- core/config/config.go | 6 ++++-- operator/cmd/main.go | 6 +++--- plugin/cmd/main.go | 5 +++-- tests/integration/integration_test.go | 8 +++++--- 9 files changed, 39 insertions(+), 15 deletions(-) rename {cli/actions => common}/read_config.go (67%) diff --git a/cli/actions/deposit_into_strategy.go b/cli/actions/deposit_into_strategy.go index 06a2235f..94f64bf8 100644 --- a/cli/actions/deposit_into_strategy.go +++ b/cli/actions/deposit_into_strategy.go @@ -6,6 +6,7 @@ import ( "log" "math/big" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" "github.com/Layr-Labs/incredible-squaring-avs/types" @@ -17,7 +18,7 @@ func DepositIntoStrategy(ctx *cli.Context) error { configPath := ctx.GlobalString(config.ConfigFileFlag.Name) nodeConfig := types.NodeConfig{} - err := ReadYamlConfig(configPath, &nodeConfig) + err := commonincredible.ReadYamlConfig(configPath, &nodeConfig) if err != nil { return err } diff --git a/cli/actions/print_operator_status.go b/cli/actions/print_operator_status.go index e40e98c3..36648170 100644 --- a/cli/actions/print_operator_status.go +++ b/cli/actions/print_operator_status.go @@ -4,6 +4,7 @@ import ( "encoding/json" "log" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" "github.com/Layr-Labs/incredible-squaring-avs/types" @@ -14,7 +15,7 @@ func PrintOperatorStatus(ctx *cli.Context) error { configPath := ctx.GlobalString(config.ConfigFileFlag.Name) nodeConfig := types.NodeConfig{} - err := ReadYamlConfig(configPath, &nodeConfig) + err := commonincredible.ReadYamlConfig(configPath, &nodeConfig) if err != nil { return err } diff --git a/cli/actions/register_operator_with_avs.go b/cli/actions/register_operator_with_avs.go index 8f8e14dd..dfea077b 100644 --- a/cli/actions/register_operator_with_avs.go +++ b/cli/actions/register_operator_with_avs.go @@ -6,6 +6,7 @@ import ( "os" sdkecdsa "github.com/Layr-Labs/eigensdk-go/crypto/ecdsa" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" "github.com/Layr-Labs/incredible-squaring-avs/types" @@ -16,7 +17,7 @@ func RegisterOperatorWithAvs(ctx *cli.Context) error { configPath := ctx.GlobalString(config.ConfigFileFlag.Name) nodeConfig := types.NodeConfig{} - err := ReadYamlConfig(configPath, &nodeConfig) + err := commonincredible.ReadYamlConfig(configPath, &nodeConfig) if err != nil { return err } diff --git a/cli/actions/register_operator_with_eigenlayer.go b/cli/actions/register_operator_with_eigenlayer.go index 12bda8c3..786c440b 100644 --- a/cli/actions/register_operator_with_eigenlayer.go +++ b/cli/actions/register_operator_with_eigenlayer.go @@ -6,6 +6,7 @@ import ( "github.com/urfave/cli" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" "github.com/Layr-Labs/incredible-squaring-avs/types" @@ -15,7 +16,7 @@ func RegisterOperatorWithEigenlayer(ctx *cli.Context) error { configPath := ctx.GlobalString(config.ConfigFileFlag.Name) nodeConfig := types.NodeConfig{} - err := ReadYamlConfig(configPath, &nodeConfig) + err := commonincredible.ReadYamlConfig(configPath, &nodeConfig) if err != nil { return err } diff --git a/cli/actions/read_config.go b/common/read_config.go similarity index 67% rename from cli/actions/read_config.go rename to common/read_config.go index b01f2455..a7e2cfd7 100644 --- a/cli/actions/read_config.go +++ b/common/read_config.go @@ -1,6 +1,7 @@ -package actions +package common import ( + "encoding/json" "errors" "log" "os" @@ -33,3 +34,17 @@ func ReadFile(path string) ([]byte, error) { } return b, nil } + +func ReadJsonConfig(path string, o interface{}) error { + b, err := ReadFile(path) + if err != nil { + return err + } + + err = json.Unmarshal(b, o) + if err != nil { + log.Fatalf("unable to parse file with error %#v", err) + } + + return nil +} diff --git a/core/config/config.go b/core/config/config.go index 56058a2d..565ea042 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -10,6 +10,8 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/urfave/cli" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" + "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet" "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" "github.com/Layr-Labs/eigensdk-go/crypto/bls" @@ -69,7 +71,7 @@ func NewConfig(ctx *cli.Context) (*Config, error) { var configRaw ConfigRaw configFilePath := ctx.GlobalString(ConfigFileFlag.Name) if configFilePath != "" { - sdkutils.ReadYamlConfig(configFilePath, &configRaw) + commonincredible.ReadYamlConfig(configFilePath, &configRaw) } var credibleSquaringDeploymentRaw IncredibleSquaringDeploymentRaw @@ -77,7 +79,7 @@ func NewConfig(ctx *cli.Context) (*Config, error) { if _, err := os.Stat(credibleSquaringDeploymentFilePath); errors.Is(err, os.ErrNotExist) { panic("Path " + credibleSquaringDeploymentFilePath + " does not exist") } - sdkutils.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw) + commonincredible.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw) logger, err := sdklogging.NewZapLogger(configRaw.Environment) if err != nil { diff --git a/operator/cmd/main.go b/operator/cmd/main.go index d033bfa2..2af0a7b4 100644 --- a/operator/cmd/main.go +++ b/operator/cmd/main.go @@ -8,11 +8,11 @@ import ( "github.com/urfave/cli" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" + "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" "github.com/Layr-Labs/incredible-squaring-avs/types" - - sdkutils "github.com/Layr-Labs/eigensdk-go/utils" ) func main() { @@ -34,7 +34,7 @@ func operatorMain(ctx *cli.Context) error { log.Println("Initializing Operator") configPath := ctx.GlobalString(config.ConfigFileFlag.Name) nodeConfig := types.NodeConfig{} - err := sdkutils.ReadYamlConfig(configPath, &nodeConfig) + err := commonincredible.ReadYamlConfig(configPath, &nodeConfig) if err != nil { return err } diff --git a/plugin/cmd/main.go b/plugin/cmd/main.go index f441ed7d..1cc9bafa 100644 --- a/plugin/cmd/main.go +++ b/plugin/cmd/main.go @@ -8,6 +8,8 @@ import ( "os" "time" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" + sdkclients "github.com/Layr-Labs/eigensdk-go/chainio/clients" "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet" "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" @@ -17,7 +19,6 @@ import ( "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/signerv2" sdktypes "github.com/Layr-Labs/eigensdk-go/types" - "github.com/Layr-Labs/eigensdk-go/utils" "github.com/Layr-Labs/incredible-squaring-avs/core/chainio" "github.com/Layr-Labs/incredible-squaring-avs/types" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -86,7 +87,7 @@ func plugin(ctx *cli.Context) { configPath := ctx.GlobalString(ConfigFileFlag.Name) avsConfig := types.NodeConfig{} - err := utils.ReadYamlConfig(configPath, &avsConfig) + err := commonincredible.ReadYamlConfig(configPath, &avsConfig) if err != nil { fmt.Println(err) return diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 7f22fa3e..4aad7e82 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -10,6 +10,8 @@ import ( "testing" "time" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" + "github.com/Layr-Labs/eigensdk-go/chainio/clients" "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet" "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" @@ -48,13 +50,13 @@ func TestIntegration(t *testing.T) { /* Prepare the config file for aggregator */ var aggConfigRaw config.ConfigRaw aggConfigFilePath := "../../config-files/aggregator.yaml" - sdkutils.ReadYamlConfig(aggConfigFilePath, &aggConfigRaw) + commonincredible.ReadYamlConfig(aggConfigFilePath, &aggConfigRaw) aggConfigRaw.EthRpcUrl = "http://" + anvilEndpoint aggConfigRaw.EthWsUrl = "ws://" + anvilEndpoint var credibleSquaringDeploymentRaw config.IncredibleSquaringDeploymentRaw credibleSquaringDeploymentFilePath := "../../contracts/script/output/31337/credible_squaring_avs_deployment_output.json" - sdkutils.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw) + commonincredible.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw) logger, err := sdklogging.NewZapLogger(aggConfigRaw.Environment) if err != nil { @@ -115,7 +117,7 @@ func TestIntegration(t *testing.T) { /* Prepare the config file for operator */ nodeConfig := types.NodeConfig{} nodeConfigFilePath := "../../config-files/operator.anvil.yaml" - err = sdkutils.ReadYamlConfig(nodeConfigFilePath, &nodeConfig) + err = commonincredible.ReadYamlConfig(nodeConfigFilePath, &nodeConfig) if err != nil { t.Fatalf("Failed to read yaml config: %s", err.Error()) }