From 8862c24fc049c047efb039a8d5a730f56fb7b764 Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Sat, 16 Dec 2023 14:07:01 +0100 Subject: [PATCH] Deprecate BUSD --- README.md | 4 --- internal/money/money.go | 1 + .../server/http/merchantapi/merchant_test.go | 2 +- .../server/http/paymentapi/payment_test.go | 2 +- internal/service/blockchain/currencies.go | 26 +++++++++++++++++-- internal/service/blockchain/currencies.json | 3 ++- internal/service/merchant/service.go | 4 +-- 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ce7ad25..c87f5ea 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,6 @@ Receive crypto including stablecoins with ease. Open new opportunities for your usdc
USDC
- - busd -
BUSD
- diff --git a/internal/money/money.go b/internal/money/money.go index 7495751..929ad6e 100644 --- a/internal/money/money.go +++ b/internal/money/money.go @@ -83,6 +83,7 @@ type CryptoCurrency struct { TokenContractAddress string TestTokenContractAddress string Aliases []string + Deprecated bool } func (c CryptoCurrency) DisplayName() string { diff --git a/internal/server/http/merchantapi/merchant_test.go b/internal/server/http/merchantapi/merchant_test.go index 24f82f2..5bb9e46 100644 --- a/internal/server/http/merchantapi/merchant_test.go +++ b/internal/server/http/merchantapi/merchant_test.go @@ -91,7 +91,7 @@ func TestMerchantRoutes(t *testing.T) { mt, _ := tc.Must.CreateMerchant(t, user.ID) // And blockchain currencies - allCurrencies := tc.Services.Blockchain.ListSupportedCurrencies() + allCurrencies := tc.Services.Blockchain.ListSupportedCurrencies(false) // ACT 1 // Get merchant diff --git a/internal/server/http/paymentapi/payment_test.go b/internal/server/http/paymentapi/payment_test.go index b399b80..b2309b9 100644 --- a/internal/server/http/paymentapi/payment_test.go +++ b/internal/server/http/paymentapi/payment_test.go @@ -30,7 +30,7 @@ const ( func TestHandlers(t *testing.T) { tc := test.NewIntegrationTest(t) - allCurrencies := tc.Services.Blockchain.ListSupportedCurrencies() + allCurrencies := tc.Services.Blockchain.ListSupportedCurrencies(false) t.Run("GetSupportedMethods", func(t *testing.T) { t.Run("Returns list of supported methods", func(t *testing.T) { diff --git a/internal/service/blockchain/currencies.go b/internal/service/blockchain/currencies.go index 10c00a2..9acd3e4 100644 --- a/internal/service/blockchain/currencies.go +++ b/internal/service/blockchain/currencies.go @@ -17,7 +17,7 @@ import ( ) type Resolver interface { - ListSupportedCurrencies() []money.CryptoCurrency + ListSupportedCurrencies(withDeprecated bool) []money.CryptoCurrency ListBlockchainCurrencies(blockchain money.Blockchain) []money.CryptoCurrency GetCurrencyByTicker(ticker string) (money.CryptoCurrency, error) GetNativeCoin(blockchain money.Blockchain) (money.CryptoCurrency, error) @@ -138,12 +138,16 @@ func (r *CurrencyResolver) GetCurrencyByBlockchainAndContract(bc money.Blockchai return money.CryptoCurrency{}, ErrCurrencyNotFound } -func (r *CurrencyResolver) ListSupportedCurrencies() []money.CryptoCurrency { +func (r *CurrencyResolver) ListSupportedCurrencies(withDeprecated bool) []money.CryptoCurrency { r.mu.RLock() defer r.mu.RUnlock() results := make([]money.CryptoCurrency, 0) for i := range r.currencies { + if r.currencies[i].Deprecated && !withDeprecated { + continue + } + results = append(results, r.currencies[i]) } @@ -181,6 +185,10 @@ func (r *CurrencyResolver) addCurrency(currency money.CryptoCurrency) { r.ensureIndices(currency.Blockchain, currency.Ticker) + if currency.Deprecated { + return + } + // add currency to "index" r.blockchainCurrencies[currency.Blockchain][currency.Ticker] = struct{}{} @@ -281,6 +289,11 @@ func DefaultSetup(s *CurrencyResolver) error { return err } + deprecated, err := parseBool(c["deprecated"]) + if err != nil { + return err + } + ticker := c["ticker"] s.addCurrency(money.CryptoCurrency{ @@ -295,6 +308,7 @@ func DefaultSetup(s *CurrencyResolver) error { TestTokenContractAddress: testTokenAddr, Aliases: aliases, Decimals: int64(decimals), + Deprecated: deprecated, }) s.addMinimalWithdrawal(ticker, minimalWithdrawal) @@ -372,6 +386,14 @@ func parseUSD(raw string) (money.Money, error) { return money.FiatFromFloat64(money.USD, f) } +func parseBool(raw string) (bool, error) { + if raw == "" { + return false, nil + } + + return strconv.ParseBool(raw) +} + func parseAliases(raw string) []string { if raw == "" { return nil diff --git a/internal/service/blockchain/currencies.json b/internal/service/blockchain/currencies.json index 90ed399..0564f46 100644 --- a/internal/service/blockchain/currencies.json +++ b/internal/service/blockchain/currencies.json @@ -140,6 +140,7 @@ "networkId": "56", "testNetworkId": "97", "minimal_withdrawal_amount_usd": "10", - "minimal_instant_internal_transfer_amount_usd": "30" + "minimal_instant_internal_transfer_amount_usd": "30", + "deprecated": "true" } ] \ No newline at end of file diff --git a/internal/service/merchant/service.go b/internal/service/merchant/service.go index 3ded993..616c2c6 100644 --- a/internal/service/merchant/service.go +++ b/internal/service/merchant/service.go @@ -157,7 +157,7 @@ type SupportedCurrency struct { } func (s *Service) ListSupportedCurrencies(_ context.Context, merchant *Merchant) ([]SupportedCurrency, error) { - all := s.blockchain.ListSupportedCurrencies() + all := s.blockchain.ListSupportedCurrencies(false) enabledTickers := util.Set(merchant.Settings().PaymentMethods()) // if merchant didn't set this parameter yet, let's treat that as "all currencies enabled" @@ -197,7 +197,7 @@ func (s *Service) UpdateSupportedMethods(ctx context.Context, merchant *Merchant tickersSet := util.Set(tickers) availableTickersSet := util.Set( util.MapSlice( - s.blockchain.ListSupportedCurrencies(), + s.blockchain.ListSupportedCurrencies(false), func(c money.CryptoCurrency) string { return c.Ticker }, ), )