@@ -380,32 +380,35 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
380380 }
381381
382382 for {
383- time . Sleep ( time . Second )
384-
385- statuses , err := s .data .GetBlockchainSignatureStatuses (ctx , []solana.Signature {solana .Signature (txn .Signature ())})
386- if err != nil {
387- continue
388- }
383+ select {
384+ case <- time . After ( time . Second ):
385+ statuses , err := s .data .GetBlockchainSignatureStatuses (ctx , []solana.Signature {solana .Signature (txn .Signature ())})
386+ if err != nil {
387+ continue
388+ }
389389
390- if len (statuses ) == 0 || statuses [0 ] == nil {
391- continue
392- }
390+ if len (statuses ) == 0 || statuses [0 ] == nil {
391+ continue
392+ }
393393
394- if statuses [0 ].ErrorResult != nil {
395- log .WithError (statuses [0 ].ErrorResult ).Warn ("transaction failed" )
396- return handleSwapStructuredError (streamer , transactionpb .SwapResponse_Error_SWAP_FAILED )
397- }
394+ if statuses [0 ].ErrorResult != nil {
395+ log .WithError (statuses [0 ].ErrorResult ).Warn ("transaction failed" )
396+ return handleSwapStructuredError (streamer , transactionpb .SwapResponse_Error_SWAP_FAILED )
397+ }
398398
399- if statuses [0 ].Finalized () {
400- log .Debug ("transaction succeeded and is finalized" )
401- err = streamer .Send (& transactionpb.SwapResponse {
402- Response : & transactionpb.SwapResponse_Success_ {
403- Success : & transactionpb.SwapResponse_Success {
404- Code : transactionpb .SwapResponse_Success_SWAP_FINALIZED ,
399+ if statuses [0 ].Finalized () {
400+ log .Debug ("transaction succeeded and is finalized" )
401+ err = streamer .Send (& transactionpb.SwapResponse {
402+ Response : & transactionpb.SwapResponse_Success_ {
403+ Success : & transactionpb.SwapResponse_Success {
404+ Code : transactionpb .SwapResponse_Success_SWAP_FINALIZED ,
405+ },
405406 },
406- },
407- })
408- return handleSwapError (streamer , err )
407+ })
408+ return handleSwapError (streamer , err )
409+ }
410+ case <- ctx .Done ():
411+ return handleSwapError (streamer , ctx .Err ())
409412 }
410413 }
411414}
0 commit comments