Esempio n. 1
0
    def get(self):
        try:
            args = self.parser.parse_args()
            start, end = args.get('start'), args.get('end')
            page = args.get('page')

            # return block in range [start, end)
            if not isinstance(start, int):
                if isinstance(page, int):
                    start = DEFAULT_OFFSET * (page - 1)
                else:
                    start = DEFAULT_START

            if not isinstance(end, int):
                if isinstance(page, int):
                    end = DEFAULT_OFFSET * page
                else:
                    end = DEFAULT_OFFSET

            result = self.manager.list_txs(start, end)
            result['page'] = 1 if not page else int(page)
        except Exception as e:
            self.logger.error("TxListAPI.get Error: %s" % str(e))
            return util.wrap_error_response()

        return util.wrap_response(data=result)
Esempio n. 2
0
 def get(self):
     try:
         rank_info = self.manager.handle_rank_address()
         return util.wrap_response(data=rank_info)
     except Exception as e:
         self.logger.error("RankAPI.get Error: %s" % str(e))
         return util.wrap_error_response()
Esempio n. 3
0
 def post(self):
     args = self.parser.parse_args()
     info = args.get('q')
     found = self.manager.search(info)
     if not found:
         return util.wrap_error_response(status='failure', code='404')
     return util.wrap_response(status='success', data=found, code='302')
Esempio n. 4
0
class BlockListAPI(Resource):
    def __init__(self):
        self.logger = current_app.logger
        self.manager = BlockManager()

        self.parser = reqparse.RequestParser()
        self.parser.add_argument('page', type=int, help='page number')

        super(BlockListAPI, self).__init__()

    @cache.cached(timeout=60 * 3, key_prefix=cache_key)
    def get(self):
        try:
            args = self.parser.parse_args()
            page = args.get('page', None) if args is not None else None
            if not isinstance(page, int) or page <= 0:
                page = 1
            start, end = DEFAULT_OFFSET * (page - 1), DEFAULT_OFFSET * page
            result = self.manager.list_blocks(start, end)
            if len(result.get('blocks', [])) == 0:
                raise Exception('Blocks NotFound')

            result['no_page'] = 1 if not page else int(page)
        except Exception, e:
            self.logger.error("BlockListAPI.get Error: %s" % str(e))
            return util.wrap_error_response()

        return util.wrap_response(data=result)
Esempio n. 5
0
    def get(self):
        try:
            result = self.manager.list_node_stats()
        except Exception as e:
            self.logger.error("NodeStatsAPI.get Error: %s" % str(e))
            return util.wrap_error_response()

        return util.wrap_response(data=result)
Esempio n. 6
0
    def get(self, chain_api):
        try:
            if chain_api is None:
                raise Exception("void query info")
            chain_api = chain_api.lower()  # Case-insensitive, BBE compatible
            if chain_api not in self.apis:
                raise Exception("Not a valid chain API")

            result = self.manager.handle_chain_api(chain_api)
            return util.wrap_response(data=result)
        except Exception, e:
            self.logger.error("BytomChainAPI.get Error: %s" % str(e))
            return util.wrap_error_response("无效的Chain API参数")
Esempio n. 7
0
    def get(self):
        try:
            args = self.parser.parse_args()
            page = args.get('page')
            page = 1 if page is None or not isinstance(
                page, int) or page <= 0 else page
            result = self.manager.list_assets(page)
            if len(result) == 0:
                raise Exception("Asset NotFound!")
        except Exception as e:
            self.logger.error("AssetListAPI.get Error: %s" % str(e))
            return util.wrap_error_response()

        return util.wrap_response(data=result)
Esempio n. 8
0
    def get(self, tx_api):
        try:
            if tx_api is None:
                raise Exception("void query info")

            args = self.parser.parse_args()
            query = args.get('q', self.apis[0])

            if query not in self.apis:
                raise Exception("Not a valid Tx API")

            result = self.manager.handle_tx_api(tx_api.lower(), query)
            return util.wrap_response(data=result)
        except Exception, e:
            self.logger.error("BytomTxAPI.get Error: %s" % str(e))
            return util.wrap_error_response("无效的Tx API参数")
Esempio n. 9
0
    def get(self, asset_id):
        try:
            asset_id = remove_0x(asset_id.strip().lower())
            args = self.parser.parse_args()
            page = args.get('page')
            tag = args.get('tag')
            page = 1 if page is None or not isinstance(
                page, int) or page <= 0 else page
            tag = 'txs' if tag is None or not isinstance(tag, str) or tag not in [
                'txs', 'balances'] else tag
            result = self.manager.handle_asset(asset_id, page, tag)
            if len(result) == 0:
                raise Exception("Asset NotFound!")

        except Exception as e:
            self.logger.error("AssetAPI.get Error: %s" % str(e))
            return util.wrap_error_response()

        return util.wrap_response(data=result)
Esempio n. 10
0
class BlockAPI(Resource):
    def __init__(self):
        self.logger = current_app.logger
        self.manager = BlockManager()

        super(BlockAPI, self).__init__()

    @cache.cached(timeout=60 * 3, key_prefix=cache_key)
    def get(self, block_id):
        try:
            block_id = remove_0x(block_id.strip().lower())
            result = self.manager.handle_block(block_id)

            if result is None:
                raise Exception('Block NotFound')
        except Exception, e:
            self.logger.error("BlockAPI.get Error: %s" % str(e))
            return util.wrap_error_response()

        return util.wrap_response(data=result)