satellite/payments/stripecoinpayments: don't request anything from

Coinpayments if credentials are missing

Workaround for hitting Coinpayment API while tests.

Change-Id: I27114c820d4d7e17d05b066f55a13a709dac1711
This commit is contained in:
Michal Niewrzal 2020-05-22 12:42:17 +02:00
parent 7014cf2083
commit 88a2561317
2 changed files with 13 additions and 0 deletions

View File

@ -19,6 +19,9 @@ import (
// Error is error class API errors.
var Error = errs.Class("coinpayments client error")
// ErrMissingPublicKey is returned when Coinpayments client is missing public key.
var ErrMissingPublicKey = errs.Class("missing public key")
// Credentials contains public and private API keys for client.
type Credentials struct {
PublicKey string
@ -54,6 +57,10 @@ func (c *Client) ConversionRates() ConversionRates {
// do handles base API request routines.
func (c *Client) do(ctx context.Context, cmd string, values url.Values) (_ json.RawMessage, err error) {
if c.creds.PublicKey == "" {
return nil, Error.Wrap(ErrMissingPublicKey.New(""))
}
values.Set("version", "1")
values.Set("format", "json")
values.Set("key", c.creds.PublicKey)

View File

@ -329,6 +329,12 @@ func (service *Service) UpdateRates(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
rates, err := service.coinPayments.ConversionRates().Get(ctx)
if coinpayments.ErrMissingPublicKey.Has(err) {
rates = coinpayments.CurrencyRateInfos{}
err = nil
service.log.Info("Coinpayment client is missing public key")
}
service.mu.Lock()
defer service.mu.Unlock()