avm_interface/
raw_outcome.rs

1/*
2 * Copyright 2021 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use crate::CallSeDeErrors;
18
19use super::CallRequests;
20
21use air_interpreter_interface::InterpreterOutcome;
22
23use air_interpreter_interface::SoftLimitsTriggering;
24use serde::Deserialize;
25use serde::Serialize;
26
27/// This struct is very similar to AVMOutcome, but keeps error_code and error_msg for test purposes.
28#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
29pub struct RawAVMOutcome {
30    pub ret_code: i64,
31    pub error_message: String,
32    pub data: Vec<u8>,
33    pub call_requests: CallRequests,
34    pub next_peer_pks: Vec<String>,
35    pub soft_limits_triggering: SoftLimitsTriggering,
36}
37
38impl RawAVMOutcome {
39    pub fn from_interpreter_outcome(outcome: InterpreterOutcome) -> Result<Self, CallSeDeErrors> {
40        let InterpreterOutcome {
41            ret_code,
42            error_message,
43            data,
44            call_requests,
45            next_peer_pks,
46            air_size_limit_exceeded,
47            particle_size_limit_exceeded,
48            call_result_size_limit_exceeded,
49        } = outcome;
50
51        let call_requests = crate::from_raw_call_requests(call_requests.into())?;
52        let soft_limits_triggering = SoftLimitsTriggering::new(
53            air_size_limit_exceeded,
54            particle_size_limit_exceeded,
55            call_result_size_limit_exceeded,
56        );
57
58        let raw_avm_outcome = Self {
59            ret_code,
60            error_message,
61            data,
62            call_requests,
63            next_peer_pks,
64            soft_limits_triggering,
65        };
66
67        Ok(raw_avm_outcome)
68    }
69}