From e0465b6b4d8c7b0c5a7fe2a413ace9c117bdebde Mon Sep 17 00:00:00 2001 From: Neylix Date: Tue, 25 Jul 2023 15:43:06 +0200 Subject: [PATCH] Refactor web router (#1177) * Reorganize archethic_web folders * Reorganize archetic_web_test folders * Rename archethic_web modules * Rework archethic web routers * Refactor API folder * Add error control in router_dispatch --- config/config.exs | 8 +-- config/dev.exs | 6 +- config/prod.exs | 6 +- config/test.exs | 4 +- lib/archethic_web/aeweb.ex | 39 +++++++++++ lib/archethic_web/aeweb/aeweb_router.ex | 28 ++++++++ .../controllers}/web_hosting_controller.ex | 14 ++-- .../directory_listing.ex | 10 +-- .../reference_transaction.ex | 2 +- .../web_hosting_controller/resources.ex | 4 +- lib/archethic_web/aeweb/dnslink_router.ex | 31 +++++++++ lib/archethic_web/{ => aeweb}/domain.ex | 5 +- .../templates/dir_listing/index.html.heex | 0 .../{ => aeweb}/views/dir_listing_view.ex | 4 +- lib/archethic_web/aeweb_router.ex | 20 ------ lib/archethic_web/api.ex | 25 +++++++ lib/archethic_web/api/api_router.ex | 43 ++++++++++++ .../controllers}/origin_key_controller.ex | 20 +++--- .../controllers}/schema/authorized_key.ex | 0 .../api => api/controllers}/schema/ledger.ex | 0 .../controllers}/schema/origin_public_key.ex | 0 .../controllers}/schema/ownership.ex | 0 .../controllers}/schema/token_ledger.ex | 0 .../controllers}/schema/transaction_data.ex | 0 .../controllers}/schema/uco_ledger.ex | 0 .../controllers}/transaction_controller.ex | 13 ++-- .../controllers}/transaction_payload.ex | 0 .../api => api/controllers}/types/address.ex | 0 .../controllers}/types/address_list.ex | 0 .../api => api/controllers}/types/hex.ex | 0 .../controllers}/types/public_key.ex | 0 .../controllers}/types/secret_list.ex | 0 .../controllers}/types/transaction_type.ex | 0 .../graphql/context.ex} | 2 +- .../graphql/schema.ex} | 2 +- .../graphql/schema}/address_type.ex | 2 +- .../schema}/beacon_chain_summary_type.ex | 2 +- .../graphql/schema}/content_type.ex | 2 +- .../graphql/schema}/datetime_type.ex | 2 +- .../graphql/schema}/hash_type.ex | 2 +- .../graphql/schema}/hex_type.ex | 2 +- .../graphql/schema}/integer_type.ex | 2 +- .../graphql/schema}/oracle_data.ex | 2 +- .../graphql/schema}/p2p_type.ex | 2 +- .../graphql/schema}/public_key_type.ex | 2 +- .../graphql/schema}/resolver.ex | 2 +- .../graphql/schema}/shared_secrets_type.ex | 2 +- .../graphql/schema}/sort_order_enum.ex | 2 +- .../schema}/transaction_attestation.ex | 2 +- .../graphql/schema}/transaction_error.ex | 2 +- .../graphql/schema}/transaction_type.ex | 4 +- .../graphql/schema}/version_type.ex | 2 +- .../controllers/aeweb_root_controller.ex | 11 --- lib/archethic_web/endpoint.ex | 34 ++++----- .../explorer.ex} | 21 ++---- .../{ => explorer}/components/pagination.ex | 2 +- .../controllers/code_controller.ex | 8 +-- .../controllers/explorer_controller.ex | 6 +- .../controllers/explorer_root_controller.ex | 4 +- .../controllers/faucet_controller.ex | 18 +++-- .../controllers/metrics_controller.ex | 4 +- .../controllers/up_controller.ex | 4 +- .../{ => explorer}/explorer_router.ex | 69 +++---------------- .../{ => explorer}/faucet_rate_limiter.ex | 2 +- .../{ => explorer}/live/chains/beacon_live.ex | 8 +-- .../{ => explorer}/live/chains/cache.ex | 2 +- .../live/chains/node_shared_secrets_live.ex | 25 +++---- .../{ => explorer}/live/chains/oracle_live.ex | 6 +- .../{ => explorer}/live/chains/origin_live.ex | 31 +++++---- .../{ => explorer}/live/chains/reward_live.ex | 18 ++--- .../live/chains/transaction_live.ex | 6 +- .../live/code_proposal_chat_live.ex | 6 +- .../live/code_proposal_details_live.ex | 6 +- .../live/code_proposals_live.ex | 6 +- .../{ => explorer}/live/code_viewer_live.ex | 6 +- .../{ => explorer}/live/dashboard_live.ex | 6 +- .../live/explorer/top_transaction_cache.ex} | 2 +- .../live/explorer_index_live.ex | 8 +-- .../{ => explorer}/live/node_details_live.ex | 6 +- .../{ => explorer}/live/node_list_live.ex | 6 +- .../{ => explorer}/live/settings_live.ex | 4 +- .../{ => explorer}/live/top_node_live.ex | 6 +- .../live/top_transactions_component.ex | 8 +-- .../explorer/live/transaction_builder_live.ex | 15 ++++ .../live/transaction_details_live.ex | 6 +- .../{ => explorer}/live/worldmap_live.ex | 6 +- .../templates/code/proposal_details.html.heex | 4 +- .../templates/code/proposal_list.html.heex | 4 +- .../templates/code/viewer.html.heex | 0 .../templates/dashboard/dashboard.html.heex | 0 .../templates/error/404.html.heex | 0 .../templates/error/500.html.heex | 0 .../templates/explorer/404.html.heex | 0 .../explorer/beacon_chain_index.html.heex | 4 +- .../templates/explorer/chain.html.heex | 4 +- .../templates/explorer/index.html.heex | 2 +- .../explorer/ko_transaction.html.heex | 0 .../node_shared_secrets_chain_index.html.heex | 4 +- .../explorer/oracle_chain_index.html.heex | 4 +- .../explorer/origin_chain_index.html.heex | 4 +- .../explorer/reward_chain_index.html.heex | 4 +- .../explorer/top_transactions.html.heex | 0 .../explorer/transaction_builder.html.heex | 0 .../explorer/transaction_details.html.heex | 32 ++++----- .../explorer/transaction_list.html.heex | 0 .../explorer/transaction_summary.html.heex | 2 +- .../templates/faucet/index.html.heex | 4 +- .../templates/layout/app.html.heex | 0 .../templates/layout/live.html.heex | 0 .../templates/layout/root.html.heex | 24 +++---- .../templates/node/details.html.heex | 4 +- .../templates/node/list.html.heex | 6 +- .../templates/node/worldmap.html.heex | 0 .../{ => explorer}/views/code_view.ex | 4 +- .../explorer/views/dashboard_view.ex | 3 + .../{ => explorer}/views/error_view.ex | 4 +- .../{ => explorer}/views/explorer_view.ex | 6 +- .../{ => explorer}/views/faucet_view.ex | 4 +- .../explorer/views/layout_view.ex | 9 +++ lib/archethic_web/explorer/views/node_view.ex | 4 ++ .../live/transaction_builder_live.ex | 15 ---- lib/archethic_web/plugs/archethic_up.ex | 30 ++++++++ ...and_path.ex => throttle_by_ip_and_path.ex} | 2 +- ...e_by_ip_high.ex => throttle_by_ip_high.ex} | 2 +- ...tle_by_ip_low.ex => throttle_by_ip_low.ex} | 2 +- lib/archethic_web/router_dispatch.ex | 64 +++++++++-------- lib/archethic_web/supervisor.ex | 17 +++-- .../{channels => }/user_socket.ex | 2 +- lib/archethic_web/views/dashboard_view.ex | 3 - lib/archethic_web/views/error_helpers.ex | 14 ---- lib/archethic_web/views/layout_helpers.ex | 49 ------------- lib/archethic_web/views/layout_view.ex | 9 --- lib/archethic_web/views/node_view.ex | 4 -- lib/archethic_web/web_utils.ex | 57 +++++++++++++++ priv/json-schemas/aeweb.json | 2 +- .../web_hosting_controller_test.exs | 52 +++++++------- .../origin_key_controller_test.exs | 0 .../schema/origin_public_key_test.exs | 0 .../transaction_controller_test.exs | 0 .../controllers}/transaction_payload_test.exs | 0 .../graphql/schema_test.exs} | 4 +- .../controllers/faucet_controller_test.exs | 6 +- .../controllers}/up_controller_test.exs | 2 +- .../{ => explorer}/live/rewards_live_test.exs | 4 +- .../live/worldmap_live_test.exs | 2 +- ...t.exs => throttle_by_ip_and_path_test.exs} | 2 +- ...w_test.exs => throttle_by_ip_low_test.exs} | 2 +- test/archethic_web/views/error_view_test.exs | 15 ---- test/support/graphql_subscription_case.ex | 2 +- 149 files changed, 643 insertions(+), 558 deletions(-) create mode 100644 lib/archethic_web/aeweb.ex create mode 100644 lib/archethic_web/aeweb/aeweb_router.ex rename lib/archethic_web/{controllers/api => aeweb/controllers}/web_hosting_controller.ex (94%) rename lib/archethic_web/{controllers/api => aeweb/controllers}/web_hosting_controller/directory_listing.ex (92%) rename lib/archethic_web/{controllers/api => aeweb/controllers}/web_hosting_controller/reference_transaction.ex (97%) rename lib/archethic_web/{controllers/api => aeweb/controllers}/web_hosting_controller/resources.ex (98%) create mode 100644 lib/archethic_web/aeweb/dnslink_router.ex rename lib/archethic_web/{ => aeweb}/domain.ex (96%) rename lib/archethic_web/{ => aeweb}/templates/dir_listing/index.html.heex (100%) rename lib/archethic_web/{ => aeweb}/views/dir_listing_view.ex (88%) delete mode 100644 lib/archethic_web/aeweb_router.ex create mode 100644 lib/archethic_web/api.ex create mode 100644 lib/archethic_web/api/api_router.ex rename lib/archethic_web/{controllers/api => api/controllers}/origin_key_controller.ex (84%) rename lib/archethic_web/{controllers/api => api/controllers}/schema/authorized_key.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/schema/ledger.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/schema/origin_public_key.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/schema/ownership.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/schema/token_ledger.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/schema/transaction_data.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/schema/uco_ledger.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/transaction_controller.ex (96%) rename lib/archethic_web/{controllers/api => api/controllers}/transaction_payload.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/types/address.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/types/address_list.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/types/hex.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/types/public_key.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/types/secret_list.ex (100%) rename lib/archethic_web/{controllers/api => api/controllers}/types/transaction_type.ex (100%) rename lib/archethic_web/{graphl_context.ex => api/graphql/context.ex} (84%) rename lib/archethic_web/{graphql_schema.ex => api/graphql/schema.ex} (99%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/address_type.ex (93%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/beacon_chain_summary_type.ex (96%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/content_type.ex (88%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/datetime_type.ex (91%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/hash_type.ex (94%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/hex_type.ex (80%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/integer_type.ex (92%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/oracle_data.ex (86%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/p2p_type.ex (93%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/public_key_type.ex (93%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/resolver.ex (99%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/shared_secrets_type.ex (86%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/sort_order_enum.ex (82%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/transaction_attestation.ex (86%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/transaction_error.ex (87%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/transaction_type.ex (98%) rename lib/archethic_web/{graphql_schema => api/graphql/schema}/version_type.ex (82%) delete mode 100644 lib/archethic_web/controllers/aeweb_root_controller.ex rename lib/{archethic_web.ex => archethic_web/explorer.ex} (78%) rename lib/archethic_web/{ => explorer}/components/pagination.ex (95%) rename lib/archethic_web/{ => explorer}/controllers/code_controller.ex (86%) rename lib/archethic_web/{ => explorer}/controllers/explorer_controller.ex (76%) rename lib/archethic_web/{ => explorer}/controllers/explorer_root_controller.ex (88%) rename lib/archethic_web/{ => explorer}/controllers/faucet_controller.ex (90%) rename lib/archethic_web/{ => explorer}/controllers/metrics_controller.ex (67%) rename lib/archethic_web/{ => explorer}/controllers/up_controller.ex (65%) rename lib/archethic_web/{ => explorer}/explorer_router.ex (52%) rename lib/archethic_web/{ => explorer}/faucet_rate_limiter.ex (98%) rename lib/archethic_web/{ => explorer}/live/chains/beacon_live.ex (97%) rename lib/archethic_web/{ => explorer}/live/chains/cache.ex (97%) rename lib/archethic_web/{ => explorer}/live/chains/node_shared_secrets_live.ex (91%) rename lib/archethic_web/{ => explorer}/live/chains/oracle_live.ex (97%) rename lib/archethic_web/{ => explorer}/live/chains/origin_live.ex (89%) rename lib/archethic_web/{ => explorer}/live/chains/reward_live.ex (94%) rename lib/archethic_web/{ => explorer}/live/chains/transaction_live.ex (96%) rename lib/archethic_web/{ => explorer}/live/code_proposal_chat_live.ex (93%) rename lib/archethic_web/{ => explorer}/live/code_proposal_details_live.ex (94%) rename lib/archethic_web/{ => explorer}/live/code_proposals_live.ex (82%) rename lib/archethic_web/{ => explorer}/live/code_viewer_live.ex (94%) rename lib/archethic_web/{ => explorer}/live/dashboard_live.ex (96%) rename lib/archethic_web/{live/explorer/cache.ex => explorer/live/explorer/top_transaction_cache.ex} (93%) rename lib/archethic_web/{ => explorer}/live/explorer_index_live.ex (91%) rename lib/archethic_web/{ => explorer}/live/node_details_live.ex (91%) rename lib/archethic_web/{ => explorer}/live/node_list_live.ex (92%) rename lib/archethic_web/{ => explorer}/live/settings_live.ex (98%) rename lib/archethic_web/{ => explorer}/live/top_node_live.ex (86%) rename lib/archethic_web/{ => explorer}/live/top_transactions_component.ex (89%) create mode 100644 lib/archethic_web/explorer/live/transaction_builder_live.ex rename lib/archethic_web/{ => explorer}/live/transaction_details_live.ex (98%) rename lib/archethic_web/{ => explorer}/live/worldmap_live.ex (93%) rename lib/archethic_web/{ => explorer}/templates/code/proposal_details.html.heex (94%) rename lib/archethic_web/{ => explorer}/templates/code/proposal_list.html.heex (94%) rename lib/archethic_web/{ => explorer}/templates/code/viewer.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/dashboard/dashboard.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/error/404.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/error/500.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/explorer/404.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/explorer/beacon_chain_index.html.heex (93%) rename lib/archethic_web/{ => explorer}/templates/explorer/chain.html.heex (97%) rename lib/archethic_web/{ => explorer}/templates/explorer/index.html.heex (93%) rename lib/archethic_web/{ => explorer}/templates/explorer/ko_transaction.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/explorer/node_shared_secrets_chain_index.html.heex (93%) rename lib/archethic_web/{ => explorer}/templates/explorer/oracle_chain_index.html.heex (92%) rename lib/archethic_web/{ => explorer}/templates/explorer/origin_chain_index.html.heex (91%) rename lib/archethic_web/{ => explorer}/templates/explorer/reward_chain_index.html.heex (91%) rename lib/archethic_web/{ => explorer}/templates/explorer/top_transactions.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/explorer/transaction_builder.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/explorer/transaction_details.html.heex (96%) rename lib/archethic_web/{ => explorer}/templates/explorer/transaction_list.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/explorer/transaction_summary.html.heex (84%) rename lib/archethic_web/{ => explorer}/templates/faucet/index.html.heex (94%) rename lib/archethic_web/{ => explorer}/templates/layout/app.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/layout/live.html.heex (100%) rename lib/archethic_web/{ => explorer}/templates/layout/root.html.heex (85%) rename lib/archethic_web/{ => explorer}/templates/node/details.html.heex (94%) rename lib/archethic_web/{ => explorer}/templates/node/list.html.heex (96%) rename lib/archethic_web/{ => explorer}/templates/node/worldmap.html.heex (100%) rename lib/archethic_web/{ => explorer}/views/code_view.ex (96%) create mode 100644 lib/archethic_web/explorer/views/dashboard_view.ex rename lib/archethic_web/{ => explorer}/views/error_view.ex (88%) rename lib/archethic_web/{ => explorer}/views/explorer_view.ex (98%) rename lib/archethic_web/{ => explorer}/views/faucet_view.ex (79%) create mode 100644 lib/archethic_web/explorer/views/layout_view.ex create mode 100644 lib/archethic_web/explorer/views/node_view.ex delete mode 100644 lib/archethic_web/live/transaction_builder_live.ex create mode 100644 lib/archethic_web/plugs/archethic_up.ex rename lib/archethic_web/plugs/{plug_throttle_by_ip_and_path.ex => throttle_by_ip_and_path.ex} (92%) rename lib/archethic_web/plugs/{plug_throttle_by_ip_high.ex => throttle_by_ip_high.ex} (92%) rename lib/archethic_web/plugs/{plug_throttle_by_ip_low.ex => throttle_by_ip_low.ex} (92%) rename lib/archethic_web/{channels => }/user_socket.ex (96%) delete mode 100644 lib/archethic_web/views/dashboard_view.ex delete mode 100644 lib/archethic_web/views/error_helpers.ex delete mode 100644 lib/archethic_web/views/layout_helpers.ex delete mode 100644 lib/archethic_web/views/layout_view.ex delete mode 100644 lib/archethic_web/views/node_view.ex rename test/archethic_web/{controllers/api => aeweb/controllers}/web_hosting_controller_test.exs (87%) rename test/archethic_web/{controllers/api => api/controllers}/origin_key_controller_test.exs (100%) rename test/archethic_web/{controllers/api => api/controllers}/schema/origin_public_key_test.exs (100%) rename test/archethic_web/{controllers/api => api/controllers}/transaction_controller_test.exs (100%) rename test/archethic_web/{controllers/api => api/controllers}/transaction_payload_test.exs (100%) rename test/archethic_web/{graphql_schema_test.exs => api/graphql/schema_test.exs} (99%) rename test/archethic_web/{ => explorer}/controllers/faucet_controller_test.exs (96%) rename test/archethic_web/{controllers/api => explorer/controllers}/up_controller_test.exs (89%) rename test/archethic_web/{ => explorer}/live/rewards_live_test.exs (94%) rename test/archethic_web/{ => explorer}/live/worldmap_live_test.exs (98%) rename test/archethic_web/plugs/{plug_throttle_by_ip_and_path_test.exs => throttle_by_ip_and_path_test.exs} (93%) rename test/archethic_web/plugs/{plug_throttle_by_ip_low_test.exs => throttle_by_ip_low_test.exs} (93%) delete mode 100644 test/archethic_web/views/error_view_test.exs diff --git a/config/config.exs b/config/config.exs index aad544248..b48e9e95b 100644 --- a/config/config.exs +++ b/config/config.exs @@ -121,11 +121,11 @@ config :archethic, # Configure the endpoint config :archethic, ArchethicWeb.Endpoint, secret_key_base: "5mFu4p5cPMY5Ii0HvjkLfhYZYtC0JAJofu70bzmi5x3xzFIJNlXFgIY5g8YdDPMf", - render_errors: [view: ArchethicWeb.ErrorView, accepts: ~w(json)], + render_errors: [view: ArchethicWeb.Explorer.ErrorView, accepts: ~w(json)], pubsub_server: ArchethicWeb.PubSub, live_view: [ signing_salt: "3D6jYvx3", - layout: {ArchethicWeb.LayoutView, "live.html"} + layout: {ArchethicWeb.Explorer.LayoutView, "live.html"} ] config :archethic, Archethic.Mining.StandaloneWorkflow, global_timeout: 10_000 @@ -149,7 +149,7 @@ config :archethic, Archethic.OracleChain.Services.UCOPrice, Archethic.OracleChain.Services.UCOPrice.Providers.CoinPaprika => [refresh_interval: 120_000] } -config :archethic, ArchethicWeb.FaucetController, +config :archethic, ArchethicWeb.Explorer.FaucetController, seed: "3A7B579DBFB7CEBE26293850058F180A65D6A3D2F6964543F5EDE07BEB2EFDA4" |> Base.decode16!(case: :mixed) @@ -165,7 +165,7 @@ config :archethic, Archethic.Networking.IPLookup.RemoteDiscovery, config :archethic, Archethic.Networking.PortForwarding, port_range: 49_152..65_535 # -----End-of-Networking-configs ------ -config :archethic, ArchethicWeb.API.WebHostingController, +config :archethic, ArchethicWeb.AEWeb.WebHostingController, # The tx_cache is stored on RAM # 750MB should hold a minimum 250 transactions tx_cache_bytes: 750 * 1024 * 1024, diff --git a/config/dev.exs b/config/dev.exs index d32bf2a50..f285ecb50 100755 --- a/config/dev.exs +++ b/config/dev.exs @@ -125,8 +125,8 @@ config :archethic, Archethic.SharedSecrets.NodeRenewalScheduler, config :archethic, Archethic.P2P.Listener, port: System.get_env("ARCHETHIC_P2P_PORT", "3002") |> String.to_integer() -config :archethic, ArchethicWeb.FaucetController, enabled: true -config :archethic, ArchethicWeb.FaucetRateLimiter, enabled: true +config :archethic, ArchethicWeb.Explorer.FaucetController, enabled: true +config :archethic, ArchethicWeb.Explorer.FaucetRateLimiter, enabled: true # For development, we disable any cache and enable # debugging and code reloading. @@ -159,7 +159,7 @@ config :archethic, ArchethicWeb.Endpoint, port: System.get_env("ARCHETHIC_HTTPS_PORT", "5000") |> String.to_integer(), cipher_suite: :strong, otp_app: :archethic, - sni_fun: &ArchethicWeb.Domain.sni/1, + sni_fun: &ArchethicWeb.AEWeb.Domain.sni/1, keyfile: "priv/cert/selfsigned_key.pem", certfile: "priv/cert/selfsigned.pem" ] diff --git a/config/prod.exs b/config/prod.exs index c6e3fb255..cfdb89f05 100755 --- a/config/prod.exs +++ b/config/prod.exs @@ -232,10 +232,10 @@ config :archethic, Archethic.P2P.BootstrappingSeeds, config :archethic, Archethic.Utils.DetectNodeResponsiveness, timeout: 10_000 -config :archethic, ArchethicWeb.FaucetController, +config :archethic, ArchethicWeb.Explorer.FaucetController, enabled: System.get_env("ARCHETHIC_NETWORK_TYPE") == "testnet" -config :archethic, ArchethicWeb.FaucetRateLimiter, +config :archethic, ArchethicWeb.Explorer.FaucetRateLimiter, enabled: System.get_env("ARCHETHIC_NETWORK_TYPE") == "testnet" # For production, don't forget to configure the url host @@ -272,7 +272,7 @@ config :archethic, ArchethicWeb.Endpoint, cipher_suite: :strong, otp_app: :archethic, port: System.get_env("ARCHETHIC_HTTPS_PORT", "50000") |> String.to_integer(), - sni_fun: &ArchethicWeb.Domain.sni/1, + sni_fun: &ArchethicWeb.AEWeb.Domain.sni/1, keyfile: System.get_env("ARCHETHIC_WEB_SSL_KEYFILE", "priv/cert/selfsigned_key.pem"), certfile: System.get_env("ARCHETHIC_WEB_SSL_CERTFILE", "priv/cert/selfsigned.pem") ] diff --git a/config/test.exs b/config/test.exs index 4acf7a51c..e82dc9a79 100755 --- a/config/test.exs +++ b/config/test.exs @@ -165,8 +165,8 @@ config :archethic, Archethic.TransactionChain.MemTablesLoader, enabled: false config :archethic, Archethic.Utils.DetectNodeResponsiveness, timeout: 1_000 -config :archethic, ArchethicWeb.FaucetController, enabled: true -config :archethic, ArchethicWeb.FaucetRateLimiter, enabled: false +config :archethic, ArchethicWeb.Explorer.FaucetController, enabled: true +config :archethic, ArchethicWeb.Explorer.FaucetRateLimiter, enabled: false config :archethic, ArchethicWeb.TransactionSubscriber, enabled: false # We don't run a server during test. If one is required, diff --git a/lib/archethic_web/aeweb.ex b/lib/archethic_web/aeweb.ex new file mode 100644 index 000000000..267e9244c --- /dev/null +++ b/lib/archethic_web/aeweb.ex @@ -0,0 +1,39 @@ +defmodule ArchethicWeb.AEWeb do + @moduledoc false + + def controller do + quote do + use Phoenix.Controller, namespace: ArchethicWeb.AEWeb + + import Plug.Conn + end + end + + def view do + quote do + use Phoenix.View, + root: "lib/archethic_web/aeweb/templates", + namespace: ArchethicWeb.AEWeb + + # Import convenience functions from controllers + import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1] + import ArchethicWeb.WebUtils + # Import basic rendering functionality (render, render_layout, etc) + import Phoenix.View + end + end + + def router do + quote do + use Phoenix.Router + import Phoenix.Controller + end + end + + @doc """ + When used, dispatch to the appropriate controller/view/etc. + """ + defmacro __using__(which) when is_atom(which) do + apply(__MODULE__, which, []) + end +end diff --git a/lib/archethic_web/aeweb/aeweb_router.ex b/lib/archethic_web/aeweb/aeweb_router.ex new file mode 100644 index 000000000..fca1a3b6f --- /dev/null +++ b/lib/archethic_web/aeweb/aeweb_router.ex @@ -0,0 +1,28 @@ +defmodule ArchethicWeb.AEWebRouter do + @moduledoc false + use ArchethicWeb.AEWeb, :router + + alias ArchethicWeb.AEWeb.WebHostingController + + alias ArchethicWeb.Plug.ThrottleByIPHigh + alias ArchethicWeb.Plug.ThrottleByIPandPath + + pipeline :browser do + plug(:accepts, ["html"]) + plug(:put_secure_browser_headers) + plug(ThrottleByIPHigh) + plug(ThrottleByIPandPath) + end + + scope "/aeweb" do + pipe_through(:browser) + + get("/:address/*url_path", WebHostingController, :web_hosting) + end + + scope "/api/web_hosting" do + pipe_through(:browser) + + get("/:address/*url_path", WebHostingController, :web_hosting) + end +end diff --git a/lib/archethic_web/controllers/api/web_hosting_controller.ex b/lib/archethic_web/aeweb/controllers/web_hosting_controller.ex similarity index 94% rename from lib/archethic_web/controllers/api/web_hosting_controller.ex rename to lib/archethic_web/aeweb/controllers/web_hosting_controller.ex index a716d97a8..a7ab968b5 100644 --- a/lib/archethic_web/controllers/api/web_hosting_controller.ex +++ b/lib/archethic_web/aeweb/controllers/web_hosting_controller.ex @@ -1,17 +1,15 @@ -defmodule ArchethicWeb.API.WebHostingController do +defmodule ArchethicWeb.AEWeb.WebHostingController do @moduledoc false - use ArchethicWeb, :controller + use ArchethicWeb.AEWeb, :controller alias Archethic.Crypto - require Logger + alias ArchethicWeb.AEWeb.WebHostingController.Resources + alias ArchethicWeb.AEWeb.WebHostingController.DirectoryListing + alias ArchethicWeb.AEWeb.WebHostingController.ReferenceTransaction - alias ArchethicWeb.API.WebHostingController.{ - Resources, - DirectoryListing, - ReferenceTransaction - } + require Logger @spec web_hosting(Plug.Conn.t(), params :: map()) :: Plug.Conn.t() def web_hosting(conn, params = %{"url_path" => []}) do diff --git a/lib/archethic_web/controllers/api/web_hosting_controller/directory_listing.ex b/lib/archethic_web/aeweb/controllers/web_hosting_controller/directory_listing.ex similarity index 92% rename from lib/archethic_web/controllers/api/web_hosting_controller/directory_listing.ex rename to lib/archethic_web/aeweb/controllers/web_hosting_controller/directory_listing.ex index 2583555cc..be7bbe4ab 100644 --- a/lib/archethic_web/controllers/api/web_hosting_controller/directory_listing.ex +++ b/lib/archethic_web/aeweb/controllers/web_hosting_controller/directory_listing.ex @@ -1,7 +1,8 @@ -defmodule ArchethicWeb.API.WebHostingController.DirectoryListing do +defmodule ArchethicWeb.AEWeb.WebHostingController.DirectoryListing do @moduledoc false - alias ArchethicWeb.API.WebHostingController.ReferenceTransaction + alias ArchethicWeb.AEWeb.DirListingView + alias ArchethicWeb.AEWeb.WebHostingController.ReferenceTransaction require Logger @@ -40,8 +41,9 @@ defmodule ArchethicWeb.API.WebHostingController.DirectoryListing do address ) - {:ok, Phoenix.View.render_to_iodata(ArchethicWeb.DirListingView, "index.html", assigns), - nil, mime_type, cached?, etag} + render = Phoenix.View.render_to_iodata(DirListingView, "index.html", assigns) + + {:ok, render, nil, mime_type, cached?, etag} end end diff --git a/lib/archethic_web/controllers/api/web_hosting_controller/reference_transaction.ex b/lib/archethic_web/aeweb/controllers/web_hosting_controller/reference_transaction.ex similarity index 97% rename from lib/archethic_web/controllers/api/web_hosting_controller/reference_transaction.ex rename to lib/archethic_web/aeweb/controllers/web_hosting_controller/reference_transaction.ex index bb240cb9f..e5c5a8c2b 100644 --- a/lib/archethic_web/controllers/api/web_hosting_controller/reference_transaction.ex +++ b/lib/archethic_web/aeweb/controllers/web_hosting_controller/reference_transaction.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.API.WebHostingController.ReferenceTransaction do +defmodule ArchethicWeb.AEWeb.WebHostingController.ReferenceTransaction do @moduledoc """ ReferenceTransaction is a subset of a transaction It is meant to be cached so we use a lighter structure diff --git a/lib/archethic_web/controllers/api/web_hosting_controller/resources.ex b/lib/archethic_web/aeweb/controllers/web_hosting_controller/resources.ex similarity index 98% rename from lib/archethic_web/controllers/api/web_hosting_controller/resources.ex rename to lib/archethic_web/aeweb/controllers/web_hosting_controller/resources.ex index d4f5ccd18..319072674 100644 --- a/lib/archethic_web/controllers/api/web_hosting_controller/resources.ex +++ b/lib/archethic_web/aeweb/controllers/web_hosting_controller/resources.ex @@ -1,9 +1,9 @@ -defmodule ArchethicWeb.API.WebHostingController.Resources do +defmodule ArchethicWeb.AEWeb.WebHostingController.Resources do @moduledoc false alias Archethic.TransactionChain.{Transaction, TransactionData} alias ArchethicCache.LRUDisk - alias ArchethicWeb.API.WebHostingController.ReferenceTransaction + alias ArchethicWeb.AEWeb.WebHostingController.ReferenceTransaction require Logger diff --git a/lib/archethic_web/aeweb/dnslink_router.ex b/lib/archethic_web/aeweb/dnslink_router.ex new file mode 100644 index 000000000..b25ae03ac --- /dev/null +++ b/lib/archethic_web/aeweb/dnslink_router.ex @@ -0,0 +1,31 @@ +defmodule ArchethicWeb.DNSLinkRouter do + @moduledoc """ + Catch dns link redirection for AEWeb and call WebHostingController + """ + + alias ArchethicWeb.AEWeb.Domain + alias ArchethicWeb.AEWeb.WebHostingController + + @behaviour Plug + + def init(opts), do: opts + + def call(conn = %Plug.Conn{host: host, method: "GET", path_info: url_path}, _) do + case get_dnslink_address(host) do + {:ok, address} -> + WebHostingController.web_hosting(conn, %{"address" => address, "url_path" => url_path}) + + _ -> + throw("No DNSLink defined") + end + end + + def call(_conn, _), do: throw("No DNSLink defined") + + defp get_dnslink_address(host) do + if is_ip_address?(host), do: {:error, :ip_address}, else: Domain.lookup_dnslink_address(host) + end + + defp is_ip_address?(host), + do: {:ok, _ip} |> match?(host |> String.to_charlist() |> :inet.parse_address()) +end diff --git a/lib/archethic_web/domain.ex b/lib/archethic_web/aeweb/domain.ex similarity index 96% rename from lib/archethic_web/domain.ex rename to lib/archethic_web/aeweb/domain.ex index f6ade4e51..2f25a723d 100644 --- a/lib/archethic_web/domain.ex +++ b/lib/archethic_web/aeweb/domain.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.Domain do +defmodule ArchethicWeb.AEWeb.Domain do @moduledoc """ Manage AEWeb domain logic """ @@ -6,7 +6,8 @@ defmodule ArchethicWeb.Domain do alias Archethic alias Archethic.Crypto alias Archethic.TransactionChain.TransactionData.Ownership - alias ArchethicWeb.API.WebHostingController.ReferenceTransaction + + alias ArchethicWeb.AEWeb.WebHostingController.ReferenceTransaction require Logger diff --git a/lib/archethic_web/templates/dir_listing/index.html.heex b/lib/archethic_web/aeweb/templates/dir_listing/index.html.heex similarity index 100% rename from lib/archethic_web/templates/dir_listing/index.html.heex rename to lib/archethic_web/aeweb/templates/dir_listing/index.html.heex diff --git a/lib/archethic_web/views/dir_listing_view.ex b/lib/archethic_web/aeweb/views/dir_listing_view.ex similarity index 88% rename from lib/archethic_web/views/dir_listing_view.ex rename to lib/archethic_web/aeweb/views/dir_listing_view.ex index 749fd5736..72394d831 100644 --- a/lib/archethic_web/views/dir_listing_view.ex +++ b/lib/archethic_web/aeweb/views/dir_listing_view.ex @@ -1,6 +1,6 @@ -defmodule ArchethicWeb.DirListingView do +defmodule ArchethicWeb.AEWeb.DirListingView do @moduledoc false - use ArchethicWeb, :view + use ArchethicWeb.AEWeb, :view @spec prepare_addresses(list(String.t())) :: list(map()) def prepare_addresses(addresses) do diff --git a/lib/archethic_web/aeweb_router.ex b/lib/archethic_web/aeweb_router.ex deleted file mode 100644 index 62fec3dd5..000000000 --- a/lib/archethic_web/aeweb_router.ex +++ /dev/null @@ -1,20 +0,0 @@ -defmodule ArchethicWeb.AEWebRouter do - @moduledoc false - - use ArchethicWeb, :router - - pipeline :browser do - plug(:accepts, ["html"]) - plug(:fetch_session) - plug(:fetch_live_flash) - plug(:put_secure_browser_headers) - plug(ArchethicWeb.PlugThrottleByIPHigh) - plug(ArchethicWeb.PlugThrottleByIPandPath) - end - - scope "/", ArchethicWeb do - pipe_through(:browser) - - get("/*url_path", AEWebRootController, :index) - end -end diff --git a/lib/archethic_web/api.ex b/lib/archethic_web/api.ex new file mode 100644 index 000000000..f2c6f928d --- /dev/null +++ b/lib/archethic_web/api.ex @@ -0,0 +1,25 @@ +defmodule ArchethicWeb.API do + @moduledoc false + + def controller do + quote do + use Phoenix.Controller, namespace: ArchethicWeb.API + + import Plug.Conn + end + end + + def router do + quote do + use Phoenix.Router + import Plug.Conn + end + end + + @doc """ + When used, dispatch to the appropriate controller/view/etc. + """ + defmacro __using__(which) when is_atom(which) do + apply(__MODULE__, which, []) + end +end diff --git a/lib/archethic_web/api/api_router.ex b/lib/archethic_web/api/api_router.ex new file mode 100644 index 000000000..43af7f9e7 --- /dev/null +++ b/lib/archethic_web/api/api_router.ex @@ -0,0 +1,43 @@ +defmodule ArchethicWeb.APIRouter do + @moduledoc false + + alias ArchethicWeb.API + alias ArchethicWeb.Plug.ThrottleByIPLow + + use ArchethicWeb.Explorer, :router + + pipeline :api do + plug(:accepts, ["json"]) + plug(ThrottleByIPLow) + plug(ArchethicWeb.API.GraphQL.Context) + end + + scope "/api", API do + pipe_through(:api) + + get("/last_transaction/:address/content", TransactionController, :last_transaction_content) + + post("/origin_key", OriginKeyController, :origin_key) + post("/transaction", TransactionController, :new) + post("/transaction_fee", TransactionController, :transaction_fee) + + post("/transaction/contract/simulator", TransactionController, :simulate_contract_execution) + end + + scope "/api" do + pipe_through(:api) + + forward( + "/graphiql", + Absinthe.Plug.GraphiQL, + schema: ArchethicWeb.API.GraphQL.Schema, + socket: ArchethicWeb.UserSocket + ) + + forward( + "/", + Absinthe.Plug, + schema: ArchethicWeb.API.GraphQL.Schema + ) + end +end diff --git a/lib/archethic_web/controllers/api/origin_key_controller.ex b/lib/archethic_web/api/controllers/origin_key_controller.ex similarity index 84% rename from lib/archethic_web/controllers/api/origin_key_controller.ex rename to lib/archethic_web/api/controllers/origin_key_controller.ex index 81c377db9..b5f9b1472 100644 --- a/lib/archethic_web/controllers/api/origin_key_controller.ex +++ b/lib/archethic_web/api/controllers/origin_key_controller.ex @@ -1,15 +1,15 @@ defmodule ArchethicWeb.API.OriginKeyController do - use ArchethicWeb, :controller + use ArchethicWeb.API, :controller - alias ArchethicWeb.{TransactionSubscriber, API.Schema.OriginPublicKey} + alias ArchethicWeb.API.Schema.OriginPublicKey - alias Archethic.{ - Crypto, - SharedSecrets, - TransactionChain, - TransactionChain.TransactionData, - TransactionChain.Transaction - } + alias ArchethicWeb.TransactionSubscriber + + alias Archethic.Crypto + alias Archethic.SharedSecrets + alias Archethic.TransactionChain + alias Archethic.TransactionChain.TransactionData + alias Archethic.TransactionChain.Transaction @spec origin_key(Plug.Conn.t(), map()) :: Plug.Conn.t() def origin_key(conn, params = %{}) do @@ -32,7 +32,7 @@ defmodule ArchethicWeb.API.OriginKeyController do changeset -> conn |> put_status(400) - |> put_view(ArchethicWeb.ErrorView) + |> put_view(ArchethicWeb.Explorer.ErrorView) |> render("400.json", changeset: changeset) end end diff --git a/lib/archethic_web/controllers/api/schema/authorized_key.ex b/lib/archethic_web/api/controllers/schema/authorized_key.ex similarity index 100% rename from lib/archethic_web/controllers/api/schema/authorized_key.ex rename to lib/archethic_web/api/controllers/schema/authorized_key.ex diff --git a/lib/archethic_web/controllers/api/schema/ledger.ex b/lib/archethic_web/api/controllers/schema/ledger.ex similarity index 100% rename from lib/archethic_web/controllers/api/schema/ledger.ex rename to lib/archethic_web/api/controllers/schema/ledger.ex diff --git a/lib/archethic_web/controllers/api/schema/origin_public_key.ex b/lib/archethic_web/api/controllers/schema/origin_public_key.ex similarity index 100% rename from lib/archethic_web/controllers/api/schema/origin_public_key.ex rename to lib/archethic_web/api/controllers/schema/origin_public_key.ex diff --git a/lib/archethic_web/controllers/api/schema/ownership.ex b/lib/archethic_web/api/controllers/schema/ownership.ex similarity index 100% rename from lib/archethic_web/controllers/api/schema/ownership.ex rename to lib/archethic_web/api/controllers/schema/ownership.ex diff --git a/lib/archethic_web/controllers/api/schema/token_ledger.ex b/lib/archethic_web/api/controllers/schema/token_ledger.ex similarity index 100% rename from lib/archethic_web/controllers/api/schema/token_ledger.ex rename to lib/archethic_web/api/controllers/schema/token_ledger.ex diff --git a/lib/archethic_web/controllers/api/schema/transaction_data.ex b/lib/archethic_web/api/controllers/schema/transaction_data.ex similarity index 100% rename from lib/archethic_web/controllers/api/schema/transaction_data.ex rename to lib/archethic_web/api/controllers/schema/transaction_data.ex diff --git a/lib/archethic_web/controllers/api/schema/uco_ledger.ex b/lib/archethic_web/api/controllers/schema/uco_ledger.ex similarity index 100% rename from lib/archethic_web/controllers/api/schema/uco_ledger.ex rename to lib/archethic_web/api/controllers/schema/uco_ledger.ex diff --git a/lib/archethic_web/controllers/api/transaction_controller.ex b/lib/archethic_web/api/controllers/transaction_controller.ex similarity index 96% rename from lib/archethic_web/controllers/api/transaction_controller.ex rename to lib/archethic_web/api/controllers/transaction_controller.ex index faf873636..2b33ae4c5 100644 --- a/lib/archethic_web/controllers/api/transaction_controller.ex +++ b/lib/archethic_web/api/controllers/transaction_controller.ex @@ -1,9 +1,7 @@ defmodule ArchethicWeb.API.TransactionController do @moduledoc false - use ArchethicWeb, :controller - - alias Archethic + use ArchethicWeb.API, :controller alias Archethic.TransactionChain.Transaction alias Archethic.TransactionChain.Transaction.ValidationStamp @@ -13,7 +11,7 @@ defmodule ArchethicWeb.API.TransactionController do alias Archethic.OracleChain alias ArchethicWeb.API.TransactionPayload - alias ArchethicWeb.ErrorView + alias ArchethicWeb.Explorer.ErrorView alias ArchethicWeb.TransactionSubscriber require Logger @@ -42,7 +40,7 @@ defmodule ArchethicWeb.API.TransactionController do changeset -> Logger.debug( - "Invalid transaction #{inspect(Ecto.Changeset.traverse_errors(changeset, &ArchethicWeb.ErrorHelpers.translate_error/1))}" + "Invalid transaction #{inspect(Ecto.Changeset.traverse_errors(changeset, &ArchethicWeb.WebUtils.translate_error/1))}" ) conn @@ -212,7 +210,10 @@ defmodule ArchethicWeb.API.TransactionController do changeset -> error_details = - Ecto.Changeset.traverse_errors(changeset, &ArchethicWeb.ErrorHelpers.translate_error/1) + Ecto.Changeset.traverse_errors( + changeset, + &ArchethicWeb.WebUtils.translate_error/1 + ) json_body = Map.merge(error_details, %{"valid" => false, "reason" => "Query validation failled"}) diff --git a/lib/archethic_web/controllers/api/transaction_payload.ex b/lib/archethic_web/api/controllers/transaction_payload.ex similarity index 100% rename from lib/archethic_web/controllers/api/transaction_payload.ex rename to lib/archethic_web/api/controllers/transaction_payload.ex diff --git a/lib/archethic_web/controllers/api/types/address.ex b/lib/archethic_web/api/controllers/types/address.ex similarity index 100% rename from lib/archethic_web/controllers/api/types/address.ex rename to lib/archethic_web/api/controllers/types/address.ex diff --git a/lib/archethic_web/controllers/api/types/address_list.ex b/lib/archethic_web/api/controllers/types/address_list.ex similarity index 100% rename from lib/archethic_web/controllers/api/types/address_list.ex rename to lib/archethic_web/api/controllers/types/address_list.ex diff --git a/lib/archethic_web/controllers/api/types/hex.ex b/lib/archethic_web/api/controllers/types/hex.ex similarity index 100% rename from lib/archethic_web/controllers/api/types/hex.ex rename to lib/archethic_web/api/controllers/types/hex.ex diff --git a/lib/archethic_web/controllers/api/types/public_key.ex b/lib/archethic_web/api/controllers/types/public_key.ex similarity index 100% rename from lib/archethic_web/controllers/api/types/public_key.ex rename to lib/archethic_web/api/controllers/types/public_key.ex diff --git a/lib/archethic_web/controllers/api/types/secret_list.ex b/lib/archethic_web/api/controllers/types/secret_list.ex similarity index 100% rename from lib/archethic_web/controllers/api/types/secret_list.ex rename to lib/archethic_web/api/controllers/types/secret_list.ex diff --git a/lib/archethic_web/controllers/api/types/transaction_type.ex b/lib/archethic_web/api/controllers/types/transaction_type.ex similarity index 100% rename from lib/archethic_web/controllers/api/types/transaction_type.ex rename to lib/archethic_web/api/controllers/types/transaction_type.ex diff --git a/lib/archethic_web/graphl_context.ex b/lib/archethic_web/api/graphql/context.ex similarity index 84% rename from lib/archethic_web/graphl_context.ex rename to lib/archethic_web/api/graphql/context.ex index 03e980c1c..97cd26e73 100644 --- a/lib/archethic_web/graphl_context.ex +++ b/lib/archethic_web/api/graphql/context.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLContext do +defmodule ArchethicWeb.API.GraphQL.Context do @moduledoc false @behaviour Plug diff --git a/lib/archethic_web/graphql_schema.ex b/lib/archethic_web/api/graphql/schema.ex similarity index 99% rename from lib/archethic_web/graphql_schema.ex rename to lib/archethic_web/api/graphql/schema.ex index 71759217b..73f60804a 100644 --- a/lib/archethic_web/graphql_schema.ex +++ b/lib/archethic_web/api/graphql/schema.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema do +defmodule ArchethicWeb.API.GraphQL.Schema do @moduledoc false use Absinthe.Schema diff --git a/lib/archethic_web/graphql_schema/address_type.ex b/lib/archethic_web/api/graphql/schema/address_type.ex similarity index 93% rename from lib/archethic_web/graphql_schema/address_type.ex rename to lib/archethic_web/api/graphql/schema/address_type.ex index fbcbf08a7..03a930f19 100644 --- a/lib/archethic_web/graphql_schema/address_type.ex +++ b/lib/archethic_web/api/graphql/schema/address_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.AddressType do +defmodule ArchethicWeb.API.GraphQL.Schema.AddressType do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/beacon_chain_summary_type.ex b/lib/archethic_web/api/graphql/schema/beacon_chain_summary_type.ex similarity index 96% rename from lib/archethic_web/graphql_schema/beacon_chain_summary_type.ex rename to lib/archethic_web/api/graphql/schema/beacon_chain_summary_type.ex index d06333e8e..eeef40cd1 100644 --- a/lib/archethic_web/graphql_schema/beacon_chain_summary_type.ex +++ b/lib/archethic_web/api/graphql/schema/beacon_chain_summary_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.BeaconChainSummary do +defmodule ArchethicWeb.API.GraphQL.Schema.BeaconChainSummary do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/content_type.ex b/lib/archethic_web/api/graphql/schema/content_type.ex similarity index 88% rename from lib/archethic_web/graphql_schema/content_type.ex rename to lib/archethic_web/api/graphql/schema/content_type.ex index c6ffe2784..f47a12377 100644 --- a/lib/archethic_web/graphql_schema/content_type.ex +++ b/lib/archethic_web/api/graphql/schema/content_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.ContentType do +defmodule ArchethicWeb.API.GraphQL.Schema.ContentType do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/datetime_type.ex b/lib/archethic_web/api/graphql/schema/datetime_type.ex similarity index 91% rename from lib/archethic_web/graphql_schema/datetime_type.ex rename to lib/archethic_web/api/graphql/schema/datetime_type.ex index 1b2efa2e5..d568b55b0 100644 --- a/lib/archethic_web/graphql_schema/datetime_type.ex +++ b/lib/archethic_web/api/graphql/schema/datetime_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.DateTimeType do +defmodule ArchethicWeb.API.GraphQL.Schema.DateTimeType do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/hash_type.ex b/lib/archethic_web/api/graphql/schema/hash_type.ex similarity index 94% rename from lib/archethic_web/graphql_schema/hash_type.ex rename to lib/archethic_web/api/graphql/schema/hash_type.ex index c36c70730..ee09f8909 100644 --- a/lib/archethic_web/graphql_schema/hash_type.ex +++ b/lib/archethic_web/api/graphql/schema/hash_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.HashType do +defmodule ArchethicWeb.API.GraphQL.Schema.HashType do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/hex_type.ex b/lib/archethic_web/api/graphql/schema/hex_type.ex similarity index 80% rename from lib/archethic_web/graphql_schema/hex_type.ex rename to lib/archethic_web/api/graphql/schema/hex_type.ex index 2707ac4aa..d05855b73 100644 --- a/lib/archethic_web/graphql_schema/hex_type.ex +++ b/lib/archethic_web/api/graphql/schema/hex_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.HexType do +defmodule ArchethicWeb.API.GraphQL.Schema.HexType do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/integer_type.ex b/lib/archethic_web/api/graphql/schema/integer_type.ex similarity index 92% rename from lib/archethic_web/graphql_schema/integer_type.ex rename to lib/archethic_web/api/graphql/schema/integer_type.ex index 05d8b4626..297ef590a 100644 --- a/lib/archethic_web/graphql_schema/integer_type.ex +++ b/lib/archethic_web/api/graphql/schema/integer_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.IntegerType do +defmodule ArchethicWeb.API.GraphQL.Schema.IntegerType do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/oracle_data.ex b/lib/archethic_web/api/graphql/schema/oracle_data.ex similarity index 86% rename from lib/archethic_web/graphql_schema/oracle_data.ex rename to lib/archethic_web/api/graphql/schema/oracle_data.ex index 0a3743ba7..48fd08d78 100644 --- a/lib/archethic_web/graphql_schema/oracle_data.ex +++ b/lib/archethic_web/api/graphql/schema/oracle_data.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.OracleData do +defmodule ArchethicWeb.API.GraphQL.Schema.OracleData do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/p2p_type.ex b/lib/archethic_web/api/graphql/schema/p2p_type.ex similarity index 93% rename from lib/archethic_web/graphql_schema/p2p_type.ex rename to lib/archethic_web/api/graphql/schema/p2p_type.ex index adbc7320b..b841295de 100644 --- a/lib/archethic_web/graphql_schema/p2p_type.ex +++ b/lib/archethic_web/api/graphql/schema/p2p_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.P2PType do +defmodule ArchethicWeb.API.GraphQL.Schema.P2PType do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/public_key_type.ex b/lib/archethic_web/api/graphql/schema/public_key_type.ex similarity index 93% rename from lib/archethic_web/graphql_schema/public_key_type.ex rename to lib/archethic_web/api/graphql/schema/public_key_type.ex index d4806c359..5ae85e58a 100644 --- a/lib/archethic_web/graphql_schema/public_key_type.ex +++ b/lib/archethic_web/api/graphql/schema/public_key_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.PublicKeyType do +defmodule ArchethicWeb.API.GraphQL.Schema.PublicKeyType do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/resolver.ex b/lib/archethic_web/api/graphql/schema/resolver.ex similarity index 99% rename from lib/archethic_web/graphql_schema/resolver.ex rename to lib/archethic_web/api/graphql/schema/resolver.ex index 08aa9b166..b996dffa8 100644 --- a/lib/archethic_web/graphql_schema/resolver.ex +++ b/lib/archethic_web/api/graphql/schema/resolver.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.Resolver do +defmodule ArchethicWeb.API.GraphQL.Schema.Resolver do @moduledoc false alias Archethic diff --git a/lib/archethic_web/graphql_schema/shared_secrets_type.ex b/lib/archethic_web/api/graphql/schema/shared_secrets_type.ex similarity index 86% rename from lib/archethic_web/graphql_schema/shared_secrets_type.ex rename to lib/archethic_web/api/graphql/schema/shared_secrets_type.ex index 749075e71..43f21139d 100644 --- a/lib/archethic_web/graphql_schema/shared_secrets_type.ex +++ b/lib/archethic_web/api/graphql/schema/shared_secrets_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.SharedSecretsType do +defmodule ArchethicWeb.API.GraphQL.Schema.SharedSecretsType do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/sort_order_enum.ex b/lib/archethic_web/api/graphql/schema/sort_order_enum.ex similarity index 82% rename from lib/archethic_web/graphql_schema/sort_order_enum.ex rename to lib/archethic_web/api/graphql/schema/sort_order_enum.ex index 386942694..fe67d5826 100644 --- a/lib/archethic_web/graphql_schema/sort_order_enum.ex +++ b/lib/archethic_web/api/graphql/schema/sort_order_enum.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.SortOrderEnum do +defmodule ArchethicWeb.API.GraphQL.Schema.SortOrderEnum do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/transaction_attestation.ex b/lib/archethic_web/api/graphql/schema/transaction_attestation.ex similarity index 86% rename from lib/archethic_web/graphql_schema/transaction_attestation.ex rename to lib/archethic_web/api/graphql/schema/transaction_attestation.ex index 58f7b19df..d13744ac1 100644 --- a/lib/archethic_web/graphql_schema/transaction_attestation.ex +++ b/lib/archethic_web/api/graphql/schema/transaction_attestation.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.TransactionAttestation do +defmodule ArchethicWeb.API.GraphQL.Schema.TransactionAttestation do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/transaction_error.ex b/lib/archethic_web/api/graphql/schema/transaction_error.ex similarity index 87% rename from lib/archethic_web/graphql_schema/transaction_error.ex rename to lib/archethic_web/api/graphql/schema/transaction_error.ex index fa74647e0..0a3f5625b 100644 --- a/lib/archethic_web/graphql_schema/transaction_error.ex +++ b/lib/archethic_web/api/graphql/schema/transaction_error.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.TransactionError do +defmodule ArchethicWeb.API.GraphQL.Schema.TransactionError do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/graphql_schema/transaction_type.ex b/lib/archethic_web/api/graphql/schema/transaction_type.ex similarity index 98% rename from lib/archethic_web/graphql_schema/transaction_type.ex rename to lib/archethic_web/api/graphql/schema/transaction_type.ex index d49f7023d..8f3d427fa 100644 --- a/lib/archethic_web/graphql_schema/transaction_type.ex +++ b/lib/archethic_web/api/graphql/schema/transaction_type.ex @@ -1,9 +1,9 @@ -defmodule ArchethicWeb.GraphQLSchema.TransactionType do +defmodule ArchethicWeb.API.GraphQL.Schema.TransactionType do @moduledoc false use Absinthe.Schema.Notation - alias ArchethicWeb.GraphQLSchema.Resolver + alias ArchethicWeb.API.GraphQL.Schema.Resolver alias Archethic.TransactionChain.Transaction diff --git a/lib/archethic_web/graphql_schema/version_type.ex b/lib/archethic_web/api/graphql/schema/version_type.ex similarity index 82% rename from lib/archethic_web/graphql_schema/version_type.ex rename to lib/archethic_web/api/graphql/schema/version_type.ex index a0ba9986f..8e26e0ba1 100644 --- a/lib/archethic_web/graphql_schema/version_type.ex +++ b/lib/archethic_web/api/graphql/schema/version_type.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.GraphQLSchema.Version do +defmodule ArchethicWeb.API.GraphQL.Schema.Version do @moduledoc false use Absinthe.Schema.Notation diff --git a/lib/archethic_web/controllers/aeweb_root_controller.ex b/lib/archethic_web/controllers/aeweb_root_controller.ex deleted file mode 100644 index c88c3764f..000000000 --- a/lib/archethic_web/controllers/aeweb_root_controller.ex +++ /dev/null @@ -1,11 +0,0 @@ -defmodule ArchethicWeb.AEWebRootController do - @moduledoc false - - alias ArchethicWeb.API.WebHostingController - - use ArchethicWeb, :controller - - def index(conn, params) do - WebHostingController.web_hosting(conn, params) - end -end diff --git a/lib/archethic_web/endpoint.ex b/lib/archethic_web/endpoint.ex index 6e6db3d96..ecd416442 100644 --- a/lib/archethic_web/endpoint.ex +++ b/lib/archethic_web/endpoint.ex @@ -1,14 +1,20 @@ defmodule ArchethicWeb.Endpoint do @moduledoc false - use Phoenix.Endpoint, otp_app: :archethic - use Absinthe.Phoenix.Endpoint + alias ArchethicWeb.Plugs.ArchethicUp + alias ArchethicWeb.Plugs.RemoteIP + alias ArchethicWeb.RouterDispatch - require Logger + alias ArchethicWeb.AEWebRouter + alias ArchethicWeb.APIRouter + alias ArchethicWeb.DNSLinkRouter + alias ArchethicWeb.ExplorerRouter - plug(:archethic_up) + use Phoenix.Endpoint, otp_app: :archethic + use Absinthe.Phoenix.Endpoint - plug(ArchethicWeb.Plugs.RemoteIP) + plug(ArchethicUp) + plug(RemoteIP) # The session will be stored in the cookie and signed, # this means its contents can be read but not tampered with. @@ -56,22 +62,6 @@ defmodule ArchethicWeb.Endpoint do plug(Plug.Head) plug(Plug.Session, @session_options) plug(CORSPlug, origin: "*") - plug(ArchethicWeb.RouterDispatch) - # don't serve anything before the node is bootstraped - # - # ps: this handle only HTTP(S) requests - # for WS, see archethic_web/channels/user_socket.ex - defp archethic_up(conn, _opts) do - request_path = Map.get(conn, :request_path, nil) - - if request_path in ["/metrics", "/metrics/"] or Archethic.up?() do - conn - else - Logger.debug("Received a web request but node is bootstraping") - conn - |> send_resp(503, "") - |> halt() - end - end + plug(RouterDispatch, routers: [DNSLinkRouter, AEWebRouter, APIRouter, ExplorerRouter]) end diff --git a/lib/archethic_web.ex b/lib/archethic_web/explorer.ex similarity index 78% rename from lib/archethic_web.ex rename to lib/archethic_web/explorer.ex index d8aae8be1..7244ac0be 100644 --- a/lib/archethic_web.ex +++ b/lib/archethic_web/explorer.ex @@ -1,9 +1,9 @@ -defmodule ArchethicWeb do +defmodule ArchethicWeb.Explorer do @moduledoc false def controller do quote do - use Phoenix.Controller, namespace: ArchethicWeb + use Phoenix.Controller, namespace: ArchethicWeb.Explorer import Plug.Conn import Phoenix.LiveView.Controller @@ -14,8 +14,8 @@ defmodule ArchethicWeb do def view do quote do use Phoenix.View, - root: "lib/archethic_web/templates", - namespace: ArchethicWeb + root: "lib/archethic_web/explorer/templates", + namespace: ArchethicWeb.Explorer # Import convenience functions from controllers import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1] @@ -28,7 +28,7 @@ defmodule ArchethicWeb do def live_view do quote do use Phoenix.LiveView, - layout: {ArchethicWeb.LayoutView, :live} + layout: {ArchethicWeb.Explorer.LayoutView, :live} unquote(view_helpers()) end @@ -53,8 +53,7 @@ defmodule ArchethicWeb do # Import basic rendering functionality (render, render_layout, etc) import Phoenix.View - import ArchethicWeb.ErrorHelpers - import ArchethicWeb.LayoutHelpers + import ArchethicWeb.WebUtils alias ArchethicWeb.ExplorerRouter.Helpers, as: Routes end @@ -64,14 +63,8 @@ defmodule ArchethicWeb do quote do use Phoenix.Router import Plug.Conn - import Phoenix.Controller import Phoenix.LiveView.Router - end - end - - def channel do - quote do - use Phoenix.Channel + import Phoenix.LiveDashboard.Router end end diff --git a/lib/archethic_web/components/pagination.ex b/lib/archethic_web/explorer/components/pagination.ex similarity index 95% rename from lib/archethic_web/components/pagination.ex rename to lib/archethic_web/explorer/components/pagination.ex index e8a993829..7818b0987 100644 --- a/lib/archethic_web/components/pagination.ex +++ b/lib/archethic_web/explorer/components/pagination.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.Pagination do +defmodule ArchethicWeb.Explorer.Pagination do @moduledoc false use Phoenix.Component diff --git a/lib/archethic_web/controllers/code_controller.ex b/lib/archethic_web/explorer/controllers/code_controller.ex similarity index 86% rename from lib/archethic_web/controllers/code_controller.ex rename to lib/archethic_web/explorer/controllers/code_controller.ex index 66d3cb604..20b8fcc50 100644 --- a/lib/archethic_web/controllers/code_controller.ex +++ b/lib/archethic_web/explorer/controllers/code_controller.ex @@ -1,11 +1,11 @@ -defmodule ArchethicWeb.CodeController do +defmodule ArchethicWeb.Explorer.CodeController do @moduledoc false - use ArchethicWeb, :controller + use ArchethicWeb.Explorer, :controller # alias Archethic.TransactionChain - # alias ArchethicWeb.CodeProposalDetailsLive - # alias ArchethicWeb.ExplorerView + # alias ArchethicWeb.Explorer.CodeProposalDetailsLive + # alias ArchethicWeb.Explorer.ExplorerView @src_dir Application.compile_env(:archethic, :src_dir) diff --git a/lib/archethic_web/controllers/explorer_controller.ex b/lib/archethic_web/explorer/controllers/explorer_controller.ex similarity index 76% rename from lib/archethic_web/controllers/explorer_controller.ex rename to lib/archethic_web/explorer/controllers/explorer_controller.ex index 48f71969f..6becfd872 100644 --- a/lib/archethic_web/controllers/explorer_controller.ex +++ b/lib/archethic_web/explorer/controllers/explorer_controller.ex @@ -1,13 +1,13 @@ -defmodule ArchethicWeb.ExplorerController do +defmodule ArchethicWeb.Explorer.ExplorerController do @moduledoc false - use ArchethicWeb, :controller + use ArchethicWeb.Explorer, :controller alias Archethic.Crypto alias Archethic.TransactionChain.Transaction def index(conn, _params) do - render(conn, "index.html", layout: {ArchethicWeb.LayoutView, "index.html"}) + render(conn, "index.html", layout: {ArchethicWeb.Explorer.LayoutView, "index.html"}) end def search(conn, _params = %{"address" => address}) do diff --git a/lib/archethic_web/controllers/explorer_root_controller.ex b/lib/archethic_web/explorer/controllers/explorer_root_controller.ex similarity index 88% rename from lib/archethic_web/controllers/explorer_root_controller.ex rename to lib/archethic_web/explorer/controllers/explorer_root_controller.ex index 19e52cac4..b0bebd2d0 100644 --- a/lib/archethic_web/controllers/explorer_root_controller.ex +++ b/lib/archethic_web/explorer/controllers/explorer_root_controller.ex @@ -1,7 +1,7 @@ -defmodule ArchethicWeb.ExplorerRootController do +defmodule ArchethicWeb.Explorer.ExplorerRootController do @moduledoc false - use ArchethicWeb, :controller + use ArchethicWeb.Explorer, :controller # def index(conn, _params), do: redirect(conn, to: "/explorer") def index(conn, _params) do diff --git a/lib/archethic_web/controllers/faucet_controller.ex b/lib/archethic_web/explorer/controllers/faucet_controller.ex similarity index 90% rename from lib/archethic_web/controllers/faucet_controller.ex rename to lib/archethic_web/explorer/controllers/faucet_controller.ex index 74e04ecf3..9151c61ec 100644 --- a/lib/archethic_web/controllers/faucet_controller.ex +++ b/lib/archethic_web/explorer/controllers/faucet_controller.ex @@ -1,19 +1,17 @@ -defmodule ArchethicWeb.FaucetController do +defmodule ArchethicWeb.Explorer.FaucetController do @moduledoc false - use ArchethicWeb, :controller + use ArchethicWeb.Explorer, :controller alias Archethic.Crypto - alias Archethic.TransactionChain.{ - Transaction, - TransactionData, - TransactionData.Ledger, - TransactionData.UCOLedger - } + alias Archethic.TransactionChain.Transaction + alias Archethic.TransactionChain.TransactionData + alias Archethic.TransactionChain.TransactionData.Ledger + alias Archethic.TransactionChain.TransactionData.UCOLedger alias ArchethicWeb.TransactionSubscriber - alias ArchethicWeb.FaucetRateLimiter + alias ArchethicWeb.Explorer.FaucetRateLimiter @pool_seed Application.compile_env(:archethic, [__MODULE__, :seed]) @faucet_rate_limit_expiry Application.compile_env(:archethic, :faucet_rate_limit_expiry) @@ -26,7 +24,7 @@ defmodule ArchethicWeb.FaucetController do else conn |> put_status(:not_found) - |> put_view(ArchethicWeb.ErrorView) + |> put_view(ArchethicWeb.Explorer.ErrorView) |> render("404.html") |> halt() end diff --git a/lib/archethic_web/controllers/metrics_controller.ex b/lib/archethic_web/explorer/controllers/metrics_controller.ex similarity index 67% rename from lib/archethic_web/controllers/metrics_controller.ex rename to lib/archethic_web/explorer/controllers/metrics_controller.ex index 069b05187..f36ac1777 100644 --- a/lib/archethic_web/controllers/metrics_controller.ex +++ b/lib/archethic_web/explorer/controllers/metrics_controller.ex @@ -1,6 +1,6 @@ -defmodule ArchethicWeb.MetricsController do +defmodule ArchethicWeb.Explorer.MetricsController do alias TelemetryMetricsPrometheus.Core - use ArchethicWeb, :controller + use ArchethicWeb.Explorer, :controller def index(conn, _params) do metrics = Core.scrape() diff --git a/lib/archethic_web/controllers/up_controller.ex b/lib/archethic_web/explorer/controllers/up_controller.ex similarity index 65% rename from lib/archethic_web/controllers/up_controller.ex rename to lib/archethic_web/explorer/controllers/up_controller.ex index f56ca892b..a263cbc3c 100644 --- a/lib/archethic_web/controllers/up_controller.ex +++ b/lib/archethic_web/explorer/controllers/up_controller.ex @@ -1,7 +1,7 @@ -defmodule ArchethicWeb.UpController do +defmodule ArchethicWeb.Explorer.UpController do @moduledoc false - use ArchethicWeb, :controller + use ArchethicWeb.Explorer, :controller @doc """ The logic to respond 503 when node is not bootstraped is moved in a plug diff --git a/lib/archethic_web/explorer_router.ex b/lib/archethic_web/explorer/explorer_router.ex similarity index 52% rename from lib/archethic_web/explorer_router.ex rename to lib/archethic_web/explorer/explorer_router.ex index bf710ca2c..7553d361b 100644 --- a/lib/archethic_web/explorer_router.ex +++ b/lib/archethic_web/explorer/explorer_router.ex @@ -1,8 +1,11 @@ defmodule ArchethicWeb.ExplorerRouter do @moduledoc false - use ArchethicWeb, :router - import Phoenix.LiveDashboard.Router + alias ArchethicWeb.Explorer + + alias ArchethicWeb.Plug.ThrottleByIPLow + + use ArchethicWeb.Explorer, :router pipeline :browser do plug(:accepts, ["html"]) @@ -10,23 +13,11 @@ defmodule ArchethicWeb.ExplorerRouter do plug(:fetch_live_flash) plug(:protect_from_forgery) plug(:put_secure_browser_headers) - plug(ArchethicWeb.PlugThrottleByIPLow) - plug(:put_root_layout, {ArchethicWeb.LayoutView, :root}) - end - - pipeline :api do - plug(:accepts, ["json"]) - plug(ArchethicWeb.PlugThrottleByIPLow) - plug(ArchethicWeb.GraphQLContext) - end - - pipeline :unrestricted_api do - plug(:accepts, ["json"]) - plug(ArchethicWeb.PlugThrottleByIPHigh) - plug(ArchethicWeb.PlugThrottleByIPandPath) + plug(ThrottleByIPLow) + plug(:put_root_layout, {Explorer.LayoutView, :root}) end - scope "/", ArchethicWeb do + scope "/", Explorer do pipe_through(:browser) get("/", ExplorerRootController, :index) @@ -47,7 +38,7 @@ defmodule ArchethicWeb.ExplorerRouter do post("/faucet", FaucetController, :create_transfer) end - scope "/explorer", ArchethicWeb do + scope "/explorer", Explorer do pipe_through(:browser) live("/", ExplorerIndexLive) @@ -72,50 +63,12 @@ defmodule ArchethicWeb.ExplorerRouter do get("/code/download", CodeController, :download) end - scope "/api" do - pipe_through(:unrestricted_api) - get("/web_hosting/:address/*url_path", ArchethicWeb.API.WebHostingController, :web_hosting) - end - - scope "/api" do - pipe_through(:api) - - get( - "/last_transaction/:address/content", - ArchethicWeb.API.TransactionController, - :last_transaction_content - ) - - post("/origin_key", ArchethicWeb.API.OriginKeyController, :origin_key) - post("/transaction", ArchethicWeb.API.TransactionController, :new) - post("/transaction_fee", ArchethicWeb.API.TransactionController, :transaction_fee) - - post( - "/transaction/contract/simulator", - ArchethicWeb.API.TransactionController, - :simulate_contract_execution - ) - - forward( - "/graphiql", - Absinthe.Plug.GraphiQL, - schema: ArchethicWeb.GraphQLSchema, - socket: ArchethicWeb.UserSocket - ) - - forward( - "/", - Absinthe.Plug, - schema: ArchethicWeb.GraphQLSchema - ) - end - live_session :settings, session: {ArchethicWeb.WebUtils, :keep_remote_ip, []} do pipe_through(:browser) - live("/settings", ArchethicWeb.SettingsLive) + live("/settings", ArchethicWeb.Explorer.SettingsLive) end - scope "/", ArchethicWeb do + scope "/", Explorer do get("/*path", ExplorerRootController, :index) post("/*path", ExplorerRootController, :return_404) end diff --git a/lib/archethic_web/faucet_rate_limiter.ex b/lib/archethic_web/explorer/faucet_rate_limiter.ex similarity index 98% rename from lib/archethic_web/faucet_rate_limiter.ex rename to lib/archethic_web/explorer/faucet_rate_limiter.ex index 3cc4c6bc2..81e77538c 100644 --- a/lib/archethic_web/faucet_rate_limiter.ex +++ b/lib/archethic_web/explorer/faucet_rate_limiter.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.FaucetRateLimiter do +defmodule ArchethicWeb.Explorer.FaucetRateLimiter do @moduledoc false use GenServer diff --git a/lib/archethic_web/live/chains/beacon_live.ex b/lib/archethic_web/explorer/live/chains/beacon_live.ex similarity index 97% rename from lib/archethic_web/live/chains/beacon_live.ex rename to lib/archethic_web/explorer/live/chains/beacon_live.ex index 517e2de54..01cf38872 100644 --- a/lib/archethic_web/live/chains/beacon_live.ex +++ b/lib/archethic_web/explorer/live/chains/beacon_live.ex @@ -1,6 +1,6 @@ -defmodule ArchethicWeb.BeaconChainLive do +defmodule ArchethicWeb.Explorer.BeaconChainLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Archethic.BeaconChain alias Archethic.BeaconChain.SummaryAggregate @@ -11,8 +11,8 @@ defmodule ArchethicWeb.BeaconChainLive do alias Archethic.PubSub alias Archethic.TransactionChain.TransactionSummary - alias ArchethicWeb.ExplorerView - alias ArchethicWeb.TransactionCache + alias ArchethicWeb.Explorer.ExplorerView + alias ArchethicWeb.Explorer.TransactionCache alias Phoenix.View diff --git a/lib/archethic_web/live/chains/cache.ex b/lib/archethic_web/explorer/live/chains/cache.ex similarity index 97% rename from lib/archethic_web/live/chains/cache.ex rename to lib/archethic_web/explorer/live/chains/cache.ex index d7b69500a..5c4dcafc7 100644 --- a/lib/archethic_web/live/chains/cache.ex +++ b/lib/archethic_web/explorer/live/chains/cache.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.TransactionCache do +defmodule ArchethicWeb.Explorer.TransactionCache do @table :transactions # 5 minutes @default_time 5 * 60 * 1000 diff --git a/lib/archethic_web/live/chains/node_shared_secrets_live.ex b/lib/archethic_web/explorer/live/chains/node_shared_secrets_live.ex similarity index 91% rename from lib/archethic_web/live/chains/node_shared_secrets_live.ex rename to lib/archethic_web/explorer/live/chains/node_shared_secrets_live.ex index f26092d37..2401ce40e 100644 --- a/lib/archethic_web/live/chains/node_shared_secrets_live.ex +++ b/lib/archethic_web/explorer/live/chains/node_shared_secrets_live.ex @@ -1,19 +1,20 @@ -defmodule ArchethicWeb.NodeSharedSecretsChainLive do +defmodule ArchethicWeb.Explorer.NodeSharedSecretsChainLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view - alias Archethic.{ - TransactionChain, - TransactionChain.Transaction, - TransactionChain.TransactionData, - TransactionChain.TransactionData.Ownership, - PubSub, - SharedSecrets - } + alias Archethic.TransactionChain + alias Archethic.TransactionChain.Transaction + alias Archethic.TransactionChain.TransactionData + alias Archethic.TransactionChain.TransactionData.Ownership + alias Archethic.PubSub + alias Archethic.SharedSecrets - alias ArchethicWeb.{ExplorerView, WebUtils} - alias Phoenix.{LiveView, View} + alias ArchethicWeb.Explorer.ExplorerView + alias ArchethicWeb.WebUtils + + alias Phoenix.LiveView + alias Phoenix.View @display_limit 10 @txn_type :node_shared_secrets diff --git a/lib/archethic_web/live/chains/oracle_live.ex b/lib/archethic_web/explorer/live/chains/oracle_live.ex similarity index 97% rename from lib/archethic_web/live/chains/oracle_live.ex rename to lib/archethic_web/explorer/live/chains/oracle_live.ex index e461f583b..cdd8ba1f9 100644 --- a/lib/archethic_web/live/chains/oracle_live.ex +++ b/lib/archethic_web/explorer/live/chains/oracle_live.ex @@ -1,7 +1,7 @@ -defmodule ArchethicWeb.OracleChainLive do +defmodule ArchethicWeb.Explorer.OracleChainLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Archethic.Crypto @@ -17,7 +17,7 @@ defmodule ArchethicWeb.OracleChainLive do alias Archethic.TransactionChain.Transaction.ValidationStamp alias Archethic.TransactionChain.TransactionData - alias ArchethicWeb.ExplorerView + alias ArchethicWeb.Explorer.ExplorerView alias Phoenix.View diff --git a/lib/archethic_web/live/chains/origin_live.ex b/lib/archethic_web/explorer/live/chains/origin_live.ex similarity index 89% rename from lib/archethic_web/live/chains/origin_live.ex rename to lib/archethic_web/explorer/live/chains/origin_live.ex index 8d6f58893..f40828819 100644 --- a/lib/archethic_web/live/chains/origin_live.ex +++ b/lib/archethic_web/explorer/live/chains/origin_live.ex @@ -1,19 +1,20 @@ -defmodule ArchethicWeb.OriginChainLive do +defmodule ArchethicWeb.Explorer.OriginChainLive do @moduledoc false - use ArchethicWeb, :live_view - - alias Archethic.{ - TransactionChain, - TransactionChain.Transaction, - TransactionChain.TransactionData, - TransactionChain.Transaction.ValidationStamp, - PubSub, - SharedSecrets, - Utils - } - - alias ArchethicWeb.{ExplorerView, WebUtils} - alias Phoenix.{LiveView, View} + use ArchethicWeb.Explorer, :live_view + + alias Archethic.TransactionChain + alias Archethic.TransactionChain.Transaction + alias Archethic.TransactionChain.TransactionData + alias Archethic.TransactionChain.Transaction.ValidationStamp + alias Archethic.PubSub + alias Archethic.SharedSecrets + alias Archethic.Utils + + alias ArchethicWeb.Explorer.ExplorerView + alias ArchethicWeb.WebUtils + + alias Phoenix.LiveView + alias Phoenix.View @display_limit 10 @txn_type :origin diff --git a/lib/archethic_web/live/chains/reward_live.ex b/lib/archethic_web/explorer/live/chains/reward_live.ex similarity index 94% rename from lib/archethic_web/live/chains/reward_live.ex rename to lib/archethic_web/explorer/live/chains/reward_live.ex index f0250ae62..2a6b2e972 100644 --- a/lib/archethic_web/live/chains/reward_live.ex +++ b/lib/archethic_web/explorer/live/chains/reward_live.ex @@ -1,16 +1,16 @@ -defmodule ArchethicWeb.RewardChainLive do +defmodule ArchethicWeb.Explorer.RewardChainLive do @moduledoc false - alias Archethic.{ - TransactionChain, - PubSub, - Reward - } + use ArchethicWeb.Explorer, :live_view - use ArchethicWeb, :live_view + alias Archethic.TransactionChain + alias Archethic.PubSub + alias Archethic.Reward - alias ArchethicWeb.{ExplorerView, WebUtils} - alias Phoenix.{View} + alias ArchethicWeb.Explorer.ExplorerView + alias ArchethicWeb.WebUtils + + alias Phoenix.View @display_limit 10 diff --git a/lib/archethic_web/live/chains/transaction_live.ex b/lib/archethic_web/explorer/live/chains/transaction_live.ex similarity index 96% rename from lib/archethic_web/live/chains/transaction_live.ex rename to lib/archethic_web/explorer/live/chains/transaction_live.ex index bbf00cdac..c919741e8 100644 --- a/lib/archethic_web/live/chains/transaction_live.ex +++ b/lib/archethic_web/explorer/live/chains/transaction_live.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.TransactionChainLive do +defmodule ArchethicWeb.Explorer.TransactionChainLive do @moduledoc """ Displays the transaction chain (all transactions in the chain) of an address. User can type any address part of the chain. We will always fetch from the latest transaction DESC. @@ -8,12 +8,12 @@ defmodule ArchethicWeb.TransactionChainLive do We use instead the address of the last transaction loaded for the pagination. """ - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Archethic.Crypto alias Archethic.OracleChain - alias ArchethicWeb.{ExplorerView} + alias ArchethicWeb.Explorer.{ExplorerView} alias Phoenix.{View} diff --git a/lib/archethic_web/live/code_proposal_chat_live.ex b/lib/archethic_web/explorer/live/code_proposal_chat_live.ex similarity index 93% rename from lib/archethic_web/live/code_proposal_chat_live.ex rename to lib/archethic_web/explorer/live/code_proposal_chat_live.ex index 30216b9ad..7ce5bbef2 100644 --- a/lib/archethic_web/live/code_proposal_chat_live.ex +++ b/lib/archethic_web/explorer/live/code_proposal_chat_live.ex @@ -1,6 +1,6 @@ -defmodule ArchethicWeb.CodeProposalChatLive do +defmodule ArchethicWeb.Explorer.CodeProposalChatLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view # alias Archethic.P2P # alias Archethic.P2P.Message.NewChatProposal @@ -10,7 +10,7 @@ defmodule ArchethicWeb.CodeProposalChatLive do alias Phoenix.View - alias ArchethicWeb.CodeView + alias ArchethicWeb.Explorer.CodeView alias ArchethicWeb.Endpoint def mount(_params, %{"proposal_address" => proposal_address}, socket) do diff --git a/lib/archethic_web/live/code_proposal_details_live.ex b/lib/archethic_web/explorer/live/code_proposal_details_live.ex similarity index 94% rename from lib/archethic_web/live/code_proposal_details_live.ex rename to lib/archethic_web/explorer/live/code_proposal_details_live.ex index 7e7411b37..2b643728a 100644 --- a/lib/archethic_web/live/code_proposal_details_live.ex +++ b/lib/archethic_web/explorer/live/code_proposal_details_live.ex @@ -1,6 +1,6 @@ -defmodule ArchethicWeb.CodeProposalDetailsLive do +defmodule ArchethicWeb.Explorer.CodeProposalDetailsLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Phoenix.View @@ -11,7 +11,7 @@ defmodule ArchethicWeb.CodeProposalDetailsLive do alias Archethic.PubSub - alias ArchethicWeb.CodeView + alias ArchethicWeb.Explorer.CodeView def mount(%{"address" => address}, _params, socket) do if connected?(socket) do diff --git a/lib/archethic_web/live/code_proposals_live.ex b/lib/archethic_web/explorer/live/code_proposals_live.ex similarity index 82% rename from lib/archethic_web/live/code_proposals_live.ex rename to lib/archethic_web/explorer/live/code_proposals_live.ex index 461c0dee7..3dfe4272f 100644 --- a/lib/archethic_web/live/code_proposals_live.ex +++ b/lib/archethic_web/explorer/live/code_proposals_live.ex @@ -1,6 +1,6 @@ -defmodule ArchethicWeb.CodeProposalsLive do +defmodule ArchethicWeb.Explorer.CodeProposalsLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Phoenix.View @@ -8,7 +8,7 @@ defmodule ArchethicWeb.CodeProposalsLive do alias Archethic.PubSub - alias ArchethicWeb.CodeView + alias ArchethicWeb.Explorer.CodeView def mount(_params, _session, socket) do if connected?(socket) do diff --git a/lib/archethic_web/live/code_viewer_live.ex b/lib/archethic_web/explorer/live/code_viewer_live.ex similarity index 94% rename from lib/archethic_web/live/code_viewer_live.ex rename to lib/archethic_web/explorer/live/code_viewer_live.ex index c5770fa6a..43319ed21 100644 --- a/lib/archethic_web/live/code_viewer_live.ex +++ b/lib/archethic_web/explorer/live/code_viewer_live.ex @@ -1,9 +1,9 @@ -defmodule ArchethicWeb.CodeViewerLive do +defmodule ArchethicWeb.Explorer.CodeViewerLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Archethic.Governance - alias ArchethicWeb.CodeView + alias ArchethicWeb.Explorer.CodeView alias Phoenix.View diff --git a/lib/archethic_web/live/dashboard_live.ex b/lib/archethic_web/explorer/live/dashboard_live.ex similarity index 96% rename from lib/archethic_web/live/dashboard_live.ex rename to lib/archethic_web/explorer/live/dashboard_live.ex index fcee5ca11..96c094000 100755 --- a/lib/archethic_web/live/dashboard_live.ex +++ b/lib/archethic_web/explorer/live/dashboard_live.ex @@ -1,11 +1,11 @@ -defmodule ArchethicWeb.DashboardLive do +defmodule ArchethicWeb.Explorer.DashboardLive do @moduledoc """ Live-View for Network-Metric-Dashboard """ - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Archethic.Metrics.Poller - alias ArchethicWeb.DashboardView + alias ArchethicWeb.Explorer.DashboardView alias Phoenix.View diff --git a/lib/archethic_web/live/explorer/cache.ex b/lib/archethic_web/explorer/live/explorer/top_transaction_cache.ex similarity index 93% rename from lib/archethic_web/live/explorer/cache.ex rename to lib/archethic_web/explorer/live/explorer/top_transaction_cache.ex index d2b8b6730..c0a85f5b2 100644 --- a/lib/archethic_web/live/explorer/cache.ex +++ b/lib/archethic_web/explorer/live/explorer/top_transaction_cache.ex @@ -1,4 +1,4 @@ -defmodule ArchethicWeb.ExplorerLive.TopTransactionsCache do +defmodule ArchethicWeb.Explorer.ExplorerLive.TopTransactionsCache do @table :last_transactions @moduledoc false diff --git a/lib/archethic_web/live/explorer_index_live.ex b/lib/archethic_web/explorer/live/explorer_index_live.ex similarity index 91% rename from lib/archethic_web/live/explorer_index_live.ex rename to lib/archethic_web/explorer/live/explorer_index_live.ex index 8dde244cd..91648e3ea 100644 --- a/lib/archethic_web/live/explorer_index_live.ex +++ b/lib/archethic_web/explorer/live/explorer_index_live.ex @@ -1,14 +1,14 @@ -defmodule ArchethicWeb.ExplorerIndexLive do +defmodule ArchethicWeb.Explorer.ExplorerIndexLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Phoenix.View alias Archethic.{DB, PubSub, BeaconChain} alias Archethic.TransactionChain.TransactionSummary - alias ArchethicWeb.ExplorerView - alias ArchethicWeb.ExplorerIndexLive.TopTransactionsComponent + alias ArchethicWeb.Explorer.ExplorerView + alias ArchethicWeb.Explorer.ExplorerIndexLive.TopTransactionsComponent def mount(_params, _session, socket) do tps = DB.get_latest_tps() diff --git a/lib/archethic_web/live/node_details_live.ex b/lib/archethic_web/explorer/live/node_details_live.ex similarity index 91% rename from lib/archethic_web/live/node_details_live.ex rename to lib/archethic_web/explorer/live/node_details_live.ex index 75d8fcd29..64456af2e 100644 --- a/lib/archethic_web/live/node_details_live.ex +++ b/lib/archethic_web/explorer/live/node_details_live.ex @@ -1,14 +1,14 @@ -defmodule ArchethicWeb.NodeDetailsLive do +defmodule ArchethicWeb.Explorer.NodeDetailsLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Archethic.Crypto alias Archethic.P2P alias Archethic.P2P.Node alias Archethic.PubSub - alias ArchethicWeb.NodeView + alias ArchethicWeb.Explorer.NodeView alias Phoenix.View diff --git a/lib/archethic_web/live/node_list_live.ex b/lib/archethic_web/explorer/live/node_list_live.ex similarity index 92% rename from lib/archethic_web/live/node_list_live.ex rename to lib/archethic_web/explorer/live/node_list_live.ex index 3f4338ade..021bc8981 100644 --- a/lib/archethic_web/live/node_list_live.ex +++ b/lib/archethic_web/explorer/live/node_list_live.ex @@ -1,12 +1,12 @@ -defmodule ArchethicWeb.NodeListLive do +defmodule ArchethicWeb.Explorer.NodeListLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Archethic.P2P alias Archethic.PubSub - alias ArchethicWeb.NodeView + alias ArchethicWeb.Explorer.NodeView alias Phoenix.View diff --git a/lib/archethic_web/live/settings_live.ex b/lib/archethic_web/explorer/live/settings_live.ex similarity index 98% rename from lib/archethic_web/live/settings_live.ex rename to lib/archethic_web/explorer/live/settings_live.ex index 04854b4b8..62bb7c78a 100644 --- a/lib/archethic_web/live/settings_live.ex +++ b/lib/archethic_web/explorer/live/settings_live.ex @@ -1,7 +1,7 @@ -defmodule ArchethicWeb.SettingsLive do +defmodule ArchethicWeb.Explorer.SettingsLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Archethic.Crypto diff --git a/lib/archethic_web/live/top_node_live.ex b/lib/archethic_web/explorer/live/top_node_live.ex similarity index 86% rename from lib/archethic_web/live/top_node_live.ex rename to lib/archethic_web/explorer/live/top_node_live.ex index 50d5d8bc6..6bc8aad40 100644 --- a/lib/archethic_web/live/top_node_live.ex +++ b/lib/archethic_web/explorer/live/top_node_live.ex @@ -1,6 +1,6 @@ -defmodule ArchethicWeb.TopNodeLive do +defmodule ArchethicWeb.Explorer.TopNodeLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Phoenix.View @@ -9,7 +9,7 @@ defmodule ArchethicWeb.TopNodeLive do alias Archethic.PubSub - alias ArchethicWeb.ExplorerView + alias ArchethicWeb.Explorer.ExplorerView def mount(_params, _session, socket) do if connected?(socket) do diff --git a/lib/archethic_web/live/top_transactions_component.ex b/lib/archethic_web/explorer/live/top_transactions_component.ex similarity index 89% rename from lib/archethic_web/live/top_transactions_component.ex rename to lib/archethic_web/explorer/live/top_transactions_component.ex index c5b5aa687..d191f213a 100644 --- a/lib/archethic_web/live/top_transactions_component.ex +++ b/lib/archethic_web/explorer/live/top_transactions_component.ex @@ -1,11 +1,11 @@ -defmodule ArchethicWeb.ExplorerIndexLive.TopTransactionsComponent do +defmodule ArchethicWeb.Explorer.ExplorerIndexLive.TopTransactionsComponent do @moduledoc """ Live component for Dashboard Explorer to display recent transactions """ - use ArchethicWeb, :live_component + use ArchethicWeb.Explorer, :live_component - alias ArchethicWeb.ExplorerLive.TopTransactionsCache + alias ArchethicWeb.Explorer.ExplorerLive.TopTransactionsCache def mount(socket) do socket = @@ -57,7 +57,7 @@ defmodule ArchethicWeb.ExplorerIndexLive.TopTransactionsComponent do <%= for tx <- @transactions do %>
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(tx.address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(tx.address)) do%> <%= Base.encode16(tx.address) %> <% end %>
diff --git a/lib/archethic_web/explorer/live/transaction_builder_live.ex b/lib/archethic_web/explorer/live/transaction_builder_live.ex new file mode 100644 index 000000000..cd1d2ad2f --- /dev/null +++ b/lib/archethic_web/explorer/live/transaction_builder_live.ex @@ -0,0 +1,15 @@ +defmodule ArchethicWeb.Explorer.TransactionBuilderLive do + @moduledoc false + + use ArchethicWeb.Explorer, :live_component + + alias Phoenix.View + + def mount(socket) do + {:ok, socket} + end + + def render(assigns) do + View.render(ArchethicWeb.Explorer.ExplorerView, "transaction_builder.html", assigns) + end +end diff --git a/lib/archethic_web/live/transaction_details_live.ex b/lib/archethic_web/explorer/live/transaction_details_live.ex similarity index 98% rename from lib/archethic_web/live/transaction_details_live.ex rename to lib/archethic_web/explorer/live/transaction_details_live.ex index c6378241f..525f35fd3 100644 --- a/lib/archethic_web/live/transaction_details_live.ex +++ b/lib/archethic_web/explorer/live/transaction_details_live.ex @@ -1,6 +1,6 @@ -defmodule ArchethicWeb.TransactionDetailsLive do +defmodule ArchethicWeb.Explorer.TransactionDetailsLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Phoenix.View @@ -19,7 +19,7 @@ defmodule ArchethicWeb.TransactionDetailsLive do alias Archethic.TransactionChain.Transaction.ValidationStamp.LedgerOperations.TransactionMovement - alias ArchethicWeb.ExplorerView + alias ArchethicWeb.Explorer.ExplorerView alias Archethic.OracleChain diff --git a/lib/archethic_web/live/worldmap_live.ex b/lib/archethic_web/explorer/live/worldmap_live.ex similarity index 93% rename from lib/archethic_web/live/worldmap_live.ex rename to lib/archethic_web/explorer/live/worldmap_live.ex index 8dd4ca8a0..1845e1028 100644 --- a/lib/archethic_web/live/worldmap_live.ex +++ b/lib/archethic_web/explorer/live/worldmap_live.ex @@ -1,10 +1,10 @@ -defmodule ArchethicWeb.WorldMapLive do +defmodule ArchethicWeb.Explorer.WorldMapLive do @moduledoc false - use ArchethicWeb, :live_view + use ArchethicWeb.Explorer, :live_view alias Phoenix.View - alias ArchethicWeb.NodeView + alias ArchethicWeb.Explorer.NodeView alias Archethic.P2P alias Archethic.PubSub alias Archethic.P2P.Node diff --git a/lib/archethic_web/templates/code/proposal_details.html.heex b/lib/archethic_web/explorer/templates/code/proposal_details.html.heex similarity index 94% rename from lib/archethic_web/templates/code/proposal_details.html.heex rename to lib/archethic_web/explorer/templates/code/proposal_details.html.heex index 2c8a8127a..bf8827513 100644 --- a/lib/archethic_web/templates/code/proposal_details.html.heex +++ b/lib/archethic_web/explorer/templates/code/proposal_details.html.heex @@ -23,7 +23,7 @@

Code proposal

- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(@address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(@address)) do%> <%= Base.encode16(@address) %> <% end %>
@@ -58,7 +58,7 @@ <%= for approval <- @approvals do %>
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(approval)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(approval)) do%> <%= Base.encode16(approval) %> <% end %>
diff --git a/lib/archethic_web/templates/code/proposal_list.html.heex b/lib/archethic_web/explorer/templates/code/proposal_list.html.heex similarity index 94% rename from lib/archethic_web/templates/code/proposal_list.html.heex rename to lib/archethic_web/explorer/templates/code/proposal_list.html.heex index 4734f69dd..b2af21190 100644 --- a/lib/archethic_web/templates/code/proposal_list.html.heex +++ b/lib/archethic_web/explorer/templates/code/proposal_list.html.heex @@ -11,7 +11,7 @@

Transaction address

- <%= link to: Routes.live_path(@socket, ArchethicWeb.CodeProposalDetailsLive, Base.encode16(proposal.address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.CodeProposalDetailsLive, Base.encode16(proposal.address)) do%> <%= Base.encode16(:binary.part(proposal.address, 0, 13)) %>... <% end %>
@@ -36,4 +36,4 @@
-<% end %> \ No newline at end of file +<% end %> diff --git a/lib/archethic_web/templates/code/viewer.html.heex b/lib/archethic_web/explorer/templates/code/viewer.html.heex similarity index 100% rename from lib/archethic_web/templates/code/viewer.html.heex rename to lib/archethic_web/explorer/templates/code/viewer.html.heex diff --git a/lib/archethic_web/templates/dashboard/dashboard.html.heex b/lib/archethic_web/explorer/templates/dashboard/dashboard.html.heex similarity index 100% rename from lib/archethic_web/templates/dashboard/dashboard.html.heex rename to lib/archethic_web/explorer/templates/dashboard/dashboard.html.heex diff --git a/lib/archethic_web/templates/error/404.html.heex b/lib/archethic_web/explorer/templates/error/404.html.heex similarity index 100% rename from lib/archethic_web/templates/error/404.html.heex rename to lib/archethic_web/explorer/templates/error/404.html.heex diff --git a/lib/archethic_web/templates/error/500.html.heex b/lib/archethic_web/explorer/templates/error/500.html.heex similarity index 100% rename from lib/archethic_web/templates/error/500.html.heex rename to lib/archethic_web/explorer/templates/error/500.html.heex diff --git a/lib/archethic_web/templates/explorer/404.html.heex b/lib/archethic_web/explorer/templates/explorer/404.html.heex similarity index 100% rename from lib/archethic_web/templates/explorer/404.html.heex rename to lib/archethic_web/explorer/templates/explorer/404.html.heex diff --git a/lib/archethic_web/templates/explorer/beacon_chain_index.html.heex b/lib/archethic_web/explorer/templates/explorer/beacon_chain_index.html.heex similarity index 93% rename from lib/archethic_web/templates/explorer/beacon_chain_index.html.heex rename to lib/archethic_web/explorer/templates/explorer/beacon_chain_index.html.heex index 60739a619..cbdc97aca 100644 --- a/lib/archethic_web/templates/explorer/beacon_chain_index.html.heex +++ b/lib/archethic_web/explorer/templates/explorer/beacon_chain_index.html.heex @@ -11,7 +11,7 @@
-
@@ -31,7 +31,7 @@ <%= for tx <- @transactions do %>
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(tx.address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(tx.address)) do%> <%= Base.encode16(tx.address) %> <% end %>
diff --git a/lib/archethic_web/templates/explorer/chain.html.heex b/lib/archethic_web/explorer/templates/explorer/chain.html.heex similarity index 97% rename from lib/archethic_web/templates/explorer/chain.html.heex rename to lib/archethic_web/explorer/templates/explorer/chain.html.heex index 64e7f2b29..a64d35ba7 100644 --- a/lib/archethic_web/templates/explorer/chain.html.heex +++ b/lib/archethic_web/explorer/templates/explorer/chain.html.heex @@ -6,7 +6,7 @@
-
+
@@ -77,7 +77,7 @@ <%= for tx <- @transaction_chain do %>
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(tx.address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(tx.address)) do%> <%= Base.encode16(tx.address) %> <%= Base.encode16(:binary.part(tx.address, 0, 13)) %>... <% end %> diff --git a/lib/archethic_web/templates/explorer/index.html.heex b/lib/archethic_web/explorer/templates/explorer/index.html.heex similarity index 93% rename from lib/archethic_web/templates/explorer/index.html.heex rename to lib/archethic_web/explorer/templates/explorer/index.html.heex index 9ba2f6169..68aec1e87 100644 --- a/lib/archethic_web/templates/explorer/index.html.heex +++ b/lib/archethic_web/explorer/templates/explorer/index.html.heex @@ -19,7 +19,7 @@
- <.live_component module={ArchethicWeb.ExplorerIndexLive.TopTransactionsComponent} id="last_ten_transactions" /> + <.live_component module={ArchethicWeb.Explorer.ExplorerIndexLive.TopTransactionsComponent} id="last_ten_transactions" />
diff --git a/lib/archethic_web/templates/explorer/ko_transaction.html.heex b/lib/archethic_web/explorer/templates/explorer/ko_transaction.html.heex similarity index 100% rename from lib/archethic_web/templates/explorer/ko_transaction.html.heex rename to lib/archethic_web/explorer/templates/explorer/ko_transaction.html.heex diff --git a/lib/archethic_web/templates/explorer/node_shared_secrets_chain_index.html.heex b/lib/archethic_web/explorer/templates/explorer/node_shared_secrets_chain_index.html.heex similarity index 93% rename from lib/archethic_web/templates/explorer/node_shared_secrets_chain_index.html.heex rename to lib/archethic_web/explorer/templates/explorer/node_shared_secrets_chain_index.html.heex index 44adb482e..ac9857daa 100644 --- a/lib/archethic_web/templates/explorer/node_shared_secrets_chain_index.html.heex +++ b/lib/archethic_web/explorer/templates/explorer/node_shared_secrets_chain_index.html.heex @@ -20,7 +20,7 @@
-
@@ -35,7 +35,7 @@ <%= for tx <- @transactions do %>
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(tx.address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(tx.address)) do%> <%= Base.encode16(tx.address) %> <% end %>
diff --git a/lib/archethic_web/templates/explorer/oracle_chain_index.html.heex b/lib/archethic_web/explorer/templates/explorer/oracle_chain_index.html.heex similarity index 92% rename from lib/archethic_web/templates/explorer/oracle_chain_index.html.heex rename to lib/archethic_web/explorer/templates/explorer/oracle_chain_index.html.heex index 1fdab39c9..3e9d6c1ab 100644 --- a/lib/archethic_web/templates/explorer/oracle_chain_index.html.heex +++ b/lib/archethic_web/explorer/templates/explorer/oracle_chain_index.html.heex @@ -20,7 +20,7 @@
-
@@ -35,7 +35,7 @@ <%= for tx <- @transactions do %>
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(tx.address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(tx.address)) do%> <%= Base.encode16(tx.address) %> <% end %>
diff --git a/lib/archethic_web/templates/explorer/origin_chain_index.html.heex b/lib/archethic_web/explorer/templates/explorer/origin_chain_index.html.heex similarity index 91% rename from lib/archethic_web/templates/explorer/origin_chain_index.html.heex rename to lib/archethic_web/explorer/templates/explorer/origin_chain_index.html.heex index f72e841dc..e5973b872 100644 --- a/lib/archethic_web/templates/explorer/origin_chain_index.html.heex +++ b/lib/archethic_web/explorer/templates/explorer/origin_chain_index.html.heex @@ -8,7 +8,7 @@
-
@@ -23,7 +23,7 @@ <%= for tx <- @transactions do %>
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(tx.address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(tx.address)) do%> <%= Base.encode16(tx.address) %> <% end %>
diff --git a/lib/archethic_web/templates/explorer/reward_chain_index.html.heex b/lib/archethic_web/explorer/templates/explorer/reward_chain_index.html.heex similarity index 91% rename from lib/archethic_web/templates/explorer/reward_chain_index.html.heex rename to lib/archethic_web/explorer/templates/explorer/reward_chain_index.html.heex index eb5171eea..7ac4e924b 100644 --- a/lib/archethic_web/templates/explorer/reward_chain_index.html.heex +++ b/lib/archethic_web/explorer/templates/explorer/reward_chain_index.html.heex @@ -8,7 +8,7 @@
-
@@ -23,7 +23,7 @@ <%= for tx <- @transactions do %>
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(tx.address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(tx.address)) do%> <%= Base.encode16(tx.address) %> <% end %>
diff --git a/lib/archethic_web/templates/explorer/top_transactions.html.heex b/lib/archethic_web/explorer/templates/explorer/top_transactions.html.heex similarity index 100% rename from lib/archethic_web/templates/explorer/top_transactions.html.heex rename to lib/archethic_web/explorer/templates/explorer/top_transactions.html.heex diff --git a/lib/archethic_web/templates/explorer/transaction_builder.html.heex b/lib/archethic_web/explorer/templates/explorer/transaction_builder.html.heex similarity index 100% rename from lib/archethic_web/templates/explorer/transaction_builder.html.heex rename to lib/archethic_web/explorer/templates/explorer/transaction_builder.html.heex diff --git a/lib/archethic_web/templates/explorer/transaction_details.html.heex b/lib/archethic_web/explorer/templates/explorer/transaction_details.html.heex similarity index 96% rename from lib/archethic_web/templates/explorer/transaction_details.html.heex rename to lib/archethic_web/explorer/templates/explorer/transaction_details.html.heex index d88ee0234..ac3d11766 100644 --- a/lib/archethic_web/templates/explorer/transaction_details.html.heex +++ b/lib/archethic_web/explorer/templates/explorer/transaction_details.html.heex @@ -18,12 +18,12 @@ <%= if assigns[:error] == nil do %>
- <%= link class: "button is-primary is-outlined is-fullwidth", to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(@previous_address)) do%> + <%= link class: "button is-primary is-outlined is-fullwidth", to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(@previous_address)) do%> Previous transaction <% end %>
- <%= link class: "button is-primary is-outlined is-fullwidth", to: Routes.live_path(@socket, ArchethicWeb.TransactionChainLive, address: Base.encode16(@address)) do%> + <%= link class: "button is-primary is-outlined is-fullwidth", to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionChainLive, address: Base.encode16(@address)) do%> Explore chain <% end %>
@@ -175,7 +175,7 @@
To
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(transfer.to)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(transfer.to)) do%> <%= Base.encode16(transfer.to) %> <% end %>
@@ -202,7 +202,7 @@
To
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(transfer.to)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(transfer.to)) do%> <%= Base.encode16(transfer.to) %> <% end %>
@@ -217,7 +217,7 @@
Token
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(transfer.token_address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(transfer.token_address)) do%> <%= case Map.get(@token_properties, transfer.token_address, %{}) |> Map.get(:symbol) do nil -> Base.encode16(transfer.token_address) @@ -268,7 +268,7 @@
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(address)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(address)) do%> <%= Base.encode16(address) %> <% end %>
@@ -354,7 +354,7 @@
To
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(movement.to)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(movement.to)) do%> <%= Base.encode16(movement.to) %> <% end %>
@@ -377,7 +377,7 @@ (#<%= token_id %>) <% end %> - <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(token_address)) do %> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(token_address)) do %> <%= case Map.get(@token_properties, token_address, %{}) |> Map.get(:symbol) do nil -> "#{Base.encode16(:binary.part(token_address, 0, 13))}..." @@ -400,7 +400,7 @@
From
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(unspent_output.from)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(unspent_output.from)) do%> <%= Base.encode16(unspent_output.from) %> <% end %>
@@ -423,7 +423,7 @@ (#<%= token_id %>) <% end %> - <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(token_address)) do %> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(token_address)) do %> <%= case Map.get(@token_properties, token_address, %{}) |> Map.get(:symbol) do nil -> "#{Base.encode16(:binary.part(token_address, 0, 13))}..." @@ -446,7 +446,7 @@ <%= if @transaction.validation_stamp.ledger_operations.fee > 0 do %> (<%= format_full_usd_amount(@transaction.validation_stamp.ledger_operations.fee, @uco_price_at_time[:usd], @uco_price_now[:usd]) %>)

The fees have been transfered to the - <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(Archethic.TransactionChain.Transaction.ValidationStamp.LedgerOperations.burning_address())) do %>burning address<% end %>

+ <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(Archethic.TransactionChain.Transaction.ValidationStamp.LedgerOperations.burning_address())) do %>burning address<% end %>

<% end %>

@@ -461,7 +461,7 @@ <% end %> <%= for recipient <- @transaction.validation_stamp.recipients do %> - <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(recipient)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(recipient)) do%>

<%= Base.encode16(recipient) %>

<% end %> <% end %> @@ -485,7 +485,7 @@
Node public key
- <%= link to: Routes.live_path(@socket, ArchethicWeb.NodeDetailsLive, Base.encode16(cross_validation_stamp.node_public_key)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.NodeDetailsLive, Base.encode16(cross_validation_stamp.node_public_key)) do%> <%= Base.encode16(cross_validation_stamp.node_public_key) %> <% end %>
@@ -539,7 +539,7 @@
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(input.from)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(input.from)) do%> <%= Base.encode16(input.from) %> <%= Base.encode16(:binary.part(input.from, 0, 12)) %>... <% end %> @@ -583,7 +583,7 @@ <% end %>
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(token_address)) do + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(token_address)) do case Map.get(@token_properties, token_address, %{}) |> Map.get(:symbol) do %> <% nil -> %> <%= Base.encode16(:binary.part(token_address, 0, 6)) %>... @@ -621,7 +621,7 @@
- <%= link to: Routes.live_path(@socket, ArchethicWeb.TransactionDetailsLive, Base.encode16(call.from)) do%> + <%= link to: Routes.live_path(@socket, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(call.from)) do%> <%= Base.encode16(call.from) %> <%= Base.encode16(:binary.part(call.from, 0, 12)) %>... <% end %> diff --git a/lib/archethic_web/templates/explorer/transaction_list.html.heex b/lib/archethic_web/explorer/templates/explorer/transaction_list.html.heex similarity index 100% rename from lib/archethic_web/templates/explorer/transaction_list.html.heex rename to lib/archethic_web/explorer/templates/explorer/transaction_list.html.heex diff --git a/lib/archethic_web/templates/explorer/transaction_summary.html.heex b/lib/archethic_web/explorer/templates/explorer/transaction_summary.html.heex similarity index 84% rename from lib/archethic_web/templates/explorer/transaction_summary.html.heex rename to lib/archethic_web/explorer/templates/explorer/transaction_summary.html.heex index dd08d258b..344e1aaa5 100644 --- a/lib/archethic_web/templates/explorer/transaction_summary.html.heex +++ b/lib/archethic_web/explorer/templates/explorer/transaction_summary.html.heex @@ -2,7 +2,7 @@

Address

- <%= link to: Routes.live_path(@conn, ArchethicWeb.TransactionDetailsLive, Base.encode16(@transaction.address)) do%> + <%= link to: Routes.live_path(@conn, ArchethicWeb.Explorer.TransactionDetailsLive, Base.encode16(@transaction.address)) do%> <%= Base.encode16(:binary.part(@transaction.address, 0, 30)) %>... <%= Base.encode16(:binary.part(@transaction.address, 0, 13)) %>... <% end %> diff --git a/lib/archethic_web/templates/faucet/index.html.heex b/lib/archethic_web/explorer/templates/faucet/index.html.heex similarity index 94% rename from lib/archethic_web/templates/faucet/index.html.heex rename to lib/archethic_web/explorer/templates/faucet/index.html.heex index b604405aa..3abec686c 100644 --- a/lib/archethic_web/templates/faucet/index.html.heex +++ b/lib/archethic_web/explorer/templates/faucet/index.html.heex @@ -2,7 +2,7 @@ <%= if info = get_flash(@conn, :info) do %>

@@ -50,4 +50,4 @@
-
\ No newline at end of file +
diff --git a/lib/archethic_web/templates/layout/app.html.heex b/lib/archethic_web/explorer/templates/layout/app.html.heex similarity index 100% rename from lib/archethic_web/templates/layout/app.html.heex rename to lib/archethic_web/explorer/templates/layout/app.html.heex diff --git a/lib/archethic_web/templates/layout/live.html.heex b/lib/archethic_web/explorer/templates/layout/live.html.heex similarity index 100% rename from lib/archethic_web/templates/layout/live.html.heex rename to lib/archethic_web/explorer/templates/layout/live.html.heex diff --git a/lib/archethic_web/templates/layout/root.html.heex b/lib/archethic_web/explorer/templates/layout/root.html.heex similarity index 85% rename from lib/archethic_web/templates/layout/root.html.heex rename to lib/archethic_web/explorer/templates/layout/root.html.heex index 8de65c6f6..5add4de17 100644 --- a/lib/archethic_web/templates/layout/root.html.heex +++ b/lib/archethic_web/explorer/templates/layout/root.html.heex @@ -14,7 +14,7 @@