feat(polyplets)!: move SecurityTetraplets to marine-rs-sdk (#674)

* wip

* remove patch.crates-io section

* switch from Into to From

* fmt + Cargo.lock update

* try use marine-rs-sdk 0.9.0

* Revert "try use marine-rs-sdk 0.9.0"

This reverts commit 603c18fb71.
This commit is contained in:
Valery Antopol 2023-08-17 00:04:36 +03:00 committed by GitHub
parent 681ec35d07
commit 7a8a460572
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 122 deletions

24
Cargo.lock generated
View File

@ -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"

View File

@ -38,6 +38,3 @@ debug = true
overflow-checks = true
debug-assertions = false
panic = "unwind"
[patch.crates-io]
polyplets = { path = "crates/air-lib/polyplets" }

View File

@ -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<Self> {
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)?;

View File

@ -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"] }

View File

@ -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;
}

View File

@ -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<String>,
service_id: impl Into<String>,
function_name: impl Into<String>,
json_path: impl Into<String>,
) -> 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<String>) -> 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
)
}
}

View File

@ -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<ResolvedTriplet> 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(),
}
}
}