Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Copy this file to .env and customize values as needed for your local
# development or CI environment.
# Copy this file to .env and replace placeholder values.

# Soroban network selection (profile name). Valid values: testnet, mainnet, sandbox
SOROBAN_NETWORK=testnet
# Target Stellar network (for example: testnet, mainnet).
STELLAR_NETWORK=testnet

# Override the RPC endpoint and network passphrase if necessary
SOROBAN_RPC_URL=https://rpc.testnet.soroban.stellar.org
SOROBAN_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
# Platform account secret seed used for signing platform transactions.
STELLAR_PLATFORM_SECRET=SBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

# Horizon REST API endpoint for the selected network.
HORIZON_URL=https://horizon-testnet.stellar.org

# Example keypair file path; tools may read this
# SOROBAN_KEY_FILE=./keys/contract-key.json
# Soroban RPC endpoint for the selected network.
SOROBAN_RPC_URL=https://rpc.testnet.soroban.stellar.org
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
stellar-strkey = "0.0.8"
ed25519-dalek = "2"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
dotenvy = "0.15"
43 changes: 43 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::env;

use thiserror::Error;

#[derive(Debug, Clone)]
pub struct Config {
pub stellar_network: String,
pub stellar_platform_secret: String,
pub horizon_url: String,
pub soroban_rpc_url: String,
}

#[derive(Debug, Error)]
pub enum ConfigError {
#[error("missing required environment variable: {0}")]
MissingEnvVar(&'static str),

#[error("environment variable {name} cannot be empty")]
EmptyEnvVar { name: &'static str },
}

impl Config {
pub fn from_env() -> Result<Self, ConfigError> {
dotenvy::dotenv().ok();

Ok(Self {
stellar_network: read_required_env("STELLAR_NETWORK")?,
stellar_platform_secret: read_required_env("STELLAR_PLATFORM_SECRET")?,
horizon_url: read_required_env("HORIZON_URL")?,
soroban_rpc_url: read_required_env("SOROBAN_RPC_URL")?,
})
}
}

fn read_required_env(name: &'static str) -> Result<String, ConfigError> {
let value = env::var(name).map_err(|_| ConfigError::MissingEnvVar(name))?;

if value.trim().is_empty() {
return Err(ConfigError::EmptyEnvVar { name });
}

Ok(value)
}
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
pub mod config;
pub mod errors;

pub mod friendbot;
pub mod horizon;
mod setup;
pub mod utils;

fn main() {}
fn main() {
if let Err(err) = config::Config::from_env() {
eprintln!("Startup configuration error: {err}");
std::process::exit(1);
}
}