separate lib code from demo code

This commit is contained in:
boneyard93501 2021-10-20 12:28:31 -05:00
parent 033cdfc203
commit f668c13074
4 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,5 @@
debug/
target/
Cargo.lock
**/*.bk
**/*.bak

View File

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

View File

@ -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<String>) -> 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<String>) -> MountedBinaryResult;
}

View File

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