block.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # This file is part of DarkFi (https://dark.fi)
  2. #
  3. # Copyright (C) 2020-2025 Dyne.org foundation
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. """
  18. Blueprint: block_bp
  19. This module defines a Flask blueprint (`block_bp`) for handling block-related functionality,
  20. serving as a primary location for Flask code related to routes and features associated with blocks.
  21. """
  22. from flask import Blueprint, render_template
  23. import rpc
  24. # Create block blueprint
  25. block_bp = Blueprint("block", __name__)
  26. @block_bp.route('/block/<header_hash>')
  27. async def block(header_hash):
  28. """
  29. Retrieves and displays details of a specific block and its associated transactions based
  30. on the provided header hash using RPC calls to the explorer daemon, returning a rendered template.
  31. Path Args:
  32. header_hash (str): The header hash of the block to retrieve.
  33. """
  34. # Fetch the block details
  35. block = await rpc.get_block(header_hash)
  36. # Fetch transactions associated with the block
  37. transactions = await rpc.get_block_transactions(header_hash)
  38. # Render the template with the block details and associated transactions
  39. return render_template('block.html', block=block, transactions=transactions)