Developing Steem Files : Journal Entry for 2018 03(March) 09

in #steemdev6 years ago

March 9th, 2018

In this developer's journal of Steem Files:

  • Steem vs. Beem
  • Multi-signature in Steem
  • Command Line interfaces in Python3
  • Account Management using Beem
  • Keybox Program's commands

developing.png

Steem vs. Beem

As you might have read in my previous journal entry. Someone who I will remember to mention here, @holger80, pointed out to me there is an alternative interface to public RPC nodes for Python. And it is ready to work with Appbase apparently. After my little hack of Steem-Python, I found that the unit tests wouldn't work when I set the library to use a 19.4 node. So, I probably should move to beem. It's a real bitch porting over something as big as Steem files, though!

Multi-signature in Steem

Not only does Steem have four distinct public/private key pairs for various functions but you an account can be setup to allow posting, voting, spending and even password changes from other accounts. You can set things up so that an account requires a co-signer before moving funds. This is all requires a rather powerful computer right now, so I implemented a skeleton of a program that allows you to list what accounts can post and vote on your behalf, spend on your behalf, and change your master password on your behalf.

The Command Line Interface

Okay. It's not 1980. Why show a command line interface (CLI)? Well, the truth is, CLIs are functional and still work today and they are easy to implement. We can start with a CLI, and then later upgrade the code to use a graphical user interface.

So, you might be tempted to design your CLI like this

while True:
    print(f"@{user}>", end="")
    sys.stdout.flush()
    line = sys.stdin.readline()
    if len(line):
        line = line[0:-1]
    if line == 'quit':
        break
    command = line.split(' ')
    if command[0] == 'command1':
        # do stuff
    elif command[0] == 'command2':
        # do stuff
    # do stuff
    

When you have while loops in Python, you can reimplement it as a for loop by creating a generator:

def line_generator():
    while True:
        print(f"@{user}>", end="")
        sys.stdout.flush()
        line = sys.stdin.readline()
        if len(line):
            line = line[0:-1]
        command = line.split(' ')
        yield command

Now the loop becomes:

for command in line_generator():
    if command[0] == 'quit':
        break
    elif command[0] == 'command1':
        # do stuff
    elif command[0] == 'command2':
        # do stuff
    # do stuff

We want this because we separate the concern of handling lines and converting them into a form to process from handling the commands themselves.

Account management with Beem

I discovered a gotcha in Beem. If you initialize a Steem object with more than one key. The transactions will be signed with all of the keys! So, even if you are posting something and you have an active key included in a dictionary, it will sign with the posting key and the active key! This was worked around by creating a Steem object on every command. Hopefully, the devs fix that problem.

To make matters worse, there seems to be no way to get all of the guts of account information with beem. I want to know, what keys are needed or accounts are given the four roles: owner, active, posting, and memo.

Testing

First, i created a user elf for experiments on the testnet.
/usr/bin/curl --data "username=elf&password=secretpassword" https://testnet.steem.vc/create

Developing using this account and leaving the account name and the password hard coded as I debugged the thing helped keep me from getting frustrated.

Tomorrow I will go into detail on how it works under the hood. Today, I will give examples.

Keybox Program's commands or How to use Keybox

Create your account on the testnet as illustrated above and run the following commands:

You will need to type in the username and password.
Then run python3 keybox.py

ls

This will list the keys you have and who else has the owner, active, posting roles. It turns out that the memo role can only have one key and no other accounts may have that role but it is included for completeness in the list.

---------------------------
owner
Threshold: 1
        key: STX5kJnwhzphuAdpQLLSgcu5rvA6smznNmQEydSTSTURvHfXhVnbo, weight: 1
        account:leprechaun weight: 1
        account:steemfiles weight: 1
---------------------------
active
Threshold: 1
        key: STX87vxdvcxVNAVyhLVKcRzvX6f9y1XnWJV2a8NwbUtcdndzQCtKa, weight: 1
        account:leprechaun weight: 1
        account:steemfiles weight: 1
---------------------------
posting
Threshold: 1
        key: STX5LhRERMbjJviw3hxaLuMSEgpgn7uYDTWBvDEyJNfXdQcFLF6qX, weight: 1
---------------------------
memo
Threshold: 1
        key: STX6SZXWqS3z1jS4wfeFHehauC5hSsrfWmyTeSwyCoLpa83h2Txdc, weight: 1

allow leprechaun to own

This gives leprechaun the ability to modify to change the master password and lock you out of your account. It's testnet, so give it try you only have quadrillions in fake money to lose.

allow leprechaun to post

This gives leprechaun the ability to modify to post or vote according to this new user.

allow leprechaun to activate

This gives leprechaun the ability to move money in your account but its testnet.

disallow leprechaun from owning

This removes the permission of leprechaun to modify all your passwords or add authorities to any of the accounts.

disallow leprechaun from activating

This removes the permission of leprechaun to spend money in this account

disallow leprechaun from posting

This removes the permission of leprechaun to post or vote for this new account.

Previous Journal Entries:

Dash XjzjT4mr4f7T3E8G9jQQzozTgA2J1ehMkV
LTC LLXj1ZPQPaBA1LFtoU1Gkvu5ZrxYzeLGKt
BitcoinCash 1KVqnW7wZwn2cWbrXmSxsrzqYVC5Wj836u
Bitcoin 1Q1WX5gVPKxJKoQXF6pNNZmstWLR87ityw (too expensive to use for tips)

See also

See my other recent article:


Sort:  

just wow post it is

Where can I find keybox.py?

I will post about keybox again today with detail on how I call beem and a link to keybox.py.

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.027
BTC 61129.70
ETH 2660.38
USDT 1.00
SBD 2.55