New version of Tower (Hivemind + REST)

in utopian-io •  2 months ago


Tower is a REST api service on the top Hivemind. It allows you to query a Hivemind database in terms of REST practices.

I have pushed a couple of updates and fixes to the Tower in the recent week.

Docker Installation Support

Tower may be a little bit tricky to configure/deploy if you don't have any experience with Python ecosystem.

In order to make the installation easier for parties interested, I have dockerized the app.

$ docker run -p 8090:8000 -e DB_PASS='hive' \
    -e DB_USER='hivemind_db_user' \
    -e DB_NAME='hivemind_db_name' \
    -e DB_PORT='5432' \
    -e DB_HOST='<hivemind_database_host_ip>' \
    emrebeyler/tower:stable

will install and run the application on :8090.

This uses pre-built image on my Dockerhub profile. As an alternative, you can also build the image directly.

$ git clone https://github.com/emre/tower.git
$ cd tower
$ docker build -t tower .
$ docker run -p 8090:8000 -e DB_PASS='hive' \
    -e DB_USER='hivemind_db_user' \
    -e DB_NAME='hivemind_db_name' \
    -e DB_PORT='5432' \
    -e DB_HOST='<hivemind_database_host_ip>' \
    tower

will do the same thing.

State API


Added a new /api/v1/state endpoint which represents the hive_state table in the database level.

It gives the latest processed block and dynamic global properties.

Relationship endpoints

4 new endpoints added to /api/v1/{username}/ namespace.

  • /api/v1/<username>/followers

Returns the follower list of <username.

  • /api/v1/<username>/following

Returns the following list of <username.

  • /api/v1/<username>/muting

Returns the muting list of <username.

  • /api/v1/<username>/muters

Returns the muter list of <username.

There is no pagination on any of these endpoints. Getting the list without pagination is not possible on RPC nodes, which makes the process slower in most cases.

In comparison, it's way more efficient to use Hivemind/Tower to get these lists.

Example:

Get the follower list of @utopian-io w/ steem-python:

$ time python -c 'from steem.account import Account;from steem import Steem;print(len(Account("utopian-io", steemd_instance=Steem(nodes=["https://rpc.usesteem.com"])).get_followers()));'

Result:

10937
python -c   0.54s user 0.32s system 6% cpu 13.952 total

Same script using Tower:

$ time python -c 'import requests; print(len(requests.get("http://tower.emrebeyler.me/api/v1/accounts/utopian-io/followers/").json()["followers"]))'

Result:

10936
python -c   0.36s user 0.31s system 29% cpu 2.264 total

6x more efficient, obviously.

By the way, there is a discrepancy on the follower count between Hivemind and RPC node. Investigating it.

Fix on /api/v1/accounts

There was a bug on account detail endpoint which was leading to 404 pages on account names including a . char on it. This issue is addressed w/ cfe43f.

Public tower nodes

Pull requests and commits

Vote for my 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

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:  
  • Good looking post, but mostly great achievement for the docker and new end points.
  • Code could use more comments, post could use code samples.

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? Chat with us on Discord.

[utopian-moderator]

·

Thank you for your review, @helo! Keep up the good work!

What about:

/api/v1/<author>/<permlink>/upvotes

And such. You’ll have to parse hive_posts_cache.votes as CSV and filter them. But it might come in handy.

·

Great idea! Will implement, soon.

@paulag, I believe you had asked the state API before. Check the post.

·

Awesome, i look forward to using it. Im gonna try it later

Posted using Partiko Android

Thank you so much for participating the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!

hiç kod bilgisi olmayanlar için, yer varmı ?

·

bize yok derler

El código podría usar más comentarios, la publicación podría usar ejemplos de código.

I love it. Is there anything more to say? Setting this up really quick now!

·

Enjoy! Let me know if you encounter any issues.

·
·

Thanks for helping through Discord while setting up the Oracle-D tower installation :)

good. good but a little more descriptive though

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!

This post has been included in the latest edition of SoS Daily News - a digest of all you need to know about the State of Steem.



Dear @emrebeyler

I was wondering if you're receiving any of my messages on Discord? I tried to re-connect with you but so far it seem that you're not seeing any of my messages.

Yours
Piotr