1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * AquaVM Workflow Engine
 *
 * Copyright (C) 2024 Fluence DAO
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

use crate::execution_step::RcSecurityTetraplet;
use crate::JValue;

use air_interpreter_data::TracePos;
use polyplets::SecurityTetraplet;
use serde::Deserialize;
use serde::Serialize;

use std::rc::Rc;

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
// no lambda here are literal + lambda is literal
pub struct LiteralAggregate {
    pub result: JValue,
    // this Rc is not really shared ATM, as execution passes through the Resolvable needle
    pub init_peer_id: Rc<str>,
    // TODO #[serde(skip)]
    pub trace_pos: TracePos,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct ServiceResultAggregate {
    pub result: JValue,
    pub tetraplet: RcSecurityTetraplet,
    // TODO #[serde(skip)]
    pub trace_pos: TracePos,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct CanonResultAggregate {
    pub result: JValue,
    pub peer_id: Rc<str>,
    pub lambda: Rc<str>,
    // TODO #[serde(skip)]
    pub trace_pos: TracePos,
}

impl LiteralAggregate {
    pub(crate) fn new(result: JValue, init_peer_id: Rc<str>, trace_pos: TracePos) -> Self {
        Self {
            result,
            init_peer_id,
            trace_pos,
        }
    }

    pub(crate) fn get_tetraplet(&self) -> RcSecurityTetraplet {
        SecurityTetraplet::literal_tetraplet(self.init_peer_id.as_ref()).into()
    }
}

impl ServiceResultAggregate {
    pub(crate) fn new(result: JValue, tetraplet: RcSecurityTetraplet, trace_pos: TracePos) -> Self {
        Self {
            result,
            tetraplet,
            trace_pos,
        }
    }
}

impl CanonResultAggregate {
    pub(crate) fn new(result: JValue, peer_id: Rc<str>, lambda: &str, trace_pos: TracePos) -> Self {
        Self {
            result,
            peer_id,
            lambda: lambda.into(),
            trace_pos,
        }
    }

    pub(crate) fn get_tetraplet(&self) -> RcSecurityTetraplet {
        SecurityTetraplet::new(self.peer_id.as_ref(), "", "", self.lambda.as_ref()).into()
    }
}