From aee41603e839a36e381cc833b0f2c5a5c19b11bf Mon Sep 17 00:00:00 2001 From: vms Date: Thu, 24 Sep 2020 12:55:29 +0300 Subject: [PATCH] first prototype --- Cargo.lock | 50 ++++++++++++++++++++++++++++++++++++---- Cargo.toml | 3 +++ src/instructions/call.rs | 25 ++++++++++++++++++++ src/instructions/mod.rs | 28 ++++++++++++++++++++++ src/lib.rs | 19 +++++++++++++++ src/main.rs | 25 +++++++++++++------- src/stepper_outcome.rs | 23 ++++++++++++++++++ 7 files changed, 161 insertions(+), 12 deletions(-) create mode 100644 src/instructions/call.rs create mode 100644 src/instructions/mod.rs create mode 100644 src/lib.rs create mode 100644 src/stepper_outcome.rs diff --git a/Cargo.lock b/Cargo.lock index 0da8e02b..fa807b81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,6 +6,9 @@ version = "0.1.0" dependencies = [ "fluence", "log", + "serde", + "serde-lexpr", + "serde_derive", ] [[package]] @@ -16,7 +19,7 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "fluence" -version = "0.2.6" +version = "0.2.7" dependencies = [ "fluence-sdk-macro", "fluence-sdk-main", @@ -24,14 +27,14 @@ dependencies = [ [[package]] name = "fluence-sdk-macro" -version = "0.2.6" +version = "0.2.7" dependencies = [ "fluence-sdk-wit", ] [[package]] name = "fluence-sdk-main" -version = "0.2.6" +version = "0.2.7" dependencies = [ "fluence-sdk-macro", "log", @@ -40,7 +43,7 @@ dependencies = [ [[package]] name = "fluence-sdk-wit" -version = "0.2.6" +version = "0.2.7" dependencies = [ "proc-macro2", "quote", @@ -67,6 +70,29 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" +[[package]] +name = "lexpr" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6b5eeb1dcf1c6a1fad8c1a88c4cc01618db83810c55cc64c1f86d73688fbfdc" +dependencies = [ + "itoa", + "lexpr-macros", + "proc-macro-hack", + "ryu", +] + +[[package]] +name = "lexpr-macros" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd627fb38e19c00d8d068618259205f7a91c91aeade5c15bc35dbca037bb1c35" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", +] + [[package]] name = "libc" version = "0.2.77" @@ -88,6 +114,12 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" +[[package]] +name = "proc-macro-hack" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" + [[package]] name = "proc-macro2" version = "1.0.21" @@ -162,6 +194,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-lexpr" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "143e5e658ac3a7374bdf285b9355cab74dd144293b86c9be27eab39452239d41" +dependencies = [ + "lexpr", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.116" diff --git a/Cargo.toml b/Cargo.toml index c9965510..a766f28c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,7 @@ path = "src/main.rs" [dependencies] fluence = { path = "/Users/mike/dev/work/fluence/wasm/rust-sdk", features = ["logger"] } +serde = "1.0.116" +serde_derive = "1.0.116" +serde-lexpr = "0.1.1" log = "0.4.11" diff --git a/src/instructions/call.rs b/src/instructions/call.rs new file mode 100644 index 00000000..0e4218fa --- /dev/null +++ b/src/instructions/call.rs @@ -0,0 +1,25 @@ +/* + * 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 serde_derive::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] +pub(crate) struct Call { + pub peer_part: (String, Option), + pub fn_part: (Option, String), + pub args: String, + pub result_name: String, +} diff --git a/src/instructions/mod.rs b/src/instructions/mod.rs new file mode 100644 index 00000000..3e3cad5e --- /dev/null +++ b/src/instructions/mod.rs @@ -0,0 +1,28 @@ +/* + * 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. + */ + +mod call; + +use serde_derive::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] +#[serde(rename_all = "kebab-case")] +pub(crate) enum Instruction { + Null, + Call(call::Call), + Par(Box, Box), + Seq(Box, Box), +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..1759f6f1 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,19 @@ +/* + * 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. + */ + +mod stepper_outcome; + +pub use stepper_outcome::StepperOutcome; diff --git a/src/main.rs b/src/main.rs index 12795930..eeb1a4d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,23 +14,21 @@ * limitations under the License. */ mod air; +mod instructions; +mod stepper_outcome; + +use instructions::Instruction; +use stepper_outcome::StepperOutcome; use fluence::fce; -use log::info; pub fn main() { fluence::WasmLogger::init_with_level(log::Level::Info).unwrap(); } -#[fce] -pub struct StepperOutcome { - pub data: String, - pub next_peer_pks: Vec, -} - #[fce] pub fn invoke(init_user_id: String, aqua: String, data: String) -> StepperOutcome { - info!( + log::info!( "stepper invoked with user_id = {}, aqua = {:?}, data = {:?}", init_user_id, aqua, data ); @@ -40,5 +38,16 @@ pub fn invoke(init_user_id: String, aqua: String, data: String) -> StepperOutcom next_peer_pks: vec![init_user_id], }; + let parsed_aqua: Vec = match serde_lexpr::from_str(&aqua) { + Ok(parsed) => parsed, + Err(e) => { + log::error!("supplied aqua script can't be parsed: {:?}", e); + + return outcome; + } + }; + + log::info!("parsed_aqua: {:?}", parsed_aqua); + outcome } diff --git a/src/stepper_outcome.rs b/src/stepper_outcome.rs new file mode 100644 index 00000000..fa17633c --- /dev/null +++ b/src/stepper_outcome.rs @@ -0,0 +1,23 @@ +/* + * 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 fluence::fce; + +#[fce] +pub struct StepperOutcome { + pub data: String, + pub next_peer_pks: Vec, +} \ No newline at end of file