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
14 changes: 13 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",
"ee0ffdb86c74fc9596e0e171d6490b2c80d523adeaf4c45fe43143bd5bc11a73",
),
(
"xdr/Stellar-contract.x",
Expand Down Expand Up @@ -5003,6 +5003,9 @@ pub use sc_meta_entry::*;
mod sc_spec_doc_limit;
#[allow(unused_imports)]
pub use sc_spec_doc_limit::*;
mod sc_spec_id_len;
#[allow(unused_imports)]
pub use sc_spec_id_len::*;
mod sc_spec_type;
#[allow(unused_imports)]
pub use sc_spec_type::*;
Expand All @@ -5027,6 +5030,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 Expand Up @@ -5084,6 +5090,12 @@ pub use sc_spec_event_v0::*;
mod sc_spec_entry_kind;
#[allow(unused_imports)]
pub use sc_spec_entry_kind::*;
mod sc_spec_entry_v2_body;
#[allow(unused_imports)]
pub use sc_spec_entry_v2_body::*;
mod sc_spec_entry_v2;
#[allow(unused_imports)]
pub use sc_spec_entry_v2::*;
mod sc_spec_entry;
#[allow(unused_imports)]
pub use sc_spec_entry::*;
Expand Down
16 changes: 16 additions & 0 deletions src/generated/sc_spec_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use super::*;
/// SCSpecUDTErrorEnumV0 udtErrorEnumV0;
/// case SC_SPEC_ENTRY_EVENT_V0:
/// SCSpecEventV0 eventV0;
/// case SC_SPEC_ENTRY_V2:
/// SCSpecEntryV2 v2;
/// };
/// ```
///
Expand All @@ -40,6 +42,7 @@ pub enum ScSpecEntry {
UdtEnumV0(ScSpecUdtEnumV0),
UdtErrorEnumV0(ScSpecUdtErrorEnumV0),
EventV0(ScSpecEventV0),
V2(ScSpecEntryV2),
}

#[cfg(feature = "alloc")]
Expand All @@ -57,6 +60,7 @@ impl ScSpecEntry {
ScSpecEntryKind::UdtEnumV0,
ScSpecEntryKind::UdtErrorEnumV0,
ScSpecEntryKind::EventV0,
ScSpecEntryKind::V2,
];
pub const VARIANTS: [ScSpecEntryKind; Self::_VARIANTS.len()] = {
let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
Expand All @@ -74,6 +78,7 @@ impl ScSpecEntry {
"UdtEnumV0",
"UdtErrorEnumV0",
"EventV0",
"V2",
];
pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
Expand All @@ -94,6 +99,7 @@ impl ScSpecEntry {
Self::UdtEnumV0(_) => "UdtEnumV0",
Self::UdtErrorEnumV0(_) => "UdtErrorEnumV0",
Self::EventV0(_) => "EventV0",
Self::V2(_) => "V2",
}
}

Expand All @@ -107,6 +113,7 @@ impl ScSpecEntry {
Self::UdtEnumV0(_) => ScSpecEntryKind::UdtEnumV0,
Self::UdtErrorEnumV0(_) => ScSpecEntryKind::UdtErrorEnumV0,
Self::EventV0(_) => ScSpecEntryKind::EventV0,
Self::V2(_) => ScSpecEntryKind::V2,
}
}

Expand Down Expand Up @@ -153,6 +160,7 @@ impl ReadXdr for ScSpecEntry {
Self::UdtErrorEnumV0(ScSpecUdtErrorEnumV0::read_xdr(r)?)
}
ScSpecEntryKind::EventV0 => Self::EventV0(ScSpecEventV0::read_xdr(r)?),
ScSpecEntryKind::V2 => Self::V2(ScSpecEntryV2::read_xdr(r)?),
#[allow(unreachable_patterns)]
_ => return Err(Error::Invalid),
};
Expand All @@ -174,6 +182,7 @@ impl WriteXdr for ScSpecEntry {
Self::UdtEnumV0(v) => v.write_xdr(w)?,
Self::UdtErrorEnumV0(v) => v.write_xdr(w)?,
Self::EventV0(v) => v.write_xdr(w)?,
Self::V2(v) => v.write_xdr(w)?,
};
Ok(())
})
Expand All @@ -191,6 +200,7 @@ pub enum ScSpecEntryView<'a> {
UdtEnumV0(ScSpecUdtEnumV0View<'a>),
UdtErrorEnumV0(ScSpecUdtErrorEnumV0View<'a>),
EventV0(ScSpecEventV0View<'a>),
V2(ScSpecEntryV2View<'a>),
}

#[cfg(feature = "alloc")]
Expand All @@ -205,6 +215,7 @@ impl From<&ScSpecEntryView<'_>> for ScSpecEntry {
ScSpecEntryView::UdtEnumV0(value) => Self::UdtEnumV0(value.into()),
ScSpecEntryView::UdtErrorEnumV0(value) => Self::UdtErrorEnumV0(value.into()),
ScSpecEntryView::EventV0(value) => Self::EventV0(value.into()),
ScSpecEntryView::V2(value) => Self::V2(value.into()),
}
}
}
Expand All @@ -228,6 +239,7 @@ impl ScSpecEntryView<'_> {
Self::UdtEnumV0(_) => ScSpecEntryKind::UdtEnumV0,
Self::UdtErrorEnumV0(_) => ScSpecEntryKind::UdtErrorEnumV0,
Self::EventV0(_) => ScSpecEntryKind::EventV0,
Self::V2(_) => ScSpecEntryKind::V2,
}
}
}
Expand All @@ -245,6 +257,7 @@ impl WriteXdr for ScSpecEntryView<'_> {
Self::UdtEnumV0(v) => v.write_xdr(w)?,
Self::UdtErrorEnumV0(v) => v.write_xdr(w)?,
Self::EventV0(v) => v.write_xdr(w)?,
Self::V2(v) => v.write_xdr(w)?,
};
Ok(())
})
Expand Down Expand Up @@ -279,6 +292,9 @@ impl ScSpecEntryView<'_> {
Self::EventV0(v) => {
v.const_write_xdr(w);
}
Self::V2(v) => {
v.const_write_xdr(w);
}
}
w.leave_depth();
}
Expand Down
8 changes: 7 additions & 1 deletion src/generated/sc_spec_entry_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use super::*;
/// SC_SPEC_ENTRY_UDT_UNION_V0 = 2,
/// SC_SPEC_ENTRY_UDT_ENUM_V0 = 3,
/// SC_SPEC_ENTRY_UDT_ERROR_ENUM_V0 = 4,
/// SC_SPEC_ENTRY_EVENT_V0 = 5
/// SC_SPEC_ENTRY_EVENT_V0 = 5,
/// SC_SPEC_ENTRY_V2 = 6
/// };
/// ```
///
Expand All @@ -34,6 +35,7 @@ pub enum ScSpecEntryKind {
UdtEnumV0 = 3,
UdtErrorEnumV0 = 4,
EventV0 = 5,
V2 = 6,
}

impl ScSpecEntryKind {
Expand All @@ -44,6 +46,7 @@ impl ScSpecEntryKind {
ScSpecEntryKind::UdtEnumV0,
ScSpecEntryKind::UdtErrorEnumV0,
ScSpecEntryKind::EventV0,
ScSpecEntryKind::V2,
];
pub const VARIANTS: [ScSpecEntryKind; Self::_VARIANTS.len()] = {
let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
Expand All @@ -61,6 +64,7 @@ impl ScSpecEntryKind {
"UdtEnumV0",
"UdtErrorEnumV0",
"EventV0",
"V2",
];
pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
Expand All @@ -81,6 +85,7 @@ impl ScSpecEntryKind {
Self::UdtEnumV0 => "UdtEnumV0",
Self::UdtErrorEnumV0 => "UdtErrorEnumV0",
Self::EventV0 => "EventV0",
Self::V2 => "V2",
}
}

Expand Down Expand Up @@ -122,6 +127,7 @@ impl TryFrom<i32> for ScSpecEntryKind {
3 => ScSpecEntryKind::UdtEnumV0,
4 => ScSpecEntryKind::UdtErrorEnumV0,
5 => ScSpecEntryKind::EventV0,
6 => ScSpecEntryKind::V2,
#[allow(unreachable_patterns)]
_ => return Err(Error::Invalid),
};
Expand Down
158 changes: 158 additions & 0 deletions src/generated/sc_spec_entry_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#[allow(unused_imports, clippy::wildcard_imports)]
use super::*;

/// ScSpecEntryV2 is an XDR Struct defined as:
///
/// ```text
/// struct SCSpecEntryV2
/// {
/// opaque id[SC_SPEC_ID_LEN];
/// union switch (SCSpecEntryKind kind)
/// {
/// case SC_SPEC_ENTRY_FUNCTION_V0:
/// SCSpecFunctionV0 functionV0;
/// case SC_SPEC_ENTRY_UDT_STRUCT_V0:
/// SCSpecUDTStructV0 udtStructV0;
/// case SC_SPEC_ENTRY_UDT_UNION_V0:
/// SCSpecUDTUnionV0 udtUnionV0;
/// case SC_SPEC_ENTRY_UDT_ENUM_V0:
/// SCSpecUDTEnumV0 udtEnumV0;
/// case SC_SPEC_ENTRY_UDT_ERROR_ENUM_V0:
/// SCSpecUDTErrorEnumV0 udtErrorEnumV0;
/// case SC_SPEC_ENTRY_EVENT_V0:
/// SCSpecEventV0 eventV0;
/// } body;
/// };
/// ```
///
#[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 ScSpecEntryV2 {
pub id: [u8; 8],
pub body: ScSpecEntryV2Body,
}

impl ReadXdr for ScSpecEntryV2 {
#[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)?,
body: ScSpecEntryV2Body::read_xdr(r)?,
})
})
}
}

impl WriteXdr for ScSpecEntryV2 {
#[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)?;
self.body.write_xdr(w)?;
Ok(())
})
}
}

/// ScSpecEntryV2View is a borrowing equivalent of [`ScSpecEntryV2`], usable in
/// const contexts and convertible to the owned type via [`From`]/[`Into`].
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct ScSpecEntryV2View<'a> {
pub id: [u8; 8],
pub body: ScSpecEntryV2BodyView<'a>,
}

#[cfg(feature = "alloc")]
impl From<&ScSpecEntryV2View<'_>> for ScSpecEntryV2 {
#[must_use]
fn from(v: &ScSpecEntryV2View<'_>) -> Self {
Self {
id: v.id,
body: (&v.body).into(),
}
}
}

#[cfg(feature = "alloc")]
impl From<ScSpecEntryV2View<'_>> for ScSpecEntryV2 {
#[must_use]
fn from(v: ScSpecEntryV2View<'_>) -> Self {
Self::from(&v)
}
}

impl WriteXdr for ScSpecEntryV2View<'_> {
#[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)?;
self.body.write_xdr(w)?;
Ok(())
})
}
}
#[cfg(feature = "const")]
impl ScSpecEntryV2View<'_> {
/// 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);
self.body.const_write_xdr(w);
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