WalletLocked exceptions in beempy?

in HiveDevs3 days ago

Been struggling with some code for reviving the Silent Bob curation on creativecoin in a few months. While I'm not a huge fan of synchronous python, I decided on beempy for the @silentbot bot. Tracing the curation commands on the chain works just fine, but when I try to take some actual action using the posting key of the bot, I keep getting WalletLocked exceptions. But I'm not using a wallet, just the posting key, because I want my bot to be running in docker on my NAS.

I hope maybe someone in the HiveDevs community can help me out to get this working.

In the constructor of my bot I'm doing something like this:

class SilentBot:
    def __init__(self, wif, rewind=5):
        self.stm = Hive(node="https://api.hive.blog", keys=[wif])
        self.account = Account(self.stm.wallet.getAccountFromPrivateKey(wif))

Then, later in my code:

    def star(self, author, permlink, star_count):
        comment = Comment("@" + author + "/" + permlink)
        power_up = (comment.json()["percent_hbd"] == 0)
        if star_count > 5:
            star_count = 5
        if star_count < 1:
            star_count = 1
        config = self.lookup[power_up][star_count]
        body = '<A HREF="' + config["link"] + '"><IMG SRC="' + config["icon"] + '"></A>'
        comment.reply(body=body, author=self.account)
        print("STAR", star_count, power_up, author, permlink, config["percentage"])
        self.vote_queue.append([config["percentage"], author, permlink])

At the moment comment.reply gets called I end up with a WalletLocked exception:

BLOCK: 59453240
BLOCK: 59453241
Traceback (most recent call last):
  File "./silentbot.py", line 141, in <module>
  File "./silentbot.py", line 129, in run
    count = self.upto_head()
  File "./silentbot.py", line 111, in upto_head
    self.invocation(vals["parent_author"], vals["parent_permlink"], vals["body"])
  File "./silentbot.py", line 90, in invocation
    return self.star(author, permlink, star_count)
  File "./silentbot.py", line 75, in star
    comment.reply(body=body, author=self.account)
  File "/home/rob-install/.local/lib/python3.6/site-packages/beem/comment.py", line 785, in reply
  File "/home/rob-install/.local/lib/python3.6/site-packages/beem/blockchaininstance.py", line 2022, in post
    return self.finalizeOp(ops, account, "posting", **kwargs)
  File "/home/rob-install/.local/lib/python3.6/site-packages/beem/blockchaininstance.py", line 935, in finalizeOp
    self.txbuffer.appendSigner(account, permission)
  File "/home/rob-install/.local/lib/python3.6/site-packages/beem/transactionbuilder.py", line 247, in appendSigner
    raise WalletLocked()

Does beempy only allow replies using a wallet? Or amy I doing something stupid here, resulting in this exception ? Or is beempy, just like my own discontinued async python library considered deprecated, and should I use another Python library for my project?


I believe the getAccountFromPrivateKey method is for interacting with the built-in Beempy wallet . I dont believe this method will work on the public nodes. The blockchain stores the public key that matches your private posting key. You may need to write up your own function that will convert your private posting key to a public key and query the public node to obtain the user account. I haven't tested that theory so i am just spit-balling at the moment.
To overcome the exception your receiving, you will need to unlock the wallet using wallet.unlock("supersecret-passphrase") . I was recently experimenting with the unlock function. Here's the code I was using .

from beem import Hive
hive = Hive()

Does beempy command line function okay?
See UNLOCK and upvote post section.

The commandline for reply makes very little sense to me right now. There isn't a way to specify the author/permlink designation of what comment I'm replying to ? There is an AUTHORPERM, that I assume is the posting signing key for posting, but not sure why it's called AUTHORPERM, so maybe it's something else. Or is it the misnamed permalink to the post I'm responding to, and is the only way to get the signing key string in by importing it to a wallet (the exact thing I don't want to be doing) ?


I haven't used this solution but my best guess it's the author/permlink and you need to setup encrypted wallet account with passphrase first then unlock to use it.