@@ -98,14 +98,14 @@ func (p *service) maybeInitiateGiftCardAutoReturn(ctx context.Context, accountIn
9898 log .Trace ("gift card is claimed and will be removed from worker queue" )
9999
100100 // Cleanup anything related to gift card auto-return, since it cannot be scheduled
101- err = initiateProcessToCleanupGiftCardAutoReturn (ctx , p .data , giftCardVaultAccount )
101+ err = InitiateProcessToCleanupGiftCardAutoReturn (ctx , p .data , giftCardVaultAccount )
102102 if err != nil {
103103 log .WithError (err ).Warn ("failure cleaning up auto-return action" )
104104 return err
105105 }
106106
107107 // Gift card is claimed, so take it out of the worker queue.
108- return markAutoReturnCheckComplete (ctx , p .data , accountInfoRecord )
108+ return MarkAutoReturnCheckComplete (ctx , p .data , accountInfoRecord )
109109 } else if err != action .ErrActionNotFound {
110110 return err
111111 }
@@ -129,7 +129,9 @@ func (p *service) maybeInitiateGiftCardAutoReturn(ctx context.Context, accountIn
129129 log .WithError (err ).Warn ("failure initiating process to return gift card balance to issuer" )
130130 return err
131131 }
132- return markAutoReturnCheckComplete (ctx , p .data , accountInfoRecord )
132+
133+ // Gift card is auto-returned, so take it out of the worker queue
134+ return MarkAutoReturnCheckComplete (ctx , p .data , accountInfoRecord )
133135}
134136
135137// Note: This is the first instance of handling a conditional action, and could be
@@ -201,27 +203,30 @@ func InitiateProcessToAutoReturnGiftCard(ctx context.Context, data code_data.Pro
201203 })
202204}
203205
204- func initiateProcessToCleanupGiftCardAutoReturn (ctx context.Context , data code_data.Provider , giftCardVaultAccount * common.Account ) error {
205- autoReturnAction , err := data .GetGiftCardAutoReturnAction (ctx , giftCardVaultAccount .PublicKey ().ToBase58 ())
206- if err != nil {
207- return err
208- }
206+ // todo: This probably belongs somewhere more common
207+ func InitiateProcessToCleanupGiftCardAutoReturn (ctx context.Context , data code_data.Provider , giftCardVaultAccount * common.Account ) error {
208+ return data .ExecuteInTx (ctx , sql .LevelDefault , func (ctx context.Context ) error {
209+ autoReturnAction , err := data .GetGiftCardAutoReturnAction (ctx , giftCardVaultAccount .PublicKey ().ToBase58 ())
210+ if err != nil {
211+ return err
212+ }
209213
210- autoReturnFulfillment , err := data .GetAllFulfillmentsByAction (ctx , autoReturnAction .Intent , autoReturnAction .ActionId )
211- if err != nil {
212- return err
213- }
214+ autoReturnFulfillment , err := data .GetAllFulfillmentsByAction (ctx , autoReturnAction .Intent , autoReturnAction .ActionId )
215+ if err != nil {
216+ return err
217+ }
214218
215- err = markActionAsRevoked (ctx , data , autoReturnAction )
216- if err != nil {
217- return err
218- }
219+ err = markActionAsRevoked (ctx , data , autoReturnAction )
220+ if err != nil {
221+ return err
222+ }
219223
220- // The sequencer will handle state transition and any cleanup
221- return markFulfillmentAsActivelyScheduled (ctx , data , autoReturnFulfillment [0 ])
224+ // The sequencer will handle state transition and any cleanup
225+ return markFulfillmentAsActivelyScheduled (ctx , data , autoReturnFulfillment [0 ])
226+ })
222227}
223228
224- func markAutoReturnCheckComplete (ctx context.Context , data code_data.Provider , record * account.Record ) error {
229+ func MarkAutoReturnCheckComplete (ctx context.Context , data code_data.Provider , record * account.Record ) error {
225230 if ! record .RequiresAutoReturnCheck {
226231 return nil
227232 }
0 commit comments