From de70689307cc4820e3a90e1ac5613203174e6af7 Mon Sep 17 00:00:00 2001 From: husobee Date: Thu, 16 Dec 2021 12:21:11 -0500 Subject: [PATCH 1/2] collapse transactions into one tx (#1060) --- promotion/drain.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/promotion/drain.go b/promotion/drain.go index fcd7ad7e1..fd1eee635 100644 --- a/promotion/drain.go +++ b/promotion/drain.go @@ -334,8 +334,16 @@ func (service *Service) SubmitBatchTransfer(ctx context.Context, batchID *uuid.U totalJPYTransfer = decimal.Zero ) + var ( + totalF64 float64 + depositID string + transferID string + ) + for _, v := range transfers { - totalF64, _ := v.Total.Float64() + t, _ := v.Total.Float64() + totalF64 += t + totalJPYTransfer = totalJPYTransfer.Add(v.Total.Mul(quote.Rate)) if totalJPYTransfer.GreaterThan(JPYLimit) { @@ -347,17 +355,22 @@ func (service *Service) SubmitBatchTransfer(ctx context.Context, batchID *uuid.U over, quote.Rate, totalJPYTransfer), "over custodian transfer limit", new(bitflyerOverTransferLimit)) + break } - - withdraws = append(withdraws, bitflyer.WithdrawToDepositIDPayload{ - CurrencyCode: "BAT", - Amount: totalF64, - DepositID: *v.DepositID, - TransferID: v.ID.String(), - SourceFrom: "userdrain", - }) + depositID = *v.DepositID + transferID = transferID + v.ID.String() } + // collapse into one transaction, not multiples in a bulk upload + + withdraws = append(withdraws, bitflyer.WithdrawToDepositIDPayload{ + CurrencyCode: "BAT", + Amount: totalF64, + DepositID: depositID, + TransferID: transferID, + SourceFrom: "userdrain", + }) + // create a WithdrawToDepositIDBulkPayload payload := bitflyer.WithdrawToDepositIDBulkPayload{ Withdrawals: withdraws, From a2cad619568ecc0df754eb2c68b7b82c91144690 Mon Sep 17 00:00:00 2001 From: clD11 <23483715+clD11@users.noreply.github.com> Date: Thu, 16 Dec 2021 17:21:40 +0000 Subject: [PATCH 2/2] feat(284): investigate invalid memory address error suggestions (#1061) added check for nil issuer and nil promotion --- promotion/suggestions.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/promotion/suggestions.go b/promotion/suggestions.go index 3973ad1e9..93549aebd 100644 --- a/promotion/suggestions.go +++ b/promotion/suggestions.go @@ -163,8 +163,9 @@ func (service *Service) GetCredentialRedemptions(ctx context.Context, credential if issuer, ok = issuers[publicKey]; !ok { issuer, err = service.Datastore.GetIssuerByPublicKey(publicKey) - if err != nil { - err = errorutils.Wrap(err, "error finding issuer") + if err != nil || issuer == nil { + e := fmt.Errorf("error finding issuer %s: %w", publicKey, err) + err = errorutils.Wrap(e, e.Error()) return } } @@ -175,8 +176,9 @@ func (service *Service) GetCredentialRedemptions(ctx context.Context, credential if promotion, ok = promotions[publicKey]; !ok { promotion, err = service.Datastore.GetPromotion(issuer.PromotionID) - if err != nil { - err = errorutils.Wrap(err, "error finding promotion") + if err != nil || promotion == nil { + e := fmt.Errorf("error finding promotion %s: %w", issuer.PromotionID, err) + err = errorutils.Wrap(e, e.Error()) return } promotions[publicKey] = promotion