def _process(cls, block, is_initial_sync=False): """Process a single block. Assumes a trx is open.""" #pylint: disable=too-many-branches num = cls._push(block) date = block['timestamp'] account_names = set() json_ops = [] for tx_idx, tx in enumerate(block['transactions']): for operation in tx['operations']: op_type = operation['type'] op = operation['value'] # account ops if op_type == 'pow_operation': account_names.add(op['worker_account']) elif op_type == 'pow2_operation': account_names.add( op['work']['value']['input']['worker_account']) elif op_type == 'account_create_operation': account_names.add(op['new_account_name']) elif op_type == 'account_create_with_delegation_operation': account_names.add(op['new_account_name']) elif op_type == 'create_claimed_account_operation': account_names.add(op['new_account_name']) # account metadata updates elif op_type == 'account_update_operation': if not is_initial_sync: Accounts.dirty(op['account']) # full elif op_type == 'account_update2_operation': if not is_initial_sync: Accounts.dirty(op['account']) # full # post ops elif op_type == 'comment_operation': Posts.comment_op(op, date) if not is_initial_sync: Accounts.dirty(op['author']) # lite - stats elif op_type == 'delete_comment_operation': Posts.delete_op(op) elif op_type == 'vote_operation': if not is_initial_sync: Accounts.dirty(op['author']) # lite - rep Accounts.dirty(op['voter']) # lite - stats CachedPost.vote(op['author'], op['permlink'], None, op['voter']) # misc ops elif op_type == 'transfer_operation': Payments.op_transfer(op, tx_idx, num, date) elif op_type == 'custom_json_operation': json_ops.append(op) Accounts.register(account_names, date) # register any new names CustomOp.process_ops(json_ops, num, date) # follow/reblog/community ops return num
def _process(cls, block, is_initial_sync=False): """Process a single block. Assumes a trx is open.""" # pylint: disable=too-many-boolean-expressions,too-many-branches num = cls._push(block) date = block['timestamp'] account_names = set() comment_ops = [] json_ops = [] delete_ops = [] voted_authors = set() for tx_idx, tx in enumerate(block['transactions']): for operation in tx['operations']: if isinstance(operation, dict): op_type = operation['type'].split('_operation')[0] op = operation['value'] else: # pre-appbase-style. remove after deploy. #APPBASE op_type, op = operation # account ops if op_type == 'pow': account_names.add(op['worker_account']) elif op_type == 'pow2': # old style. remove after #APPBASE #account_names.add(op['work'][1]['input']['worker_account']) account_names.add( op['work']['value']['input']['worker_account']) elif op_type == 'account_create': account_names.add(op['new_account_name']) elif op_type == 'account_create_with_delegation': account_names.add(op['new_account_name']) # post ops elif op_type == 'comment': comment_ops.append(op) elif op_type == 'delete_comment': delete_ops.append(op) elif op_type == 'vote': if not is_initial_sync: CachedPost.vote(op['author'], op['permlink']) voted_authors.add( op['author']) # TODO: move to cachedpost # misc ops elif op_type == 'transfer': Payments.op_transfer(op, tx_idx, num, date) elif op_type == 'custom_json': json_ops.append(op) Accounts.register(account_names, date) # register any new names Accounts.dirty(voted_authors) # update rep of voted authors Posts.comment_ops(comment_ops, date) # handle inserts, edits Posts.delete_ops(delete_ops) # handle post deletion CustomOp.process_ops(json_ops, num, date) # follow/reblog/community ops return num
def _process(cls, block, is_initial_sync=False): """Process a single block. Assumes a trx is open.""" num = cls._push(block) date = block['timestamp'] account_names = set() comment_ops = [] json_ops = [] delete_ops = [] for tx_idx, tx in enumerate(block['transactions']): for operation in tx['operations']: op_type = operation['type'] op = operation['value'] # account ops if op_type == 'pow_operation': account_names.add(op['worker_account']) elif op_type == 'pow2_operation': account_names.add( op['work']['value']['input']['worker_account']) elif op_type == 'account_create_operation': account_names.add(op['new_account_name']) elif op_type == 'account_create_with_delegation_operation': account_names.add(op['new_account_name']) elif op_type == 'create_claimed_account_operation': account_names.add(op['new_account_name']) # post ops elif op_type == 'comment_operation': comment_ops.append(op) elif op_type == 'delete_comment_operation': delete_ops.append(op) elif op_type == 'vote_operation': if not is_initial_sync: CachedPost.vote(op['author'], op['permlink']) # misc ops elif op_type == 'transfer_operation': Payments.op_transfer(op, tx_idx, num, date) elif op_type == 'custom_json_operation': json_ops.append(op) Accounts.register(account_names, date) # register any new names Posts.comment_ops(comment_ops, date) # handle inserts, edits Posts.delete_ops(delete_ops) # handle post deletion CustomOp.process_ops(json_ops, num, date) # follow/reblog/community ops return num
def _process(cls, block, is_initial_sync=False): num = cls._push(block) date = block['timestamp'] account_names = set() comment_ops = [] json_ops = [] delete_ops = [] voted_authors = set() for tx_idx, tx in enumerate(block['transactions']): for operation in tx['operations']: op_type, op = operation # account ops if op_type == 'pow': account_names.add(op['worker_account']) elif op_type == 'pow2': account_names.add(op['work'][1]['input']['worker_account']) elif op_type == 'account_create': account_names.add(op['new_account_name']) elif op_type == 'account_create_with_delegation': account_names.add(op['new_account_name']) # post ops elif op_type == 'comment': comment_ops.append(op) elif op_type == 'delete_comment': delete_ops.append(op) elif op_type == 'vote': if not is_initial_sync: CachedPost.vote(op['author'], op['permlink']) voted_authors.add( op['author']) # TODO: move to cachedpost # misc ops elif op_type == 'transfer': Payments.op_transfer(op, tx_idx, num, date) elif op_type == 'custom_json': json_ops.append(op) Accounts.register(account_names, date) # register any new names Accounts.dirty(voted_authors) # update rep of voted authors Posts.comment_ops(comment_ops, date) # handle inserts, edits Posts.delete_ops(delete_ops) # handle post deletion CustomOp.process_ops(json_ops, num, date) # follow/reblog/community ops return num
def _process(cls, block): """Process a single block. Assumes a trx is open.""" #pylint: disable=too-many-branches assert issubclass(type(block), Block) num = cls._push(block) cls._current_block_date = block.get_date() # head block date shall point to last imported block (not yet current one) to conform hived behavior. # that's why operations processed by node are included in the block being currently produced, so its processing time is equal to last produced block. # unfortunately it is not true to all operations, most likely in case of dates that used to come from # FatNode where it supplemented it with its-current head block, since it was already past block processing, # it saw later block (equal to _current_block_date here) if cls._head_block_date is None: cls._head_block_date = cls._current_block_date ineffective_deleted_ops = Blocks.prepare_vops( Posts.comment_payout_ops, block, cls._current_block_date, num, num <= cls._last_safe_cashout_block) json_ops = [] for transaction in block.get_next_transaction(): assert issubclass(type(transaction), Transaction) for operation in transaction.get_next_operation(): assert issubclass(type(operation), Operation) start = OPSM.start() op_type = operation.get_type() assert op_type, "Only supported types are expected" op = operation.get_body() assert 'block_num' not in op op['block_num'] = num account_name = None op_details = None potentially_new_account = False # account ops if op_type == OperationType.Pow: account_name = op['worker_account'] potentially_new_account = True elif op_type == OperationType.Pow2: account_name = op['work']['value']['input'][ 'worker_account'] potentially_new_account = True elif op_type == OperationType.AccountCreate: account_name = op['new_account_name'] op_details = op potentially_new_account = True elif op_type == OperationType.AccountCreateWithDelegation: account_name = op['new_account_name'] op_details = op potentially_new_account = True elif op_type == OperationType.CreateClaimedAccount: account_name = op['new_account_name'] op_details = op potentially_new_account = True if potentially_new_account and not Accounts.register( account_name, op_details, cls._head_block_date, num): log.error( "Failed to register account {} from operation: {}". format(account_name, op)) # account metadata updates if op_type == OperationType.AccountUpdate: Accounts.update_op(op, False) elif op_type == OperationType.AccountUpdate2: Accounts.update_op(op, True) # post ops elif op_type == OperationType.Comment: Posts.comment_op(op, cls._head_block_date) elif op_type == OperationType.DeleteComment: key = "{}/{}".format(op['author'], op['permlink']) if key not in ineffective_deleted_ops: Posts.delete_op(op, cls._head_block_date) elif op_type == OperationType.CommentOption: Posts.comment_options_op(op) elif op_type == OperationType.Vote: Votes.vote_op(op, cls._head_block_date) # misc ops elif op_type == OperationType.Transfer: Payments.op_transfer(op, transaction.get_id(), num, cls._head_block_date) elif op_type == OperationType.CustomJson: # follow/reblog/community ops CustomOp.process_op(op, num, cls._head_block_date) OPSM.op_stats(str(op_type), OPSM.stop(start)) cls._head_block_date = cls._current_block_date return num