diff --git a/Justfile b/Justfile index b97956c..784511e 100644 --- a/Justfile +++ b/Justfile @@ -17,4 +17,9 @@ wait-for-pg: ./scripts/wait_for_pg.sh test: - SNAP_CHECK=1 cargo test \ No newline at end of file + SNAP_CHECK=1 cargo test + +setup-archive-db: + just get-mainnet-archive-db + just pg + just wait-for-pg \ No newline at end of file diff --git a/README.md b/README.md index e65b187..9b59b58 100644 --- a/README.md +++ b/README.md @@ -22,24 +22,71 @@ The binary will be available at: target/debug/mina_mesh ``` -## Testing +## Running + +Mina Mesh requires access to a PostgreSQL Archive database and a Mina GraphQL endpoint. By default, +the configuration points to the mainnet, making it easy to get started. You can override the +configuration by either passing arguments or setting environment variables via a `.env` file (an +example is provided as `.env.example`). + +### Quick Start with Mainnet + +1. **Set up the PostgreSQL Archive Database** + +Use the predefined `just` commands to set up and start the PostgreSQL database: + +```bash +just setup-archive-db +``` + +> Note: This process sets up the PostgreSQL docker using the latest mainnet archive database. + +2. **Run the Mina Mesh Server** + +To start the server with default settings (mainnet configuration): + +```bash +target/debug/mina_mesh serve +``` + +The server will listen on `0.0.0.0:3000` by default. + +### Playground Mode + +You can enable a playground mode, which provides a simplified testing interface, by adding the +`--playground` flag: + +```bash +cargo run -- serve --playground +``` + +When enabled, you can access the playground at the root URL (`/`). -### Setup PostgreSQL with Latest Mainnet Archive DB +### Configuration -To set up the testing environment with a working PostgreSQL database, use the predefined `just` -steps: +Mina Mesh can be configured through command-line options or by using environment variables. For +convenience, you can use a `.env` file. To get started, copy the provided `.env.example`: ```bash -just get-mainnet-archive-db -just pg -just wait-for-pg +cp .env.example .env ``` -> Note: This process sets up the environment using the latest mainnet archive database. +Then modify the `.env` file to suit your environment. The available configurations include: -### Run Tests +- **Mina GraphQL Endpoint**: `MINA_PROXY_URL` (default: + `https://mainnet.minaprotocol.network/graphql`) +- **PostgreSQL Archive Database URL**: `MINA_ARCHIVE_DATABASE_URL` (default: + `postgres://mina:whatever@localhost:5432/archive`) +- **Genesis Block Identifier**: `MINA_GENESIS_BLOCK_IDENTIFIER_HEIGHT`, + `MINA_GENESIS_BLOCK_IDENTIFIER_STATE_HASH` + +> You can also pass these options as arguments to `mina_mesh serve` to override the defaults. + +## Testing -Once the setup is complete, run the tests with: +Running the tests requires having Archive database available [see: +[Quick Start with Mainnet](#quick-start-with-mainnet)]. Once the setup is complete you can run tests +using: ```bash just test diff --git a/src/bin/mina_mesh.rs b/src/bin/mina_mesh.rs index 2f1d944..b43b0bb 100644 --- a/src/bin/mina_mesh.rs +++ b/src/bin/mina_mesh.rs @@ -14,7 +14,7 @@ enum Command { #[tokio::main] async fn main() -> Result<()> { - dotenv::dotenv()?; + dotenv::dotenv().ok(); match Command::parse() { Command::Serve(cmd) => cmd.run().await, Command::FetchGenesisBlockIdentifier(cmd) => cmd.run().await, diff --git a/src/commands/serve.rs b/src/commands/serve.rs index 10029a9..e858273 100644 --- a/src/commands/serve.rs +++ b/src/commands/serve.rs @@ -23,10 +23,9 @@ pub struct ServeCommand { host: String, #[arg(default_value = "3000")] port: u16, - #[arg(env, long)] + /// Whether to enable the playground. + #[arg(env = "PLAYGROUND", long)] playground: bool, - #[arg(env = "RUST_ENV", long)] - rust_env: String, } impl ServeCommand { @@ -52,7 +51,7 @@ impl ServeCommand { .route("/network/options", post(handle_network_options)) .route("/network/status", post(handle_network_status)) .with_state(Arc::new(mina_mesh)); - if self.rust_env == "development" || self.playground { + if self.playground { router = router.route("/", get(handle_playground)); } let listener = TcpListener::bind(format!("{}:{}", self.host, self.port)).await?;