Lightsteem 0.0.7 - Account helper is arrived.

13 comments

emrebeyler
70
2 months agoBusy4 min read

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


Comments

Sort byBest