Skip to content

Commit 8c7352e

Browse files
authoredFeb 20, 2024
feat(host api)!: add particle parameters into CallParameters (#156)
1 parent 25f482c commit 8c7352e

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed
 

‎crates/call-parameters/src/lib.rs

+33-6
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ impl SecurityTetraplet {
8585
)]
8686
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
8787
pub struct CallParameters {
88-
/// Peer id of the AIR script initiator.
89-
pub init_peer_id: String,
88+
/// Parameters of the particle that caused this call.
89+
pub particle: ParticleParameters,
9090

9191
/// Id of the current service.
9292
pub service_id: String,
@@ -100,13 +100,40 @@ pub struct CallParameters {
100100
/// PeerId of the worker who hosts this service.
101101
pub worker_id: String,
102102

103-
/// Id of the particle which execution resulted a call this service.
104-
pub particle_id: String,
105-
106103
/// Security tetraplets which described origin of the arguments.
107104
pub tetraplets: Vec<Vec<SecurityTetraplet>>,
108105
}
109106

107+
#[cfg_attr(all(target_arch = "wasm32", feature = "marine-abi"), marine)]
108+
#[derive(Clone, PartialEq, Default, Eq, Debug, Serialize, Deserialize)]
109+
#[cfg_attr(
110+
feature = "rkyv",
111+
derive(::rkyv::Archive, ::rkyv::Serialize, ::rkyv::Deserialize)
112+
)]
113+
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
114+
pub struct ParticleParameters {
115+
/// Id of the particle which execution resulted a call this service.
116+
pub id: String,
117+
118+
/// Peer id of the AIR script initiator.
119+
pub init_peer_id: String,
120+
121+
/// Unix timestamp of the particle start time.
122+
pub timestamp: u64,
123+
124+
/// Time to live for this particle in milliseconds.
125+
pub ttl: u32,
126+
127+
/// AIR script in this particle.
128+
pub script: String,
129+
130+
/// Signature made by particle initiator -- init_peer_id.
131+
pub signature: Vec<u8>,
132+
133+
/// particle.signature signed by host_id -- used for FS access.
134+
pub token: String,
135+
}
136+
110137
use std::fmt;
111138
impl fmt::Display for SecurityTetraplet {
112139
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -136,7 +163,7 @@ pub fn get_call_parameters() -> CallParameters {
136163
}
137164

138165
#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
139-
#[link(wasm_import_module = "__marine_host_api_v1")]
166+
#[link(wasm_import_module = "__marine_host_api_v2")]
140167
#[allow(improper_ctypes)]
141168
extern "C" {
142169
// returns serialized current call parameters

‎crates/main/src/logger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub fn log_utf8_string(level: i32, target: i32, msg_ptr: i32, msg_size: i32) {
242242
/// TODO: mark `log_utf8_string_impl` as #[wasm_bindgen], so it is polyfilled by bindgen
243243
/// log_utf8_string should be provided directly by a host.
244244
#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
245-
#[link(wasm_import_module = "__marine_host_api_v1")]
245+
#[link(wasm_import_module = "__marine_host_api_v2")]
246246
extern "C" {
247247
// Writes a byte string of size bytes that starts from ptr to a logger
248248
#[link_name = "log_utf8_string"]

‎crates/marine-macro-impl/src/parse_macro_input/item_foreign_mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use syn::spanned::Spanned;
2525
const LINK_NAME_DIRECTIVE_NAME: &str = "link_name";
2626
const HOST_IMPORT_DIRECTIVE_NAME: &str = "host_import";
2727
const MODULE_IMPORT_DIRECTIVE_NAME: &str = "module_import";
28-
const HOST_IMPORT_NAMESPACE: &str = "__marine_host_api_v1";
28+
const HOST_IMPORT_NAMESPACE: &str = "__marine_host_api_v2";
2929

3030
impl ParseMacroInput for syn::ItemForeignMod {
3131
fn parse_macro_input(self) -> Result<MarineAst> {

‎src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub use marine_macro::marine;
7777
pub use marine_macro::fce;
7878

7979
pub use marine_call_parameters::CallParameters;
80+
pub use marine_call_parameters::ParticleParameters;
8081
pub use marine_call_parameters::SecurityTetraplet;
8182
pub use marine_call_parameters::get_call_parameters;
8283

0 commit comments

Comments
 (0)