Steem-Python for dummies #2 - Playing with accounts

In the last post, we had set-up our development environment and learned how to create posts, comments, upvotes, and transfers in the blockchain.

In the second part of the "SteemPython for dummies" series, we will play with accounts in the blockchain. You can see the first part here.

Account data

Let's get the initial, public data of an account in the chain.

from steem.account import Account
account = Account('emrebeyler')
print(account)

This will print lots of data about my account. Since the output is huge, you can check an example response from here.

Three of useful metrics in that data are:

  • Reputation Points
  • Voting Powers (Percent)
  • Steem Power

1. Calculating Reputation Point

account data has a field of reputation which looks like a big number like this:

'reputation': '6458590899303',

This is not actually what we see in the Steemit interface (condenser). Condenser has an implementation to transform this value into a readable format. parsersAndFormatters.js in condenser source

steem-python package has a helper function trying to do the same for us, let's try it.

acc = Account('emrebeyler',  steemd_instance=s)
print("Raw Reputation point: %s" % acc["reputation"])
print("Calculated Reputation: %s" % acc.rep)

Output:

Raw Reputation point: 6458590899303
Calculated Reputation: 59.29

We can just use account.rep property to get the formatted point.

Tip: Currently, steem-python package has a little bug which results with miscalculated reputation points. (after formatting) You can see a potential solution and a pull request of mine here.

2. Calculating effective SP

Our effective steem power formula is easy:

total_sp = owned_sp + received_sp - delegated_sp

Let's implement this formula and find out my effective Steem Power.

To implement the SP amount of an account:

sp_vests = Amount(acc['vesting_shares']).amount
total_sp = round(acc.converter.vests_to_sp(sp_vests), 3)

For the received delegation and outgoing delegations:

received_vests = Amount(acc['received_vesting_shares']).amount
received_sp = round(acc.converter.vests_to_sp(received_vests), 3)
delegated_vests = Amount(acc['delegated_vesting_shares']).amount
delegated_sp = round(acc.converter.vests_to_sp(delegated_vests), 3)

Tip: Some of the data bounded to profile are VESTS which we can convert them to SP with a helper method steem-python. Package has a class of Converter which you can convert a lot of things like:

  • sp to vests
  • sp to rshares
  • steem to sbd
  • sbd to steem
  • sbd to rshares

Let's get back to calculating effective SP, Since I have all I need to calculate it, let's do the math.

print(total_sp + received_sp - delegated_sp)

will print my account's effective SP. (It should be around 843 now. It's hard to be a minnow.)

3. Calculating Voting Power

This is tricky topic. Let's get my account's voting power.

print(acc["voting_power"])

It returns an integer as 9141. Just divide it by 100, and you get the actual voting power.

But this is not up to date voting power. That caused a bug at steem.rocks. It turns out the data you get here is the voting power on the last vote time which is also specified in the account data.

Based on vote regeneration constants and last vote time, we can calculate up-to-date voting power ourselves.

Here is a simple implementation to calculate it right. Click the image to get the raw code.


That's all for this post. Feel free to ask questions or request topics about steem-python for the incoming posts.



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
9 Comments