mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 23:16:49 +00:00
* tag optional sonic and allow full library conversion * Add workflow and disallow arm and darwin usage * Add basic hotswap benchmark * linter: fix * use bash * linter: fix? * Fix whoopsie, add to make file, also add mention in features list. * test enforcement * actually read documentation see if this works * linter: fix * linter: fix * sonic: bump tagged version * encoding/json: drop build tag arch and os filters * encoding/json: consolidate tests * encoding/json: log build tag usage * rm superfluous builds * glorious/nits: add template change and regen docs * glorious/nits: update commentary on nolint directive * glorious/nits: rm init func and log results in main.go * Test to actually pull flag in * linter: fix * thrasher: nits * gk: nits 4 goflags goooooooooo! * gk: nits rn * make sonic default json implementation * screen 386 * linter: fix * Add commentary * glorious: nits Makefile not working * gk: nits * gk: nits whoops * whoopsirino * mention 32bit systems won't be sonic * gk: super-duper nit of extremes --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package versions
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/buger/jsonparser"
|
|
v0 "github.com/thrasher-corp/gocryptotrader/config/versions/v0"
|
|
v1 "github.com/thrasher-corp/gocryptotrader/config/versions/v1"
|
|
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
|
)
|
|
|
|
// Version1 is an ExchangeVersion to upgrade currency pair format for exchanges
|
|
type Version1 struct {
|
|
}
|
|
|
|
func init() {
|
|
Manager.registerVersion(1, &Version1{})
|
|
}
|
|
|
|
// Exchanges returns all exchanges: "*"
|
|
func (v *Version1) Exchanges() []string { return []string{"*"} }
|
|
|
|
// UpgradeExchange will upgrade currency pair format
|
|
func (v *Version1) UpgradeExchange(_ context.Context, e []byte) ([]byte, error) {
|
|
if _, d, _, err := jsonparser.Get(e, "currencyPairs"); err == nil && d == jsonparser.Object {
|
|
return e, nil
|
|
}
|
|
|
|
d := &v0.Exchange{}
|
|
if err := json.Unmarshal(e, d); err != nil {
|
|
return e, err
|
|
}
|
|
|
|
p := &v1.PairsManager{
|
|
UseGlobalFormat: true,
|
|
LastUpdated: d.PairsLastUpdated,
|
|
ConfigFormat: d.ConfigCurrencyPairFormat,
|
|
RequestFormat: d.RequestCurrencyPairFormat,
|
|
Pairs: v1.FullStore{
|
|
"spot": {
|
|
Available: d.AvailablePairs,
|
|
Enabled: d.EnabledPairs,
|
|
},
|
|
},
|
|
}
|
|
j, err := json.Marshal(p)
|
|
if err != nil {
|
|
return e, err
|
|
}
|
|
for _, f := range []string{"pairsLastUpdated", "configCurrencyPairFormat", "requestCurrencyPairFormat", "assetTypes", "availablePairs", "enabledPairs"} {
|
|
e = jsonparser.Delete(e, f)
|
|
}
|
|
return jsonparser.Set(e, j, "currencyPairs")
|
|
}
|
|
|
|
// DowngradeExchange doesn't do anything for v1; There's no downgrade path since the original state is lossy and v1 was before versioning
|
|
func (v *Version1) DowngradeExchange(_ context.Context, e []byte) ([]byte, error) {
|
|
return e, nil
|
|
}
|