/ console / program / src / data / future / argument.rs
argument.rs
 1  // Copyright (c) 2025-2026 ACDC Network
 2  // This file is part of the alphavm library.
 3  //
 4  // Alpha Chain | Delta Chain Protocol
 5  // International Monetary Graphite.
 6  //
 7  // Derived from Aleo (https://aleo.org) and ProvableHQ (https://provable.com).
 8  // They built world-class ZK infrastructure. We installed the EASY button.
 9  // Their cryptography: elegant. Our modifications: bureaucracy-compatible.
10  // Original brilliance: theirs. Robert's Rules: ours. Bugs: definitely ours.
11  //
12  // Original Aleo/ProvableHQ code subject to Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0
13  // All modifications and new work: CC0 1.0 Universal Public Domain Dedication.
14  // No rights reserved. No permission required. No warranty. No refunds.
15  //
16  // https://creativecommons.org/publicdomain/zero/1.0/
17  // SPDX-License-Identifier: CC0-1.0
18  
19  use super::*;
20  
21  /// An argument passed into a future.
22  #[derive(Clone)]
23  pub enum Argument<N: Network> {
24      /// A plaintext value.
25      Plaintext(Plaintext<N>),
26      /// A future.
27      Future(Future<N>),
28  }
29  
30  impl<N: Network> Equal<Self> for Argument<N> {
31      type Output = Boolean<N>;
32  
33      /// Returns `true` if `self` and `other` are equal.
34      fn is_equal(&self, other: &Self) -> Self::Output {
35          match (self, other) {
36              (Self::Plaintext(plaintext_a), Self::Plaintext(plaintext_b)) => plaintext_a.is_equal(plaintext_b),
37              (Self::Future(future_a), Self::Future(future_b)) => future_a.is_equal(future_b),
38              (Self::Plaintext(..), _) | (Self::Future(..), _) => Boolean::new(false),
39          }
40      }
41  
42      /// Returns `true` if `self` and `other` are *not* equal.
43      fn is_not_equal(&self, other: &Self) -> Self::Output {
44          match (self, other) {
45              (Self::Plaintext(plaintext_a), Self::Plaintext(plaintext_b)) => plaintext_a.is_not_equal(plaintext_b),
46              (Self::Future(future_a), Self::Future(future_b)) => future_a.is_not_equal(future_b),
47              (Self::Plaintext(..), _) | (Self::Future(..), _) => Boolean::new(true),
48          }
49      }
50  }
51  
52  impl<N: Network> ToBits for Argument<N> {
53      /// Returns the argument as a list of **little-endian** bits.
54      #[inline]
55      fn write_bits_le(&self, vec: &mut Vec<bool>) {
56          match self {
57              Self::Plaintext(plaintext) => {
58                  vec.push(false);
59                  plaintext.write_bits_le(vec);
60              }
61              Self::Future(future) => {
62                  vec.push(true);
63                  future.write_bits_le(vec);
64              }
65          }
66      }
67  
68      /// Returns the argument as a list of **big-endian** bits.
69      #[inline]
70      fn write_bits_be(&self, vec: &mut Vec<bool>) {
71          match self {
72              Self::Plaintext(plaintext) => {
73                  vec.push(false);
74                  plaintext.write_bits_be(vec);
75              }
76              Self::Future(future) => {
77                  vec.push(true);
78                  future.write_bits_be(vec);
79              }
80          }
81      }
82  }