From 033cdfc203460854c392b566c9c54ad3aa605825 Mon Sep 17 00:00:00 2001 From: boneyard93501 <4523011+boneyard93501@users.noreply.github.com> Date: Wed, 20 Oct 2021 12:27:29 -0500 Subject: [PATCH] reorg --- .../configs/ceramic_adapter_cfg.json | 2 +- aqua-examples/ceramic-demo/scripts/build.sh | 2 +- .../services/ceramic-adapter/.gitignore | 5 - .../services/ceramic-adapter/Cargo.toml | 22 ---- .../ceramic-adapter/src/ceramic_cli.rs | 101 ------------------ .../ceramic-adapter/src/ceramic_http.rs | 81 -------------- .../services/ceramic-adapter/src/main.rs | 26 ----- .../services/curl-adapter/src/main.rs | 2 +- .../services/processor/.gitignore | 5 - .../services/processor/Cargo.toml | 32 ------ .../services/processor/Config.toml | 6 -- .../services/processor/scripts/build.sh | 7 -- .../services/processor/src/main.rs | 24 ----- 13 files changed, 3 insertions(+), 312 deletions(-) delete mode 100644 aqua-examples/ceramic-demo/services/ceramic-adapter/.gitignore delete mode 100644 aqua-examples/ceramic-demo/services/ceramic-adapter/Cargo.toml delete mode 100644 aqua-examples/ceramic-demo/services/ceramic-adapter/src/ceramic_cli.rs delete mode 100644 aqua-examples/ceramic-demo/services/ceramic-adapter/src/ceramic_http.rs delete mode 100644 aqua-examples/ceramic-demo/services/ceramic-adapter/src/main.rs delete mode 100644 aqua-examples/ceramic-demo/services/processor/.gitignore delete mode 100644 aqua-examples/ceramic-demo/services/processor/Cargo.toml delete mode 100644 aqua-examples/ceramic-demo/services/processor/Config.toml delete mode 100755 aqua-examples/ceramic-demo/services/processor/scripts/build.sh delete mode 100644 aqua-examples/ceramic-demo/services/processor/src/main.rs diff --git a/aqua-examples/ceramic-demo/configs/ceramic_adapter_cfg.json b/aqua-examples/ceramic-demo/configs/ceramic_adapter_cfg.json index 9c7fe68..48afdef 100644 --- a/aqua-examples/ceramic-demo/configs/ceramic_adapter_cfg.json +++ b/aqua-examples/ceramic-demo/configs/ceramic_adapter_cfg.json @@ -1,7 +1,7 @@ { "name": "ceramic_adapter", "mountedBinaries": { - "ceramic": "/usr/bin/ceramic"" + "ceramic": "/usr/bin/ceramic" }, "mem_page_count": 100, "logger_enabled": false diff --git a/aqua-examples/ceramic-demo/scripts/build.sh b/aqua-examples/ceramic-demo/scripts/build.sh index 29a965e..48475d9 100755 --- a/aqua-examples/ceramic-demo/scripts/build.sh +++ b/aqua-examples/ceramic-demo/scripts/build.sh @@ -9,7 +9,7 @@ cargo update --aggressive marine build --release cp target/wasm32-wasi/release/curl_adapter.wasm ../../artifacts/ -cd ../ceramic-adapter +cd ../ceramic-adapter-custom cargo update --aggressive marine build --release cp target/wasm32-wasi/release/ceramic_adapter.wasm ../../artifacts/ diff --git a/aqua-examples/ceramic-demo/services/ceramic-adapter/.gitignore b/aqua-examples/ceramic-demo/services/ceramic-adapter/.gitignore deleted file mode 100644 index bbccc88..0000000 --- a/aqua-examples/ceramic-demo/services/ceramic-adapter/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -debug/ -target/ -Cargo.lock -**/*.bk -**/*.bak diff --git a/aqua-examples/ceramic-demo/services/ceramic-adapter/Cargo.toml b/aqua-examples/ceramic-demo/services/ceramic-adapter/Cargo.toml deleted file mode 100644 index 31f782a..0000000 --- a/aqua-examples/ceramic-demo/services/ceramic-adapter/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[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/src/ceramic_cli.rs b/aqua-examples/ceramic-demo/services/ceramic-adapter/src/ceramic_cli.rs deleted file mode 100644 index 9f07d5c..0000000 --- a/aqua-examples/ceramic-demo/services/ceramic-adapter/src/ceramic_cli.rs +++ /dev/null @@ -1,101 +0,0 @@ -use marine_rs_sdk::{marine, MountedBinaryResult}; - -#[marine] -pub struct CeramicResult { - pub ret_code: i32, - pub stderr: String, - pub stdout: String, -} - -impl CeramicResult { - fn new(mb: MountedBinaryResult) -> Self { - CeramicResult { - ret_code: mb.ret_code, - stderr: String::from_utf8(mb.stderr).unwrap(), - stdout: String::from_utf8(mb.stdout).unwrap(), - } - } - - fn create(ret_code: i32, stdout: String, stderr: String) -> Self { - CeramicResult { - ret_code, - stderr, - stdout, - } - } -} - -#[marine] -pub fn ceramic_request(args: Vec) -> CeramicResult { - let response = ceramic(args); - CeramicResult::new(response) -} - -#[marine] -pub fn create_stream(payload: String) -> CeramicResult { - let args = vec![ - "create".to_string(), - "tile".to_string(), - "--content".to_string(), - payload, - ]; - let response: MountedBinaryResult = ceramic(args); - if response.stderr.len() > 0 { - return CeramicResult::new(response); - } - let stdout_str: String = String::from_utf8(response.stdout).unwrap(); - - if stdout_str.contains("StreamID") { - let res: Vec<&str> = stdout_str.split("\n").collect(); - let stream_id = res[0].replace("StreamID(", "").replace(")", ""); - return CeramicResult::create(response.ret_code, stream_id.to_string(), "".to_string()); - } else { - return CeramicResult::create( - response.ret_code, - "Missing StreamId".to_string(), - "".to_string(), - ); - } -} - -#[marine] -pub fn show(stream_id: String) -> CeramicResult { - let response = ceramic(vec!["show".to_string(), stream_id]); - CeramicResult::new(response) -} - -#[marine] -pub fn state(stream_id: String) -> CeramicResult { - let response = ceramic(vec!["state".to_string(), stream_id]); - CeramicResult::new(response) -} - -#[marine] -pub fn update(stream_id: String, payload: String) -> CeramicResult { - let response = ceramic(vec![ - "update".to_string(), - stream_id, - "--content".to_string(), - payload, - ]); - CeramicResult::new(response) -} - -#[marine] -pub fn create_schema(schema: String) -> CeramicResult { - let args = vec![ - "create".to_string(), - "tile".to_string(), - "--content".to_string(), - schema, - ]; - let response = ceramic(args); - CeramicResult::new(response) -} - -// mounted_binaries are available to import like this: -#[marine] -#[link(wasm_import_module = "host")] -extern "C" { - pub fn ceramic(cmd: Vec) -> MountedBinaryResult; -} diff --git a/aqua-examples/ceramic-demo/services/ceramic-adapter/src/ceramic_http.rs b/aqua-examples/ceramic-demo/services/ceramic-adapter/src/ceramic_http.rs deleted file mode 100644 index c77996b..0000000 --- a/aqua-examples/ceramic-demo/services/ceramic-adapter/src/ceramic_http.rs +++ /dev/null @@ -1,81 +0,0 @@ -use marine_rs_sdk::{marine, MountedBinaryResult}; - -// source: https://developers.ceramic.network/build/http/api/ -static API: &str = "api"; -static VERSION: &str = "v0"; -static STREAM: &str = "streams"; - -fn url_maker(host: String, port: u32, arg: String, stream_id: Option) -> String { - let curl_args = format!( - "http://{}:{}/{}/{}/{}", - host, - port, - API, - VERSION, - arg.to_uppercase(), - ); - match stream_id { - Some(sid) => format!("{}/{}", curl_args, sid), - None => curl_args, - } -} - -#[marine] -pub fn http_streams(url: String, port: u32, stream_id: String) -> String { - // curl http://localhost:7007/api/v0/streams/kjzl6cwe1jw147r7878h32yazawcll6bxe5v92348cxitif6cota91qp68grbhm - let url = url_maker(url, port, STREAM.to_string(), Some(stream_id)); - let cmd = vec![url, "GET".to_string()]; - let response: MountedBinaryResult = curl_request(cmd); - String::from_utf8(response.stdout).unwrap() -} - -#[marine] -pub fn http_chain_id(url: String, port: u32) -> String { - let url = url_maker(url, port, "NODE/CHAINS".to_string(), None); - let cmd = vec![url, "GET".to_string()]; - println!("cmd: {:?}", cmd); - let response: MountedBinaryResult = curl_request(cmd); - String::from_utf8(response.stdout).unwrap() -} - -#[marine] -pub fn http_health(url: String, port: u32) -> String { - let url = url_maker(url, port, "NODE/HEALTHCHECK".to_string(), None); - let cmd = vec![url, "GET".to_string()]; - println!("cmd: {:?}", cmd); - let response: MountedBinaryResult = curl_request(cmd); - String::from_utf8(response.stdout).unwrap() -} - -#[marine] -pub fn http_pins(url: String, port: u32) -> String { - let url = url_maker(url, port, "PINS".to_string(), None); - let cmd = vec![url, "GET".to_string()]; - let response: MountedBinaryResult = curl_request(cmd); - String::from_utf8(response.stdout).unwrap() -} - -#[marine] -pub fn http_pin(url: String, port: u32, stream_id: String) -> String { - let url = url_maker(url, port, "PINS".to_string(), Some(stream_id)); - let cmd = vec![url, "GET".to_string()]; - println!("cmd: {:?}", cmd); - let response: MountedBinaryResult = curl_request(cmd); - String::from_utf8(response.stdout).unwrap() -} - -#[marine] -pub fn http_rm_pin(url: String, port: u32, stream_id: String) -> String { - // not available in gateway mode: https://developers.ceramic.network/build/http/api/#remove-from-pinset - let url = url_maker(url, port, "PINS".to_string(), Some(stream_id)); - let cmd = vec![url, "-X DELETE".to_string()]; - println!("cmd: {:?}", cmd); - let response: MountedBinaryResult = curl_request(cmd); - String::from_utf8(response.stdout).unwrap() -} - -#[marine] -#[link(wasm_import_module = "curl_adapter")] -extern "C" { - pub fn curl_request(cmd: Vec) -> MountedBinaryResult; -} diff --git a/aqua-examples/ceramic-demo/services/ceramic-adapter/src/main.rs b/aqua-examples/ceramic-demo/services/ceramic-adapter/src/main.rs deleted file mode 100644 index 13fc255..0000000 --- a/aqua-examples/ceramic-demo/services/ceramic-adapter/src/main.rs +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 mod ceramic_http; - -pub fn main() { - // WasmLoggerBuilder::new().build().ok(); -} diff --git a/aqua-examples/ceramic-demo/services/curl-adapter/src/main.rs b/aqua-examples/ceramic-demo/services/curl-adapter/src/main.rs index 16b1451..e60fc7f 100644 --- a/aqua-examples/ceramic-demo/services/curl-adapter/src/main.rs +++ b/aqua-examples/ceramic-demo/services/curl-adapter/src/main.rs @@ -24,7 +24,7 @@ use marine_rs_sdk::WasmLoggerBuilder; module_manifest!(); pub fn main() { - // WasmLoggerBuilder::new().build().ok(); + WasmLoggerBuilder::new().build().ok(); } #[marine] diff --git a/aqua-examples/ceramic-demo/services/processor/.gitignore b/aqua-examples/ceramic-demo/services/processor/.gitignore deleted file mode 100644 index bbccc88..0000000 --- a/aqua-examples/ceramic-demo/services/processor/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -debug/ -target/ -Cargo.lock -**/*.bk -**/*.bak diff --git a/aqua-examples/ceramic-demo/services/processor/Cargo.toml b/aqua-examples/ceramic-demo/services/processor/Cargo.toml deleted file mode 100644 index 788fe91..0000000 --- a/aqua-examples/ceramic-demo/services/processor/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -name = "processor" -version = "0.1.0" -authors = ["boneyard93501 <4523011+boneyard93501@users.noreply.github.com>"] -edition = "2018" -description = "processor, a Marine wasi module" -license = "Apache-2.0" - -[[bin]] -name = "processor" -path = "src/main.rs" - -[dependencies] -marine-rs-sdk = { version = "0.6.11", features = ["logger"] } -log = "0.4.14" -# eip-712 = { git = "https://github.com/717a56e1/openethereum/", branch = "eip-712-parser", package = "eip-712" } -eip-712 = { path = "/Users/bebo/localdev/openethereum/crates/util/EIP-712" } -rustc-hex = "2.1.0" -serde_json = "1.0.66" -zeroize = "1.4.1" -validator = "0.8" -chrono = "0.4.19" -libsecp256k1 = "0.6.0" -tiny-keccak = "2.0.2" -hex = "0.4.3" - -[dev-dependencies] -marine-rs-sdk-test = "0.1.11" - -[dev] -[profile.release] -opt-level = "s" diff --git a/aqua-examples/ceramic-demo/services/processor/Config.toml b/aqua-examples/ceramic-demo/services/processor/Config.toml deleted file mode 100644 index b22b42c..0000000 --- a/aqua-examples/ceramic-demo/services/processor/Config.toml +++ /dev/null @@ -1,6 +0,0 @@ -modules_dir = "artifacts/" - -[[module]] - name = "processor" - mem_pages_count = 1 - logger_enabled = true diff --git a/aqua-examples/ceramic-demo/services/processor/scripts/build.sh b/aqua-examples/ceramic-demo/services/processor/scripts/build.sh deleted file mode 100755 index 705d8cd..0000000 --- a/aqua-examples/ceramic-demo/services/processor/scripts/build.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -o errexit -o nounset -o pipefail -cargo update --aggressive - -mkdir -p artifacts -rm -f artifacts/*.wasm -marine build --release -cp target/wasm32-wasi/release/processor.wasm artifacts/ diff --git a/aqua-examples/ceramic-demo/services/processor/src/main.rs b/aqua-examples/ceramic-demo/services/processor/src/main.rs deleted file mode 100644 index 5373f81..0000000 --- a/aqua-examples/ceramic-demo/services/processor/src/main.rs +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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::{marine, module_manifest, WasmLoggerBuilder}; -use serde_json; - -module_manifest!(); - -pub fn main() { - WasmLoggerBuilder::new().build().ok(); -}