#![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::option::Option;
use core::ops::{Deref, DerefMut};
#[cfg(feature = "std")]
use std::io::{Read, Write};
#[cfg(feature = "xdrs")]
use xdrs::*;
#[cfg(feature = "serde")]
use ::serde::{{Serialize, Deserialize}};
pub const kDefaultMaxContractSizeBytes : u32 = 524288;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractBlob {
pub data: BytesM,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Copy)]
#[repr(transparent)]
pub struct ContractType(pub i32);
impl ContractType {
pub const kNative: Self = Self(1);
pub const kMockTest: Self = Self(2);
pub const kRv32: Self = Self(3);
}
impl From<i32> for ContractType {
fn from(v: i32) -> Self {
Self(v)
}
}
#[cfg(feature = "std")]
impl core::fmt::Display for ContractType {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self.0 {
x if x == Self::kNative.0 => {
write!(f, "ContractType::kNative")
},
x if x == Self::kMockTest.0 => {
write!(f, "ContractType::kMockTest")
},
x if x == Self::kRv32.0 => {
write!(f, "ContractType::kRv32")
},
_ => {
write!(f, "ContractType({})", self.0)
}
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[repr(i32)]
#[non_exhaustive]
pub enum Contract {
kNative { native_contract_id: HogexecPrecompiledNativeContracts } = ContractType::kNative.0 as i32,
kMockTest { mock_contract_id: i32 } = ContractType::kMockTest.0 as i32,
kRv32 { rv32_contract: ContractBlob } = ContractType::kRv32.0 as i32,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractDeploymentHashPreimage {
pub deployer_address: ContractAddress,
pub nonce: SHA256Hash,
pub contract_hash: SHA256Hash,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Default, Copy)]
#[repr(transparent)]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct ContractEntrypointID {
#[cfg_attr(feature = "serde", serde(with = "xdr_common::serde_hex"))]
inner: [u8; 8 as usize],
}
impl From<[u8; 8 as usize]> for ContractEntrypointID {
fn from(_inner: [u8; 8 as usize]) -> Self {
Self { inner: _inner }
}
}
impl ContractEntrypointID {
pub fn into_inner(self) -> [u8; 8 as usize] {
self.inner
}
pub const fn new(_inner: [u8; 8 as usize]) -> Self {
Self { inner: _inner }
}
}
impl Deref for ContractEntrypointID {
type Target = [u8; 8 as usize];
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl DerefMut for ContractEntrypointID {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<[u8]> for ContractEntrypointID {
fn as_ref(&self) -> &[u8] {
self.deref().as_slice()
}
}
impl<'a> From<&'a [u8; 8]> for &'a ContractEntrypointID {
fn from(arr: &[u8; 8]) -> Self {
let ptr = arr as *const [u8; 8] as *const ContractEntrypointID;
unsafe { &*ptr }
}
}
#[cfg(feature = "xdrs")]
impl<'r: 'a, 'a> ReadXDR<'r> for &'a ContractEntrypointID {
fn read_xdr<R: xdrs::Reader<'r>>(r: &mut R) -> xdrs::ReadResult<Self> {
let arr: &[u8; 8] = xdrs::read_xdr(r)?;
let val = Self::from(arr);
Ok(val)
}
}
#[cfg(feature = "schema")]
impl schemars::JsonSchema for ContractEntrypointID {
fn schema_name() -> ::std::borrow::Cow<'static, str> {
"ContractEntrypointID".into()
}
fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"type": "string",
"contentEncoding": "hex",
"contentMediaType": "application/binary",
"minLength": 16,
"maxLength": 16
})
}
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct DeployedContractHash {
pub hash: SHA256Hash,
pub contract_size: u32,
pub contract_type: ContractType,
}
impl Contract {
#[allow(clippy::match_single_binding)]
pub fn contract_type(&self) -> ContractType {
match self {
_ => (unsafe { *(self as *const Self as *const i32) }).into(),
}
}
}