#[allow(unused_imports, clippy::wildcard_imports)]
use super::*;
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[allow(clippy::large_enum_variant)]
pub enum HashIdPreimage {
OpId(HashIdPreimageOperationId),
PoolRevokeOpId(HashIdPreimageRevokeId),
ContractId(HashIdPreimageContractId),
SorobanAuthorization(HashIdPreimageSorobanAuthorization),
SorobanAuthorizationWithAddress(HashIdPreimageSorobanAuthorizationWithAddress),
}
impl HashIdPreimage {
#[must_use]
pub const fn discriminant(&self) -> EnvelopeType {
#[allow(clippy::match_same_arms)]
match self {
Self::OpId(_) => EnvelopeType::OpId,
Self::PoolRevokeOpId(_) => EnvelopeType::PoolRevokeOpId,
Self::ContractId(_) => EnvelopeType::ContractId,
Self::SorobanAuthorization(_) => EnvelopeType::SorobanAuthorization,
Self::SorobanAuthorizationWithAddress(_) => {
EnvelopeType::SorobanAuthorizationWithAddress
}
}
}
}
impl HashIdPreimage {
#[must_use]
pub const fn const_xdr_len(&self) -> usize {
let mut empty: [u8; 0] = [];
let mut w = ConstWriter::new(&mut empty);
w.write_type_hash_id_preimage(self);
w.len()
}
#[must_use]
pub const fn const_to_xdr<const N: usize>(&self) -> [u8; N] {
let mut buf = [0u8; N];
let mut w = ConstWriter::new(&mut buf);
w.write_type_hash_id_preimage(self);
assert!(
w.len() == N,
"const_to_xdr: N does not equal the XDR-encoded length"
);
buf
}
}
impl ConstWriter<'_> {
pub const fn write_type_hash_id_preimage(&mut self, v: &HashIdPreimage) {
let d = v.discriminant();
self.write_type_envelope_type(&d);
#[allow(clippy::match_same_arms)]
match v {
HashIdPreimage::OpId(value) => {
self.write_type_hash_id_preimage_operation_id(value);
}
HashIdPreimage::PoolRevokeOpId(value) => {
self.write_type_hash_id_preimage_revoke_id(value);
}
HashIdPreimage::ContractId(value) => {
self.write_type_hash_id_preimage_contract_id(value);
}
HashIdPreimage::SorobanAuthorization(value) => {
self.write_type_hash_id_preimage_soroban_authorization(value);
}
HashIdPreimage::SorobanAuthorizationWithAddress(value) => {
self.write_type_hash_id_preimage_soroban_authorization_with_address(value);
}
}
}
}