Skip to content
Snippets Groups Projects
Commit b51f84d8 authored by Holger's avatar Holger
Browse files

Add claimaccount to beempy and some improvements for steem.sbd_symbol

parent 60b3994a
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ import sys ...@@ -11,6 +11,7 @@ import sys
from prettytable import PrettyTable from prettytable import PrettyTable
from datetime import datetime, timedelta from datetime import datetime, timedelta
import pytz import pytz
import time
import math import math
import random import random
import logging import logging
...@@ -42,6 +43,7 @@ from beemgraphenebase.account import PrivateKey, PublicKey, BrainKey ...@@ -42,6 +43,7 @@ from beemgraphenebase.account import PrivateKey, PublicKey, BrainKey
from beemgraphenebase.base58 import Base58 from beemgraphenebase.base58 import Base58
from beem.nodelist import NodeList from beem.nodelist import NodeList
from beem.conveyor import Conveyor from beem.conveyor import Conveyor
from beem.rc import RC
click.disable_unicode_literals_warning = True click.disable_unicode_literals_warning = True
...@@ -1218,6 +1220,51 @@ def disallow(foreign_account, permission, account, threshold): ...@@ -1218,6 +1220,51 @@ def disallow(foreign_account, permission, account, threshold):
print(tx) 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() @cli.command()
@click.argument('accountname', nargs=1, required=True) @click.argument('accountname', nargs=1, required=True)
@click.option('--account', '-a', help='Account that pays the fee') @click.option('--account', '-a', help='Account that pays the fee')
......
...@@ -88,13 +88,9 @@ class Comment(BlockchainObject): ...@@ -88,13 +88,9 @@ class Comment(BlockchainObject):
"total_pending_payout_value", "total_pending_payout_value",
"promoted", "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: for p in sbd_amounts:
if p in comment and isinstance(comment.get(p), (string_types, list, dict)) and symbol is not None: if p in comment and isinstance(comment.get(p), (string_types, list, dict)):
comment[p] = Amount(comment.get(p, "0.000 %s" % (symbol)), steem_instance=self.steem) comment[p] = Amount(comment.get(p, "0.000 %s" % (self.steem.sbd_symbol)), steem_instance=self.steem)
# turn json_metadata into python dict # turn json_metadata into python dict
meta_str = comment.get("json_metadata", "{}") meta_str = comment.get("json_metadata", "{}")
...@@ -280,11 +276,7 @@ class Comment(BlockchainObject): ...@@ -280,11 +276,7 @@ class Comment(BlockchainObject):
def reward(self): def reward(self):
""" Return the estimated total SBD reward. """ Return the estimated total SBD reward.
""" """
if self.steem.sbd_symbol is not None: a_zero = Amount(0, self.steem.sbd_symbol, steem_instance=self.steem)
symbol = self.steem.sbd_symbol
else:
symbol = self.steem.steem_symbol
a_zero = Amount(0, symbol, steem_instance=self.steem)
total = Amount(self.get("total_payout_value", a_zero), 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) pending = Amount(self.get("pending_payout_value", a_zero), steem_instance=self.steem)
return total + pending return total + pending
...@@ -293,11 +285,7 @@ class Comment(BlockchainObject): ...@@ -293,11 +285,7 @@ class Comment(BlockchainObject):
""" Return if the payout is pending (the post/comment """ Return if the payout is pending (the post/comment
is younger than 7 days) is younger than 7 days)
""" """
if self.steem.sbd_symbol is not None: a_zero = Amount(0, self.steem.sbd_symbol, steem_instance=self.steem)
symbol = self.steem.sbd_symbol
else:
symbol = self.steem.steem_symbol
a_zero = Amount(0, symbol, steem_instance=self.steem)
total = Amount(self.get("total_payout_value", a_zero), 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 post_age_days = self.time_elapsed().total_seconds() / 60 / 60 / 24
return post_age_days < 7.0 and float(total) == 0 return post_age_days < 7.0 and float(total) == 0
......
...@@ -1907,14 +1907,18 @@ class Steem(object): ...@@ -1907,14 +1907,18 @@ class Steem(object):
for asset in self.chain_params['chain_assets']: for asset in self.chain_params['chain_assets']:
if asset['id'] == asset_id: if asset['id'] == asset_id:
return asset['symbol'] return asset['symbol']
if asset_id < 3:
return None
raise KeyError("asset ID not found in chain assets") raise KeyError("asset ID not found in chain assets")
@property @property
def sbd_symbol(self): def sbd_symbol(self):
""" get the current chains symbol for SBD (e.g. "TBD" on testnet) """ """ 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 @property
def steem_symbol(self): def steem_symbol(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment