beem.hive

class beem.hive.Hive(node='', rpcuser=None, rpcpassword=None, debug=False, data_refresh_time_seconds=900, **kwargs)

Bases: beem.blockchaininstance.BlockChainInstance

Connect to the Hive network.

Parameters:
  • node (str) – Node to connect to (optional)
  • rpcuser (str) – RPC user (optional)
  • rpcpassword (str) – RPC password (optional)
  • nobroadcast (bool) – Do not broadcast a transaction! (optional)
  • unsigned (bool) – Do not sign a transaction! (optional)
  • debug (bool) – Enable Debugging (optional)
  • keys (array, dict, string) – Predefine the wif keys to shortcut the wallet database (optional)
  • wif (array, dict, string) – Predefine the wif keys to shortcut the wallet database (optional)
  • offline (bool) – Boolean to prevent connecting to network (defaults to False) (optional)
  • expiration (int) – Delay in seconds until transactions are supposed to expire (optional) (default is 30)
  • blocking (str) – Wait for broadcasted transactions to be included in a block and return full transaction (can be “head” or “irreversible”)
  • bundle (bool) – Do not broadcast transactions right away, but allow to bundle operations. It is not possible to send out more than one vote operation and more than one comment operation in a single broadcast (optional)
  • appbase (bool) – Use the new appbase rpc protocol on nodes with version 0.19.4 or higher. The settings has no effect on nodes with version of 0.19.3 or lower.
  • num_retries (int) – Set the maximum number of reconnects to the nodes before NumRetriesReached is raised. Disabled for -1. (default is -1)
  • num_retries_call (int) – Repeat num_retries_call times a rpc call on node error (default is 5)
  • timeout (int) – Timeout setting for https nodes (default is 60)
  • use_hs (bool) – When True, a hivesigner object is created. Can be used for broadcast posting op or creating hot_links (default is False)
  • hivesigner (HiveSigner) – A HiveSigner object can be set manually, set use_hs to True
  • custom_chains (dict) – custom chain which should be added to the known chains

Three wallet operation modes are possible:

  • Wallet Database: Here, the beemlibs load the keys from the locally stored wallet SQLite database (see storage.py). To use this mode, simply call Hive() without the keys parameter
  • Providing Keys: Here, you can provide the keys for your accounts manually. All you need to do is add the wif keys for the accounts you want to use as a simple array using the keys parameter to Steem().
  • Force keys: This more is for advanced users and requires that you know what you are doing. Here, the keys parameter is a dictionary that overwrite the active, owner, posting or memo keys for any account. This mode is only used for foreign signatures!

If no node is provided, it will connect to default nodes from beem.NodeList. Default settings can be changed with:

hive = Hive(<host>)

where <host> starts with https://, ws:// or wss://.

The purpose of this class it to simplify interaction with Hive.

The idea is to have a class that allows to do this:

>>> from beem import Hive
>>> hive = Hive()
>>> print(hive.get_blockchain_version())  

This class also deals with edits, votes and reading content.

Example for adding a custom chain:

from beem import Hive
stm = Hive(node=["https://mytstnet.com"], custom_chains={"MYTESTNET":
    {'chain_assets': [{'asset': 'HBD', 'id': 0, 'precision': 3, 'symbol': 'HBD'},
                      {'asset': 'STEEM', 'id': 1, 'precision': 3, 'symbol': 'STEEM'},
                      {'asset': 'VESTS', 'id': 2, 'precision': 6, 'symbol': 'VESTS'}],
     'chain_id': '79276aea5d4877d9a25892eaa01b0adf019d3e5cb12a97478df3298ccdd01674',
     'min_version': '0.0.0',
     'prefix': 'MTN'}
    }
)
chain_params
get_hbd_per_rshares(not_broadcasted_vote_rshares=0, use_stored_data=True)

Returns the current rshares to HBD ratio

get_hive_per_mvest(time_stamp=None, use_stored_data=True)

Returns the MVEST to HIVE ratio

Parameters:time_stamp (int) – (optional) if set, return an estimated HIVE per MVEST ratio for the given time stamp. If unset the current ratio is returned (default). (can also be a datetime object)
get_network(use_stored_data=True, config=None)

Identify the network

Parameters:use_stored_data (bool) – if True, stored data will be returned. If stored data are empty or old, refresh_data() is used.
Returns:Network parameters
Return type:dictionary
get_token_per_mvest(time_stamp=None, use_stored_data=True)

Returns the MVEST to TOKEN ratio

Parameters:time_stamp (int) – (optional) if set, return an estimated TOKEN per MVEST ratio for the given time stamp. If unset the current ratio is returned (default). (can also be a datetime object)
hardfork
hbd_symbol

get the current chains symbol for HBD (e.g. “TBD” on testnet)

hbd_to_rshares(hbd, not_broadcasted_vote=False, use_stored_data=True)

Obtain the r-shares from HBD

Parameters:
  • hbd (str, int, amount.Amount) – HBD
  • not_broadcasted_vote (bool) – not_broadcasted or already broadcasted vote (True = not_broadcasted vote). Only impactful for very high amounts of HBD. Slight modification to the value calculation, as the not_broadcasted vote rshares decreases the reward pool.
hbd_to_vote_pct(hbd, post_rshares=0, hive_power=None, vests=None, voting_power=10000, not_broadcasted_vote=True, use_stored_data=True)

Obtain the voting percentage for a desired HBD value for a given Hive Power or vesting shares and voting power Give either Hive Power or vests, not both. When the output is greater than 10000 or smaller than -10000, the HBD value is too high.

Returns the required voting percentage (100% = 10000)

Parameters:
  • hbd (str, int, amount.Amount) – desired HBD value
  • hive_power (number) – Hive Power
  • vests (number) – vesting shares
  • not_broadcasted_vote (bool) – not_broadcasted or already broadcasted vote (True = not_broadcasted vote). Only impactful for very high amounts of HBD. Slight modification to the value calculation, as the not_broadcasted vote rshares decreases the reward pool.
hive_symbol

get the current chains symbol for HIVE (e.g. “TESTS” on testnet)

hp_to_hbd(hp, post_rshares=0, voting_power=10000, vote_pct=10000, not_broadcasted_vote=True, use_stored_data=True)

Obtain the resulting HBD vote value from Hive power

Parameters:
  • hive_power (number) – Hive Power
  • post_rshares (int) – rshares of post which is voted
  • voting_power (int) – voting power (100% = 10000)
  • vote_pct (int) – voting percentage (100% = 10000)
  • not_broadcasted_vote (bool) – not_broadcasted or already broadcasted vote (True = not_broadcasted vote).

Only impactful for very big votes. Slight modification to the value calculation, as the not_broadcasted vote rshares decreases the reward pool.

hp_to_rshares(hive_power, post_rshares=0, voting_power=10000, vote_pct=10000, use_stored_data=True)

Obtain the r-shares from Hive power

Parameters:
  • hive_power (number) – Hive Power
  • post_rshares (int) – rshares of post which is voted
  • voting_power (int) – voting power (100% = 10000)
  • vote_pct (int) – voting percentage (100% = 10000)
hp_to_vests(hp, timestamp=None, use_stored_data=True)

Converts HP to vests

Parameters:
  • hp (float) – Hive power to convert
  • timestamp (datetime) – (Optional) Can be used to calculate the conversion rate from the past
is_hive
rshares_to_hbd(rshares, not_broadcasted_vote=False, use_stored_data=True)

Calculates the current HBD value of a vote

rshares_to_token_backed_dollar(rshares, not_broadcasted_vote=False, use_stored_data=True)

Calculates the current HBD value of a vote

rshares_to_vote_pct(rshares, post_rshares=0, hive_power=None, vests=None, voting_power=10000, use_stored_data=True)

Obtain the voting percentage for a desired rshares value for a given Hive Power or vesting shares and voting_power Give either hive_power or vests, not both. When the output is greater than 10000 or less than -10000, the given absolute rshares are too high

Returns the required voting percentage (100% = 10000)

Parameters:
  • rshares (number) – desired rshares value
  • hive_power (number) – Hive Power
  • vests (number) – vesting shares
  • voting_power (int) – voting power (100% = 10000)
token_power_to_token_backed_dollar(token_power, post_rshares=0, voting_power=10000, vote_pct=10000, not_broadcasted_vote=True, use_stored_data=True)

Obtain the resulting Token backed dollar vote value from Token power

Parameters:
  • hive_power (number) – Token Power
  • post_rshares (int) – rshares of post which is voted
  • voting_power (int) – voting power (100% = 10000)
  • vote_pct (int) – voting percentage (100% = 10000)
  • not_broadcasted_vote (bool) – not_broadcasted or already broadcasted vote (True = not_broadcasted vote).

Only impactful for very big votes. Slight modification to the value calculation, as the not_broadcasted vote rshares decreases the reward pool.

token_power_to_vests(token_power, timestamp=None, use_stored_data=True)

Converts TokenPower to vests

Parameters:
  • token_power (float) – Token power to convert
  • timestamp (datetime) – (Optional) Can be used to calculate the conversion rate from the past
vests_symbol

get the current chains symbol for VESTS

vests_to_hbd(vests, post_rshares=0, voting_power=10000, vote_pct=10000, not_broadcasted_vote=True, use_stored_data=True)

Obtain the resulting HBD vote value from vests

Parameters:
  • vests (number) – vesting shares
  • post_rshares (int) – rshares of post which is voted
  • voting_power (int) – voting power (100% = 10000)
  • vote_pct (int) – voting percentage (100% = 10000)
  • not_broadcasted_vote (bool) – not_broadcasted or already broadcasted vote (True = not_broadcasted vote).

Only impactful for very big votes. Slight modification to the value calculation, as the not_broadcasted vote rshares decreases the reward pool.

vests_to_hp(vests, timestamp=None, use_stored_data=True)

Converts vests to HP

Parameters:
  • vests/float vests (amount.Amount) – Vests to convert
  • timestamp (int) – (Optional) Can be used to calculate the conversion rate from the past
vests_to_rshares(vests, post_rshares=0, voting_power=10000, vote_pct=10000, subtract_dust_threshold=True, use_stored_data=True)

Obtain the r-shares from vests

Parameters:
  • vests (number) – vesting shares
  • post_rshares (int) – rshares of post which is voted
  • voting_power (int) – voting power (100% = 10000)
  • vote_pct (int) – voting percentage (100% = 10000)
vests_to_token_power(vests, timestamp=None, use_stored_data=True)

Converts vests to TokenPower

Parameters:
  • vests/float vests (amount.Amount) – Vests to convert
  • timestamp (int) – (Optional) Can be used to calculate the conversion rate from the past