Claim more accounts with beem

in Česky!4 years ago
I tried do claim and create discount account using beem library while writing the last post. And what about claiming maximum accounts you can with your RC?
ENGLISH:

If you have enough RC, you can claim more then one discount account. You can do it in peakd.com, but there you have to put the number of requested claims. And if we have a python script for that purpose, just do a little modification and we can calculate that number from your RC. We will count with 90% of your RC to spare some of RC for next interactions with blockchain.

ČESKY:

Pokud máte dost RC, můžete si claimnout více volných účtů. Tato funkce je nyní dostupná i v peakd.com, kde ale musíte zadat onen počet účtů, které chcete vytěžit. Ale pokud již máme python script pro tento účel, stačí udělat malou modifikaci a počet vytěžitelných účtů si spočítáme z RC. A počítat budeme pouze s 90%, aby nám případně zbylo dost na interakce s bockchainem.

Následující text pouze anglicky. Myslím, že tomu porozumí i neangličtináři ;) Kdyby přeci byl problém, tak se ptejte v komentáři.

For next transactions was used Python version 3.7.1 and beem version 0.23.3.

Claim maximum discount accounts from RC, leave 10% RC remain

The first one will ask for your private active key, from which will determine your account name. Then will check the RC and actual claim account costs. If you have enough RC for claim at least one account, we calculate how many accounts should be claimed for the max. 90% of your RC. Then the accounts are claimed.

from beem import Steem
from beem.nodelist import NodeList
from beem.account import Account
from beem.rc import RC
import getpass
import time
nodelist = NodeList()
nodelist.update_nodes()
nodes = nodelist.get_nodes(hive=True)
hive = Steem(node=nodes)
print(hive)

if __name__ == "__main__":
    wif = getpass.getpass(prompt='Enter your active key:')
    stm = Steem(node="https://api.pharesim.me", keys=[wif])
    creator = stm.wallet.getAccountFromPrivateKey(wif)
    creator = Account(creator)
    rc = RC(steem_instance=stm)
    current_costs = stm.get_rc_cost(rc.get_resource_count(tx_size=250, new_account_op_count=1, execution_time_count = 1))
    current_mana = creator.get_rc_manabar()["current_mana"]
    last_mana = current_mana
    print("Current costs %.2f G RC / Current mana %.2f G RC" % (current_costs / 1e9, current_mana / 1e9))
    
    free_mana = int(current_mana / 100 * 90)
    accounts_available = free_mana // current_costs

    print("Free mana (9/10) %.2f G RC / %i accounts possible to claim / %.2f G RC remaining" % 
        (free_mana / 1e9, accounts_available, (current_mana - (current_costs * accounts_available))/ 1e9 ))

    # if current_costs + 10 < current_mana:
    if accounts_available >= 1:
      
      for i in range(accounts_available):   
        stm.claim_account(creator)
        time.sleep(10)
        creator.refresh()
        current_mana = creator.get_rc_manabar()["current_mana"]
        print("Account claimed and %.2f G RC paid." % ((last_mana - current_mana) / 1e9))
        last_mana = current_mana
        
    else:
        print("Not enough RC for a claim!")

The script done. It writes some info for you in console:

py_claim_more.png

And the result visible on hive blocks:

blocks_claimed_more.png

If you have free votes, you can vote for me as Hive witness. If you want, of course ;)

Thank you for stopping by.
Thank you for your votes.