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-21 15:33:31 +03:00
|
|
|
mod air;
|
2020-09-24 12:55:29 +03:00
|
|
|
mod instructions;
|
2020-09-28 15:40:27 +03:00
|
|
|
mod stepper;
|
2020-09-24 12:55:29 +03:00
|
|
|
mod stepper_outcome;
|
|
|
|
|
|
|
|
use instructions::Instruction;
|
|
|
|
use stepper_outcome::StepperOutcome;
|
2020-09-21 14:11:09 +03:00
|
|
|
|
|
|
|
use fluence::fce;
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
fluence::WasmLogger::init_with_level(log::Level::Info).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[fce]
|
2020-09-28 15:40:27 +03:00
|
|
|
pub fn invoke(init_user_id: String, aqua: String, data: Vec<u8>) -> StepperOutcome {
|
2020-09-24 12:55:29 +03:00
|
|
|
log::info!(
|
2020-09-22 16:27:33 +03:00
|
|
|
"stepper invoked with user_id = {}, aqua = {:?}, data = {:?}",
|
2020-09-28 15:40:27 +03:00
|
|
|
init_user_id,
|
|
|
|
aqua,
|
|
|
|
data
|
2020-09-22 16:27:33 +03:00
|
|
|
);
|
2020-09-21 14:11:09 +03:00
|
|
|
|
|
|
|
let outcome = StepperOutcome {
|
2020-09-22 16:27:33 +03:00
|
|
|
data,
|
|
|
|
next_peer_pks: vec![init_user_id],
|
2020-09-21 14:11:09 +03:00
|
|
|
};
|
|
|
|
|
2020-09-28 15:40:27 +03:00
|
|
|
let parsed_aqua = match serde_sexpr::from_str::<Vec<Instruction>>(&aqua) {
|
2020-09-24 12:55:29 +03:00
|
|
|
Ok(parsed) => parsed,
|
|
|
|
Err(e) => {
|
|
|
|
log::error!("supplied aqua script can't be parsed: {:?}", e);
|
|
|
|
|
|
|
|
return outcome;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
log::info!("parsed_aqua: {:?}", parsed_aqua);
|
|
|
|
|
2020-09-28 15:40:27 +03:00
|
|
|
crate::stepper::execute(parsed_aqua);
|
|
|
|
|
2020-09-21 14:11:09 +03:00
|
|
|
outcome
|
|
|
|
}
|
2020-09-28 15:40:27 +03:00
|
|
|
|
|
|
|
#[fce]
|
|
|
|
pub struct CallServiceResult {
|
|
|
|
pub result: i32,
|
|
|
|
pub outcome: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[fce]
|
|
|
|
#[link(wasm_import_module = "aqua_test_module")]
|
|
|
|
extern "C" {
|
|
|
|
pub fn call_service(service_id: String, fn_name: String, args: Vec<u8>) -> CallServiceResult;
|
|
|
|
}
|