def main(): accounts = [] votes_db = pickledb.load('steem_account_votes.db', False) comments_db = pickledb.load('steem_account_comments.db', False) transfers_db = pickledb.load('steem_account_trasnfers.db', False) vesting_transfers_db = pickledb.load('steem_account_vesting_transfers.db', False) result_db = pickledb.load('result.db', False) steemd = Steem(STEEM_NODES) chain = Blockchain(steemd_instance = steemd, mode = 'head') logging.getLogger().setLevel(20) databases = {'account_create': accounts, 'vote': votes_db, 'comment': comments_db, 'transfer': transfers_db, 'transfer_to_vesting': vesting_transfers_db} fill(databases, chain, round((1497970800 - 1451606400) / 3), chain.info()['head_block_number']) votes_db.dump() comments_db.dump() transfers_db.dump() vesting_transfers_db.dump() analyze(databases, result_db) result_db.dump()
def worth_sp(self): s = get_steem_conn() b = Blockchain() p = 10000 sp = self.total_sp # steem power vp = 100 # voting power vw = 100 # voting weight tvf = float(b.info()['total_vesting_fund_steem'].replace(" STEEM", "")) tvs = float(b.info()['total_vesting_shares'].replace(" VESTS", "")) r = float(sp / (tvf / tvs)) m = float(100 * vp * (100 * vw) / p) m = float((m + 49) / 50) quote = float(s.get_current_median_history_price()['quote'].replace( " STEEM", "")) base = float(s.get_current_median_history_price()['base'].replace( " SBD", "")) o = base / quote rb = float( s.get_reward_fund('post')['reward_balance'].replace(" STEEM", "")) rc = float(s.get_reward_fund('post')['recent_claims']) i = rb / rc return "%.4f" % (r * m * 100 * i * o)
def run(): global start_block_num steemd_nodes = [ steemd_url, ] s = Steemd(nodes=steemd_nodes) b = Blockchain(s) while True: head_block_number = b.info()['head_block_number'] end_block_num = int(head_block_number) if start_block_num == 0: start_block_num = end_block_num - 3 if start_block_num >= end_block_num: continue with futures.ThreadPoolExecutor(max_workers=worker_num) as executor: executor.submit(worker, start_block_num, end_block_num) start_block_num = end_block_num + 1
def main(): account_db = pickledb.load("steem_accounts.db", False) votes_db = pickledb.load('steem_account_votes.db', False) post_votes_db = pickledb.load('steemt_post_votes.db', False) comments_db = pickledb.load('steem_account_comments.db', False) transfers_db = pickledb.load('steem_account_trasnfers.db', False) transfer_memos_db = pickledb.load('steem_account_trasnfer_memos.db', False) vesting_transfers_db = pickledb.load('steem_account_vesting_transfers.db', False) result_db = pickledb.load('result.db', False) steemd = Steem(STEEM_NODES) chain = Blockchain(steemd_instance=steemd, mode='head') logging.getLogger().setLevel(20) databases = { 'account_create': account_db, 'vote': votes_db, 'vote_post': post_votes_db, 'comment': comments_db, 'transfer': transfers_db, 'transfer_memos': transfer_memos_db, 'transfer_to_vesting': vesting_transfers_db } fill(databases, chain, first_block=1, last_block=chain.info()['head_block_number']) account_db.dump() votes_db.dump() post_votes_db.dump() comments_db.dump() transfers_db.dump() transfer_memos_db.dumo() vesting_transfers_db.dump() analyze(databases, result_db) result_db.dump()
def run(): global start_block_num steemd_nodes = [ 'https://rpc.buildteam.io', 'https://api.steemit.com', ] s = Steemd(nodes=steemd_nodes) b = Blockchain(s) while True: head_block_number = b.info()['head_block_number'] end_block_num = int(head_block_number) if start_block_num == 0: start_block_num = end_block_num - 3 if start_block_num >= end_block_num: continue with futures.ThreadPoolExecutor(max_workers=worker_num) as executor: executor.submit(worker, start_block_num, end_block_num) start_block_num = end_block_num + 1 time.sleep(3)
def run(self): steemd_nodes = [ 'https://api.steemit.com', ] s = Steemd(nodes=steemd_nodes) b = Blockchain(s) while True: head_block_number = b.info()['head_block_number'] end_block_num = int(head_block_number) start_block_num = end_block_num - 1 block_infos = s.get_blocks(range(start_block_num, end_block_num)) print('start from {start} to {end}'.format(start=start_block_num, end=end_block_num)) for block_info in block_infos: transactions = block_info['transactions'] for trans in transactions: operations = trans['operations'] self.data.put(operations) time.sleep(3)
def run(): global start_block_num steemd_nodes = [ steemd_url, ] s = Steemd(nodes=steemd_nodes) b = Blockchain(s) create_db() create_table() connect_db() start_block_num_from_db = get_start_num_from_db() if start_block_num_from_db != 0: start_block_num = start_block_num_from_db while True: head_block_number = b.info()['head_block_number'] end_block_num = int(head_block_number) if start_block_num == 0: start_block_num = end_block_num - 3 if start_block_num >= end_block_num: continue if end_block_num - start_block_num >= 50: while start_block_num < end_block_num: tmp_end_block_num = start_block_num + 50 if tmp_end_block_num > end_block_num: tmp_end_block_num = end_block_num with futures.ThreadPoolExecutor( max_workers=worker_num) as executor: executor.submit(worker, start_block_num, tmp_end_block_num) start_block_num = tmp_end_block_num + 1 else: with futures.ThreadPoolExecutor( max_workers=worker_num) as executor: executor.submit(worker, start_block_num, end_block_num) start_block_num = end_block_num + 1
def blockchain_data(): blockchain = Blockchain() return blockchain.info()
class Voter: def __init__(self, steem, account): self.db = DB('curangel.sqlite3') steem = Steem(nodes=steemd_nodes) self.chain = Blockchain(steem) self.steem = steem self.account = account def _get_account(self): return self.steem.get_account(self.account) def get_current_vp(self, includeWaste=False): account = self._get_account() base_vp = account["voting_power"] timestamp_fmt = "%Y-%m-%dT%H:%M:%S" base_time = datetime.datetime.strptime(account["last_vote_time"], timestamp_fmt) since_vote = (datetime.datetime.utcnow() - base_time).total_seconds() vp_per_second = 1 / VP_TICK_SECONDS current_power = since_vote * vp_per_second + base_vp if not includeWaste and current_power > MAX_VP: current_power = MAX_VP return current_power def get_recharge_time(self, allowNegative=False): current_power = self.get_current_vp(True) remaining_ticks = MAX_VP - current_power seconds_to_full = remaining_ticks * VP_TICK_SECONDS if not allowNegative and seconds_to_full < 0: seconds_to_full = 0 return datetime.timedelta(seconds=seconds_to_full) def next_in_queue(self, steem): results = self.db.select('upvotes', ['id,link'], {'status': 'in queue'}, 'created ASC', '1') if len(results) > 0: link = results[0]['link'].split('#') if len(link) > 1: link = link[1].split('/') else: link = results[0]['link'].split('/') uri = link[-2][1:] + '/' + link[-1] post = steem.get_content(link[-2][1:], link[-1]) # check payout time cashoutts = time.mktime( datetime.datetime.strptime(post['cashout_time'], "%Y-%m-%dT%H:%M:%S").timetuple()) chaints = time.mktime( datetime.datetime.strptime(self.chain.info()['time'], "%Y-%m-%dT%H:%M:%S").timetuple()) if cashoutts - chaints < 60 * 60 * 12: print( "\nskipping '{}' because payout is in less than 12 hours..." .format(results[0]['link'])) self.db.update( 'upvotes', {'status': 'skipped voting due to payout approaching'}, {'id': results[0]['id']}) return self.next_in_queue(steem) # check if author used bitbots bidbots = [ 'alfanso', 'appreciator', 'bdvoter', 'bid4joy', 'boomerang', 'booster', 'brandonfrye', 'buildawhale', 'edensgarden', 'inciter', 'joeparys', 'leo.voter', 'luckyvotes', 'minnowbooster', 'minnowhelper', 'minnowvotes', 'ocdb', 'onlyprofitbot', 'postpromoter', 'profitvote', 'promobot', 'qustodian', 'redlambo', 'rocky1', 'sct.voter', 'smartmarket', 'smartsteem', 'sneaky-ninja', 'sportsvoter', 'spydo', 'steemyoda', 'thebot', 'therising', 'tipu', 'treeplanter', 'triplea.bot', 'upmewhale', 'upmyvote', 'whalepromobot' ] postaccount = Account(post['author'], steem) history = postaccount.get_account_history(-1, 2500, filter_by='transfer') for h in history: if h['to'] in bidbots: if (h['to'] == 'minnowbooster' or h['to'] == 'tipu') and h['memo'][:4] != 'http': continue print( "\nskipping '{}' because author bought vote...".format( results[0]['link'])) self.db.update( 'upvotes', {'status': 'skipped voting due to vote buying'}, {'id': results[0]['id']}) return self.next_in_queue(steem) last = h['timestamp'] txts = time.mktime( datetime.datetime.strptime( h['timestamp'], "%Y-%m-%dT%H:%M:%S").timetuple()) chaints = time.mktime( datetime.datetime.strptime( self.chain.info()['time'], "%Y-%m-%dT%H:%M:%S").timetuple()) if chaints - txts > 60 * 60 * 24 * 7: break return uri, results[0]['id'] else: return False, False def calculate_vote_weight(self, id): results = self.db.select('upvotes', ['id'], {'status': 'in queue'}, 'created ASC', '9999') weight = MAX_VOTE_WEIGHT with QueueDBHelper('curangel.sqlite3') as qdbh: for result in results: if result['id'] != id: try: strength = qdbh.query_upvote_strength(result["id"]) except NoVoteStrengthError: strength = 1 diff = weight - (weight / (WEIGHT_FACTOR)) weight = weight - diff * strength strength = qdbh.query_upvote_strength(id) weight *= strength if weight < MIN_VOTE_WEIGHT: weight = MIN_VOTE_WEIGHT weight = int(weight) return float(weight / 100) def sendVote(self, uri, weight, id): last_vote_time = self._get_account()["last_vote_time"] try: self.steem.commit.vote(uri, weight, self.account) except: time.sleep(3) self.sendVote(uri, weight, id) else: self.db.update( 'upvotes', { 'status': 'voted with ' + str(weight) + '%', 'vote_time': datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') }, {'id': id}) while last_vote_time == self._get_account()["last_vote_time"]: # Block until the vote is reflected on the remote node. # This prevents double vote attempts. time.sleep(1) def vote(self, uri, id): weight = self.calculate_vote_weight(id) print("\nvoting '{}' with weight of {}...".format(uri, weight)) self.sendVote(uri, weight, id)
print(e) return 0 def parse(future): res = future.result() if res == 0: return print('Inserted %i operations from %s to %s' % (res['op_count'], res['start'], res['end'])) if __name__ == '__main__': with suppress(KeyboardInterrupt): #end_block_num = 5000 end_block_num = b.info()['last_irreversible_block_num'] print('end block num: %i' % end_block_num) p = ProcessPoolExecutor(worker_num) keep = True #start_block_num = 4950 start = start_block_num while keep: if start + step < end_block_num: future = p.submit(process, [start, start + step]) start = start + step else: future = p.submit(process, [start, end_block_num + 1]) keep = False future.add_done_callback(parse) p.shutdown(wait=True)
def get(): # get db config config = utils.get_config() db_c = config['steem_config'] # connect db db = pymysql.connect(host=db_c['host'], user=db_c['user'], password=db_c['pass'], database=db_c['db'], charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor, autocommit=True) # check lost block first result = checkLostBlockCache(db, config) # get synced head_block_num sql = 'select block_num from block_cache order by block_num desc limit 1' with db.cursor() as cur: cur.execute(sql) res = cur.fetchone() if res == None: print('no_block_cache') curr_cache_head = 0 else: curr_cache_head = int(res['block_num']) db.close() print('curr_cache_head: ', curr_cache_head) base_step = config['base_step'] # get lastest block_num steemd_nodes = [ 'https://api.steemit.com', 'https://rpc.buildteam.io', #'https://steemd.privex.io', #'https://rpc.steemviz.com', ] s = Steemd(nodes=steemd_nodes) b = Blockchain(s) head_block_number = int(b.info()['head_block_number']) print('blockchain_head', head_block_number) if head_block_number <= curr_cache_head: print('It is newest', head_block_number, latest_num) return [] start_num = curr_cache_head + 1 if head_block_number > start_num + 10000: end_num = start_num + 10000 else: end_num = head_block_number i = start_num while i <= end_num: tmp_end_num = i + base_step if tmp_end_num >= end_num: tmp_end_num = end_num result.append({ "task_type": "new_block", "content": range(i, tmp_end_num + 1) }) i = tmp_end_num + 1 return result