mirror of
https://github.com/fluencelabs/examples
synced 2025-06-12 09:31:20 +00:00
update to marine 0.6.2, remove unsafe
This commit is contained in:
@ -10,6 +10,6 @@ cd ether_price_getter
|
||||
fce build --release
|
||||
cd ..
|
||||
|
||||
rm -f artifacts/*
|
||||
rm -f artifacts/*.wasm
|
||||
cp curl_adapter/target/wasm32-wasi/release/curl_adapter.wasm artifacts/
|
||||
cp ether_price_getter/target/wasm32-wasi/release/ether_price_getter.wasm artifacts/
|
||||
|
@ -10,5 +10,5 @@ path = "src/main.rs"
|
||||
name = "curl_adapter"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.2.18", features = ["logger"]}
|
||||
fluence = { version = "=0.6.2", features = ["logger"]}
|
||||
log = "0.4.8"
|
||||
|
@ -13,25 +13,28 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
use fluence::MountedBinaryResult;
|
||||
use fluence::WasmLoggerBuilder;
|
||||
|
||||
/// Log level can be changed by `RUST_LOG` env as well.
|
||||
pub fn main() {
|
||||
module_manifest!();
|
||||
|
||||
fn main() {
|
||||
WasmLoggerBuilder::new().build().unwrap();
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn curl_request(url: String) -> String {
|
||||
// log::info!("get called with url {}", url);
|
||||
|
||||
unsafe { curl(url) }
|
||||
pub fn curl_request(curl_cmd: Vec<String>) -> MountedBinaryResult {
|
||||
let response = curl(curl_cmd);
|
||||
response
|
||||
}
|
||||
|
||||
/// Permissions in `Config.toml` should exist to use host functions.
|
||||
// mounted_binaries are available to import like this:
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "host")]
|
||||
extern "C" {
|
||||
fn curl(cmd: String) -> String;
|
||||
pub fn curl(cmd: Vec<String>) -> MountedBinaryResult;
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ name = "ether_price_getter"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "0.2.18", features = ["logger"]}
|
||||
fluence = { version = "=0.6.2", features = ["logger"]}
|
||||
log = "0.4.8"
|
||||
fstrings = { version="0.2.3" }
|
||||
|
@ -14,16 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use fluence::fce;
|
||||
use crate::curl_request;
|
||||
use fluence::fce;
|
||||
|
||||
static URL_LATEST: &'static str = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest";
|
||||
|
||||
static URL_LATEST: &'static str =
|
||||
"https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest";
|
||||
|
||||
#[fce]
|
||||
pub fn ether_price_getter(api_key: String, currency_symbol: String) -> String {
|
||||
let curl_args = f!(r#"-H "X-CMC_PRO_API_KEY: {api_key}" -H "Accept: application/json" -d "symbol=ETH&convert={currency_symbol}" -G {URL_LATEST}"#);
|
||||
let response: String = unsafe { curl_request(curl_args) };
|
||||
response
|
||||
let curl_args = f!(
|
||||
r#"-H "X-CMC_PRO_API_KEY: {api_key}" -H "Accept: application/json" -d "symbol=ETH&convert={currency_symbol}" -G {URL_LATEST}"#
|
||||
);
|
||||
let response = curl_request(vec![curl_args]);
|
||||
String::from_utf8(response.stdout).unwrap()
|
||||
}
|
||||
|
@ -13,16 +13,27 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#![allow(non_snake_case, unused_variables, unused_imports, unused_parens, unused_mut)]
|
||||
#![allow(
|
||||
non_snake_case,
|
||||
unused_variables,
|
||||
unused_imports,
|
||||
unused_parens,
|
||||
unused_mut
|
||||
)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate fstrings;
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::module_manifest;
|
||||
use fluence::MountedBinaryResult;
|
||||
use fluence::WasmLoggerBuilder;
|
||||
|
||||
mod eth_price_getter;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) type Result<T> = std::result::Result<T, T>;
|
||||
|
||||
pub fn main() {
|
||||
@ -32,5 +43,5 @@ pub fn main() {
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "curl_adapter")]
|
||||
extern "C" {
|
||||
pub fn curl_request(url: String) -> String;
|
||||
pub fn curl_request(url: Vec<String>) -> MountedBinaryResult;
|
||||
}
|
||||
|
Reference in New Issue
Block a user