New version of Tower (Hivemind + REST)

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@emrebeyler·
0.000 HBD
New version of Tower (Hivemind + REST)
<center><img src="https://cdn.steemitimages.com/DQmNQ8RsVgaVaSw9uaezw7FjvEFxMZNWksejZg24TXF31Lz/Screen%20Shot%202019-01-16%20at%202.28.27%20PM.png"></center>
***
[Tower](https://github.com/emre/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

<center><img src="https://ipfs.busy.org/ipfs/QmP4tEDWNxHW6YE4TC4qvRKxZtpeLBw5NJY7hEWwdXwV2h"></center>
***

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.

<center><img src="https://ipfs.busy.org/ipfs/QmXomtZAGdvFtkuMigKrRq8tQdwRdJ7NZgjp8fN3bPTHH9"></center>

- `/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](https://github.com/emre/tower/issues/1) on account detail endpoint which was leading to 404 pages on account names including a `.` char on it. This issue is addressed w/ [cfe43f](https://github.com/emre/tower/commit/cfe43f77a31bf96ec7898393339a59220138262b).

# Public tower nodes

- `https://tower.emrebeyler.me` by @emrebeyler
- `https://hivemind.steemviz.com` by @ausbitbank.
- `https://tower.hive.oracle-d.com` by @oracle-d, @wehmoen.

# Pull requests and commits

- https://github.com/emre/tower/pull/2
- https://github.com/emre/tower/pull/3
- https://github.com/emre/tower/pull/4
- [cfe43f](https://github.com/emre/tower/commit/cfe43f77a31bf96ec7898393339a59220138262b)

### 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](https://steemconnect.com/sign/account-witness-vote?witness=emrebeyler&approve=1) or on [steemit.com](https://steemit.com/~witnesses)
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,