mirror of
https://github.com/fluencelabs/examples
synced 2024-12-04 19:20:17 +00:00
update fce examples
This commit is contained in:
parent
3dd0c531ea
commit
c2e4e5e4cb
@ -10,4 +10,4 @@ name = "call_parameters"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = "=0.3.2"
|
||||
fluence = "=0.5.0"
|
||||
|
@ -2,6 +2,8 @@
|
||||
name = "wasm-greeting"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
description = "The greeting module for the Fluence network"
|
||||
repository = "https://github.com/fluencelabs/fce/tree/master/examples/greeting"
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
@ -10,4 +12,4 @@ name = "greeting"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = "=0.3.2"
|
||||
fluence = "0.5.0"
|
||||
|
@ -15,6 +15,9 @@
|
||||
*/
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
|
@ -10,5 +10,5 @@ name = "ipfs_effector"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.3.2", features = ["logger"] }
|
||||
log = "0.4.11"
|
||||
fluence = { version = "=0.5.0", features = ["logger"] }
|
||||
log = "0.4.14"
|
||||
|
@ -21,6 +21,7 @@ mod path;
|
||||
use crate::path::to_full_path;
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
use fluence::WasmLoggerBuilder;
|
||||
use fluence::MountedBinaryResult;
|
||||
|
||||
@ -28,9 +29,11 @@ const RESULT_FILE_PATH: &str = "/tmp/ipfs_rpc_file";
|
||||
const IPFS_ADDR_ENV_NAME: &str = "IPFS_ADDR";
|
||||
const TIMEOUT_ENV_NAME: &str = "timeout";
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {
|
||||
WasmLoggerBuilder::new()
|
||||
.with_log_level(log::Level::Info)
|
||||
.with_log_level(log::LevelFilter::Info)
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -10,5 +10,5 @@ name = "ipfs_pure"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.3.2", features = ["logger"] }
|
||||
log = "0.4.11"
|
||||
fluence = { version = "=0.5.0", features = ["logger"] }
|
||||
log = "0.4.14"
|
||||
|
@ -17,6 +17,7 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
use fluence::WasmLoggerBuilder;
|
||||
|
||||
use std::fs;
|
||||
@ -24,9 +25,11 @@ use std::path::PathBuf;
|
||||
|
||||
const RPC_TMP_FILEPATH: &str = "/tmp/ipfs_rpc_file";
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {
|
||||
WasmLoggerBuilder::new()
|
||||
.with_log_level(log::Level::Info)
|
||||
.with_log_level(log::LevelFilter::Info)
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -10,5 +10,5 @@ name = "records_effector"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.3.2", features = ["logger"]}
|
||||
fluence = { version = "=0.5.0", features = ["logger"]}
|
||||
test-record = { path = "../test-record" }
|
||||
|
@ -15,8 +15,12 @@
|
||||
*/
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
|
||||
use test_record::TestRecord;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[fce]
|
||||
|
@ -10,5 +10,5 @@ name = "records_pure"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.3.2", features = ["logger"]}
|
||||
fluence = { version = "=0.5.0", features = ["logger"]}
|
||||
test-record = { path = "../test-record" }
|
||||
|
@ -17,8 +17,12 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
|
||||
use test_record::TestRecord;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[fce]
|
||||
|
@ -10,4 +10,4 @@ name = "test_record"
|
||||
path = "src/test_record.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = "=0.3.2"
|
||||
fluence = "=0.5.0"
|
||||
|
@ -10,5 +10,5 @@ name = "sqlite_test"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = "=0.3.2"
|
||||
fce-sqlite-connector = "=0.1.3"
|
||||
fluence = "0.5.0"
|
||||
fce-sqlite-connector = "0.2.0"
|
||||
|
@ -5,9 +5,15 @@ modules_dir = "artifacts/"
|
||||
mem_pages_count = 100
|
||||
logger_enabled = false
|
||||
|
||||
[module.wasi]
|
||||
preopened_files = ["/tmp"]
|
||||
mapped_dirs = { "tmp" = "/tmp" }
|
||||
|
||||
[[module]]
|
||||
name = "sqlite_test"
|
||||
name = "sqlite_test"
|
||||
mem_pages_count = 1
|
||||
logger_enabled = false
|
||||
preopened_files = ["/var"]
|
||||
mapped_dirs = { "var" = "./var" }
|
||||
|
||||
[module.wasi]
|
||||
preopened_files = ["/tmp"]
|
||||
mapped_dirs = { "tmp" = "/tmp" }
|
||||
|
@ -6,5 +6,5 @@ fce build --release
|
||||
|
||||
rm artifacts/*
|
||||
cp ../../target/wasm32-wasi/release/sqlite_test.wasm artifacts/
|
||||
wget https://github.com/fluencelabs/sqlite/releases/download/v0.9.0_w/sqlite3.wasm
|
||||
wget https://github.com/fluencelabs/sqlite/releases/download/v0.10.0_w/sqlite3.wasm
|
||||
mv sqlite3.wasm artifacts/
|
||||
|
@ -15,9 +15,13 @@
|
||||
*/
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
|
||||
use fce_sqlite_connector;
|
||||
use fce_sqlite_connector::State;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[fce]
|
||||
@ -83,20 +87,21 @@ pub fn test2(age: i64) {
|
||||
|
||||
#[fce]
|
||||
pub fn test3() {
|
||||
let db_path = "/var/users.sqlite";
|
||||
let connection = fce_sqlite_connector::open(db_path).expect("error on connection establishing");
|
||||
let db_path = "/tmp/users.sqlite";
|
||||
let connection = fce_sqlite_connector::open(db_path).expect("db should be opened");
|
||||
|
||||
let execute_result = connection.execute(
|
||||
"
|
||||
CREATE TABLE users (name TEXT, age INTEGER);
|
||||
connection
|
||||
.execute(
|
||||
"
|
||||
CREATE TABLE IF NOT EXISTS users (name TEXT, age INTEGER);
|
||||
INSERT INTO users VALUES ('Alice', 42);
|
||||
INSERT INTO users VALUES ('Bob', 69);
|
||||
",
|
||||
);
|
||||
)
|
||||
.expect("table should be created successfully");
|
||||
|
||||
println!("execute result: {:?}", execute_result);
|
||||
let connection = fce_sqlite_connector::open(db_path).expect("db should be opened");
|
||||
let cursor = connection.prepare("SELECT * FROM users").unwrap().cursor();
|
||||
|
||||
//TODO fix it
|
||||
// let file_size = std::fs::metadata(db_path).expect("error on file_size check").len();
|
||||
// println!("{} file size is {}", db_path, file_size);
|
||||
println!("table size is: {:?}", cursor.count());
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
# Download file to disk
|
||||
|
||||
Example to show how to work with disk + link several .wasm modules into a service.
|
||||
|
||||
# Build & deploy it
|
||||
```shell
|
||||
./deploy.sh
|
||||
```
|
||||
|
||||
# Call it
|
||||
```shell
|
||||
fldist run_air -p download.air -d '{"service": "08eba00d-ff40-4e38-bbe6-ee3646498400"}'
|
||||
```
|
||||
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"name": "curl_adapter",
|
||||
"mountedBinaries":
|
||||
{
|
||||
"curl": "/usr/bin/curl"
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
{"name": "facade"}
|
@ -1,12 +0,0 @@
|
||||
{
|
||||
"name": "local_storage",
|
||||
"preopenedFiles": [
|
||||
"/tmp"
|
||||
],
|
||||
"mappedDirs": {
|
||||
"sites": "/tmp"
|
||||
},
|
||||
"mountedBinaries": {
|
||||
"curl": "/usr/bin/curl"
|
||||
}
|
||||
}
|
@ -1,24 +1,18 @@
|
||||
#!/bin/sh -euo pipefail
|
||||
#!/bin/sh
|
||||
|
||||
# This script builds all subprojects and puts all created Wasm modules in one dir
|
||||
(
|
||||
cd local_storage
|
||||
cargo update
|
||||
fce build --release
|
||||
)
|
||||
(
|
||||
cd curl_adapter
|
||||
cargo update
|
||||
fce build --release
|
||||
)
|
||||
(
|
||||
cd facade
|
||||
cargo update
|
||||
fce build --release
|
||||
)
|
||||
cd local_storage
|
||||
cargo update
|
||||
fce build --release
|
||||
cd ../curl_adapter
|
||||
cargo update
|
||||
fce build --release
|
||||
cd ../facade
|
||||
cargo update
|
||||
fce build --release
|
||||
|
||||
mkdir -p artifacts
|
||||
rm -f artifacts/*.wasm
|
||||
cp local_storage/target/wasm32-wasi/release/local_storage.wasm artifacts/
|
||||
cp curl_adapter/target/wasm32-wasi/release/curl_adapter.wasm artifacts/
|
||||
cp facade/target/wasm32-wasi/release/facade.wasm artifacts/
|
||||
cd ..
|
||||
rm -f artifacts/*
|
||||
cp ../../target/wasm32-wasi/release/local_storage.wasm artifacts/
|
||||
cp ../../target/wasm32-wasi/release/curl_adapter.wasm artifacts/
|
||||
cp ../../target/wasm32-wasi/release/facade.wasm artifacts/
|
||||
|
@ -1,13 +0,0 @@
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call relay (curl "download") ["https://fluence.network/img/svg/logo_new.svg"] contents)
|
||||
(call relay (storage "put") ["logo.svg" contents.$.stdout!] ret_code)
|
||||
)
|
||||
(call relay (storage "get") ["logo.svg"] bytes)
|
||||
)
|
||||
(call %init_peer_id% (returnService "run") [ret_code bytes])
|
||||
)
|
||||
(call %init_peer_id% (returnService "run") [%last_error%])
|
||||
)
|
178
url-downloader/curl_adapter/Cargo.lock
generated
178
url-downloader/curl_adapter/Cargo.lock
generated
@ -1,178 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "curl_adapter"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"fluence",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84c621ecf5ba628a3a66c4571cb63b9e57de5b8e1ffbb4636873349d04ed9c4c"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"fluence-sdk-main",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-macro"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3ed152de2a9f59c5494a5ead9d85b40cc1588696d10bb69129addebf0239efb"
|
||||
dependencies = [
|
||||
"fluence-sdk-wit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-main"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ed74c32aded592c2a4c2d11a4586369e2d9f793e6c7b500a2a22f4a61769784"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"log",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-wit"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a65bb11a2ebb063b8809e43c1837d32e44c12ba3c281e55f2fcf5c5819a6a9ad"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"syn",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43535db9747a4ba938c0ce0a98cc631a46ebf943c9e1d604e091df6007620bf6"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -10,5 +10,5 @@ path = "src/main.rs"
|
||||
name = "curl_adapter"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.3.3", features = ["logger"] }
|
||||
fluence = { version = "=0.5.0", features = ["logger"] }
|
||||
log = "0.4.8"
|
||||
|
@ -17,10 +17,12 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
|
||||
use fluence::WasmLoggerBuilder;
|
||||
use fluence::MountedBinaryResult as Result;
|
||||
use fluence::MountedBinaryStringResult as StringResult;
|
||||
use fluence::MountedBinaryResult;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
/// Log level can be changed by `RUST_LOG` env as well.
|
||||
pub fn main() {
|
||||
@ -28,21 +30,16 @@ pub fn main() {
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn request(url: String) -> StringResult {
|
||||
unsafe { curl(vec![url]) }.stringify().unwrap()
|
||||
pub fn download(url: String) -> String {
|
||||
log::info!("get called with url {}", url);
|
||||
|
||||
let result = unsafe { curl(vec![url]) };
|
||||
String::from_utf8(result.stdout).unwrap()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn download(url: String) -> Result {
|
||||
log::info!("download called with url {}", url);
|
||||
|
||||
unsafe { curl(vec![url]) }
|
||||
}
|
||||
|
||||
|
||||
/// Permissions in `Config.toml` should exist to use host functions.
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "host")]
|
||||
extern "C" {
|
||||
fn curl(cmd: Vec<String>) -> Result;
|
||||
fn curl(cmd: Vec<String>) -> MountedBinaryResult;
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
#!/bin/sh -euo pipefail
|
||||
|
||||
# build wasms
|
||||
./build.sh
|
||||
|
||||
(
|
||||
cd artifacts
|
||||
fldist new_service --name "url_downloader" --modules \
|
||||
curl_adapter.wasm:curl_adapter.json \
|
||||
local_storage.wasm:local_storage.json \
|
||||
facade.wasm:facade.json
|
||||
)
|
@ -1,15 +0,0 @@
|
||||
#!/bin/sh -euo pipefail
|
||||
|
||||
./build.sh
|
||||
|
||||
echo "Deploying storage"
|
||||
(
|
||||
cd artifacts
|
||||
fldist new_service --name "local_storage" --modules local_storage.wasm:local_storage.json
|
||||
)
|
||||
|
||||
echo "\n\nDeploying curl"
|
||||
(
|
||||
cd artifacts
|
||||
fldist new_service --name "curl_adapter" --modules curl_adapter.wasm:curl_adapter.json
|
||||
)
|
@ -1,10 +0,0 @@
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call relay (service "get_n_save") ["https://fluence.network/img/svg/logo_new.svg" "logo.svg"] ret_code)
|
||||
(call relay (service "load_file") ["logo.svg"] bytes)
|
||||
)
|
||||
(call %init_peer_id% (returnService "run") [ret_code bytes])
|
||||
)
|
||||
(call %init_peer_id% (returnService "run") [%last_error%])
|
||||
)
|
185
url-downloader/facade/Cargo.lock
generated
185
url-downloader/facade/Cargo.lock
generated
@ -1,185 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "facade"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"fluence",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84c621ecf5ba628a3a66c4571cb63b9e57de5b8e1ffbb4636873349d04ed9c4c"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"fluence-sdk-main",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-macro"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3ed152de2a9f59c5494a5ead9d85b40cc1588696d10bb69129addebf0239efb"
|
||||
dependencies = [
|
||||
"fluence-sdk-wit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-main"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ed74c32aded592c2a4c2d11a4586369e2d9f793e6c7b500a2a22f4a61769784"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"log",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-wit"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a65bb11a2ebb063b8809e43c1837d32e44c12ba3c281e55f2fcf5c5819a6a9ad"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"syn",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43535db9747a4ba938c0ce0a98cc631a46ebf943c9e1d604e091df6007620bf6"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -10,6 +10,6 @@ name = "facade"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.3.3", features = ["logger"]}
|
||||
fluence = { version = "=0.5.0", features = ["logger"]}
|
||||
anyhow = "1.0.31"
|
||||
log = "0.4.8"
|
||||
base64 = "0.13.0"
|
||||
|
@ -16,9 +16,11 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::MountedBinaryResult as Result;
|
||||
use fluence::module_manifest;
|
||||
use fluence::WasmLoggerBuilder;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {
|
||||
WasmLoggerBuilder::new().build().unwrap();
|
||||
}
|
||||
@ -28,30 +30,19 @@ pub fn main() {
|
||||
#[fce]
|
||||
pub fn get_n_save(url: String, file_name: String) -> String {
|
||||
let result = unsafe { download(url) };
|
||||
if result.is_success() {
|
||||
log::info!("saving file {}", file_name);
|
||||
unsafe { file_put(file_name, result.stdout) }
|
||||
} else {
|
||||
log::error!("download failed: {:#?}", result.as_std());
|
||||
format!("download failed: {:#?}", result.as_std())
|
||||
}
|
||||
unsafe { file_put(file_name, result.into_bytes()) };
|
||||
|
||||
String::from("Ok")
|
||||
}
|
||||
|
||||
#[fce]
|
||||
/// Loads file from disk and returns its content as base64
|
||||
pub fn load_file(file_name: String) -> String {
|
||||
let bytes = unsafe { file_get(file_name) };
|
||||
base64::encode(bytes)
|
||||
}
|
||||
|
||||
/// Import `curl_adapter` module
|
||||
/// Importing `curl` module
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "curl_adapter")]
|
||||
extern "C" {
|
||||
pub fn download(url: String) -> Result;
|
||||
pub fn download(url: String) -> String;
|
||||
}
|
||||
|
||||
/// Import `local_storage` module
|
||||
/// Importing `local_storage` module
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "local_storage")]
|
||||
extern "C" {
|
||||
|
178
url-downloader/local_storage/Cargo.lock
generated
178
url-downloader/local_storage/Cargo.lock
generated
@ -1,178 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "fluence"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84c621ecf5ba628a3a66c4571cb63b9e57de5b8e1ffbb4636873349d04ed9c4c"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"fluence-sdk-main",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-macro"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3ed152de2a9f59c5494a5ead9d85b40cc1588696d10bb69129addebf0239efb"
|
||||
dependencies = [
|
||||
"fluence-sdk-wit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-main"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ed74c32aded592c2a4c2d11a4586369e2d9f793e6c7b500a2a22f4a61769784"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"log",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-wit"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a65bb11a2ebb063b8809e43c1837d32e44c12ba3c281e55f2fcf5c5819a6a9ad"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"syn",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "local_storage"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"fluence",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43535db9747a4ba938c0ce0a98cc631a46ebf943c9e1d604e091df6007620bf6"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -10,5 +10,5 @@ name = "local_storage"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.3.3", features = ["logger"]}
|
||||
fluence = { version = "=0.5.0", features = ["logger"]}
|
||||
log = "0.4.8"
|
||||
|
@ -14,10 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use std::fs;
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
use fluence::WasmLoggerBuilder;
|
||||
use std::path::Path;
|
||||
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
const SITES_DIR: &str = "/sites/";
|
||||
|
||||
@ -28,14 +32,14 @@ pub fn main() {
|
||||
|
||||
/// You can read or write files from the file system if there is permission to use directories described in `Config.toml`.
|
||||
#[fce]
|
||||
pub fn put(file_name: String, file_content: Vec<u8>) -> String {
|
||||
log::info!("put called with file name {}", file_name);
|
||||
pub fn put(name: String, file_content: Vec<u8>) -> String {
|
||||
log::info!("put called with file name {}", name);
|
||||
|
||||
let path = Path::new(SITES_DIR).join(file_name);
|
||||
let rpc_tmp_filepath = format!("{}{}", SITES_DIR, name);
|
||||
|
||||
let result = fs::write(&path, file_content);
|
||||
let result = fs::write(PathBuf::from(rpc_tmp_filepath.clone()), file_content);
|
||||
if let Err(e) = result {
|
||||
return format!("file {} can't be written: {}", path.to_string_lossy(), e);
|
||||
return format!("file can't be written: {}", e);
|
||||
}
|
||||
|
||||
String::from("Ok")
|
||||
@ -45,7 +49,7 @@ pub fn put(file_name: String, file_content: Vec<u8>) -> String {
|
||||
pub fn get(file_name: String) -> Vec<u8> {
|
||||
log::info!("get called with file name: {}", file_name);
|
||||
|
||||
let path = Path::new(SITES_DIR).join(file_name);
|
||||
let tmp_filepath = format!("{}{}", SITES_DIR, file_name);
|
||||
|
||||
fs::read(&path).unwrap_or_else(|err| format!("error while reading file {}: {}", path.to_string_lossy(), err).into_bytes())
|
||||
fs::read(tmp_filepath).unwrap_or_else(|_| b"error while reading file".to_vec())
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
modules_dir = "artifacts/"
|
||||
|
||||
[[module]]
|
||||
name = "local_storage"
|
||||
logger_enabled = true
|
||||
|
||||
[module.wasi]
|
||||
preopened_files = ["."]
|
||||
# this is where files will be stored
|
||||
mapped_dirs = { "sites" = "." }
|
||||
|
||||
[[module]]
|
||||
name = "curl_adapter"
|
||||
logger_enabled = true
|
||||
|
||||
[module.mounted_binaries]
|
||||
curl = "/usr/bin/curl"
|
||||
|
||||
[[module]]
|
||||
name = "facade"
|
||||
logger_enabled = true
|
Loading…
Reference in New Issue
Block a user