create account

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

View this thread on: hive.blogpeakd.comecency.com
· @holger80 · (edited)
$77.24
Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed
## Repository

https://github.com/holgern/beem<center>
![beem-logo](https://cdn.steemitimages.com/DQmcRrwLPSywSYMierfP6um6mejeMNGjN9Rxw7audJqTDgb/beem-logo)
</center>
[beem](https://github.com/holgern/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](https://files.peakd.com/file/peakd-hive/holger80/vpp87qrJ-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](https://files.peakd.com/file/peakd-hive/holger80/9JWZO14d-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](https://files.peakd.com/file/peakd-hive/holger80/9Yvyehyv-image.png)



***
*If you like what I do, consider casting a vote for me as witness on [Hivesigner](https://hivesigner.com/sign/account-witness-vote?witness=holger80&approve=1) or on [PeakD](https://peakd.com/witnesses)*.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 318 others
👎  
properties (23)
authorholger80
permlinkupdate-for-beem-steem-objects-renamed-to-blockchain-new-hive-class-and-vote-calculation-has-been-fixed
categoryhive-139531
json_metadata{"app":"peakd/2020.04.3","format":"markdown","tags":["development","hive","beem","python"],"users":["flugschwein","ocd"],"links":["https://github.com/holgern/beem","https://github.com/holgern/beem","https://discord.gg/4HM592V","/@flugschwein","/@flugschwein","https://hivesigner.com/sign/account-witness-vote?witness=holger80&amp;approve=1","/witnesses"],"image":["https://cdn.steemitimages.com/DQmcRrwLPSywSYMierfP6um6mejeMNGjN9Rxw7audJqTDgb/beem-logo","https://files.peakd.com/file/peakd-hive/holger80/vpp87qrJ-image.png","https://files.peakd.com/file/peakd-hive/holger80/9JWZO14d-image.png","https://files.peakd.com/file/peakd-hive/holger80/9Yvyehyv-image.png"]}
created2020-04-18 19:35:03
last_update2020-04-18 20:25:54
depth0
children8
last_payout2020-04-25 19:35:03
cashout_time1969-12-31 23:59:59
total_payout_value40.919 HBD
curator_payout_value36.322 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,786
author_reputation358,857,509,568,825
root_title"Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id96,897,367
net_rshares188,493,966,701,467
author_curate_reward""
vote details (383)
@amico ·
___
A huge hug from @amico! 🤗
👍  
properties (23)
authoramico
permlinkre-update-for-beem-steem-objects-renamed-to-blockchain-new-hive-class-and-vote-calculation-has-been-fixed-20200418t193919z
categoryhive-139531
json_metadata"{"app": "rewarding/0.1.0"}"
created2020-04-18 19:39:27
last_update2020-04-18 19:39:27
depth1
children0
last_payout2020-04-25 19:39:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length32
author_reputation51,076,240,298,517
root_title"Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,897,429
net_rshares470,475,791
author_curate_reward""
vote details (1)
@chitty ·
I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!
properties (22)
authorchitty
permlinkre-update-for-beem-steem-objects-renamed-to-blockchain-new-hive-class-and-vote-calculation-has-been-fixed-20200420t000821
categoryhive-139531
json_metadata""
created2020-04-20 00:08:24
last_update2020-04-20 00:08:24
depth1
children0
last_payout2020-04-27 00:08:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length86
author_reputation86,901,300,608,582
root_title"Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,914,128
net_rshares0
@fth09000 ·
thanks for the info
properties (22)
authorfth09000
permlinkre-holger80-q917bx
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.04.3"}
created2020-04-19 10:48:00
last_update2020-04-19 10:48:00
depth1
children0
last_payout2020-04-26 10:48:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length19
author_reputation0
root_title"Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,905,355
net_rshares0
@lemouth ·
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.
properties (22)
authorlemouth
permlinkre-holger80-q908q0
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.04.3"}
created2020-04-18 22:20:24
last_update2020-04-18 22:20:24
depth1
children0
last_payout2020-04-25 22:20:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation338,011,164,701,274
root_title"Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,899,112
net_rshares0
@nrg ·
Ill definitely use your libs when I get into python. I think I already have when I was messing around with scripts
properties (22)
authornrg
permlinkq911u2
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-04-19 08:49:15
last_update2020-04-19 08:49:15
depth1
children0
last_payout2020-04-26 08:49:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length114
author_reputation1,378,983,266,690
root_title"Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,904,284
net_rshares0
@paragism ·
This is important update 
properties (22)
authorparagism
permlinkre-holger80-2020420t04036430z
categoryhive-139531
json_metadata{"tags":["development","hive","beem","python"],"app":"esteem/2.2.5-mobile","format":"markdown+html","community":"hive-125125"}
created2020-04-19 19:10:39
last_update2020-04-19 19:10:39
depth1
children0
last_payout2020-04-26 19:10:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length25
author_reputation36,292,755,022,096
root_title"Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,911,066
net_rshares0
@scorer ·
$0.13
@holger80, your Hivesigner link has double .com in its address.
👍  
👎  
properties (23)
authorscorer
permlinkq903b7
categoryhive-139531
json_metadata{"users":["holger80"],"app":"hiveblog/0.1"}
created2020-04-18 20:23:33
last_update2020-04-18 20:23:33
depth1
children1
last_payout2020-04-25 20:23:33
cashout_time1969-12-31 23:59:59
total_payout_value0.064 HBD
curator_payout_value0.065 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length63
author_reputation5,082,149,757,589
root_title"Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,897,905
net_rshares552,842,983,031
author_curate_reward""
vote details (2)
@holger80 ·
Thanks, I fixed the link.
👍  , , ,
properties (23)
authorholger80
permlinkre-scorer-q903pe
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.04.3"}
created2020-04-18 20:32:03
last_update2020-04-18 20:32:03
depth2
children0
last_payout2020-04-25 20:32:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length25
author_reputation358,857,509,568,825
root_title"Update for beem: steem objects renamed to blockchain, new Hive class and vote calculation has been fixed"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,898,005
net_rshares43,026,447,258
author_curate_reward""
vote details (4)