Skip to content

Commit

Permalink
Fixed Linter and Linted Project Files (#156)
Browse files Browse the repository at this point in the history
* fixed linter and linted project files

* removed dead code
  • Loading branch information
dutterbutter committed Jun 18, 2019
1 parent c891936 commit 952ef79
Show file tree
Hide file tree
Showing 15 changed files with 482 additions and 68 deletions.
15 changes: 2 additions & 13 deletions .golangci.yml
Expand Up @@ -150,13 +150,6 @@ linters-settings:
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default
gocritic:
# Which checks should be enabled; can't be combined with 'disabled-checks';
# See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
# By default list of stable checks is used.
enabled-checks:
- rangeValCopy

# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
disabled-checks:
- regexpMust
Expand All @@ -176,6 +169,8 @@ linters:
enable:
- megacheck
- govet
- gofmt
- goimports
enable-all: false
disable:
- maligned
Expand Down Expand Up @@ -242,9 +237,3 @@ issues:
# of integration: much better don't allow issues in new code.
# Default is false.
new: false

# Show only new issues created after git revision `REV`
new-from-rev: REV

# Show only new issues created in git patch with set file path.
#new-from-patch: path/to/patch/file
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -12,11 +12,12 @@ help: Makefile

$(GOLANGCI):
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s latest
wget -O - -q https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s latest

## lint: Lints project files, go gets golangci-lint if missing. Runs `golangci-lint` on project files.
.PHONY: lint
lint: $(GOLANGCI)
golangci-lint run -v
golangci-lint run ./...

## test: Runs `go test` on project test files.
test:
Expand Down
18 changes: 10 additions & 8 deletions cmd/gossamer/configcmd.go
Expand Up @@ -17,6 +17,12 @@ package main

import (
"fmt"
"os"
"path/filepath"
"reflect"
"strings"
"unicode"

"github.com/ChainSafe/gossamer/cmd/utils"
cfg "github.com/ChainSafe/gossamer/config"
"github.com/ChainSafe/gossamer/dot"
Expand All @@ -25,11 +31,6 @@ import (
log "github.com/inconshreveable/log15"
"github.com/naoina/toml"
"github.com/urfave/cli"
"os"
"path/filepath"
"reflect"
"strings"
"unicode"
)

var (
Expand Down Expand Up @@ -104,7 +105,7 @@ func loadConfig(file string) (*cfg.Config, error) {
filep := filepath.Join(filepath.Clean(fp))
info, err := os.Lstat(filep)
if err != nil {
log.Crit("config file err ","err", err)
log.Crit("config file err ", "err", err)
os.Exit(1)
}
if info.IsDir() {
Expand All @@ -114,7 +115,7 @@ func loadConfig(file string) (*cfg.Config, error) {
/* #nosec */
f, err := os.Open(filep)
if err != nil {
log.Crit("opening file err ", "err",err)
log.Crit("opening file err ", "err", err)
os.Exit(1)
}
defer func() {
Expand Down Expand Up @@ -149,6 +150,7 @@ func setP2PConfig(ctx *cli.Context, cfg *p2p.ServiceConfig) *p2p.Service {
srv := startP2PService(cfg)
return srv
}

// startP2PService starts a p2p network layer from provided config
func startP2PService(cfg *p2p.ServiceConfig) *p2p.Service {
srv, err := p2p.NewService(cfg)
Expand Down Expand Up @@ -212,4 +214,4 @@ var tomlSettings = toml.Config{
}
return fmt.Errorf("field '%s' is not defined in %s%s", field, rt.String(), link)
},
}
}
1 change: 0 additions & 1 deletion cmd/utils/flags.go
Expand Up @@ -50,4 +50,3 @@ var (
Value: "",
}
)

12 changes: 5 additions & 7 deletions codec/decode.go
Expand Up @@ -240,10 +240,10 @@ func (sd *Decoder) DecodeInterface(t interface{}) (interface{}, error) {
switch reflect.ValueOf(t).Kind() {
case reflect.Ptr:
switch reflect.ValueOf(t).Elem().Kind() {
case reflect.Slice, reflect.Array:
return sd.DecodeArray(t)
default:
return sd.DecodeTuple(t)
case reflect.Slice, reflect.Array:
return sd.DecodeArray(t)
default:
return sd.DecodeTuple(t)
}
case reflect.Slice, reflect.Array:
return sd.DecodeArray(t)
Expand All @@ -252,7 +252,6 @@ func (sd *Decoder) DecodeInterface(t interface{}) (interface{}, error) {
}
}


func (sd *Decoder) DecodeArray(t interface{}) (interface{}, error) {
var v reflect.Value
switch reflect.ValueOf(t).Kind() {
Expand Down Expand Up @@ -303,7 +302,6 @@ func (sd *Decoder) DecodeArray(t interface{}) (interface{}, error) {
return t, err
}


// DecodeTuple accepts a byte array representing the SCALE encoded tuple and an interface. This interface should be a pointer
// to a struct which the encoded tuple should be marshalled into. If it is a valid encoding for the struct, it returns the
// decoded struct, otherwise error,
Expand Down Expand Up @@ -443,4 +441,4 @@ func (sd *Decoder) DecodeBoolArray() ([]bool, error) {
}
}
return o, nil
}
}
2 changes: 1 addition & 1 deletion codec/encode_test.go
Expand Up @@ -97,7 +97,7 @@ var encodeTests = []encodeTest{
{val: []int{1073741824, 2, 3, 4}, output: []byte{0x10, 0x03, 0x00, 0x00, 0x00, 0x40, 0x08, 0x0c, 0x10}, bytesEncoded: 9},
{val: []int{1 << 32, 2, 3, 1 << 32}, output: []byte{0x10, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01}, bytesEncoded: 15},
{val: []bool{true, false, true}, output: []byte{0x0c, 0x01, 0x00, 0x01}, bytesEncoded: 4},
{val: [][]int{[]int{0, 1}, []int{1, 0}}, output: []byte{0x08, 0x08, 0x00, 0x04, 0x08, 0x04, 0x00}, bytesEncoded: 7},
{val: [][]int{{0, 1}, {1, 0}}, output: []byte{0x08, 0x08, 0x00, 0x04, 0x08, 0x04, 0x00}, bytesEncoded: 7},
{val: []*big.Int{big.NewInt(0), big.NewInt(1)}, output: []byte{0x08, 0x00, 0x04}, bytesEncoded: 3},
}

Expand Down
8 changes: 4 additions & 4 deletions common/types.go
Expand Up @@ -9,9 +9,9 @@ type Hash [32]byte

// BlockHeader is the header of a Polkadot block
type BlockHeader struct {
ParentHash Hash // the block hash of the block's parent
ParentHash Hash // the block hash of the block's parent
Number *big.Int // block number
StateRoot Hash // the root of the state trie
ExtrinsicsRoot Hash // the root of the extrinsics trie
Digest []byte // any addition block info eg. logs, seal
StateRoot Hash // the root of the state trie
ExtrinsicsRoot Hash // the root of the extrinsics trie
Digest []byte // any addition block info eg. logs, seal
}
23 changes: 5 additions & 18 deletions config/config.go
Expand Up @@ -22,37 +22,24 @@ import (
)

var (
defaultP2PPort = 7001
defaultP2PPort = 7001
defaultP2PRandSeed = int64(33)
)

// Config is a collection of configurations throughout the system
type Config struct {
ServiceConfig *p2p.ServiceConfig
DbConfig polkadb.DbConfig
DbConfig polkadb.DbConfig
}

// DefaultConfig is the default settings used when a config.toml file is not passed in during instantiation
var DefaultConfig = &Config{
ServiceConfig: &p2p.ServiceConfig{
BootstrapNodes: []string{"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM"},
Port: defaultP2PPort,
RandSeed: defaultP2PRandSeed,
Port: defaultP2PPort,
RandSeed: defaultP2PRandSeed,
},
DbConfig: polkadb.DbConfig{
Datadir: "chaindata",
},
}



//[ServiceConfig]
//BootstrapNodes=["/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",]
//Port= 7001
//RandSeed= 33
//
//[DbConfig]
//Datadir="chaindata"




5 changes: 3 additions & 2 deletions config/defaults.go
Expand Up @@ -17,12 +17,13 @@
package cfg

import (
"github.com/inconshreveable/log15"
"os"
"os/user"
"path/filepath"
"regexp"
"runtime"

"github.com/inconshreveable/log15"
)

const (
Expand Down Expand Up @@ -84,4 +85,4 @@ func CheckConfig(ext string) string {
log15.Error("please specify a config file", "err", err)
}
return file
}
}
2 changes: 1 addition & 1 deletion dot/dot.go
Expand Up @@ -26,4 +26,4 @@ type Dot struct {
ServerConfig *p2p.ServiceConfig
Server *p2p.Service // Currently running P2P networking layer
Polkadb *polkadb.BadgerDB //BadgerDB database
}
}
57 changes: 54 additions & 3 deletions go.mod
Expand Up @@ -3,26 +3,77 @@ module github.com/ChainSafe/gossamer
replace github.com/go-interpreter/wagon v0.0.0 => github.com/perlin-network/wagon v0.3.1-0.20180825141017-f8cb99b55a39

require (
cloud.google.com/go v0.40.0 // indirect
github.com/OpenPeeDeeP/depguard v0.0.0-20181229194401-1f388ab2d810 // indirect
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.13+incompatible // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20190617083831-1652836e9bdc // indirect
github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-critic/go-critic v0.3.4 // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/golang/mock v1.3.1 // indirect
github.com/golang/snappy v0.0.1
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/gostaticanalysis/analysisutil v0.0.0-20190329151158-56bca42c7635 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.9.2 // indirect
github.com/inconshreveable/log15 v0.0.0-20180818164646-67afb5ed74ec
github.com/ipfs/go-datastore v0.0.2
github.com/ipfs/go-ipfs v0.4.19-rc2.0.20190328185617-7aab3c29f9d4
github.com/ipfs/go-ipfs-config v0.0.1
github.com/kisielk/errcheck v1.2.0 // indirect
github.com/klauspost/compress v1.7.1 // indirect
github.com/klauspost/cpuid v1.2.1 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kr/pty v1.1.5 // indirect
github.com/libp2p/go-libp2p v0.0.3
github.com/libp2p/go-libp2p-crypto v0.0.1
github.com/libp2p/go-libp2p-host v0.0.2
github.com/libp2p/go-libp2p-kad-dht v0.0.6
github.com/libp2p/go-libp2p-net v0.0.1
github.com/libp2p/go-libp2p-peer v0.1.0
github.com/libp2p/go-libp2p-peerstore v0.0.1
github.com/logrusorgru/aurora v0.0.0-20190428105938-cea283e61946 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/multiformats/go-multiaddr v0.0.2
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.1
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/perlin-network/life v0.0.0-20190402092845-c30697b41680
github.com/pkg/errors v0.8.1
github.com/prometheus/common v0.5.0 // indirect
github.com/rogpeppe/fastuuid v1.1.0 // indirect
github.com/russross/blackfriday v2.0.0+incompatible // indirect
github.com/shirou/gopsutil v2.18.12+incompatible // indirect
github.com/shurcooL/go v0.0.0-20190330031554-6713ea532688 // indirect
github.com/sirupsen/logrus v1.4.2 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v0.0.5 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.4.0 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/ugorji/go v1.1.5-pre // indirect
github.com/urfave/cli v1.20.0
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25
google.golang.org/appengine v1.6.0 // indirect
github.com/valyala/fasthttp v1.3.0 // indirect
go.etcd.io/bbolt v1.3.3 // indirect
go.opencensus.io v0.22.0 // indirect
golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522 // indirect
golang.org/x/image v0.0.0-20190616094056-33659d3de4f5 // indirect
golang.org/x/mobile v0.0.0-20190607214518-6fa95d984e88 // indirect
golang.org/x/mod v0.1.0 // indirect
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f // indirect
golang.org/x/tools v0.0.0-20190617190820-da514acc4774 // indirect
google.golang.org/appengine v1.6.1 // indirect
google.golang.org/genproto v0.0.0-20190611190212-a7e196e89fd3 // indirect
google.golang.org/grpc v1.21.1 // indirect
honnef.co/go/tools v0.0.0-20190614002413-cb51c254f01b // indirect
mvdan.cc/unparam v0.0.0-20190310220240-1b9ccfa71afe // indirect
sourcegraph.com/sqs/pbtypes v1.0.0 // indirect
)

0 comments on commit 952ef79

Please sign in to comment.