def check_config(config, necessary_fields, stm): config_cnt = 0 token_config = {} token_list = Tokens() for conf in config: config_cnt += 1 # check if all fields are set all_fields_ok = True for field in necessary_fields: if field not in conf: logger.warn("Error in %d. config: %s missing" % (config_cnt, field)) all_fields_ok = False if not all_fields_ok: continue # Check if scot_account exists (exception will be raised when not) Account(conf["scot_account"], steem_instance=stm) # Check if scot_token exists if token_list.get_token(conf["scot_token"]) is None: logger.warn("Token %s does not exists" % conf["scot_token"]) continue scot_wallet = Wallet(conf["scot_account"], steem_instance=stm) scot_token = scot_wallet.get_token(conf["scot_token"]) logger.info("%s has %s token" % (conf["scot_account"], str(scot_token))) token_config[conf["scot_token"]] = conf if len(token_config) == 0: raise Exception("Broken config, shutdown bot...") logger.info("%d configs were found." % len(token_config)) return token_config
def sell(self, account, amount, symbol, price): """Sell token for given price. :param str account: account name :param float amount: Amount to withdraw :param str symbol: symbol :param float price: price Sell example: .. code-block:: python from steemengine.market import Market from beem import Steem active_wif = "5xxxx" stm = Steem(keys=[active_wif]) market = Market(steem_instance=stm) market.sell("test", 1, "ENG", 0.95) """ wallet = Wallet(account, api=self.api, steem_instance=self.steem) token_in_wallet = wallet.get_token(symbol) if token_in_wallet is None: raise TokenNotInWallet("%s is not in wallet." % symbol) if float(token_in_wallet["balance"]) < float(amount): raise InsufficientTokenAmount("Only %.3f in wallet" % float(token_in_wallet["balance"])) token = Token(symbol, api=self.api) quant_amount = token.quantize(amount) if quant_amount <= decimal.Decimal("0"): raise InvalidTokenAmount("Amount to transfer is below token precision of %d" % token["precision"]) contract_payload = {"symbol": symbol.upper(), "quantity":str(quant_amount), "price": str(price)} json_data = {"contractName":"market","contractAction":"sell", "contractPayload":contract_payload} tx = self.steem.custom_json(self.ssc_id, json_data, required_auths=[account]) return tx
def withdraw(self, account, amount): """Widthdraw STEEMP to account as STEEM. :param str account: account name :param float amount: Amount to withdraw Withdraw example: .. code-block:: python from steemengine.market import Market from beem import Steem active_wif = "5xxxx" stm = Steem(keys=[active_wif]) market = Market(steem_instance=stm) market.withdraw("test", 1) """ wallet = Wallet(account, api=self.api, steem_instance=self.steem) token_in_wallet = wallet.get_token("STEEMP") if token_in_wallet is None: raise TokenNotInWallet("%s is not in wallet." % "STEEMP") if float(token_in_wallet["balance"]) < float(amount): raise InsufficientTokenAmount("Only %.3f in wallet" % float(token_in_wallet["balance"])) token = Token("STEEMP", api=self.api) quant_amount = token.quantize(amount) if quant_amount <= decimal.Decimal("0"): raise InvalidTokenAmount("Amount to transfer is below token precision of %d" % token["precision"]) contract_payload = {"quantity":str(quant_amount)} json_data = {"contractName":"steempegged","contractAction":"withdraw", "contractPayload":contract_payload} tx = self.steem.custom_json(self.ssc_id, json_data, required_auths=[account]) return tx
def __init__(self, config, steemd_instance): self.config = config self.stm = steemd_instance self.daily_inflation = self.config["yearly_inflation"] / 365 if not self.config["no_broadcast"]: self.stm.wallet.unlock(self.config["wallet_password"]) self.scot_token = Token(self.config["scot_token"]) self.token_wallet = Wallet(self.config["scot_account"], steem_instance=self.stm)
def scot(player, steem_balance, sbd_balance): token = ["STEEM", "SBD"] scot_balance = [steem_balance, sbd_balance] if player != "": wallet = Wallet(player) scot = wallet.get_balances() for i in scot: if float(i["balance"]) > 0: token.append(i["symbol"]) scot_balance.append(i["balance"]) print(token) print(scot_balance) return token, scot_balance
def cancel_unstake(amount, trx_id): """unstake a token""" 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 wallet = Wallet(account, steem_instance=stm) tx = wallet.cancel_unstake(trx_id) tx = json.dumps(tx, indent=4) print(tx)
def issue(to, amount, token, account): """Issue a token""" 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 wallet = Wallet(account, steem_instance=stm) tx = wallet.issue(to, amount, token) tx = json.dumps(tx, indent=4) print(tx)
def transfer(to, amount, token, memo, account): """Transfer a token""" stm = shared_steem_instance() if stm.rpc is not None: stm.rpc.rpcconnect() if not account: account = stm.config["default_account"] if not bool(memo): memo = '' if not unlock_wallet(stm): return wallet = Wallet(account, steem_instance=stm) tx = wallet.transfer(to, amount, token, memo) tx = json.dumps(tx, indent=4) print(tx)
class SteemTransfer: def __init__(self, account): self.account = SteemAccount(account) self.transfers = None self.se_wallet = Wallet(self.account.author) def get_token_transfers(self, token, offset=0, limit=100): if self.transfers is None: url = URL.format(account=self.account.author, symbol=token, offset=offset, limit=limit) try: r = requests.get(url) if r.ok: self.transfers = r.json() else: logger.error("Failed when retrieving transfer info") except: logger.error( "Failed when retrieving transfer info. Error: {}".format( traceback.format_exc())) return self.transfers def transfer(self, to, token, amount, memo="", retries=5): if retries <= 0: logger.info("Transfer failed after maximum retires") return if to and token and amount and memo is not None: token = token.upper() try: if token in ["STEEM", "SBD"]: self.account.account.transfer(to, amount, token, memo) else: self.se_wallet.transfer(to, amount, token, memo=memo) logger.info("Transferred {} {} to {} with memo [{}]".format( amount, token, to, memo)) except: logger.error( "Failed when tranferring {} {} to {} with memo [{}].\nError: {}" .format(amount, token, to, memo, traceback.format_exc())) self.transfer(to, token, amount, memo, retries - 1)
from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import sys from datetime import datetime, timedelta import time import io import logging from beem import Steem from steemengine.wallet import Wallet from beembase import transactions, operations log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) if __name__ == "__main__": stm = Steem() stm.wallet.unlock(pwd="wallet_pass") wallet = Wallet("beembot", steem_instance=stm) dragon_token = wallet.get_token("DRAGON") if dragon_token is not None and float(dragon_token["balance"]) >= 0.01: print("balance %.2f" % float(dragon_token["balance"])) print(wallet.transfer("holger80", 0.01, "DRAGON", "test")) else: print("Could not sent") time.sleep(15) wallet.refresh() dragon_token = wallet.get_token("DRAGON") print("new balance %.2f" % float(dragon_token["balance"]))
from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import time from beem import Steem from beem.nodelist import NodeList from steemengine.api import Api from steemengine.wallet import Wallet if __name__ == "__main__": nodelist = NodeList() nodelist.update_nodes() stm = Steem(node=nodelist.get_nodes()) api = Api() wallet = Wallet("ufm.pay") # edit here upvote_account = "ufm.pay" upvote_token = "KITTENS" token_weight_factor = 1 # multiply token amount to get weight kitten_ratio = 20 stm = Steem() stm.wallet.unlock(pwd="") wallet = Wallet(upvote_account, steem_instance=stm) stamps = [] whitelist = [] blacklist = ["market", "tokens"] last_steem_block = 1950 # It is a good idea to store this block, otherwise all transfers will be checked again while True: main_token = wallet.get_token("CATS")
def __init__(self, account): self.account = SteemAccount(account) self.transfers = None self.se_wallet = Wallet(self.account.author)
def run(self, start_block): self.stm.wallet.unlock(self.config["wallet_password"]) self.blockchain = Blockchain(mode='head', steem_instance=self.stm) stop_block = self.blockchain.get_current_block_num() if start_block is not None: last_block_num = start_block - 1 self.log_data["start_block_num"] = start_block for op in self.blockchain.stream(start=start_block, stop=stop_block, opNames=["comment"], max_batch_size=50): self.log_data = print_block_log(self.log_data, op, self.config["print_log_at_block"]) last_block_num = op["block_num"] if op["type"] == "comment": token = None for key in self.token_config: if op["body"].find( self.token_config[key]["comment_command"]) >= 0: token = key if token is None: continue if op["author"] == self.token_config[token]["token_account"]: continue try: c_comment = Comment(op, steem_instance=self.stm) c_comment.refresh() except: logger.warn("Could not read %s/%s" % (op["author"], op["permlink"])) continue if c_comment.is_main_post(): continue if abs((c_comment["created"] - op['timestamp']).total_seconds()) > 9.0: logger.warn("Skip %s, as edited" % c_comment["authorperm"]) continue already_replied = False for r in c_comment.get_all_replies(): if r["author"] == self.token_config[token][ "token_account"]: already_replied = True if already_replied: continue muting_acc = Account(self.token_config[token]["token_account"], steem_instance=self.stm) blocked_accounts = muting_acc.get_mutings() if c_comment["author"] in blocked_accounts: logger.info("%s is blocked" % c_comment["author"]) continue # Load bot token balance bot_wallet = Wallet(self.token_config[token]["token_account"], steem_instance=self.stm) symbol = bot_wallet.get_token( self.token_config[token]["symbol"]) # parse amount when user_can_specify_amount is true amount = self.token_config[token]["default_amount"] if self.token_config[token]["user_can_specify_amount"]: start_index = c_comment["body"].find( self.token_config[token]["comment_command"]) stop_index = c_comment["body"][start_index:].find("\n") if stop_index >= 0: command = c_comment["body"][start_index + 1:start_index + stop_index] else: command = c_comment["body"][start_index + 1:] command_args = command.replace(' ', ' ').split(" ")[1:] if len(command_args) > 0: try: amount = float(command_args[0]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.info("Could not parse amount") if self.token_config[token][ "maximum_amount_per_comment"] and amount > self.token_config[ token]["maximum_amount_per_comment"]: amount = self.token_config[token][ "maximum_amount_per_comment"] if not self.config["no_broadcast"] and self.stm.wallet.locked( ): self.stm.wallet.unlock(self.config["wallet_password"]) self.log_data["new_commands"] += 1 wallet = Wallet(c_comment["author"], steem_instance=self.stm) token_in_wallet = wallet.get_token( self.token_config[token]["symbol"]) if token_in_wallet is not None: balance = float(token_in_wallet["balance"]) if "stake" in token_in_wallet: balance += float(token_in_wallet['stake']) if 'delegationsIn' in token_in_wallet and float( token_in_wallet['delegationsIn']) > 0: balance += float(token_in_wallet['delegationsIn']) if 'pendingUnstake' in token_in_wallet and float( token_in_wallet['pendingUnstake']) > 0: balance += float(token_in_wallet['pendingUnstake']) if balance > self.token_config[token][ "min_token_in_wallet"]: if self.token_config[token][ "token_in_wallet_for_each_outgoing_token"] > 0: max_token_to_give = int( balance / self.token_config[token] ["token_in_wallet_for_each_outgoing_token"]) else: max_token_to_give = self.token_config[token][ "maximum_amount_per_comment"] else: max_token_to_give = 0 else: max_token_to_give = 0 db_data = read_data(self.data_file) if "accounts" in db_data and c_comment["author"] in db_data[ "accounts"] and token in db_data["accounts"][ c_comment["author"]]: if db_data["accounts"][c_comment["author"]][token][ "last_date"] == date.today( ) and self.token_config[token][ "token_in_wallet_for_each_outgoing_token"] > 0: max_token_to_give = max_token_to_give - db_data[ "accounts"][c_comment["author"]][token]["amount"] if amount > max_token_to_give: amount = max_token_to_give if amount > self.token_config[token][ "maximum_amount_per_comment"]: amount = self.token_config[token][ "maximum_amount_per_comment"] if token_in_wallet is None or float( token_in_wallet["balance"] ) < self.token_config[token]["min_token_in_wallet"]: reply_body = self.token_config[token]["fail_reply_body"] elif max_token_to_give < 1: reply_body = self.token_config[token][ "no_token_left_for_today"] elif c_comment["parent_author"] == c_comment["author"]: reply_body = "You cannot sent token to yourself." elif float(symbol["balance"]) < amount: reply_body = self.token_config[token]["no_token_left_body"] else: if "{}" in self.token_config[token]["sucess_reply_body"]: reply_body = (self.token_config[token] ["sucess_reply_body"]).format( c_comment["parent_author"]) else: reply_body = self.token_config[token][ "sucess_reply_body"] if "{}" in self.token_config[token]["token_memo"]: token_memo = ( self.token_config[token]["token_memo"]).format( c_comment["author"]) else: token_memo = self.token_config[token]["token_memo"] sendwallet = Wallet( self.token_config[token]["token_account"], steem_instance=self.stm) try: logger.info( "Sending %.2f %s to %s" % (amount, self.token_config[token]["symbol"], c_comment["parent_author"])) sendwallet.transfer(c_comment["parent_author"], amount, self.token_config[token]["symbol"], token_memo) if "accounts" in db_data: accounts = db_data["accounts"] else: accounts = {} if c_comment["author"] not in accounts: accounts[c_comment["author"]] = {} accounts[c_comment["author"]][token] = { "last_date": date.today(), "n_comments": 1, "amount": amount } elif token not in accounts[c_comment["author"]]: accounts[c_comment["author"]][token] = { "last_date": date.today(), "n_comments": 1, "amount": amount } else: if accounts[c_comment["author"]][token][ "last_date"] < date.today(): accounts[c_comment["author"]][token] = { "last_date": date.today(), "n_comments": 1, "amount": amount } else: accounts[c_comment["author"]][token][ "n_comments"] += 1 accounts[c_comment["author"]][token][ "amount"] += amount store_data(self.data_file, "accounts", accounts) logger.info( "%s - %s" % (c_comment["author"], str(accounts[c_comment["author"]][token]))) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn( "%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not send %s token" % self.token_config[token]["symbol"]) continue reply_identifier = construct_authorperm( c_comment["parent_author"], c_comment["parent_permlink"]) if self.config["no_broadcast"]: logger.info("%s" % reply_body) else: try: self.stm.post( "", reply_body, author=self.token_config[token]["token_account"], reply_identifier=reply_identifier) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn( "%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not reply to post") continue if self.token_config[token]["usage_upvote_percentage"] > 0: try: c_comment.upvote(self.token_config[token] ["usage_upvote_percentage"], voter=self.token_config[token] ["token_account"]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not upvote comment") time.sleep(4) return last_block_num
nodelist.update_nodes() stm = Steem(node=nodelist.get_nodes()) # edit here upvote_account = "beembot" upvote_token = "DRAGON" token_weight_factor = 100 # multiply token amount to get weight min_token_amount = 0.01 max_post_age_days = 3 whitelist = [] # When empty, the whitelist is disabled blacklist_tags = [] # When empty, the tag blacklist is disabled reply_comment = "" # When empty, no reply comment is created only_main_posts = True stm.wallet.unlock("wallet-passwd") wallet = Wallet(upvote_account, steem_instance=stm) last_steem_block = 1950 # It is a good idea to store this block, otherwise all transfers will be checked again while True: history = wallet.get_history(upvote_token) for h in history: if int(h["block"]) <= last_steem_block: continue if h["to"] != upvote_account: continue last_steem_block = int(h["block"]) if len(whitelist) > 0 and h["from"] not in whitelist: print("%s is not in the whitelist, skipping" % h["from"]) continue if float(h["quantity"]) < min_token_amount: print("Below min token amount skipping...")
def run(self, start_block): self.stm.wallet.unlock(self.config["wallet_password"]) self.blockchain = Blockchain(mode='head', steem_instance=self.stm) stop_block = self.blockchain.get_current_block_num() if start_block is not None: last_block_num = start_block - 1 self.log_data["start_block_num"] = start_block for op in self.blockchain.stream(start=start_block, stop=stop_block, opNames=["comment"], max_batch_size=50): self.log_data = print_block_log(self.log_data, op, self.config["print_log_at_block"]) last_block_num = op["block_num"] if op["type"] == "comment": token = None for key in self.token_config: if op["body"].find(self.token_config[key]["comment_command"]) >= 0: token = key if token is None: continue if op["author"] == self.token_config[token]["scot_account"]: continue try: c_comment = Comment(op, steem_instance=self.stm) c_comment.refresh() except: logger.warn("Could not read %s/%s" % (op["author"], op["permlink"])) continue if c_comment.is_main_post(): continue if abs((c_comment["created"] - op['timestamp']).total_seconds()) > 9.0: logger.warn("Skip %s, as edited" % c_comment["authorperm"]) continue already_replied = False for r in c_comment.get_all_replies(): if r["author"] == self.token_config[token]["scot_account"]: already_replied = True if already_replied: continue # Load scot token balance scot_wallet = Wallet(self.token_config[token]["scot_account"], steem_instance=self.stm) scot_token = scot_wallet.get_token(self.token_config[token]["scot_token"]) # parse amount when user_can_specify_amount is true amount = self.token_config[token]["maximum_amount"] if self.token_config[token]["user_can_specify_amount"]: start_index = c_comment["body"].find(self.token_config[token]["comment_command"]) stop_index = c_comment["body"][start_index:].find("\n") if stop_index >= 0: command = c_comment["body"][start_index + 1:start_index + stop_index] else: command = c_comment["body"][start_index + 1:] command_args = command.replace(' ', ' ').split(" ")[1:] if len(command_args) > 0: try: amount = float(command_args[0]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.info("Could not parse amount") if not self.config["no_broadcast"] and self.stm.wallet.locked(): self.stm.wallet.unlock(self.config["wallet_password"]) self.log_data["new_commands"] += 1 wallet = Wallet(c_comment["author"], steem_instance=self.stm) token_in_wallet = wallet.get_token(self.token_config[token]["scot_token"]) if token_in_wallet is None or float(token_in_wallet["balance"]) < self.token_config[token]["min_staked_token"]: reply_body = self.token_config[token]["fail_reply_body"] elif c_comment["parent_author"] == c_comment["author"]: reply_body = "You cannot sent token to yourself." elif float(scot_token["balance"]) < amount: reply_body = self.token_config[token]["no_token_left_body"] else: if "%s" in self.token_config[token]["sucess_reply_body"]: reply_body = self.token_config[token]["sucess_reply_body"] % c_comment["parent_author"] else: reply_body = self.token_config[token]["sucess_reply_body"] if "%s" in self.token_config[token]["token_memo"]: token_memo = self.token_config[token]["token_memo"] % c_comment["author"] else: token_memo = self.token_config[token]["token_memo"] sendwallet = Wallet(self.token_config[token]["scot_account"], steem_instance=self.stm) try: logger.info("Sending %.2f %s to %s" % (amount, self.token_config[token]["scot_token"], c_comment["parent_author"])) sendwallet.transfer(c_comment["parent_author"], amount, self.token_config[token]["scot_token"], token_memo) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not send %s token" % self.token_config[token]["scot_token"]) continue reply_identifier = construct_authorperm(c_comment["parent_author"], c_comment["parent_permlink"]) if self.config["no_broadcast"]: logger.info("%s" % reply_body) else: try: self.stm.post("", reply_body, author=self.token_config[token]["scot_account"], reply_identifier=reply_identifier) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not reply to post") continue if self.token_config[token]["usage_upvote_percentage"] > 0: try: c_comment.upvote(self.token_config[token]["usage_upvote_percentage"], voter=self.token_config[token]["scot_account"]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not upvote comment") time.sleep(4) return last_block_num
def info(objects): """ Show basic blockchain info General information about steem-engine, a block, an account, a token, and a transaction id """ stm = None api = Api() if not objects: latest_block = api.get_latest_block_info() tokens = Tokens() t = PrettyTable(["Key", "Value"]) t.align = "l" t.add_row(["latest block number", latest_block["blockNumber"]]) t.add_row(["latest steem block", latest_block["refSteemBlockNumber"]]) t.add_row(["latest timestamp", latest_block["timestamp"]]) t.add_row(["Number of created tokens", len(tokens)]) print(t.get_string()) for obj in objects: if re.match("^[0-9-]*$", obj): block_info = api.get_block_info(int(obj)) print("Block info: %d" % (int(obj))) trx_nr = 0 for trx in block_info["transactions"]: trx_nr += 1 t = PrettyTable(["Key", "Value"]) t.align = "l" t.add_row(["trx_nr", str(trx_nr)]) t.add_row(["action", trx["action"]]) t.add_row(["contract", trx["contract"]]) t.add_row( ["logs", json.dumps(json.loads(trx["logs"]), indent=4)]) t.add_row([ "payload", json.dumps(json.loads(trx["payload"]), indent=4) ]) t.add_row(["refSteemBlockNumber", trx["refSteemBlockNumber"]]) t.add_row(["timestamp", block_info["timestamp"]]) t.add_row(["sender", trx["sender"]]) t.add_row(["transactionId", trx["transactionId"]]) print(t.get_string()) elif re.match("^[A-Z0-9\-\._]{1,16}$", obj): print("Token: %s" % obj) tokens = Tokens() token = tokens.get_token(obj) if token is None: print("Could not found token %s" % obj) return t = PrettyTable(["Key", "Value"]) t.align = "l" metadata = json.loads(token["metadata"]) for key in token: if key == "metadata": if "url" in metadata: t.add_row(["metadata_url", metadata["url"]]) if "icon" in metadata: t.add_row(["metadata_icon", metadata["icon"]]) if "desc" in metadata: t.add_row(["metadata_desc", metadata["desc"]]) else: t.add_row([key, token[key]]) market_info = token.get_market_info() if market_info is not None: for key in market_info: if key in ["$loki", "symbol"]: continue t.add_row([key, market_info[key]]) print(t.get_string()) elif re.match("^[a-zA-Z0-9\-\._]{2,16}$", obj): print("Token Wallet: %s" % obj) if stm is None: nodelist = NodeList() nodelist.update_nodes() stm = Steem(node=nodelist.get_nodes()) wallet = Wallet(obj, steem_instance=stm) t = PrettyTable( ["id", "symbol", "balance", "stake", "pendingUnstake"]) t.align = "l" for token in wallet: if "stake" in token: stake = token["stake"] else: stake = "-" if "pendingUnstake" in token: pendingUnstake = token["pendingUnstake"] else: pendingUnstake = "-" t.add_row([ token["$loki"], token["symbol"], token["balance"], stake, pendingUnstake ]) print(t.get_string(sortby="id")) elif len(obj) == 40: print("Transaction Id: %s" % obj) trx = api.get_transaction_info(obj) if trx is None: print("trx_id: %s is not a valid steem-engine trx_id!" % obj) return payload = json.loads(trx["payload"]) logs = json.loads(trx["logs"]) t = PrettyTable(["Key", "Value"]) t.align = "l" t.add_row(["blockNumber", str(trx["blockNumber"])]) t.add_row(["action", trx["action"]]) t.add_row(["contract", trx["contract"]]) t.add_row(["logs", json.dumps(logs, indent=4)]) t.add_row(["payload", json.dumps(payload, indent=4)]) t.add_row(["refSteemBlockNumber", trx["refSteemBlockNumber"]]) t.add_row(["sender", trx["sender"]]) t.add_row(["transactionId", trx["transactionId"]]) print(t.get_string())
from dhooks import Webhook import math from beem.nodelist import NodeList import json import six import requests import getpass beem_pass = "" # Password to unlock beem wallet api = Api() tokens = Tokens() token = Token("TMPS") stm = Steem() market = Market(steem_instance=stm) wallet = Wallet("tmps", steem_instance=stm) wallet2 = Wallet("market", steem_instance=stm) stm.wallet.unlock(pwd=beem_pass) blacklist = ["market", "tokens", "null", "tmps"] dragon_token = wallet.get_token("TMPS") wallet.refresh() upvote_account = "ufm.pay" adjusted_dragon = float(dragon_token["balance"]) * 0.95 balances = token.get_holder() info = token.get_info() max_post_age_days = 6 min_post_age = 5 whitelist = [] blacklist_tags = [] only_main_posts = True sell_tokens = ["SPORTS", "NEOXAG", "PHOTO", "PAL"]
class Scot: def __init__(self, config, steemd_instance): self.config = config self.stm = steemd_instance self.daily_inflation = self.config["yearly_inflation"] / 365 if not self.config["no_broadcast"]: self.stm.wallet.unlock(self.config["wallet_password"]) self.scot_token = Token(self.config["scot_token"]) self.token_wallet = Wallet(self.config["scot_account"], steem_instance=self.stm) def get_token_holder(self): offset = 0 get_holder = self.scot_token.get_holder() offset += 1000 new_holder = self.scot_token.get_holder(offset=offset) while len(new_holder) > 0: get_holder.append(new_holder) offset += 1000 new_holder = self.scot_token.get_holder(offset=offset) token_per_100_vote = {} token_sum = 0 for item in get_holder: if item["account"] == self.config["scot_account"]: continue token_sum += float(item["balance"]) for item in get_holder: if item["account"] == self.config["scot_account"]: continue token_sum += float(item["balance"]) if float(item["balance"]) > 0: token_per_100_vote[item["account"]] = (float( item["balance"]) / token_sum) * self.daily_inflation / 10 return token_per_100_vote def get_token_to_sent(self, start_block, stop_block, token_per_100_vote): token_to_authors = {} b = Blockchain(steem_instance=self.stm) for op in b.stream(start=start_block, stop=stop_block, opNames=["vote"], max_batch_size=50): if op["voter"] not in token_per_100_vote: continue if not self.config["downvotes"] and op["weight"] < 0: continue if not self.config["upvotes"] and op["weight"] > 0: continue comment = Comment(op, steem_instance=self.stm) try: comment.refresh() except: print("Could not fetch %s" % comment["authorperm"]) continue json_metadata = comment["json_metadata"] app = None SETokensSupported = None if isinstance(json_metadata, str): json_metadata = json.loads(json_metadata) if "app" in json_metadata: app = json_metadata["app"] if isinstance(app, dict) and "name" in app: app = app["name"] elif isinstance(app, dict): app = "" if "SETokensSupported" in json_metadata: SETokensSupported = json_metadata["SETokensSupported"] app_or_symbol = False if app is not None and len( self.config["included_apps"] ) > 0 and app != "" and app in self.config["included_apps"]: app_or_symbol = True elif self.config["include_token_as_tag"] and self.scot_token[ "symbol"] in comment["tags"]: app_or_symbol = True elif SETokensSupported is not None and len( SETokensSupported ) > 0 and self.scot_token["symbol"] in SETokensSupported: app_or_symbol = True if not app_or_symbol and not self.config["include_all_posts"]: continue token_amount = abs( op["weight"]) / 10000 * token_per_100_vote[op["voter"]] if op["weight"] < 0: if op["voter"] not in token_to_authors: token_to_authors[op["voter"]] = token_amount else: token_to_authors[op["voter"]] += token_amount else: if op["author"] not in token_to_authors: token_to_authors[op["author"]] = token_amount else: token_to_authors[op["author"]] += token_amount return token_to_authors def get_token_transfer_last_24_h(self): yesterday = date.today() - timedelta(days=1) yesterday_0_0_0 = datetime(yesterday.year, yesterday.month, yesterday.day) yesterday_23_59_59 = datetime(yesterday.year, yesterday.month, yesterday.day, 23, 59, 59) token_sent_last_24_h = 0 for hist in self.token_wallet.get_history(self.scot_token["symbol"]): timestamp = datetime.strptime(hist["timestamp"], timeFormatZ) if timestamp <= yesterday_23_59_59: continue print(hist) if hist["from"] != self.config["scot_account"]: continue token_sent_last_24_h = float(hist["quantity"]) return token_sent_last_24_h def count_token(self, token_to_authors): token_amount_to_sent = 0 for author in token_to_authors: token_amount_to_sent += token_to_authors[author] return token_amount_to_sent def adapt_to_precision(self, token_to_authors): token_amount_to_sent = self.count_token(token_to_authors) for author in token_to_authors: token_to_authors[author] = token_to_authors[ author] * self.daily_inflation / token_amount_to_sent token_to_authors[author] = math.floor( token_to_authors[author] * 10**self.scot_token["precision"] ) / 10**self.scot_token["precision"] return token_to_authors def send_token(self, token_to_authors): for author in token_to_authors: if token_to_authors[author] < 10**(-self.scot_token["precision"]): continue if self.config["no_broadcast"]: logger.info("Sending %f %s to %s" % (token_to_authors[author], self.scot_token["symbol"], author)) else: self.token_wallet.transfer(author, token_to_authors[author], self.scot_token["symbol"], memo=self.config["token_memo"]) time.sleep(4) def run(self): b = Blockchain(steem_instance=self.stm) yesterday = date.today() - timedelta(days=1) yesterday_0_0_0 = datetime(yesterday.year, yesterday.month, yesterday.day) yesterday_23_59_59 = datetime(yesterday.year, yesterday.month, yesterday.day, 23, 59, 59) start_block = b.get_estimated_block_num(addTzInfo(yesterday_0_0_0)) stop_block = b.get_estimated_block_num(addTzInfo(yesterday_23_59_59)) logger.info("Check token transfer from %s..." % self.config["scot_account"]) token_sent_last_24_h = self.get_token_transfer_last_24_h() if token_sent_last_24_h > 0: logger.warning("Token were already sent today...") return logger.info("No token transfer were found, continue...") token_per_100_vote = self.get_token_holder() logger.info("%d token holder were found." % len(token_per_100_vote)) token_to_authors = self.get_token_to_sent(start_block, stop_block, token_per_100_vote) token_to_authors = self.adapt_to_precision(token_to_authors) token_amount_to_sent = self.count_token(token_to_authors) logger.info("Start to send %f token to %d accounts" % (token_amount_to_sent, len(token_to_authors))) self.send_token(token_to_authors)