diff --git a/Cargo.lock b/Cargo.lock index 943f6f1b..34d50a67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,7 +92,7 @@ dependencies = [ "newtype_derive", "num-traits", "once_cell", - "polyplets", + "polyplets 0.4.1", "semver 1.0.17", "serde", "serde_json", @@ -195,7 +195,7 @@ dependencies = [ "bimap", "log", "num-traits", - "polyplets", + "polyplets 0.4.1", "serde_json", "thiserror", "tracing", @@ -324,7 +324,7 @@ dependencies = [ "marine-rs-sdk", "non-empty-vec", "once_cell", - "polyplets", + "polyplets 0.4.1", "pretty_assertions 0.6.1", "semver 1.0.17", "serde", @@ -473,7 +473,7 @@ dependencies = [ "air-utils", "log", "maplit", - "polyplets", + "polyplets 0.4.1", "serde", "serde_json", "thiserror", @@ -494,7 +494,7 @@ dependencies = [ "maplit", "marine-runtime", "parking_lot 0.12.1", - "polyplets", + "polyplets 0.4.1", "serde", "serde_json", "thiserror", @@ -2275,7 +2275,7 @@ dependencies = [ "marine-macro", "marine-rs-sdk-main", "marine-timestamp-macro", - "polyplets", + "polyplets 0.4.0", "serde", ] @@ -2735,13 +2735,23 @@ dependencies = [ [[package]] name = "polyplets" -version = "0.4.1" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b579a79a461ca50abb202eac61c76d8782fdf091a91775c9e181352e7cd30a8b" dependencies = [ "marine-macro", "marine-rs-sdk-main", "serde", ] +[[package]] +name = "polyplets" +version = "0.4.1" +dependencies = [ + "marine-rs-sdk", + "serde", +] + [[package]] name = "ppv-lite86" version = "0.2.17" diff --git a/Cargo.toml b/Cargo.toml index 05318d7a..79def04b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,3 @@ debug = true overflow-checks = true debug-assertions = false panic = "unwind" - -[patch.crates-io] -polyplets = { path = "crates/air-lib/polyplets" } diff --git a/air/src/execution_step/instructions/call/resolved_call.rs b/air/src/execution_step/instructions/call/resolved_call.rs index 3edd1ac5..4f257da9 100644 --- a/air/src/execution_step/instructions/call/resolved_call.rs +++ b/air/src/execution_step/instructions/call/resolved_call.rs @@ -73,7 +73,7 @@ impl<'i> ResolvedCall<'i> { #[tracing::instrument(level = "trace", skip_all)] pub(super) fn new(raw_call: &Call<'i>, exec_ctx: &ExecutionCtx<'i>) -> ExecutionResult { let triplet = resolve(&raw_call.triplet, exec_ctx)?; - let tetraplet = SecurityTetraplet::from_triplet(triplet); + let tetraplet = triplet.into(); let tetraplet = Rc::new(tetraplet); check_output_name(&raw_call.output, exec_ctx)?; diff --git a/crates/air-lib/polyplets/Cargo.toml b/crates/air-lib/polyplets/Cargo.toml index ed3c252f..a5ebd851 100644 --- a/crates/air-lib/polyplets/Cargo.toml +++ b/crates/air-lib/polyplets/Cargo.toml @@ -15,7 +15,6 @@ name = "polyplets" path = "src/lib.rs" [dependencies] -marine-macro = "0.8.1" -marine-rs-sdk-main = "0.8.1" +marine-rs-sdk = "0.8.1" serde = { version = "1.0.164", features = ["rc", "derive"] } diff --git a/crates/air-lib/polyplets/src/lib.rs b/crates/air-lib/polyplets/src/lib.rs index 0a16ae16..810954e9 100644 --- a/crates/air-lib/polyplets/src/lib.rs +++ b/crates/air-lib/polyplets/src/lib.rs @@ -26,22 +26,7 @@ unreachable_patterns )] -mod tetraplet; mod triplet; -pub use tetraplet::SecurityTetraplet; +pub use marine_rs_sdk::SecurityTetraplet; pub use triplet::ResolvedTriplet; - -// This is a temporary solution that allow using the marine macro by importing -// just marine-macro crate instead of marine-rs-sdk. -#[allow(unused_extern_crates)] -extern crate self as marine_rs_sdk; - -#[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; -} diff --git a/crates/air-lib/polyplets/src/tetraplet.rs b/crates/air-lib/polyplets/src/tetraplet.rs deleted file mode 100644 index ab81b93b..00000000 --- a/crates/air-lib/polyplets/src/tetraplet.rs +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2020 Fluence Labs Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -use crate::ResolvedTriplet; - -use marine_macro::marine; -use serde::Deserialize; -use serde::Serialize; - -/// Describes an origin that set corresponding value. -#[marine] -#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Serialize, Deserialize)] -pub struct SecurityTetraplet { - /// Id of a peer where corresponding value was set. - pub peer_pk: String, - - /// Id of a service that set corresponding value. - pub service_id: String, - - /// Name of a function that returned corresponding value. - pub function_name: String, - - /// Value was produced by applying this `json_path` to the output from `call_service`. - // TODO: since it's not a json path anymore, it's needed to rename it to lambda - pub json_path: String, -} - -impl SecurityTetraplet { - pub fn new( - peer_pk: impl Into, - service_id: impl Into, - function_name: impl Into, - json_path: impl Into, - ) -> Self { - Self { - peer_pk: peer_pk.into(), - service_id: service_id.into(), - function_name: function_name.into(), - json_path: json_path.into(), - } - } - - /// Create a tetraplet for string literals defined in the script - /// such as variable here `(call ("" "") "" ["variable_1"])`. - pub fn literal_tetraplet(init_peer_id: impl Into) -> Self { - Self { - // these variables represent the initiator peer - peer_pk: init_peer_id.into(), - service_id: String::new(), - function_name: String::new(), - // json path can't be applied to the string literals - json_path: String::new(), - } - } - - pub fn from_triplet(triplet: ResolvedTriplet) -> Self { - Self { - peer_pk: triplet.peer_pk, - service_id: triplet.service_id, - function_name: triplet.function_name, - json_path: String::new(), - } - } - - pub fn add_lambda(&mut self, json_path: &str) { - self.json_path.push_str(json_path) - } -} - -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: {}, json_path: {}", - self.peer_pk, self.service_id, self.function_name, self.json_path - ) - } -} diff --git a/crates/air-lib/polyplets/src/triplet.rs b/crates/air-lib/polyplets/src/triplet.rs index 04af2b61..707a1ab2 100644 --- a/crates/air-lib/polyplets/src/triplet.rs +++ b/crates/air-lib/polyplets/src/triplet.rs @@ -14,6 +14,8 @@ * limitations under the License. */ +use marine_rs_sdk::SecurityTetraplet; + use serde::Deserialize; use serde::Serialize; @@ -27,3 +29,14 @@ pub struct ResolvedTriplet { pub service_id: String, pub function_name: String, } + +impl From for SecurityTetraplet { + fn from(triplet: ResolvedTriplet) -> Self { + Self { + peer_pk: triplet.peer_pk, + service_id: triplet.service_id, + function_name: triplet.function_name, + json_path: String::new(), + } + } +}