Skip to content

Commit

Permalink
Tweak initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Jun 10, 2024
1 parent e762b30 commit 7bef375
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
19 changes: 16 additions & 3 deletions cmd/accumulated/cmd_init_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package main
import (
"crypto/ed25519"
"crypto/rand"
"encoding/json"
"fmt"
"io"
"os"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/BurntSushi/toml"
tmed25519 "github.com/cometbft/cometbft/crypto/ed25519"
cmtjson "github.com/cometbft/cometbft/libs/json"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
"gitlab.com/accumulatenetwork/accumulate/cmd/accumulated/run"
"gitlab.com/accumulatenetwork/accumulate/exp/faucet"
Expand All @@ -34,6 +34,7 @@ import (
"gitlab.com/accumulatenetwork/accumulate/pkg/url"
"gitlab.com/accumulatenetwork/accumulate/protocol"
"gitlab.com/accumulatenetwork/accumulate/test/testing"
"gopkg.in/yaml.v3"
)

var cmdInitNetwork = &cobra.Command{
Expand Down Expand Up @@ -66,7 +67,16 @@ func loadNetworkConfiguration(file ...string) *accumulated.NetworkInit {
for _, file := range file {
b, err := os.ReadFile(file)
check(err)
check(yaml.Unmarshal(b, &network))

switch filepath.Ext(file) {
case ".yml", ".yaml":
var v any
check(yaml.Unmarshal(b, &v))
b, err = json.Marshal(v)
check(err)
}

check(json.Unmarshal(b, &network))
}

for _, bvn := range network.Bvns {
Expand All @@ -78,7 +88,10 @@ func loadNetworkConfiguration(file ...string) *accumulated.NetworkInit {
node.DnNodeKey = tmed25519.GenPrivKey()
}
if node.BvnNodeKey == nil {
node.BvnNodeKey = tmed25519.GenPrivKey()
node.BvnNodeKey = node.DnNodeKey
}
if node.BsnNodeKey == nil {
node.BsnNodeKey = node.DnNodeKey
}
if node.ListenAddress == "" {
node.ListenAddress = "0.0.0.0"
Expand Down
7 changes: 5 additions & 2 deletions pkg/types/encoding/json_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ func (j *JsonUnmarshalListWith[T]) unmarshalList(data []byte) error {
return err
}

j.Value = make([]T, len(list))
if n := len(list) - len(j.Value); n > 0 {
j.Value = append(j.Value, make([]T, n)...)
}

for i, raw := range list {
j.Value[i], err = j.Func(raw)
if err != nil {
Expand Down Expand Up @@ -113,7 +116,7 @@ type JsonList[T any] []T

func (j *JsonList[T]) UnmarshalJSON(data []byte) error {
// Attempt to unmarshal as a slice
var list []T
var list []T = *j
err1 := json.Unmarshal(data, &list)
if err1 == nil {
*j = list
Expand Down

0 comments on commit 7bef375

Please sign in to comment.