def process_ops(cls, ops, block_num, block_date): """Given a list of operation in block, filter and process them.""" for op in ops: if op['id'] not in ['follow', 'com.steemit.community']: continue # we assume `required_posting_auths` is always used and length 1. # it may be that some ops require `required_active_auths` instead. # (e.g. if we use that route for admin action of acct creation) # if op['required_active_auths']: # log.warning("unexpected active auths: %s" % op) if len(op['required_posting_auths']) != 1: log.warning("unexpected auths: %s", op) continue account = op['required_posting_auths'][0] op_json = load_json_key(op, 'json') if op['id'] == 'follow': if block_num < 6000000 and not isinstance(op_json, list): op_json = ['follow', op_json] # legacy compat cls._process_legacy(account, op_json, block_date) elif op['id'] == 'com.steemit.community': if block_num > 23e6: process_json_community_op(account, op_json, block_date)
def process_ops(cls, ops, block_num, block_date): """Given a list of operation in block, filter and process them.""" for op in ops: if op['id'] not in ['follow', 'com.steemit.community']: continue account = _get_auth(op) if not account: continue op_json = load_json_key(op, 'json') if op['id'] == 'follow': if block_num < 6000000 and not isinstance(op_json, list): op_json = ['follow', op_json] # legacy compat cls._process_legacy(account, op_json, block_date) elif op['id'] == 'com.steemit.community': if block_num > 30e6: process_json_community_op(account, op_json, block_date)
def process_op(cls, op, block_num, block_date): opName = str(op['id']) + ('-ignored' if op['id'] not in [ 'follow', 'community', 'notify', 'reblog' ] else '') account = _get_auth(op) if not account: return op_json = load_json_key(op, 'json') if op['id'] == 'follow': if block_num < 6000000 and not isinstance(op_json, list): op_json = ['follow', op_json] # legacy compat cls._process_legacy(account, op_json, block_date, block_num) elif op['id'] == 'reblog': if block_num < 6000000 and not isinstance(op_json, list): op_json = ['reblog', op_json] # legacy compat cls._process_legacy(account, op_json, block_date, block_num) elif op['id'] == 'community': if block_num > Community.start_block: process_json_community_op(account, op_json, block_date, block_num) elif op['id'] == 'notify': cls._process_notify(account, op_json, block_date)
def process_block(block, is_initial_sync=False): date = block['timestamp'] block_id = block['block_id'] prev = block['previous'] block_num = int(block_id[:8], base=16) txs = block['transactions'] query( "INSERT INTO hive_blocks (num, hash, prev, txs, created_at) " "VALUES (:num, :hash, :prev, :txs, :date)", num=block_num, hash=block_id, prev=prev, txs=len(txs), date=date) accounts = set() comments = [] json_ops = [] deleted = [] dirty = set() for tx in txs: for operation in tx['operations']: op_type, op = operation if op_type == 'pow': accounts.add(op['worker_account']) elif op_type == 'pow2': accounts.add(op['work'][1]['input']['worker_account']) elif op_type in [ 'account_create', 'account_create_with_delegation' ]: accounts.add(op['new_account_name']) elif op_type == 'comment': comments.append(op) dirty.add(op['author'] + '/' + op['permlink']) elif op_type == 'delete_comment': deleted.append(op) elif op_type == 'custom_json': json_ops.append(op) elif op_type == 'vote': dirty.add(op['author'] + '/' + op['permlink']) register_accounts( accounts, date) # if an account does not exist, mark it as created in this block register_posts( comments, date ) # if this is a new post, add the entry and validate community param delete_posts(deleted) # mark hive_posts.is_deleted = 1 for op in json_ops: if op['id'] not in ['follow', 'com.steemit.community']: continue # we are assuming `required_posting_auths` is always used and length 1. # it may be that some ops will require `required_active_auths` instead # (e.g. if we use that route for admin action of acct creation) # if op['required_active_auths']: # log.warning("unexpected active auths: %s" % op) if len(op['required_posting_auths']) != 1: log.warning("unexpected auths: %s" % op) continue account = op['required_posting_auths'][0] op_json = {} try: op_json = json.loads(op['json']) except JSONDecodeError: pass if op['id'] == 'follow': if block_num < 6000000 and type(op_json) != list: op_json = ['follow', op_json] # legacy compat process_json_follow_op(account, op_json, date) elif op['id'] == 'com.steemit.community': if block_num > 13e6: process_json_community_op(account, op_json, date) # return all posts modified this block return dirty