Skip to content

Commit

Permalink
Fix a few more linting problems
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Jun 20, 2024
1 parent 42181cb commit f66c6d2
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 24 deletions.
9 changes: 5 additions & 4 deletions cmd/soroban-rpc/internal/config/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ type Options []*Option

// Validate all the config options.
func (options Options) Validate() error {
var missingOptions []errMissingRequiredOption
var missingOptions []missingRequiredOptionError
for _, option := range options {
if option.Validate != nil {
err := option.Validate(option)
if err == nil {
continue
}
if missingOption, ok := err.(errMissingRequiredOption); ok {
missingOptions = append(missingOptions, missingOption)
var missingOptionErr missingRequiredOptionError
if ok := errors.As(err, &missingOptionErr); ok {
missingOptions = append(missingOptions, missingOptionErr)
continue
}
return errors.New("Invalid config value for " + option.Name)
Expand All @@ -39,7 +40,7 @@ func (options Options) Validate() error {
errString += "\n*\t" + missingOpt.strErr
errString += "\n \t" + missingOpt.usage
}
return &errMissingRequiredOption{strErr: errString}
return &missingRequiredOptionError{strErr: errString}
}
return nil
}
Expand Down
13 changes: 6 additions & 7 deletions cmd/soroban-rpc/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/sirupsen/logrus"

"github.com/stellar/go/network"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/support/strutils"

"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/ledgerbucketwindow"
Expand Down Expand Up @@ -119,10 +118,10 @@ func (cfg *Config) options() Options {
case nil:
return nil
case string:
return errors.Wrapf(
cfg.LogFormat.UnmarshalText([]byte(v)),
"could not parse %s",
return fmt.Errorf(
"could not parse %s: %w",
option.Name,
cfg.LogFormat.UnmarshalText([]byte(v)),
)
case LogFormat:
cfg.LogFormat = v
Expand Down Expand Up @@ -484,12 +483,12 @@ func (cfg *Config) options() Options {
return *cfg.optionsCache
}

type errMissingRequiredOption struct {
type missingRequiredOptionError struct {
strErr string
usage string
}

func (e errMissingRequiredOption) Error() string {
func (e missingRequiredOptionError) Error() string {
return e.strErr
}

Expand Down Expand Up @@ -527,7 +526,7 @@ func required(option *Option) error {
advice = fmt.Sprintf(" Please %s, %s, or %s.", waysToSet[0], waysToSet[1], waysToSet[2])
}

return errMissingRequiredOption{strErr: fmt.Sprintf("%s is required.%s", option.Name, advice), usage: option.Usage}
return missingRequiredOptionError{strErr: fmt.Sprintf("%s is required.%s", option.Name, advice), usage: option.Usage}
}

func positive(option *Option) error {
Expand Down
4 changes: 1 addition & 3 deletions cmd/soroban-rpc/internal/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"strconv"
"strings"
"time"

"github.com/stellar/go/support/errors"
)

func parseBool(option *Option, i interface{}) error {
Expand Down Expand Up @@ -136,7 +134,7 @@ func parseDuration(option *Option, i interface{}) error {
case string:
d, err := time.ParseDuration(v)
if err != nil {
return errors.Wrapf(err, "could not parse duration: %q", v)
return fmt.Errorf("could not parse duration: %q: %w", v, err)
}
*option.ConfigKey.(*time.Duration) = d
case time.Duration:
Expand Down
1 change: 1 addition & 0 deletions cmd/soroban-rpc/internal/config/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:gochecknoglobals // allow global variables
package config

var (
Expand Down
8 changes: 5 additions & 3 deletions cmd/soroban-rpc/internal/events/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func (c *Cursor) UnmarshalJSON(b []byte) error {
return err
}

if parsed, err := ParseCursor(s); err != nil {
parsed, err := ParseCursor(s)
if err != nil {
return err
} else {
*c = parsed
}
*c = parsed
return nil
}

Expand Down Expand Up @@ -113,8 +113,10 @@ func (c Cursor) Cmp(other Cursor) int {

var (
// MinCursor is the smallest possible cursor
//nolint:gochecknoglobals
MinCursor = Cursor{}
// MaxCursor is the largest possible cursor
//nolint:gochecknoglobals
MaxCursor = Cursor{
Ledger: math.MaxUint32,
Tx: math.MaxUint32,
Expand Down
5 changes: 3 additions & 2 deletions cmd/soroban-rpc/internal/feewindow/feewindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (fw *FeeWindow) AppendLedgerFees(fees ledgerbucketwindow.LedgerBucket[[]uin
}

var allFees []uint64
for i := uint32(0); i < fw.feesPerLedger.Len(); i++ {
for i := range fw.feesPerLedger.Len() {
allFees = append(allFees, fw.feesPerLedger.Get(i).BucketContent...)
}
fw.distribution = computeFeeDistribution(allFees, fw.feesPerLedger.Len())
Expand Down Expand Up @@ -166,7 +166,8 @@ func (fw *FeeWindows) IngestFees(meta xdr.LedgerCloseMeta) error {
continue
}
sorobanFees := tx.UnsafeMeta.V3.SorobanMeta.Ext.V1
resourceFeeCharged := sorobanFees.TotalNonRefundableResourceFeeCharged + sorobanFees.TotalRefundableResourceFeeCharged
resourceFeeCharged := sorobanFees.TotalNonRefundableResourceFeeCharged +
sorobanFees.TotalRefundableResourceFeeCharged
inclusionFee := feeCharged - uint64(resourceFeeCharged)
sorobanInclusionFees = append(sorobanInclusionFees, inclusionFee)
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func PreflightTransactionParamsLocally(t *testing.T, params txnbuild.Transaction
for _, b64 := range response.Results[0].Auth {
var a xdr.SorobanAuthorizationEntry
err := xdr.SafeUnmarshalBase64(b64, &a)
assert.NoError(t, err)
require.NoError(t, err)
auth = append(auth, a)
}
v.Auth = auth
Expand Down
10 changes: 7 additions & 3 deletions cmd/soroban-rpc/internal/methods/get_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package methods
import (
"context"
"encoding/base64"
"errors"
"fmt"
"io"
"strconv"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/creachadair/jrpc2/handler"

"github.com/stellar/go/ingest"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/support/log"
"github.com/stellar/go/toid"

Expand All @@ -38,7 +38,11 @@ func (req GetTransactionsRequest) isValid(maxLimit uint, ledgerRange ledgerbucke
return errors.New("startLedger and cursor cannot both be set")
}
} else if req.StartLedger < ledgerRange.FirstLedger.Sequence || req.StartLedger > ledgerRange.LastLedger.Sequence {
return errors.Errorf("start ledger must be between the oldest ledger: %d and the latest ledger: %d for this rpc instance.", ledgerRange.FirstLedger.Sequence, ledgerRange.LastLedger.Sequence)
return fmt.Errorf(
"start ledger must be between the oldest ledger: %d and the latest ledger: %d for this rpc instance",
ledgerRange.FirstLedger.Sequence,
ledgerRange.LastLedger.Sequence,
)
}

if req.Pagination != nil && req.Pagination.Limit > maxLimit {
Expand Down Expand Up @@ -148,7 +152,7 @@ LedgerLoop:
} else if !found {
return GetTransactionsResponse{}, &jrpc2.Error{
Code: jrpc2.InvalidParams,
Message: errors.Errorf("ledger close meta not found: %d", ledgerSeq).Error(),
Message: fmt.Sprintf("ledger close meta not found: %d", ledgerSeq),
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/network/requestdurationlimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (w *bufferedResponseWriter) WriteOut(ctx context.Context, rw http.ResponseW

// TODO: refactor and simplify this function
//
//nolint:gocognit
//nolint:gocognit,cyclop
func (q *httpRequestDurationLimiter) ServeHTTP(res http.ResponseWriter, req *http.Request) {
if q.limitThreshold == RequestDurationLimiterNoLimit {
// if specified max duration, pass-through
Expand Down

0 comments on commit f66c6d2

Please sign in to comment.