Dicebot Dev Post #4: A New ApproachsteemCreated with Sketch.

in #steemit7 years ago

Code

So a while back I had the idea of developing a "dicebot" for Steem. This would be a bot that would scan posts in the blockchain for lines like @dicebot roll 4d6 and roll virtual dice and respond with a comment containing the result.

This has been a difficult process for me since, when I started out, I didn't really know much about blockchains and such on the most basic levels. I am very much learning as I go along. I can't recall why, but eventually I stopped working on the project; it might have been just around the time I (unwisely) took a time out from Steem as a whole for a couple months.

Well, now that I've fallen back in love with it, I've started to re-examine the idea of building this bot. And, completely forgetting the approach I had decided on in my last post, I again started writing it up in Swift.

This time, I decided to knuckle down and learn about WebSockets. It turns out Swift has a good WebSocket library called Starscream, but I was frustrated getting it to work with the list of Steem API servers I found in this post. As it turns out, that post is woefully out of date and most if not all of the servers in that list aren't actually working anymore; the one here seems to be far more up-to-date.

Okay, so I can connect to the server, so how about actually getting responses from it? The trick is to format JSON queries similar to what's outlined here, although that post isn't about the WebSocket interface per se. It wasn't long before I was able to get blocks and then iterate though their operations for "comments" and such.

Okay! Having come to terms with WebSockets, I started looking into how to create new comment transactions, including signing and "broadcasting" (posting) them to the blockchain. And that's where, as the kids say, shit starts getting real. Aside from creating a JSON object, I also need to do a binary encoding of the stuff I'm posting - okay, fair enough. And then I need to sign it with… all this weird crypto-babble about elliptical curves and stuff. Oh, no.

Well, perhaps unwisely, I haven't yet again given up on using Swift for this. Nonetheless, there's a whole lot I can get wrong in this process and not be aware of where the bug lies. I'd really like to have a mentor whose brain I could periodically pick on this sort of stuff and help me figure out where things might be going wrong. Alternatively, I might just go ahead and build a crude working prototype with the Python libraries just so I can see how things should be working while I recreate them in Swift.

Back at it tomorrow. Wish me luck.

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 62922.70
ETH 2543.02
USDT 1.00
SBD 2.83