viz.blockchain
¶
Module Contents¶
-
class
Blockchain
¶
- 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.
-
static
hash_op
(event: dict)¶ This method generates a hash of blockchain operation.
-
define_classes
(self)¶
-
get_block_interval
(self)¶ Override class from graphenelib because our API is different.
-
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, withfull_blocks=True
.- Parameters
start_block (int) – Block to start with. If not provided, current (head) block is used.
end_block (int) – Stop iterating at this block. If not provided, this generator will run forever (streaming mode).
batch_operations (bool) – (Defaults to False) Rather than yielding operations one by one, yield a list of all operations for each block.
full_blocks (bool) – (Defaults to False) Rather than yielding operations, return raw, unedited blocks as provided by blokchain_instance. This mode will NOT include virtual operations.
only_virtual_ops (bool) – stream only virtual operations
-
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.- Parameters
Example op when streaming virtual ops,
raw_output = False
:{ '_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
:{ '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:
{ 'type': 'transfer', 'timestamp': '2020-05-29T19:20:07', 'block_num': 6, 'from': 'viz', 'to': 'alice', 'amount': '1.000 VIZ', 'memo': 'test stream', }