mirror of
https://github.com/fluencelabs/examples
synced 2025-06-13 01:51:20 +00:00
reorg
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ceramic_adapter",
|
"name": "ceramic_adapter",
|
||||||
"mountedBinaries": {
|
"mountedBinaries": {
|
||||||
"ceramic": "/usr/bin/ceramic""
|
"ceramic": "/usr/bin/ceramic"
|
||||||
},
|
},
|
||||||
"mem_page_count": 100,
|
"mem_page_count": 100,
|
||||||
"logger_enabled": false
|
"logger_enabled": false
|
||||||
|
@ -9,7 +9,7 @@ cargo update --aggressive
|
|||||||
marine build --release
|
marine build --release
|
||||||
cp target/wasm32-wasi/release/curl_adapter.wasm ../../artifacts/
|
cp target/wasm32-wasi/release/curl_adapter.wasm ../../artifacts/
|
||||||
|
|
||||||
cd ../ceramic-adapter
|
cd ../ceramic-adapter-custom
|
||||||
cargo update --aggressive
|
cargo update --aggressive
|
||||||
marine build --release
|
marine build --release
|
||||||
cp target/wasm32-wasi/release/ceramic_adapter.wasm ../../artifacts/
|
cp target/wasm32-wasi/release/ceramic_adapter.wasm ../../artifacts/
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
debug/
|
|
||||||
target/
|
|
||||||
Cargo.lock
|
|
||||||
**/*.bk
|
|
||||||
**/*.bak
|
|
@ -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"
|
|
@ -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<String>) -> 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<String>) -> MountedBinaryResult;
|
|
||||||
}
|
|
@ -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>) -> 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<String>) -> MountedBinaryResult;
|
|
||||||
}
|
|
@ -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();
|
|
||||||
}
|
|
@ -24,7 +24,7 @@ use marine_rs_sdk::WasmLoggerBuilder;
|
|||||||
module_manifest!();
|
module_manifest!();
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
// WasmLoggerBuilder::new().build().ok();
|
WasmLoggerBuilder::new().build().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[marine]
|
#[marine]
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
debug/
|
|
||||||
target/
|
|
||||||
Cargo.lock
|
|
||||||
**/*.bk
|
|
||||||
**/*.bak
|
|
@ -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"
|
|
@ -1,6 +0,0 @@
|
|||||||
modules_dir = "artifacts/"
|
|
||||||
|
|
||||||
[[module]]
|
|
||||||
name = "processor"
|
|
||||||
mem_pages_count = 1
|
|
||||||
logger_enabled = true
|
|
@ -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/
|
|
@ -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();
|
|
||||||
}
|
|
Reference in New Issue
Block a user