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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#[cfg(test)]
use snarkvm_circuit_types::environment::assert_scope;
mod from_outputs;
mod process_outputs_from_callback;
use crate::{Identifier, ProgramID, Value};
use snarkvm_circuit_network::Aleo;
use snarkvm_circuit_types::{environment::prelude::*, Field, U16};
pub enum OutputID<A: Aleo> {
Constant(Field<A>),
Public(Field<A>),
Private(Field<A>),
Record(Field<A>, Field<A>),
ExternalRecord(Field<A>),
}
#[cfg(console)]
impl<A: Aleo> Inject for OutputID<A> {
type Primitive = console::OutputID<A::Network>;
fn new(_: Mode, output: Self::Primitive) -> Self {
match output {
console::OutputID::Constant(field) => Self::Constant(Field::new(Mode::Public, field)),
console::OutputID::Public(field) => Self::Public(Field::new(Mode::Public, field)),
console::OutputID::Private(field) => Self::Private(Field::new(Mode::Public, field)),
console::OutputID::Record(commitment, checksum) => {
Self::Record(Field::new(Mode::Public, commitment), Field::new(Mode::Public, checksum))
}
console::OutputID::ExternalRecord(hash) => Self::ExternalRecord(Field::new(Mode::Public, hash)),
}
}
}
impl<A: Aleo> OutputID<A> {
fn constant(expected_hash: Field<A>) -> Self {
let output_hash = Field::new(Mode::Public, expected_hash.eject_value());
A::assert_eq(&output_hash, expected_hash);
Self::Constant(output_hash)
}
fn public(expected_hash: Field<A>) -> Self {
let output_hash = Field::new(Mode::Public, expected_hash.eject_value());
A::assert_eq(&output_hash, expected_hash);
Self::Public(output_hash)
}
fn private(expected_hash: Field<A>) -> Self {
let output_hash = Field::new(Mode::Public, expected_hash.eject_value());
A::assert_eq(&output_hash, expected_hash);
Self::Private(output_hash)
}
fn record(expected_commitment: Field<A>, expected_checksum: Field<A>) -> Self {
let output_commitment = Field::new(Mode::Public, expected_commitment.eject_value());
let output_checksum = Field::new(Mode::Public, expected_checksum.eject_value());
A::assert_eq(&output_commitment, expected_commitment);
A::assert_eq(&output_checksum, expected_checksum);
Self::Record(output_commitment, output_checksum)
}
fn external_record(expected_hash: Field<A>) -> Self {
let output_hash = Field::new(Mode::Public, expected_hash.eject_value());
A::assert_eq(&output_hash, expected_hash);
Self::ExternalRecord(output_hash)
}
}
#[cfg(console)]
impl<A: Aleo> Eject for OutputID<A> {
type Primitive = console::OutputID<A::Network>;
fn eject_mode(&self) -> Mode {
match self {
Self::Constant(field) => field.eject_mode(),
Self::Public(field) => field.eject_mode(),
Self::Private(field) => field.eject_mode(),
Self::Record(commitment, checksum) => Mode::combine(commitment.eject_mode(), [checksum.eject_mode()]),
Self::ExternalRecord(hash) => hash.eject_mode(),
}
}
fn eject_value(&self) -> Self::Primitive {
match self {
Self::Constant(field) => console::OutputID::Constant(field.eject_value()),
Self::Public(field) => console::OutputID::Public(field.eject_value()),
Self::Private(field) => console::OutputID::Private(field.eject_value()),
Self::Record(commitment, checksum) => {
console::OutputID::Record(commitment.eject_value(), checksum.eject_value())
}
Self::ExternalRecord(hash) => console::OutputID::ExternalRecord(hash.eject_value()),
}
}
}
pub struct Response<A: Aleo> {
output_ids: Vec<OutputID<A>>,
outputs: Vec<Value<A>>,
}
impl<A: Aleo> Response<A> {
pub fn output_ids(&self) -> &[OutputID<A>] {
&self.output_ids
}
pub fn outputs(&self) -> &[Value<A>] {
&self.outputs
}
}
#[cfg(console)]
impl<A: Aleo> Eject for Response<A> {
type Primitive = console::Response<A::Network>;
fn eject_mode(&self) -> Mode {
Mode::combine(self.output_ids.eject_mode(), [self.outputs.eject_mode()])
}
fn eject_value(&self) -> Self::Primitive {
Self::Primitive::from((
self.output_ids.iter().map(|output_id| output_id.eject_value()).collect(),
self.outputs.eject_value(),
))
}
}