use snarkvm_circuit_network::Aleo;
use snarkvm_circuit_types::{Boolean, Field, U8, U16, environment::prelude::*};
#[derive(Clone)]
pub struct TransactionLeaf<A: Aleo> {
variant: U8<A>,
index: U16<A>,
id: Field<A>,
}
impl<A: Aleo> TransactionLeaf<A> {
pub const fn variant(&self) -> &U8<A> {
&self.variant
}
pub const fn index(&self) -> &U16<A> {
&self.index
}
pub const fn id(&self) -> &Field<A> {
&self.id
}
}
impl<A: Aleo> Inject for TransactionLeaf<A> {
type Primitive = console::TransactionLeaf<A::Network>;
fn new(mode: Mode, transaction_leaf: Self::Primitive) -> Self {
Self {
variant: U8::new(mode, console::U8::new(transaction_leaf.variant())),
index: U16::new(mode, console::U16::new(transaction_leaf.index())),
id: Field::new(mode, transaction_leaf.id()),
}
}
}
impl<A: Aleo> Eject for TransactionLeaf<A> {
type Primitive = console::TransactionLeaf<A::Network>;
fn eject_mode(&self) -> Mode {
(&self.variant, &self.index, &self.id).eject_mode()
}
fn eject_value(&self) -> Self::Primitive {
Self::Primitive::from(*self.variant.eject_value(), *self.index.eject_value(), self.id.eject_value())
}
}
impl<A: Aleo> ToBits for TransactionLeaf<A> {
type Boolean = Boolean<A>;
fn write_bits_le(&self, vec: &mut Vec<Self::Boolean>) {
self.variant.write_bits_le(vec);
self.index.write_bits_le(vec);
self.id.write_bits_le(vec);
}
fn write_bits_be(&self, vec: &mut Vec<Self::Boolean>) {
self.variant.write_bits_be(vec);
self.index.write_bits_be(vec);
self.id.write_bits_be(vec);
}
}