create account

steem-python tips #5 - Calculating witness rewards by emrebeyler

View this thread on: hive.blogpeakd.comecency.com
· @emrebeyler · (edited)
$18.41
steem-python tips #5 - Calculating witness rewards
<img src="https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5drxhdemuq4r4ezSCFC6xhAknvQspB_1680x8400">

#### Calculating witness rewards
***

Every time a witness produces a block, steem blockchain rewards the witness with a **producer_reward** operation in the blockchain. This is a virtul operation - don't exactly bounded to a transaction, therefore it doesn't have a transaction ID.

It is possible to go through the account history and calculate how much a witness made by being a witness. :)

Some of the properties of a producer_reward operation:

	{
	    'producer': 'emrebeyler',
	    'vesting_shares': '1980.464769 VESTS',
	    'block': 20633599,
	    'timestamp': '2018-03-13T07:48:27',
	}

#### Main Flow of the script
***

- Go through the account history
- Filter "producer_reward" operations
- Sum all rewarded VESTS and convert to Steam Power

<center><img src="http://i.hizliresim.com/YgaNn2.png"></center>
<center><sup>My witness earnings so far. I am rich!</sup></center>

#### Script
***

```
from steem import Steem
from steem.account import Account
from steem.amount import Amount
from steem.converter import Converter
import logging
logger = logging.getLogger('producer rewards')
logger.setLevel(logging.INFO)
logging.basicConfig()
def calculate_producer_rewards(steemd_instance, witness_account):
    account = Account(witness_account,steemd_instance=steemd_instance)
    total_vests = 0
    for producer_reward in account.history_reverse(filter_by=["producer_reward"]):
        total_vests += Amount(producer_reward["vesting_shares"]).amount
    converter = Converter(steemd_instance=s)
    total_sp = converter.vests_to_sp(total_vests)
    return total_vests, total_sp
if __name__ == '__main__':
    s = Steem(nodes=["https://api.steemit.com"])
    witness_account = 'emrebeyler'
    vests, sp = calculate_producer_rewards(s, witness_account)
    print("Account: %s, Total Vests: %s, Total SP: %s" % (
        witness_account, round(vests, 2), round(sp, 2)))
```

See the script nicely formatted at [Github Gists](https://gist.github.com/emre/ffb0c8e895b0e4d9506f3f587664dd2b).

#### Notes
***

- This script scans all operation history. Execution time may take forever for old witnesses.

- Conversion to the SP is done with the current VESTS to SP rate. This is a dynamic variable and may differ from time to time.

#### Requirements
***

You need to have **steem-python** library installed in your local environment.

Have fun.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 85 others
properties (23)
authoremrebeyler
permlinksteam-python-tips-5-calculating-witness-rewards
categorysteem-python
json_metadata{"community":"busy","app":"steemit/0.1","format":"markdown","tags":["steem-python","python","witness","sndbox","busy"],"links":["https://gist.github.com/emre/ffb0c8e895b0e4d9506f3f587664dd2b"],"image":["https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5drxhdemuq4r4ezSCFC6xhAknvQspB_1680x8400","http://i.hizliresim.com/YgaNn2.png"]}
created2018-03-14 17:39:54
last_update2018-03-14 19:23:51
depth0
children9
last_payout2018-03-21 17:39:54
cashout_time1969-12-31 23:59:59
total_payout_value15.575 HBD
curator_payout_value2.833 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,472
author_reputation448,535,049,068,622
root_title"steem-python tips #5 - Calculating witness rewards"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id44,419,941
net_rshares5,694,147,232,301
author_curate_reward""
vote details (149)
@chitty ·
$0.05
This is a very useful script for witnesses!
👍  
properties (23)
authorchitty
permlinkre-emrebeyler-steam-python-tips-5-calculating-witness-rewards-20180318t190833123z
categorysteem-python
json_metadata{"tags":["steem-python"],"app":"steemit/0.1"}
created2018-03-18 19:08:24
last_update2018-03-18 19:08:24
depth1
children0
last_payout2018-03-25 19:08:24
cashout_time1969-12-31 23:59:59
total_payout_value0.040 HBD
curator_payout_value0.013 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length43
author_reputation86,901,300,608,582
root_title"steem-python tips #5 - Calculating witness rewards"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,194,315
net_rshares16,413,078,190
author_curate_reward""
vote details (1)
@fadil94 ·
informasi sangat beemanfaat, kamu telah melakukan pekerjaan yang mulia, terimakasih telah berbagi..good luck
properties (22)
authorfadil94
permlinkre-emrebeyler-steam-python-tips-5-calculating-witness-rewards-20180315t085232943z
categorysteem-python
json_metadata{"tags":["steem-python"],"app":"steemit/0.1"}
created2018-03-15 08:52:39
last_update2018-03-15 08:52:39
depth1
children0
last_payout2018-03-22 08:52: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_length108
author_reputation803,879,722,663
root_title"steem-python tips #5 - Calculating witness rewards"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id44,551,839
net_rshares0
@flugschwein ·
I don't think you want to have **_steam_** python tips in your title ;)
properties (22)
authorflugschwein
permlinkre-emrebeyler-steam-python-tips-5-calculating-witness-rewards-20180314t191906021z
categorysteem-python
json_metadata{"tags":["steem-python"],"app":"steemit/0.1"}
created2018-03-14 19:19:06
last_update2018-03-14 19:19:06
depth1
children2
last_payout2018-03-21 19:19:06
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_length71
author_reputation11,950,112,708,339
root_title"steem-python tips #5 - Calculating witness rewards"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id44,437,481
net_rshares0
@emrebeyler ·
fixed. thanks!
properties (22)
authoremrebeyler
permlinkre-flugschwein-re-emrebeyler-steam-python-tips-5-calculating-witness-rewards-20180314t192409218z
categorysteem-python
json_metadata{"tags":["steem-python"],"app":"steemit/0.1"}
created2018-03-14 19:24:09
last_update2018-03-14 19:24:09
depth2
children1
last_payout2018-03-21 19:24:09
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_length14
author_reputation448,535,049,068,622
root_title"steem-python tips #5 - Calculating witness rewards"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id44,438,303
net_rshares0
@flugschwein ·
You're welcome. I'm glad I could help.
properties (22)
authorflugschwein
permlinkre-emrebeyler-re-flugschwein-re-emrebeyler-steam-python-tips-5-calculating-witness-rewards-20180314t193721307z
categorysteem-python
json_metadata{"tags":["steem-python"],"app":"steemit/0.1"}
created2018-03-14 19:37:24
last_update2018-03-14 19:37:24
depth3
children0
last_payout2018-03-21 19:37: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_length38
author_reputation11,950,112,708,339
root_title"steem-python tips #5 - Calculating witness rewards"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id44,440,380
net_rshares0
@geekpowered ·
$0.05
Cool little script. Might be useful for a dashboard or site or something.
👍  
properties (23)
authorgeekpowered
permlinkre-emrebeyler-steam-python-tips-5-calculating-witness-rewards-20180319t042612952z
categorysteem-python
json_metadata{"tags":["steem-python"],"app":"steemit/0.1"}
created2018-03-19 04:26:12
last_update2018-03-19 04:26:12
depth1
children1
last_payout2018-03-26 04:26:12
cashout_time1969-12-31 23:59:59
total_payout_value0.040 HBD
curator_payout_value0.011 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length73
author_reputation99,319,261,112,097
root_title"steem-python tips #5 - Calculating witness rewards"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,264,803
net_rshares16,413,078,190
author_curate_reward""
vote details (1)
@emrebeyler ·
That's actually a good idea - I will do a leaderboard for the top100 witnesses :)
👍  
properties (23)
authoremrebeyler
permlinkre-geekpowered-re-emrebeyler-steam-python-tips-5-calculating-witness-rewards-20180319t065836032z
categorysteem-python
json_metadata{"tags":["steem-python"],"app":"steemit/0.1"}
created2018-03-19 06:58:36
last_update2018-03-19 06:58:36
depth2
children0
last_payout2018-03-26 06:58:36
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_length81
author_reputation448,535,049,068,622
root_title"steem-python tips #5 - Calculating witness rewards"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,284,086
net_rshares3,310,197,232
author_curate_reward""
vote details (1)
@sumanbiswas ·
Great informative update news...thank you so much...i like it...
properties (22)
authorsumanbiswas
permlinkre-emrebeyler-steam-python-tips-5-calculating-witness-rewards-20180314t180252068z
categorysteem-python
json_metadata{"tags":["steem-python"],"app":"steemit/0.1"}
created2018-03-14 18:02:57
last_update2018-03-14 18:02:57
depth1
children0
last_payout2018-03-21 18:02:57
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_length64
author_reputation425,351,397,895
root_title"steem-python tips #5 - Calculating witness rewards"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id44,424,111
net_rshares0
@tooche ·
İyiymiş bu sistem teşekkürler 😊
properties (22)
authortooche
permlinkre-emrebeyler-steam-python-tips-5-calculating-witness-rewards-20180314t174254096z
categorysteem-python
json_metadata{"tags":["steem-python"],"app":"steemit/0.1"}
created2018-03-14 17:42:57
last_update2018-03-14 17:42:57
depth1
children0
last_payout2018-03-21 17:42:57
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_length31
author_reputation3,291,365,132
root_title"steem-python tips #5 - Calculating witness rewards"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id44,420,481
net_rshares0