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)]
|
2020-10-08 12:43:23 +03:00
|
|
|
#![warn(rust_2018_idioms)]
|
|
|
|
#![deny(
|
|
|
|
dead_code,
|
|
|
|
nonstandard_style,
|
|
|
|
unused_imports,
|
|
|
|
unused_mut,
|
|
|
|
unused_variables,
|
|
|
|
unused_unsafe,
|
|
|
|
unreachable_patterns
|
|
|
|
)]
|
|
|
|
|
2020-12-02 18:47:14 +03:00
|
|
|
mod ast;
|
2020-11-25 17:10:30 +03:00
|
|
|
mod logger;
|
|
|
|
|
2020-09-21 14:11:09 +03:00
|
|
|
use fluence::fce;
|
2020-12-07 20:28:26 +03:00
|
|
|
use logger::DEFAULT_LOG_LEVEL;
|
2020-10-30 20:29:05 +03:00
|
|
|
use stepper_lib::execute_aqua;
|
2020-12-29 14:11:18 +03:00
|
|
|
use stepper_lib::StepperOutcome;
|
2020-10-08 14:27:59 +03:00
|
|
|
|
2020-12-07 20:28:26 +03:00
|
|
|
use log::Level as LogLevel;
|
|
|
|
|
2020-12-23 20:06:19 +03:00
|
|
|
const WASM_LOG_ENV_NAME: &str = "WASM_LOG";
|
2020-12-07 20:28:26 +03:00
|
|
|
|
2020-09-21 14:11:09 +03:00
|
|
|
pub fn main() {
|
2020-11-25 17:10:30 +03:00
|
|
|
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 {
|
2020-12-07 20:28:26 +03:00
|
|
|
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
|
|
|
}
|
2020-12-02 18:47:14 +03:00
|
|
|
|
|
|
|
#[fce]
|
|
|
|
pub fn ast(script: String) -> String {
|
|
|
|
ast::ast(script)
|
|
|
|
}
|
2020-12-07 20:28:26 +03:00
|
|
|
|
|
|
|
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) {
|
2020-12-07 20:28:26 +03:00
|
|
|
Ok(log_level_str) => LogLevel::from_str(&log_level_str).unwrap_or(DEFAULT_LOG_LEVEL),
|
|
|
|
Err(_) => DEFAULT_LOG_LEVEL,
|
|
|
|
}
|
|
|
|
}
|