From b51f84d82eb2afe7fc6cb8a3ee2f53b8f0ccf802 Mon Sep 17 00:00:00 2001 From: Holger <holger@nahrstaedt.de> Date: Mon, 8 Oct 2018 17:19:09 +0200 Subject: [PATCH] Add claimaccount to beempy and some improvements for steem.sbd_symbol --- beem/cli.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ beem/comment.py | 20 ++++---------------- beem/steem.py | 10 +++++++--- 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/beem/cli.py b/beem/cli.py index 66b29636..55abe982 100644 --- a/beem/cli.py +++ b/beem/cli.py @@ -11,6 +11,7 @@ import sys from prettytable import PrettyTable from datetime import datetime, timedelta import pytz +import time import math import random import logging @@ -42,6 +43,7 @@ from beemgraphenebase.account import PrivateKey, PublicKey, BrainKey from beemgraphenebase.base58 import Base58 from beem.nodelist import NodeList from beem.conveyor import Conveyor +from beem.rc import RC click.disable_unicode_literals_warning = True @@ -1218,6 +1220,51 @@ def disallow(foreign_account, permission, account, threshold): print(tx) +@cli.command() +@click.argument('creator', nargs=1, required=True) +@click.option('--fee', help='When fee is 0 STEEM (default) a subsidized account is claimed and can be created later with create_claimed_account', default='0 STEEM') +@click.option('--number', '-n', help='Number of subsidized accounts to be claimed (default = 1), when fee = 0 STEEM', default=1) +def claimaccount(creator, fee, number): + """Claim account for claimed account creation.""" + stm = shared_steem_instance() + if stm.rpc is not None: + stm.rpc.rpcconnect() + if not creator: + creator = stm.config["default_account"] + if not unlock_wallet(stm): + return + creator = Account(creator, steem_instance=stm) + fee = Amount(fee, steem_instance=stm) + if stm.unsigned and stm.nobroadcast and stm.steemconnect is not None: + tx = stm.claim_account(creator, fee=fee) + tx = stm.steemconnect.url_from_tx(tx) + elif float(fee) == 0: + rc = RC(steem_instance=stm) + current_costs = stm.get_rc_cost(rc.get_resource_count(tx_size=200, new_account_op_count=1)) + current_mana = creator.get_rc_manabar()["current_mana"] + last_mana = current_mana + cnt = 0 + print("Current costs %.2f G RC - current mana %.2f G RC" % (current_costs / 1e9, current_mana / 1e9)) + while current_costs + 10 < current_mana and cnt < number: + if cnt > 0: + print("Current costs %.2f G RC - current mana %.2f G RC" % (current_costs / 1e9, current_mana / 1e9)) + tx = json.dumps(tx, indent=4) + print(tx) + cnt += 1 + tx = stm.claim_account(creator, fee=fee) + 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!") + else: + tx = stm.claim_account(creator, fee=fee) + tx = json.dumps(tx, indent=4) + print(tx) + + @cli.command() @click.argument('accountname', nargs=1, required=True) @click.option('--account', '-a', help='Account that pays the fee') diff --git a/beem/comment.py b/beem/comment.py index 94122881..0bca1bd7 100644 --- a/beem/comment.py +++ b/beem/comment.py @@ -88,13 +88,9 @@ class Comment(BlockchainObject): "total_pending_payout_value", "promoted", ] - if self.steem.sbd_symbol is not None: - symbol = self.steem.sbd_symbol - else: - symbol = self.steem.steem_symbol for p in sbd_amounts: - if p in comment and isinstance(comment.get(p), (string_types, list, dict)) and symbol is not None: - comment[p] = Amount(comment.get(p, "0.000 %s" % (symbol)), steem_instance=self.steem) + if p in comment and isinstance(comment.get(p), (string_types, list, dict)): + comment[p] = Amount(comment.get(p, "0.000 %s" % (self.steem.sbd_symbol)), steem_instance=self.steem) # turn json_metadata into python dict meta_str = comment.get("json_metadata", "{}") @@ -280,11 +276,7 @@ class Comment(BlockchainObject): def reward(self): """ Return the estimated total SBD reward. """ - if self.steem.sbd_symbol is not None: - symbol = self.steem.sbd_symbol - else: - symbol = self.steem.steem_symbol - a_zero = Amount(0, symbol, steem_instance=self.steem) + a_zero = Amount(0, self.steem.sbd_symbol, steem_instance=self.steem) total = Amount(self.get("total_payout_value", a_zero), steem_instance=self.steem) pending = Amount(self.get("pending_payout_value", a_zero), steem_instance=self.steem) return total + pending @@ -293,11 +285,7 @@ class Comment(BlockchainObject): """ Return if the payout is pending (the post/comment is younger than 7 days) """ - if self.steem.sbd_symbol is not None: - symbol = self.steem.sbd_symbol - else: - symbol = self.steem.steem_symbol - a_zero = Amount(0, symbol, steem_instance=self.steem) + a_zero = Amount(0, self.steem.sbd_symbol, steem_instance=self.steem) total = Amount(self.get("total_payout_value", a_zero), steem_instance=self.steem) post_age_days = self.time_elapsed().total_seconds() / 60 / 60 / 24 return post_age_days < 7.0 and float(total) == 0 diff --git a/beem/steem.py b/beem/steem.py index 34b556a0..29319eb1 100644 --- a/beem/steem.py +++ b/beem/steem.py @@ -1907,14 +1907,18 @@ class Steem(object): for asset in self.chain_params['chain_assets']: if asset['id'] == asset_id: return asset['symbol'] - if asset_id < 3: - return None + raise KeyError("asset ID not found in chain assets") @property def sbd_symbol(self): """ get the current chains symbol for SBD (e.g. "TBD" on testnet) """ - return self._get_asset_symbol(0) + # some networks (e.g. whaleshares) do not have SBD + try: + symbol = self._get_asset_symbol(0) + except KeyError: + symbol = self._get_asset_symbol(1) + return symbol @property def steem_symbol(self): -- GitLab