beem.blockchain

class beem.blockchain.Blockchain(steem_instance=None, mode='irreversible', max_block_wait_repetition=None, data_refresh_time_seconds=900)

Bases: object

This class allows to access the blockchain and read data from it

Parameters:
  • steem_instance (beem.steem.Steem) – Steem instance
  • mode (str) – (default) Irreversible block (irreversible) or actual head block (head)
  • max_block_wait_repetition (int) – maximum wait repetition for next block where each repetition is block_interval long (default is 3)

This class let’s you deal with blockchain related data and methods. Read blockchain related data:

Read current block and blockchain info

print(chain.get_current_block())
print(chain.steem.info())

Monitor for new blocks. When stop is not set, monitoring will never stop.

blocks = []
current_num = chain.get_current_block_num()
for block in chain.blocks(start=current_num - 99, stop=current_num):
    blocks.append(block)
len(blocks)
100

or each operation individually:

ops = []
current_num = chain.get_current_block_num()
for operation in chain.ops(start=current_num - 99, stop=current_num):
    ops.append(operation)
awaitTxConfirmation(transaction, limit=10)

Returns the transaction as seen by the blockchain after being included into a block

Note

If you want instant confirmation, you need to instantiate class:beem.blockchain.Blockchain with mode="head", otherwise, the call will wait until confirmed in an irreversible block.

Note

This method returns once the blockchain has included a transaction with the same signature. Even though the signature is not usually used to identify a transaction, it still cannot be forfeited and is derived from the transaction contented and thus identifies a transaction uniquely.

block_time(block_num)

Returns a datetime of the block with the given block number.

Parameters:block_num (int) – Block number
block_timestamp(block_num)

Returns the timestamp of the block with the given block number.

Parameters:block_num (int) – Block number
blocks(start=None, stop=None, max_batch_size=None, threading=False, thread_num=8, only_ops=False, only_virtual_ops=False)

Yields blocks starting from start.

Parameters:
  • start (int) – Starting block
  • stop (int) – Stop at this block
  • max_batch_size (int) – only for appbase nodes. When not None, batch calls of are used. Cannot combine with threading
  • threading (bool) – Enables threading. Cannot be combined with batch calls
  • thread_num (int) – Defines the number of threads, when threading is set.
  • only_ops (bool) – Only yielding operations, when set to True (default: False)
  • only_virtual_ops (bool) – Only yield virtual operations (default: False)

Note

If you want instant confirmation, you need to instantiate class:beem.blockchain.Blockchain with mode="head", otherwise, the call will wait until confirmed in an irreversible block.

get_all_accounts(start='', stop='', steps=1000.0, limit=-1, **kwargs)

Yields account names between start and stop.

Parameters:
  • start (str) – Start at this account name
  • stop (str) – Stop at this account name
  • steps (int) – Obtain steps ret with a single call from RPC
get_current_block(only_ops=False, only_virtual_ops=False)

This call returns the current block

Parameters:
  • only_ops (bool) – Returns block with operations only, when set to True (default: False)
  • only_virtual_ops (bool) – Includes only virtual operations (default: False)

Note

The block number returned depends on the mode used when instanciating from this class.

get_current_block_num()

This call returns the current block number

Note

The block number returned depends on the mode used when instanciating from this class.

get_estimated_block_num(date, estimateForwards=False, accurate=True)

This call estimates the block number based on a given date

Parameters:date (datetime) – block time for which a block number is estimated

Note

The block number returned depends on the mode used when instanciating from this class.

get_transaction(transaction_id)

Returns a transaction from the blockchain

Parameters:transaction_id (str) – transaction_id
static hash_op(event)

This method generates a hash of blockchain operation.

is_irreversible_mode()
ops(start=None, stop=None, only_virtual_ops=False, **kwargs)

Blockchain.ops() is deprecated. Please use Blockchain.stream() instead.

ops_statistics(start, stop=None, add_to_ops_stat=None, verbose=False)

Generates a statistics for all operations (including virtual operations) starting from start.

Parameters:
  • start (int) – Starting block
  • stop (int) – Stop at this block, if set to None, the current_block_num is taken
  • add_to_ops_stat (dict) – if set, the result is added to add_to_ops_stat
  • verbose (bool) – if True, the current block number and timestamp is printed

This call returns a dict with all possible operations and their occurence.

stream(opNames=[], *args, **kwargs)

Yield specific operations (e.g. comments) only

Parameters:
  • opNames (array) – List of operations to filter for
  • start (int) – Start at this block
  • stop (int) – Stop at this block
  • max_batch_size (int) – only for appbase nodes. When not None, batch calls of are used. Cannot combine with threading
  • threading (bool) – Enables threading. Cannot be combined with batch calls
  • thread_num (int) – Defines the number of threads, when threading is set.
  • only_ops (bool) – Only yielding operations, when set to True (default: False)
  • only_virtual_ops (bool) – Only yield virtual operations (default: False)

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 actualy operation.

Note

If you want instant confirmation, you need to instantiate class:beem.blockchain.Blockchain with mode="head", otherwise, the call will wait until confirmed in an irreversible block.

wait_for_and_get_block(block_number, blocks_waiting_for=None, only_ops=False, only_virtual_ops=False)

Get the desired block from the chain, if the current head block is smaller (for both head and irreversible) then we wait, but a maxmimum of blocks_waiting_for * max_block_wait_repetition time before failure.

Parameters:
  • block_number (int) – desired block number
  • blocks_waiting_for (int) – difference between block_number and current head and defines how many blocks we are willing to wait, positive int (default: None)
  • only_ops (bool) – Returns blocks with operations only, when set to True (default: False)
  • only_virtual_ops (bool) – Includes only virtual operations (default: False)