Skip to content

Commit

Permalink
default get_block to strict
Browse files Browse the repository at this point in the history
  • Loading branch information
roadscape committed Feb 5, 2019
1 parent 609a39e commit d8eb1cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hive/steem/block/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def start(self, start_block):

while self._gap_ok(curr, head):
head = schedule.wait_for_block(curr)
block = self._client.get_block(curr)
block = self._client.get_block(curr, strict=False)
schedule.check_block(curr, block)

if not block:
Expand Down
9 changes: 7 additions & 2 deletions hive/steem/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ def get_content_batch(self, tuples):
assert 'author' in post, "invalid post: %s" % post
return posts

def get_block(self, num):
def get_block(self, num, strict=True):
"""Fetches a single block.
If the result does not contain a `block` key, it's assumed
this block does not yet exist and None is returned.
"""
result = self.__exec('get_block', {'block_num': num})
return result['block'] if 'block' in result else None
if 'block' in result:
return result['block']
elif strict:
raise Exception('block %d not available' % num)
else:
return None

def stream_blocks(self, start_from, trail_blocks=0, max_gap=100):
"""Stream blocks. Returns a generator."""
Expand Down

0 comments on commit d8eb1cc

Please sign in to comment.