:mod:`viz.blockchain` ===================== .. py:module:: viz.blockchain Module Contents --------------- .. py:class:: Blockchain Bases: :class:`graphenecommon.blockchain.Blockchain` .. autoapi-inheritance-diagram:: viz.blockchain.Blockchain :parts: 1 :private-bases: This class allows to access the blockchain and read data from it. :param viz.viz.Client blockchain_instance: Client instance :param str mode: Irreversible block (``irreversible``) or actual head block (``head``) (default: *irreversible*) :param int max_block_wait_repetition: maximum wait time for next block is ``max_block_wait_repetition * block_interval`` (default 3) This class let's you deal with blockchain related data and methods. .. method:: hash_op(event: dict) :staticmethod: This method generates a hash of blockchain operation. .. method:: define_classes(self) .. method:: get_block_interval(self) Override class from graphenelib because our API is different. .. method:: stream_from(self, start_block: Optional[int] = None, end_block: Optional[int] = None, batch_operations: bool = False, full_blocks: bool = False, only_virtual_ops: bool = False) This call yields raw blocks or operations depending on ``full_blocks`` param. By default, this generator will yield operations, one by one. You can choose to yield lists of operations, batched to contain all operations for each block with ``batch_operations=True``. You can also yield full blocks instead, with ``full_blocks=True``. :param int start_block: Block to start with. If not provided, current (head) block is used. :param int end_block: Stop iterating at this block. If not provided, this generator will run forever (streaming mode). :param bool batch_operations: (Defaults to False) Rather than yielding operations one by one, yield a list of all operations for each block. :param bool full_blocks: (Defaults to False) Rather than yielding operations, return raw, unedited blocks as provided by blokchain_instance. This mode will NOT include virtual operations. :param bool only_virtual_ops: stream only virtual operations .. method:: stream(self, filter_by: Optional[Union[str, List[str]]] = None, start_block: Optional[int] = None, end_block: Optional[int] = None, raw_output: bool = False) Yield a stream of specific operations, starting with current head block. This method can work in 2 modes: 1. Whether only real operations are requested, it will use get_block() API call, so you don't need to have neigher operation_history nor accunt_history plugins enabled. 2. Whether you're requesting any of the virtual operations, your node should have operation_history or accunt_history plugins enabled and appropriate settings for the history-related params should be set (history-start-block, history-whitelist-ops or history-blacklist-ops). The dict output is formated such that ``type`` caries the operation type, timestamp and block_num are taken from the block the operation was stored in and the other key depend on the actual operation. :param str,list filter_by: List of operations to filter for :param int start_block: Block to start with. If not provided, current (head) block is used. :param int end_block: Stop iterating at this block. If not provided, this generator will run forever (streaming mode). :param bool raw_output: when streaming virtual ops, yield raw ops instead of extended ops format Example op when streaming virtual ops, ``raw_output = False``: .. code-block:: python { '_id': 'e2fabb498706edfccd1114921f05d95e8fd64e4c', 'type': 'witness_reward', 'timestamp': '2020-05-29T19:07:48', 'block_num': 1, 'trx_id': '0000000000000000000000000000000000000000', 'witness': 'committee', 'shares': '0.032999 SHARES', } Virtual op with ``raw_output = True``: .. code-block:: python { 'trx_id': '0000000000000000000000000000000000000000', 'block': 1, 'trx_in_block': 65535, 'op_in_trx': 0, 'virtual_op': 1, 'timestamp': '2020-05-29T19:28:08', 'op': ['witness_reward', {'witness': 'committee', 'shares': '0.032999 SHARES'}], } Real op example: .. code-block:: python { 'type': 'transfer', 'timestamp': '2020-05-29T19:20:07', 'block_num': 6, 'from': 'viz', 'to': 'alice', 'amount': '1.000 VIZ', 'memo': 'test stream', }