From 744dcfcd9bcb3c0f085e9392039defc276b78b5a Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Fri, 21 Jan 2022 11:24:53 -0500 Subject: [PATCH] New version of go-whatsonchain has ctx now --- client.go | 2 +- conversions.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- rates.go | 2 +- rates_test.go | 44 ++++++++++++++++++++++---------------------- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/client.go b/client.go index 0146084..defbb85 100644 --- a/client.go +++ b/client.go @@ -24,7 +24,7 @@ type preevInterface interface { // whatsOnChainInterface is an interface for the WOC Client type whatsOnChainInterface interface { - GetExchangeRate() (rate *whatsonchain.ExchangeRate, err error) + GetExchangeRate(ctx context.Context) (rate *whatsonchain.ExchangeRate, err error) } // coinPaprikaInterface is an interface for the Coin Paprika Client diff --git a/conversions.go b/conversions.go index 3318666..3c258e0 100644 --- a/conversions.go +++ b/conversions.go @@ -32,7 +32,7 @@ func (c *Client) GetConversion(ctx context.Context, currency Currency, amount fl } case ProviderWhatsOnChain: var response *whatsonchain.ExchangeRate - if response, err = c.WhatsOnChain.GetExchangeRate(); err == nil && response != nil { + if response, err = c.WhatsOnChain.GetExchangeRate(ctx); err == nil && response != nil { var rate float64 if rate, err = strconv.ParseFloat(response.Rate, 64); err == nil { satoshis, err = ConvertPriceToSatoshis(rate, amount) diff --git a/go.mod b/go.mod index 22d1b38..bc16c47 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.16 require ( github.com/gojektech/heimdall/v6 v6.1.0 github.com/mrz1836/go-preev v0.2.6 - github.com/mrz1836/go-whatsonchain v0.6.7 + github.com/mrz1836/go-whatsonchain v0.7.0 github.com/shopspring/decimal v1.3.1 github.com/stretchr/testify v1.7.0 ) diff --git a/go.sum b/go.sum index ca52072..23c7394 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVY github.com/mattn/goveralls v0.0.6/go.mod h1:h8b4ow6FxSPMQHF6o2ve3qsclnffZjYTNEKmLesRwqw= github.com/mrz1836/go-preev v0.2.6 h1:hEXyXWEDOq8jsWpJnvn9d6Wb0FbiP6QJBKe/KdweLYA= github.com/mrz1836/go-preev v0.2.6/go.mod h1:tOcsi6SnHWQqA3Ujhr9vlbaV8R9lQo3Sb1bU3Wc6hNQ= -github.com/mrz1836/go-whatsonchain v0.6.7 h1:2SwrS8+q0Ksk7q9uOgMmwDfFx81gY1BW2gqKsDm8jgg= -github.com/mrz1836/go-whatsonchain v0.6.7/go.mod h1:qVch/m2I8ecQGqapkH4/41/mWoFO0J03R9QEPTOPSw4= +github.com/mrz1836/go-whatsonchain v0.7.0 h1:3+sm19o7iFHQTnOvEkzVJ81jAof4190/e6CZSFU1joI= +github.com/mrz1836/go-whatsonchain v0.7.0/go.mod h1:qVch/m2I8ecQGqapkH4/41/mWoFO0J03R9QEPTOPSw4= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/rates.go b/rates.go index 18fd018..684282b 100644 --- a/rates.go +++ b/rates.go @@ -33,7 +33,7 @@ func (c *Client) GetRate(ctx context.Context, currency Currency) (rate float64, } case ProviderWhatsOnChain: var response *whatsonchain.ExchangeRate - if response, err = c.WhatsOnChain.GetExchangeRate(); err == nil && response != nil { + if response, err = c.WhatsOnChain.GetExchangeRate(ctx); err == nil && response != nil { rate, err = strconv.ParseFloat(response.Rate, 64) } case ProviderPreev: diff --git a/rates_test.go b/rates_test.go index dadab2a..968e5b2 100644 --- a/rates_test.go +++ b/rates_test.go @@ -16,7 +16,7 @@ import ( type mockWOCValid struct{} // GetExchangeRate is a mock response -func (m *mockWOCValid) GetExchangeRate() (rate *whatsonchain.ExchangeRate, err error) { +func (m *mockWOCValid) GetExchangeRate(_ context.Context) (rate *whatsonchain.ExchangeRate, err error) { rate = &whatsonchain.ExchangeRate{ Rate: "159.01", @@ -30,7 +30,7 @@ func (m *mockWOCValid) GetExchangeRate() (rate *whatsonchain.ExchangeRate, err e type mockWOCFailed struct{} // GetExchangeRate is a mock response -func (m *mockWOCFailed) GetExchangeRate() (rate *whatsonchain.ExchangeRate, err error) { +func (m *mockWOCFailed) GetExchangeRate(_ context.Context) (rate *whatsonchain.ExchangeRate, err error) { return } @@ -39,7 +39,7 @@ func (m *mockWOCFailed) GetExchangeRate() (rate *whatsonchain.ExchangeRate, err type mockPaprikaValid struct{} // GetMarketPrice is a mock response -func (m *mockPaprikaValid) GetMarketPrice(ctx context.Context, coinID string) (response *TickerResponse, err error) { +func (m *mockPaprikaValid) GetMarketPrice(_ context.Context, coinID string) (response *TickerResponse, err error) { response = &TickerResponse{ BetaValue: 1.39789, @@ -67,7 +67,7 @@ func (m *mockPaprikaValid) GetMarketPrice(ctx context.Context, coinID string) (r } // GetBaseAmountAndCurrencyID is a mock response -func (m *mockPaprikaValid) GetBaseAmountAndCurrencyID(currency string, amount float64) (string, float64) { +func (m *mockPaprikaValid) GetBaseAmountAndCurrencyID(currency string, _ float64) (string, float64) { // This is just a mock request @@ -75,7 +75,7 @@ func (m *mockPaprikaValid) GetBaseAmountAndCurrencyID(currency string, amount fl } // GetPriceConversion is a mock response -func (m *mockPaprikaValid) GetPriceConversion(ctx context.Context, baseCurrencyID, quoteCurrencyID string, amount float64) (response *PriceConversionResponse, err error) { +func (m *mockPaprikaValid) GetPriceConversion(_ context.Context, baseCurrencyID, quoteCurrencyID string, amount float64) (response *PriceConversionResponse, err error) { response = &PriceConversionResponse{ Amount: amount, @@ -92,8 +92,8 @@ func (m *mockPaprikaValid) GetPriceConversion(ctx context.Context, baseCurrencyI } // GetHistoricalTickers is a mock response -func (m *mockPaprikaValid) GetHistoricalTickers(ctx context.Context, coinID string, start, end time.Time, limit int, - quote tickerQuote, interval tickerInterval) (response *HistoricalResponse, err error) { +func (m *mockPaprikaValid) GetHistoricalTickers(_ context.Context, _ string, _, _ time.Time, _ int, + _ tickerQuote, _ tickerInterval) (response *HistoricalResponse, err error) { // This is just a mock response @@ -101,7 +101,7 @@ func (m *mockPaprikaValid) GetHistoricalTickers(ctx context.Context, coinID stri } // IsAcceptedCurrency is a mock response -func (m *mockPaprikaValid) IsAcceptedCurrency(currency string) bool { +func (m *mockPaprikaValid) IsAcceptedCurrency(_ string) bool { // This is just a mock response @@ -112,7 +112,7 @@ func (m *mockPaprikaValid) IsAcceptedCurrency(currency string) bool { type mockPreevValid struct{} // GetTicker is a mock response -func (m *mockPreevValid) GetTicker(ctx context.Context, pairID string) (ticker *preev.Ticker, err error) { +func (m *mockPreevValid) GetTicker(_ context.Context, pairID string) (ticker *preev.Ticker, err error) { ticker = &preev.Ticker{ ID: pairID, @@ -133,19 +133,19 @@ func (m *mockPreevValid) GetTicker(ctx context.Context, pairID string) (ticker * } // GetPair is a mock response -func (m *mockPreevValid) GetPair(ctx context.Context, pairID string) (pair *preev.Pair, err error) { +func (m *mockPreevValid) GetPair(_ context.Context, _ string) (pair *preev.Pair, err error) { return } // GetPairs is a mock response -func (m *mockPreevValid) GetPairs(ctx context.Context) (pairList *preev.PairList, err error) { +func (m *mockPreevValid) GetPairs(_ context.Context) (pairList *preev.PairList, err error) { return } // GetTickers is a mock response -func (m *mockPreevValid) GetTickers(ctx context.Context) (tickerList *preev.TickerList, err error) { +func (m *mockPreevValid) GetTickers(_ context.Context) (tickerList *preev.TickerList, err error) { return } @@ -154,26 +154,26 @@ func (m *mockPreevValid) GetTickers(ctx context.Context) (tickerList *preev.Tick type mockPaprikaFailed struct{} // GetMarketPrice is a mock response -func (m *mockPaprikaFailed) GetMarketPrice(ctx context.Context, coinID string) (response *TickerResponse, err error) { +func (m *mockPaprikaFailed) GetMarketPrice(_ context.Context, _ string) (response *TickerResponse, err error) { err = fmt.Errorf("request to paprika fails... 502") return } // GetBaseAmountAndCurrencyID is a mock response -func (m *mockPaprikaFailed) GetBaseAmountAndCurrencyID(currency string, amount float64) (string, float64) { +func (m *mockPaprikaFailed) GetBaseAmountAndCurrencyID(_ string, _ float64) (string, float64) { return "", 0 } // GetPriceConversion is a mock response -func (m *mockPaprikaFailed) GetPriceConversion(ctx context.Context, baseCurrencyID, quoteCurrencyID string, amount float64) (response *PriceConversionResponse, err error) { +func (m *mockPaprikaFailed) GetPriceConversion(_ context.Context, _, _ string, _ float64) (response *PriceConversionResponse, err error) { return nil, fmt.Errorf("some error occurred") } // GetHistoricalTickers is a mock response -func (m *mockPaprikaFailed) GetHistoricalTickers(ctx context.Context, coinID string, start, end time.Time, limit int, - quote tickerQuote, interval tickerInterval) (response *HistoricalResponse, err error) { +func (m *mockPaprikaFailed) GetHistoricalTickers(_ context.Context, _ string, _, _ time.Time, _ int, + _ tickerQuote, _ tickerInterval) (response *HistoricalResponse, err error) { // This is just a mock response @@ -181,7 +181,7 @@ func (m *mockPaprikaFailed) GetHistoricalTickers(ctx context.Context, coinID str } // IsAcceptedCurrency is a mock response -func (m *mockPaprikaFailed) IsAcceptedCurrency(currency string) bool { +func (m *mockPaprikaFailed) IsAcceptedCurrency(_ string) bool { return false } @@ -190,25 +190,25 @@ func (m *mockPaprikaFailed) IsAcceptedCurrency(currency string) bool { type mockPreevFailed struct{} // GetPair is a mock response -func (m *mockPreevFailed) GetPair(ctx context.Context, pairID string) (pair *preev.Pair, err error) { +func (m *mockPreevFailed) GetPair(_ context.Context, _ string) (pair *preev.Pair, err error) { return nil, fmt.Errorf("some error occurred") } // GetTicker is a mock response -func (m *mockPreevFailed) GetTicker(ctx context.Context, pairID string) (ticker *preev.Ticker, err error) { +func (m *mockPreevFailed) GetTicker(_ context.Context, _ string) (ticker *preev.Ticker, err error) { return nil, fmt.Errorf("some error occurred") } // GetTickers is a mock response -func (m *mockPreevFailed) GetTickers(ctx context.Context) (tickerList *preev.TickerList, err error) { +func (m *mockPreevFailed) GetTickers(_ context.Context) (tickerList *preev.TickerList, err error) { return nil, fmt.Errorf("some error occurred") } // GetPairs is a mock response -func (m *mockPreevFailed) GetPairs(ctx context.Context) (pairList *preev.PairList, err error) { +func (m *mockPreevFailed) GetPairs(_ context.Context) (pairList *preev.PairList, err error) { return nil, fmt.Errorf("some error occurred") }