示例#1
0
    def run(self):
        b = Blockchain(steem_instance=self.stm)

        yesterday = date.today() - timedelta(days=1)
        yesterday_0_0_0 = datetime(yesterday.year, yesterday.month,
                                   yesterday.day)
        yesterday_23_59_59 = datetime(yesterday.year, yesterday.month,
                                      yesterday.day, 23, 59, 59)
        start_block = b.get_estimated_block_num(addTzInfo(yesterday_0_0_0))
        stop_block = b.get_estimated_block_num(addTzInfo(yesterday_23_59_59))
        logger.info("Check token transfer from %s..." %
                    self.config["scot_account"])
        token_sent_last_24_h = self.get_token_transfer_last_24_h()
        if token_sent_last_24_h > 0:
            logger.warning("Token were already sent today...")
            return
        logger.info("No token transfer were found, continue...")
        token_per_100_vote = self.get_token_holder()
        logger.info("%d token holder were found." % len(token_per_100_vote))
        token_to_authors = self.get_token_to_sent(start_block, stop_block,
                                                  token_per_100_vote)
        token_to_authors = self.adapt_to_precision(token_to_authors)
        token_amount_to_sent = self.count_token(token_to_authors)
        logger.info("Start to send %f token to %d accounts" %
                    (token_amount_to_sent, len(token_to_authors)))
        self.send_token(token_to_authors)
示例#2
0
 def search(self, search_str, start=None, stop=None, use_block_num=True):
     """ Returns ops in the given range"""
     ops = []
     if start is not None:
         start = addTzInfo(start)
     if stop is not None:
         stop = addTzInfo(stop)
     for op in self:
         if use_block_num and start is not None and isinstance(start, int):
             if op["block"] < start:
                 continue
         elif not use_block_num and start is not None and isinstance(
                 start, int):
             if op["index"] < start:
                 continue
         elif start is not None and isinstance(start,
                                               (datetime, date, time)):
             if start > formatTimeString(op["timestamp"]):
                 continue
         if use_block_num and stop is not None and isinstance(stop, int):
             if op["block"] > stop:
                 continue
         elif not use_block_num and stop is not None and isinstance(
                 stop, int):
             if op["index"] > stop:
                 continue
         elif stop is not None and isinstance(stop, (datetime, date, time)):
             if stop < formatTimeString(op["timestamp"]):
                 continue
         op_string = json.dumps(list(op.values()))
         if re.search(search_str, op_string):
             ops.append(op)
     return ops
示例#3
0
    def get_SBD_transfer(self, account, shares, timestamp):
        """ Returns all entries for given value

        """
        table = self.db[self.__tablename__]
        found_trx = None
        for trx in table.find(account=account,
                              shares=-shares,
                              share_type="SBD"):
            if addTzInfo(trx["timestamp"]) < addTzInfo(timestamp):
                found_trx = trx
        return found_trx
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:]
示例#5
0
 def get_data(self, timestamp=None, index=0):
     """ Returns snapshot for given timestamp"""
     if timestamp is None:
         timestamp = datetime.utcnow()
     timestamp = addTzInfo(timestamp)
     # Find rightmost value less than x
     i = bisect_left(self.timestamps, timestamp)
     if i:
         index = i - 1
     else:
         return {}
     ts = self.timestamps[index]
     own = self.own_vests[index]
     din = self.delegated_vests_in[index]
     dout = self.delegated_vests_out[index]
     steem = self.own_steem[index]
     sbd = self.own_sbd[index]
     sum_in = sum([din[key].amount for key in din])
     sum_out = sum([dout[key].amount for key in dout])
     sp_in = self.steem.vests_to_sp(sum_in, timestamp=ts)
     sp_out = self.steem.vests_to_sp(sum_out, timestamp=ts)
     sp_own = self.steem.vests_to_sp(own, timestamp=ts)
     sp_eff = sp_own + sp_in - sp_out
     return {
         "timestamp": ts,
         "vests": own,
         "delegated_vests_in": din,
         "delegated_vests_out": dout,
         "sp_own": sp_own,
         "sp_eff": sp_eff,
         "steem": steem,
         "sbd": sbd,
         "index": index
     }
示例#6
0
 def reset(self):
     """ Resets the arrays not the stored account history
     """
     self.own_vests = [
         Amount(0, self.steem.vests_symbol, steem_instance=self.steem)
     ]
     self.own_steem = [
         Amount(0, self.steem.steem_symbol, steem_instance=self.steem)
     ]
     self.own_sbd = [
         Amount(0, self.steem.sbd_symbol, steem_instance=self.steem)
     ]
     self.delegated_vests_in = [{}]
     self.delegated_vests_out = [{}]
     self.timestamps = [addTzInfo(datetime(1970, 1, 1, 0, 0, 0, 0))]
     import beembase.operationids
     self.ops_statistics = beembase.operationids.operations.copy()
     for key in self.ops_statistics:
         self.ops_statistics[key] = 0
     self.reward_timestamps = []
     self.author_rewards = []
     self.curation_rewards = []
     self.curation_per_1000_SP_timestamp = []
     self.curation_per_1000_SP = []
     self.out_vote_timestamp = []
     self.out_vote_weight = []
     self.in_vote_timestamp = []
     self.in_vote_weight = []
     self.in_vote_rep = []
     self.in_vote_rshares = []
     self.vp = []
     self.vp_timestamp = []
     self.rep = []
     self.rep_timestamp = []
示例#7
0
    def __init__(self,
                 account,
                 path,
                 trxStorage,
                 transactionStorage,
                 transactionOutStorage,
                 member_data,
                 memberStorage=None,
                 steem_instance=None):
        self.steem = steem_instance or shared_steem_instance()
        self.account = Account(account, steem_instance=self.steem)
        self.delegated_vests_in = {}
        self.delegated_vests_out = {}
        self.timestamp = addTzInfo(datetime(1970, 1, 1, 0, 0, 0, 0))
        self.path = path
        self.member_data = member_data
        self.memberStorage = memberStorage
        self.memo_parser = MemoParser(steem_instance=self.steem)
        self.excluded_accounts = [
            "minnowbooster", "smartsteem", "randowhale", "steemvoter",
            "jerrybanfield", "boomerang", "postpromoter", "appreciator",
            "buildawhale", "upme", "smartmarket", "minnowhelper", "pushup",
            "steembasicincome", "sbi2", "sbi3", "sbi4", "sbi5", "sbi6", "sbi7",
            "sbi8", "sbi9"
        ]

        self.trxStorage = trxStorage
        self.transactionStorage = transactionStorage
        self.transactionOutStorage = transactionOutStorage
示例#8
0
    def update_account_feed(self):
        if self.hist_account is None:
            return
        try:
            updated_feed = self.hist_account.get_account_posts()
        except:
            print("could not update feed")
            return
        if len(self.feed) == 0:
            self.feed = updated_feed
        else:
            for post in updated_feed[::-1]:
                found = False
                for p in self.feed:
                    if post["authorperm"] == p["authorperm"]:
                        found = True
                if not found:
                    self.feed.insert(0, post)
                    if (addTzInfo(datetime.utcnow()) - post["created"]).total_seconds() / 60 < 5:
                        self.tray.showMessage(post["author"], post["title"])
        with self.updateLock:
            if self.post is None:
                self.post = self.feed[0]
                self.triggeredPreview()

            self.feedListWidget.currentRowChanged.disconnect(self.change_displayed_post)
            self.feedListWidget.clear()
            for post in self.feed[::-1]:
                post_text = "%s - %s" % (post["author"], post["title"])
                post_item = QListWidgetItem()
                post_item.setText(post_text)
                post_item.setToolTip(post["author"])
                self.feedListWidget.insertItem(0, post_item)   
            self.feedListWidget.currentRowChanged.connect(self.change_displayed_post, Qt.QueuedConnection)
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:]
示例#10
0
def get_wait_time(account):
    """Get the time (in seconds) required until the next comment can be posted.
    Only works for one 'queued' comment.
    """
    account.refresh()
    last_post_timedelta = addTzInfo(datetime.datetime.utcnow()) - account['last_post']
    return max(0, STEEM_MIN_REPLY_INTERVAL - last_post_timedelta.total_seconds())
示例#11
0
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:]
示例#12
0
 def get_ops(self,
             start=None,
             stop=None,
             use_block_num=True,
             only_ops=[],
             exclude_ops=[]):
     """ Returns ops in the given range"""
     if start is not None:
         start = addTzInfo(start)
     if stop is not None:
         stop = addTzInfo(stop)
     for op in self:
         if use_block_num and start is not None and isinstance(start, int):
             if op["block"] < start:
                 continue
         elif not use_block_num and start is not None and isinstance(
                 start, int):
             if op["index"] < start:
                 continue
         elif start is not None and isinstance(start,
                                               (datetime, date, time)):
             if start > formatTimeString(op["timestamp"]):
                 continue
         if use_block_num and stop is not None and isinstance(stop, int):
             if op["block"] > stop:
                 continue
         elif not use_block_num and stop is not None and isinstance(
                 stop, int):
             if op["index"] > stop:
                 continue
         elif stop is not None and isinstance(stop, (datetime, date, time)):
             if stop < formatTimeString(op["timestamp"]):
                 continue
         if exclude_ops and op["type"] in exclude_ops:
             continue
         if not only_ops or op["type"] in only_ops:
             yield op
示例#13
0
def analyze(account):
    """Analyze ACCOUNT for possible hack leftovers.

    """
    acc = Account(account.replace("@", ""))
    if acc['last_owner_update'] not in time_unset:
        days = (addTzInfo(datetime.utcnow()) - \
                acc['last_owner_update']).days
        last_update = "%s (%d days ago)" % (acc['last_owner_update'], days)
    else:
        last_update = "never"
    logger.info("Last owner update: %s" % (last_update))
    logger.info("Recovery account: @%s" % (acc['recovery_account']))

    # check if the account is currently powering down

    if acc['next_vesting_withdrawal'] not in time_unset:
        vests = acc['vesting_withdraw_rate']
        sp = acc.blockchain.vests_to_sp(vests.amount)
        logger.warning("Account is currently powering down:")
        logger.warning("Next vesting withdrawal: %s (~%.3f %s) at %s" %
                       (vests, sp, acc.blockchain.token_symbol,
                        acc['next_vesting_withdrawal']))
    else:
        logger.info("Account is not powering down.")

    # check for active withdraw vesting routes
    routes = acc.get_withdraw_routes()
    if len(routes):
        tbl = PrettyTable(['From', 'To', 'Percent', 'Auto-vest'])
        for route in routes:
            tbl.add_row([
                route['from_account'], route['to_account'],
                int(route['percent']) / STEEM_1_PERCENT, route['auto_vest']
            ])
        logger.warning("Account has withdraw routes set:\n" + str(tbl))
    else:
        logger.info("Account has no withdraw routes set")

    bc = Blockchain()
    requests = bc.find_change_recovery_account_requests([account])
    if len(requests):
        logger.warning(
            "Request to change the recovery account to "
            "@%s, will be effective on: %s" %
            (requests[0]['recovery_account'], requests[0]['effective_on']))
    else:
        logger.info("No pending requests to change the recovery account")
示例#14
0
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
    }
示例#15
0
import numpy as np

VOTE_DUST_THRESHOLD = int(50e6)


def get_var_log_bins(nbins, minval, maxval):
    logmin = math.log10(minval)
    logmax = math.log10(maxval)
    binwidth = (logmax - logmin) / nbins
    return [
        float(math.pow(10, logmin + i * binwidth))
        for i in range(0, nbins + 1)
    ]


vote_start = addTzInfo(datetime(2018, 8, 1))
vote_end = addTzInfo(datetime(2018, 8, 8))
date = datetime(2018, 7, 25)

rshare_distribution_hf19 = []
rshares_per_day_hf19 = hist()
rshare_distribution_hf20 = []
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:
示例#16
0
        db.store_blocks(ops)
    else:
        print("loading db")

        start_op = db.get_last_op()
        print(start_op)
        data = db.read_missing_block_data(start_op)
        print("finished")
        if len(data) > 0:
            # print(op["timestamp"])
            for d in data:
                print(d)
            db.append_blocks(data)
    print("%d entries" % db.get_count())
    ops = db.load_blocks()
    last_op = {}
    last_op["index"] = -1
    last_op["timestamp"] = formatTimeString('2000-12-29T10:07:45')
    lastest_index = 0
    error_index = -1
    for op in ops[-1000:]:
        lastest_index += 1
        if (addTzInfo(op["timestamp"]) < addTzInfo(last_op["timestamp"])):
            if error_index < 0:
                error_index = lastest_index - 1
            print("error %s %s" % (formatTimeString(
                op["timestamp"]), formatTimeString(last_op["timestamp"])))
        last_op = op
    #if error_index > -1:
    #    store_account_hist(db_type, path, account_name, ops[:error_index])
示例#17
0
             zeros_trustscore += 1
         if "last_trust_score" not in f:
             f["last_trust_score"] = 0.0
         if "rank" not in f:
             f["rank"] = 0
         if "trust_score_norm" not in f:
             f["trust_score_norm"] = 0.0
         if "trust_score_n" not in f:
             f["trust_score_n"] = 0.0
         if "created_at" not in f:
             f["created_at"] = None
         elif latest_created is None:
             latest_created = f["created_at"]
             latest_block_num = f["block_num"]
         elif isinstance(f["created_at"], str):
             if addTzInfo(latest_created) < formatTimeString(f["created_at"]):
                 latest_created = formatTimeString(f["created_at"]).replace(tzinfo=None)
             f["created_at"] = formatTimeString(f["created_at"]).replace(tzinfo=None)
             print(f["name"])
         if f["created_at"] is not None and latest_created < f["created_at"]:
             latest_created = f["created_at"]
             latest_block_num = f["block_num"]            
         accounts[f["name"]] = f     
         cnt += 1
         if cnt % 100000 == 0:
             print(cnt)
     print("account with zero trustscore %d" % zeros_trustscore)
     print("latest created %s" % str(latest_created))
 else:
     accounts = account2TrxStorage.get_accounts()
 
示例#18
0
            if member_data[m]["shares"] <= 0:
                empty_shares.append(m)
                member_data[m]["total_share_days"] = 0
                member_data[m]["avg_share_age"] = 0
                continue
            member_data[m].calc_share_age()
            if latest_enrollment is None:
                latest_enrollment = member_data[m]["latest_enrollment"]
            elif latest_enrollment < member_data[m]["latest_enrollment"]:
                latest_enrollment = member_data[m]["latest_enrollment"]
        
        print("latest data timestamp: %s - latest member enrollment %s" % (str(latest_data_timestamp), str(latest_enrollment)))
        
        # date_now = datetime.utcnow()
        date_now = latest_enrollment
        date_7_before = addTzInfo(date_now - timedelta(seconds=7 * 24 * 60 * 60))
        date_28_before = addTzInfo(date_now - timedelta(seconds=28 * 24 * 60 * 60))
        if new_cycle:
            
            for m in member_data:
                if member_data[m]["shares"] <= 0:
                    continue
                if "first_cycle_at" not  in member_data[m]:
                    member_data[m]["first_cycle_at"] = current_cycle
                elif member_data[m]["first_cycle_at"] < datetime(2000, 1 , 1, 0, 0, 0):
                    member_data[m]["first_cycle_at"] = current_cycle
                member_data[m]["balance_rshares"] += (member_data[m]["shares"] * rshares_per_cycle) + (member_data[m]["bonus_shares"] * del_rshares_per_cycle)
                member_data[m]["earned_rshares"] += (member_data[m]["shares"] * rshares_per_cycle) + (member_data[m]["bonus_shares"] * del_rshares_per_cycle)
                member_data[m]["subscribed_rshares"] += (member_data[m]["shares"] * rshares_per_cycle)
                member_data[m]["delegation_rshares"] += (member_data[m]["bonus_shares"] * del_rshares_per_cycle)
示例#19
0
s = shelve.open(sys.argv[1])
posts = s['posts']
s.close()

authors = set()
root_authors = set()
comment_authors = set()

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']])
示例#20
0
         member_data_list = []
         for m in member_data:
             member_data_list.append(member_data[m])
         memberStorage.add_batch(member_data_list)
         member_data_list = []
     cnt2 += 1
 try:
     c = Comment(authorperm, steem_instance=stm)
 except:
     continue
 cnt3 = 0
 for vote in c["active_votes"]:
     cnt3 += 1
     if int(vote["rshares"]) == 0:
         continue
     if (addTzInfo(datetime.utcnow()) - (vote["time"])
         ).total_seconds() / 60 / 60 / 24 <= 7:
         continue
     if vote["voter"] not in member_data:
         continue
     if authorperm in comments_transfer and stm.rshares_to_sbd(
             int(vote["rshares"])) >= 0.05:
         try:
             if cnt3 % 10 == 0:
                 print("%d/%d votes" %
                       (cnt3, len(c["active_votes"])))
             block_num = b.get_estimated_block_num(
                 vote["time"])
             current_block_num = b.get_current_block_num()
             transaction = None
             block_search_list = [
示例#21
0
    def update_account_hist(self):
        if self.hist_account is None:
            return
        votes = []
        daily_curation = 0
        daily_author_SP = 0
        daily_author_SBD = 0
        daily_author_STEEM = 0
        self.append_account_hist()

        new_op_found = False

        start_block = self.account_hist_info["start_block"]
        if start_block == 0:
            first_call = True
        else:
            first_call = False
        trx_ids = self.account_hist_info["trx_ids"]

        for op in self.account_history:
            if op["block"] < start_block:
                # last_block = op["block"]
                continue
            elif op["block"] == start_block:
                if op["trx_id"] in trx_ids:
                    continue
                else:
                    trx_ids.append(op["trx_id"])
            else:
                trx_ids = [op["trx_id"]]
            start_block = op["block"]
            new_op_found = True
            op_timedelta = formatTimedelta(
                addTzInfo(datetime.utcnow()) -
                formatTimeString(op["timestamp"]))
            op_local_time = formatTimeString(op["timestamp"]).astimezone(
                tz.tzlocal())
            # print("Read %d" % op["index"])
            if op["type"] == "vote":
                if op["voter"] == self.hist_account["name"]:
                    continue
                if op["weight"] >= 0:

                    self.lastUpvotesListWidget.insertItem(
                        0, "%s - %s (%.2f %%) upvote %s" %
                        (op_timedelta, op["voter"], op["weight"] / 100,
                         op["permlink"]))
                    hist_item = "%s - %s - %s (%.2f %%) upvote %s" % (
                        op_local_time, op["type"], op["voter"],
                        op["weight"] / 100, op["permlink"])
                    tray_item = "%s - %s (%.2f %%) upvote %s" % (
                        op["type"], op["voter"], op["weight"] / 100,
                        op["permlink"])
                else:
                    hist_item = "%s - %s - %s (%.2f %%) downvote %s" % (
                        op_local_time, op["type"], op["voter"],
                        op["weight"] / 100, op["permlink"])
                    tray_item = "%s - %s (%.2f %%) downvote %s" % (
                        op["type"], op["voter"], op["weight"] / 100,
                        op["permlink"])

                self.accountHistListWidget.insertItem(0, hist_item)
            elif op["type"] == "curation_reward":
                curation_reward = self.stm.vests_to_sp(
                    Amount(op["reward"], steem_instance=self.stm))
                self.lastCurationListWidget.insertItem(
                    0, "%s - %.3f HP for %s" %
                    (op_timedelta, curation_reward,
                     construct_authorperm(op["comment_author"],
                                          op["comment_permlink"])))
                hist_item = "%s - %s - %.3f HP for %s" % (
                    op_local_time, op["type"], curation_reward,
                    construct_authorperm(op["comment_author"],
                                         op["comment_permlink"]))
                tray_item = "%s - %.3f HP for %s" % (
                    op["type"], curation_reward,
                    construct_authorperm(op["comment_author"],
                                         op["comment_permlink"]))
                self.accountHistListWidget.insertItem(0, hist_item)
            elif op["type"] == "author_reward":
                sbd_payout = (Amount(op["sbd_payout"],
                                     steem_instance=self.stm))
                steem_payout = (Amount(op["steem_payout"],
                                       steem_instance=self.stm))
                sp_payout = self.stm.vests_to_sp(
                    Amount(op["vesting_payout"], steem_instance=self.stm))
                self.lastAuthorListWidget.insertItem(
                    0, "%s - %s %s %.3f HP for %s" %
                    (op_timedelta, str(sbd_payout), str(steem_payout),
                     sp_payout, op["permlink"]))
                hist_item = "%s - %s - %s %s %.3f SP for %s" % (
                    op_local_time, op["type"], str(sbd_payout),
                    str(steem_payout), sp_payout, op["permlink"])
                tray_item = "%s - %s %s %.3f SP for %s" % (
                    op["type"], str(sbd_payout), str(steem_payout), sp_payout,
                    op["permlink"])
                self.accountHistListWidget.insertItem(0, hist_item)
            elif op["type"] == "custom_json":
                hist_item = "%s - %s - %s" % (op_local_time, op["type"],
                                              op["id"])
                tray_item = "%s - %s" % (op["type"], op["id"])
                self.accountHistListWidget.insertItem(0, hist_item)
            elif op["type"] == "transfer":
                hist_item = "%s - %s - %s from %s" % (
                    op_local_time, op["type"],
                    str(Amount(op["amount"],
                               steem_instance=self.stm)), op["from"])
                tray_item = "%s - %s from %s" % (
                    op["type"],
                    str(Amount(op["amount"],
                               steem_instance=self.stm)), op["from"])
                self.accountHistListWidget.insertItem(0, hist_item)
            elif op["type"] == "comment":
                comment_type = "post"
                if op["parent_author"] != "":
                    hist_item = "%s - comment on %s - %s from %s" % (
                        op_local_time,
                        construct_authorperm(
                            op["parent_author"],
                            op["parent_permlink"]), op["title"], op["author"])
                    tray_item = "comment from %s: %s on %s" % (
                        op["author"], op["body"][:100], op["title"])
                else:
                    hist_item = "%s - post - %s from %s" % (
                        op_local_time, op["title"], op["author"])
                    tray_item = "post from %s: %s" % (op["author"],
                                                      op["title"])
                self.accountHistListWidget.insertItem(0, hist_item)
            else:
                hist_item = "%s - %s" % (op_local_time, op["type"])
                tray_item = "%s" % (op["type"])
                self.accountHistListWidget.insertItem(0, hist_item)

            if self.accountHistNotificationCheckBox.isChecked(
            ) and not first_call:
                self.tray.showMessage(self.hist_account["name"], tray_item)

        if new_op_found:
            self.account_hist_info["start_block"] = start_block
            self.account_hist_info["trx_ids"] = trx_ids

            for op in self.account_history:
                if op["type"] == "vote":
                    if op["voter"] == self.hist_account["name"]:
                        continue
                    votes.append(op)
                elif op["type"] == "curation_reward":
                    curation_reward = self.stm.vests_to_sp(
                        Amount(op["reward"], steem_instance=self.stm))
                    daily_curation += curation_reward
                elif op["type"] == "author_reward":
                    sbd_payout = (Amount(op["sbd_payout"],
                                         steem_instance=self.stm))
                    steem_payout = (Amount(op["steem_payout"],
                                           steem_instance=self.stm))
                    sp_payout = self.stm.vests_to_sp(
                        Amount(op["vesting_payout"], steem_instance=self.stm))
                    daily_author_SP += sp_payout
                    daily_author_STEEM += float(steem_payout)
                    daily_author_SBD += float(sbd_payout)

            reward_text = "Curation reward (last 24 h): %.3f HP\n" % daily_curation
            reward_text += "Author reward (last 24 h):\n"
            reward_text += "%.3f HP - %.3f HIVE - %.3f HBD" % (
                daily_author_SP, (daily_author_STEEM), (daily_author_SBD))
            self.text2.setText(reward_text)
import sys
import shelve
from datetime import datetime

created = []
reputation = []
effective_sp = []
own_sp = []
posts = []
creator = hist()
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))
from beem.account import Account
from beem.comment import Comment
from beem.utils import addTzInfo, construct_authorperm, parse_time
from datetime import datetime
import sys
import shelve

start = addTzInfo(datetime(2018, 6, 10))
stop = addTzInfo(datetime(2018, 6, 12))
hist_start = addTzInfo(datetime(2018, 6, 18))

a = Account("steem")
created_accounts = set()
for op in a.history(start=start, stop=stop,
                    only_ops=['account_create_with_delegation']):
    sys.stdout.write("%s\r" % (op['timestamp']))
    name = op['new_account_name']
    created_accounts |= set([name])

print("\n", len(created_accounts))

known_accs = set()
with open("alike_names_zoomed.txt") as f:
    for line in f.readlines():
        if line.endswith("\n"):
            line = line[:-1]
        known_accs |= set([line])

created_accounts = created_accounts - known_accs
print(len(created_accounts))
#!/usr/bin/python
import shelve
from beem import Steem
from beem.utils import addTzInfo
from datetime import datetime
from nltk import edit_distance

LIMIT = 100
MAX_EDIT_DISTANCE = 2
MIN_LAST_VOTE_TIME = addTzInfo(datetime(2018, 6, 20))

stm = Steem(offline=True)

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

all_names = set([a for a in accounts.keys() if len(a) > (MAX_EDIT_DISTANCE + 2)])
top_accounts = set()
print("By effective VESTS")
idx = 0
for name in sorted(accounts, key=lambda k:
                   accounts[k]['effective_vests'], reverse=True)[:LIMIT]:
    if len(name) <= MAX_EDIT_DISTANCE + 2:
        continue
    print("%d: %16s %.2f MVEST" % (idx, name,
                                   accounts[name]['effective_vests']/1e6))
    top_accounts |= set([name])
    idx += 1

print("By STEEM balance")
示例#25
0
from beem.utils import addTzInfo
from beemgraphenebase.account import PasswordKey, PrivateKey, PublicKey
from beembase import operations
from beem.account import Account
from beem.constants import STEEM_1_PERCENT
from prettytable import PrettyTable
from getpass import getpass
from datetime import datetime

# map input to raw_input for Python2
if hasattr(__builtins__, 'raw_input'):
    input = raw_input

verbosities = ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG']
time_unset = [
    addTzInfo(datetime.utcfromtimestamp(0)),
    addTzInfo(datetime.utcfromtimestamp(-1))
]


def passwordkey_to_key(passwordkey, account, role, prefix="STM"):
    """ Get a private key from an input that may be a key or a master
    password.

    :param str passwordkey: Key or master password to check/transform.
    :param str account: Account name the key is for.
    :param str role: Role of the key (posting, active, owner, memo)
    :param str prefix: Network prefix (default: "STM")

    """
    try:
    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)
    
    
    blocks_per_day = 20 * 60 * 24

    start_block = accountTrx.get_latest_block_num()
    
    if start_block is None:
        start_block = b.get_estimated_block_num(addTzInfo(start_time))
        # block_id_list = []
        trx_id_list = []
    else:
        trx_id_list = accountTrx.get_block_trx_id(start_block)
    # end_block = current_block["id"] 
    end_block = current_block["id"] - (20 * 10)
    if end_block > start_block + 6000:
        end_block = start_block + 6000
    
    print("Checking member upvotes from %d to %d" % (start_block, end_block))
    
    date_now = datetime.utcnow()
    date_7_before = addTzInfo(date_now - timedelta(seconds=7 * 24 * 60 * 60))
    date_28_before = addTzInfo(date_now - timedelta(seconds=28 * 24 * 60 * 60))
    date_72h_before = addTzInfo(date_now - timedelta(seconds=72 * 60 * 60))    
示例#27
0
def benchmark_block_diff(node,
                         num_retries=10,
                         num_retries_call=10,
                         timeout=60):
    block_count = 0
    history_count = 0
    access_time = timeout
    follow_time = 0
    sucessfull = False
    error_msg = None
    start_total = timer()
    block_diff = 0
    block_head_diff = 0
    try:
        stm = Steem(node=node,
                    num_retries=num_retries,
                    num_retries_call=num_retries_call,
                    timeout=timeout)

        b = Blockchain(steem_instance=stm)
        b_head = Blockchain(mode="head", steem_instance=stm)
        dhi_max = 0
        head_max = timedelta(0)
        for i in range(0, 5):
            utcnow = addTzInfo(datetime.utcnow())
            df_head = addTzInfo(
                datetime.utcnow()) - b_head.get_current_block()["timestamp"]
            diff_value = b_head.get_current_block_num(
            ) - b.get_current_block_num()
            if diff_value > dhi_max:
                dhi_max = diff_value
            if df_head > head_max:
                head_max = df_head

            time.sleep(3)

        block_head_diff = head_max.total_seconds()
        block_diff = dhi_max
        sucessfull = True
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        sucessfull = False
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        # quit = True
    except Exception as e:
        error_msg = str(e)
        sucessfull = False
    total_duration = float("{0:.2f}".format(timer() - start_total))
    block_diff = float("{0:.2f}".format(block_diff))
    block_head_diff = float("{0:.2f}".format(block_head_diff))
    return {
        'sucessfull': sucessfull,
        'node': node,
        'error': error_msg,
        'total_duration': total_duration,
        'access_time': None,
        'count': None,
        'diff_head_irreversible': block_diff,
        'head_delay': block_head_diff
    }
示例#28
0
 def test_formatTimeString(self):
     t = "2018-07-10T10:08:39"
     t = formatTimeString(t)
     t2 = addTzInfo(datetime(2018, 7, 10, 10, 8, 39))
     self.assertEqual(t, t2)
示例#29
0
                    except:
                        op_dict = op["op_dict"]
                        comment = json.loads(op_dict[:op_dict.find("body") -
                                                     3] + '}')
                    try:
                        comment = Comment(comment, steem_instance=stm)
                        comment.refresh()
                        created = comment["created"]
                    except:
                        continue
                    if comment.is_pending():
                        continue
                    if comment["author"] != account["name"]:
                        continue

                    if comment["parent_author"] == "" and created > addTzInfo(
                            last_paid_post):
                        print("add post %s" % comment["authorperm"])
                        blog.append(comment["authorperm"])
                    elif comment["parent_author"] != "" and created > addTzInfo(
                            last_paid_comment):
                        print("add comment %s" % comment["authorperm"])
                        posts.append(comment["authorperm"])

                post_rshares = 0
                for authorperm in blog:
                    post = Comment(authorperm, steem_instance=stm)
                    if post["created"] > addTzInfo(new_paid_post):
                        new_paid_post = post["created"].replace(tzinfo=None)
                    last_paid_post = post["created"].replace(tzinfo=None)
                    all_votes = ActiveVotes(post["authorperm"])
                    for vote in all_votes:
示例#30
0
            start_block = 1091
            trx_id_list = []
        else:
            start_block = blockTrxStorage.get_latest_block_num()
            trx_id_list = blockTrxStorage.get_block_trx_id(start_block)
        if start_block is None:
            start_block = 1091
            trx_id_list = []
        end_block = b.get_current_block_num()
        end_block_round = int(start_block) + blocks_per_day - 1

        cnt = 0
        sb = Block(start_block, steem_instance=stm)
        print("start: %d - %s" % (start_block, str(sb["timestamp"])))
        end_date = datetime(sb["timestamp"].year, sb["timestamp"].month, sb["timestamp"].day, 23, 59, 50) + timedelta(seconds = 60 * 60 * 24)
        if (addTzInfo(end_date) - sb["timestamp"]).total_seconds() / 60 / 60 / 24 > 1.1:
            end_date = datetime(sb["timestamp"].year, sb["timestamp"].month, sb["timestamp"].day, 23, 59, 50)
        #end_block_round = b.get_estimated_block_num(end_date) - 1
        print("end: %d - %s" % (end_block_round, str(end_date)))
        next_account_id = accountTrxStorage.get_latest_index() + 1
        
        if end_block_round > end_block:
            end_block_round = end_block
            data_available = False
        db_data = []
        db_account = []
        db_follow = []
        accounts = accountTrxStorage.get_accounts()
        last_block_num = None
        new_accounts_found = 0
        new_follow_found = 0