From df43edf909fe8c16927fc005e99aab2e7e7567a4 Mon Sep 17 00:00:00 2001 From: Bartek Wrona <wrona@syncad.com> Date: Thu, 25 Jun 2020 03:44:06 +0200 Subject: [PATCH] Preliminary version using filters in enum_virtual_ops. Some strange porblems occured related to missing payout in comment_reward_operation. --- hive/indexer/blocks.py | 2 ++ hive/steem/client.py | 36 +++++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/hive/indexer/blocks.py b/hive/indexer/blocks.py index 9013190a9..a1184f81d 100644 --- a/hive/indexer/blocks.py +++ b/hive/indexer/blocks.py @@ -105,6 +105,8 @@ class Blocks: key = "{}/{}".format(op_value['author'], op_value['permlink']) val = {'hbd_payout':op_value['hbd_payout'], 'hive_payout':op_value['hive_payout'], 'vesting_payout':op_value['vesting_payout']} elif op_type == 'comment_reward_operation': + if('payout' not in op_value or op_value['payout'] is None): + logger.error("Broken op: `{}'".format(str(op))) key = "{}/{}".format(op_value['author'], op_value['permlink']) val = {'payout':op_value['payout'], 'author_rewards':op_value['author_rewards']} elif op_type == 'effective_comment_vote_operation': diff --git a/hive/steem/client.py b/hive/steem/client.py index 9e34db398..08a38d614 100644 --- a/hive/steem/client.py +++ b/hive/steem/client.py @@ -156,24 +156,46 @@ class SteemClient: def enum_virtual_ops(self, begin_block, end_block): """ Get virtual ops for range of blocks """ ret = {} - delta = 100 + delta = 1000 from_block = begin_block to_block = (begin_block + delta) if begin_block + delta < end_block else end_block + #According to definition of hive::plugins::acount_history::enum_vops_filter: + + author_reward_operation = 0x000002 + curation_reward_operation = 0x000004 + comment_reward_operation = 0x000008 + effective_comment_vote_operation = 0x400000 + + tracked_ops_filter = curation_reward_operation | author_reward_operation | comment_reward_operation | effective_comment_vote_operation + tracked_ops = ['curation_reward_operation', 'author_reward_operation', 'comment_reward_operation', 'effective_comment_vote_operation'] + + resume_on_operation = 0 + while from_block < to_block: - result = self.__exec('enum_virtual_ops', {"block_range_begin":from_block, "block_range_end":to_block}) + result = self.__exec('enum_virtual_ops', {"block_range_begin":from_block, "block_range_end":to_block + , "operation_begin": resume_on_operation, "limit": 1000, "filter": tracked_ops_filter + }) ops = result['ops'] if 'ops' in result else [] - tracked_ops = ['curation_reward_operation', 'author_reward_operation', 'comment_reward_operation', 'effective_comment_vote_operation'] - + resume_on_operation = result['next_operation_begin'] if 'next_operation_begin' in result else 0 + + next_block = result['next_block_range_begin'] if 'next_block_range_begin' in result else from_block + delta + for op in ops: + if(op['op']['type'] not in tracked_ops): + logger.error("{} VOPS Filtering failed: `{}'".format(str(tracked_ops_filter), str(op))) + + if(op['op']['type'] == 'comment_reward_operation' and 'payout' not in op['op']['value']): + logger.error("Broken op: `{}'".format(str(op))) + block = op['block'] - if block in ret and op['op']['type'] in tracked_ops: + if block in ret: ret[block]['ops'].append(op['op']) - if block not in ret and op['op']['type'] in tracked_ops: + if block not in ret: ret[block] = {'timestamp':op['timestamp'], 'ops':[op['op']]} from_block = to_block - to_block = (from_block + delta) if from_block + delta < end_block else end_block + to_block = next_block if next_block < end_block else end_block return ret def get_comment_pending_payouts(self, comments): -- GitLab