From d8eb1cc7c6ecec2a9558d496a3e634dbb4879981 Mon Sep 17 00:00:00 2001 From: roadscape Date: Tue, 5 Feb 2019 12:06:10 -0600 Subject: [PATCH] default get_block to strict --- hive/steem/block/stream.py | 2 +- hive/steem/client.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hive/steem/block/stream.py b/hive/steem/block/stream.py index e7c1d0d6b..89be9da1b 100644 --- a/hive/steem/block/stream.py +++ b/hive/steem/block/stream.py @@ -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: diff --git a/hive/steem/client.py b/hive/steem/client.py index 4a56daa8a..5671262a7 100644 --- a/hive/steem/client.py +++ b/hive/steem/client.py @@ -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."""