Lightsteem 0.0.7 - Account helper is arrived.

in lightsteem •  2 months ago

It's been a while since the last update on Lightsteem. It's my primary way to interact with the STEEM blockchain.

Adding helper classes and functions for well-known blockchain objects was in the plans in the initial design of Lightsteem. Later on, I have decided to put this on hold to see how it goes to develop with Lightsteem.

While I was enjoying Lightsteem in the last couple of weeks (as a library user), I had to implement similar stuff (recursive account history, recursive follow/follower list) and repeating myself in different projects, and scripts.

Therefore, the new plan is going back to the old plan and implementing helpers module. The first iteration includes Account and Amount helpers.

Installation / Upgrading


$ (sudo) pip install lightsteem --upgrade

Account helper


This class defines an Account in the STEEM blockchain.

from lightsteem.client import Client
c = Client()
account = c.get_account('emrebeyler')
Account History

Screen Shot 2018-09-04 at 5.20.07 PM.png


account_history is an important call for the STEEM applications. A few use cases:

  • Getting incoming delegations
  • Filtering transfers on specific accounts
  • Getting author, curation rewards

etc.

Example: Get all incoming STEEM of binance account in the last 7 days

import datetime

from lightsteem.client import Client
from lightsteem.helpers.amount import Amount

client = Client()
account = client.account('deepcrypto8')

one_week_ago = datetime.datetime.utcnow() -
    datetime.timedelta(days=7)
total_steem = 0
for op in account.history(
        stop_at=one_week_ago,
        filter=["transfer"]):

    if op["to"] != "deepcrypto8":
        continue

    total_steem += Amount(op["amount"]).amount

print("Total STEEM deposited to Binance", total_steem)
Relationships (Follow, Mute)
Getting followers:

from lightsteem.client import Client

client = Client()
account = client.account('deepcrypto8')

print(account.followers())
Getting following

from lightsteem.client import Client

client = Client()
account = client.account('emrebeyler')
print(account.following())
Getting muters

from lightsteem.client import Client

client = Client()
account = client.account('emrebeyler')

print(account.ignorers())
Getting muted list

from lightsteem.client import Client

client = Client()
account = client.account('emrebeyler')

print(account.ignorings())
Voting Power

This helper method determines the account's voting power. In default, It considers
account's regenerated VP. (Actual VP)

If you want the VP at the time the last vote casted, you can pass consider_regeneration=False.

from lightsteem.client import Client

client = Client()
account = client.account('emrebeyler')

print(account.vp())
print(account.vp(consider_regeneration=False))
Normalized Account Reputation

from lightsteem.client import Client

client = Client()
account = client.account('emrebeyler')

print(account.reputation())

Default precision is 2. You can set it by passing precision=N parameter.

Amount helper


A simple class to convert "1234.1234 STEEM" kind of values to Decimal.


from lightsteem.helpers.amount import Amount

amount = Amount("42.5466 STEEM")

print(amount.amount)
print(amount.symbol)

Moar Helpers in the roadmap


  • Witness class
  • BlockStream class
  • Post class
  • Vote class
  • Converter class (vests to sp, etc.)

Bonus: Benchmark time


While implementing account.followers(), I have realized that steem-python and beem would be less efficient compared to lightsteem in accounts has a following more than 100.

Let's get the well known witness @blocktrades' followers with this three libraries:

  • Lightsteem
import logging


from lightsteem.client import Client

c = Client(loglevel=logging.DEBUG, nodes=["https://appbase.buildteam.io"])
account = c.account('blocktrades')

print(len(account.followers()))

  • Beem

from beem import Steem
from beem.account import Account

import logging
logging.basicConfig(level=logging.DEBUG)

steemd = Steem(node=["https://appbase.buildteam.io"])
acc = Account('blocktrades', steem_instance=steemd)

print(len(acc.get_followers()))
  • Steem-Python
from steem import Steem
from steem.account import Account

import logging
logging.basicConfig(level=logging.DEBUG)


steemd = Steem(nodes=["https://appbase.buildteam.io"])

acc = Account('blocktrades', steemd_instance=steemd)

print(len(acc.get_followers()))
Results

LibraryTotal Time SpentTotal Requests
LightSteem0.81s24
Beem1.46s240
Steem-Python0.87s240

In a small implementation detail, while steem-python and beem call the related RPC method with limit=100, lightsteem uses 1000 as default.

Contributing


  • You can stop by Lightsteem discord and join the development with your feedback and ideas.

  • You can pick an open issue and start working on it. But we should reach a consensus about the design decisions before any merge.

  • Make sure you update the documentation and unit tests for each change you do on the codebase.

Related pull request


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for your contribution.

  1. It is interesting to see the benchmarking for performance. But I wonder how many test-runs have you carried out.
  2. I notice some code are quite the same for example here seems taken from here, it would be better to give a reference somewhere in your project.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

·

I notice some code are quite the same for example here seems taken from here, it would be better to give a reference somewhere in your project.

Yep, base58 module stands for transaction signing stuff which is mostly derived from steem-python. It's already written in the earlier announcement posts and related pull requests.

For example, beem has a similar base58.py and bitshares-python has the same, and goes on. Also steem-python's base58 module is based on cryptocoins project, etc.

However, also adding somewhere in the project would make sense since this is not the first time I hear that.

Thanks.

·

Thank you for your review, @justyy!

So far this week you've reviewed 1 contributions. Keep up the good work!

First of all receive a cordial greeting, sorry if my question doesn't come up but I need help from someone with knowledge. I recently decided to create delegation accounts for my blood brothers. I didn't have much experience with that so when I created the first account I didn't copy the password. I took the delegation off the account but it's been more than 16 days and the delegation is not coming back to me. How can I get my SPs back? I would really appreciate any help that you or anyone else can please give me in this regard as I have not found this information anywhere.

·

It will take 1 month to take it back after you revoke your account creation delegation.

·
·

Thank you for your reply. Last night I asked the question to several witnesses and all have answered me and of course the answer coincides and is a relief to me. I'm proud of our witnesses!

Thank you for your continued contributions. Great stuff as always 😄

@DUnite supports this author!

·

Thank you.

Hi @emrebeyler!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @emrebeyler!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

awesome as always. I should really give another chance to steem + python

·