コード例 #1
0
 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()))
コード例 #2
0
 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
コード例 #3
0
 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
コード例 #4
0
ファイル: tests.py プロジェクト: Whiteblock/sawtooth-core
 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()))
コード例 #5
0
    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)))
コード例 #6
0
 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)
コード例 #7
0
    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)
コード例 #8
0
    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)
コード例 #9
0
 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()]
コード例 #10
0
 def _batch_index_keys(block):
     blkw = BlockWrapper.wrap(block)
     return [batch.header_signature.encode() for batch in blkw.batches]
コード例 #11
0
 def wrap_block(blk):
     return BlockWrapper.wrap(blk)
コード例 #12
0
    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)
コード例 #13
0
 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()]
コード例 #14
0
 def _batch_index_keys(block):
     blkw = BlockWrapper.wrap(block)
     return [batch.header_signature.encode()
             for batch in blkw.batches]
コード例 #15
0
ファイル: publisher.py プロジェクト: cianx/sawtooth-core
    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)))