SteemSnippets 1.2.5, Block feed skeleton, get root comment and reputation snippets

in #utopian-io7 years ago (edited)

steemsnippetsv1.2.2(2).png

Hello !

After two weeks it's time for another update. This time I'll focus on only a few snippets and talk about some code change. I mostly did a lot of work to bring forth a block parser skeleton with dsteem. To Allow you to easily act on some actions as soon as they enter the blockchain.

If you're wondering what this project is about you can find the long version here : https://steemit.com/programming/@howo/introducting-steemsnippets

In short :

Steemsnippets is a repository with lots of small snippets examples with a very specific functionnality in mind so that programmers who are beginners ( or not) with the steem ecosystem can go in there and be like "ok how I do that ?" and find a corresponding snippet with complete documentation associated with it.

Slight modifications :

  • The repository is now using the MIT license !

  • The voting and posting snippets now use the posting key instead of the password which was insecure.

  • Rewrote part of the readme to organize steemjs snippets in two categories : active aka putting operations on the blockchain and passive aka reading stuff from it.

  • Fixed a few errors on the README function

    Most of this small work can be found in the history of the commits : https://github.com/drov0/steemsnippets/commits/master

New snippets :

Block feed

This is a big one, way bigger than my usual snippets but for a good reason.

This snippet reads the blocks as they go live in the blockchain and for every operation inside of it there is an if clause to allow you to act on.

Want to build a service where you activate their account as soon as you receive a payment ? Instead of having a function to check every x minutes if you received a payment, you can now know instantly. Same goes for trailing votes/ Making some pretty website where you see the flow of posts/comments etc. Or if you want your own ginabot to send you a dm/mail whenever something is happening on the blockchain that concerns you.

This is also a great baseline if you have a project where you want to store some specific operations in a db for later use.

I think I have added all the possible operations. but I let an "else" case anyways to future proof it.

I won't show a code example in this post as it wouldn't make much sense without the context. So come check it out on github :D

https://github.com/drov0/steemsnippets/commit/c0bb40ae527a9558805bb840fbbdc41c0cfabc02

Get root post

Recently I found myself in a situation where I had a comment, the permlink and the author of that comment but not the actual post on which it was posted. So I wrote a function to get that :D

This function catches errors and returns them properly in case of rpc errors.

The example easily shows how it works

I will show you how to get @wehmoen cool project, pixelhosting introduction post from this comment

   // working example
    let data =  await get_root_post("howo", "re-pixelhosting-pixelhosting-by-wehmoen-free-image-hosting-for-steem-projects-20180422t001219308z");
    console.log(data); // { root_permlink: 'pixelhosting-by-wehmoen-free-image-hosting-for-steem-projects', root_author: 'pixelhosting' }

    // comment that doesn't exist
    data =  await get_root_post("howo", "re-pixeddddlhosting-pixelhosting-by-wehmoen-free-image-hosting-for-steem-projects-20180422t001219308z");
    console.log(data) // { error: 'content not found' }

related commit : https://github.com/drov0/steemsnippets/commit/a67decc3e171e585d45008b7fd38495be5f20eb4

Get reputation

After the simplified rep to raw from last week : https://github.com/drov0/steemsnippets/tree/master/steemjs/simplified_rep_to_raw we continue our work on reputation with a snippet to get the simple and raw reputation from an user.

This function catches errors and returns them properly in case of rpc errors/nonexistant accounts.

The example :

    // working example
    let data =  await get_reputation("howo");
    console.log(data); // { simplified_reputation: 63, raw_reputation: '17178492578569' }

    // account that doesn't exist
    data =  await get_reputation("a");
    console.log(data) // { error: 'Account doesn't exist' }

related commit :

https://github.com/drov0/steemsnippets/commit/ace0fb809172c28d5f1a91f0ab2305010085c36a

SteemConnect incoming !

I have started to work with steemconnect so expect some snippets in the next weeks.

The project is open source so feel free to submit pull requests with your own snippets :)

@howo



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for your contribution.


Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Hey @justyy, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Thanks for changing the license to MIT!

Your code was awesome. Thanks for this lesson. I'm gonna try it so soon.

Thanks !

Snippets are a brilliant idea! I can see this making coding way easier. It reminds me of user defined procedures in old school programming. Awesome work.

That's exactly the idea :D

Nice work on this update. It's great to see all of these examples up on Github now. Makes a massive change since the end of last year when I first started diving into steemdev it was a struggle to find any examples at all.

Keep em coming, no doubt this is useful to many people. 👊

Thanks ! I started this project exactly because of that, no examples. So it was annoying as hell to do steem stuff proprely.

Thank you for this amazing post @howo. Maybe we will meet at the LCCS in october?

I doubt very much I'll miss that ;)

  • Are you a CSE engineer?You are brilliant in programming.Next time I also try to post on @utopian-io.
    Thanks @howo

Great content ...... keep it up.