From 421e4cb3b08ed266450249e58e08f2c6d3ca9bbb Mon Sep 17 00:00:00 2001
From: Anthony Martin <github@martin-studio.com>
Date: Tue, 23 Oct 2018 19:59:38 -0700
Subject: [PATCH] add retry elements for dealing with errors in batch responses
 #6

---
 lib/steem/stream.rb | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/steem/stream.rb b/lib/steem/stream.rb
index 8590821..1e9b25c 100644
--- a/lib/steem/stream.rb
+++ b/lib/steem/stream.rb
@@ -91,6 +91,14 @@ module Steem
     # @option options [Integer] :until_block_num Ends the stream at the given block number.  Default: nil.
     def transactions(options = {}, &block)
       blocks(options) do |block, block_num|
+        if block.nil?
+          warn "Batch missing block_num: #{block_num}, retrying ..."
+          
+          block = block_api.get_block(block_num: block_num) do |result|
+            result.block
+          end
+        end
+        
         block.transactions.each_with_index do |transaction, index|
           trx_id = block.transaction_ids[index]
           
@@ -332,9 +340,8 @@ module Steem
         end
         
         response = account_history_api.get_ops_in_block(*get_ops_in_block_options)
-        result = response.result
         
-        if result.nil?
+        if response.nil? || (result = response.result).nil?
           if retries < MAX_RETRY_COUNT
             warn "Retrying get_ops_in_block on block #{block_num}" unless @no_warn
             retries = retries + 1
@@ -360,7 +367,8 @@ module Steem
             retries = retries + 1
             redo
           else
-            raise TooManyRetriesError, "unable to find virtual operations for block: #{block_num}"
+            warn "unable to find virtual operations for block: #{block_num}"
+            # raise TooManyRetriesError, "unable to find virtual operations for block: #{block_num}"
           end
         end
         
@@ -374,4 +382,4 @@ module Steem
       end
     end
   end
-end
\ No newline at end of file
+end
-- 
GitLab