diff --git a/config/versions/fixtures_test.go b/config/versions/fixtures_test.go index 44123bdacf8..19f8cc4e460 100644 --- a/config/versions/fixtures_test.go +++ b/config/versions/fixtures_test.go @@ -55,20 +55,3 @@ func (v *TestVersion2) DowngradeExchange(_ context.Context, e []byte) ([]byte, e } return e, nil } - -// TestVersion3 is a Disabled fixture -type TestVersion3 struct { -} - -// Disabled implements the DisabledVersion interface -func (v *TestVersion3) Disabled() {} - -// UpgradeConfig implements the ConfigdVersion interface -func (v *TestVersion3) UpgradeConfig(_ context.Context, c []byte) ([]byte, error) { - return c, nil -} - -// DowngradeConfig implements the ConfigdVersion interface -func (v *TestVersion3) DowngradeConfig(_ context.Context, c []byte) ([]byte, error) { - return c, nil -} diff --git a/config/versions/import.go b/config/versions/import.go deleted file mode 100644 index 0a7cbb2221f..00000000000 --- a/config/versions/import.go +++ /dev/null @@ -1,43 +0,0 @@ -package versions - -import ( - "fmt" - "reflect" - "strconv" - "strings" - "unsafe" - - "github.com/thrasher-corp/gocryptotrader/common" -) - -//go:linkname typelinks reflect.typelinks -func typelinks() (sections []unsafe.Pointer, offset [][]int32) - -//go:linkname add reflect.add -func add(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer - -func init() { - exchangeVersion := reflect.TypeFor[ExchangeVersion]() - configVersion := reflect.TypeFor[ConfigVersion]() - sections, offsets := typelinks() - for i, base := range sections { - for _, offset := range offsets[i] { - typeAddr := add(base, uintptr(offset), "") - typ := reflect.TypeOf(*(*interface{})(unsafe.Pointer(&typeAddr))) - if typ.Implements(exchangeVersion) || typ.Implements(configVersion) { - v := reflect.New(typ.Elem()).Interface() - verTyp := fmt.Sprintf("%T", v) - verTyp = strings.TrimPrefix(verTyp, "*versions.") - if strings.HasPrefix(verTyp, "TestVersion") { - continue - } - verTyp = strings.TrimPrefix(verTyp, "Version") - if ver, err := strconv.Atoi(verTyp); err != nil { - Manager.errors = common.AppendError(Manager.errors, fmt.Errorf("%w '%T': %w", errRegisteringVersion, v, err)) - } else { - Manager.registerVersion(ver, v) - } - } - } - } -} diff --git a/config/versions/v0.go b/config/versions/v0.go index 241af1b1d2b..9d29aea79a5 100644 --- a/config/versions/v0.go +++ b/config/versions/v0.go @@ -9,6 +9,10 @@ import ( type Version0 struct { } +func init() { + Manager.registerVersion(0, &Version0{}) +} + // UpgradeConfig is an empty stub func (v *Version0) UpgradeConfig(_ context.Context, j []byte) ([]byte, error) { return j, nil diff --git a/config/versions/v1.go b/config/versions/v1.go index ce172dc0448..378d6c35c9f 100644 --- a/config/versions/v1.go +++ b/config/versions/v1.go @@ -13,6 +13,10 @@ import ( type Version1 struct { } +func init() { + Manager.registerVersion(1, &Version1{}) +} + // Exchanges returns all exchanges: "*" func (v *Version1) Exchanges() []string { return []string{"*"} } diff --git a/config/versions/v2.go b/config/versions/v2.go index c0ea8da0bde..d2ebea68198 100644 --- a/config/versions/v2.go +++ b/config/versions/v2.go @@ -9,6 +9,10 @@ import ( // Version2 is an ExchangeVersion to change the name of GDAX to CoinbasePro type Version2 struct{} +func init() { + Manager.registerVersion(2, &Version2{}) +} + const ( from = "GDAX" to = "CoinbasePro" diff --git a/config/versions/versions.go b/config/versions/versions.go index d845c0e9b44..34eabf108f3 100644 --- a/config/versions/versions.go +++ b/config/versions/versions.go @@ -8,8 +8,6 @@ versions handles config upgrades and downgrades - Versions must be registered in import.go - Versions must implement ExchangeVersion or ConfigVersion, and may implement both - - - Versions implementing DisabledVersion will be silently ignored, but must be the highest version numbers to avoid errVersionSequence */ package versions @@ -35,11 +33,6 @@ var ( errApplyingVersion = errors.New("error applying version") ) -// DisabledVersion allows authors to rollback changes easily during development -type DisabledVersion interface { - Disabled() -} - // ConfigVersion is a version that affects the general configuration type ConfigVersion interface { UpgradeConfig(context.Context, []byte) ([]byte, error) @@ -173,11 +166,10 @@ func exchangeDeploy(ctx context.Context, patch ExchangeVersion, method func(Exch // Versions should be added sequentially without gaps, in import.go init // Any errors will also added to the registry for reporting later func (m *manager) registerVersion(ver int, v any) { + log.Println("Registering version") m.m.Lock() defer m.m.Unlock() switch v.(type) { - case DisabledVersion: - return case ExchangeVersion, ConfigVersion: default: m.errors = common.AppendError(m.errors, fmt.Errorf("%w: %v", errVersionIncompatible, ver)) @@ -187,6 +179,7 @@ func (m *manager) registerVersion(ver int, v any) { m.errors = common.AppendError(m.errors, fmt.Errorf("%w: %v", errVersionSequence, ver)) return } + log.Println("Registering version: done") m.versions = append(m.versions, v) } diff --git a/config/versions/versions_test.go b/config/versions/versions_test.go index a2c9967d358..643bffbfb06 100644 --- a/config/versions/versions_test.go +++ b/config/versions/versions_test.go @@ -93,11 +93,6 @@ func TestRegisterVersion(t *testing.T) { m.registerVersion(2, &TestVersion2{}) assert.ErrorIs(t, m.errors, errVersionSequence) assert.ErrorContains(t, m.errors, ": 2") - - m.errors = nil - m.registerVersion(3, &TestVersion3{}) - assert.NoError(t, m.errors) - assert.Len(t, m.versions, 1, "Disabled Versions should not be registered") } func TestLatest(t *testing.T) {