feat: Migrate SAL to Cargo workspace
- Migrate individual modules to independent crates - Refactor dependencies for improved modularity - Update build system and testing infrastructure - Update documentation to reflect new structure
This commit is contained in:
		@@ -13,10 +13,7 @@
 | 
			
		||||
//!
 | 
			
		||||
//! All interactions with the Mycelium API are performed asynchronously.
 | 
			
		||||
 | 
			
		||||
use base64::{
 | 
			
		||||
    engine::general_purpose,
 | 
			
		||||
    Engine as _,
 | 
			
		||||
};
 | 
			
		||||
use base64::{engine::general_purpose, Engine as _};
 | 
			
		||||
use reqwest::Client;
 | 
			
		||||
use serde_json::Value;
 | 
			
		||||
use std::time::Duration;
 | 
			
		||||
 
 | 
			
		||||
@@ -4,11 +4,11 @@
 | 
			
		||||
 | 
			
		||||
use std::time::Duration;
 | 
			
		||||
 | 
			
		||||
use rhai::{Engine, EvalAltResult, Array, Dynamic, Map};
 | 
			
		||||
use crate as client;
 | 
			
		||||
use tokio::runtime::Runtime;
 | 
			
		||||
use serde_json::Value;
 | 
			
		||||
use rhai::Position;
 | 
			
		||||
use rhai::{Array, Dynamic, Engine, EvalAltResult, Map};
 | 
			
		||||
use serde_json::Value;
 | 
			
		||||
use tokio::runtime::Runtime;
 | 
			
		||||
 | 
			
		||||
/// Register Mycelium module functions with the Rhai engine
 | 
			
		||||
///
 | 
			
		||||
@@ -25,11 +25,17 @@ pub fn register_mycelium_module(engine: &mut Engine) -> Result<(), Box<EvalAltRe
 | 
			
		||||
    engine.register_fn("mycelium_list_peers", mycelium_list_peers);
 | 
			
		||||
    engine.register_fn("mycelium_add_peer", mycelium_add_peer);
 | 
			
		||||
    engine.register_fn("mycelium_remove_peer", mycelium_remove_peer);
 | 
			
		||||
    engine.register_fn("mycelium_list_selected_routes", mycelium_list_selected_routes);
 | 
			
		||||
    engine.register_fn("mycelium_list_fallback_routes", mycelium_list_fallback_routes);
 | 
			
		||||
    engine.register_fn(
 | 
			
		||||
        "mycelium_list_selected_routes",
 | 
			
		||||
        mycelium_list_selected_routes,
 | 
			
		||||
    );
 | 
			
		||||
    engine.register_fn(
 | 
			
		||||
        "mycelium_list_fallback_routes",
 | 
			
		||||
        mycelium_list_fallback_routes,
 | 
			
		||||
    );
 | 
			
		||||
    engine.register_fn("mycelium_send_message", mycelium_send_message);
 | 
			
		||||
    engine.register_fn("mycelium_receive_messages", mycelium_receive_messages);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -38,7 +44,7 @@ fn get_runtime() -> Result<Runtime, Box<EvalAltResult>> {
 | 
			
		||||
    tokio::runtime::Runtime::new().map_err(|e| {
 | 
			
		||||
        Box::new(EvalAltResult::ErrorRuntime(
 | 
			
		||||
            format!("Failed to create Tokio runtime: {}", e).into(),
 | 
			
		||||
            rhai::Position::NONE
 | 
			
		||||
            rhai::Position::NONE,
 | 
			
		||||
        ))
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
@@ -56,7 +62,7 @@ fn value_to_dynamic(value: Value) -> Dynamic {
 | 
			
		||||
            } else {
 | 
			
		||||
                Dynamic::from(n.to_string())
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        }
 | 
			
		||||
        Value::String(s) => Dynamic::from(s),
 | 
			
		||||
        Value::Array(arr) => {
 | 
			
		||||
            let mut rhai_arr = Array::new();
 | 
			
		||||
@@ -64,7 +70,7 @@ fn value_to_dynamic(value: Value) -> Dynamic {
 | 
			
		||||
                rhai_arr.push(value_to_dynamic(item));
 | 
			
		||||
            }
 | 
			
		||||
            Dynamic::from(rhai_arr)
 | 
			
		||||
        },
 | 
			
		||||
        }
 | 
			
		||||
        Value::Object(map) => {
 | 
			
		||||
            let mut rhai_map = Map::new();
 | 
			
		||||
            for (k, v) in map {
 | 
			
		||||
@@ -75,7 +81,6 @@ fn value_to_dynamic(value: Value) -> Dynamic {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// Mycelium Client Function Wrappers
 | 
			
		||||
//
 | 
			
		||||
@@ -206,8 +211,9 @@ pub fn mycelium_send_message(
 | 
			
		||||
        Some(Duration::from_secs(reply_deadline_secs as u64))
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let result =
 | 
			
		||||
        rt.block_on(async { client::send_message(api_url, destination, topic, message, deadline).await });
 | 
			
		||||
    let result = rt.block_on(async {
 | 
			
		||||
        client::send_message(api_url, destination, topic, message, deadline).await
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    let response = result.map_err(|e| {
 | 
			
		||||
        Box::new(EvalAltResult::ErrorRuntime(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user