aquavm/stepper/src/fce.rs

66 lines
1.6 KiB
Rust
Raw Normal View History

2020-09-21 14:11:09 +03:00
/*
* Copyright 2020 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2020-09-30 12:39:00 +03:00
2020-10-16 12:47:46 +03:00
#![allow(improper_ctypes)]
#![warn(rust_2018_idioms)]
#![deny(
dead_code,
nonstandard_style,
unused_imports,
unused_mut,
unused_variables,
unused_unsafe,
unreachable_patterns
)]
mod ast;
mod logger;
2020-09-21 14:11:09 +03:00
use fluence::fce;
use logger::DEFAULT_LOG_LEVEL;
2020-12-17 21:44:24 +03:00
use stepper_interface::StepperOutcome;
2020-10-30 20:29:05 +03:00
use stepper_lib::execute_aqua;
2020-10-08 14:27:59 +03:00
use log::Level as LogLevel;
2020-12-23 20:06:19 +03:00
const WASM_LOG_ENV_NAME: &str = "WASM_LOG";
2020-09-21 14:11:09 +03:00
pub fn main() {
logger::init_logger();
2020-10-08 14:27:59 +03:00
}
2020-09-28 15:40:27 +03:00
#[fce]
2020-12-17 21:44:24 +03:00
pub fn invoke(init_peer_id: String, aqua: String, prev_data: Vec<u8>, data: Vec<u8>) -> StepperOutcome {
let log_level = get_log_level();
log::set_max_level(log_level.to_level_filter());
2020-11-11 14:31:53 +03:00
execute_aqua(init_peer_id, aqua, prev_data, data)
2020-09-28 15:40:27 +03:00
}
#[fce]
pub fn ast(script: String) -> String {
ast::ast(script)
}
fn get_log_level() -> LogLevel {
use std::str::FromStr;
2020-12-23 20:06:19 +03:00
match std::env::var(WASM_LOG_ENV_NAME) {
Ok(log_level_str) => LogLevel::from_str(&log_level_str).unwrap_or(DEFAULT_LOG_LEVEL),
Err(_) => DEFAULT_LOG_LEVEL,
}
}