Skip to content

Commit

Permalink
New version of go-whatsonchain has ctx now
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jan 21, 2022
1 parent 8dab9cb commit 744dcfc
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion rates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 22 additions & 22 deletions rates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}
Expand All @@ -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,
Expand Down Expand Up @@ -67,15 +67,15 @@ 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

return currency, 0.01
}

// 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,
Expand All @@ -92,16 +92,16 @@ 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

return
}

// IsAcceptedCurrency is a mock response
func (m *mockPaprikaValid) IsAcceptedCurrency(currency string) bool {
func (m *mockPaprikaValid) IsAcceptedCurrency(_ string) bool {

// This is just a mock response

Expand All @@ -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,
Expand All @@ -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
}
Expand All @@ -154,34 +154,34 @@ 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

return nil, fmt.Errorf("some error occurred")
}

// IsAcceptedCurrency is a mock response
func (m *mockPaprikaFailed) IsAcceptedCurrency(currency string) bool {
func (m *mockPaprikaFailed) IsAcceptedCurrency(_ string) bool {

return false
}
Expand All @@ -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")
}
Expand Down

0 comments on commit 744dcfc

Please sign in to comment.