Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra linters to address common review points. #411

Merged
merged 5 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
- name: Build
run: go build ./...
- name: Install Linters
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3"
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2"
- name: Test and Lint
run: ./run_tests.sh
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@ linters:
enable:
- asciicheck
- bidichk
- containedctx
- dupword
- durationcheck
- errcheck
- errchkjson
- errorlint
- exhaustive
- exportloopref
- goconst
- godot
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- makezero
- misspell
- nilerr
- nosprintfhostport
- prealloc
- predeclared
- reassign
- revive
- staticcheck
- tparallel
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (c *Client) do(ctx context.Context, method, path string, addr stdaddr.Addre

err = ValidateServerSignature(reply, respBody, c.PubKey)
if err != nil {
return fmt.Errorf("authenticate server response: %v", err)
return fmt.Errorf("authenticate server response: %w", err)
}

err = json.Unmarshal(respBody, resp)
Expand Down
2 changes: 1 addition & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const (
backupFileMode = 0600
)

// backupMtx should be held when writing to the database backup file
// backupMtx should be held when writing to the database backup file.
var backupMtx sync.Mutex

// writeHotBackupFile writes a backup of the database file while the database
Expand Down
21 changes: 10 additions & 11 deletions rpc/dcrd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const (
// of JSON encoding.
type DcrdRPC struct {
Caller
ctx context.Context
}

type DcrdConnect struct {
Expand Down Expand Up @@ -81,7 +80,7 @@ func (d *DcrdConnect) Client() (*DcrdRPC, string, error) {
// If this is a reused connection, we don't need to validate the dcrd config
// again.
if !newConnection {
return &DcrdRPC{c, ctx}, d.client.addr, nil
return &DcrdRPC{c}, d.client.addr, nil
}

// Verify dcrd is at the required api version.
Expand Down Expand Up @@ -139,15 +138,15 @@ func (d *DcrdConnect) Client() (*DcrdRPC, string, error) {

d.log.Debugf("Connected to dcrd")

return &DcrdRPC{c, ctx}, d.client.addr, nil
return &DcrdRPC{c}, d.client.addr, nil
}

// GetRawTransaction uses getrawtransaction RPC to retrieve details about the
// transaction with the provided hash.
func (c *DcrdRPC) GetRawTransaction(txHash string) (*dcrdtypes.TxRawResult, error) {
verbose := 1
var resp dcrdtypes.TxRawResult
err := c.Call(c.ctx, "getrawtransaction", &resp, txHash, verbose)
err := c.Call(context.TODO(), "getrawtransaction", &resp, txHash, verbose)
if err != nil {
return nil, err
}
Expand All @@ -157,7 +156,7 @@ func (c *DcrdRPC) GetRawTransaction(txHash string) (*dcrdtypes.TxRawResult, erro
// DecodeRawTransaction uses decoderawtransaction RPC to decode raw transaction bytes.
func (c *DcrdRPC) DecodeRawTransaction(txHex string) (*dcrdtypes.TxRawDecodeResult, error) {
var resp dcrdtypes.TxRawDecodeResult
err := c.Call(c.ctx, "decoderawtransaction", &resp, txHex)
err := c.Call(context.TODO(), "decoderawtransaction", &resp, txHex)
if err != nil {
return nil, err
}
Expand All @@ -169,7 +168,7 @@ func (c *DcrdRPC) DecodeRawTransaction(txHex string) (*dcrdtypes.TxRawDecodeResu
// the network. It ignores errors caused by duplicate transactions.
func (c *DcrdRPC) SendRawTransaction(txHex string) error {
const allowHighFees = false
err := c.Call(c.ctx, "sendrawtransaction", nil, txHex, allowHighFees)
err := c.Call(context.TODO(), "sendrawtransaction", nil, txHex, allowHighFees)
if err != nil {

// Ignore errors caused by the transaction already existing in the
Expand Down Expand Up @@ -200,7 +199,7 @@ func (c *DcrdRPC) SendRawTransaction(txHex string) error {
// agenda has activated on the current network.
func (c *DcrdRPC) IsDCP0010Active() (bool, error) {
var info dcrdtypes.GetBlockChainInfoResult
err := c.Call(c.ctx, "getblockchaininfo", &info)
err := c.Call(context.TODO(), "getblockchaininfo", &info)
if err != nil {
return false, err
}
Expand All @@ -216,14 +215,14 @@ func (c *DcrdRPC) IsDCP0010Active() (bool, error) {

// NotifyBlocks uses notifyblocks RPC to request new block notifications from dcrd.
func (c *DcrdRPC) NotifyBlocks() error {
return c.Call(c.ctx, "notifyblocks", nil)
return c.Call(context.TODO(), "notifyblocks", nil)
}

// GetBestBlockHeader uses getbestblockhash RPC, followed by getblockheader RPC,
// to retrieve the header of the best block known to the dcrd instance.
func (c *DcrdRPC) GetBestBlockHeader() (*dcrdtypes.GetBlockHeaderVerboseResult, error) {
var bestBlockHash string
err := c.Call(c.ctx, "getbestblockhash", &bestBlockHash)
err := c.Call(context.TODO(), "getbestblockhash", &bestBlockHash)
if err != nil {
return nil, err
}
Expand All @@ -240,7 +239,7 @@ func (c *DcrdRPC) GetBestBlockHeader() (*dcrdtypes.GetBlockHeaderVerboseResult,
func (c *DcrdRPC) GetBlockHeaderVerbose(blockHash string) (*dcrdtypes.GetBlockHeaderVerboseResult, error) {
const verbose = true
var blockHeader dcrdtypes.GetBlockHeaderVerboseResult
err := c.Call(c.ctx, "getblockheader", &blockHeader, blockHash, verbose)
err := c.Call(context.TODO(), "getblockheader", &blockHeader, blockHash, verbose)
if err != nil {
return nil, err
}
Expand All @@ -251,7 +250,7 @@ func (c *DcrdRPC) GetBlockHeaderVerbose(blockHash string) (*dcrdtypes.GetBlockHe
// hash is a live ticket known to the dcrd instance.
func (c *DcrdRPC) ExistsLiveTicket(ticketHash string) (bool, error) {
var exists string
err := c.Call(c.ctx, "existslivetickets", &exists, []string{ticketHash})
err := c.Call(context.TODO(), "existslivetickets", &exists, []string{ticketHash})
if err != nil {
return false, err
}
Expand Down
23 changes: 11 additions & 12 deletions rpc/dcrwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var (
// of JSON encoding.
type WalletRPC struct {
Caller
ctx context.Context
}

type WalletConnect struct {
Expand Down Expand Up @@ -73,7 +72,7 @@ func (w *WalletConnect) Clients() ([]*WalletRPC, []string) {
// If this is a reused connection, we don't need to validate the
// dcrwallet config again.
if !newConnection {
walletClients = append(walletClients, &WalletRPC{c, ctx})
walletClients = append(walletClients, &WalletRPC{c})
continue
}

Expand Down Expand Up @@ -123,7 +122,7 @@ func (w *WalletConnect) Clients() ([]*WalletRPC, []string) {
}

// Verify dcrwallet is voting and unlocked.
walletRPC := &WalletRPC{c, ctx}
walletRPC := &WalletRPC{c}
walletInfo, err := walletRPC.WalletInfo()
if err != nil {
w.log.Errorf("dcrwallet.WalletInfo error (wallet=%s): %v", c.String(), err)
Expand Down Expand Up @@ -160,7 +159,7 @@ func (w *WalletConnect) Clients() ([]*WalletRPC, []string) {
// dcrwallet instance is configured.
func (c *WalletRPC) WalletInfo() (*wallettypes.WalletInfoResult, error) {
var walletInfo wallettypes.WalletInfoResult
err := c.Call(c.ctx, "walletinfo", &walletInfo)
err := c.Call(context.TODO(), "walletinfo", &walletInfo)
if err != nil {
return nil, err
}
Expand All @@ -173,12 +172,12 @@ func (c *WalletRPC) AddTicketForVoting(votingWIF, blockHash, txHex string) error
const label = "imported"
const rescan = false
const scanFrom = 0
err := c.Call(c.ctx, "importprivkey", nil, votingWIF, label, rescan, scanFrom)
err := c.Call(context.TODO(), "importprivkey", nil, votingWIF, label, rescan, scanFrom)
if err != nil {
return fmt.Errorf("importprivkey failed: %w", err)
}

err = c.Call(c.ctx, "addtransaction", nil, blockHash, txHex)
err = c.Call(context.TODO(), "addtransaction", nil, blockHash, txHex)
if err != nil {
return fmt.Errorf("addtransaction failed: %w", err)
}
Expand All @@ -189,14 +188,14 @@ func (c *WalletRPC) AddTicketForVoting(votingWIF, blockHash, txHex string) error
// SetVoteChoice uses setvotechoice RPC to set the vote choice on the given
// agenda, for the given ticket.
func (c *WalletRPC) SetVoteChoice(agenda, choice, ticketHash string) error {
return c.Call(c.ctx, "setvotechoice", nil, agenda, choice, ticketHash)
return c.Call(context.TODO(), "setvotechoice", nil, agenda, choice, ticketHash)
}

// GetBestBlockHeight uses getblockcount RPC to query the height of the best
// block known by the dcrwallet instance.
func (c *WalletRPC) GetBestBlockHeight() (int64, error) {
var height int64
err := c.Call(c.ctx, "getblockcount", &height)
err := c.Call(context.TODO(), "getblockcount", &height)
if err != nil {
return 0, err
}
Expand All @@ -207,7 +206,7 @@ func (c *WalletRPC) GetBestBlockHeight() (int64, error) {
// known by this dcrwallet instance.
func (c *WalletRPC) TicketInfo(startHeight int64) (map[string]*wallettypes.TicketInfoResult, error) {
var result []*wallettypes.TicketInfoResult
err := c.Call(c.ctx, "ticketinfo", &result, startHeight)
err := c.Call(context.TODO(), "ticketinfo", &result, startHeight)
if err != nil {
return nil, err
}
Expand All @@ -225,17 +224,17 @@ func (c *WalletRPC) TicketInfo(startHeight int64) (map[string]*wallettypes.Ticke
// RescanFrom uses rescanwallet RPC to trigger the wallet to perform a rescan
// from the specified block height.
func (c *WalletRPC) RescanFrom(fromHeight int64) error {
return c.Call(c.ctx, "rescanwallet", nil, fromHeight)
return c.Call(context.TODO(), "rescanwallet", nil, fromHeight)
}

// SetTreasuryPolicy sets the specified tickets voting policy for all tspends
// published by the given treasury key.
func (c *WalletRPC) SetTreasuryPolicy(key, policy, ticket string) error {
return c.Call(c.ctx, "settreasurypolicy", nil, key, policy, ticket)
return c.Call(context.TODO(), "settreasurypolicy", nil, key, policy, ticket)
}

// SetTSpendPolicy sets the specified tickets voting policy for a single tspend
// identified by its hash.
func (c *WalletRPC) SetTSpendPolicy(tSpend, policy, ticket string) error {
return c.Call(c.ctx, "settspendpolicy", nil, tSpend, policy, ticket)
return c.Call(context.TODO(), "settspendpolicy", nil, tSpend, policy, ticket)
}
Loading