steem-scot - distributing token by comment command

in #utopian-io7 years ago (edited)

Repository

https://github.com/holgern/steem-scot

image.png

The python package steem-scot is an implementation for distribute Smart Contract Organizational Token (SCOT). It can be installed by

$ (sudo) pip install steem-scot

and depends on beem and steemengine.

Distribute token by specific comment commands

I added a second way for distributing token. Every steem account which has sufficient Token, is allowed to issue token to other by writing a command into a reply.
image.png

image.png

In this case, the scot-account was beembot and the scot-token is DRAGON. As I have more than 10 DRAGON, I'm allowed to write the !DRAGON command as reply. Whenever I'm doing this, the scot-account will issue a certain amount of the token to the parent author of my comment.

An example is the DRAMA token, which works in this way. So everyone can have their own DRAMA by using the steem-scot package.

Usage

The script should be running all day, so that new comments can be parsed and comments with the specified command can be found.

$ scot_by_comment /path/to/config.json

config.json

In order to be using the script, a config.json must be created. All fields must be included.

OptionValue
scot_accountsteem account name, which should distribute the token
scot_tokentoken symbol, which should be distributed
token_memomemo which is attached to each token transfer
wallet_passwordContains the beempy wallet password
no_broadcastWhen true, no transfer is made
min_staked_tokenMinimum amount of token a comment writer must have
send_token_amountAmount of token that will be send
sucess_reply_bodyReply body, when token are send
fail_reply_bodyReply body, when no token are sent (not min_staked_token available)
comment_commandCommand which must be included in a comment, to activate the bot

The sucess_reply_body can have a placeholder %s, which will be filled with the comment parent author. token_memo can also have a placeholder %s, which is replaced by the command issuer.

How does the script work

The posting and active key of the scot account, which will sent the token and reply to the comment with the command, needs to be stored in the beem wallet.

The script parses all comment ops by:

       for op in self.blockchain.stream(start=start_block, stop=stop_block, opNames=["comment"],  max_batch_size=50):
            cnt += 1
            last_block_num = op["block_num"]

last_block_num is stored in a shelve:

data_db = shelve.open('data.db')
data_db["last_block_num"] = last_block_num
data_db.close()

This allows it to start exactly there where the script was stopped. When a comment with a command was found (all comments which do not include the command string will be skipped):

if op["body"].find(self.config["comment_command"]) < 0:
    continue
if op["author"] == self.config["scot_account"]:
    continue
try:
    c_comment = Comment(op, steem_instance=self.stm)
    c_comment.refresh()
except:
    logger.warn("Could not read %s/%s" % (op["author"], op["permlink"]))
    continue
if c_comment.is_main_post():
    continue
if abs((c_comment["created"] - op['timestamp']).total_seconds()) > 9.0:
    logger.warn("Skip %s, as edited" % c_comment["authorperm"])
    continue
already_replied = False
for r in c_comment.get_all_replies():
    if r["author"] == self.config["scot_account"]:
        already_replied = True
if already_replied:
    continue

It is then checked if the comment writer has sufficient token. If this is the case, a comment is replied with the stored sucess_reply_body from the config file and send_token_amount token are sent to the parent author.

wallet = Wallet(c_comment["author"], steem_instance=self.stm)
token = wallet.get_token(self.config["scot_token"])
if token is None or float(token["balance"]) < self.config["min_staked_token"]:
    reply_body = self.config["fail_reply_body"]
elif c_comment["parent_author"] == c_comment["author"]:
    reply_body = "You cannot sent token to yourself."
else:
    if "%s" in self.config["sucess_reply_body"]:
        reply_body = self.config["sucess_reply_body"] % c_comment["parent_author"]
    else:
        reply_body = self.config["sucess_reply_body"]
    if "%s" in self.config["token_memo"]:
        token_memo = self.config["token_memo"] % c_comment["author"]
    else:
        token_memo = self.config["token_memo"]
    sendwallet = Wallet(self.config["scot_account"], steem_instance=self.stm)
    sendwallet.transfer(c_comment["parent_author"], self.config["send_token_amount"], self.config["scot_token"], token_memo)
reply_identifier = c_comment["authorperm"]
if self.config["no_broadcast"]:
    logger.info("%s" % reply_body)
else:
    self.stm.post("", reply_body, author=self.config["scot_account"], reply_identifier=reply_identifier)
time.sleep(4)

Commits

Version 0.2.0, added a way to distribution token by comment commands

GitHub Account

https://github.com/holgern

Sort:  

Very interesting way to send tokens, and it also seems very easy to use. As Asher said, it would be even better if you could specify the amount, and I look forward to seeing that in a future update!

Looking at the code, here's some thoughts:

  • It's better to write if token is None as if not token.
  • Funny use of if "%s" in - haven't really seen it used like that before. In general I prefer f-strings and .format(), so maybe that's why.
  • Some code is pretty wide (had to scroll horizontally on GitHub to actually see everything), so I'd reformat it if I were you.

Great job once again, Holger! I'm looking forward to the next update!


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, @amosbastian! Keep up the good work!

Hi @holger80 ! We are so excited to connect with you again as moonSTEEM V2 is NOW LIVE and BIGGER !

Try your luck, possibility to win more than 300 STEEM every round !
FREE Upvote player lottery worth 0.78$ every 2 and half hours !

🚀🌕 PLAY NOW on moonSTEEM.com !

Earn tokens by playing, delegating, bringing friends, investing and get a share of profits !
Invest in the Bankroll and get even more profits !

So just want to make sure im understanding correctly. This can be used for any steemengine token as long as you have at least 1 to send?

Posted using Partiko Android

Yes, this can be used with every steemengine token. There will be an account that transfer token and everyone who has sufficient token in their wallet can distribute them by writing a comment with the command.


Everything is okay! 👌


You received an automatic upvote, because I believe in you and I love what you create! 😉

A huge hug from @amico! 🤗

😍 I love promoting @steembasicincome, even with #sbi-skip! 😜


If you dislike this automatic message, please let me know: thanks! 🙏

Hi @holger80!

This looks good, I want to do the following right now :D

!ENGAGE 200

That's a good inspiration for my next update, thanks:)

Posted using Partiko Android

Could you host something for everyone's tokens? That would be awesome!

The problem is that sending token needs the active authority, it's not like voting...

Thank you so much for participating in 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 @holger80!

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

Hi, @holger80!

You just got a 3.2% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Hey, @holger80!

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!

Hi @Holger80,

Cool stuff, we will test this the next days.

We will come back with some cool surprise for all Steemians.

You have been infected by the King of Disease!

Will you quarantine yourself?

Or will you spread the plague?

King Of Disease

!SSS Very Cool!

Dear holger80, The SSS is on its way!

Congratulations @holger80! You received a personal award!

Congratulations! You've been among the most infectious people during the April Fools' Steem Plague in 2019! organized by @suesa

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Hey man, I think @bookkeeping is down?