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

Commit

Permalink
Fixed lots of linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Apr 2, 2024
1 parent 2c7c914 commit 765967a
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 25 deletions.
8 changes: 4 additions & 4 deletions beef_bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ func checkParentTransactions(ctx context.Context, store TransactionGetter, btTx
return validBtTxs, validTxs, nil
}

func getRequiredTransactions(ctx context.Context, txIds []string, store TransactionGetter) ([]*Transaction, error) {
txs, err := store.GetTransactionsByIDs(ctx, txIds)
func getRequiredTransactions(ctx context.Context, txIDs []string, store TransactionGetter) ([]*Transaction, error) {
txs, err := store.GetTransactionsByIDs(ctx, txIDs)
if err != nil {
return nil, fmt.Errorf("cannot get transactions from database: %w", err)
}

if len(txs) != len(txIds) {
missingTxIDs := getMissingTxs(txIds, txs)
if len(txs) != len(txIDs) {
missingTxIDs := getMissingTxs(txIDs, txs)
return nil, fmt.Errorf("required transactions not found in database: %v", missingTxIDs)
}

Expand Down
4 changes: 4 additions & 0 deletions beef_tx_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import (
"context"
)

// MockTransactionStore is a mock implementation of the TransactionStore interface
type MockTransactionStore struct {
Transactions map[string]*Transaction
}

// NewMockTransactionStore creates a new instance of the MockTransactionStore
func NewMockTransactionStore() *MockTransactionStore {
return &MockTransactionStore{
Transactions: make(map[string]*Transaction),
}
}

// AddToStore adds a transaction to the store
func (m *MockTransactionStore) AddToStore(tx *Transaction) {
m.Transactions[tx.ID] = tx
}

// GetTransactionsByIDs returns transactions by their IDs
func (m *MockTransactionStore) GetTransactionsByIDs(ctx context.Context, txIDs []string) ([]*Transaction, error) {
var txs []*Transaction
for _, txID := range txIDs {
Expand Down
4 changes: 2 additions & 2 deletions beef_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func Test_ToBeef_ErrorPaths(t *testing.T) {
}
}

func createProcessedTx(ctx context.Context, t *testing.T, client ClientInterface, testCase *beefTestCase, ancestors []*Transaction) *Transaction {
func createProcessedTx(_ context.Context, t *testing.T, client ClientInterface, testCase *beefTestCase, ancestors []*Transaction) *Transaction {
draftTx := newDraftTransaction(
testXPub, &TransactionConfig{
Inputs: createInputsUsingAncestors(ancestors, client),
Expand Down Expand Up @@ -323,7 +323,7 @@ func addAncestor(ctx context.Context, testCase *beefTestCaseAncestor, client Cli
ancestor.BlockHeight = uint64(testCase.blockHeight)

var bump BUMP
err := json.Unmarshal([]byte(testCase.bumpJSON), &bump)
err = json.Unmarshal([]byte(testCase.bumpJSON), &bump)
require.NoError(t, err)
ancestor.BUMP = bump
} else {
Expand Down
2 changes: 1 addition & 1 deletion bux_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bux
import (
"context"
"fmt"
"github.com/rs/zerolog"
"sync"
"testing"
"time"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/dolthub/go-mysql-server/server"
embeddedPostgres "github.com/fergusstrange/embedded-postgres"
"github.com/mrz1836/go-datastore"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/tryvium-travels/memongo"
Expand Down
2 changes: 1 addition & 1 deletion chainstate/minercraft_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (i *minercraftInitializer) getFeeQuote(ctx context.Context, miner *minercra

quote, err := c.Minercraft().FeeQuote(ctx, miner)
if err != nil {
return nil, fmt.Errorf("no FeeQuote response from miner %s. Reason: %s", miner.Name, err)
return nil, fmt.Errorf("no FeeQuote response from miner %s. Reason: %w", miner.Name, err)
}

btFee := quote.Quote.GetFee(mapi.FeeTypeData)
Expand Down
4 changes: 2 additions & 2 deletions chainstate/transaction_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type TransactionInfo struct {
// BlockHash and MerkleProof (from mAPI) or BUMP (from Arc)
func (t *TransactionInfo) Valid() bool {
arcInvalid := t.BUMP == nil
mApiInvalid := t.MerkleProof == nil || t.MerkleProof.TxOrID == "" || len(t.MerkleProof.Nodes) == 0
invalid := t.BlockHash == "" || (arcInvalid && mApiInvalid)
mAPIInvalid := t.MerkleProof == nil || t.MerkleProof.TxOrID == "" || len(t.MerkleProof.Nodes) == 0
invalid := t.BlockHash == "" || (arcInvalid && mAPIInvalid)
return !invalid
}
1 change: 1 addition & 0 deletions logging/adapters.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package logging is the logging package
package logging

import (
Expand Down
2 changes: 1 addition & 1 deletion metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (m *Metrics) TrackQueryTransaction() EndWithClassification {
func (m *Metrics) TrackCron(name string) EndWithClassification {
start := time.Now()
m.cronLastExecution.WithLabelValues(name).Set(float64(start.Unix()))
return func(success bool) {
return func(_ bool) {
m.cronHistogram.WithLabelValues(name).Observe(time.Since(start).Seconds())
}
}
Expand Down
4 changes: 2 additions & 2 deletions model_destinations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (ts *EmbeddedDBTestSuite) TestDestination_Save() {
assert.Equal(t, true, setCmd.Called)
})

ts.T().Run("[mongo] [redis] [mocking] - create destination", func(t *testing.T) {
/*ts.T().Run("[mongo] [redis] [mocking] - create destination", func(t *testing.T) {
// todo: mocking for MongoDB
})
})*/
}
4 changes: 2 additions & 2 deletions model_xpubs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (ts *EmbeddedDBTestSuite) TestXpub_Save() {
assert.Equal(t, true, setCmd.Called)
})

ts.T().Run("[mongo] [redis] [mocking] - create xpub", func(t *testing.T) {
/*ts.T().Run("[mongo] [redis] [mocking] - create xpub", func(t *testing.T) {
// todo: mocking for MongoDB
})
})*/
}
3 changes: 2 additions & 1 deletion paymail.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"errors"
"fmt"
"strings"

"github.com/bitcoin-sv/go-paymail"
"github.com/mrz1836/go-cachestore"
"strings"
)

// getCapabilities is a utility function to retrieve capabilities for a Paymail provider
Expand Down
2 changes: 1 addition & 1 deletion paymail_service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (p *PaymailDefaultServiceProvider) RecordTransaction(ctx context.Context,
if err != nil {
return nil, err
}
if err := rts.Validate(); err != nil {
if err = rts.Validate(); err != nil {
return nil, err
}

Expand Down
3 changes: 2 additions & 1 deletion sync_tx_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func broadcastSyncTransaction(ctx context.Context, syncTx *SyncTransaction) erro
txHex = syncTx.transaction.Hex
} else {
// else get hex from DB
transaction, err := getTransactionByID(
var transaction *Transaction
transaction, err = getTransactionByID(
ctx, "", syncTx.ID, syncTx.GetOptions(false)...,
)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions taskmanager/cron_jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestCronTasks(t *testing.T) {
err := tm.CronJobsInit(CronJobs{
"test": {
Period: 1 * time.Second,
Handler: func(ctx context.Context) error {
Handler: func(_ context.Context) error {
target.times <- true
return nil
},
Expand Down Expand Up @@ -62,14 +62,14 @@ func TestCronTasks(t *testing.T) {
err := tm.CronJobsInit(CronJobs{
"test1": {
Period: 1 * time.Second,
Handler: func(ctx context.Context) error {
Handler: func(_ context.Context) error {
target.times <- 1
return nil
},
},
"test2": {
Period: 1 * time.Second,
Handler: func(ctx context.Context) error {
Handler: func(_ context.Context) error {
target.times <- 2
return nil
},
Expand Down
6 changes: 3 additions & 3 deletions taskmanager/taskq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ func TestNewTaskManager_RegisterTwice(t *testing.T) {
task1Arg := "task d"
resultChan := make(chan int, 1)

err := c.RegisterTask(task1Arg, func(name string) error {
err := c.RegisterTask(task1Arg, func(_ string) error {
resultChan <- 1
return nil
})
require.NoError(t, err)

err = c.RegisterTask(task1Arg, func(name string) error {
err = c.RegisterTask(task1Arg, func(_ string) error {
resultChan <- 2
return nil
})
Expand All @@ -119,7 +119,7 @@ func TestNewTaskManager_RunTwice(t *testing.T) {

task1Arg := "task e"

err := c.RegisterTask(task1Arg, func(name string) error {
err := c.RegisterTask(task1Arg, func(_ string) error {
return nil
})
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ func find[E any](collection []E, predicate func(E) bool) *E {
return nil
}

func contains[E any](collection []E, predicate func(E) bool) bool{
func contains[E any](collection []E, predicate func(E) bool) bool {
return find(collection, predicate) != nil
}

0 comments on commit 765967a

Please sign in to comment.