mirror of
https://github.com/fluencelabs/examples
synced 2024-12-04 19:20:17 +00:00
update curl adapter
This commit is contained in:
parent
b3b47fc930
commit
61c9d5eaf4
@ -10,6 +10,6 @@ path = "src/main.rs"
|
|||||||
name = "curl_adapter"
|
name = "curl_adapter"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fluence = { version = "=0.2.18", features = ["logger"]}
|
fluence = { version = "=0.3.3", features = ["logger"] }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
serde_json = "1.0.64"
|
serde_json = "1.0.64"
|
||||||
|
@ -13,43 +13,24 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#![allow(improper_ctypes)]
|
||||||
|
|
||||||
use fluence::fce;
|
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.
|
fn main() {}
|
||||||
pub fn main() {
|
|
||||||
WasmLoggerBuilder::new().build().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[fce]
|
#[fce]
|
||||||
pub fn curl_request(url: String) -> String {
|
pub fn curl_request(curl_cmd: Vec<String>) -> Result {
|
||||||
// log::info!("get called with url {}", url);
|
let response = unsafe { curl(curl_cmd.clone()) };
|
||||||
|
log::info!("curl response for {:?} : {:?}", curl_cmd, response);
|
||||||
unsafe { curl(url) }
|
response
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Permissions in `Config.toml` should exist to use host functions.
|
// mounted_binaries are available to import like this:
|
||||||
#[fce]
|
#[fce]
|
||||||
#[link(wasm_import_module = "host")]
|
#[link(wasm_import_module = "host")]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn curl(cmd: String) -> String;
|
pub fn curl(cmd: Vec<String>) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user