Tower: A REST API implementation on the top of Hivemind

The official STEEM public node, api.steemit.com started routing some of the endpoints (follow api + tags api) to a Hivemind instance. It looks like the current migration performs well.

I have been running a public Hivemind node for a while. Current endpoint list of Hivemind is limited, however, it has a powerful database where you can filter and audit blockchain actions.

Hivemind doesn't sync every type of operation into its internal database. But, you can access

  • accounts
  • posts/comments
  • relationships (follows, reblogs, etc.)

with a direct SQL query.

Introducing Tower

Tower is a solution to expose the Hivemind's database as REST API interface. You can have a look at the documentation at tower.emrebeyler.me, and the base URL for the API is: https://tower.emrebeyler.me/api/v1/.

Example Calls (/api/v1/accounts)

  • Get the accounts in Germany, ordered by highest reputation

/api/v1/accounts/?location__contains=Germany&ordering=-reputation

  • Get the most followed accounts (Top10)

/api/v1/accounts/?ordering=-followers&limit=10

  • List the accounts selected @inertia as their witness voting proxy

/api/v1/accounts/?proxy=inertia

  • Get an account detail

api/v1/accounts/emrebeyler/

Example Calls (/api/v1/post_cache)

/api/v1/post_cache/?author=emrebeyler&ordering=-payout

  • Find @inertia's first post in the chain

api/v1/post_cache/?author=inertia&ordering=created_at&limit=1

Example Calls (/api/v1/posts/)

  • Find @emrebeyler's posts where the community was dpoll.

api/v1/posts/?author=emrebeyler&community=poll

  • Find an author's deleted posts/comments

/api/v1/posts/?is_deleted=True&limit=10&author=author


These are just example queries. Make sure to check the documentation for filters and ordering options.

Limitations

Available filters and ordering choices may subject to change in the future. Also, keep in mind that this is an experimental service and depending of the costs, my tower.emrebeyler.me may become private.

Technical Details

Tower is a Python3.6 and Django application. It uses DRF to expose database models as a REST interface.

If you want to run a Tower instance, follow these steps.

Installation

$ git clone https://github.com/emre/tower.git
$ python3.6 -m venv tower-env
$ source tower-env/bin/activate
$ cd tower
$ pip install -r requirements.txt

Configuration

$ vim tower/local_settings.py

Add database information of your Hivemind:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'db_name',
        'USER': 'db_user',
        'PASSWORD': 'db_password',
        'HOST': 'host',
        'PORT': 'port',
    }
}

Running

For development:

$ python manage.py runserver

For production:

$ gunicorn tower.wsgi

Roadmap

  • More filtering options on posts and posts_cache tables. These tables are huge and don't have many indexes. If I come up with a fast solution, I plan to add more filtering options.

  • Additional view sets for relationships (follow, reblog, etc.) These are already handled on the hive's internal RPC server, not a priority but good to have.

Post Updates

Vote for me as a witness

I do my best to support the blockchain with my skills. If you like what I do, consider casting a vote on via Steemconnect or on steemit.com.

H2
H3
H4
Upload from PC
Video gallery
3 columns
2 columns
1 column
94 Comments