Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def tearDownClass(cls):
stm = shared_steem_instance()
stm.config.recover_with_latest_backup()
def test_config(self):
set_shared_config({"node": self.urls})
set_shared_steem_instance(None)
o = shared_steem_instance()
self.assertIn(o.rpc.url, self.urls)
def setprofile(variable, value, account, pair):
"""Set a variable in an account\'s profile"""
stm = shared_steem_instance()
if stm.rpc is not None:
stm.rpc.rpcconnect()
keys = []
values = []
if pair:
for p in pair:
key, value = p.split("=")
keys.append(key)
values.append(value)
if variable and value:
keys.append(variable)
values.append(value)
profile = Profile(keys, values)
if not account:
def importaccount(account, roles):
"""Import an account using a passphrase"""
from beemgraphenebase.account import PasswordKey
stm = shared_steem_instance()
if stm.rpc is not None:
stm.rpc.rpcconnect()
if not unlock_wallet(stm):
return
account = Account(account, steem_instance=stm)
imported = False
password = click.prompt("Account Passphrase", confirmation_prompt=False, hide_input=True)
if not password:
print("You cannot chose an empty Passphrase")
return
if "owner" in roles:
owner_key = PasswordKey(account["name"], password, role="owner")
owner_pubkey = format(owner_key.get_public_key(), stm.prefix)
if owner_pubkey in [x[0] for x in account["owner"]["key_auths"]]:
print("Importing owner key!")
owner_privkey = owner_key.get_private_key()
def config():
""" Shows local configuration
"""
stm = shared_steem_instance()
t = PrettyTable(["Key", "Value"])
t.align = "l"
for key in stm.config:
# hide internal config data
if key in availableConfigurationKeys and key != "nodes" and key != "node":
t.add_row([key, stm.config[key]])
node = stm.get_default_nodes()
nodes = json.dumps(node, indent=4)
t.add_row(["nodes", nodes])
if "password_storage" not in availableConfigurationKeys:
t.add_row(["password_storage", stm.config["password_storage"]])
t.add_row(["data_dir", stm.config.data_dir])
print(t)
def delegate(amount, to_account, account):
"""Delegate (start delegate VESTS to another account)
amount is in VESTS / Steem
"""
stm = shared_steem_instance()
if stm.rpc is not None:
stm.rpc.rpcconnect()
if not account:
account = stm.config["default_account"]
if not unlock_wallet(stm):
return
acc = Account(account, steem_instance=stm)
try:
amount = float(amount)
except:
amount = Amount(str(amount), steem_instance=stm)
if amount.symbol == stm.steem_symbol:
amount = stm.sp_to_vests(float(amount))
tx = acc.delegate_vesting_shares(to_account, amount)
if stm.unsigned and stm.nobroadcast and stm.steemconnect is not None:
def buy(amount, asset, price, account, orderid):
"""Buy STEEM or SBD from the internal market
Limit buy price denoted in (SBD per STEEM)
"""
stm = shared_steem_instance()
if stm.rpc is not None:
stm.rpc.rpcconnect()
if account is None:
account = stm.config["default_account"]
if asset == stm.sbd_symbol:
market = Market(base=Asset(stm.steem_symbol), quote=Asset(stm.sbd_symbol), steem_instance=stm)
else:
market = Market(base=Asset(stm.sbd_symbol), quote=Asset(stm.steem_symbol), steem_instance=stm)
if price is None:
orderbook = market.orderbook(limit=1, raw_data=False)
if asset == stm.steem_symbol and len(orderbook["bids"]) > 0:
p = Price(orderbook["bids"][0]["base"], orderbook["bids"][0]["quote"], steem_instance=stm).invert()
p_show = p
elif len(orderbook["asks"]) > 0:
p = Price(orderbook["asks"][0]["base"], orderbook["asks"][0]["quote"], steem_instance=stm).invert()
p_show = p
def __init__(self, steem_instance=None, *args, **kwargs):
self.steem = steem_instance or shared_steem_instance()
self.access_token = None
self.get_refresh_token = kwargs.get("get_refresh_token", False)
self.hot_sign_redirect_uri = kwargs.get("hot_sign_redirect_uri", config["hot_sign_redirect_uri"])
if self.hot_sign_redirect_uri == "":
self.hot_sign_redirect_uri = None
self.client_id = kwargs.get("client_id", config["sc2_client_id"])
self.scope = kwargs.get("scope", "login")
self.oauth_base_url = kwargs.get("oauth_base_url", config["oauth_base_url"])
self.sc2_api_url = kwargs.get("sc2_api_url", config["sc2_api_url"])
def ticker(sbd_to_steem):
""" Show ticker
"""
stm = shared_steem_instance()
if stm.rpc is not None:
stm.rpc.rpcconnect()
t = PrettyTable(["Key", "Value"])
t.align = "l"
market = Market(steem_instance=stm)
ticker = market.ticker()
for key in ticker:
if key in ["highest_bid", "latest", "lowest_ask"] and sbd_to_steem:
t.add_row([key, str(ticker[key].as_base("SBD"))])
elif key in "percent_change" and sbd_to_steem:
t.add_row([key, "%.2f %%" % -ticker[key]])
elif key in "percent_change":
t.add_row([key, "%.2f %%" % ticker[key]])
else:
t.add_row([key, str(ticker[key])])
print(t)
def convert(amount, account):
"""Convert STEEMDollars to Steem (takes a week to settle)"""
stm = shared_steem_instance()
if stm.rpc is not None:
stm.rpc.rpcconnect()
if not account:
account = stm.config["default_account"]
if not unlock_wallet(stm):
return
acc = Account(account, steem_instance=stm)
try:
amount = float(amount)
except:
amount = str(amount)
tx = acc.convert(amount)
if stm.unsigned and stm.nobroadcast and stm.steemconnect is not None:
tx = stm.steemconnect.url_from_tx(tx)
tx = json.dumps(tx, indent=4)
print(tx)