Esempio n. 1
0
 def get(self, id=None, height=0, range=0, fields=None):
     database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     LOGGER.warn(
         "WorkerAPI_shares get id:{} height:{} range:{} fields:{}".format(
             id, height, range, fields))
     fields = lib.fields_to_list(fields)
     if height == 0:
         height = Blocks.get_latest().height
     shares_records = []
     if id is None:
         for shares in Worker_shares.get_by_height(height, range):
             shares_records.append(shares.to_json(fields))
         return shares_records
     else:
         if range is None:
             worker_sh_recs = Worker_shares.get_by_height_and_id(height, id)
             #print("worker_sh_recs = {}".format(worker_sh_recs))
             if res is None:
                 return "[]".to_json()
             return res.to_json(fields)
         else:
             for share in Worker_shares.get_by_height_and_id(
                     height, id, range):
                 shares_records.append(share.to_json(fields))
             return shares_records
Esempio n. 2
0
 def get(self, id=None, height=None, range=0, fields=None):
     global database
     #database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     # AUTH FILTER
     if id != g.user.id:
         response = jsonify({ 'message': 'Not authorized to access data for other users' })
         response.status_code = 403
         return response
     debug and LOGGER.warn("WorkerAPI_shares get id:{} height:{} range:{} fields:{}".format(id, height, range, fields))
     # Enforce range limit
     if range is not None:
         range = min(range, worker_shares_range_limit)
     fields = lib.fields_to_list(fields)
     if height is None:
         return Worker_shares.get_latest_height(id)
     if height == 0:
         height = Blocks.get_latest().height
     shares_records = []
     if id is None:
         for shares in Worker_shares.get_by_height(height, range):
             shares_records.append(shares.to_json(fields))
         return shares_records
     else:
         if range is None:
             worker_sh_recs = Worker_shares.get_by_height_and_id(height, id)
             #print("worker_sh_recs = {}".format(worker_sh_recs))
             if res is None:
                 return "[]".to_json()
             return res.to_json(fields)
         else:
             for share in Worker_shares.get_by_height_and_id(height, id, range):
                 shares_records.append(share.to_json(fields))
             return shares_records
Esempio n. 3
0
 def get(self, id, height=None, range=None, fields=None):
     global database
     #database = lib.get_db()
     # Enforce range limit
     if range is not None:
         range = min(range, worker_block_range_limit)
     fields = lib.fields_to_list(fields)
     # AUTH FILTER
     if id != g.user.id:
         response = jsonify({ 'message': 'Not authorized to access data for other users' })
         response.status_code = 403
         return response
     if height is None or height == 0:
         blocks = Pool_blocks.get_latest(range, id)
     else:
         blocks = Pool_blocks.get_by_height(height, range, id)
     if range == None:
         if blocks is None:
             return None
         return blocks.to_json(fields, True)
     else:
         bl = []
         for block in blocks:
             bl.append(block.to_json(fields, True))
         return bl
Esempio n. 4
0
 def get(self, id, range=None, fields=None):
     global database
     #database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     # AUTH FILTER
     if id != g.user.id:
         response = jsonify(
             {'message': 'Not authorized to access data for other users'})
         response.status_code = 403
         return response
     debug and LOGGER.warn(
         "WorkerAPI_payments get id:{} range:{} fields:{}".format(
             id, range, fields))
     # Enforce range limit
     if range is not None:
         range = min(range, worker_payment_record_range_limit)
     fields = lib.fields_to_list(fields)
     if range is None:
         payment_rec = Pool_payment.get_latest_by_userid(id)
         if payment_rec is None:
             return None
         return payment_rec.to_json(fields)
     else:
         payments = []
         for payment_rec in Pool_payment.get_latest_by_userid(id, range):
             payments.append(payment_rec.to_json(fields))
         return payments
Esempio n. 5
0
 def get(self, id=None, height=0, range=None, fields=None):
     database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     LOGGER.warn(
         "WorkerAPI_stats get id:{} height:{} range:{} fields:{}".format(
             id, height, range, fields))
     fields = lib.fields_to_list(fields)
     if height == 0:
         height = Blocks.get_latest().height
     stats = []
     if id is None:
         for stat in Worker_stats.get_by_height(height, range):
             #print("YYY: {}".format(stats))
             stats.append(stat.to_json(fields))
         return stats
     else:
         if range is None:
             res = Worker_stats.get_by_height_and_id(id, height)
             if res is None:
                 return "[]".to_json()
             return res.to_json(fields)
         else:
             for stat in Worker_stats.get_by_height_and_id(
                     id, height, range):
                 stats.append(stat.to_json(fields))
             return stats
Esempio n. 6
0
 def get(self, id=None, fields=None):
     database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     LOGGER.warn("WorkerAPI_payments get id:{} fields:{}".format(
         id, fields))
     fields = lib.fields_to_list(fields)
     utxo = Pool_utxo.get_by_address(id)
     return utxo.to_json(fields)
Esempio n. 7
0
 def get(self, height=0, range=None, fields=None):
     global database
     #database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     debug and LOGGER.warn("WorkersAPI_shares get height:{} range:{} fields:{}".format(height, range, fields))
     fields = lib.fields_to_list(fields)
     shares_records = []
     if height == 0:
         height = Blocks.get_latest().height
     for shares in Worker_shares.get_by_height(height, range):
         # AUTH FILTER
         if shares.user_id == g.user.id:
             shares_records.append(shares.to_json(fields))
     return shares_records
Esempio n. 8
0
 def get(self, height=None, range=None, fields=None):
     fields = lib.fields_to_list(fields)
     if height is None or height == 0:
         blocks = Pool_blocks.get_latest(range)
     else:
         blocks = Pool_blocks.get_by_height(height, range)
     if range == None:
         if blocks is None:
             return None
         return blocks.to_json(fields)
     else:
         bl = []
         for block in blocks:
             bl.append(block.to_json(fields))
         return bl
Esempio n. 9
0
 def get(self, id, fields=None):
     global database
     #database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     # AUTH FILTER
     if id != g.user.id:
         response = jsonify({ 'message': 'Not authorized to access data for other users' })
         response.status_code = 403
         return response
     debug and LOGGER.warn("WorkerAPI_utxo get id:{} fields:{}".format(id, fields))
     fields = lib.fields_to_list(fields)
     utxo = Pool_utxo.get_by_userid(id)
     if utxo is None:
         return None
     return utxo.to_json(fields)
Esempio n. 10
0
 def get(self, height=0, range=None, fields=None):
     database = lib.get_db()
     fields = lib.fields_to_list(fields)
     if height == 0:
         height = grin.get_current_height()
     if range == None:
         stat = Pool_stats.get_by_height(height)
         if stat is None:
             return None
         return stat.to_json(fields)
     else:
         stats = []
         for stat in Pool_stats.get_by_height(height, range):
             stats.append(stat.to_json(fields))
         return stats
Esempio n. 11
0
 def get(self, height=0, range=None, fields=None):
     database = lib.get_db()
     fields = lib.fields_to_list(fields)
     if height == 0:
         height = grin.get_current_height()
     if range == None:
         block = Blocks.get_by_height(height)
         if block is None:
             return None
         return block.to_json(fields)
     else:
         blocks = []
         for block in Blocks.get_by_height(height, range):
             blocks.append(block.to_json(fields))
         return blocks
Esempio n. 12
0
    def get(self, height=0, range=None, fields=None):
        global database
        #database = lib.get_db()
        LOGGER = lib.get_logger(PROCESS)
        LOGGER.warn("WorkersAPI_stats get height:{} range:{} fields:{}".format(
            height, range, fields))
        fields = lib.fields_to_list(fields)
        stats = []
        if height == 0:
            height = Blocks.get_latest().height
        for stat in Worker_stats.get_by_height(height, range):
            # AUTH FILTER
            if stat.user_id == ADMIN_ID:
                stats.append(stat.to_json(fields))

        return stats
Esempio n. 13
0
 def get(self, height=0, range=None, fields=None):
     database = lib.get_db()
     fields = lib.fields_to_list(fields)
     if height == 0:
         height = Pool_blocks.get_latest().height
     if range == None:
         block = Pool_blocks.get_by_height(height)
         if block is None:
             return None
         else:
             return block.to_json(fields)
     else:
         blocks = []
         for block in Pool_blocks.get_by_height(height, range):
             blocks.append(block.to_json(fields))
         return blocks
Esempio n. 14
0
 def get(self, height=None, range=None, fields=None):
     LOGGER = lib.get_logger(PROCESS)
     LOGGER.warn("GrinAPI_blocks get height:{} range:{} fields:{}".format(
         height, range, fields))
     fields = lib.fields_to_list(fields)
     if height is None or height == 0:
         blocks = Blocks.get_latest(range)
     else:
         blocks = Blocks.get_by_height(height, range)
     if range == None:
         if blocks is None:
             return None
         return blocks.to_json(fields)
     else:
         bl = []
         for block in blocks:
             bl.append(block.to_json(fields))
         return bl
Esempio n. 15
0
 def get(self, height=None, range=None, fields=None):
     LOGGER = lib.get_logger(PROCESS)
     LOGGER.warn("PoolAPI_stats get height:{} range:{} fields:{}".format(
         height, range, fields))
     fields = lib.fields_to_list(fields)
     if height is None or height == 0:
         stats = Pool_stats.get_latest(range)
     else:
         stats = Pool_stats.get_by_height(height, range)
     if range == None:
         if stats is None:
             return None
         return stats.to_json(fields)
     else:
         st = []
         for stat in stats:
             st.append(stat.to_json(fields))
         return st
Esempio n. 16
0
 def get(self, height=None, range=None, fields=None):
     LOGGER = lib.get_logger(PROCESS)
     debug and LOGGER.warn("PoolAPI_blocks get height:{}, range:{}, fields:{}".format(height, range, fields))
     # Enforce range limit
     if range is not None:
         range = min(range, pool_blocks_range_limit)
     fields = lib.fields_to_list(fields)
     if height is None or height == 0:
         blocks = Pool_blocks.get_latest(range)
     else:
         blocks = Pool_blocks.get_by_height(height, range)
     if range == None:
         if blocks is None:
             return None
         return blocks.to_json(fields)
     else:
         bl = []
         for block in blocks:
             bl = [block.to_json(fields)] + bl
         return bl
Esempio n. 17
0
 def get(self, id=None, height=0, range=None, fields=None):
     database = lib.get_db()
     fields = lib.fields_to_list(fields)
     if height == 0:
         height = grin.get_current_height()
     stats = []
     if id == None:
         for stat in Worker_stats.get_by_height(height, range):
             stats.append(stat.to_json(fields))
         return stats
     else:
         if range == None:
             res = Worker_stats.get_by_height_and_id(id, height)
             if res is None:
                 return res
             return res.to_json(fields)
         else:
             for stat in Worker_stats.get_by_height_and_id(
                     id, height, range):
                 stats.append(stat.to_json(fields))
             return stats
Esempio n. 18
0
 def get(self, height=None, range=None, fields=None):
     LOGGER = lib.get_logger(PROCESS)
     debug and LOGGER.warn("GrinAPI_stats get height:{} range:{} fields:{}".format(height, range, fields))
     # Enforce range limit
     if range is not None:
         range = min(range, grin_stats_range_limit)
     fields = lib.fields_to_list(fields)
     if height is None or height == 0:
         stats = Grin_stats.get_latest(range)
     else:
         stats = Grin_stats.get_by_height(height, range)
     #pp.pprint(stats)
     
     if range == None:
         if stats is None:
             return None
         return stats.to_json(fields)
     else:
         st = []
         for stat in stats:
             st.append(stat.to_json(fields))
         return st
Esempio n. 19
0
 def get(self, id, height=0, range=None, fields=None):
     global database
     #database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     # AUTH FILTER
     if id != g.user.id:
         response = jsonify(
             {'message': 'Not authorized to access data for other users'})
         response.status_code = 403
         return response
     debug and LOGGER.warn(
         "WorkerAPI_stats get id:{} height:{} range:{} fields:{}".format(
             id, height, range, fields))
     # Enforce range limit
     if range is not None:
         range = min(range, worker_stats_range_limit)
     fields = lib.fields_to_list(fields)
     res = None
     if range is None:
         # Getting a single record
         if height == 0:
             # Get the most recent stats for this user
             res = Worker_stats.get_latest_by_id(id)
         else:
             res = Worker_stats.get_by_height_and_id(id, height)
         if res is None:
             return None
         return res.to_json(fields)
     else:
         # Getting a range of records
         if height == 0:
             height = Blocks.get_latest().height
         res = Worker_stats.get_by_height_and_id(id, height, range)
         if res is None:
             return None
         stats = []
         for stat in res:
             stats.append(stat.to_json(fields))
         return stats
Esempio n. 20
0
 def get(self, id=None, fields=None):
     database = lib.get_db()
     fields = lib.fields_to_list(fields)
     utxo = Pool_utxo.get_by_address(id)
     return utxo.to_json(fields)