def _create_block(self): return BlockWrapper.wrap( Block(header_signature='some_block_id', batches=[], header=BlockHeader(block_num=0, previous_block_id=NULL_BLOCK_IDENTIFIER). SerializeToString()))
def _transaction_index_keys(block): blkw = BlockWrapper.wrap(block) keys = [] for batch in blkw.batches: for txn in batch.transactions: keys.append(txn.header_signature.encode()) return keys
def _create_block(self): return BlockWrapper.wrap( Block( header_signature='some_block_id', batches=[], header=BlockHeader( block_num=0, previous_block_id=NULL_BLOCK_IDENTIFIER) .SerializeToString()))
def __init__(self, block_store, block_manager, transaction_executor, state_view_factory, block_sender, batch_sender, identity_signer, data_dir, config_dir, permission_verifier, batch_observers, batch_injector_factory=None): """ Initialize the BlockPublisher object Args: block_store (:obj: `BlockStore`): A BlockStore instance block_manager (:obj:`BlockManager`): A BlockManager instance transaction_executor (:obj:`TransactionExecutor`): A TransactionExecutor instance. state_view_factory (:obj:`NativeStateViewFactory`): NativeStateViewFactory for read-only state views. block_sender (:obj:`BlockSender`): The BlockSender instance. batch_sender (:obj:`BatchSender`): The BatchSender instance. chain_head_lock (:obj:`RLock`): The chain head lock. identity_signer (:obj:`Signer`): Cryptographic signer for signing blocks data_dir (str): path to location where persistent data for the consensus module can be stored. config_dir (str): path to location where configuration can be found. batch_injector_factory (:obj:`BatchInjectorFatctory`): A factory for creating BatchInjectors. """ super(BlockPublisher, self).__init__('block_publisher_drop') if block_store.chain_head is not None: chain_head = BlockWrapper.wrap(block_store.chain_head) chain_head_block = chain_head.block else: chain_head_block = None self._to_exception( PY_LIBRARY.call('block_publisher_new', block_store.pointer, block_manager.pointer, ctypes.py_object(transaction_executor), state_view_factory.pointer, ctypes.py_object(block_sender), ctypes.py_object(batch_sender), ctypes.py_object(chain_head_block), ctypes.py_object(identity_signer), ctypes.py_object(data_dir), ctypes.py_object(config_dir), ctypes.py_object(permission_verifier), ctypes.py_object(batch_observers), ctypes.py_object(batch_injector_factory), ctypes.byref(self.pointer)))
def chain_update(self, block, receipts): """Removes batches from the pending cache if found in the block store, and notifies any observers. """ block = BlockWrapper.wrap(block) with self._lock: for batch_id in block.header.batch_ids: if batch_id in self._pending: self._pending.remove(batch_id) self._update_observers(batch_id, ClientBatchStatus.COMMITTED)
def update_chain(self, new_chain, old_chain=None): """ Set the current chain head, does not validate that the block store is in a valid state, ie that all the head block and all predecessors are in the store. :param new_chain: The list of blocks of the new chain. :param old_chain: The list of blocks of the existing chain to remove from the block store. store. :return: None """ new_chain = [BlockWrapper.wrap(b) for b in new_chain] if old_chain: old_chain = [BlockWrapper.wrap(b) for b in old_chain] add_pairs = [(blkw.identifier, blkw) for blkw in new_chain] if old_chain: del_keys = [blkw.identifier for blkw in old_chain] else: del_keys = [] self._block_store.update(add_pairs, del_keys)
def _get_block(self, key): value = self._block_store.get(key) if value is None: raise KeyError('Block "{}" not found in store'.format(key)) return BlockWrapper.wrap(value)
def _block_num_index_keys(block): blkw = BlockWrapper.wrap(block) # Format the number to a 64bit hex value, for natural ordering return [BlockStore.block_num_to_hex(blkw.block_num).encode()]
def _batch_index_keys(block): blkw = BlockWrapper.wrap(block) return [batch.header_signature.encode() for batch in blkw.batches]
def wrap_block(blk): return BlockWrapper.wrap(blk)
def __init__(self, block_manager, transaction_executor, batch_committed, transaction_committed, state_view_factory, block_sender, batch_sender, chain_head, identity_signer, data_dir, config_dir, permission_verifier, batch_observers, batch_injector_factory=None): """ Initialize the BlockPublisher object Args: block_manager (:obj:`BlockManager`): A BlockManager instance transaction_executor (:obj:`TransactionExecutor`): A TransactionExecutor instance. batch_committed (fn(batch_id) -> bool): A function for checking if a batch is committed. transaction_committed (fn(transaction_id) -> bool): A function for checking if a transaction is committed. state_view_factory (:obj:`NativeStateViewFactory`): NativeStateViewFactory for read-only state views. block_sender (:obj:`BlockSender`): The BlockSender instance. batch_sender (:obj:`BatchSender`): The BatchSender instance. chain_head (:obj:`BlockWrapper`): The initial chain head. chain_head_lock (:obj:`RLock`): The chain head lock. identity_signer (:obj:`Signer`): Cryptographic signer for signing blocks data_dir (str): path to location where persistent data for the consensus module can be stored. config_dir (str): path to location where configuration can be found. batch_injector_factory (:obj:`BatchInjectorFatctory`): A factory for creating BatchInjectors. """ super(BlockPublisher, self).__init__('block_publisher_drop') if chain_head is not None: chain_head = BlockWrapper.wrap(chain_head) chain_head_block = chain_head.block else: chain_head_block = None self._to_exception(PY_LIBRARY.call( 'block_publisher_new', block_manager.pointer, ctypes.py_object(transaction_executor), ctypes.py_object(batch_committed), ctypes.py_object(transaction_committed), state_view_factory.pointer, ctypes.py_object(block_sender), ctypes.py_object(batch_sender), ctypes.py_object(chain_head_block), ctypes.py_object(identity_signer), ctypes.py_object(data_dir), ctypes.py_object(config_dir), ctypes.py_object(permission_verifier), ctypes.py_object(batch_observers), ctypes.py_object(batch_injector_factory), ctypes.byref(self.pointer)))