예제 #1
0
def main():
    CONFIG = lib.get_config()
    LOGGER = lib.get_logger(PROCESS)
    LOGGER.warn("=== Starting {}".format(PROCESS))
    # Connect to DB
    database = lib.get_db()
    database.db.initializeSession()

    pp = pprint.PrettyPrinter(indent=4)

    # Fetch and print pool block reward estimates for latest N pool blocks
    try:
        pool_blocks = Pool_blocks.get_latest(NUM_BLOCKS)
        pool_blocks_h = [blk.height for blk in pool_blocks]
        LOGGER.warn(
            "Will report estimates for pool blocks: {}".format(pool_blocks_h))

        # Print Estimate
        for height in pool_blocks_h:
            pp.pprint("Eestimate for block: {}".format(height))
            payout_map = pool.get_block_payout_map_estimate(height, LOGGER)
            pp.pprint(payout_map)
    except Exception as e:  # AssertionError as e:
        LOGGER.error("Something went wrong: {} - {}".format(
            e, traceback.print_stack()))

        LOGGER.warn("=== Completed {}".format(PROCESS))
예제 #2
0
파일: api.py 프로젝트: bitgrin/grin-pool
 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
예제 #3
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
예제 #4
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
예제 #5
0
 def get(self, height=None, range=None, fields=None):
     database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     LOGGER.warn("PoolAPI_blocks get height:{} range:{} fields:{}".format(
         height, range, fields))
     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
예제 #6
0
파일: api.py 프로젝트: bitgrin/grin-pool
 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
예제 #7
0
파일: api.py 프로젝트: waosman/grin-pool
 def get(self, id, height=None, range=None):
     LOGGER = lib.get_logger(PROCESS)
     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("EstimateApi_payment get id:{} height:{}".format(
         id, height))
     id_str = str(id)
     if height is None:
         # Immature Balance Estimate
         LOGGER.warn("Immature Balance Estimate")
         # Get a list of all new and unlocked blocks
         unlocked_blocks = Pool_blocks.get_all_unlocked()
         unlocked_blocks_h = [blk.height for blk in unlocked_blocks]
         #LOGGER.warn("EstimateApi_payment unlocked blocks: {}".format(unlocked_blocks))
         new_blocks = Pool_blocks.get_all_new()
         new_blocks_h = [blk.height for blk in new_blocks]
         #LOGGER.warn("EstimateApi_payment new blocks: {}".format(new_blocks))
         total = 0
         for height in unlocked_blocks_h + new_blocks_h:
             debug and print("Estimate block at height: {}".format(height))
             payout_map = pool.get_block_payout_map_estimate(height, LOGGER)
             if payout_map is not None and id_str in payout_map:
                 total = total + payout_map[id_str]
         return {"immature": total}
     if type(height) == str:
         if height == "next":
             # Next block estimate
             debug and LOGGER.warn("Next block estimate")
             estimate = 0
             payout_map = pool.get_block_payout_map_estimate(height, LOGGER)
             if payout_map is None:
                 estimate = "TBD"
             elif id_str in payout_map:
                 estimate = payout_map[id_str]
             else:
                 estimate = 0
             return {"next": estimate}
         else:
             response = jsonify({'message': 'Invalid Request'})
             response.status_code = 400
             return response
     # Block Reward estimate
     if range is None:
         # One specific block estimate
         debug and LOGGER.warn("One specific block estimate")
         estimate = 0
         payout_map = pool.get_block_payout_map_estimate(height, LOGGER)
         if payout_map is not None:
             if id_str in payout_map.keys():
                 estimate = payout_map[id_str]
             else:
                 estimate = 0
         else:
             # Maybe this is a pool block but we didnt estimate it yet
             pb = Pool_blocks.get_by_height(height)
             if pb is not None:
                 estimate = "TBD"
         str_height = str(height)
         return {str_height: estimate}
     # Range of pool block reward estimates
     debug and LOGGER.warn("Range of blocks estimate")
     # Enforce range limit
     range = min(range, pool_blocks_range_limit)
     # Get the list of pool block(s) heights
     if height == 0:
         blocks = Pool_blocks.get_latest(range)
     else:
         blocks = Pool_blocks.get_by_height(height, range)
     block_heights = [pb.height for pb in blocks]
     # Get estimates for each of the blocks
     estimates = {}
     for height in block_heights:
         estimate = 0
         payout_map = pool.get_block_payout_map_estimate(height, LOGGER)
         if payout_map is None:
             estimate = "TBD"
         elif id_str in payout_map:
             estimate = payout_map[id_str]
         else:
             estimate = 0
         str_height = str(height)
         estimates[str_height] = estimate
     return estimates