Skip to content

Commit

Permalink
remove extra newline not needed, fix method comments, fix typos, remo…
Browse files Browse the repository at this point in the history
…ve redundant type conversion (#1104)

remove extra newline not needed, fix method comments, fix typos, remove redundant type conversion vochain/genesis: update types to remove package name, it will be redundant calling genesis.GenesisAppState, cmd/cli: fix exported function with the unexported return type util/net: fix unhandled error adding comments deepsource issues: removed method receiver 'd' that is not used replace len(s.Topic) == 0 with s.Topic == ""
  • Loading branch information
mariajdab authored Oct 9, 2023
1 parent 7c854c5 commit 35a1ad4
Show file tree
Hide file tree
Showing 27 changed files with 110 additions and 111 deletions.
2 changes: 1 addition & 1 deletion api/censuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (a *API) censusAddHandler(msg *apirest.APIdata, ctx *httprouter.HTTPContext
// censusTypeHandler
//
// @Summary Get type of census
// @Description Get the type of a census
// @Description Get the census type
// @Tags Censuses
// @Accept json
// @Produce json
Expand Down
2 changes: 1 addition & 1 deletion api/elections.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (a *API) electionFullListHandler(_ *apirest.APIdata, ctx *httprouter.HTTPCo
}
list = append(list, a.electionSummary(e))
}
// wrap list in a struct to consistently return list in a object, return empty
// wrap list in a struct to consistently return list in an object, return empty
// object if the list does not contains any result
data, err := json.Marshal(struct {
Elections []ElectionSummary `json:"elections"`
Expand Down
2 changes: 1 addition & 1 deletion api/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
FaucetHandler = "faucet"
)

// FaucetAPI is an httprouter/apirest handler for the faucet.
// FaucetAPI is a httprouter/apirest handler for the faucet.
// It generates a signed package that can be used to request tokens from the faucet.
type FaucetAPI struct {
signingKey *ethereum.SignKeys
Expand Down
2 changes: 1 addition & 1 deletion api/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (a *API) walletSignAndSendTx(stx *models.SignedTx, wallet *ethereum.SignKey
// walletAddHandler
//
// @Summary Add account
// @Description Add a new account to the local store. It return a token used to manage this account on the future.
// @Description Add a new account to the local store. It returns a token used to manage this account on the future.
// @Tags Wallet
// @Accept json
// @Produce json
Expand Down
26 changes: 13 additions & 13 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ func main() {

}

func accountIsSet(c *vocdoniCLI) bool {
func accountIsSet(c *VocdoniCLI) bool {
return c.currentAccount >= 0
}

func accountHandler(c *vocdoniCLI) error {
func accountHandler(c *VocdoniCLI) error {
accountAddNewStr := "-> import an account (from hexadecimal private key)"
accountGenerateStr := "-> generate a new account"
p := ui.Select{
Expand Down Expand Up @@ -193,7 +193,7 @@ func accountHandler(c *vocdoniCLI) error {
return nil
}

func accountSet(c *vocdoniCLI) error {
func accountSet(c *VocdoniCLI) error {
p := ui.Prompt{
Label: "Account private key",
}
Expand All @@ -212,7 +212,7 @@ func accountSet(c *vocdoniCLI) error {
return c.setAPIaccount(key, memo)
}

func accountGen(c *vocdoniCLI) error {
func accountGen(c *VocdoniCLI) error {
p := ui.Prompt{
Label: "Account memo note",
}
Expand All @@ -225,7 +225,7 @@ func accountGen(c *vocdoniCLI) error {
return c.setAPIaccount(key, memo)
}

func accountInfo(c *vocdoniCLI) error {
func accountInfo(c *VocdoniCLI) error {
acc, err := c.api.Account("")
if err != nil {
return err
Expand All @@ -243,7 +243,7 @@ func accountInfo(c *vocdoniCLI) error {
if acc.Metadata != nil {
accMetadata, err := json.MarshalIndent(acc.Metadata, "", " ")
if err != nil {
log.Debug("account metadta cannot be unmarshal")
log.Debug("account metadata cannot be unmarshal")
} else {
fmt.Printf("%s:\n%s\n", keysPrint.Sprintf(" ➥ metadata"), valuesPrint.Sprintf("%s", accMetadata))
}
Expand All @@ -252,7 +252,7 @@ func accountInfo(c *vocdoniCLI) error {
return nil
}

func networkInfo(cli *vocdoniCLI) error {
func networkInfo(cli *VocdoniCLI) error {
info, err := cli.api.ChainInfo()
if err != nil {
return err
Expand All @@ -265,7 +265,7 @@ func networkInfo(cli *vocdoniCLI) error {
return nil
}

func bootStrapAccount(cli *vocdoniCLI) error {
func bootStrapAccount(cli *VocdoniCLI) error {
var faucetPkg *models.FaucetPackage
p := ui.Prompt{
Label: "Do you have a faucet package? [y,n]",
Expand Down Expand Up @@ -322,7 +322,7 @@ func bootStrapAccount(cli *vocdoniCLI) error {
return nil
}

func transfer(cli *vocdoniCLI) error {
func transfer(cli *VocdoniCLI) error {
s := ui.Select{
Label: "Select a destination account",
Items: append(cli.listAccounts(), "to external account"),
Expand Down Expand Up @@ -397,10 +397,10 @@ func transfer(cli *vocdoniCLI) error {
return nil
}

func hostHandler(cli *vocdoniCLI) error {
func hostHandler(cli *VocdoniCLI) error {
validateFunc := func(url string) error {
log.Debugf("performing ping test to %s", url)
_, err := http.NewRequest("GET", url+"/ping", nil)
_, err := http.NewRequest("GET", url+"/ping", http.NoBody)
return err
}
p := ui.Prompt{
Expand Down Expand Up @@ -431,7 +431,7 @@ func hostHandler(cli *vocdoniCLI) error {
return cli.setAuthToken(token)
}

func accountSetMetadata(cli *vocdoniCLI) error {
func accountSetMetadata(cli *VocdoniCLI) error {
currentAccount, err := cli.api.Account("")
if err != nil {
return err
Expand Down Expand Up @@ -515,7 +515,7 @@ func accountSetMetadata(cli *vocdoniCLI) error {

}

func electionHandler(cli *vocdoniCLI) error {
func electionHandler(cli *VocdoniCLI) error {
infoPrint.Printf("preparing the election template...\n")
description := api.ElectionDescription{
Title: map[string]string{"default": "election title"},
Expand Down
26 changes: 13 additions & 13 deletions cmd/cli/vocdonicli.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Account struct {
PublicKey types.HexBytes `json:"pubKey"`
}

type vocdoniCLI struct {
type VocdoniCLI struct {
filepath string
config *Config
api *apiclient.HTTPclient
Expand All @@ -63,7 +63,7 @@ type vocdoniCLI struct {
currentAccount int
}

func NewVocdoniCLI(configFile, host string) (*vocdoniCLI, error) {
func NewVocdoniCLI(configFile, host string) (*VocdoniCLI, error) {
cfg := Config{}
if err := cfg.Load(configFile); err != nil {
return nil, err
Expand Down Expand Up @@ -101,7 +101,7 @@ func NewVocdoniCLI(configFile, host string) (*vocdoniCLI, error) {
return nil, err
}
}
return &vocdoniCLI{
return &VocdoniCLI{
filepath: configFile,
config: &cfg,
api: api,
Expand All @@ -110,7 +110,7 @@ func NewVocdoniCLI(configFile, host string) (*vocdoniCLI, error) {
}, nil
}

func (v *vocdoniCLI) setHost(host string) error {
func (v *VocdoniCLI) setHost(host string) error {
u, err := url.Parse(host)
if err != nil {
return err
Expand All @@ -127,7 +127,7 @@ func (v *vocdoniCLI) setHost(host string) error {
return v.save()
}

func (v *vocdoniCLI) setAuthToken(token string) error {
func (v *VocdoniCLI) setAuthToken(token string) error {
t, err := uuid.Parse(token)
if err != nil {
return err
Expand All @@ -137,7 +137,7 @@ func (v *vocdoniCLI) setAuthToken(token string) error {
return v.save()
}

func (v *vocdoniCLI) useAccount(index int) error {
func (v *VocdoniCLI) useAccount(index int) error {
if index >= len(v.config.Accounts) {
return fmt.Errorf("account %d does not exist", index)
}
Expand All @@ -149,21 +149,21 @@ func (v *vocdoniCLI) useAccount(index int) error {
return v.api.SetAccount(v.config.Accounts[index].PrivKey.String())
}

func (v *vocdoniCLI) getAccount(index int) (*Account, error) {
func (v *VocdoniCLI) getAccount(index int) (*Account, error) {
if index >= len(v.config.Accounts) {
return nil, fmt.Errorf("account %d does not exist", index)
}
return &v.config.Accounts[index], nil
}

func (v *vocdoniCLI) getCurrentAccount() *Account {
func (v *VocdoniCLI) getCurrentAccount() *Account {
if v.currentAccount < 0 {
return nil
}
return &v.config.Accounts[v.currentAccount]
}

func (v *vocdoniCLI) setAPIaccount(key, memo string) error {
func (v *VocdoniCLI) setAPIaccount(key, memo string) error {
if err := v.api.SetAccount(key); err != nil {
return err
}
Expand Down Expand Up @@ -198,20 +198,20 @@ func (v *vocdoniCLI) setAPIaccount(key, memo string) error {
}

// listAccounts list the memo notes of all stored accounts
func (v *vocdoniCLI) listAccounts() []string {
func (v *VocdoniCLI) listAccounts() []string {
accounts := []string{}
for _, a := range v.config.Accounts {
accounts = append(accounts, a.Memo)
}
return accounts
}

func (v *vocdoniCLI) transactionMined(txHash types.HexBytes) bool {
func (v *VocdoniCLI) transactionMined(txHash types.HexBytes) bool {
_, err := v.api.TransactionReference(txHash)
return err == nil
}

func (v *vocdoniCLI) waitForTransaction(txHash types.HexBytes) bool {
func (v *VocdoniCLI) waitForTransaction(txHash types.HexBytes) bool {
startTime := time.Now()
for time.Now().Before(startTime.Add(transactionConfirmationThreshold)) {
if v.transactionMined(txHash) {
Expand All @@ -222,6 +222,6 @@ func (v *vocdoniCLI) waitForTransaction(txHash types.HexBytes) bool {
return false
}

func (v *vocdoniCLI) save() error {
func (v *VocdoniCLI) save() error {
return v.config.Save(v.filepath)
}
2 changes: 1 addition & 1 deletion cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func main() {
// set IsSeedNode to true if seed mode configured
globalCfg.Vochain.IsSeedNode = types.ModeSeed == globalCfg.Mode
// do we need indexer?
globalCfg.Vochain.Indexer.Enabled = (globalCfg.Mode == types.ModeGateway)
globalCfg.Vochain.Indexer.Enabled = globalCfg.Mode == types.ModeGateway
// offchainDataDownloader is only needed for gateways
globalCfg.Vochain.OffChainDataDownloader = globalCfg.Vochain.OffChainDataDownloader &&
globalCfg.Mode == types.ModeGateway
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type Config struct {
// Vochain config options
Vochain *VochainCfg
// Ipfs ipfs config options
// Ipfs config options
Ipfs *IPFSCfg
// Metrics config options
Metrics *MetricsCfg
Expand Down
2 changes: 1 addition & 1 deletion data/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
// ImportRetrieveTimeout the maximum duration the import queue will wait
// for retrieving a remote file.
ImportRetrieveTimeout = 5 * time.Minute
// ImportQueueTimeout is the maximum duration the import queue will wait
// ImportPinTimeout is the maximum duration the import queue will wait
// for pinning a remote file.
ImportPinTimeout = 3 * time.Minute
// MaxFileSize is the maximum size of a file that can be imported.
Expand Down
6 changes: 4 additions & 2 deletions data/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
ihelper "github.com/ipfs/boxo/ipld/unixfs/importer/helpers"
ipfscid "github.com/ipfs/go-cid"
"github.com/ipfs/kubo/commands"
config "github.com/ipfs/kubo/config"
"github.com/ipfs/kubo/config"
ipfscore "github.com/ipfs/kubo/core"
ipfsapi "github.com/ipfs/kubo/core/coreapi"
"github.com/ipfs/kubo/plugin/loader"
Expand Down Expand Up @@ -236,7 +236,9 @@ func checkWritable(dir string) error {
}
return fmt.Errorf("unexpected error while checking writeablility of repo root: %s", err)
}
fi.Close()
if err := fi.Close(); err != nil {
return err
}
return os.Remove(testfile)
}

Expand Down
1 change: 0 additions & 1 deletion httprouter/httprouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ func (r *HTTProuter) Init(host string, port int) error {
}
r.address = ln.Addr()
return nil

}

// EnablePrometheusMetrics enables go-chi prometheus metrics under specified ID.
Expand Down
2 changes: 1 addition & 1 deletion log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var logTestTime, _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")

type testHook struct{}

// To ensure that the log output in the test is deterministic.
// Run ensure that the log output in the test is deterministic.
func (*testHook) Run(e *zerolog.Event, _ zerolog.Level, _ string) {
e.Stringer("time", logTestTime)
}
Expand Down
4 changes: 2 additions & 2 deletions statedb/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (*readOnlyWriteTx) Set(_ []byte, _ []byte) error {
return ErrReadOnly
}

// Set implements db.WriteTx.Delete but returns error always.
// Delete implements db.WriteTx.Delete but returns error always.
func (*readOnlyWriteTx) Delete(_ []byte) error {
return ErrReadOnly
}
Expand All @@ -373,7 +373,7 @@ func (*readOnlyWriteTx) Apply(_ db.WriteTx) error {
// Commit implements db.WriteTx.Commit but returns nil always.
func (*readOnlyWriteTx) Commit() error { return nil }

// Commit implements db.WriteTx.Discard as a no-op.
// Discard implements db.WriteTx.Discard as a no-op.
func (*readOnlyWriteTx) Discard() {}

// TreeView returns the mainTree opened at root as a TreeView for read-only.
Expand Down
4 changes: 2 additions & 2 deletions subpub/subpub.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
// We use go-bare for export/import the trie. In order to support
// big census (up to 8 Million entries) we need to increase the maximums.
bareMaxArrayLength uint64 = 1024 * 1014 * 8 // 8 Million entries
bareMaxUnmarshalBytes uint64 = bareMaxArrayLength * 32 // Assuming 32 bytes per entry
bareMaxUnmarshalBytes = bareMaxArrayLength * 32 // Assuming 32 bytes per entry
)

// SubPub is a simplified PubSub protocol using libp2p.
Expand Down Expand Up @@ -90,7 +90,7 @@ func NewSubPub(groupKey [32]byte, node *core.IpfsNode) *SubPub {
// Start connects the SubPub networking stack
// and begins passing incoming messages to the receiver chan
func (s *SubPub) Start(ctx context.Context, receiver chan *Message) {
if len(s.Topic) == 0 {
if s.Topic == "" {
log.Fatal("no group key provided")
}
ipfslog.SetLogLevel("*", "ERROR")
Expand Down
Loading

0 comments on commit 35a1ad4

Please sign in to comment.