From c9c9edbe53fd1da782b86541bf8c4bc06310d3c9 Mon Sep 17 00:00:00 2001 From: sameh-farouk Date: Wed, 1 Nov 2023 14:31:53 +0200 Subject: [PATCH] fix: use provided context insted of new one --- bridge/tfchain_bridge/pkg/bridge/mint.go | 18 ++++++++---------- bridge/tfchain_bridge/pkg/bridge/refund.go | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/bridge/tfchain_bridge/pkg/bridge/mint.go b/bridge/tfchain_bridge/pkg/bridge/mint.go index 7e503e90a..9b94fe6f3 100644 --- a/bridge/tfchain_bridge/pkg/bridge/mint.go +++ b/bridge/tfchain_bridge/pkg/bridge/mint.go @@ -17,7 +17,6 @@ import ( // mint handler for stellar func (bridge *Bridge) mint(ctx context.Context, senders map[string]*big.Int, tx hProtocol.Transaction) error { logger := log.Logger.With().Str("span_id", tx.ID).Logger() - refund_contex := context.Background() minted, err := bridge.subClient.IsMintedAlready(tx.Hash) if err != nil { @@ -44,10 +43,9 @@ func (bridge *Bridge) mint(ctx context.Context, senders map[string]*big.Int, tx // only one payment in transaction is allowed if len(senders) > 1 { - refund_contex = context.WithValue(refund_contex, "refund_reason", "multiple senders found") - + ctx = context.WithValue(ctx, "refund_reason", "multiple senders found") for sender, depositAmount := range senders { - return bridge.refund(refund_contex, sender, depositAmount.Int64(), tx) // how this should be refund the multiple sender ? + return bridge.refund(ctx, sender, depositAmount.Int64(), tx) // how this should be refund the multiple sender ? } } @@ -59,8 +57,8 @@ func (bridge *Bridge) mint(ctx context.Context, senders map[string]*big.Int, tx } if tx.Memo == "" { - refund_contex = context.WithValue(refund_contex, "refund_reason", "the transaction does not contain any memo") - return bridge.refund(refund_contex, receiver, depositedAmount.Int64(), tx) + ctx = context.WithValue(ctx, "refund_reason", "the transaction does not contain any memo") + return bridge.refund(ctx, receiver, depositedAmount.Int64(), tx) } if tx.MemoType == "return" { @@ -76,16 +74,16 @@ func (bridge *Bridge) mint(ctx context.Context, senders map[string]*big.Int, tx // if the deposited amount is lower than the depositfee, trigger a refund if depositedAmount.Cmp(big.NewInt(bridge.depositFee)) <= 0 { - refund_contex = context.WithValue(refund_contex, "refund_reason", "the deposited amount is insufficient to cover the deposit fee") - return bridge.refund(refund_contex, receiver, depositedAmount.Int64(), tx) + ctx = context.WithValue(ctx, "refund_reason", "the deposited amount is insufficient to cover the deposit fee") + return bridge.refund(ctx, receiver, depositedAmount.Int64(), tx) } destinationSubstrateAddress, err := bridge.getSubstrateAddressFromMemo(tx.Memo) if err != nil { logger.Debug().Err(err).Msg("there was an issue decoding the memo for the transaction") // memo is not formatted correctly, issue a refund - refund_contex = context.WithValue(refund_contex, "refund_reason", "the transaction contains a memo text that is not properly formatted") - return bridge.refund(refund_contex, receiver, depositedAmount.Int64(), tx) + ctx = context.WithValue(ctx, "refund_reason", "the transaction contains a memo text that is not properly formatted") + return bridge.refund(ctx, receiver, depositedAmount.Int64(), tx) } accountID, err := substrate.FromAddress(destinationSubstrateAddress) diff --git a/bridge/tfchain_bridge/pkg/bridge/refund.go b/bridge/tfchain_bridge/pkg/bridge/refund.go index e5a40741e..245f3e1c9 100644 --- a/bridge/tfchain_bridge/pkg/bridge/refund.go +++ b/bridge/tfchain_bridge/pkg/bridge/refund.go @@ -42,7 +42,7 @@ func (bridge *Bridge) handleRefundExpired(ctx context.Context, refundExpiredEven if refunded { logger.Info(). Str("event_type", "refund_skipped"). - Msgf("the transaction has already been refunded", refundExpiredEvent.Hash) + Msg("the transaction has already been refunded") return nil }