2020-10-08 12:43:23 +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-10-16 12:47:46 +03:00
|
|
|
mod epilog;
|
|
|
|
mod prolog;
|
|
|
|
mod utils;
|
|
|
|
|
|
|
|
use epilog::make_result_data;
|
|
|
|
use prolog::make_contexts;
|
|
|
|
use prolog::prepare;
|
|
|
|
use utils::dedup;
|
|
|
|
|
2020-10-08 12:43:23 +03:00
|
|
|
use crate::air::ExecutableInstruction;
|
|
|
|
use crate::Result;
|
2020-10-16 12:47:46 +03:00
|
|
|
use crate::StepperOutcome;
|
|
|
|
use crate::STEPPER_SUCCESS;
|
2020-10-08 12:43:23 +03:00
|
|
|
|
2020-10-16 12:47:46 +03:00
|
|
|
pub(self) const CALL_EVIDENCE_CTX_KEY: &str = "__call";
|
2020-10-15 17:31:56 +03:00
|
|
|
|
2020-10-16 12:47:46 +03:00
|
|
|
pub(crate) fn execute_aqua(init_user_id: String, aqua: String, prev_data: String, data: String) -> StepperOutcome {
|
2020-10-23 12:41:58 +03:00
|
|
|
log::info!("aquamarine version is {}", env!("CARGO_PKG_VERSION"));
|
|
|
|
|
2020-10-08 12:43:23 +03:00
|
|
|
log::info!(
|
2020-10-16 12:47:46 +03:00
|
|
|
"stepper invoked with user_id = {}, aqua = {:?}, prev_data = {:?}, data = {:?}",
|
2020-10-08 12:43:23 +03:00
|
|
|
init_user_id,
|
|
|
|
aqua,
|
2020-10-16 12:47:46 +03:00
|
|
|
prev_data,
|
2020-10-08 12:43:23 +03:00
|
|
|
data
|
|
|
|
);
|
|
|
|
|
2020-10-16 12:47:46 +03:00
|
|
|
execute_aqua_impl(init_user_id, aqua, prev_data, data).unwrap_or_else(Into::into)
|
2020-10-08 12:43:23 +03:00
|
|
|
}
|
|
|
|
|
2020-10-16 12:47:46 +03:00
|
|
|
fn execute_aqua_impl(_init_user_id: String, aqua: String, prev_data: String, data: String) -> Result<StepperOutcome> {
|
|
|
|
let (prev_data, data, aqua) = prepare(prev_data, data, aqua)?;
|
|
|
|
let (mut exec_ctx, mut call_ctx) = make_contexts(prev_data, data)?;
|
2020-10-08 12:43:23 +03:00
|
|
|
|
2020-10-16 12:47:46 +03:00
|
|
|
aqua.execute(&mut exec_ctx, &mut call_ctx)?;
|
2020-10-15 17:31:56 +03:00
|
|
|
|
2020-10-16 12:47:46 +03:00
|
|
|
let data = make_result_data(exec_ctx.data, call_ctx)?;
|
2020-10-08 12:43:23 +03:00
|
|
|
|
|
|
|
Ok(StepperOutcome {
|
2020-10-16 12:47:46 +03:00
|
|
|
ret_code: STEPPER_SUCCESS,
|
2020-10-08 12:43:23 +03:00
|
|
|
data,
|
2020-10-16 12:47:46 +03:00
|
|
|
next_peer_pks: dedup(exec_ctx.next_peer_pks),
|
2020-10-08 12:43:23 +03:00
|
|
|
})
|
|
|
|
}
|