def test_blockchain(self): bts = self.bts b = Blockchain(steem_instance=bts) num = b.get_current_block_num() self.assertTrue(num > 0) self.assertTrue(isinstance(num, int)) block = b.get_current_block() self.assertTrue(isinstance(block, Block)) self.assertTrue((num - block.identifier) < 3) block_time = b.block_time(block.identifier) self.assertEqual(block.time(), block_time) block_timestamp = b.block_timestamp(block.identifier) timestamp = int(time.mktime(block.time().timetuple())) self.assertEqual(block_timestamp, timestamp)
def test_estimate_block_num(self): bts = self.bts b = Blockchain(steem_instance=bts) last_block = b.get_current_block() num = last_block.identifier old_block = Block(num - 60, steem_instance=bts) date = old_block.time() est_block_num = b.get_estimated_block_num(date, accurate=False) self.assertTrue((est_block_num - (old_block.identifier)) < 10) est_block_num = b.get_estimated_block_num(date, accurate=True) self.assertTrue((est_block_num - (old_block.identifier)) < 2) est_block_num = b.get_estimated_block_num(date, estimateForwards=True, accurate=True) self.assertTrue((est_block_num - (old_block.identifier)) < 2) est_block_num = b.get_estimated_block_num(date, estimateForwards=True, accurate=False)
owner_privkey = owner_key.get_private_key() memo_privkey = memo_key.get_private_key() if useWallet: stm.wallet.addPrivateKey(owner_privkey) stm.wallet.addPrivateKey(active_privkey) stm.wallet.addPrivateKey(memo_privkey) stm.wallet.addPrivateKey(posting_privkey) else: stm = Steem(node=testnet_node, wif={'active': str(active_privkey), 'posting': str(posting_privkey), 'memo': str(memo_privkey)}) account = Account(username, steem_instance=stm) if account["name"] == "beem": account.disallow("beem1", permission='posting') account.allow('beem1', weight=1, permission='posting', account=None) account.follow("beem1") elif account["name"] == "beem5": account.allow('beem4', weight=2, permission='active', account=None) if useWallet: stm.wallet.getAccountFromPrivateKey(str(active_privkey)) # stm.create_account("beem1", creator=account, password=password1) account1 = Account("beem1", steem_instance=stm) b = Blockchain(steem_instance=stm) blocknum = b.get_current_block().identifier account.transfer("beem1", 1, "SBD", "test") b1 = Block(blocknum, steem_instance=stm)
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 }
table.upsert( { "id": 1, "last_steem_block_num": latest_block_num }, ["id"]) table = connection["transactions"] if trx_entry is None: # print("Zero transaction found") #block = b.get_current_block() #date = block['timestamp'].replace(tzinfo=None) table = connection["blocks"] current_block = table.find_one(order_by='-block_num') if current_block is None or ( 'timestamp' in current_block and current_block['timestamp'] is None): current_block = b.get_current_block() date = current_block['timestamp'].replace(tzinfo=None) else: date = current_block['timestamp'].replace(tzinfo=None) table = connection["virtualops"] if last_vops_count_check is not None and ( date - last_vops_count_check).total_seconds( ) < 6 and date > datetime(2019, 8, 2, 13, 38, 0): vops_count = 0 else: start_time = time.time() vops_count = table.count(tr_status=0, trigger_date={'<=': date}) print("vops count took %.2f s" % (time.time() - start_time))
except exceptions.ContentDoesNotExistsException: print("Could not find Comment: %s" % (authorperm)) al = list() if not vote_event["voter"] in self.looked_up: al.append(vote_event["voter"]) self.looked_up.add(vote_event["voter"]) if not vote_event["author"] in self.looked_up: al.append(vote_event["author"]) self.looked_up.add(vote_event["author"]) if len(al) > 0: lookup_accounts(al) if __name__ == "__main__": wtw = WatchingTheWatchers() tb = WatchingTheWatchersBot(wtw) blockchain = Blockchain() threading = True thread_num = 16 cur_block = blockchain.get_current_block() stop = cur_block.identifier startdate = cur_block.time() - timedelta(days=1) start = blockchain.get_estimated_block_num(startdate, accurate=True) for vote in blockchain.stream(opNames=["vote"], start=start, stop=stop, threading=threading, thread_num=thread_num): tb.vote(vote) wtw.report()