From 61c9d5eaf42e79e15536d762c4041a75fd6fe524 Mon Sep 17 00:00:00 2001 From: boneyard93501 <4523011+boneyard93501@users.noreply.github.com> Date: Wed, 3 Mar 2021 14:32:23 -0600 Subject: [PATCH] update curl adapter --- multi-service/curl_adapter/Cargo.toml | 2 +- multi-service/curl_adapter/src/main.rs | 41 +++++++------------------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/multi-service/curl_adapter/Cargo.toml b/multi-service/curl_adapter/Cargo.toml index 5888634..aef526a 100644 --- a/multi-service/curl_adapter/Cargo.toml +++ b/multi-service/curl_adapter/Cargo.toml @@ -10,6 +10,6 @@ path = "src/main.rs" name = "curl_adapter" [dependencies] -fluence = { version = "=0.2.18", features = ["logger"]} +fluence = { version = "=0.3.3", features = ["logger"] } log = "0.4.8" serde_json = "1.0.64" diff --git a/multi-service/curl_adapter/src/main.rs b/multi-service/curl_adapter/src/main.rs index 65406ba..120878b 100644 --- a/multi-service/curl_adapter/src/main.rs +++ b/multi-service/curl_adapter/src/main.rs @@ -13,43 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#![allow(improper_ctypes)] use fluence::fce; -use fluence::WasmLoggerBuilder; +// use fluence::MountedBinaryStringResult as StringResult; +use fluence::MountedBinaryResult as Result; -/// Log level can be changed by `RUST_LOG` env as well. -pub fn main() { - WasmLoggerBuilder::new().build().unwrap(); -} +fn main() {} #[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) -> Result { + let response = unsafe { curl(curl_cmd.clone()) }; + log::info!("curl response for {:?} : {:?}", curl_cmd, response); + 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; -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn curl_test() { - let args = r#"-X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x1b4", true],"id":1}'"#; - let url = "https://kovan.infura.io/v3//0cc023286cae4ab886598ecd14e256fd"; - - let cmd = format!("{} {}", args, url); - println!("cmd: {}", cmd); - - let res = curl_request(cmd); - println!("res: {}", res); - assert!(true); - } -} + pub fn curl(cmd: Vec) -> Result; +} \ No newline at end of file