anya-core 1.2.0

Enterprise-grade Bitcoin Infrastructure Platform
Documentation
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Core API Reference - Anya Documentation</title>
    <link rel="stylesheet" href="../styles.css">
</head>
<body>
    <header>
        <h1>Core API Reference</h1>
        <nav>
            <a href="../index.html">Home</a>
            <a href="#initialization">Initialization</a>
            <a href="#configuration">Configuration</a>
            <a href="#core-functions">Core Functions</a>
        </nav>
    </header>

    <main>
        <section id="initialization">
            <h2>Initialization</h2>
            <p>The core API provides the main entry point for interacting with the Anya system.</p>
            
            <h3>Creating a New Instance</h3>
            <pre><code>use anya::Anya;
use anyhow::Result;

async fn initialize() -> Result<()> {
    // Create a new instance with default configuration
    let anya = Anya::new().await?;
    
    // Or with custom configuration
    let config = Config::from_file("anya.toml")?;
    let anya = Anya::with_config(config).await?;
    
    // Initialize the system
    anya.init().await?;
    
    Ok(())
}</code></pre>
        </section>

        <section id="configuration">
            <h2>Configuration</h2>
            <p>The configuration API allows you to customize Anya's behavior:</p>
            
            <h3>Configuration Options</h3>
            <pre><code>use anya::config::{Config, NetworkType, SecurityLevel};

async fn configure() -> Result<Config> {
    let mut config = Config::default();
    
    // Set network type
    config.set_network(NetworkType::Testnet);
    
    // Configure security settings
    config.set_security_level(SecurityLevel::High);
    
    // Set custom data directory
    config.set_data_dir("/path/to/data");
    
    Ok(config)
}</code></pre>
        </section>

        <section id="core-functions">
            <h2>Core Functions</h2>
            
            <h3>System Management</h3>
            <pre><code>impl Anya {
    /// Check system status
    pub async fn status(&self) -> Result<SystemStatus> {
        // Returns current system status
    }
    
    /// Gracefully shutdown the system
    pub async fn shutdown(&self) -> Result<()> {
        // Performs cleanup and shutdown
    }
    
    /// Backup system data
    pub async fn backup(&self, path: &str) -> Result<()> {
        // Creates system backup
    }
}</code></pre>

            <h3>Event Handling</h3>
            <pre><code>use anya::events::{EventHandler, SystemEvent};

async fn handle_events(anya: &Anya) -> Result<()> {
    // Subscribe to system events
    anya.events()
        .subscribe(|event: SystemEvent| {
            match event {
                SystemEvent::WalletUpdated(wallet_id) => {
                    println!("Wallet {} updated", wallet_id);
                }
                SystemEvent::TransactionConfirmed(tx_id) => {
                    println!("Transaction {} confirmed", tx_id);
                }
                // Handle other events...
            }
        })
        .await?;
    
    Ok(())
}</code></pre>

            <h3>Error Handling</h3>
            <pre><code>use anya::error::AnyaError;

impl Anya {
    /// Handle system errors
    pub async fn handle_error(&self, error: AnyaError) -> Result<()> {
        match error {
            AnyaError::Configuration(e) => {
                // Handle configuration errors
            }
            AnyaError::Network(e) => {
                // Handle network errors
            }
            AnyaError::Security(e) => {
                // Handle security errors
            }
            // Handle other error types...
        }
    }
}</code></pre>
        </section>

        <section id="examples">
            <h2>Examples</h2>
            
            <h3>Complete System Setup</h3>
            <pre><code>use anya::{Anya, Config};
use anyhow::Result;

#[tokio::main]
async fn main() -> Result<()> {
    // Load configuration
    let config = Config::from_file("anya.toml")?;
    
    // Initialize system
    let anya = Anya::with_config(config).await?;
    
    // Setup event handlers
    anya.events()
        .subscribe(handle_events)
        .await?;
    
    // Initialize components
    anya.init().await?;
    
    // System is ready
    println!("Anya system initialized successfully");
    
    Ok(())
}</code></pre>
        </section>
    </main>

    <footer>
        <p>© 2025 Anya Core Contributors. All rights reserved.</p>
        <p>
            <a href="https://github.com/anya-org/anya-core">GitHub</a> |
            <a href="../changelog.html">Changelog</a> |
            <a href="../contributing.html">Contributing</a>
        </p>
    </footer>
</body>
</html>