Blockchain

Read blockchain related data-

from bitshares.blockchain import Blockchain
chain = Blockchain()

Read current block and blockchain info

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

Monitor for new blocks ..

for block in chain.blocks():
    print(block)

... or each operation individually:

for operations in chain.ops():
    print(operations)
class bitshares.blockchain.Blockchain(bitshares_instance=None, mode='irreversible')

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

Parameters:
  • bitshares_instance (bitshares.bitshares.BitShares) – BitShares instance
  • mode (str) – (default) Irreversible block (irreversible) or actual head block (head)

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

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:bitshares.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)

Yields blocks starting from start.

Parameters:
  • start (int) – Starting block
  • stop (int) – Stop at this block
  • mode (str) – We here have the choice between * “head”: the last block * “irreversible”: the block that is confirmed by 2/3 of all block producers and is thus irreversible!
chainParameters()

The blockchain parameters, such as fees, and committee-controlled parameters are returned here

config()

Returns object 2.0.0

get_all_accounts(start='', stop='', steps=1000.0, **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_chain_properties()

Return chain properties

get_current_block()

This call returns the current block

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

Note

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

get_network()

Identify the network

Returns:Network parameters
Return type:dict
info()

This call returns the dynamic global properties

ops(start=None, stop=None, **kwargs)

Yields all operations (including virtual operations) starting from start.

Parameters:
  • start (int) – Starting block
  • stop (int) – Stop at this block
  • mode (str) – We here have the choice between * “head”: the last block * “irreversible”: the block that is confirmed by 2/3 of all block producers and is thus irreversible!
  • only_virtual_ops (bool) – Only yield virtual operations

This call returns a list that only carries one operation and its type!

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
  • mode (str) – We here have the choice between * “head”: the last block * “irreversible”: the block that is confirmed by 2/3 of all block producers and is thus irreversible!

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.