Exemple #1
0
 async def status_report(request):
     report = {
         'name': 'Hive Plug & Play',
         'sync': normalize_types(SystemStatus.get_sync_status()),
         'timestamp': datetime.utcnow().isoformat()
     }
     return web.json_response(status=200, data=report)
async def get_ops_by_block(context, block_num):
    """Returns a list of ops within the specified block number."""
    db = context['db']
    status = SystemStatus.get_sync_status()
    if not status: return [] # TODO: error handling/reporting
    latest = status['latest_block']
    if block_num > latest: return []
    return db.get_ops_by_block(block_num)
Exemple #3
0
 def _streamer(self):
     # start the stream
     while True:
         current_time = datetime.utcnow()
         if current_time > self._latest_block_time + timedelta(
                 seconds=(BLOCK_TIME_SECS * 10)):
             next_block = self._latest_block + 1
             block = self._fetch_block(next_block)
             self._add_block_to_cache(next_block, block[1])
             SystemStatus.set_sync_status(self._latest_block,
                                          self._latest_block_time,
                                          self.is_behind_schedule())
         if (self._latest_block_time +
                 timedelta(seconds=(BLOCK_TIME_SECS * 20))) < current_time:
             # catchup if behind
             self._fetch_dynamic_global_props()
             self._fetch_multiple_blocks((self._latest_block + 1),
                                         (self._hive_head_block))
         time.sleep(0.3)
Exemple #4
0
 def _feeder(self):
     block_to_push = self._start_block
     while True:
         while block_to_push not in self._cache:
             time.sleep(0.1)
         # check before pushing
         block = self._cache[block_to_push]
         if self._is_valid_block(block_to_push, block):
             self._prev_hash = block['block_id']
         else:
             print("Invalid block detected.")
             os._exit(1)  # TODO: replace with standby
         BlockProcessor.process_block(block_to_push,
                                      self._cache[block_to_push])
         self._latest_block = block_to_push
         self._latest_block_time = datetime.strptime(
             block['timestamp'], UTC_TIMESTAMP_FORMAT)
         SystemStatus.set_sync_status(self._latest_block,
                                      self._latest_block_time,
                                      self.is_behind_schedule())
         self._prune_block(block_to_push)
         block_to_push += 1
Exemple #5
0
 def subscribe(cls, community, block_range=None):
     """
         "subscribe"    | {"community":"hive-178179"}
     """
     if block_range is None:
         latest = SystemStatus.get_latest_block()
         if not latest: return None  # TODO: notify??
         block_range = [latest - 28800, latest]
     query = f"""
         SELECT *  
         FROM (
             SELECT req_posting_auths [1]
             FROM custom_json_ops
             WHERE op_id = 'community'
                 AND (op_json -> 0)::text = '"subscribe"'
                 AND block_num BETWEEN {block_range[0]} and {block_range[1]} 
         )AS subscribe_ops;
     """
     return query
Exemple #6
0
 def flag_post(cls,
               community=None,
               account=None,
               permlink=None,
               notes=None,
               block_range=None):
     """Populates query to retrieve `flagPost` ops"""
     if block_range is None:
         latest = SystemStatus.get_latest_block()
         if not latest: return None  # TODO: notify??
         block_range = [latest - 28800, latest]
     query = f"""
         SELECT *  
         FROM (
             SELECT req_posting_auths [1],
                 op_json -> 1 -> 'account'::text,
                 op_json -> 1 -> 'permlink'::text,
                 op_json -> 1 -> 'notes'::text
             FROM custom_json_ops
             WHERE op_id = 'community'
                 AND (op_json -> 0)::text = '"flagPost"'
                 AND block_num BETWEEN {block_range[0]} and {block_range[1]} 
     """
     if community:
         query += f"""
         AND (op_json -> 1 -> 'community'):: text = '"{community}"'
         """
     if account:
         query += f"""
         AND (op_json -> 1 -> 'account'):: text = '"{account}"'
         """
     if permlink:
         query += f"""
         AND (op_json -> 1 -> 'permlink'):: text = '"{permlink}"'
         """
     if notes:
         query += f"""
         AND (op_json -> 1 -> 'notes'):: text = '"{notes}"'
         """
     query += ")AS flag_post_ops;"
     return query
async def get_sync_status(context):
    return normalize_types(SystemStatus.get_sync_status())