Skip to content

Commit

Permalink
ci: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Jan 10, 2024
1 parent 442e7c8 commit 3ee79e6
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 90 deletions.
8 changes: 4 additions & 4 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ runs:
- name: Configure git # required for golangci-lint on Windows
shell: bash
run: git config --global core.autocrlf false
# - name: Lint
# uses: golangci/golangci-lint-action@v3
# with:
# skip-cache: true
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
skip-cache: true
- name: Analyze
uses: SiaFoundation/action-golang-analysis@HEAD
with:
Expand Down
161 changes: 161 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Based off of the example file at https://github.com/golangci/golangci-lint

# options for analysis running
run:
# default concurrency is a available CPU number
concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 600s

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true

# list of build tags, all linters use it. Default is empty list.
build-tags: []

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
skip-dirs:
- cover

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files: []

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true

# all available settings of specific linters
linters-settings:
## Enabled linters:
govet:
# report about shadowed variables
check-shadowing: false
disable-all: false

tagliatelle:
case:
rules:
json: goCamel
yaml: goCamel


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:
- argOrder # Diagnostic options
- badCond
- caseOrder
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- nilValReturn
- offBy1
- weakCond
- boolExprSimplify # Style options here and below.
- builtinShadow
- emptyFallthrough
- hexLiteral
- underef
- equalFold
revive:
ignore-generated-header: true
rules:
- name: blank-imports
disabled: false
- name: bool-literal-in-expr
disabled: false
- name: confusing-results
disabled: false
- name: constant-logical-expr
disabled: false
- name: context-as-argument
disabled: false
- name: exported
disabled: false
- name: errorf
disabled: false
- name: if-return
disabled: false
- name: indent-error-flow
disabled: false
- name: increment-decrement
disabled: false
- name: modifies-value-receiver
disabled: false
- name: optimize-operands-order
disabled: false
- name: range-val-in-closure
disabled: false
- name: struct-tag
disabled: false
- name: superfluous-else
disabled: false
- name: time-equal
disabled: false
- name: unexported-naming
disabled: false
- name: unexported-return
disabled: false
- name: unnecessary-stmt
disabled: false
- name: unreachable-code
disabled: false
- name: package-comments
disabled: true

linters:
disable-all: true
fast: false
enable:
- tagliatelle
- gocritic
- gofmt
- revive
- govet
- misspell
- typecheck
- whitespace

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
exclude: []

# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.
# Default value for this option is true.
exclude-use-default: false
3 changes: 3 additions & 0 deletions persist/sqlite/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func updateElementProofs(tx txn, table string, updater proofUpdater) error {
return nil
}

// applyChainUpdates applies the given chain updates to the database.
func applyChainUpdates(tx txn, updates []*chain.ApplyUpdate) error {
stmt, err := tx.Prepare(`SELECT id FROM sia_addresses WHERE sia_address=$1 LIMIT 1`)
if err != nil {
Expand Down Expand Up @@ -399,6 +400,7 @@ func applyChainUpdates(tx txn, updates []*chain.ApplyUpdate) error {
return nil
}

// ProcessChainApplyUpdate implements chain.Subscriber
func (s *Store) ProcessChainApplyUpdate(cau *chain.ApplyUpdate, mayCommit bool) error {
s.updates = append(s.updates, cau)

Expand All @@ -414,6 +416,7 @@ func (s *Store) ProcessChainApplyUpdate(cau *chain.ApplyUpdate, mayCommit bool)
return nil
}

// ProcessChainRevertUpdate implements chain.Subscriber
func (s *Store) ProcessChainRevertUpdate(cru *chain.RevertUpdate) error {
// update hasn't been committed yet
if len(s.updates) > 0 && s.updates[len(s.updates)-1].Block.ID() == cru.Block.ID() {
Expand Down
1 change: 1 addition & 0 deletions persist/sqlite/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type decodable[T types.DecoderFrom] struct {
n int64
}

// Scan implements the sql.Scanner interface.
func (d *decodable[T]) Scan(src any) error {
switch src := src.(type) {
case []byte:
Expand Down
12 changes: 12 additions & 0 deletions persist/sqlite/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RETURNING id`
return
}

// WalletEvents returns the events relevant to a wallet, sorted by height descending.
func (s *Store) WalletEvents(walletID string, offset, limit int) (events []wallet.Event, err error) {
err = s.transaction(func(tx txn) error {
const query = `SELECT ev.id, ev.date_created, ci.height, ci.block_id, ev.event_type, ev.event_data
Expand Down Expand Up @@ -76,6 +77,7 @@ LIMIT $2 OFFSET $3`
return
}

// AddWallet adds a wallet to the database.
func (s *Store) AddWallet(name string, info json.RawMessage) error {
return s.transaction(func(tx txn) error {
const query = `INSERT INTO wallets (id, extra_data) VALUES ($1, $2)`
Expand All @@ -88,13 +90,16 @@ func (s *Store) AddWallet(name string, info json.RawMessage) error {
})
}

// DeleteWallet deletes a wallet from the database. This does not stop tracking
// addresses that were previously associated with the wallet.
func (s *Store) DeleteWallet(name string) error {
return s.transaction(func(tx txn) error {
_, err := tx.Exec(`DELETE FROM wallets WHERE id=$1`, name)
return err
})
}

// Wallets returns a map of wallet names to wallet extra data.
func (s *Store) Wallets() (map[string]json.RawMessage, error) {
wallets := make(map[string]json.RawMessage)
err := s.transaction(func(tx txn) error {
Expand All @@ -119,6 +124,7 @@ func (s *Store) Wallets() (map[string]json.RawMessage, error) {
return wallets, err
}

// AddAddress adds an address to a wallet.
func (s *Store) AddAddress(walletID string, address types.Address, info json.RawMessage) error {
return s.transaction(func(tx txn) error {
addressID, err := insertAddress(tx, address)
Expand All @@ -130,6 +136,8 @@ func (s *Store) AddAddress(walletID string, address types.Address, info json.Raw
})
}

// RemoveAddress removes an address from a wallet. This does not stop tracking
// the address.
func (s *Store) RemoveAddress(walletID string, address types.Address) error {
return s.transaction(func(tx txn) error {
const query = `DELETE FROM wallet_addresses WHERE wallet_id=$1 AND address_id=(SELECT id FROM sia_addresses WHERE sia_address=$2)`
Expand All @@ -138,6 +146,7 @@ func (s *Store) RemoveAddress(walletID string, address types.Address) error {
})
}

// Addresses returns a map of addresses to their extra data for a wallet.
func (s *Store) Addresses(walletID string) (map[types.Address]json.RawMessage, error) {
addresses := make(map[types.Address]json.RawMessage)
err := s.transaction(func(tx txn) error {
Expand Down Expand Up @@ -165,6 +174,7 @@ WHERE wa.wallet_id=$1`
return addresses, err
}

// UnspentSiacoinOutputs returns the unspent siacoin outputs for a wallet.
func (s *Store) UnspentSiacoinOutputs(walletID string) (siacoins []types.SiacoinElement, err error) {
err = s.transaction(func(tx txn) error {
const query = `SELECT se.id, se.leaf_index, se.merkle_proof, se.siacoin_value, sa.sia_address, se.maturity_height
Expand Down Expand Up @@ -193,6 +203,7 @@ func (s *Store) UnspentSiacoinOutputs(walletID string) (siacoins []types.Siacoin
return
}

// UnspentSiafundOutputs returns the unspent siafund outputs for a wallet.
func (s *Store) UnspentSiafundOutputs(walletID string) (siafunds []types.SiafundElement, err error) {
err = s.transaction(func(tx txn) error {
const query = `SELECT se.id, se.leaf_index, se.merkle_proof, se.siafund_value, se.claim_start, sa.sia_address
Expand Down Expand Up @@ -257,6 +268,7 @@ func (s *Store) AddressBalance(address types.Address) (sc types.Currency, sf uin
return
}

// Annotate annotates a list of transactions using the wallet's addresses.
func (s *Store) Annotate(walletID string, txns []types.Transaction) (annotated []wallet.PoolTransaction, err error) {
err = s.transaction(func(tx txn) error {
stmt, err := tx.Prepare(`SELECT sia_address FROM wallet_addresses WHERE wallet_id=$1 AND sia_address=$2 LIMIT 1`)
Expand Down
2 changes: 2 additions & 0 deletions wallet/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import (
)

type (
// A ChainManager manages the consensus state
ChainManager interface {
AddSubscriber(chain.Subscriber, types.ChainIndex) error
RemoveSubscriber(chain.Subscriber)

BestIndex(height uint64) (types.ChainIndex, bool)
}

// A Store is a persistent store of wallet data.
Store interface {
chain.Subscriber

Expand Down
83 changes: 0 additions & 83 deletions wallet/state.go

This file was deleted.

Loading

0 comments on commit 3ee79e6

Please sign in to comment.