Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
bing bong
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear committed Sep 20, 2023
1 parent 5818f79 commit 8f59b14
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 70 deletions.
46 changes: 23 additions & 23 deletions cosmos/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ import (
"math/big"
"time"

"github.com/ethereum/go-ethereum/node"
"github.com/spf13/cast"

"pkg.berachain.dev/polaris/eth/polar"

servertypes "github.com/cosmos/cosmos-sdk/server/types"

"github.com/ethereum/go-ethereum/node"

"pkg.berachain.dev/polaris/eth/polar"
)

var handleError = func(err error) error {
if err != nil {
return fmt.Errorf("error while reading configuration: %w", err)
}
return nil
}

// DefaultConfig returns the default configuration for a polaris chain.
func DefaultConfig() *Config {
return &Config{
Expand All @@ -46,16 +54,12 @@ type Config struct {
Node node.Config
}

//nolint:funlen // TODO break up later.
func ReadConfigFromAppOpts(opts servertypes.AppOptions) (*Config, error) {

Check failure on line 58 in cosmos/config/config.go

View workflow job for this annotation

GitHub Actions / ci (lint, polaris-linux-latest, 1.21.1)

cognitive complexity 50 of func `ReadConfigFromAppOpts` is high (> 20) (gocognit)
var err error
var val int64
conf := &Config{}

handleError := func(err error) error {
if err != nil {
return fmt.Errorf("error while reading configuration: %w", err)
}
return nil
}

// Wrapping casting functions to return both value and error
getString := func(key string) (string, error) { return cast.ToStringE(opts.Get(key)) }
getInt := func(key string) (int, error) { return cast.ToIntE(opts.Get(key)) }
Expand All @@ -66,17 +70,14 @@ func ReadConfigFromAppOpts(opts servertypes.AppOptions) (*Config, error) {
getStringSlice := func(key string) ([]string, error) { return cast.ToStringSliceE(opts.Get(key)) }
getTimeDuration := func(key string) (time.Duration, error) { return cast.ToDurationE(opts.Get(key)) }

var err error
var val int64

// Polar settings
if conf.Polar.RPCGasCap, err = getUint64(flagRpcGasCap); err != nil {
if conf.Polar.RPCGasCap, err = getUint64(flagRPCGasCap); err != nil {
return nil, handleError(err)
}
if conf.Polar.RPCEVMTimeout, err = getTimeDuration(flagRpcEvmTimeout); err != nil {
if conf.Polar.RPCEVMTimeout, err = getTimeDuration(flagRPCEvmTimeout); err != nil {
return nil, handleError(err)
}
if conf.Polar.RPCTxFeeCap, err = getFloat64(flagRpcTxFeeCap); err != nil {
if conf.Polar.RPCTxFeeCap, err = getFloat64(flagRPCTxFeeCap); err != nil {
return nil, handleError(err)
}

Expand Down Expand Up @@ -146,27 +147,27 @@ func ReadConfigFromAppOpts(opts servertypes.AppOptions) (*Config, error) {
return nil, handleError(err)
}

if conf.Node.HTTPHost, err = getString(flagHttpHost); err != nil {
if conf.Node.HTTPHost, err = getString(flagHTTPHost); err != nil {
return nil, handleError(err)
}

if conf.Node.HTTPPort, err = getInt(flagHttpPort); err != nil {
if conf.Node.HTTPPort, err = getInt(flagHTTPPort); err != nil {
return nil, handleError(err)
}

if conf.Node.HTTPCors, err = getStringSlice(flagHttpCors); err != nil {
if conf.Node.HTTPCors, err = getStringSlice(flagHTTPCors); err != nil {
return nil, handleError(err)
}

if conf.Node.HTTPVirtualHosts, err = getStringSlice(flagHttpVirtualHosts); err != nil {
if conf.Node.HTTPVirtualHosts, err = getStringSlice(flagHTTPVirtualHosts); err != nil {
return nil, handleError(err)
}

if conf.Node.HTTPModules, err = getStringSlice(flagHttpModules); err != nil {
if conf.Node.HTTPModules, err = getStringSlice(flagHTTPModules); err != nil {
return nil, handleError(err)
}

if conf.Node.HTTPPathPrefix, err = getString(flagHttpPathPrefix); err != nil {
if conf.Node.HTTPPathPrefix, err = getString(flagHTTPPathPrefix); err != nil {
return nil, handleError(err)
}

Expand Down Expand Up @@ -234,7 +235,6 @@ func ReadConfigFromAppOpts(opts servertypes.AppOptions) (*Config, error) {
return nil, handleError(err)
}

// Node.HTTPTimeouts settings
// Node.HTTPTimeouts settings
if conf.Node.HTTPTimeouts.ReadTimeout, err = getTimeDuration(flagReadTimeout); err != nil {
return nil, handleError(err)
Expand Down
38 changes: 29 additions & 9 deletions cosmos/config/flags.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2023, Berachain Foundation. All rights reserved.
// Use of this software is govered by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package config

const (
Expand All @@ -15,11 +35,11 @@ const (
flagGraphqlCors = "polaris.node.graphql-cors"
flagSmartCardDaemonPath = "polaris.node.smart-card-daemon-path"
flagWsModules = "polaris.node.ws-modules"
flagHttpCors = "polaris.node.http-cors"
flagHTTPCors = "polaris.node.http-cors"
flagIdleTimeout = "polaris.node.http-timeouts.idle-timeout"
flagAuthAddr = "polaris.node.auth-addr"
flagAllowUnprotectedTxs = "polaris.node.allow-unprotected-txs"
flagHttpHost = "polaris.node.http-host"
flagHTTPHost = "polaris.node.http-host"
flagUseLightweightKdf = "polaris.node.use-lightweight-kdf"
flagWsExposeAll = "polaris.node.ws-expose-all"
flagMaxBlockHistory = "polaris.polar.gpo.max-block-history"
Expand All @@ -28,22 +48,22 @@ const (
flagWsPathPrefix = "polaris.node.ws-path-prefix"
flagWsHost = "polaris.node.ws-host"
flagName = "polaris.node.name"
flagRpcEvmTimeout = "polaris.polar.rpc-evm-timeout"
flagRPCEvmTimeout = "polaris.polar.rpc-evm-timeout"
flagAuthVirtualHosts = "polaris.node.auth-virtual-hosts"
flagAuthPort = "polaris.node.auth-port"
flagUsb = "polaris.node.usb"
flagHttpPort = "polaris.node.http-port"
flagHTTPPort = "polaris.node.http-port"
flagBatchResponseMaxSize = "polaris.node.batch-response-max-size"
flagVersion = "polaris.node.version"
flagHttpVirtualHosts = "polaris.node.http-virtual-hosts"
flagRpcTxFeeCap = "polaris.polar.rpc-tx-fee-cap"
flagHTTPVirtualHosts = "polaris.node.http-virtual-hosts"
flagRPCTxFeeCap = "polaris.polar.rpc-tx-fee-cap"
flagMaxHeaderHistory = "polaris.polar.gpo.max-header-history"
flagExternalSigner = "polaris.node.external-signer"
flagHttpPathPrefix = "polaris.node.http-path-prefix"
flagHTTPPathPrefix = "polaris.node.http-path-prefix"
flagWriteTimeout = "polaris.node.http-timeouts.write-timeout"
flagReadHeaderTimeout = "polaris.node.http-timeouts.read-header-timeout"
flagHttpModules = "polaris.node.http-modules"
flagRpcGasCap = "polaris.polar.rpc-gas-cap"
flagHTTPModules = "polaris.node.http-modules"
flagRPCGasCap = "polaris.polar.rpc-gas-cap"
flagWsOrigins = "polaris.node.ws-origins"
flagDefault = "polaris.node.http-timeouts.default"
flagMaxPrice = "polaris.node.http-timeouts.max-price"
Expand Down
2 changes: 1 addition & 1 deletion cosmos/config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

//nolint:lll // template file.
//nolint:lll,cyclo // template file.
package config

Check failure on line 22 in cosmos/config/template.go

View workflow job for this annotation

GitHub Actions / ci (lint, polaris-linux-latest, 1.21.1)

the average complexity for the package config is 24.500000, max is 10.000000 (cyclop)

const (
Expand Down
37 changes: 0 additions & 37 deletions eth/polar/.polaris.example.toml

This file was deleted.

0 comments on commit 8f59b14

Please sign in to comment.