Let me start off this post by saying that the library I've started working on isn't meant to replace either lighthive or beem. I'm not a big fan of beem myself, but lighthive by is a really good python lib for writing commandline scripts.
When building the hive archeology bot however, I kept running into the fact that long running processes like HIVE bots and DApp backends have a little bit different needs that aren't really such a good fit for this library.
Back in the STEEM days, I maintained the asyncsteem python library for Python 2, and for a long time I've been tempted to do something of a restart of an async python library that would be better suited for these kinds of tasks.
I just pushed the first bit of working code to github here. It's not much yet, but the basic structure is working, and a little piece of demo code is actually running.
The code is still rough and edgy, it needs a lot of work still, including docstrings, and the code hasn't even gone through a linter yet, but I'm already happy that I gor it working.
Let;s start to have a look at what the demo code using th unfinished library looks like right now.
#!/usr/bin/env python3
import asyncio
from aiohivebot import BaseBot
class MyBot(BaseBot):
async def vote_operation(self, body):
if "voter" in body and "author" in body and "permlink" in body:
print("Checking vote by", body["voter"])
content = await self.bridge.get_post(author=body["author"],
permlink=body["permlink"])
if "is_paidout" in content and content["is_paidout"]:
print(" + Vote on expired post detected: @" + body["author"] + "/" + body["permlink"] )
pncset = MyBot()
loop = asyncio.get_event_loop()
loop.run_until_complete(pncset.run(loop))
You can see straight away that the API is quite a bit different from a typical beem or lighthive script. The code is meant to run in an event driven async way, and most of this happens under the hood.
In the code we see that we subclass the BaseBot class and in this case we define a single method named vote_operation. Any valid operation type name is valid as a method name, and will result in the proper method being invoked for each such operation.
There are alo hooks for block, transaction and operation if you need more low-level operations.
The JSON-RPC API's, excluding broadcast operatiions should all be working, but not that robust yet, work on that is comming.
The interesting part is that the BaseBot is doing a lot of heavy lifting. It is connecting to most of the available public API nodes, and it's querying all of them for the existence of new blocks. While querying, it keeps track of node errors and request latency in order to always be able to call the fastest most reliable nose at any time.
At startup, and roughtly every hour, all the nodes get scanned for what JSON-RPC APIs they support, so that a JSON-RPC query isn't going to be sent to a node that doesn't support a given sub API, and if a JSON-RPC query still fails, there is a fail over to the other available nodes, sorted by reliabiltiy forst and latency second.
There is still a lot of work to do to get this library production ready, but this first milestone of having some code working is quite nice. As stated, this isn't going to be a general purpose HIVE library for Python. It's specificly aimed at bots and DApp backend code that needs to do new block based event handling.
Some things coming up soon:
- Docstrings
- Run the code through the linters (pycodestyle/pylint/vulture/etc)
- Error handling and exceptions
- Client side method/param checks
- Storage hooks for restarts withour lost events
- Push code to pypi
- Broadcast operations
I hope to soon have something available supporting close to what asyncsteem used to provide, but my first concern is to have enough working to port the hive arechology bot to aiohivebot soon.
Available for projects
If you think my skills and knowledge could be usefull for your project, I am currently available for contract work for up to 20 hours a week. My hourly rate depends on the type of activity (Python dev, C++ dev or data analysis), wether the project at hand will be open source or not, and if you want to sponsor my pet project coinZdense that aims to create a multi-language programming library for post-quantum signing and least authority subkey management.
| Activity | Hourly rate | Open source discount | Minimal hours | Maximum hours |
|---|---|---|---|---|
| C++ development | 150 $HBD/€ | 30 $HBD/€ | 4 | - |
| Python development | 140 $HBD/€ | 30 $HBD/€ | 4 | - |
| Data analysis (python/pandas) | 120 $HBD/€ | - | 2 | - |
| Sponsored coinZdense work | 50 $HBD/€ | - | 0 | - |
| Paired up coinZdense work | 25 $HBD/€ | - | 1 | 2x contract h |
Development work on open-source project get a 30 $HBD discount on my hourly rates.
Next to contract work, you can also become a sponsor of my coinZdense project.
Note that if you pair up to two coinZdense sponsor hours with a contract hour, you can sponsor twice the amount of hours to the coinZdense project.
If you wish to pay for my services or sponsor my project with other coins than $HBD, all rates are slightly higher (same rates, but in Euro or euro equivalent value at transaction time). I welcome payments in Euro (through paypall), $HIVE, $QRL $ZEC, $LTC, $DOGE, $BCH, $ETH or $BTC/lightning.
Contact: coin<at>z-den.se