- Workspace: core/ (blockchain library) + node/ (REST API) - Core: block, chain, wallet, transaction, mining, persistence, state - Node: axum 0.8 REST API with full endpoint set - SHA-256 hashing, Ed25519 signatures, account-based model - Unit tests for all core modules
40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
mod api;
|
|
mod state;
|
|
|
|
use blockchain_core::persistence;
|
|
use blockchain_core::Blockchain;
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
// Initialize logging
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(EnvFilter::from_default_env().add_directive("blockchain_node=info".parse().unwrap()))
|
|
.init();
|
|
|
|
// Load existing chain or create new
|
|
let chain = match persistence::load_json::<Blockchain>() {
|
|
Ok(Some(chain)) => {
|
|
tracing::info!("Loaded existing chain ({} blocks)", chain.len());
|
|
chain
|
|
}
|
|
Ok(None) => {
|
|
tracing::info!("No existing chain found, creating new blockchain");
|
|
Blockchain::new()
|
|
}
|
|
Err(e) => {
|
|
tracing::warn!("Failed to load chain: {}, creating new", e);
|
|
Blockchain::new()
|
|
}
|
|
};
|
|
|
|
let shared_state = state::new_shared_state(chain);
|
|
let router = api::create_router(shared_state);
|
|
|
|
let addr = "0.0.0.0:3000";
|
|
tracing::info!("Blockchain node starting on {}", addr);
|
|
|
|
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
|
axum::serve(listener, router).await.unwrap();
|
|
}
|