2022-06-10 08:28:40 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2022 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use crate::test_runner::AirRunner;
|
2023-12-15 18:23:09 +04:00
|
|
|
use air_interpreter_interface::CallResultsRepr;
|
2022-06-10 08:28:40 +03:00
|
|
|
use air_interpreter_interface::RunParameters;
|
2023-12-15 18:23:09 +04:00
|
|
|
use air_interpreter_sede::ToSerialized;
|
2022-06-10 08:28:40 +03:00
|
|
|
use avm_server::avm_runner::*;
|
|
|
|
use avm_server::into_raw_result;
|
2023-06-23 03:12:37 +07:00
|
|
|
use fluence_keypair::KeyPair;
|
2022-06-10 08:28:40 +03:00
|
|
|
|
|
|
|
pub struct NativeAirRunner {
|
|
|
|
current_peer_id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AirRunner for NativeAirRunner {
|
|
|
|
fn new(current_peer_id: impl Into<String>) -> Self {
|
|
|
|
Self {
|
|
|
|
current_peer_id: current_peer_id.into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn call(
|
|
|
|
&mut self,
|
|
|
|
air: impl Into<String>,
|
|
|
|
prev_data: impl Into<Vec<u8>>,
|
|
|
|
data: impl Into<Vec<u8>>,
|
|
|
|
init_peer_id: impl Into<String>,
|
|
|
|
timestamp: u64,
|
|
|
|
ttl: u32,
|
2022-11-25 10:59:09 +03:00
|
|
|
override_current_peer_id: Option<String>,
|
2022-06-10 08:28:40 +03:00
|
|
|
call_results: avm_server::CallResults,
|
2023-06-23 03:12:37 +07:00
|
|
|
keypair: &KeyPair,
|
|
|
|
particle_id: String,
|
2022-06-10 08:28:40 +03:00
|
|
|
) -> Result<RawAVMOutcome, Box<dyn std::error::Error>> {
|
|
|
|
// some inner parts transformations
|
|
|
|
let raw_call_results = into_raw_result(call_results);
|
2023-12-15 18:23:09 +04:00
|
|
|
let raw_call_results = CallResultsRepr.serialize(&raw_call_results).unwrap();
|
2022-06-10 08:28:40 +03:00
|
|
|
|
2022-11-25 10:59:09 +03:00
|
|
|
let current_peer_id =
|
|
|
|
override_current_peer_id.unwrap_or_else(|| self.current_peer_id.clone());
|
|
|
|
|
2023-06-23 03:12:37 +07:00
|
|
|
let key_format = keypair.key_format().into();
|
|
|
|
let secret_key_bytes = keypair.secret().unwrap();
|
|
|
|
|
2022-06-10 08:28:40 +03:00
|
|
|
let outcome = air::execute_air(
|
|
|
|
air.into(),
|
|
|
|
prev_data.into(),
|
|
|
|
data.into(),
|
|
|
|
RunParameters {
|
|
|
|
init_peer_id: init_peer_id.into(),
|
2022-11-25 10:59:09 +03:00
|
|
|
current_peer_id,
|
2022-06-10 08:28:40 +03:00
|
|
|
timestamp,
|
|
|
|
ttl,
|
2023-06-23 03:12:37 +07:00
|
|
|
key_format,
|
|
|
|
secret_key_bytes,
|
|
|
|
particle_id,
|
2022-06-10 08:28:40 +03:00
|
|
|
},
|
|
|
|
raw_call_results,
|
|
|
|
);
|
|
|
|
let outcome = RawAVMOutcome::from_interpreter_outcome(outcome)?;
|
|
|
|
|
|
|
|
Ok(outcome)
|
|
|
|
}
|
2023-10-13 23:19:02 +04:00
|
|
|
|
|
|
|
fn get_current_peer_id(&self) -> &str {
|
|
|
|
&self.current_peer_id
|
|
|
|
}
|
2022-06-10 08:28:40 +03:00
|
|
|
}
|