aquavm/stepper-lib/src/execution.rs

57 lines
1.8 KiB
Rust
Raw Normal View History

/*
* 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 prolog;
mod utils;
use prolog::make_contexts;
use prolog::prepare;
use utils::dedup;
use crate::air::ExecutableInstruction;
2020-10-30 20:29:05 +03:00
use crate::AquamarineError::CallEvidenceSerializationError as CallSeError;
use crate::Result;
2020-10-16 12:47:46 +03:00
use crate::StepperOutcome;
use crate::STEPPER_SUCCESS;
pub use prolog::parse;
2020-11-11 14:31:53 +03:00
pub fn execute_aqua(init_peer_id: String, aqua: String, prev_data: String, data: String) -> StepperOutcome {
log::trace!(
2020-10-30 20:29:05 +03:00
"aquamarine version is {}, init user id is {}",
env!("CARGO_PKG_VERSION"),
2020-11-11 14:31:53 +03:00
init_peer_id
);
2020-11-11 14:31:53 +03:00
execute_aqua_impl(init_peer_id, aqua, prev_data, data).unwrap_or_else(Into::into)
}
2020-11-11 14:31:53 +03:00
fn execute_aqua_impl(init_peer_id: String, aqua: String, prev_path: String, path: String) -> Result<StepperOutcome> {
2020-11-03 17:43:58 +03:00
let (prev_path, path, aqua) = prepare(prev_path, path, aqua.as_str())?;
2020-11-11 14:31:53 +03:00
let (mut exec_ctx, mut call_ctx) = make_contexts(prev_path, path, init_peer_id)?;
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-30 20:29:05 +03:00
let next_peer_pks = dedup(exec_ctx.next_peer_pks);
let data = serde_json::to_string(&call_ctx.new_path).map_err(CallSeError)?;
Ok(StepperOutcome {
2020-10-16 12:47:46 +03:00
ret_code: STEPPER_SUCCESS,
data,
2020-10-30 20:29:05 +03:00
next_peer_pks,
})
}