mirror of
https://github.com/fluencelabs/examples
synced 2025-06-13 18:11:22 +00:00
update to fce 0.6.2, remove unsafe
This commit is contained in:
@ -18,8 +18,7 @@ use crate::curl_request;
|
||||
use fluence::fce;
|
||||
use fluence::MountedBinaryResult;
|
||||
|
||||
|
||||
fn result_to_string(result:MountedBinaryResult) -> String {
|
||||
fn result_to_string(result: MountedBinaryResult) -> String {
|
||||
if result.is_success() {
|
||||
return String::from_utf8(result.stdout).expect("Found invalid UTF-8");
|
||||
}
|
||||
@ -28,11 +27,12 @@ fn result_to_string(result:MountedBinaryResult) -> String {
|
||||
|
||||
#[fce]
|
||||
pub fn get_latest_block(api_key: String) -> String {
|
||||
let url = f!("https://api.etherscan.io/api?module=proxy&action=eth_blockNumber&apikey={api_key}");
|
||||
let url =
|
||||
f!("https://api.etherscan.io/api?module=proxy&action=eth_blockNumber&apikey={api_key}");
|
||||
let header = "-d \"\"";
|
||||
|
||||
let curl_cmd:Vec<String> = vec![header.into(), url.into()];
|
||||
let response = unsafe { curl_request(curl_cmd) };
|
||||
let curl_cmd: Vec<String> = vec![header.into(), url.into()];
|
||||
let response = curl_request(curl_cmd);
|
||||
let res = result_to_string(response);
|
||||
let obj = serde_json::from_str::<serde_json::Value>(&res).unwrap();
|
||||
serde_json::from_value(obj["result"].clone()).unwrap()
|
||||
@ -43,7 +43,7 @@ pub fn get_block(api_key: String, block_number: u32) -> String {
|
||||
let url = f!("https://api.etherscan.io/api?module=block&action=getblockreward&blockno={block_number}&apikey={api_key}");
|
||||
let header = "-d \"\"";
|
||||
|
||||
let curl_cmd:Vec<String> = vec![header.into(), url];
|
||||
let response = unsafe { curl_request(curl_cmd) };
|
||||
let curl_cmd: Vec<String> = vec![header.into(), url];
|
||||
let response = curl_request(curl_cmd);
|
||||
result_to_string(response)
|
||||
}
|
||||
|
@ -16,11 +16,14 @@
|
||||
#[macro_use]
|
||||
extern crate fstrings;
|
||||
|
||||
use fluence::module_manifest;
|
||||
use fluence::MountedBinaryResult;
|
||||
use fluence::{fce, WasmLoggerBuilder};
|
||||
use fluence::MountedBinaryResult as Result;
|
||||
|
||||
mod eth_block_getters;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
fn main() {
|
||||
WasmLoggerBuilder::new().build().ok();
|
||||
}
|
||||
@ -28,6 +31,5 @@ fn main() {
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "curl_adapter")]
|
||||
extern "C" {
|
||||
pub fn curl_request(curl_cmd: Vec<String>) -> Result;
|
||||
pub fn curl_request(curl_cmd: Vec<String>) -> MountedBinaryResult;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,6 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.3.3", features = ["logger"] }
|
||||
fluence = { version = "=0.6.2", features = ["logger"] }
|
||||
log = "0.4.8"
|
||||
serde_json = "1.0.64"
|
||||
|
@ -1,17 +1,19 @@
|
||||
use fluence::module_manifest;
|
||||
use fluence::{fce, WasmLoggerBuilder};
|
||||
use serde_json;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
fn main() {
|
||||
WasmLoggerBuilder::new().build().ok();
|
||||
}
|
||||
|
||||
|
||||
#[fce]
|
||||
pub fn extract_miner_address(json_string: String) -> String {
|
||||
let obj = serde_json::from_str::<serde_json::Value>(&json_string);
|
||||
match obj {
|
||||
Ok(x) => x["result"]["blockMiner"].to_string(),
|
||||
// Ok(x) => json_string,
|
||||
Ok(x) => x["result"]["blockMiner"].to_string(),
|
||||
// Ok(x) => json_string,
|
||||
Err(_) => String::from("boo yah"),
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,6 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.3.3", features = ["logger"] }
|
||||
fluence = { version = "=0.6.2", features = ["logger"] }
|
||||
log = "0.4.8"
|
||||
serde_json = "1.0.64"
|
||||
|
@ -14,9 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use fluence::module_manifest;
|
||||
use fluence::{fce, WasmLoggerBuilder};
|
||||
use serde_json;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
fn main() {
|
||||
WasmLoggerBuilder::new().build().ok();
|
||||
}
|
||||
@ -29,15 +32,17 @@ pub fn hex_to_int(data: String) -> u64 {
|
||||
return res.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
if data.contains("result") {
|
||||
let obj = serde_json::from_str::<serde_json::Value>(&data);
|
||||
let res = match obj {
|
||||
Ok(x) => { let res = x["result"].to_string(); u64::from_str_radix(&res[2..], 16).unwrap()},
|
||||
Ok(x) => {
|
||||
let res = x["result"].to_string();
|
||||
u64::from_str_radix(&res[2..], 16).unwrap()
|
||||
}
|
||||
Err(_) => 0u64,
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
0u64
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ cd extract_miner_address
|
||||
fce build --release
|
||||
cd ..
|
||||
|
||||
rm -f artifacts/*
|
||||
rm -f artifacts/*.wasm
|
||||
|
||||
cp curl_adapter/target/wasm32-wasi/release/curl_adapter.wasm artifacts/
|
||||
cp hex_converter/target/wasm32-wasi/release/hex_converter.wasm artifacts/
|
||||
cp block_getter/target/wasm32-wasi/release/block_getter.wasm artifacts/
|
||||
|
109
multi-service/simple_range_func/Cargo.lock
generated
109
multi-service/simple_range_func/Cargo.lock
generated
@ -1,5 +1,11 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
@ -7,29 +13,54 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "fluence"
|
||||
version = "0.2.18"
|
||||
name = "chrono"
|
||||
version = "0.4.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27d9a5e4292d7bbd809a0e968e3c3aacac91cbc5acab3e26ee1e1d726f0aab24"
|
||||
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"time",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fce-timestamp-macro"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c59a6302902583b2c84e87de9d72b949da4396a369baf0aaa49e97021600bb0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b731bd4a69a3945186f2ff96ff753908939c8a2debd60e1f0e8edb6a28757f8"
|
||||
dependencies = [
|
||||
"fce-timestamp-macro",
|
||||
"fluence-sdk-macro",
|
||||
"fluence-sdk-main",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-macro"
|
||||
version = "0.2.18"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea1a7c75a617f827d1ba9a17b4d84e1565ab239915c63f5a85c41f89a9f1d4ba"
|
||||
checksum = "cb43d2f51f1becb70e2125ef8ca9759597900f95cc22ce7dca981a7d6ccd7dde"
|
||||
dependencies = [
|
||||
"fluence-sdk-wit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-main"
|
||||
version = "0.2.18"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6edcc983f9517c1b6bf9f851ef27f2894a3159aaa4a2fb6c9deb2ae8ecb603fa"
|
||||
checksum = "a78910d85e3cdcb9c2baf56144f20a99925c67ac445d4156220c005bfd2f9604"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"log",
|
||||
@ -38,9 +69,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-wit"
|
||||
version = "0.2.18"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b75dbdd0275160f3818db3218563d791e6c612b616cd3c5d6e66283f207f648d"
|
||||
checksum = "eab3ed39703b72e0e52bce9e1760746c73f65a5694c8da4dec751d3bfdec15b8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -82,6 +113,25 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
@ -147,15 +197,26 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.60"
|
||||
version = "1.0.67"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
|
||||
checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
@ -173,6 +234,28 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
version = "0.10.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
@ -5,5 +5,5 @@ authors = ["Fluence Team"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "0.2.18", features = ["logger"]}
|
||||
fluence = { version = "0.6.2", features = ["logger"]}
|
||||
log = "0.4.8"
|
@ -1,4 +1,7 @@
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
fn main() {}
|
||||
|
||||
|
Reference in New Issue
Block a user