steem python robot manages the steem account created by beempy and keys through the JSON file
Steem uses hierarchical authorization, so a steem account has four keys: "owner", "active", "posting", "Memo"
These keys are very long. It's not realistic to remember them by human brain. They can only be stored in files and read and written by robots themselves.
Last time I demonstrated how to use beempy, now let the creation process use JSON file management.
< Beempy creates a new steem account by using the pending claimed accounts collected by RC >
Format of JSON file storage(/bots.json):
{
"nodes": [
"https://anyx.io",
"https://api.steemit.com"
],
"steems": {
"steemaccount": {
}
}
}
Demo for creating a new account to store in the JSON file with beempy(create_claimed_account_beem.py):
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# python create_claimed_account_beem.py creator account
import sys
import getopt
import time
import json
# from beem import Steem
from beem.account import Account
from beem.instance import shared_steem_instance
from beemgraphenebase.account import BrainKey, PasswordKey
try:
creator = sys.argv[1]
account = sys.argv[2]
except Exception as e:
sys.exit()
print('creator:', creator)
print('account:', account)
stm = shared_steem_instance()
# Enter the local wallet password or set value directly in the code
password = '' # 'walletkey'
if not password:
password = input('local wallet password : ')
stm.wallet.unlock(password)
accounts_file = '/bots.json'
try:
creatorA = Account(creator, steem_instance=stm)
accountA = Account(account, steem_instance=stm)
except Exception as e:
print('account can be created:', account)
bk = BrainKey()
brainkey = bk.get_brainkey()
print('brain key:', str(brainkey))
prikey = str(bk.get_private())
print('private key:', str(prikey))
pubkey = format(bk.get_public(), "STM")
print('public key:', str(pubkey))
tx = stm.create_claimed_account(
account, creator=creatorA, password=prikey, store_owner_key=True)
print('create_claimed_account:', json.dumps(tx, indent=4))
posting_key = PasswordKey(account, prikey, role="posting", prefix=stm.prefix)
active_key = PasswordKey(account, prikey, role="active", prefix=stm.prefix)
memo_key = PasswordKey(account, prikey, role="memo", prefix=stm.prefix)
owner_key = PasswordKey(account, prikey, role="owner", prefix=stm.prefix)
memo_pubkey = memo_key.get_public_key()
active_privkey = active_key.get_private_key()
posting_privkey = posting_key.get_private_key()
owner_privkey = owner_key.get_private_key()
memo_privkey = memo_key.get_private_key()
print('posting_privkey:', str(posting_privkey))
print('active_privkey:', str(active_privkey))
print('owner_privkey:', str(owner_privkey))
print('memo_privkey:', str(memo_privkey))
with open(accounts_file, 'r', encoding='utf-8') as f:
accounts_dict = json.load(f)
# print('old.accounts_dict:', accounts_dict)
accounts_dict['steems'][account] = {
"name": account, # steem 账号名称
"email": "sample@,pwd", # steem 注册 email
"mobile": "sample9,from", # steem 注册 手机号
"keys": {
"brain": brainkey, # steem 账号的脑密码
"private": prikey, # steem 账号当前的私钥
"public": pubkey, # steem 账号当前的公钥
"history": [ # steem 账号的私钥的修改记录
prikey,
"sample2",
"sample3"
],
"posting": str(posting_privkey), # steem 账号的 posting 私钥
"active": str(active_privkey), # steem 账号的 active 私钥
"owner": str(owner_privkey), # steem 账号的 owner 私钥
"memo": str(memo_privkey), # steem 账号的 memo 私钥,用于解密memo
"memo_key": str(memo_pubkey) # steem 账号的 memo 公钥,用于加密memo
}
}
with open(accounts_file, 'w', encoding='utf-8') as f:
json.dump(accounts_dict, f, indent=4, ensure_ascii=False)
Run it:python create_claimed_account_beem dappcoder newaccddd
Results consistent with expectations.
中文版本:
#steemdevs #hive-139531 #stem #programming #dev #steemstem #community #sct #whalepower #dblog #actnearn #neoxian #palnet #upfundme #zzan #jjm #lifestyle #mediaofficials #lassecash #liv #steemleo #busy #esteem #esteem-cn #marlians