Exemple #1
0
    def build(self,
              only_ops=[],
              exclude_ops=[],
              enable_rewards=False,
              enable_out_votes=False,
              enable_in_votes=False):
        """ Builds the account history based on all account operations

            :param array only_ops: Limit generator by these
                operations (*optional*)
            :param array exclude_ops: Exclude thse operations from
                generator (*optional*)

        """
        if len(self.timestamps) > 0:
            start_timestamp = self.timestamps[-1]
        else:
            start_timestamp = None
        for op in sorted(self, key=lambda k: k['timestamp']):
            ts = parse_time(op['timestamp'])
            if start_timestamp is not None and start_timestamp > ts:
                continue
            # print(op)
            if op['type'] in exclude_ops:
                continue
            if len(only_ops) > 0 and op['type'] not in only_ops:
                continue
            self.ops_statistics[op['type']] += 1
            self.parse_op(op,
                          only_ops=only_ops,
                          enable_rewards=enable_rewards,
                          enable_out_votes=enable_out_votes,
                          enable_in_votes=enable_in_votes)
def memomatch(exchange, memo, days=0, debug=False):
    """Find all transfers to a given exchange that were done with the
    provided memo within the last [days] days. The memo parameter may
    be a substring of the actual transfer memo.

    :param str exchange: exchange account to parse
    :param str memo: memo or memo-substring to match
    :param float days: number of days to take into account. 0 uses all
    available data (default)
    :param bool debug: enable debug printout (disabled by default)

    :return multi-line string with the results

    """
    acc = Account(exchange)
    stop_time = addTzInfo(datetime.utcnow()) - timedelta(days=days)
    result = ""
    for op in acc.history_reverse(only_ops=['transfer']):
        if debug:
            sys.stdout.write("%s\r" % (op['timestamp']))
        if days and parse_time(op['timestamp']) < stop_time:
            break
        if memo not in op['memo']:
            continue
        result += "\n%s: %s transferred %s to %s: %s" % \
                  (datestr(op['timestamp']), op['from'],
                   Amount(op['amount']), op['to'], op['memo'])

    return result[1:]
def prepare_account(account):
    json = account.copy()
    dates = [ "last_owner_update", "last_account_update", "created",
              "last_owner_proved", "last_active_proved",
              "last_account_recovery", "last_vote_time",
              "sbd_seconds_last_update", "sbd_last_interest_payment",
              "savings_sbd_seconds_last_update",
              "savings_sbd_last_interest_payment",
              "next_vesting_withdrawal", "last_market_bandwidth_update",
              "last_post", "last_root_post", "last_bandwidth_update" ]
    for date in dates:
        if date in account:
            json[date] = parse_time(account[date])

    amounts = [ "balance", "savings_balance", "sbd_balance",
                "savings_sbd_balance", "reward_sbd_balance",
                "reward_steem_balance", "reward_vesting_balance",
                "reward_vesting_steem", "vesting_shares",
                "delegated_vesting_shares", "received_vesting_shares",
                "vesting_withdraw_rate", "vesting_balance"]
    for amount in amounts:
        if amount in account:
            json[amount] = Amount(account[amount]).amount

    if "json_metadata" in json:
        try:
            json['json_metadata'] = jloads(json['json_metadata'])
        except:
            json['json_metadata'] = {}

    return json
def exchangetransfers(account, days=0, debug=False):
    """Find all outgoing transfers from a given account to any of the
    exchanges within the last [days] days.

    :param str account: account to parse
    :param float days: number of days to take into account. 0 uses all
    available data (default)
    :param bool debug: enable debug printout (disabled by default)

    :return multi-line string with the results
    """
    acc = Account(account)
    stop_time = addTzInfo(datetime.utcnow()) - timedelta(days=days)
    result = ""
    for op in acc.history_reverse(only_ops=['transfer']):
        if debug:
            sys.stdout.write("%s\r" % (op['timestamp']))
        if days and parse_time(op['timestamp']) < stop_time:
            break
        if op['to'] not in EXCHANGES:
            continue
        result += "\n%s: %s transferred %s to %s: %s" % \
                  (datestr(op['timestamp']), op['from'],
                   Amount(op['amount']), op['to'], op['memo'])
    return result[1:]
def datestr(date=None):
    """Convert timestamps to strings in a predefined format

    """
    if date is None:
        date = datetime.utcnow()
    if isinstance(date, str):
        date = parse_time(date)
    return date.strftime("%y-%m-%d %H:%M:%S")
def transfers(account,
              trx_type='all',
              days=0,
              include_bots=False,
              debug=False):
    """Find all transfers sent or received by [account] within the last
    [days] days.

    :param str account: account to parse
    :param str trx_type: transaction type to list. Valid types are
    "in", "out" and "all".
    :param float days: number of days to take into account. 0 uses all
    available data (default)
    :param bool debug: enable debug printout (disabled by default)

    :return multi-line string with the results

    """
    trx_types = ['in', 'out', 'all']
    if trx_type not in trx_types:
        raise ValueError("Invalid trx_type - allowed values: %s" % (trx_types))
    acc = Account(account)
    stop_time = addTzInfo(datetime.utcnow()) - timedelta(days=days)
    receivers = set()
    senders = set()
    result = ""
    for op in acc.history_reverse(only_ops=['transfer']):
        if debug:
            sys.stdout.write("%s\r" % (op['timestamp']))
        if days and parse_time(op['timestamp']) < stop_time:
            break
        if include_bots is False and \
           (op['from'] in BOTS or op['to'] in BOTS):
            continue  # skip transfers from/to bots
        if op['to'] == acc['name'] and trx_type in ['in', 'all']:
            result += "\n%s: %s received %s from %s: %s" % \
                      (datestr(op['timestamp']), op['to'],
                       Amount(op['amount']), op['from'], op['memo'])
            senders |= set([op['from']])
        if op['from'] == acc['name'] and trx_type in ['out', 'all']:
            result += "\n%s: %s sent %s to %s: %s" % \
                      (datestr(op['timestamp']), op['from'],
                       Amount(op['amount']), op['to'], op['memo'])
            receivers |= set([op['to']])
    if trx_type in ['in', 'all']:
        result += "\n%s received funds from %d senders: %s" % \
                  (account, len(senders), ", ".join(sorted(senders)))
    if trx_type in ['out', 'all']:
        result += "\n%s sent funds to %d receivers: %s" % \
                  (account, len(receivers), ", ".join(sorted(receivers)))
    if trx_type == 'all':
        overlap = set(senders) & set(receivers)
        result += "\n%s both sent to and received funds from %d accounts: " \
                  "%s" % (account, len(overlap), ", ".join(sorted(overlap)))
    return result[1:]
def parse_transfer_history(account, days=0, include_bots=False, debug=False):
    """parse the transfer history of an account

    :param str account: account to be parsed
    :param float days: number of days to take into account. 0 uses all
    available data (default)
    :param bool debug: enable debug printout (disabled by default)

    :return dict of sets with the list of receivers (`'sent_to'`),
    senders (`'received_from'`) and exchange memos
    (`'exchange_memos'`).

    """
    sent_to = set()
    received_from = set()
    exchange_memos = set()
    if debug:
        print("Parsing account history of %s" % (account))
    acc = Account(account)
    stop_time = addTzInfo(datetime.utcnow()) - timedelta(days=days)
    for op in acc.history_reverse(only_ops=['transfer']):
        if debug:
            sys.stdout.write("%s\r" % (op['timestamp']))
        if days and parse_time(op['timestamp']) < stop_time:
            break
        if acc['name'] == op['from']:
            if op['to'] in EXCHANGES:
                exchange_memos |= set([op['memo']])
            elif op['to'] not in BOTS or include_bots is True:
                sent_to |= set([op['to']])
        if acc['name'] == op['to']:
            if op['from'] in EXCHANGES or \
               (op['from'] in BOTS and not include_bots):
                continue
            received_from |= set([op['from']])
    return {
        'sent_to': sent_to,
        'received_from': received_from,
        'exchange_memos': exchange_memos
    }
Exemple #8
0
s.close()

lists = []
last_list = []
last_list10 = []
last_list20 = []
all_witnesses = set()
change_ts = []
change_ts20 = []
change_ts10 = []
for op in ops:
    meta = json.loads(op['json_metadata'])
    if 'witnesses' not in meta:
        continue
    witnesses = meta['witnesses']
    ts = parse_time(op['timestamp'])
    if witnesses != last_list:
        lists.append(witnesses)
        change_ts.append(ts)
    if witnesses[:20] != last_list20:
        change_ts20.append(ts)
    if witnesses[:10] != last_list10:
        change_ts10.append(ts)
    last_list = witnesses
    last_list20 = witnesses[:20]
    last_list10 = witnesses[:10]
    all_witnesses |= set(witnesses)

all_witnesses = list(last_list)
# print(all_witnesses)
# print(len(all_witnesses))
follow_timestamps = {}
for acc in known_accs:
    print("%d/%d - parsing %s (%d connected)" % (idx, len(known_accs),
                                                 acc,
                                                 len(connected_accounts)))
    if acc not in voting_timestamps:
        voting_timestamps[acc] = []
    if acc not in follow_timestamps:
        follow_timestamps[acc] = []
    try:
        a = Account(acc)
    except:
        continue
    for op in a.history(start=hist_start, only_ops=['vote', 'custom_json']):
        if op['type'] == 'custom_json':
            follow_timestamps[acc].append(parse_time(op['timestamp']))
            continue
        if op['voter'] != acc:
            continue
        voting_timestamps[acc].append(parse_time(op['timestamp']))
        authorperm = construct_authorperm(op)
        if authorperm in authorperms:
            continue
        c = Comment(authorperm)
        voters = set([v['voter'] for v in c['active_votes']])
        connected_accounts |= (voters & created_accounts)
    idx += 1

print(connected_accounts)
print(len(connected_accounts))
Exemple #10
0
            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
                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:
                    total_duration = formatTimedelta(datetime.now() -
                                                     startTime)
                    last_block_id = block_no
                    avtran = total_transaction / (last_block_id - 19273700)
                    break
            start_time = time.time()

            stopOP = virtual_op_count - how_many_virtual_op + 1
            i = 0
            for acc_op in account.history_reverse(stop=stopOP):
                i += 1
Exemple #11
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 #12
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/steem-pressure-4-need-for-speed|gandalf"
    [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter)
    authorperm = construct_authorperm(author, permlink)
    last_block_id = 19273700
    try:
        stm = Steem(node=node, num_retries=3, num_retries_call=3, timeout=30)
        blockchain = Blockchain(steem_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        last_block = Block(last_block_id, steem_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 = Steem(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", steem_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 = Steem(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", steem_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        start = timer()
        Vote(authorpermvoter, steem_instance=stm)
        stop = timer()
        vote_time = stop - start
        start = timer()
        Comment(authorperm, steem_instance=stm)
        stop = timer()
        comment_time = stop - start
        start = timer()
        Account(author, steem_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}
votes = {}

post_count = 0
comment_count = 0

for post in posts:
    created = addTzInfo(post['created'])
    authors |= set([post['author']])
    if post['depth'] > 0:
        comment_authors |= set([post['author']])
        comment_count += 1
    else:
        root_authors |= set([post['author']])
        post_count += 1
    for v in post['active_votes']:
        time = parse_time(v['time'])
        date = time.date()
        if time - created > timedelta(days=7):
            date = created.date()
        if date not in votes:
            votes[date] = {'voters': set(), 'rshares': 0}
        votes[date]['voters'] |= set([v['voter']])
        votes[date]['rshares'] += abs(int(v['rshares']))

stats = {
    'authors': len(authors),
    'root_authors': len(root_authors),
    'comment_authors': len(comment_authors),
    'votes': votes,
    'post_count': post_count,
    'comment_count': comment_count
Exemple #14
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 #15
0
    print(query)
    cursor.execute(query)

    ops = []
    for op in cursor:
        entry = {}
        # print(op)
        for field, value in zip(fields, op):
            if field == "active_votes":
                value = json.loads(value)
                # print(len(value))
                for vote in range(len(value)):
                    value[vote]['rshares'] = int(value[vote]['rshares'])
                    value[vote]['weight'] = int(value[vote]['weight'])
                    value[vote]['percent'] = int(value[vote]['percent'])
                    value[vote]['time'] = parse_time(value[vote]['time'])
                    value[vote]['reputation'] = int(value[vote]['reputation'])

            entry[field] = value
        ops.append(entry)
        sys.stdout.write("%s\r" % (entry['created']))
        # print(entry)

    s = shelve.open("posts-%d%02d%02d.shelf" %
                    (qstart.year, qstart.month, qstart.day))
    s['posts'] = ops
    s.close()

    print(start_date, len(ops))

    start_date = qstop
Exemple #16
0
    def parse_op(self,
                 op,
                 only_ops=[],
                 enable_rewards=False,
                 enable_out_votes=False,
                 enable_in_votes=False):
        """ Parse account history operation"""
        ts = parse_time(op['timestamp'])

        if op['type'] == "account_create":
            fee_steem = Amount(op['fee'], steem_instance=self.steem).amount
            fee_vests = self.steem.sp_to_vests(Amount(
                op['fee'], steem_instance=self.steem).amount,
                                               timestamp=ts)
            # print(fee_vests)
            if op['new_account_name'] == self.account["name"]:
                self.update(ts, fee_vests, 0, 0)
                return
            if op['creator'] == self.account["name"]:
                self.update(ts, 0, 0, 0, fee_steem * (-1), 0)
                return

        elif op['type'] == "account_create_with_delegation":
            fee_steem = Amount(op['fee'], steem_instance=self.steem).amount
            fee_vests = self.steem.sp_to_vests(Amount(
                op['fee'], steem_instance=self.steem).amount,
                                               timestamp=ts)
            if op['new_account_name'] == self.account["name"]:
                if Amount(op['delegation'],
                          steem_instance=self.steem).amount > 0:
                    delegation = {
                        'account':
                        op['creator'],
                        'amount':
                        Amount(op['delegation'], steem_instance=self.steem)
                    }
                else:
                    delegation = None
                self.update(ts, fee_vests, delegation, 0)
                return

            if op['creator'] == self.account["name"]:
                delegation = {
                    'account': op['new_account_name'],
                    'amount': Amount(op['delegation'],
                                     steem_instance=self.steem)
                }
                self.update(ts, 0, 0, delegation, fee_steem * (-1), 0)
                return

        elif op['type'] == "delegate_vesting_shares":
            vests = Amount(op['vesting_shares'], steem_instance=self.steem)
            # print(op)
            if op['delegator'] == self.account["name"]:
                delegation = {'account': op['delegatee'], 'amount': vests}
                self.update(ts, 0, 0, delegation)
                return
            if op['delegatee'] == self.account["name"]:
                delegation = {'account': op['delegator'], 'amount': vests}
                self.update(ts, 0, delegation, 0)
                return

        elif op['type'] == "transfer":
            amount = Amount(op['amount'], steem_instance=self.steem)
            # print(op)
            if op['from'] == self.account["name"]:
                if amount.symbol == self.steem.steem_symbol:
                    self.update(ts, 0, 0, 0, amount * (-1), 0)
                elif amount.symbol == self.steem.sbd_symbol:
                    self.update(ts, 0, 0, 0, 0, amount * (-1))
            if op['to'] == self.account["name"]:
                if amount.symbol == self.steem.steem_symbol:
                    self.update(ts, 0, 0, 0, amount, 0)
                elif amount.symbol == self.steem.sbd_symbol:
                    self.update(ts, 0, 0, 0, 0, amount)
            # print(op, vests)
            # self.update(ts, vests, 0, 0)
            return

        elif op['type'] == "fill_order":
            current_pays = Amount(op["current_pays"],
                                  steem_instance=self.steem)
            open_pays = Amount(op["open_pays"], steem_instance=self.steem)
            if op["current_owner"] == self.account["name"]:
                if current_pays.symbol == self.steem.steem_symbol:
                    self.update(ts, 0, 0, 0, current_pays * (-1), open_pays)
                elif current_pays.symbol == self.steem.sbd_symbol:
                    self.update(ts, 0, 0, 0, open_pays, current_pays * (-1))
            if op["open_owner"] == self.account["name"]:
                if current_pays.symbol == self.steem.steem_symbol:
                    self.update(ts, 0, 0, 0, current_pays, open_pays * (-1))
                elif current_pays.symbol == self.steem.sbd_symbol:
                    self.update(ts, 0, 0, 0, open_pays * (-1), current_pays)
            # print(op)
            return

        elif op['type'] == "transfer_to_vesting":
            steem = Amount(op['amount'], steem_instance=self.steem)
            vests = self.steem.sp_to_vests(steem.amount, timestamp=ts)
            if op['from'] == self.account["name"]:
                self.update(ts, vests, 0, 0, steem * (-1), 0)
            else:
                self.update(ts, vests, 0, 0, 0, 0)
            # print(op)
            # print(op, vests)
            return

        elif op['type'] == "fill_vesting_withdraw":
            # print(op)
            vests = Amount(op['withdrawn'], steem_instance=self.steem)
            self.update(ts, vests * (-1), 0, 0)
            return

        elif op['type'] == "return_vesting_delegation":
            delegation = {
                'account': None,
                'amount': Amount(op['vesting_shares'],
                                 steem_instance=self.steem)
            }
            self.update(ts, 0, 0, delegation)
            return

        elif op['type'] == "claim_reward_balance":
            vests = Amount(op['reward_vests'], steem_instance=self.steem)
            steem = Amount(op['reward_steem'], steem_instance=self.steem)
            sbd = Amount(op['reward_sbd'], steem_instance=self.steem)
            self.update(ts, vests, 0, 0, steem, sbd)
            return

        elif op['type'] == "curation_reward":
            if "curation_reward" in only_ops or enable_rewards:
                vests = Amount(op['reward'], steem_instance=self.steem)
            if "curation_reward" in only_ops:
                self.update(ts, vests, 0, 0)
            if enable_rewards:
                self.update_rewards(ts, vests, 0, 0, 0)
            return

        elif op['type'] == "author_reward":
            if "author_reward" in only_ops or enable_rewards:
                # print(op)
                vests = Amount(op['vesting_payout'], steem_instance=self.steem)
                steem = Amount(op['steem_payout'], steem_instance=self.steem)
                sbd = Amount(op['sbd_payout'], steem_instance=self.steem)
            if "author_reward" in only_ops:
                self.update(ts, vests, 0, 0, steem, sbd)
            if enable_rewards:
                self.update_rewards(ts, 0, vests, steem, sbd)
            return

        elif op['type'] == "producer_reward":
            vests = Amount(op['vesting_shares'], steem_instance=self.steem)
            self.update(ts, vests, 0, 0)
            return

        elif op['type'] == "comment_benefactor_reward":
            if op['benefactor'] == self.account["name"]:
                if "reward" in op:
                    vests = Amount(op['reward'], steem_instance=self.steem)
                    self.update(ts, vests, 0, 0)
                else:
                    vests = Amount(op['vesting_payout'],
                                   steem_instance=self.steem)
                    steem = Amount(op['steem_payout'],
                                   steem_instance=self.steem)
                    sbd = Amount(op['sbd_payout'], steem_instance=self.steem)
                    self.update(ts, vests, 0, 0, steem, sbd)
                return
            else:
                return

        elif op['type'] == "fill_convert_request":
            amount_in = Amount(op["amount_in"], steem_instance=self.steem)
            amount_out = Amount(op["amount_out"], steem_instance=self.steem)
            if op["owner"] == self.account["name"]:
                self.update(ts, 0, 0, 0, amount_out, amount_in * (-1))
            return

        elif op['type'] == "interest":
            interest = Amount(op["interest"], steem_instance=self.steem)
            self.update(ts, 0, 0, 0, 0, interest)
            return

        elif op['type'] == "vote":
            if "vote" in only_ops or enable_out_votes:
                weight = int(op['weight'])
                if op["voter"] == self.account["name"]:
                    self.update_out_vote(ts, weight)
            if "vote" in only_ops or enable_in_votes and op[
                    "author"] == self.account["name"]:
                weight = int(op['weight'])
                self.update_in_vote(ts, weight, op)
            return

        elif op['type'] in [
                'comment', 'feed_publish', 'shutdown_witness',
                'account_witness_vote', 'witness_update', 'custom_json',
                'limit_order_create', 'account_update',
                'account_witness_proxy', 'limit_order_cancel',
                'comment_options', 'delete_comment', 'interest',
                'recover_account', 'pow', 'fill_convert_request', 'convert',
                'request_account_recovery'
        ]:
            return
Exemple #17
0
rshares_per_day_hf20 = hist()

while date < datetime(2018, 8, 8):
    try:
        print("processing ", date)
        s = shelve.open('posts-2018-%02d-%02d.shelf' % (date.month, date.day))
        posts = s['posts']
        s.close()
    except:
        posts = []
        pass
    date += timedelta(days=1)

    for post in posts:
        for vote in post['active_votes']:
            ts = parse_time(vote['time'])
            if ts < vote_start or ts >= vote_end:
                continue
            rshares_hf19 = int(vote['rshares'])
            if rshares_hf19 == 0:
                continue
            rshares_hf20 = int(
                math.copysign(max(0,
                                  abs(rshares_hf19) - VOTE_DUST_THRESHOLD),
                              rshares_hf19))
            rshares_per_day_hf19.fill(ts.date(), rshares_hf19)
            rshares_per_day_hf20.fill(ts.date(), rshares_hf20)
            rshare_distribution_hf19.append(abs(rshares_hf19))
            rshare_distribution_hf20.append(abs(rshares_hf20))

limit_args = {
posting_rewards = []
curation_rewards = []

sp_limit = 50
post_limit = 200
created_limit = addTzInfo(datetime(2018, 1, 1))
reward_limit = 2

s = shelve.open("accounts.shelf")
accounts = s['accounts']
s.close()

print(len(accounts))

for a in accounts:
    created.append(max(parse_time(a['created']), created_limit))
    reputation.append(a['reputation'])
    effective_sp.append(min(a['steem_power'], sp_limit))
    own_sp.append(min(a['own_steem_power'], sp_limit))
    print(a['name'], a['own_steem_power'], a['steem_power'])
    posts.append(min(a['post_count'], post_limit))
    creator.fill(a['creator'])
    posting_rewards.append(min(a['posting_rewards'] / 1000, reward_limit))
    curation_rewards.append(min(a['curation_rewards'] / 1000, reward_limit))

fig = plt.figure(figsize=(8, 12))
fig.autofmt_xdate()

title = "Account creation date"
xlabel = "Date"
ylabel = "Number of accounts"