Skip to content

Commit

Permalink
fix(config): update toml parser
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre committed Nov 11, 2024
1 parent ab135bc commit cadf136
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 69 deletions.
8 changes: 5 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/pactus-project/pactus/www/http"
"github.com/pactus-project/pactus/www/jsonrpc"
"github.com/pactus-project/pactus/www/nanomsg"
"github.com/pelletier/go-toml"
"github.com/pelletier/go-toml/v2"
)

var (
Expand Down Expand Up @@ -236,7 +236,7 @@ func (conf *Config) Save(path string) error {
func (conf *Config) toTOML() []byte {
buf := new(bytes.Buffer)
encoder := toml.NewEncoder(buf)
encoder.Order(toml.OrderPreserve)
encoder.SetIndentTables(true)
err := encoder.Encode(conf)
if err != nil {
panic(err)
Expand All @@ -254,7 +254,9 @@ func LoadFromFile(file string, strict bool, defaultConfig *Config) (*Config, err
conf := defaultConfig
buf := bytes.NewBuffer(data)
decoder := toml.NewDecoder(buf)
decoder.Strict(strict)
if strict {
decoder.DisallowUnknownFields()
}
if err := decoder.Decode(conf); err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ func TestExampleConfig(t *testing.T) {
exampleToml = strings.ReplaceAll(exampleToml, "\n\n", "\n")
defaultToml = strings.ReplaceAll(defaultToml, "\n\n", "\n")

defaultToml = strings.TrimSpace(defaultToml)
exampleToml = strings.TrimSpace(exampleToml)

assert.Equal(t, defaultToml, exampleToml)
}

Expand Down
60 changes: 30 additions & 30 deletions config/example_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
[store]

# `path` specifies the directory where blockchain data will be stored.
# Default is `"data"`.
path = "data"
# Default is 'data'.
path = 'data'

# `retention_days` this parameter indicates the number of days for which the node should keep or retain the blocks
# before pruning them. It is only applicable if the node is in Prune Mode.
# Default is `10`.
# Default is `10` days.
retention_days = 10

# `network` contains configuration options for the network module, which manages communication between nodes.
[network]

# `network_key` specifies the private key filename to use for node authentication and encryption in the p2p protocol.
# Default is `"network_key"`.
network_key = "network_key"
# Default is `'network_key'`.
network_key = 'network_key'

# `public_addr` is the address that is public and accessible to other nodes.
public_addr = ""
public_addr = ''

# `listen_addrs` specifies the addresses and ports where the node will listen for incoming connections from other nodes.
listen_addrs = []
Expand Down Expand Up @@ -84,13 +84,13 @@
[sync]

# `moniker` is a custom human-readable name for this node.
moniker = ""
moniker = ''

# `session_timeout` is a timeout for a download session to remain open.
# When a block download request is sent, this timer starts. If there is no activity from the target Node,
# the session will be closed after the timeout and try to get the block from another Node.
# Default is `10s`.
session_timeout = "10s"
# the session will be closed after the timeout and try to get the block from another peer.
# Default is `'10s'`.
session_timeout = '10s'

# `sync.firewall` contains configuration options for the sync firewall.
[sync.firewall]
Expand Down Expand Up @@ -122,7 +122,7 @@
# `tx_pool.fee` contains configuration to calculate the transaction fee.
[tx_pool.fee]

# The `fixed_fee` is a constant fee applied to each transaction, regardless of its size or type.
# The `fixed_fee` is a constant fee in PAC that applies to each transaction, regardless of its size or type.
# Default is `0.01` PAC.
fixed_fee = 0.01

Expand Down Expand Up @@ -160,23 +160,23 @@
compress = true

# `targets` determines where the logs will be shown, saved, or sent.
# Default is `["console", "file"]`.
targets = ["console", "file"]
# Default is `['console', 'file']`.
targets = ['console', 'file']

# `logger.levels` contains the level of logger per module.
# Available log levels are:
# "trace", "debug", "info", "warn", and "error".
# 'trace', 'debug', 'info', 'warn', and 'error'.
[logger.levels]
_consensus = "warn"
_grpc = "info"
_http = "info"
_jsonrpc = "info"
_network = "error"
_nonomsg = "info"
_pool = "error"
_state = "info"
_sync = "error"
default = "info"
_consensus = 'warn'
_grpc = 'info'
_http = 'info'
_jsonrpc = 'info'
_network = 'error'
_nonomsg = 'info'
_pool = 'error'
_state = 'info'
_sync = 'error'
default = 'info'

# `grpc` contains configuration of the gRPC module.
[grpc]
Expand All @@ -190,10 +190,10 @@
enable_wallet = false

# `listen` is the address to listen for incoming connections for gRPC server.
listen = "127.0.0.1:50051"
listen = '127.0.0.1:50051'

# `basic_auth` is the Basic Auth credential used to enhance gRPC security.
basic_auth = ""
basic_auth = ''

# `grpc.gateway` contains configuration for the gRPC Gateway server
# which translates a RESTful HTTP API into gRPC.
Expand All @@ -204,7 +204,7 @@
enable = false

# `listen` is the address to listen for incoming connections for gRPCGateway server.
listen = "127.0.0.1:8080"
listen = '127.0.0.1:8080'

# `enable_cors` indicates whether Cross-Origin Request Sharing (CORS)
# protection should be enabled or not.
Expand All @@ -219,7 +219,7 @@
enable = false

# `listen` is the address to listen for incoming connections for JSON-RPC server.
listen = "127.0.0.1:8545"
listen = '127.0.0.1:8545'

# `http` configuration.
[http]
Expand All @@ -229,7 +229,7 @@
enable = false

# `listen` is the address to listen for incoming connections for HTTP server.
listen = "127.0.0.1:80"
listen = '127.0.0.1:80'

# `enable_pprof` Enables Golang's pprof debugger for profiling CPU, memory, and goroutines,
# providing key performance insights. Be cautious as it exposes sensitive
Expand All @@ -244,4 +244,4 @@
enable = false

# `listen` is the address for incoming connections to the nanomsg server.
listen = "tcp://127.0.0.1:40899"
listen = 'tcp://127.0.0.1:40899'
44 changes: 22 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ require (
github.com/manifoldco/promptui v0.9.0
github.com/multiformats/go-multiaddr v0.14.0
github.com/pacviewer/jrpc-gateway v0.5.1
github.com/pelletier/go-toml v1.9.5
github.com/pelletier/go-toml/v2 v2.2.3
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.5
github.com/rs/zerolog v1.33.0
github.com/schollz/progressbar/v3 v3.17.0
github.com/schollz/progressbar/v3 v3.17.1
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tyler-smith/go-bip39 v1.1.0
go.nanomsg.org/mangos/v3 v3.4.2
golang.org/x/crypto v0.28.0
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
golang.org/x/term v0.25.0
google.golang.org/grpc v1.67.1
golang.org/x/crypto v0.29.0
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
golang.org/x/term v0.26.0
google.golang.org/grpc v1.68.0
google.golang.org/protobuf v1.35.1
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)
Expand All @@ -49,14 +49,14 @@ require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.14.3 // indirect
github.com/bits-and-blooms/bitset v1.15.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/consensys/bavard v0.1.22 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/creachadair/jrpc2 v1.2.1 // indirect
github.com/creachadair/mds v0.21.3 // indirect
github.com/creachadair/jrpc2 v1.3.0 // indirect
github.com/creachadair/mds v0.21.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
Expand All @@ -80,7 +80,7 @@ require (
github.com/huin/goupnp v1.3.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/boxo v0.24.2 // indirect
github.com/ipfs/boxo v0.24.3 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
Expand All @@ -89,7 +89,7 @@ require (
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
Expand Down Expand Up @@ -163,23 +163,23 @@ require (
github.com/wlynxg/anet v0.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
go.uber.org/dig v1.18.0 // indirect
go.uber.org/fx v1.23.0 // indirect
go.uber.org/mock v0.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/tools v0.26.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.27.0 // indirect
gonum.org/v1/gonum v0.15.1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand Down
Loading

0 comments on commit cadf136

Please sign in to comment.