Skip to main content

wasmify_rs/
lib.rs

1//! # wasmify-rs
2//!
3//! `wasmify-rs` is a Rust library for WebAssembly optimization and smart contract monitoring.
4
5/// Smart contract-related modules and functionalities.
6pub mod contracts;
7
8/// Framework modules for optimization and asynchronous operations.
9pub mod framework;
10
11// Exported functions and modules for external use.
12pub use contracts::deploy::deploy_contract;
13pub use contracts::abi::parse_abi;
14pub use contracts::gas::{estimate_gas, check_gas_limit, optimize_gas_dynamically};
15pub use contracts::interaction::{call_contract_function, fetch_contract_data};
16pub use contracts::watch::watch_contract_transactions;
17pub use contracts::contract_update::update_contract;
18pub use contracts::monitor::monitor_contract_activity;
19pub use crate::framework::async_operations::perform_optimized_operations;
20pub use log::{info, warn};
21pub use std::time::{Instant, Duration};
22pub use chrono::Local;
23
24use env_logger;
25use log::LevelFilter;
26use std::io::Write;
27
28/// Initializes the logging configuration for the application.
29///
30/// This function configures the logger to log information at the `Info` level
31/// and above, including timestamps and logging source details.
32/// It also allows easy integration with the `env_logger` crate.
33pub fn init_logging() {
34    env_logger::builder()
35        .filter(None, LevelFilter::Info) // Info seviyesindeki loglar gösterilecek
36        .format(|buf, record| {
37            writeln!(
38                buf,
39                "[{}] - {} - {}",  // Timestamp, log level, and message
40                Local::now().format("%Y-%m-%d %H:%M:%S"),
41                record.level(),
42                record.args()
43            )
44        })
45        .init();  // Start the logger
46}
47
48/// Main entry point for the application.
49/// Initializes logging, monitors contract activity, and performs gas optimizations.
50#[tokio::main]
51async fn main() {
52    // Initialize logging
53    init_logging();
54    
55    info!("Starting the application...");
56
57    // Monitor contract activity
58    if let Err(e) = monitor_contract_activity(
59        "0x1234567890abcdef1234567890abcdef12345678", 
60        "EventName", 
61        Duration::from_secs(5)
62    ) {
63        log::error!("Monitoring failed: {:?}", e); // Log error on failure
64    } else {
65        info!("Monitoring successful.");
66    }
67
68    // Perform parallel optimized operations
69    perform_optimized_operations().await;
70
71    info!("Application completed successfully.");
72}