print("dpaycli_acc.balances  {}".format(dpaycli_acc.balances))
 print("dpay_acc.balances {}".format(dpay_acc.balances))
 # get_balances()
 print("dpaycli_acc.get_balances()  {}".format(dpaycli_acc.get_balances()))
 print("dpay_acc.get_balances() {}".format(dpay_acc.get_balances()))
 # reputation()
 print("dpaycli_acc.get_reputation()  {}".format(
     dpaycli_acc.get_reputation()))
 print("dpay_acc.reputation() {}".format(dpay_acc.reputation()))
 # voting_power()
 print("dpaycli_acc.get_voting_power()  {}".format(
     dpaycli_acc.get_voting_power()))
 print("dpay_acc.voting_power() {}".format(dpay_acc.voting_power()))
 # get_followers()
 print("dpaycli_acc.get_followers()  {}".format(
     dpaycli_acc.get_followers()))
 print("dpay_acc.get_followers() {}".format(dpay_acc.get_followers()))
 # get_following()
 print("dpaycli_acc.get_following()  {}".format(
     dpaycli_acc.get_following()))
 print("dpay_acc.get_following() {}".format(dpay_acc.get_following()))
 # has_voted()
 print("dpaycli_acc.has_voted()  {}".format(
     dpaycli_acc.has_voted("@holger80/api-methods-list-for-appbase")))
 print("dpay_acc.has_voted() {}".format(
     dpay_acc.has_voted(
         dpayPost("@holger80/api-methods-list-for-appbase"))))
 # curation_stats()
 print("dpaycli_acc.curation_stats()  {}".format(
     dpaycli_acc.curation_stats()))
 print("dpay_acc.curation_stats() {}".format(dpay_acc.curation_stats()))
Ejemplo n.º 2
0
def benchmark_node(node, how_many_minutes=10, how_many_seconds=30):
    block_count = 0
    history_count = 0
    access_time = 0
    follow_time = 0
    blockchain_version = u'0.0.0'
    successful = True
    error_msg = None
    start_total = timer()
    max_batch_size = None
    threading = False
    thread_num = 16

    authorpermvoter = u"@gtg/dpay-pressure-4-need-for-speed|gandalf"
    [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter)
    authorperm = construct_authorperm(author, permlink)
    last_block_id = 19273700
    try:
        stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30)
        blockchain = Blockchain(dpay_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        last_block = Block(last_block_id, dpay_instance=stm)

        stopTime = last_block.time() + timedelta(seconds=how_many_minutes * 60)
        total_transaction = 0

        start = timer()
        for entry in blockchain.blocks(start=last_block_id,
                                       max_batch_size=max_batch_size,
                                       threading=threading,
                                       thread_num=thread_num):
            block_no = entry.identifier
            block_count += 1
            if "block" in entry:
                trxs = entry["block"]["transactions"]
            else:
                trxs = entry["transactions"]

            for tx in trxs:
                for op in tx["operations"]:
                    total_transaction += 1
            if "block" in entry:
                block_time = parse_time(entry["block"]["timestamp"])
            else:
                block_time = parse_time(entry["timestamp"])

            if block_time > stopTime:
                last_block_id = block_no
                break
            if timer() - start > how_many_seconds or quit_thread:
                break
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        block_count = -1
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        # quit = True
    except Exception as e:
        error_msg = str(e)
        block_count = -1

    try:
        stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", dpay_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        start = timer()
        for acc_op in account.history_reverse(batch_size=100):
            history_count += 1
            if timer() - start > how_many_seconds or quit_thread:
                break
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        history_count = -1
        successful = False
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        history_count = -1
        successful = False
        # quit = True
    except Exception as e:
        error_msg = str(e)
        history_count = -1
        successful = False

    try:
        stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", dpay_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        start = timer()
        Vote(authorpermvoter, dpay_instance=stm)
        stop = timer()
        vote_time = stop - start
        start = timer()
        Comment(authorperm, dpay_instance=stm)
        stop = timer()
        comment_time = stop - start
        start = timer()
        Account(author, dpay_instance=stm)
        stop = timer()
        account_time = stop - start
        start = timer()
        account.get_followers()
        stop = timer()
        follow_time = stop - start
        access_time = (vote_time + comment_time + account_time +
                       follow_time) / 4.0
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        access_time = -1
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        # quit = True
    except Exception as e:
        error_msg = str(e)
        access_time = -1
    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
    }