Skip to main content

openstranded_common_wasmcontract/
service.rs

1use crate::{ServiceError, Value};
2
3/// Unified interface for cross-plugin calls.
4///
5/// Each plugin registers one or more services that other plugins can call
6/// through `Service::call()`.
7///
8/// # Example
9///
10/// ```rust
11/// use openstranded_common_wasmcontract::{Service, Value, ServiceError};
12///
13/// struct HealthService;
14///
15/// impl Service for HealthService {
16///     fn call(&self, method: &str, args: &[Value]) -> Result<Value, ServiceError> {
17///         match method {
18///             "get_max" => Ok(Value::U32(100)),
19///             _ => Err(ServiceError::UnknownMethod(method.into())),
20///         }
21///     }
22/// }
23/// ```
24pub trait Service: Send + Sync {
25    /// Call a method on this service.
26    ///
27    /// - `method`: method name (case-sensitive string)
28    /// - `args`: call arguments
29    fn call(&self, method: &str, args: &[Value]) -> Result<Value, ServiceError>;
30}