mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
This commit introduces functionality for displaying native contract source code in the DarkFi explorer application, enabling users to view available contracts from the home page, access associated source files, and examine native contract Rust code and zk proofs. This enhancement provides accessibility to native contract information. To support these updates, we have added new pages to the UI, updated styles for rendering source-related pages, and implemented new RPC routes to facilitate contract-related code retrieval. Additionally, we have restructured the application into Flask blueprints to address the growing complexity of the explorer and adhere to best practices, as app.py was becoming large with diverging functionality. This proactive change prepares us for future expansions, including better organization of graph functionalities. The organization also mirrors the rest of the explorer codebase by maintaining separate pages for contracts, transactions, and blocks, as well as corresponding RPC and service rust modules. UI Support for Native Contract Source Code - We have added source code functionality to the UI, Flask blueprints, and RPC routes defined in rpc.py, along with updated styles to effectively render source-related pages. Style Updates: - Expanded the color palette for rendering source files. - Enhanced styles for displaying contract IDs and names in the native contracts table. - Implemented layout elements for proper display of source code lists and content. - Added styles for source file list links, including hover effects. RPC Routes: - New routes have been added to facilitate requests to the DarkFi daemon for retrieving native contracts, source code paths, and contract source. UI Enhancements: - A native contract section has been introduced on the explorer home page to display native contracts. - A contract source list page allows users to view and click on source code files associated with a native contract. - A dedicated contract source page renders the source for a specific path associated with a given contract. Introducing Flask Blueprints To better manage the growing complexity of the application, we introduced Flask blueprints that organize routes according to their functionality. This restructuring not only enhances readability but also aligns with best practices for Flask applications, facilitating future development. App.py Updates: - Routes have been moved to their respective blueprints. Added Blueprints: - `__init__.py` file initializes the explorer blueprint package and exposes various blueprints used by the application. - `block.py` module defines a blueprint for handling block-related functionality. - `contract.py` module defines a blueprint for managing contract-related functionality. - explore.py` module manages general functionality related to the home page and search features. - `transaction.py` module handles transaction-related functionality. Python Documentation: - We documented the Python code and updated existing documentation to adhere to Python's best practices for using docstrings, enhancing usability and integration with documentation tools. Testing: - Manual testing has been conducted through the UI to verify the functionality of the new RPC methods, ensuring they correctly retrieve and display contract-related information.
77 lines
2.8 KiB
Python
77 lines
2.8 KiB
Python
# This file is part of DarkFi (https://dark.fi)
|
|
#
|
|
# Copyright (C) 2020-2024 Dyne.org foundation
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
Module: app.py
|
|
|
|
This module initializes the DarkFi explorer Flask application by registering various blueprints for handling routes
|
|
related to blocks, contracts, transactions, search, and the explore section, including the home page. It also defines
|
|
error handlers, ensuring appropriate responses for these common HTTP errors.
|
|
"""
|
|
|
|
from flask import Flask, render_template
|
|
|
|
from blueprints.explore import explore_bp
|
|
from blueprints.block import block_bp
|
|
from blueprints.contract import contract_bp
|
|
from blueprints.transaction import transaction_bp
|
|
|
|
def create_app():
|
|
"""
|
|
Creates and configures the DarkFi explorer Flask application.
|
|
|
|
This function creates and initializes the explorer the Flask app,
|
|
registering applicable blueprints for handling explorer-related routes,
|
|
and defining error handling for common HTTP errors. It returns a fully
|
|
configured Flask application instance.
|
|
"""
|
|
app = Flask(__name__)
|
|
|
|
# Register Blueprints
|
|
app.register_blueprint(explore_bp)
|
|
app.register_blueprint(block_bp)
|
|
app.register_blueprint(contract_bp)
|
|
app.register_blueprint(transaction_bp)
|
|
|
|
# Define page not found error handler
|
|
@app.errorhandler(404)
|
|
def page_not_found(e):
|
|
"""
|
|
Handles 404 errors by rendering a custom 404 error page when a requested page is not found,
|
|
returning a rendered template along with a 404 status code.
|
|
|
|
Args:
|
|
e: The error object associated with the 404 error.
|
|
"""
|
|
# Render the custom 404 error page
|
|
return render_template('404.html'), 404
|
|
|
|
# Define internal server error handler
|
|
@app.errorhandler(500)
|
|
def internal_server_error(e):
|
|
"""
|
|
Handles 500 errors by rendering a custom 500 error page when an internal server error occurs,
|
|
returning a rendered template along with a 500 status code.
|
|
|
|
Args:
|
|
e: The error object associated with the 500 error.
|
|
"""
|
|
# Render the custom 500 error page
|
|
return render_template('500.html'), 500
|
|
|
|
return app
|