Skip to content

Commit

Permalink
Address gk's nitters and fix additional linter issue after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Feb 28, 2025
1 parent 75ee9bd commit 9c98fb6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 deletions.
9 changes: 4 additions & 5 deletions config/config_encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (c *Config) decryptConfigData(d, key []byte) ([]byte, error) {
} else {
d = d[len(encryptionVersionPrefix):]
switch ver := binary.BigEndian.Uint16(d[:versionSize]); ver {
case 1: // TODO: Add support for version migration
case 1: // TODO: Intertwine this with the existing config versioning system
d = d[versionSize:]
ciphertext, err = decryptAESGCMCiphertext(d, key)
if err != nil {
Expand All @@ -200,7 +200,7 @@ func (c *Config) decryptConfigData(d, key []byte) ([]byte, error) {
return ciphertext, nil
}

// decryptAESGCMCiphertext attempts to decrypt the ciphertext using AES-GCM
// decryptAESGCMCiphertext decrypts the ciphertext using AES-GCM
func decryptAESGCMCiphertext(data, key []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
Expand All @@ -212,11 +212,10 @@ func decryptAESGCMCiphertext(data, key []byte) ([]byte, error) {
return nil, err
}

plaintext, err := cipherAEAD.Open(nil, nil, data, nil)
return plaintext, err
return cipherAEAD.Open(nil, nil, data, nil)
}

// decryptAESCFBCiphertext attempts to decrypt the ciphertext using AES-CFB (legacy mode)
// decryptAESCFBCiphertext decrypts the ciphertext using AES-CFB (legacy mode)
func decryptAESCFBCiphertext(data, key []byte) ([]byte, error) {
if len(data) < aes.BlockSize {
return nil, errAESBlockSize
Expand Down
6 changes: 3 additions & 3 deletions config/config_encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestPromptForConfigKey(t *testing.T) {
})
}

func TestEncryptConfigFile(t *testing.T) {
func TestEncryptConfigData(t *testing.T) {
t.Parallel()
_, err := EncryptConfigData([]byte("test"), nil)
require.ErrorIs(t, err, errKeyIsEmpty)
Expand All @@ -87,7 +87,7 @@ func TestEncryptConfigFile(t *testing.T) {
require.NoError(t, err)
}

func TestDecryptConfigFile(t *testing.T) {
func TestDecryptConfigData(t *testing.T) {
t.Parallel()
e, err := EncryptConfigData([]byte(`{"test":1}`), []byte("key"))
require.NoError(t, err)
Expand All @@ -106,7 +106,7 @@ func TestDecryptConfigFile(t *testing.T) {
require.ErrorIs(t, err, errAESBlockSize)

sessionDK, salt, err := makeNewSessionDK([]byte("key"))
require.NoError(t, err)
require.NoError(t, err, "makeNewSessionDK must not error")

encData, err := legacyEncrypt(t, salt, []byte(`{"test":123}`), sessionDK)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion encoding/json/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "testing"
// BenchmarkUnmarshal-16 1859184 653.3 ns/op 900 B/op 18 allocs/op (bytedance/sonic) Usage: go test --tags=sonic -bench=BenchmarkUnmarshal -v
func BenchmarkUnmarshal(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = Unmarshal([]byte(`{"Name":"Wednesday","Age":6,"Parents":["Gomez","Morticia"]}`), &map[string]interface{}{})
}
}
3 changes: 2 additions & 1 deletion exchanges/bithumb/bithumb.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
Expand Down Expand Up @@ -244,7 +245,7 @@ func (b *Bithumb) GetAccountBalance(ctx context.Context, c string) (FullBalance,
return fullBalance, err
}
default:
return fullBalance, fmt.Errorf("unhandled type %T", v)
return fullBalance, common.GetTypeAssertError("float64|string", datum)
}

switch splitTag[0] {
Expand Down
48 changes: 20 additions & 28 deletions exchanges/kline/kline.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,41 +482,33 @@ func CalculateCandleDateRanges(start, end time.Time, interval Interval, limit ui
return nil, common.ErrStartEqualsEnd
}

intervals := make([]IntervalData, 0, count)
for iStart := start; iStart.Before(end); iStart = iStart.Add(interval.Duration()) {
intervals = append(intervals, IntervalData{
Start: CreateIntervalTime(iStart),
End: CreateIntervalTime(iStart.Add(interval.Duration())),
})
}

if limit == 0 {
limit = count
}

requests := (count + limit - 1) / limit

ranges := make([]IntervalRange, requests)
requestStart := start
remaining := count

for x := range ranges {
current := limit
if remaining < limit {
current = remaining
}

ranges[x].Start = CreateIntervalTime(requestStart)
ranges[x].Intervals = make([]IntervalData, current)

for y := range ranges[x].Intervals {
ranges[x].Intervals[y].Start = CreateIntervalTime(requestStart)
requestStart = requestStart.Add(interval.Duration())
ranges[x].Intervals[y].End = CreateIntervalTime(requestStart)
}
h := &IntervalRangeHolder{
Start: CreateIntervalTime(start),
End: CreateIntervalTime(end),
Limit: limit,
}

ranges[x].End = CreateIntervalTime(requestStart)
remaining -= current
for _, b := range common.Batch(intervals, int(limit)) { //nolint:gosec // Ignore this warning as Batch requires int
h.Ranges = append(h.Ranges, IntervalRange{
Start: b[0].Start,
End: b[len(b)-1].End,
Intervals: b,
})
}

return &IntervalRangeHolder{
Start: CreateIntervalTime(start),
End: CreateIntervalTime(requestStart),
Ranges: ranges,
Limit: limit,
}, nil
return h, nil
}

// HasDataAtDate determines whether a there is any data at a set
Expand Down

0 comments on commit 9c98fb6

Please sign in to comment.