Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed

in HiveDevs10 months ago (edited)

Repository

https://github.com/holgern/beem


beem-logo

beem is a python library for STEEM and HIVE. The current version is 0.23.0.

There is also a discord channel for beem: https://discord.gg/4HM592V

The newest beem version can be installed by:

pip install -U beem

Check that you are using hive nodes. The following command

beempy updatenodes --hive

updates the nodelist and uses only hive nodes. After setting hive as default_chain, beempy updatenodes can be used without switching to steem.

The list of nodes can be checked with

beempy config

and

beempy currentnode

shows the currently connected node.

Changelog for versions 0.23.0

  • new chain ID for HF24 on HIVE has been added
  • set hive as default for default_chain
  • get_steem_nodes added to NodeList
  • Prepared for Hive HF 24
  • steem object in all classes is replaced by blockchain
  • Hive class has been added
  • Hive and Steem are now BlockChainInstance classes
  • Hive and Steem have now is_hive and is_steem properties
  • Each class has now blockchain_instance parameter (steem_instance is stil available)
  • shared_blockchain_instance and set_shared_blockchain_instance can be used for Hive() and Steem() instances
  • token_symbol, backed_token_symbol and vest_token_symbol
  • Rename SteemWebsocket to NodeWebsocket and SteemNodeRPC to NodeRPC
  • Rshares, vote percentage and SBD/HBD calculation has been fixed for votes
  • post_rshares parameter added to all vote calculations
  • Account class has now get_token_power(), get_voting_value() and get_vote_pct_for_vote_value()
  • HF 23 and HF24 operations were added thanks to @flugschwein
  • Downvote power was added to Snapshot thanks to @flugschwein

New Hive class

There is a new Hive class that works similarly to the Steem class.

from beem import Hive
hive = Hive("https://api.hive.blog")
print(hive)

returns

<Hive node=https://api.hive.blog, nobroadcast=False>

Please node that Hive is not checking if the given node url is a hive node.

from beem import Hive
hive = Hive("https://api.steemit.com")
print(hive.get_blockchain_name())
print(hive.is_hive)

returns

steem
False

This allows beem to be compatible with old code. Thus, Steem() can still be used for Hive nodes.

from beem import Steem
hive = Steem("https://api.hive.blog")
print(hive)
print(hive.get_blockchain_name())

returns

<Steem node=https://api.hive.blog, nobroadcast=False>
hive

All steem objects are renamed to blockchain and steem_instance is now blockchain_instance

Each Account, Amount, Block, Blockchain, Comment, Discussions, Market, Price, Vote, Wallet and Witness object had a steem object which stored the Steem() class with the node-rpc. This is now renamed to blockchain:

from beem.account import Account
acc = Account("holger80")
print(acc.blockchain)

returns

<Hive node=https://api.hivekings.com, nobroadcast=False>

The Hive/Steem instance can no be set with blockchain_instance:

from beem.account import Account
from beem import Hive
hive = Hive("https://api.hive.blog")
acc = Account("holger80", blockchain_instance=hive)
print(acc.blockchain)

returns

<Hive node=https://api.hive.blog, nobroadcast=False>

steem_instance is still available and does the same as blockchain_instance:

from beem.account import Account
from beem import Hive
hive = Hive("https://api.hive.blog")
acc = Account("holger80", steem_instance=hive)
print(acc.blockchain)

returns

<Hive node=https://api.hive.blog, nobroadcast=False>

It is also possible to set the used blockchain instance with set_shared_blockchain_instance (set_shared_steem_instance is still available):

from beem import Hive
from beem.account import Account
from beem.instance import set_shared_blockchain_instance
hive = Hive("https://api.hive.blog")
set_shared_blockchain_instance(hive)
acc = Account("holger80")
print(acc.blockchain)

returns

<Hive node=https://api.hive.blog, nobroadcast=False>

Hive is the new default on a new installed pc

The nodes are stored in the persistent config. The new default for a freshly install beem is:

nodelist = NodeList()
{
'default_chain': 'hive',
'node': nodelist.get_hive_nodes(testnet=False)
...
}

Renaming of some functions

For Account

  • get_steem_power() -> get_token_power()
  • get_voting_value_SBD() -> get_voting_value()
  • get_vote_pct_for_SBD() -> get_vote_pct_for_vote_value()
  • sp -> tp is the same as get_token_power()

Steem() and Hive()

  • steem_symbol -> token_symbol
  • sbd_symbol -> backed_token_symbol
  • vests_symbol -> vest_token_symbol

Classes

  • SteemNodeRPC -> NodeRPC
  • SteemWebsocket -> Websocket

Hive() has some different functions names

  • rshares_to_hbd
  • get_hbd_per_rshares
  • get_hive_per_mvest
  • vests_to_hp
  • hp_to_vests
  • vests_to_hbd
  • hp_to_rshares
  • hbd_to_rshares
  • hbd_to_vote_pct

Vote calculation has been fixed

from beem.account import Account
acc = Account("holger80")
print("%.2f $" % acc.get_voting_value())

shows

0.95 $

which is the same amount as hive-now.com is showing:
image.png

What is my vote on a post showing 10 $?

The get_voting_value function has a post_rshares parameter, which can be used to answer such questions.

from beem import Hive
from beem.account import Account
hive = Hive()
acc = Account("holger80")
print("%.2f $ on a 10 $ post" % acc.get_voting_value(post_rshares=hive.hbd_to_rshares(10)))

returns

1.41 $ on a 10 $ post

Calculate the vote percentage

get_vote_pct_for_vote_value can be used to calculate the needed vote percentage.

Let's try to push the post output to exactly 10 $
image.png

from beem import Hive
from beem.account import Account
hive = Hive()
acc = Account("holger80")
print("%.2f %% needed to push the post to 10 $" % (acc.get_vote_pct_for_vote_value(10 - 9.337, post_rshares=hive.hbd_to_rshares(9.337))/100))

returns the needed vote percentage:

47.34 % needed to push the post to 10 $

Let's vote

beempy upvote -a holger80 -w 47.34 @ocd/ocd-daily-issue-542

It worked:
image.png


If you like what I do, consider casting a vote for me as witness on Hivesigner or on PeakD.

Sort:  

@holger80, your Hivesigner link has double .com in its address.

Thanks a lot! I am using your package a lot for all my local scripts and I have never taken the time to thank. Now it is done :)

PS: I will test the new version next week.

Ill definitely use your libs when I get into python. I think I already have when I was messing around with scripts

thanks for the info

This is important update

I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!