Skip to content

Commit

Permalink
fix: convert height to int
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs committed Aug 13, 2024
1 parent bac15cc commit 44a0c5f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 8 additions & 2 deletions cmd/rollapp/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

"github.com/pterm/pterm"
Expand Down Expand Up @@ -228,8 +229,13 @@ func runInit(cmd *cobra.Command, env string, raID string) error {
height,
blockIdHash,
)
daFields := map[string]string{
"DASer.SampleFrom": height,
heightInt, err := strconv.Atoi(height)
if err != nil {
return err
}

daFields := map[string]interface{}{
"DASer.SampleFrom": heightInt,
"Header.TrustedHash": blockIdHash,
}

Expand Down
14 changes: 11 additions & 3 deletions utils/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/pelletier/go-toml"
toml "github.com/pelletier/go-toml"
)

func WriteTomlTreeToFile(tomlConfig *toml.Tree, path string) error {
Expand All @@ -31,11 +31,19 @@ func GetKeyFromTomlFile(tmlFilePath, key string) (string, error) {
return tomlTree.Get(key).(string), nil
}

func UpdateFieldInToml(tmlFilePath, key, value string) error {
// TODO: improve
func UpdateFieldInToml(tmlFilePath, key string, value interface{}) error {
tomlCfg, err := toml.LoadFile(tmlFilePath)
if err != nil {
return fmt.Errorf("failed to load %s: %v", tmlFilePath, err)
}
tomlCfg.Set(key, value)

switch v := value.(type) {
case string, int, int64, float64, bool:
tomlCfg.Set(key, v)
default:
return fmt.Errorf("unsupported type for key %s: %T", key, value)
}

return WriteTomlTreeToFile(tomlCfg, tmlFilePath)
}

0 comments on commit 44a0c5f

Please sign in to comment.