intro: 4-ipfs-code-execution (#15)

This commit is contained in:
folex
2021-07-21 11:37:25 +03:00
committed by GitHub
parent 5ecce263a6
commit e5e0d59835
35 changed files with 31554 additions and 0 deletions

View File

@ -0,0 +1,4 @@
debug/
target/
**/*.bk
**/*.bak

View File

@ -0,0 +1,21 @@
[package]
name = "process_files"
version = "0.1.0"
authors = ["Fluence Labs"]
edition = "2018"
description = "Marine service that processes files in various ways"
license = "Apache-2.0"
[[bin]]
name = "process_files"
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"
[profile.release]
opt-level = "s"

View File

@ -0,0 +1,6 @@
modules_dir = "artifacts/"
[[module]]
name = "process_files"
mem_pages_count = 1
logger_enabled = true

View File

@ -0,0 +1,8 @@
#!/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/process_files.wasm artifacts/
marine aqua artifacts/process_files.wasm >../aqua/process_files.aqua

View File

@ -0,0 +1,37 @@
/*
* 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};
module_manifest!();
pub fn main() { }
#[marine]
pub struct SizeResult {
pub size: u32,
pub success: bool,
pub error: String,
}
#[marine]
pub fn file_size(file_path: String) -> SizeResult {
match std::fs::read(file_path) {
Ok(bytes) => SizeResult { size: bytes.len() as _, success: true, error: String::new() },
Err(err) => SizeResult { size: 0, success: false, error: err.to_string() },
}
}