Skip to content

Commit

Permalink
Read config fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodeymo committed Nov 11, 2024
1 parent ac30630 commit 86fdfff
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 15 deletions.
3 changes: 2 additions & 1 deletion cli/actions/deposit_into_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion cli/actions/print_operator_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion cli/actions/register_operator_with_avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion cli/actions/register_operator_with_eigenlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
17 changes: 16 additions & 1 deletion cli/actions/read_config.go → common/read_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package actions
package common

import (
"encoding/json"
"errors"
"log"
"os"
Expand Down Expand Up @@ -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
}
6 changes: 4 additions & 2 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -69,15 +71,15 @@ 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
credibleSquaringDeploymentFilePath := ctx.GlobalString(CredibleSquaringDeploymentFileFlag.Name)
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 {
Expand Down
6 changes: 3 additions & 3 deletions operator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions plugin/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit 86fdfff

Please sign in to comment.