thruput-xdr 0.66.2

Bindings for Thruput protocol structures
Documentation
// Generated by xdrc 0.18.0 (xdrs d7777c37264da66eb41f8139bd539c4aa049fcc5). Do not edit.

#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(clippy::unnecessary_cast)]
use crate::*;
use core::ops::{Deref, DerefMut};
use core::option::Option;
#[cfg(feature = "std")]
use std::io::{Read, Write};
#[cfg(feature = "xdrs")]
use xdrs::*;
#[cfg(feature = "serde")]
use ::serde::{Deserialize, Serialize};

/// Flags that modify the behavior of a contract invocation.
///
/// These flags are used with the Invoke syscall to control how a subinvocation
/// executes. They are combined using bitwise OR.
///
/// Note: InvokeFlagSet is NOT part of the Invocation struct itself, but is
/// instead a parameter to the Invoke syscall. The root transaction invocation
/// always has no flags set (equivalent to None).
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Copy)]
#[repr(transparent)]
pub struct InvokeFlag(pub i32);

impl InvokeFlag {
    /// No special behavior (default).
    pub const None: Self = Self(0);
    /// Enable early conflict detection for parallel execution.
    ///
    /// Thruput executes transactions in parallel without observing other
    /// transactions' writes. After execution, a two-phase commit process commits writes
    /// to the database. If there's a conflict, the entire transaction aborts.
    ///
    /// TryInvoke pulls this conflict detection earlier: when a try_invoke frame
    /// finishes, it performs two-phase commit lock acquisition immediately. If any lock fails,
    /// the subinvocation frame reverts (but the caller can handle this gracefully).
    ///
    /// This is nondeterministic, so the two-phase commit result (a boolean) is appended to
    /// the nondeterministic_bits in [`NondeterministicProposalData`] for deterministic
    /// re-execution by validators.
    pub const TryInvoke: Self = Self(0x00000001);
    /// Prevent all state modifications in the subinvocation.
    ///
    /// The subinvocation can read storage but cannot write, deploy contracts,
    /// or perform any other state-modifying operations.
    pub const ReadOnly: Self = Self(0x00000002);
    /// Execute the target contract's code in the caller's context.
    ///
    /// Similar to Ethereum's DELEGATECALL: the invoked code runs with the
    /// caller's storage and address context, allowing library-like code reuse.
    ///
    /// TODO: This flag is not yet implemented. When implementing, provide
    /// a comprehensive specification of what changes and what doesn't change in
    /// a delegatecall frame. For example, GetMsgSender and GetCurrentAddress
    /// should NOT change (they return the original caller and current address),
    /// but storage operations should operate on the caller's storage. Document
    /// the behavior of all syscalls in a delegatecall context.
    pub const DelegateCall: Self = Self(0x00000004);
}

impl From<i32> for InvokeFlag {
    fn from(v: i32) -> Self {
        Self(v)
    }
}

#[cfg(feature = "xdrs")]
impl xdrs::XDRDiscriminant for InvokeFlag {
    const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
    fn discriminant(&self) -> i32 {
        self.0
    }
    fn from_discriminant(d: i32) -> Self {
        Self(d)
    }
}

#[cfg(feature = "std")]
impl core::fmt::Display for InvokeFlag {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self.0 {
            x if x == Self::None.0 => f.write_str("InvokeFlag::None"),
            x if x == Self::TryInvoke.0 => f.write_str("InvokeFlag::TryInvoke"),
            x if x == Self::ReadOnly.0 => f.write_str("InvokeFlag::ReadOnly"),
            x if x == Self::DelegateCall.0 => f.write_str("InvokeFlag::DelegateCall"),
            _ => write!(f, "InvokeFlag({})", self.0),
        }
    }
}

/// A bitset of InvokeFlag values.
///
/// Multiple flags can be combined using bitwise OR. For example:
/// `ReadOnly | TryInvoke`
///
/// Unsigned because it holds bits, not a number, even though InvokeFlag,
/// like every XDR enum, is a signed int.
pub type InvokeFlagSet = u32;