Exemple #1
0
    def test_nodes_update(self):
        nodelist = NodeList()
        all_nodes = nodelist.get_hive_nodes()
        nodelist.update_nodes(blockchain_instance=self.bts)
        nodes = nodelist.get_hive_nodes()
        self.assertIn(nodes[0], all_nodes)

        all_nodes = nodelist.get_steem_nodes()
        nodelist.update_nodes(blockchain_instance=self.bts)
        nodes = nodelist.get_steem_nodes()
        self.assertIn(nodes[0], all_nodes)
    def test_default_connection(self):
        nodelist = NodeList()
        nodelist.update_nodes(steem_instance=Hive(node=nodelist.get_hive_nodes(), num_retries=10))

        b2 = Hive(
            node=nodelist.get_hive_nodes(),
            nobroadcast=True,
        )
        set_shared_steem_instance(b2)
        bts = Account("beem")
        self.assertEqual(bts.blockchain.prefix, "STM")
Exemple #3
0
    def test_stm1stm2(self):
        nodelist = NodeList()
        nodelist.update_nodes(steem_instance=Hive(
            node=nodelist.get_hive_nodes(), num_retries=10))
        b1 = Steem(node="https://api.steemit.com",
                   nobroadcast=True,
                   num_retries=10)
        node_list = nodelist.get_hive_nodes()

        b2 = Hive(node=node_list, nobroadcast=True, num_retries=10)

        self.assertNotEqual(b1.rpc.url, b2.rpc.url)
Exemple #4
0
 def test_hive_nodes(self):
     nodelist = NodeList()
     nodelist.update_nodes()
     hive_nodes = nodelist.get_hive_nodes()
     for node in hive_nodes:
         blockchainobject = Hive(node=node)
         assert blockchainobject.is_hive
Exemple #5
0
def getHiveNodes():
    """ Return a list of hive node URLS """
    from beem.nodelist import NodeList
    nodelist = NodeList()
    nodelist.update_nodes()
    nodes = nodelist.get_hive_nodes()
    return nodes
Exemple #6
0
 def setUpClass(cls):
     nodelist = NodeList()
     cls.bts = Hive(
         node=nodelist.get_hive_nodes(),
         nobroadcast=True,
         num_retries=10
     )
     set_shared_blockchain_instance(cls.bts)
Exemple #7
0
 def setUpClass(cls):
     nodelist = NodeList()
     nodelist.update_nodes(steem_instance=Hive(node=nodelist.get_hive_nodes(), num_retries=10))
     cls.bts = Hive(
         node=nodelist.get_nodes(exclude_limited=True),
         nobroadcast=True,
         keys=[wif],
         num_retries=10
     )
     set_shared_steem_instance(cls.bts)
Exemple #8
0
    def setUpClass(cls):
        nodelist = NodeList()
        nodelist.update_nodes(steem_instance=Steem(node=nodelist.get_hive_nodes(), num_retries=10))
        cls.bts = Steem(
            node=nodelist.get_hive_nodes(),
            nobroadcast=True,
            timeout=30,
            num_retries=30,
        )
        # 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()
        # num = 23346630
        cls.start = num - 25
        cls.stop = num
Exemple #9
0
def main():
    load_config()
    load_users()

    nodelist = NodeList()
    nodelist.update_nodes()
    nodes = nodelist.get_hive_nodes()
    hive = Hive(wif=config['wif'])
    set_shared_hive_instance(hive)

    do_airdrop(hive)
Exemple #10
0
    def start(self, authorperm=None, file=None):
        self.main_window = Tk()
        self.main_window.title('HiveDiff')
        self.__main_window_ui = MainWindowUI(self.main_window)
        
        self.leftFile = ''
        self.rightFile = ''
        self.authorperm = ''

        self.__main_window_ui.center_window()
        self.__main_window_ui.create_file_path_labels()
        self.__main_window_ui.create_text_areas()
        self.__main_window_ui.create_search_text_entry(self.__findNext)
        self.__main_window_ui.create_line_numbers()
        self.__main_window_ui.create_scroll_bars()
        self.__main_window_ui.create_file_treeview()
        path_to_my_project = os.getcwd()
        self.__main_window_ui.add_menu('File', [
            {'name': 'Compare Markdown file', 'command': self.__browse_files},
            {'name': 'View Post history', 'command': self.__enter_post},
            {'name': 'Compare Markdown files in Directory', 'command': self.__browse_directories},
            {'name': 'Reload', 'command': self.__reload, 'accelerator': 'Ctrl+R'},
            {'separator'},
            {'name': 'Exit', 'command': self.__exit, 'accelerator': 'Alt+F4'}
            ])
        self.__main_window_ui.add_menu('Edit', [
            {'name': 'Find', 'command': self.__startFindText, 'accelerator': 'Ctrl+F'},
            {'separator'},
            {'name': 'Cut', 'command': self.__cut, 'accelerator': 'Ctrl+X'},
            {'name': 'Copy', 'command': self.__copy, 'accelerator': 'Ctrl+C'},
            {'name': 'Paste', 'command': self.__paste, 'accelerator': 'Ctrl+P'},
            {'separator'},
            {'name': 'Go To Line', 'command': self.__goToLine, 'accelerator': 'Ctrl+G'}
            ])
        self.__main_window_ui.add_menu('Help', [
            {'name': 'About', 'command': self.__about},
            ])
        self.__main_window_ui.fileTreeView.bind('<<TreeviewSelect>>', lambda *x:self.treeViewItemSelected())

        nodelist = NodeList()
        nodelist.update_nodes()
        hive = Hive(node=nodelist.get_hive_nodes())
        set_shared_blockchain_instance(hive)

        self.leftFile = ''
        self.rightFile = file if file else ''
        self.filesChanged()
        if authorperm != '' and authorperm is not None:
            self.authorperm = authorperm
            self.__resolve_authorperm()

        self.__bind_key_shortcuts()

        self.main_window.mainloop()
Exemple #11
0
    def setUpClass(cls):
        nodelist = NodeList()
        nodelist.update_nodes(blockchain_instance=Hive(
            node=nodelist.get_hive_nodes(), num_retries=10))
        node_list = nodelist.get_hive_nodes()

        cls.bts = Hive(node=node_list,
                       use_condenser=True,
                       nobroadcast=True,
                       unsigned=True,
                       keys={"active": wif},
                       num_retries=10)

        acc = Account("fullnodeupdate", blockchain_instance=cls.bts)
        comment = Comment(acc.get_blog_entries(limit=5)[0],
                          blockchain_instance=cls.bts)
        cls.authorperm = comment.authorperm
        [author, permlink] = resolve_authorperm(cls.authorperm)
        cls.author = author
        cls.permlink = permlink
        cls.category = comment.category
        cls.title = comment.title
def hour_active(chain):
        nodelist = NodeList()
        nodelist.update_nodes()
        if chain=='steem':
                s = Steem(node=nodelist.get_steem_nodes())
        else:
                s = Steem(node=nodelist.get_hive_nodes())
        b=Blockchain(s)
        bl_=[]
        bl_num=int(b.get_current_block_num())
        bl_num_=bl_num-1250
        bl=b.blocks(bl_num_,bl_num)
        for i in bl:
                bl_.append(i['transactions'])

	
        x=('follower','account','voter','from','author')
        account=[]
        new=[]
        for i in x:
                acc=re.findall('"'+i+'":"(.+?)"',str(bl_))
                for l in acc:
                        if l not in account:
                                account.append(l)
        if chain=='steem':
                file=open('active_acc_steem.txt','r')
                old=file.readlines()
                file.close()
                file=open('active_acc_steem.txt','a')
                for i in account:
                        if i+'\n' not in old:
                                file.write(str(i)+'\n')
                                new.append(i)
                file.close()
        else:
                file=open('active_acc_hive.txt','r')
                old=file.readlines()
                file.close()
                file=open('active_acc_hive.txt','a')
                for i in account:
                        if i+'\n' not in old:
                                file.write(str(i)+'\n')
                                new.append(i)
                file.close()
                
        print ('one hour accounts '+chain,len(account))
        print ('one hour brand new '+chain,len(new))
        print ('total ACTIVE accounts '+chain,len(old))
Exemple #13
0
def set_node_list(chain_type=None):
    nodelist = NodeList()
    nodelist.update_nodes()
    chain = None

    if chain_type == 'steemit':
        steem_nodes = nodelist.get_steem_nodes()
        chain = Steem(node=steem_nodes)
        chain.set_default_nodes(steem_nodes)
    elif chain_type == 'hive':
        nodelist = NodeList()
        nodelist.update_nodes()
        hive_nodes = nodelist.get_hive_nodes()
        chain = Hive(node=hive_nodes)
        chain.set_default_nodes(hive_nodes)

    set_shared_blockchain_instance(chain)
    return chain
Exemple #14
0
def get_friends_data(username, follow_type):
    # Setup node list
    nodelist = NodeList()
    nodelist.update_nodes()
    nodes = nodelist.get_hive_nodes()
    hive = Hive(node=nodes)
    hive.set_default_nodes(nodes)
    # logging.warning(hive.config.items())

    # Create account object
    try:
        account = Account(username)
        logging.warning(account)
    except Exception as e:
        logging.warning(e)
        return {}

    followers = account.get_followers()
    following = account.get_following()

    if follow_type == 'followers':
        return make_dict(followers, following)
    else:
        return make_dict(following, followers)
            self.setLevel(logging.DEBUG)
        elif level == "WARNING":
            self.setLevel(logging.WARNING)
        elif level == "ERROR":
            self.setLevel(logging.ERROR)
        elif level == "CRITICAL":
            self.setLevel(logging.CRITICAL)


logger = Logger(name=name_logger)

### SETUP BEEM LIB STUFF
UTC_TIMEZONE = tz.UTC
NODELIST_INSTANCE = NodeList()
NODELIST_INSTANCE.update_nodes()
HIVE_INSTANCE = Hive(node=NODELIST_INSTANCE.get_hive_nodes())
BLOCKCHAIN_INSTANCE = Blockchain(blockchain_instance=HIVE_INSTANCE)

not_today = datetime.datetime.now(UTC_TIMEZONE) - datetime.timedelta(days=days,
                                                                     hours=1)
start = datetime.datetime(not_today.year, not_today.month, not_today.day)

today = datetime.datetime.now(UTC_TIMEZONE)
stop = datetime.datetime(today.year, today.month, today.day)

start_block_id = BLOCKCHAIN_INSTANCE.get_estimated_block_num(start,
                                                             accurate=True)

stop_block_id = BLOCKCHAIN_INSTANCE.get_estimated_block_num(stop,
                                                            accurate=True)
logger.info(f"start time: {start}")
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='.')
    parser.add_argument('--list-accounts', action='store_true')
    args = parser.parse_args()

    setup_logging(default_path=args.logconfig)

    logger.info("Loading config: %s" % str(args.config))

    config = json.loads(open(os.path.abspath(args.config)).read())
    datadir = args.datadir

    nodelist = NodeList()
    nodelist.update_nodes()
    hive = Hive(node=nodelist.get_hive_nodes(),
                num_retries=5,
                call_num_retries=3,
                timeout=15)
    blockchain = Blockchain(blockchain_instance=hive)
    logger.info(str(hive))
    data_file = os.path.join(datadir, 'data.db')
    bot = DelegationOnboardBot(config, data_file, hive)

    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 "last_block_num" in data_db:
        start_block = data_db["last_block_num"] + 1
        if start_block == 35922615:
            start_block += 1
        logger.info("Start block_num: %d" % start_block)

        stop_block = start_block + 100
        if stop_block > blockchain.get_current_block_num():
            stop_block = blockchain.get_current_block_num()
    else:
        start_block = None
        stop_block = None

    if args.list_accounts:
        t = PrettyTable([
            "account", "timestamp", "muted", "hp", "del. hp", "del. timestamp",
            "rc_comments", "del revoked"
        ])
        t.align = "l"
        for acc_name in data_db["accounts"]:
            acc = data_db["accounts"][acc_name]
            if acc["timestamp"] is None:
                timestamp = ""
            else:
                timestamp = formatTimeString(acc["timestamp"])
            if acc["delegation_timestamp"] is None:
                del_timestamp = ""
            else:
                del_timestamp = formatTimeString(acc["delegation_timestamp"])
            t.add_row([
                acc_name, timestamp, acc["muted"], acc["hp"],
                acc["delegated_hp"], del_timestamp,
                round(acc["rc_comments"], 3), acc["delegation_revoked"]
            ])
        print(t)
        return

    logger.info("starting delegation manager for onboarding..")
    block_counter = None
    last_print_stop_block = stop_block
    while True:
        if start_block is not None and stop_block is not None:
            if last_print_stop_block is not None and stop_block - last_print_stop_block > 1:
                last_print_stop_block = stop_block
        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()
            hive = Hive(node=nodelist.get_hive_nodes(),
                        num_retries=5,
                        call_num_retries=3,
                        timeout=15)

            bot.hive = hive

        start_block = last_block_num + 1

        stop_block = start_block + 100
        if stop_block > blockchain.get_current_block_num():
            stop_block = blockchain.get_current_block_num()

        store_data(data_file, "last_block_num", last_block_num)
        time.sleep(3)
Exemple #17
0
def main(args=None):

    args = parse_args(args)
    blockchain = args.blockchain

    nodelist = NodeList()
    nodelist.update_nodes(weights={"block": 1})

    if blockchain == "hive" or blockchain is None:
        max_batch_size = 50
        threading = False
        thread_num = 16
        block_debug = 1000

        nodes = nodelist.get_hive_nodes()
        blk_inst = Hive(node=nodes,
                        num_retries=3,
                        num_retries_call=3,
                        timeout=30)
    elif blockchain == "blurt":
        max_batch_size = None
        threading = False
        thread_num = 8
        block_debug = 20
        nodes = [
            "https://api.blurt.blog", "https://rpc.blurtworld.com",
            "https://rpc.blurtworld.com"
        ]
        blk_inst = Blurt(node=nodes,
                         num_retries=3,
                         num_retries_call=3,
                         timeout=30)
    elif blockchain == "steem":
        max_batch_size = 50
        threading = False
        thread_num = 16
        block_debug = 1000
        nodes = nodelist.get_steem_nodes()
        blk_inst = Steem(node=nodes,
                         num_retries=3,
                         num_retries_call=3,
                         timeout=30)
    else:
        raise Exception("Wrong parameter, can be hive, blurt or steem")
    print(blk_inst)
    block_count = 0
    total_ops = 0
    total_virtual_ops = 0
    total_trx = 0
    blocksperday = 20 * 60 * 24

    blockchain = Blockchain(blockchain_instance=blk_inst, )
    current_block_num = blockchain.get_current_block_num()
    last_block_id = current_block_num - blocksperday

    last_block = Block(last_block_id, blockchain_instance=blk_inst)

    stopTime = last_block.time() + timedelta(seconds=60 * 60 * 24)

    start = timer()
    for entry in blockchain.blocks(start=last_block_id,
                                   max_batch_size=max_batch_size,
                                   threading=threading,
                                   thread_num=thread_num):
        if "block" in entry:
            block_time = parse_time(entry["block"]["timestamp"])
        else:
            block_time = entry["timestamp"]
        if block_time > stopTime:
            break
        block_count += 1
        if "block" in entry:
            trxs = entry["block"]["transactions"]
        else:
            trxs = entry["transactions"]
        for tx in trxs:
            total_trx += 1
            for op in tx["operations"]:
                total_ops += 1

        ops_per_day = total_ops / block_count * blocksperday
        if block_count % (block_debug) == 0:
            print("%d blocks remaining... estimated ops per day: %.1f" %
                  (blocksperday - block_count, ops_per_day))

    duration = timer() - start

    stopTime = last_block.time() + timedelta(seconds=60 * 60 * 24)
    start = timer()
    for entry in blockchain.blocks(start=last_block_id,
                                   max_batch_size=max_batch_size,
                                   threading=threading,
                                   thread_num=thread_num,
                                   only_virtual_ops=True):
        block_time = entry["timestamp"]
        if block_time > stopTime:
            break
        for tx in entry["operations"]:
            for op in tx["op"]:
                total_virtual_ops += 1

    duration = timer() - start

    print("Received %.2f blocks/s." % (block_count / duration))
    print("Bocks: %d, duration %.3f s" % (block_count, duration))
    print("Operations per day: %d" % total_ops)
    print("Trx per day: %d" % total_trx)
    print("Virtual Operations per day: %d" % total_virtual_ops)
Exemple #18
0
from beem.hive import Hive
from beem.nodelist import NodeList

nodelist = NodeList()
nodelist.update_nodes()
hive_instance = Hive(node=nodelist.get_hive_nodes())

Exemple #19
0
        elif self.db_type == "pickle":
            return os.path.isfile(filename)
        elif self.db_type == "deepdish":
            return os.path.isfile(filename)
        elif self.db_type == "sqlite":
            db = dataset.connect('sqlite:///%s' % (filename))
            if self.account in db:
                return True
            else:
                return False


if __name__ == "__main__":
    nodes = NodeList()
    nodes.update_nodes()
    stm = Steem(node=nodes.get_hive_nodes())
    set_shared_steem_instance(stm)
    account_name = "holger80"
    account = Account(account_name, steem_instance=stm)
    path = QStandardPaths.writableLocation(QStandardPaths.CacheLocation)
    print(path)
    db_type = "shelve"
    db = Database(db_type, path, account_name)

    if not db.has_account_hist():
        print("new account")
        ops = db.get_acc_hist()
        db.store_account_hist(ops)
    else:
        print("loading db")
        ops = db.load_account_hist()
Exemple #20
0
def get_hive_nodes():
    nodelist = NodeList()
    nodes = nodelist.get_hive_nodes()
    nodelist.update_nodes(blockchain_instance=Hive(node=nodes, num_retries=10))
    return nodelist.get_hive_nodes()
Exemple #21
0
def main(args=None):
    
    args = parse_args(args)
    blockchain = args.blockchain
    
    nodelist = NodeList()
    nodelist.update_nodes(weights={"block": 1})
    
    if blockchain == "hive" or blockchain is None:
        max_batch_size = 50
        threading = False
        thread_num = 16
        block_debug = 1000
        
        nodes = nodelist.get_hive_nodes()
        blk_inst = Hive(node=nodes, num_retries=3, num_retries_call=3, timeout=30)
    elif blockchain == "blurt":
        max_batch_size = None
        threading = False
        thread_num = 8
        block_debug = 20
        nodes = ["https://rpc.blurt.buzz/", "https://api.blurt.blog", "https://rpc.blurtworld.com", "https://rpc.blurtworld.com"]
        blk_inst = Blurt(node=nodes, num_retries=3, num_retries_call=3, timeout=30)
    elif blockchain == "steem":
        max_batch_size = 50
        threading = False
        thread_num = 16
        block_debug = 1000
        nodes = nodelist.get_steem_nodes()
        blk_inst = Steem(node=nodes, num_retries=3, num_retries_call=3, timeout=30)
    else:
        raise Exception("Wrong parameter, can be hive, blurt or steem")
    print(blk_inst)
    block_count = 0
    total_ops = 0
    total_trx = 0
    duration_s = 60 * 60 * 1
    blocksperday = int(duration_s / 3)
    
    blockchain = Blockchain(blockchain_instance=blk_inst, )
    current_block_num = blockchain.get_current_block_num()
    last_block_id = current_block_num - blocksperday

    last_block = Block(last_block_id, blockchain_instance=blk_inst)

    stopTime = last_block.time() + timedelta(seconds=duration_s)

    start = timer()
    op_stats = {}
    for entry in blockchain.blocks(start=last_block_id, max_batch_size=max_batch_size, threading=threading, thread_num=thread_num):
        if "block" in entry:
            block_time = parse_time(entry["block"]["timestamp"])
        else:
            block_time = entry["timestamp"]
        if block_time > stopTime:
            break
        block_count += 1
        if "block" in entry:
            trxs = entry["block"]["transactions"]
        else:
            trxs = entry["transactions"]
        for tx in trxs:
            total_trx += 1
            for op in tx["operations"]:
                if "_operation" in op["type"]:
                    op_type = op["type"][:-10]
                else:
                    op_type = op["type"]
                if op_type in op_stats:
                    op_stats[op_type] += 1
                else:
                    op_stats[op_type] = 1
                total_ops += 1

        ops_per_day = total_ops / block_count * blocksperday
        if block_count % (block_debug) == 0:
            print("%d blocks remaining... estimated ops per day: %.1f" % (blocksperday - block_count, ops_per_day))

    duration = timer() - start    
    t = PrettyTable(["Type", "Count", "percentage"])
    t.align = "l"
    op_list = []
    for o in op_stats:
        op_list.append({"type": o, "n": op_stats[o], "perc": op_stats[o] / total_ops * 100})
    op_list_sorted = sorted(op_list, key=lambda x: x['n'], reverse=True)
    for op in op_list_sorted:
        t.add_row([op["type"], op["n"], "%.2f %%" % op["perc"]])
    print(t)
Exemple #22
0
    def run(self, start_block, stop_block):
        self.hive.wallet.unlock(self.config["wallet_password"])
        self.blockchain = Blockchain(mode='head',
                                     blockchain_instance=self.hive)
        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"]):
            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
                c_parent = None
                authorperm = construct_authorperm(op)
                use_tags_api = True
                while c_comment is None and cnt < 10:
                    cnt += 1
                    try:
                        c_comment = Comment(authorperm,
                                            use_tags_api=use_tags_api,
                                            blockchain_instance=self.hive)
                        c_comment.refresh()
                    except:
                        if cnt > 5:
                            use_tags_api = False
                        nodelist = NodeList()
                        nodelist.update_nodes()
                        self.hive = Hive(node=nodelist.get_hive_nodes(),
                                         num_retries=5,
                                         call_num_retries=3,
                                         timeout=15)
                        time.sleep(3)
                if cnt == 10 or c_comment is None:
                    logger.warn("Could not read %s/%s" %
                                (op["author"], op["permlink"]))
                    continue
                if 'depth' in c_comment:
                    if c_comment['depth'] == 0:
                        continue
                else:
                    if c_comment["parent_author"] == '':
                        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
                if self.token_config[token]["upvote_token_receiver"]:
                    parent_identifier = construct_authorperm(
                        c_comment["parent_author"],
                        c_comment["parent_permlink"])
                    c_parent = Comment(parent_identifier,
                                       blockchain_instance=self.hive)
                    for v in c_parent.get_votes(raw_data=True):
                        if self.token_config[token]["token_account"] == v[
                                "voter"]:
                            already_voted = True
                else:
                    for v in c_comment.get_votes(raw_data=True):
                        if self.token_config[token]["token_account"] == v[
                                "voter"]:
                            already_voted = True
                if already_voted:
                    continue

                already_replied = None
                cnt = 0
                if self.token_config[token]["usage_upvote_percentage"] == 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.hive.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"],
                                     blockchain_instance=self.hive)
                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"],
                                    blockchain_instance=self.hive)
                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.hive.wallet.locked(
                ):
                    self.hive.wallet.unlock(self.config["wallet_password"])

                self.log_data["new_commands"] += 1
                wallet = Wallet(c_comment["author"],
                                blockchain_instance=self.hive)
                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"],
                        blockchain_instance=self.hive)

                    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.hive.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.hive.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)
                        upvote_percentge = self.token_config[token][
                            "usage_upvote_percentage"]
                        if self.token_config[token]["scale_upvote_weight"]:
                            upvote_percentge = upvote_percentge * amount / self.token_config[
                                token]["maximum_amount_per_comment"]
                        print("Upvote with %.2f %%" % upvote_percentge)
                        if self.token_config[token]["upvote_token_receiver"]:
                            if c_parent is None:
                                c_parent = Comment(
                                    parent_identifier,
                                    blockchain_instance=self.hive)
                            try:
                                c_parent.upvote(upvote_percentge,
                                                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")
                        else:
                            try:
                                c_comment.upvote(upvote_percentge,
                                                 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
Exemple #23
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()
    hive = Hive(node=nodelist.get_hive_nodes(),
                num_retries=5,
                call_num_retries=3,
                timeout=15)

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

    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
        if start_block == 35922615:
            start_block += 1
        logger.info("Start block_num: %d" % start_block)

        stop_block = start_block + 100
    else:
        start_block = None
        stop_block = None
    logger.info("starting token distributor..")
    block_counter = None
    last_print_stop_block = stop_block
    while True:
        if start_block is not None and stop_block is not None:
            if stop_block - last_print_stop_block > 1:
                logger.info("%d - %d" % (start_block, stop_block))
                last_print_stop_block = stop_block
        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()
            hive = Hive(node=nodelist.get_hive_nodes(),
                        num_retries=5,
                        call_num_retries=3,
                        timeout=15)

            bot.hive = hive

        start_block = last_block_num + 1

        stop_block = start_block + 100
        store_data(data_file, "last_block_num", last_block_num)
        time.sleep(3)
Exemple #24
0
# This Python file uses the following encoding: utf-8
# (c) holger80
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from beem import Steem
from beem.comment import Comment
from beem.nodelist import NodeList
from hiveengine.wallet import Wallet
import time

if __name__ == "__main__":
    nodelist = NodeList()
    nodelist.update_nodes()
    stm = Steem(node=nodelist.get_hive_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)
Exemple #25
0
    data["sell_asset"] = sell_asset2
    df = pd.DataFrame(data)
    writer = pd.ExcelWriter(filename, engine='xlsxwriter')
    df.to_excel(writer,
                sheet_name=sheet_name,
                startrow=0,
                header=True,
                index=False)
    writer.save()


if __name__ == "__main__":
    nodelist = NodeList()
    nodelist.update_nodes()
    # stm = Steem(node=nodelist.get_steem_nodes())
    stm = Hive(node=nodelist.get_hive_nodes())
    print(stm)

    account_name = "holger80"
    data_account_name = "hive_holger80_powered_up"
    symbol = "HIVE"
    hive_fork_block = 41818753
    has_fork = True
    limit_to_year = True
    current_year = 2020

    xls_filename = "%s_%d.xlsx" % (data_account_name, current_year)
    account = Account(account_name, blockchain_instance=stm)
    ops_dict = {}
    _ids = {}
    for ops in account.history():
from beem import Hive
from beem import Steem
from beem.nodelist import NodeList

nodelist = NodeList()
nodelist.update_nodes()
HIVE_INSTANCE = Hive(node=nodelist.get_hive_nodes())
STEEM_INSTANCE = Steem(node=nodelist.get_steem_nodes())