From f668c13074abf15a580af537f89163955c791d2f Mon Sep 17 00:00:00 2001 From: boneyard93501 <4523011+boneyard93501@users.noreply.github.com> Date: Wed, 20 Oct 2021 12:28:31 -0500 Subject: [PATCH] separate lib code from demo code --- .../services/ceramic-adapter-basic/.gitignore | 5 ++ .../services/ceramic-adapter-basic/Cargo.toml | 22 +++++++ .../ceramic-adapter-basic/src/ceramic_cli.rs | 59 +++++++++++++++++++ .../ceramic-adapter-basic/src/main.rs | 25 ++++++++ 4 files changed, 111 insertions(+) create mode 100644 aqua-examples/ceramic-demo/services/ceramic-adapter-basic/.gitignore create mode 100644 aqua-examples/ceramic-demo/services/ceramic-adapter-basic/Cargo.toml create mode 100644 aqua-examples/ceramic-demo/services/ceramic-adapter-basic/src/ceramic_cli.rs create mode 100644 aqua-examples/ceramic-demo/services/ceramic-adapter-basic/src/main.rs diff --git a/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/.gitignore b/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/.gitignore new file mode 100644 index 0000000..bbccc88 --- /dev/null +++ b/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/.gitignore @@ -0,0 +1,5 @@ +debug/ +target/ +Cargo.lock +**/*.bk +**/*.bak diff --git a/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/Cargo.toml b/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/Cargo.toml new file mode 100644 index 0000000..31f782a --- /dev/null +++ b/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "ceramic" +version = "0.1.0" +authors = ["boneyard93501 <4523011+boneyard93501@users.noreply.github.com>"] +edition = "2018" +description = "ceramic-adapter" +license = "Apache-2.0" + +[[bin]] +name = "ceramic_adapter" +path = "src/main.rs" + +[dependencies] +marine-rs-sdk = { version = "0.6.11", features = ["logger"] } +log = "0.4.14" + +[dev-dependencies] +marine-rs-sdk-test = "0.1.11" + +[dev] +[profile.release] +opt-level = "s" diff --git a/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/src/ceramic_cli.rs b/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/src/ceramic_cli.rs new file mode 100644 index 0000000..73b5bf2 --- /dev/null +++ b/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/src/ceramic_cli.rs @@ -0,0 +1,59 @@ +use marine_rs_sdk::{marine, MountedBinaryResult}; + +#[marine] +// general purpose request call where users provides the vector of +// properly formatted args +// e.g., +pub fn ceramic_request(args: Vec) -> MountedBinaryResult { + ceramic(args) +} + +#[marine] +pub fn create_stream(payload: String) -> MountedBinaryResult { + let args = vec![ + "create".to_string(), + "tile".to_string(), + "--content".to_string(), + payload, + ]; + ceramic(args) +} + +#[marine] +pub fn show(stream_id: String) -> MountedBinaryResult { + ceramic(vec!["show".to_string(), stream_id]) +} + +#[marine] +pub fn state(stream_id: String) -> MountedBinaryResult { + ceramic(vec!["state".to_string(), stream_id]) +} + +#[marine] +pub fn update(stream_id: String, payload: String) -> MountedBinaryResult { + ceramic(vec![ + "update".to_string(), + stream_id, + "--content".to_string(), + payload, + ]) +} + +#[marine] +pub fn create_schema(schema: String) -> MountedBinaryResult { + let args = vec![ + "create".to_string(), + "tile".to_string(), + "--content".to_string(), + schema, + ]; + ceramic(args) +} + +// link to binary on host node with `extern` where the path comes from the +// config file. E.g., `/usr/bin/ceramic` +#[marine] +#[link(wasm_import_module = "host")] +extern "C" { + pub fn ceramic(cmd: Vec) -> MountedBinaryResult; +} diff --git a/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/src/main.rs b/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/src/main.rs new file mode 100644 index 0000000..5da1ed5 --- /dev/null +++ b/aqua-examples/ceramic-demo/services/ceramic-adapter-basic/src/main.rs @@ -0,0 +1,25 @@ +/* + * Copyright 2021 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 marine_rs_sdk::{module_manifest, WasmLoggerBuilder}; + +module_manifest!(); + +pub mod ceramic_cli; + +pub fn main() { + WasmLoggerBuilder::new().build().ok(); +}