From cdc9db123f0dcc3dcfffdd1b395456f260cef9e3 Mon Sep 17 00:00:00 2001 From: Morty <70688412+yiweichi@users.noreply.github.com> Date: Thu, 25 Jul 2024 18:27:49 +0800 Subject: [PATCH] feat: generate rollup explorer backend config (#14) --- docker/config-example.toml | 1 + docker/scripts/gen-configs.sh | 4 +++ .../rollup-explorer-backend-config.json | 5 +++ scripts/deterministic/Configuration.sol | 2 ++ scripts/deterministic/Constants.sol | 2 ++ scripts/deterministic/GenerateConfigs.s.sol | 32 ++++++++++++++++++- 6 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 docker/templates/rollup-explorer-backend-config.json diff --git a/docker/config-example.toml b/docker/config-example.toml index 06786a6..85a2743 100644 --- a/docker/config-example.toml +++ b/docker/config-example.toml @@ -43,6 +43,7 @@ L2GETH_SIGNER_0_ADDRESS = "0x756EA06BDEe36de11F22DCca45a31d8a178eF3c6" SCROLL_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/scroll?sslmode=disable" CHAIN_MONITOR_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/chain_monitor?sslmode=disable" BRIDGE_HISTORY_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/bridge_history?sslmode=disable" +ROLLUP_EXPLORER_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/rollup_explorer?sslmode=disable" [genesis] diff --git a/docker/scripts/gen-configs.sh b/docker/scripts/gen-configs.sh index 00da4f0..0a42c78 100755 --- a/docker/scripts/gen-configs.sh +++ b/docker/scripts/gen-configs.sh @@ -31,3 +31,7 @@ forge script scripts/deterministic/GenerateConfigs.s.sol:GenerateBalanceCheckerC echo "" echo "generating .env.frontend" forge script scripts/deterministic/GenerateConfigs.s.sol:GenerateFrontendConfig || exit 1 + +echo "" +echo "generating rollup-explorer-backend-config.json" +forge script scripts/deterministic/GenerateConfigs.s.sol:GenerateRollupExplorerBackendConfig || exit 1 diff --git a/docker/templates/rollup-explorer-backend-config.json b/docker/templates/rollup-explorer-backend-config.json new file mode 100644 index 0000000..a8ec249 --- /dev/null +++ b/docker/templates/rollup-explorer-backend-config.json @@ -0,0 +1,5 @@ +{ + "db_url": null, + "open_api_addr": "/rollupscan", + "max_per_page": 500 +} \ No newline at end of file diff --git a/scripts/deterministic/Configuration.sol b/scripts/deterministic/Configuration.sol index 8473bed..a39f682 100644 --- a/scripts/deterministic/Configuration.sol +++ b/scripts/deterministic/Configuration.sol @@ -59,6 +59,7 @@ abstract contract Configuration is Script { string internal SCROLL_DB_CONNECTION_STRING; string internal CHAIN_MONITOR_DB_CONNECTION_STRING; string internal BRIDGE_HISTORY_DB_CONNECTION_STRING; + string internal ROLLUP_EXPLORER_BACKEND_DB_CONNECTION_STRING; // genesis uint256 internal L2_MAX_ETH_SUPPLY; @@ -129,6 +130,7 @@ abstract contract Configuration is Script { SCROLL_DB_CONNECTION_STRING = cfg.readString(".db.SCROLL_DB_CONNECTION_STRING"); CHAIN_MONITOR_DB_CONNECTION_STRING = cfg.readString(".db.CHAIN_MONITOR_DB_CONNECTION_STRING"); BRIDGE_HISTORY_DB_CONNECTION_STRING = cfg.readString(".db.BRIDGE_HISTORY_DB_CONNECTION_STRING"); + ROLLUP_EXPLORER_BACKEND_DB_CONNECTION_STRING = cfg.readString(".db.ROLLUP_EXPLORER_DB_CONNECTION_STRING"); L2_MAX_ETH_SUPPLY = cfg.readUint(".genesis.L2_MAX_ETH_SUPPLY"); L2_DEPLOYER_INITIAL_BALANCE = cfg.readUint(".genesis.L2_DEPLOYER_INITIAL_BALANCE"); diff --git a/scripts/deterministic/Constants.sol b/scripts/deterministic/Constants.sol index ff02d60..58395a5 100644 --- a/scripts/deterministic/Constants.sol +++ b/scripts/deterministic/Constants.sol @@ -19,6 +19,7 @@ string constant COORDINATOR_CONFIG_TEMPLATE_PATH = "./docker/templates/coordinat string constant CHAIN_MONITOR_CONFIG_TEMPLATE_PATH = "./docker/templates/chain-monitor-config.json"; string constant BRIDGE_HISTORY_CONFIG_TEMPLATE_PATH = "./docker/templates/bridge-history-config.json"; string constant BALANCE_CHECKER_CONFIG_TEMPLATE_PATH = "./docker/templates/balance-checker-config.json"; +string constant ROLLUP_EXPLORER_BACKEND_CONFIG_TEMPLATE_PATH = "./docker/templates/rollup-explorer-backend-config.json"; // input files string constant CONFIG_PATH = "./volume/config.toml"; @@ -33,3 +34,4 @@ string constant CHAIN_MONITOR_CONFIG_PATH = "./volume/chain-monitor-config.json" string constant BRIDGE_HISTORY_CONFIG_PATH = "./volume/bridge-history-config.json"; string constant BALANCE_CHECKER_CONFIG_PATH = "./volume/balance-checker-config.json"; string constant FRONTEND_ENV_PATH = "./volume/.env.frontend"; +string constant ROLLUP_EXPLORER_BACKEND_CONFIG_PATH = "./volume/rollup-explorer-backend-config.json"; diff --git a/scripts/deterministic/GenerateConfigs.s.sol b/scripts/deterministic/GenerateConfigs.s.sol index 3cb921c..bb1fc90 100644 --- a/scripts/deterministic/GenerateConfigs.s.sol +++ b/scripts/deterministic/GenerateConfigs.s.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity =0.8.24; -import {BALANCE_CHECKER_CONFIG_PATH, BALANCE_CHECKER_CONFIG_TEMPLATE_PATH, BRIDGE_HISTORY_CONFIG_PATH, BRIDGE_HISTORY_CONFIG_TEMPLATE_PATH, CHAIN_MONITOR_CONFIG_PATH, CHAIN_MONITOR_CONFIG_TEMPLATE_PATH, COORDINATOR_CONFIG_PATH, COORDINATOR_CONFIG_TEMPLATE_PATH, FRONTEND_ENV_PATH, ROLLUP_CONFIG_PATH, ROLLUP_CONFIG_TEMPLATE_PATH} from "./Constants.sol"; +import {BALANCE_CHECKER_CONFIG_PATH, BALANCE_CHECKER_CONFIG_TEMPLATE_PATH, BRIDGE_HISTORY_CONFIG_PATH, BRIDGE_HISTORY_CONFIG_TEMPLATE_PATH, CHAIN_MONITOR_CONFIG_PATH, CHAIN_MONITOR_CONFIG_TEMPLATE_PATH, COORDINATOR_CONFIG_PATH, COORDINATOR_CONFIG_TEMPLATE_PATH, FRONTEND_ENV_PATH, ROLLUP_CONFIG_PATH, ROLLUP_CONFIG_TEMPLATE_PATH, ROLLUP_EXPLORER_BACKEND_CONFIG_PATH, ROLLUP_EXPLORER_BACKEND_CONFIG_TEMPLATE_PATH} from "./Constants.sol"; import {DeployScroll} from "./DeployScroll.s.sol"; contract GenerateRollupConfig is DeployScroll { @@ -326,3 +326,33 @@ contract GenerateFrontendConfig is DeployScroll { vm.writeLine(FRONTEND_ENV_PATH, "REACT_APP_L1_BATCH_BRIDGE_GATEWAY_PROXY_ADDR = \"\""); } } + +contract GenerateRollupExplorerBackendConfig is DeployScroll { + /*************** + * Entry point * + ***************/ + + function run() public { + setScriptMode(ScriptMode.VerifyConfig); + predictAllContracts(); + + generateRollupExplorerBackendConfig(); + } + + /********************* + * Private functions * + *********************/ + + // prettier-ignore + function generateRollupExplorerBackendConfig() private { + // initialize template file + if (vm.exists(ROLLUP_EXPLORER_BACKEND_CONFIG_PATH)) { + vm.removeFile(ROLLUP_EXPLORER_BACKEND_CONFIG_PATH); + } + + string memory template = vm.readFile(ROLLUP_EXPLORER_BACKEND_CONFIG_TEMPLATE_PATH); + vm.writeFile(ROLLUP_EXPLORER_BACKEND_CONFIG_PATH, template); + + vm.writeJson(ROLLUP_EXPLORER_BACKEND_DB_CONNECTION_STRING, ROLLUP_EXPLORER_BACKEND_CONFIG_PATH, ".db_url"); + } +}