#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
use marine_macro::marine;
use serde::Serialize;
use serde::Deserialize;
#[cfg_attr(all(target_arch = "wasm32", feature = "marine-abi"), marine)]
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[cfg_attr(
feature = "rkyv",
derive(::rkyv::Archive, ::rkyv::Serialize, ::rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
pub struct SecurityTetraplet {
pub peer_pk: String,
pub service_id: String,
pub function_name: String,
pub lens: String,
}
impl SecurityTetraplet {
pub fn new(
peer_pk: impl Into<String>,
service_id: impl Into<String>,
function_name: impl Into<String>,
lens: impl Into<String>,
) -> Self {
Self {
peer_pk: peer_pk.into(),
service_id: service_id.into(),
function_name: function_name.into(),
lens: lens.into(),
}
}
pub fn literal_tetraplet(init_peer_id: impl Into<String>) -> Self {
Self {
peer_pk: init_peer_id.into(),
service_id: String::new(),
function_name: String::new(),
lens: String::new(),
}
}
pub fn add_lens(&mut self, lens: &str) {
self.lens.push_str(lens)
}
}
#[cfg_attr(all(target_arch = "wasm32", feature = "marine-abi"), marine)]
#[derive(Clone, PartialEq, Default, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(
feature = "rkyv",
derive(::rkyv::Archive, ::rkyv::Serialize, ::rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
pub struct CallParameters {
pub particle: ParticleParameters,
pub service_id: String,
pub service_creator_peer_id: String,
pub host_id: String,
pub worker_id: String,
pub tetraplets: Vec<Vec<SecurityTetraplet>>,
}
#[cfg_attr(all(target_arch = "wasm32", feature = "marine-abi"), marine)]
#[derive(Clone, PartialEq, Default, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(
feature = "rkyv",
derive(::rkyv::Archive, ::rkyv::Serialize, ::rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
pub struct ParticleParameters {
pub id: String,
pub init_peer_id: String,
pub timestamp: u64,
pub ttl: u32,
pub script: String,
pub signature: Vec<u8>,
pub token: String,
}
use std::fmt;
impl fmt::Display for SecurityTetraplet {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"peer_pk: {}, service_id: {}, function_name: {}, lens: {}",
self.peer_pk, self.service_id, self.function_name, self.lens
)
}
}
#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
pub fn get_call_parameters() -> CallParameters {
unsafe {
get_call_raw_parameters();
let raw_call_parameters = crate::internal::get_result_ptr();
CallParameters::__m_generated_deserialize(raw_call_parameters as _)
}
}
#[cfg(not(all(target_arch = "wasm32", feature = "marine-abi")))]
pub fn get_call_parameters() -> CallParameters {
unimplemented!()
}
#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
#[link(wasm_import_module = "__marine_host_api_v3")]
#[allow(improper_ctypes)]
extern "C" {
#[link_name = "get_call_parameters"]
fn get_call_raw_parameters();
}
#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
#[allow(unused_extern_crates)]
extern crate self as marine_rs_sdk;
#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
#[allow(unused_imports)]
mod internal {
pub(crate) use marine_rs_sdk_main::add_object_to_release;
pub(crate) use marine_rs_sdk_main::get_result_ptr;
pub(crate) use marine_rs_sdk_main::get_result_size;
pub(crate) use marine_rs_sdk_main::set_result_ptr;
pub(crate) use marine_rs_sdk_main::set_result_size;
}