Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub const XDR_FILES_SHA256: [(&str, &str); 13] = [
),
(
"xdr/Stellar-contract-spec.x",
"f0655f82e0a28a79e067c02f427cc709db1e4323a50c9b85f730f812b9612dbd",
"c345c4589727189a83e6b8ba8e93edd2701aacc47e46ffae1fbf00d82deadbee",
),
(
"xdr/Stellar-contract.x",
Expand Down Expand Up @@ -5043,6 +5043,9 @@ pub use sc_spec_type_bytes_n::*;
mod sc_spec_type_udt;
#[allow(unused_imports)]
pub use sc_spec_type_udt::*;
mod sc_spec_type_udtv2;
#[allow(unused_imports)]
pub use sc_spec_type_udtv2::*;
mod sc_spec_type_def;
#[allow(unused_imports)]
pub use sc_spec_type_def::*;
Expand Down
8 changes: 7 additions & 1 deletion src/generated/sc_spec_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ use super::*;
/// SC_SPEC_TYPE_BYTES_N = 1006,
///
/// // User defined types.
/// SC_SPEC_TYPE_UDT = 2000
/// SC_SPEC_TYPE_UDT = 2000,
/// SC_SPEC_TYPE_UDT_V2 = 2001
/// };
/// ```
///
Expand Down Expand Up @@ -80,6 +81,7 @@ pub enum ScSpecType {
Tuple = 1005,
BytesN = 1006,
Udt = 2000,
UdtV2 = 2001,
}

impl ScSpecType {
Expand Down Expand Up @@ -110,6 +112,7 @@ impl ScSpecType {
ScSpecType::Tuple,
ScSpecType::BytesN,
ScSpecType::Udt,
ScSpecType::UdtV2,
];
pub const VARIANTS: [ScSpecType; Self::_VARIANTS.len()] = {
let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
Expand Down Expand Up @@ -147,6 +150,7 @@ impl ScSpecType {
"Tuple",
"BytesN",
"Udt",
"UdtV2",
];
pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
Expand Down Expand Up @@ -187,6 +191,7 @@ impl ScSpecType {
Self::Tuple => "Tuple",
Self::BytesN => "BytesN",
Self::Udt => "Udt",
Self::UdtV2 => "UdtV2",
}
}

Expand Down Expand Up @@ -248,6 +253,7 @@ impl TryFrom<i32> for ScSpecType {
1005 => ScSpecType::Tuple,
1006 => ScSpecType::BytesN,
2000 => ScSpecType::Udt,
2001 => ScSpecType::UdtV2,
#[allow(unreachable_patterns)]
_ => return Err(Error::Invalid),
};
Expand Down
16 changes: 16 additions & 0 deletions src/generated/sc_spec_type_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ use super::*;
/// SCSpecTypeBytesN bytesN;
/// case SC_SPEC_TYPE_UDT:
/// SCSpecTypeUDT udt;
/// case SC_SPEC_TYPE_UDT_V2:
/// SCSpecTypeUDTV2 udtV2;
/// };
/// ```
///
Expand Down Expand Up @@ -82,6 +84,7 @@ pub enum ScSpecTypeDef {
Tuple(Box<ScSpecTypeTuple>),
BytesN(ScSpecTypeBytesN),
Udt(ScSpecTypeUdt),
UdtV2(ScSpecTypeUdtv2),
}

#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -119,6 +122,7 @@ impl ScSpecTypeDef {
ScSpecType::Tuple,
ScSpecType::BytesN,
ScSpecType::Udt,
ScSpecType::UdtV2,
];
pub const VARIANTS: [ScSpecType; Self::_VARIANTS.len()] = {
let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
Expand Down Expand Up @@ -156,6 +160,7 @@ impl ScSpecTypeDef {
"Tuple",
"BytesN",
"Udt",
"UdtV2",
];
pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
Expand Down Expand Up @@ -196,6 +201,7 @@ impl ScSpecTypeDef {
Self::Tuple(_) => "Tuple",
Self::BytesN(_) => "BytesN",
Self::Udt(_) => "Udt",
Self::UdtV2(_) => "UdtV2",
}
}

Expand Down Expand Up @@ -229,6 +235,7 @@ impl ScSpecTypeDef {
Self::Tuple(_) => ScSpecType::Tuple,
Self::BytesN(_) => ScSpecType::BytesN,
Self::Udt(_) => ScSpecType::Udt,
Self::UdtV2(_) => ScSpecType::UdtV2,
}
}

Expand Down Expand Up @@ -293,6 +300,7 @@ impl ReadXdr for ScSpecTypeDef {
ScSpecType::Tuple => Self::Tuple(Box::<ScSpecTypeTuple>::read_xdr(r)?),
ScSpecType::BytesN => Self::BytesN(ScSpecTypeBytesN::read_xdr(r)?),
ScSpecType::Udt => Self::Udt(ScSpecTypeUdt::read_xdr(r)?),
ScSpecType::UdtV2 => Self::UdtV2(ScSpecTypeUdtv2::read_xdr(r)?),
#[allow(unreachable_patterns)]
_ => return Err(Error::Invalid),
};
Expand Down Expand Up @@ -334,6 +342,7 @@ impl WriteXdr for ScSpecTypeDef {
Self::Tuple(v) => v.write_xdr(w)?,
Self::BytesN(v) => v.write_xdr(w)?,
Self::Udt(v) => v.write_xdr(w)?,
Self::UdtV2(v) => v.write_xdr(w)?,
};
Ok(())
})
Expand Down Expand Up @@ -371,6 +380,7 @@ pub enum ScSpecTypeDefRef<'a> {
Tuple(&'a ScSpecTypeTupleRef<'a>),
BytesN(ScSpecTypeBytesN),
Udt(ScSpecTypeUdtRef<'a>),
UdtV2(ScSpecTypeUdtv2),
}

#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -405,6 +415,7 @@ impl From<&ScSpecTypeDefRef<'_>> for ScSpecTypeDef {
ScSpecTypeDefRef::Tuple(value) => Self::Tuple(Box::new((*value).into())),
ScSpecTypeDefRef::BytesN(value) => Self::BytesN(value.clone()),
ScSpecTypeDefRef::Udt(value) => Self::Udt(value.into()),
ScSpecTypeDefRef::UdtV2(value) => Self::UdtV2(value.clone()),
}
}
}
Expand Down Expand Up @@ -448,6 +459,7 @@ impl ScSpecTypeDefRef<'_> {
Self::Tuple(_) => ScSpecType::Tuple,
Self::BytesN(_) => ScSpecType::BytesN,
Self::Udt(_) => ScSpecType::Udt,
Self::UdtV2(_) => ScSpecType::UdtV2,
}
}
}
Expand Down Expand Up @@ -485,6 +497,7 @@ impl WriteXdr for ScSpecTypeDefRef<'_> {
Self::Tuple(v) => v.write_xdr(w)?,
Self::BytesN(v) => v.write_xdr(w)?,
Self::Udt(v) => v.write_xdr(w)?,
Self::UdtV2(v) => v.write_xdr(w)?,
};
Ok(())
})
Expand Down Expand Up @@ -551,6 +564,9 @@ impl ScSpecTypeDefRef<'_> {
Self::Udt(v) => {
v.const_write_xdr(w);
}
Self::UdtV2(v) => {
v.const_write_xdr(w);
}
}
w.leave_depth();
}
Expand Down
101 changes: 101 additions & 0 deletions src/generated/sc_spec_type_udtv2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#[allow(unused_imports, clippy::wildcard_imports)]
use super::*;

/// ScSpecTypeUdtv2 is an XDR Struct defined as:
///
/// ```text
/// struct SCSpecTypeUDTV2
/// {
/// opaque id[8];
/// };
/// ```
///
#[cfg_attr(feature = "alloc", derive(Default))]
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(
all(feature = "serde", feature = "alloc"),
serde_with::serde_as,
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "snake_case")
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct ScSpecTypeUdtv2 {
pub id: [u8; 8],
}

impl ReadXdr for ScSpecTypeUdtv2 {
#[cfg(feature = "std")]
fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
r.with_limited_depth(|r| {
Ok(Self {
id: <[u8; 8]>::read_xdr(r)?,
})
})
}
}

impl WriteXdr for ScSpecTypeUdtv2 {
#[cfg(feature = "std")]
fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
w.with_limited_depth(|w| {
self.id.write_xdr(w)?;
Ok(())
})
}
}
#[cfg(feature = "const")]
impl ScSpecTypeUdtv2 {
/// Serialize this value as XDR into a [`ConstWriter`] using only const
/// operations. This is the const counterpart to the owned type's
/// [`WriteXdr::write_xdr`].
pub const fn const_write_xdr(&self, w: &mut ConstWriter) {
w.enter_depth();
w.write_fixed_opaque(&self.id);
w.leave_depth();
}
/// The exact XDR-encoded length of this value, in bytes.
///
/// Evaluable in a const context, so a caller (such as a proc-macro) can
/// size a buffer for [`Self::const_to_xdr`] at compile time.
#[cfg(feature = "const")]
#[must_use]
pub const fn const_xdr_len(&self) -> usize {
let limits = Limits {
depth: u32::MAX,
len: usize::MAX,
};
let mut empty: [u8; 0] = [];
let mut w = ConstWriter::new(&mut empty, &limits);
self.const_write_xdr(&mut w);
w.position()
}

/// Serialize this value as XDR into a fixed-size `[u8; N]` using only const
/// operations. This is the const counterpart to [`WriteXdr::to_xdr`].
///
/// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such
/// as a proc-macro, that compute the length with `const_xdr_len` and pass
/// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`.
///
/// # Panics
///
/// Panics if `N` does not equal the value's [`Self::const_xdr_len`].
#[cfg(feature = "const")]
#[must_use]
pub const fn const_to_xdr<const N: usize>(&self) -> [u8; N] {
let limits = Limits {
depth: u32::MAX,
len: usize::MAX,
};
let mut buf = [0u8; N];
let mut w = ConstWriter::new(&mut buf, &limits);
self.const_write_xdr(&mut w);
assert!(
w.position() == N,
"const_to_xdr: N does not equal the XDR-encoded length"
);
buf
}
}
Loading
Loading