def setUpClass(cls):
        nodelist = NodeList()
        cls.bts = Steem(
            node=nodelist.get_nodes(normal=False, appbase=True, dev=True),
            nobroadcast=True,
            num_retries=10,
            use_condenser=False,
            keys={"active": wif},
        )
        # from getpass import getpass
        # self.bts.wallet.unlock(getpass())
        set_shared_steem_instance(cls.bts)
        cls.bts.set_default_account("test")

        b = Blockchain(steem_instance=cls.bts)
        num = b.get_current_block_num()
        cls.start = num - 25
        cls.stop = num
        cls.max_batch_size = 1  # appbase does not support batch rpc calls at the momement (internal error)
Exemple #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("config", help="Config file in JSON format")
    parser.add_argument("--logconfig",
                        help="Logger Config file in JSON format",
                        default='logger.json')
    parser.add_argument("--datadir", help="Data storage dir", default='.')
    args = parser.parse_args()

    setup_logging(default_path=args.logconfig)

    logger.info("Loading config: %s" % str(args.config))
    config = json.loads(open(args.config).read())
    datadir = args.datadir

    nodelist = NodeList()
    nodelist.update_nodes()
    stm = Steem(node=nodelist.get_nodes(),
                num_retries=5,
                call_num_retries=3,
                timeout=15)

    logger.info(str(stm))
    data_file = os.path.join(datadir, 'data.db')
    bot = Distribubot(config, data_file, stm)

    data_file = os.path.join(datadir, 'data.db')
    data_db = read_data(data_file)
    if "last_block_num" in data_db:
        last_block_num = data_db["last_block_num"]
    else:
        last_block_num = 0
    if "comment_queue" in data_db:
        comment_queue = data_db["comment_queue"]
    else:
        comment_queue = {}

    if "last_block_num" in data_db:
        start_block = data_db["last_block_num"] + 1
        print("Start block_num: %d" % start_block)
        stop_block = start_block + 1200
    else:
        start_block = None
        stop_block = None
    logger.info("starting token distributor..")
    block_counter = None
    while True:

        last_block_num = bot.run(start_block, stop_block)
        # Update nodes once a day
        if block_counter is None:
            block_counter = last_block_num
        elif last_block_num - block_counter > 20 * 60 * 24:
            nodelist.update_nodes()
            stm = Steem(node=nodelist.get_nodes(),
                        num_retries=5,
                        call_num_retries=3,
                        timeout=15)

            bot.stm = stm

        start_block = last_block_num + 1
        store_data(data_file, "last_block_num", last_block_num)
        time.sleep(3)
Exemple #3
0
 def test_get_nodes(self):
     nodelist = NodeList()
     all_nodes = nodelist.get_nodes(normal=True, appbase=True, dev=True, testnet=True, testnetdev=True)
     self.assertEqual(len(nodelist) - 11, len(all_nodes))
     https_nodes = nodelist.get_nodes(wss=False)
     self.assertEqual(https_nodes[0][:5], 'https')
Exemple #4
0
           formatTimeString(last_paid_comment)))

    if (datetime.utcnow() - last_cycle).total_seconds() > 60 * share_cycle_min:

        new_cycle = (datetime.utcnow() -
                     last_cycle).total_seconds() > 60 * share_cycle_min
        current_cycle = last_cycle + timedelta(seconds=60 * share_cycle_min)

        print("Update member database, new cycle: %s" % str(new_cycle))
        # memberStorage.wipe(True)
        member_accounts = memberStorage.get_all_accounts()

        #print(key_list)
        nodes = NodeList()
        nodes.update_nodes()
        stm = Steem(node=nodes.get_nodes())

        member_data = {}
        n_records = 0
        share_age_member = {}
        for m in member_accounts:
            member_data[m] = Member(memberStorage.get(m))

        if True:
            print("reward voted steembasicincome post and comments")
            # account = Account("steembasicincome", steem_instance=stm)

            if last_paid_post is None:
                last_paid_post = datetime(2018, 8, 9, 3, 36, 48)
            new_paid_post = last_paid_post
            if last_paid_comment is None:
    nodes = NodeList()
    # nodes.update_nodes(weights={"block": 1})
    try:
        nodes.update_nodes()
    except:
        print("could not update nodes")

    keys = []
    for acc in accounts:
        keys.append(keyStorage.get(acc, "posting"))
    keys_list = []
    for k in keys:
        if k["key_type"] == 'posting':
            keys_list.append(k["wif"].replace("\n", '').replace('\r', ''))
    node_list = nodes.get_nodes(normal=normal,
                                appbase=appbase,
                                wss=wss,
                                https=https)
    stm = Steem(node=node_list,
                keys=keys_list,
                num_retries=5,
                call_num_retries=3,
                timeout=15,
                nobroadcast=nobroadcast)

    voter_accounts = {}
    for acc in accounts:
        voter_accounts[acc] = Account(acc, steem_instance=stm)

    b = Blockchain(steem_instance=stm)
    # print("reading all authorperm")
    already_voted_posts = []
Exemple #6
0
        
        memo_transfer_acc = accountStorage.get_transfer_memo_sender()
        if len(memo_transfer_acc) > 0:
            memo_transfer_acc = memo_transfer_acc[0]
        key = keyStorage.get(memo_transfer_acc, "active")
        if key is not None and key["key_type"] == 'active':
            keys_list.append(key["wif"].replace("\n", '').replace('\r', ''))         
        
        transferMemos = {}
        for db_entry in transferMemosStorage.get_all_data():
            transferMemos[db_entry["memo_type"]] = {"enabled": db_entry["enabled"], "memo": db_entry["memo"]}
        
        #print(key_list)
        nodes = NodeList()
        nodes.update_nodes()
        stm = Steem(keys=keys_list, node=nodes.get_nodes(hive=hive_blockchain))
        
        if memo_transfer_acc is not None:
            try:
                memo_transfer_acc = Account(memo_transfer_acc, steem_instance=stm)
            except:
                print("%s is not a valid steem account! Will be able to send transfer memos..." % memo_transfer_acc)
        
        member_data = {}
        n_records = 0
        share_age_member = {}    
        for m in member_accounts:
            member_data[m] = Member(memberStorage.get(m))

        mngt_shares_assigned = False
        mngt_shares = 0
        if lockStorage.is_locked("build_ua_lock"):
            print("stop set_trusted_account")
            exit()

        print("top100_lock %s" % str(lockStorage.is_locked("top100_lock")))
        if lockStorage.is_locked("top100_lock"):
            print("stop set_trusted_account")
            exit()
        print("read_lock %s" % str(lockStorage.is_locked("read_lock")))
        if lockStorage.is_locked("read_lock"):
            print("stop set_trusted_account")
            exit()
    nodes = NodeList()
    nodes.update_nodes()
    node_list = nodes.get_nodes(appbase=True,
                                normal=False,
                                https=True,
                                wss=True)
    stm = Steem(node=node_list)

    cnt = 0
    continue_cnt = 1

    db_data = []
    db_account = []
    db_follows = []
    accounts = account2TrxStorage.get_accounts()

    d = 0.85

    UA_old = {}
    UA = {}
Exemple #8
0
    voteLogTrx = VoteLogTrx(db)
    failedVoteLogTrx = FailedVoteLogTrx(db)
    accountsTrx = AccountsDB(db)
    broadcastVoteTrx = BroadcastVoteTrx(db)

    conf_setup = confStorage.get()
    # last_post_block = conf_setup["last_post_block"]

    nodes = NodeList()
    # nodes.update_nodes(weights={"block": 1})
    try:
        nodes.update_nodes()
    except:
        print("could not update nodes")
    
    node_list = nodes.get_nodes(exclude_limited=False)
    stm = Steem(node=node_list, num_retries=5, call_num_retries=3, timeout=15, nobroadcast=nobroadcast) 
    stm.wallet.unlock(wallet_password)
    print("Use node %s" % str(stm))
    last_voter = None
    for vote in broadcastVoteTrx.get_all_expired():
        if last_voter is not None and last_voter == vote["voter"]:
            print("Skip %s for this round" % vote["voter"])
            continue        
        voter_acc = Account(vote["voter"], steem_instance=stm)
        if voter_acc.get_rc_manabar()["current_mana"] / 1e9 < 0.1:
            print("%s has not sufficient RC" % vote["voter"])
            last_voter = vote["voter"]
            continue
        
        if vote["retry_count"] >= 5:
Exemple #9
0
    def __init__(self):
        super(QMainWindow, self).__init__()
        # Set up the user interface from Designer.
        self.setupUi(self)

        self.setAccessibleName("Hive Desktop")
        self.redrawLock = Lock()
        self.updateLock = Lock()

        self.optionsDialog = dialogs.Options(self)
        self.aboutDialog = dialogs.About(
            self,
            copyright='holger80',
            programName='Hive Desktop',
            version=VERSION,
            website='https://github.com/holgern/hivedesktop',
            websiteLabel='Github',
            comments=
            '"Welcome to Hive desktop!\n This is the first release for testing qt5.\n Please vote for holger80 as witness, if you like this :).',
            licenseName='GPL-3.0',
            # licenseUrl=helpers.joinpath_to_cwd('LICENSE').as_uri(),
            authors=('holger80', ),
            # dependencies=[l.strip() for l in requirements.readlines()],
        )
        self.mdrenderer = MDRenderer(str(helpers.joinpath_to_cwd('themes')))

        # tmpfile = helpers.mktemp(prefix='hivedesktop', suffix='.html')

        self.post = {"body": "##test", "authorperm": "@test/test"}
        self.thread = threads.MDThread(self)

        # self.webview.url = tmpfile.as_uri()

        self.feedListWidget.currentRowChanged.connect(
            self.change_displayed_post, Qt.QueuedConnection)

        self.timer = QTimer()
        self.timer.timeout.connect(self.refresh_account_thread)

        self.timer2 = QTimer()
        self.timer2.timeout.connect(self.update_account_hist_thread)

        self.timer3 = QTimer()
        self.timer3.timeout.connect(self.update_account_feed_thread)

        self.cache_path = QStandardPaths.writableLocation(
            QStandardPaths.CacheLocation)
        self.db_type = "shelve"
        self.feed = []
        self.post = None
        # Get settings
        settings = QSettings()
        # Get checkbox state with speciying type of checkbox:
        # type=bool is a replacement of toBool() in PyQt5
        check_state = settings.value(SETTINGS_TRAY, True, type=bool)
        hist_info_check_state = settings.value(SETTINGS_HIST_INFO,
                                               True,
                                               type=bool)
        account_state = settings.value(SETTINGS_ACCOUNT, "", type=str)
        # Set state
        self.accountHistNotificationCheckBox.setChecked(hist_info_check_state)
        self.autoRefreshCheckBox.setChecked(check_state)
        if check_state:
            self.timer.start(5000)
            self.timer2.start(15000)
            self.timer3.start(60000)
        self.accountLineEdit.setText(account_state)
        # connect the slot to the signal by clicking the checkbox to save the state settings
        self.autoRefreshCheckBox.clicked.connect(self.save_check_box_settings)
        self.accountHistNotificationCheckBox.clicked.connect(
            self.save_check_box_settings)
        self.accountLineEdit.editingFinished.connect(
            self.save_account_settings)
        self.actionAbout.triggered.connect(self.about)
        self.actionOptions.triggered.connect(self.options)
        self.threadpool = QThreadPool()

        self.minimizeAction = QAction("Mi&nimize", self, triggered=self.hide)
        self.maximizeAction = QAction("Ma&ximize",
                                      self,
                                      triggered=self.showMaximized)
        self.restoreAction = QAction("&Restore",
                                     self,
                                     triggered=self.showNormal)

        menu = QMenu()
        menu.addAction(self.minimizeAction)
        menu.addAction(self.maximizeAction)
        menu.addAction(self.restoreAction)
        menu.addSeparator()
        # aboutAction = menu.addAction("about")
        # aboutAction.triggered.connect(self.about)
        exitAction = menu.addAction("Exit")
        exitAction.triggered.connect(self.closeApp)

        self.tray = QSystemTrayIcon(QIcon(':/icons/icon.ico'))

        self.tray.setContextMenu(menu)

        self.tray.setToolTip("Hive Desktop!")
        self.tray.setObjectName("Hive Desktop")
        self.setWindowTitle("Hive Desktop")
        self.tray.show()

        splash_pix = QPixmap(':/icons/splash.png')
        splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
        splash.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
        splash.setEnabled(False)

        splash.show()
        splash.showMessage("<h1><font color='green'>starting...</font></h1>",
                           Qt.AlignTop | Qt.AlignCenter, Qt.black)

        account = account_state
        nodelist = NodeList()
        nodelist.update_nodes()
        self.stm = Steem(node=nodelist.get_nodes(hive=True))
        if account != "":
            try:
                self.hist_account = Account(account, steem_instance=self.stm)
            except:
                self.hist_account = None
        else:
            self.hist_account = None
        if self.hasFocus is not None:
            self.init_new_account()
        # self.button.clicked.connect(lambda: self.text.setText(_get_quote(self.hist_account, self.stm)))
        self.refreshPushButton.clicked.connect(self.refresh_account_thread)
        self.refreshPushButton.clicked.connect(self.update_account_hist_thread)
        self.accountLineEdit.editingFinished.connect(self.update_account_info)
        splash.deleteLater()
        self.tray.showMessage("Ready", "Account history loaded!")
Exemple #10
0
    voteLogTrx = VoteLogTrx(db)
    failedVoteLogTrx = FailedVoteLogTrx(db)
    accountsTrx = AccountsDB(db)
    broadcastVoteTrx = BroadcastVoteTrx(db)

    conf_setup = confStorage.get()
    # last_post_block = conf_setup["last_post_block"]

    nodes = NodeList()
    # nodes.update_nodes(weights={"block": 1})
    try:
        nodes.update_nodes()
    except:
        print("could not update nodes")

    node_list = nodes.get_nodes(exclude_limited=False)
    stm = Steem(node=node_list,
                num_retries=5,
                call_num_retries=3,
                timeout=15,
                nobroadcast=nobroadcast)
    stm.wallet.unlock(wallet_password)

    last_voter = None

    print("Start apply new vp based votes")
    vote_count = 0
    delete_pending_votes = []

    rc_sp_to_low_account_list = []
import logging

from beem.blockchain import Blockchain
from beem.block import Block
from beem.steem import Steem
from beem.utils import parse_time, formatTimedelta
from beem.nodelist import NodeList
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

if __name__ == "__main__":
    node_setup = 1
    how_many_hours = 1
    nodes = NodeList()
    if node_setup == 0:
        stm = Steem(node=nodes.get_nodes(normal=True, wss=True),
                    num_retries=10)
        max_batch_size = None
        threading = False
        thread_num = 8
    elif node_setup == 1:
        stm = Steem(node=nodes.get_nodes(normal=True, wss=True),
                    num_retries=10)
        max_batch_size = None
        threading = True
        thread_num = 16
    elif node_setup == 2:
        stm = Steem(node=nodes.get_nodes(appbase=False, https=False),
                    num_retries=10)
        max_batch_size = None
        threading = True
    print("latest member enrollment %s" % str(latest_enrollment))

    updated_member_data = []

    db = dataset.connect(databaseConnector)
    curationOptimTrx = CurationOptimizationTrx(db)
    curationOptimTrx.delete_old_posts(days=7)
    # Update current node list from @fullnodeupdate
    nodes = NodeList()
    # nodes.update_nodes(weights={"hist": 1})
    try:
        nodes.update_nodes()
    except:
        print("could not update nodes")

    node_list = nodes.get_nodes()
    if "https://api.steemit.com" in node_list:
        node_list.remove("https://api.steemit.com")
    stm = Steem(node=node_list, num_retries=3, timeout=10)
    # print(str(stm))
    set_shared_steem_instance(stm)

    accountTrx = {}
    accountTrx = MemberHistDB(db)

    b = Blockchain(steem_instance=stm)
    current_block = b.get_current_block()
    stop_time = latest_enrollment
    stop_time = current_block["timestamp"]
    start_time = stop_time - timedelta(seconds=30 * 24 * 60 * 60)
Exemple #13
0
from beem.nodelist import NodeList
from beem.steem    import Steem
from beem.instance import set_shared_steem_instance
from datetime      import datetime, timedelta
from operator      import itemgetter

# Welcome message
print("Start of the run on:", time.asctime(time.localtime(time.time())))

# Getting the active key of the apying account
wif = getpass.getpass(prompt='Please enter your active key: ')

# Initialization of the Steem instance
n = NodeList()
n.update_nodes()
stm = Steem(node=n.get_nodes(),keys=[wif])
set_shared_steem_instance(stm)

# Get the paying account
paying_account  = stm.wallet.getAccountFromPrivateKey(wif)
if not paying_account:
    print('  --> Cannot get the paying account from the wif. Exiting.')
    print("End of the run on:", time.asctime(time.localtime(time.time())))
    sys.exit()
else:
    print('  --> The paying account is ' + str(paying_account))
paying_account  = Account(paying_account)


# Get the delgated account
account_name = input('Please enter the account from which delegations must be tracked: ')
Exemple #14
0
    def run(self, start_block, stop_block):
        self.stm.wallet.unlock(self.config["wallet_password"])
        self.blockchain = Blockchain(mode='head', steem_instance=self.stm)
        current_block = self.blockchain.get_current_block_num()
        if stop_block is None or stop_block > current_block:
            stop_block = current_block

        if start_block is None:
            start_block = current_block
            last_block_num = current_block - 1
        else:
            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
                cnt = 0
                c_comment = None
                while c_comment is None and cnt < 5:
                    cnt += 1
                    try:
                        c_comment = Comment(op, steem_instance=self.stm)
                        c_comment.refresh()
                    except:
                        nodelist = NodeList()
                        nodelist.update_nodes()
                        self.stm = Steem(node=nodelist.get_nodes(),
                                         num_retries=5,
                                         call_num_retries=3,
                                         timeout=15)
                        time.sleep(1)
                if cnt == 5:
                    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_voted = False
                for v in c_comment["active_votes"]:
                    if self.token_config[token]["token_account"] == v["voter"]:
                        already_voted = True
                if already_voted:
                    continue

                already_replied = None
                cnt = 0
                while already_replied is None and cnt < 5:
                    cnt += 1
                    try:
                        already_replied = False
                        for r in c_comment.get_all_replies():
                            if r["author"] == self.token_config[token][
                                    "token_account"]:
                                already_replied = True
                    except:
                        already_replied = None
                        self.stm.rpc.next()
                if already_replied is None:
                    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"])
                balance = 0
                if token_in_wallet is not None:
                    logger.info(token_in_wallet)
                    if self.token_config[token]["count_only_staked_token"]:
                        balance = 0
                    else:
                        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
                logger.info("token to give for %s: %f" %
                            (c_comment["author"], max_token_to_give))

                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 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)
                        if self.token_config[token][
                                "usage_upvote_percentage"] <= 0:
                            time.sleep(5)
                            self.stm.post(
                                "",
                                "Command accepted!",
                                author=self.token_config[token]
                                ["token_account"],
                                reply_identifier=c_comment["authorperm"])
                    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:
                        time.sleep(5)
                        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
    for result in table.find():
        if result is not None:
            shipstats[result["name"]] = result

    parameter["shipstats"] = shipstats

    connection.executable.close()

    last_transaction_id = 0
    date = None
    earliest_trigger_date = None

    nodes = NodeList()
    node_update_count = 0
    nodes.update_nodes()
    stm = Steem(node=nodes.get_nodes(exclude_limited=False))
    print(nodes.get_nodes(exclude_limited=False))
    b = Blockchain(mode="head",
                   max_block_wait_repetition=27,
                   steem_instance=stm)
    print("Start streaming - %s" % str(stm))
    last_vops_block_num = None
    last_vops_timestamp = None
    last_vops_count_check = None
    while True:
        #try:
        if True:
            node_update_count += 1
            connection = connectdb()
            if node_update_count > 5000:
        sys.stdout.write("\r%s" % op['block_num'])
        opcount += 1
    now = time.time()
    total_duration = now - start_time
    print(" votes: %d, time %.2f" % (opcount, total_duration))
    return opcount, total_duration


if __name__ == "__main__":
    node_setup = 1
    threading = True
    thread_num = 8
    timeout = 10
    nodes = NodeList()
    nodes.update_nodes(weights={"block": 1})
    node_list_wss = nodes.get_nodes(https=False)[:5]
    node_list_https = nodes.get_nodes(wss=False)[:5]

    vote_result = []
    duration = []
    stm_wss = Steem(node=node_list_wss, timeout=timeout)
    stm_https = Steem(node=node_list_https, timeout=timeout)
    print("Without threading wss")
    opcount_wot_wss, total_duration_wot_wss = stream_votes(stm_wss, False, 8)
    print("Without threading https")
    opcount_wot_https, total_duration_wot_https = stream_votes(stm_https, False, 8)
    if threading:
        print("\n Threading with %d threads is activated now." % thread_num)

    stm = Steem(node=node_list_wss, timeout=timeout)
    opcount_wss, total_duration_wss = stream_votes(stm, threading, thread_num)
Exemple #17
0
        wss = True
        https = True
        normal = True
        appbase = True

    nodes = NodeList()
    # nodes.update_nodes(weights={"block": 1})
    try:
        nodes.update_nodes()
    except:
        print("could not update nodes")

    tokenizer = RegexpTokenizer(r'\w+')

    node_list = nodes.get_nodes(normal=normal,
                                appbase=appbase,
                                wss=wss,
                                https=https)

    stm = Steem(node=node_list,
                num_retries=5,
                call_num_retries=3,
                timeout=15,
                nobroadcast=nobroadcast)
    print("user node %s" % str(stm))
    b = Blockchain(mode="head", steem_instance=stm)
    print("deleting old posts and votes")
    postTrx.delete_old_posts(6)
    voteTrx.delete_old_votes(8)
    broadcastVoteTrx.delete_old_votes(7)
    pendingVotesTrx.delete_old_votes(7)
    print("Parsing new blocks")
Exemple #18
0
 def test_get_nodes(self):
     nodelist = NodeList()
     all_nodes = nodelist.get_nodes(exclude_limited=False, dev=True, testnet=True, testnetdev=True)
     self.assertEqual(len(nodelist) - 13, len(all_nodes))
     https_nodes = nodelist.get_nodes(wss=False)
     self.assertEqual(https_nodes[0][:5], 'https')
    voteLogTrx = VoteLogTrx(db)
    failedVoteLogTrx = FailedVoteLogTrx(db)
    accountsTrx = AccountsDB(db)
    broadcastVoteTrx = BroadcastVoteTrx(db)

    conf_setup = confStorage.get()
    # last_post_block = conf_setup["last_post_block"]

    nodes = NodeList()
    # nodes.update_nodes(weights={"block": 1})
    try:
        nodes.update_nodes()
    except:
        print("could not update nodes")
    
    node_list = nodes.get_nodes(exclude_limited=False)
    stm = Steem(node=node_list, num_retries=5, call_num_retries=3, timeout=15, nobroadcast=nobroadcast) 
    stm.wallet.unlock(wallet_password)
    
    last_voter = None

    print("Start apply new timebased votes")
    voter_counter = 0
    delete_pending_votes = []
    rc_sp_to_low_account_list = []
    vote_counter = 0
    vote_count = 0
    for pending_vote in pendingVotesTrx.get_command_list_timed():
        settings = None
        voter_acc = None
        author, permlink = resolve_authorperm(pending_vote["authorperm"])
Exemple #20
0
 def setUpClass(cls):
     nodelist = NodeList()
     cls.bts = Steem(node=nodelist.get_nodes(exclude_limited=False),
                     nobroadcast=True,
                     num_retries=10)
     set_shared_steem_instance(cls.bts)
     confStorage.update({"last_cycle": last_cycle})
 elif True: # doing same maintanence
     data = trxStorage.get_all_data()
     data = sorted(data, key=lambda x: (datetime.utcnow() - x["timestamp"]).total_seconds(), reverse=True)
     # data = sorted(data, key=lambda x: (datetime.utcnow() - x["timestamp"]).total_seconds(), reverse=True)
     key_list = []
     key = keyStorage.get("steembasicincome", "memo")
     if key is not None:
         key_list.append(key["wif"])
     #print(key_list)
     nodes = NodeList()
     try:
         nodes.update_nodes()
     except:
         print("could not update nodes")        
     stm = Steem(keys=key_list, node=nodes.get_nodes())        
     if True: # check if member are blacklisted
         member_accounts = memberStorage.get_all_accounts()
         member_data = {}
         n_records = 0
         share_age_member = {}    
         for m in member_accounts:
             member_data[m] = Member(memberStorage.get(m))
         cnt = 0
         member_data_list = []
         for m in member_data:
             cnt += 1
             if cnt % 100 == 0:
                 print("%d/%d" % (cnt, len(member_data)))
                 if len(member_data_list) > 0:
                     memberStorage.add_batch(member_data_list)
Exemple #22
0
    return {'successful': successful, 'node': node, 'error': error_msg,
            'total_duration': timer() - start_total, 'block_count': block_count,
            'history_count': history_count, 'access_time': access_time, 'follow_time': follow_time,
            'version': blockchain_version}


if __name__ == "__main__":
    how_many_seconds = 30
    how_many_minutes = 10
    threading = True
    set_default_nodes = False
    quit_thread = False
    benchmark_time = timer()

    nodelist = NodeList()
    nodes = nodelist.get_nodes(normal=True, appbase=True, dev=True)
    t = PrettyTable(["node", "N blocks", "N acc hist", "dur. call in s"])
    t.align = "l"
    t2 = PrettyTable(["node", "version"])
    t2.align = "l"
    working_nodes = []
    results = []
    if threading and FUTURES_MODULE:
        pool = ThreadPoolExecutor(max_workers=len(nodes) + 1)
        futures = []
        for node in nodes:
            futures.append(pool.submit(benchmark_node, node, how_many_minutes, how_many_seconds))
        try:
            results = [r.result() for r in as_completed(futures)]
        except KeyboardInterrupt:
            quit_thread = True
    nodes = NodeList()
    # nodes.update_nodes(weights={"block": 1})
    try:
        nodes.update_nodes()
    except:
        print("could not update nodes")

    keys = []
    for acc in accounts:
        keys.append(keyStorage.get(acc, "posting"))
    keys_list = []
    for k in keys:
        if k["key_type"] == 'posting':
            keys_list.append(k["wif"].replace("\n", '').replace('\r', ''))
    node_list = nodes.get_nodes(hive=hive_blockchain)

    stm = Steem(node=node_list,
                keys=keys_list,
                num_retries=5,
                call_num_retries=3,
                timeout=15,
                nobroadcast=nobroadcast)

    voter_accounts = {}
    for acc in accounts:
        voter_accounts[acc] = Account(acc, steem_instance=stm)

    b = Blockchain(steem_instance=stm)
    # print("reading all authorperm")
    already_voted_posts = []
Exemple #24
0
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")
           formatTimeString(last_paid_comment)))

    if (datetime.utcnow() - last_cycle).total_seconds() > 60 * share_cycle_min:

        new_cycle = (datetime.utcnow() -
                     last_cycle).total_seconds() > 60 * share_cycle_min
        current_cycle = last_cycle + timedelta(seconds=60 * share_cycle_min)

        print("Update member database, new cycle: %s" % str(new_cycle))
        # memberStorage.wipe(True)
        member_accounts = memberStorage.get_all_accounts()

        #print(key_list)
        nodes = NodeList()
        nodes.update_nodes()
        stm = Steem(node=nodes.get_nodes(hive=hive_blockchain))
        stm2 = Steem(node=nodes.get_nodes(hive=hive_blockchain),
                     use_condenser=True)

        member_data = {}
        n_records = 0
        share_age_member = {}
        for m in member_accounts:
            member_data[m] = Member(memberStorage.get(m))

        if True:
            print("reward voted steembasicincome post and comments")
            # account = Account("steembasicincome", steem_instance=stm)

            if last_paid_post is None:
                last_paid_post = datetime(2018, 8, 9, 3, 36, 48)
    else:
        max_batch_size = None
        threading = False
        wss = True
        https = True
        normal = True
        appbase = True        

    nodes = NodeList()
    # nodes.update_nodes(weights={"block": 1})
    try:
        nodes.update_nodes()
    except:
        print("could not update nodes")
    
    node_list = nodes.get_nodes(normal=normal, appbase=appbase, wss=wss, https=https)
    if "https://steemd.minnowsupportproject.org" in node_list:
        node_list.remove("https://steemd.minnowsupportproject.org")    
    stm = Steem(node=node_list, num_retries=5, call_num_retries=3, timeout=15, nobroadcast=nobroadcast) 
    
    pendingVotesTrx.delete_old_votes(6.4)
    
    for post in postTrx.get_posts_list(last_processed_timestamp):
        authorperm = post["authorperm"]
        author = post["author"]
        main_post = post["main_post"]
        last_processed_timestamp = post["created"]
        rules = voteRulesTrx.get_rules(author, main_post)
        if len(rules) == 0:
            continue
        fitting_rules = []
Exemple #27
0
 def tearDownClass(cls):
     nodelist = NodeList()
     stm = Steem(node=nodelist.get_nodes())
     stm.config.recover_with_latest_backup()
Exemple #28
0
from beemgraphenebase.account import PasswordKey, PrivateKey, PublicKey
from beem.steem import Steem
from beem.utils import parse_time, formatTimedelta
from beemapi.exceptions import NumRetriesReached
from beem.nodelist import NodeList
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

password = "******"
username = "******"
useWallet = False

if __name__ == "__main__":
    nodelist = NodeList()
    stm = Steem(
        node=nodelist.get_nodes(normal=False, appbase=False, testnet=True))
    prefix = stm.prefix
    # curl --data "username=username&password=secretPassword" https://testnet.steem.vc/create
    stm.wallet.wipe(True)
    if useWallet:
        stm.wallet.create("123")
        stm.wallet.unlock("123")
    active_key = PasswordKey(username, password, role="active", prefix=prefix)
    owner_key = PasswordKey(username, password, role="owner", prefix=prefix)
    posting_key = PasswordKey(username,
                              password,
                              role="posting",
                              prefix=prefix)
    memo_key = PasswordKey(username, password, role="memo", prefix=prefix)
    active_pubkey = active_key.get_public_key()
    owner_pubkey = owner_key.get_public_key()
Exemple #29
0
 def test_nodes_update(self):
     nodelist = NodeList()
     all_nodes = nodelist.get_nodes(normal=True, appbase=True, dev=True, testnet=True)
     nodelist.update_nodes(steem_instance=self.bts)
     nodes = nodelist.get_nodes()
     self.assertIn(nodes[0], all_nodes)
from beem.nodelist import NodeList
from mongostorage import MongoStorage

BATCH_SIZE = 100

if len(sys.argv) != 4:
    print("ERROR: Command line argument count mismatch")
    print("Usage: %s [year] [month] [day]" % (sys.argv[0]))
    exit(-1)

year = int(sys.argv[1])
month = int(sys.argv[2])
day = int(sys.argv[3])

nl = NodeList()
s = Steem(node=nl.get_nodes(appbase=True, normal=False))
b = Blockchain(steem_instance=s)

start_date = datetime(year, month, day)
end_date = start_date + timedelta(days=1)
start_block = b.get_estimated_block_num(start_date)
end_block = b.get_estimated_block_num(end_date) - 1

m = MongoStorage(db_name="steem",
                 host='172.18.0.3',
                 port=27017,
                 user='',
                 passwd='')
m.ensure_indexes()

for block in b.blocks(start=start_block,