diff --git a/src/next/generated.rs b/src/next/generated.rs index 03dd1245..d84b4b53 100644 --- a/src/next/generated.rs +++ b/src/next/generated.rs @@ -24,11 +24,11 @@ pub const XDR_FILES_SHA256: [(&str, &str); 10] = [ ), ( "xdr/next/Stellar-contract-spec.x", - "83f5adc57ccaea49a67063352b869641049c4caf198a3070c4825c5f6e82802a", + "6268629577238adf6210d6e919e41375a3b380e941d0c7acb662013c6f8aa575", ), ( "xdr/next/Stellar-contract.x", - "99696979513d389fabe843874b84dd75a7fec8f8f329ca9ae833c600850dee2d", + "7ec20def7e005a7d90357ac7b39d616435ab5835dc806989515faecdb506f51d", ), ( "xdr/next/Stellar-internal.x", @@ -36,7 +36,7 @@ pub const XDR_FILES_SHA256: [(&str, &str); 10] = [ ), ( "xdr/next/Stellar-ledger-entries.x", - "dae8eead47f2ce6b74b87fc196080cde2b432eedba9e58893f1d5ad315155e4e", + "40ea6015526933dfa49a459b62e1f0f1fbd950ef95949f7faabec4b89d5a9241", ), ( "xdr/next/Stellar-ledger.x", @@ -48,11 +48,11 @@ pub const XDR_FILES_SHA256: [(&str, &str); 10] = [ ), ( "xdr/next/Stellar-transaction.x", - "0ab9890a6ffbe3a7f0b4496f7f531606812c1207b862a0a7bc03b70e83dbdf72", + "4fee5c1982810aa1746dbaf81dd6d84f1fe8193cb535bf0839da3509e7907547", ), ( "xdr/next/Stellar-types.x", - "7b3e5470c4bcf7c19f9cc8f8bf81a494b540fc2157476329cf19863afab2343b", + "6e3b13f0d3e360b09fa5e2b0e55d43f4d974a769df66afb34e8aecbb329d3f15", ), ]; @@ -2975,19 +2975,23 @@ pub const SC_SPEC_DOC_LIMIT: u64 = 1024; // SC_SPEC_TYPE_VAL = 0, // // // Types with no parameters. -// SC_SPEC_TYPE_U32 = 1, -// SC_SPEC_TYPE_I32 = 2, -// SC_SPEC_TYPE_U64 = 3, -// SC_SPEC_TYPE_I64 = 4, -// SC_SPEC_TYPE_U128 = 5, -// SC_SPEC_TYPE_I128 = 6, -// SC_SPEC_TYPE_BOOL = 7, -// SC_SPEC_TYPE_SYMBOL = 8, -// SC_SPEC_TYPE_BITSET = 9, -// SC_SPEC_TYPE_STATUS = 10, -// SC_SPEC_TYPE_BYTES = 11, -// SC_SPEC_TYPE_INVOKER = 12, -// SC_SPEC_TYPE_ADDRESS = 13, +// SC_SPEC_TYPE_BOOL = 1, +// SC_SPEC_TYPE_VOID = 2, +// SC_SPEC_TYPE_STATUS = 3, +// SC_SPEC_TYPE_U32 = 4, +// SC_SPEC_TYPE_I32 = 5, +// SC_SPEC_TYPE_U64 = 6, +// SC_SPEC_TYPE_I64 = 7, +// SC_SPEC_TYPE_TIMEPOINT = 8, +// SC_SPEC_TYPE_DURATION = 9, +// SC_SPEC_TYPE_U128 = 10, +// SC_SPEC_TYPE_I128 = 11, +// SC_SPEC_TYPE_U256 = 12, +// SC_SPEC_TYPE_I256 = 13, +// SC_SPEC_TYPE_BYTES = 14, +// SC_SPEC_TYPE_STRING = 16, +// SC_SPEC_TYPE_SYMBOL = 17, +// SC_SPEC_TYPE_ADDRESS = 19, // // // Types with parameters. // SC_SPEC_TYPE_OPTION = 1000, @@ -3013,19 +3017,23 @@ pub const SC_SPEC_DOC_LIMIT: u64 = 1024; #[repr(i32)] pub enum ScSpecType { Val = 0, - U32 = 1, - I32 = 2, - U64 = 3, - I64 = 4, - U128 = 5, - I128 = 6, - Bool = 7, - Symbol = 8, - Bitset = 9, - Status = 10, - Bytes = 11, - Invoker = 12, - Address = 13, + Bool = 1, + Void = 2, + Status = 3, + U32 = 4, + I32 = 5, + U64 = 6, + I64 = 7, + Timepoint = 8, + Duration = 9, + U128 = 10, + I128 = 11, + U256 = 12, + I256 = 13, + Bytes = 14, + String = 16, + Symbol = 17, + Address = 19, Option = 1000, Result = 1001, Vec = 1002, @@ -3037,20 +3045,24 @@ pub enum ScSpecType { } impl ScSpecType { - pub const VARIANTS: [ScSpecType; 22] = [ + pub const VARIANTS: [ScSpecType; 26] = [ ScSpecType::Val, + ScSpecType::Bool, + ScSpecType::Void, + ScSpecType::Status, ScSpecType::U32, ScSpecType::I32, ScSpecType::U64, ScSpecType::I64, + ScSpecType::Timepoint, + ScSpecType::Duration, ScSpecType::U128, ScSpecType::I128, - ScSpecType::Bool, - ScSpecType::Symbol, - ScSpecType::Bitset, - ScSpecType::Status, + ScSpecType::U256, + ScSpecType::I256, ScSpecType::Bytes, - ScSpecType::Invoker, + ScSpecType::String, + ScSpecType::Symbol, ScSpecType::Address, ScSpecType::Option, ScSpecType::Result, @@ -3061,9 +3073,32 @@ impl ScSpecType { ScSpecType::BytesN, ScSpecType::Udt, ]; - pub const VARIANTS_STR: [&'static str; 22] = [ - "Val", "U32", "I32", "U64", "I64", "U128", "I128", "Bool", "Symbol", "Bitset", "Status", - "Bytes", "Invoker", "Address", "Option", "Result", "Vec", "Set", "Map", "Tuple", "BytesN", + pub const VARIANTS_STR: [&'static str; 26] = [ + "Val", + "Bool", + "Void", + "Status", + "U32", + "I32", + "U64", + "I64", + "Timepoint", + "Duration", + "U128", + "I128", + "U256", + "I256", + "Bytes", + "String", + "Symbol", + "Address", + "Option", + "Result", + "Vec", + "Set", + "Map", + "Tuple", + "BytesN", "Udt", ]; @@ -3071,18 +3106,22 @@ impl ScSpecType { pub const fn name(&self) -> &'static str { match self { Self::Val => "Val", + Self::Bool => "Bool", + Self::Void => "Void", + Self::Status => "Status", Self::U32 => "U32", Self::I32 => "I32", Self::U64 => "U64", Self::I64 => "I64", + Self::Timepoint => "Timepoint", + Self::Duration => "Duration", Self::U128 => "U128", Self::I128 => "I128", - Self::Bool => "Bool", - Self::Symbol => "Symbol", - Self::Bitset => "Bitset", - Self::Status => "Status", + Self::U256 => "U256", + Self::I256 => "I256", Self::Bytes => "Bytes", - Self::Invoker => "Invoker", + Self::String => "String", + Self::Symbol => "Symbol", Self::Address => "Address", Self::Option => "Option", Self::Result => "Result", @@ -3096,7 +3135,7 @@ impl ScSpecType { } #[must_use] - pub const fn variants() -> [ScSpecType; 22] { + pub const fn variants() -> [ScSpecType; 26] { Self::VARIANTS } } @@ -3128,19 +3167,23 @@ impl TryFrom for ScSpecType { fn try_from(i: i32) -> Result { let e = match i { 0 => ScSpecType::Val, - 1 => ScSpecType::U32, - 2 => ScSpecType::I32, - 3 => ScSpecType::U64, - 4 => ScSpecType::I64, - 5 => ScSpecType::U128, - 6 => ScSpecType::I128, - 7 => ScSpecType::Bool, - 8 => ScSpecType::Symbol, - 9 => ScSpecType::Bitset, - 10 => ScSpecType::Status, - 11 => ScSpecType::Bytes, - 12 => ScSpecType::Invoker, - 13 => ScSpecType::Address, + 1 => ScSpecType::Bool, + 2 => ScSpecType::Void, + 3 => ScSpecType::Status, + 4 => ScSpecType::U32, + 5 => ScSpecType::I32, + 6 => ScSpecType::U64, + 7 => ScSpecType::I64, + 8 => ScSpecType::Timepoint, + 9 => ScSpecType::Duration, + 10 => ScSpecType::U128, + 11 => ScSpecType::I128, + 12 => ScSpecType::U256, + 13 => ScSpecType::I256, + 14 => ScSpecType::Bytes, + 16 => ScSpecType::String, + 17 => ScSpecType::Symbol, + 19 => ScSpecType::Address, 1000 => ScSpecType::Option, 1001 => ScSpecType::Result, 1002 => ScSpecType::Vec, @@ -3473,17 +3516,22 @@ impl WriteXdr for ScSpecTypeUdt { // union SCSpecTypeDef switch (SCSpecType type) // { // case SC_SPEC_TYPE_VAL: +// case SC_SPEC_TYPE_BOOL: +// case SC_SPEC_TYPE_VOID: +// case SC_SPEC_TYPE_STATUS: +// case SC_SPEC_TYPE_U32: +// case SC_SPEC_TYPE_I32: // case SC_SPEC_TYPE_U64: // case SC_SPEC_TYPE_I64: +// case SC_SPEC_TYPE_TIMEPOINT: +// case SC_SPEC_TYPE_DURATION: // case SC_SPEC_TYPE_U128: // case SC_SPEC_TYPE_I128: -// case SC_SPEC_TYPE_U32: -// case SC_SPEC_TYPE_I32: -// case SC_SPEC_TYPE_BOOL: -// case SC_SPEC_TYPE_SYMBOL: -// case SC_SPEC_TYPE_BITSET: -// case SC_SPEC_TYPE_STATUS: +// case SC_SPEC_TYPE_U256: +// case SC_SPEC_TYPE_I256: // case SC_SPEC_TYPE_BYTES: +// case SC_SPEC_TYPE_STRING: +// case SC_SPEC_TYPE_SYMBOL: // case SC_SPEC_TYPE_ADDRESS: // void; // case SC_SPEC_TYPE_OPTION: @@ -3515,17 +3563,22 @@ impl WriteXdr for ScSpecTypeUdt { #[allow(clippy::large_enum_variant)] pub enum ScSpecTypeDef { Val, + Bool, + Void, + Status, + U32, + I32, U64, I64, + Timepoint, + Duration, U128, I128, - U32, - I32, - Bool, - Symbol, - Bitset, - Status, + U256, + I256, Bytes, + String, + Symbol, Address, Option(Box), Result(Box), @@ -3538,19 +3591,24 @@ pub enum ScSpecTypeDef { } impl ScSpecTypeDef { - pub const VARIANTS: [ScSpecType; 21] = [ + pub const VARIANTS: [ScSpecType; 26] = [ ScSpecType::Val, + ScSpecType::Bool, + ScSpecType::Void, + ScSpecType::Status, + ScSpecType::U32, + ScSpecType::I32, ScSpecType::U64, ScSpecType::I64, + ScSpecType::Timepoint, + ScSpecType::Duration, ScSpecType::U128, ScSpecType::I128, - ScSpecType::U32, - ScSpecType::I32, - ScSpecType::Bool, - ScSpecType::Symbol, - ScSpecType::Bitset, - ScSpecType::Status, + ScSpecType::U256, + ScSpecType::I256, ScSpecType::Bytes, + ScSpecType::String, + ScSpecType::Symbol, ScSpecType::Address, ScSpecType::Option, ScSpecType::Result, @@ -3561,26 +3619,55 @@ impl ScSpecTypeDef { ScSpecType::BytesN, ScSpecType::Udt, ]; - pub const VARIANTS_STR: [&'static str; 21] = [ - "Val", "U64", "I64", "U128", "I128", "U32", "I32", "Bool", "Symbol", "Bitset", "Status", - "Bytes", "Address", "Option", "Result", "Vec", "Map", "Set", "Tuple", "BytesN", "Udt", + pub const VARIANTS_STR: [&'static str; 26] = [ + "Val", + "Bool", + "Void", + "Status", + "U32", + "I32", + "U64", + "I64", + "Timepoint", + "Duration", + "U128", + "I128", + "U256", + "I256", + "Bytes", + "String", + "Symbol", + "Address", + "Option", + "Result", + "Vec", + "Map", + "Set", + "Tuple", + "BytesN", + "Udt", ]; #[must_use] pub const fn name(&self) -> &'static str { match self { Self::Val => "Val", + Self::Bool => "Bool", + Self::Void => "Void", + Self::Status => "Status", + Self::U32 => "U32", + Self::I32 => "I32", Self::U64 => "U64", Self::I64 => "I64", + Self::Timepoint => "Timepoint", + Self::Duration => "Duration", Self::U128 => "U128", Self::I128 => "I128", - Self::U32 => "U32", - Self::I32 => "I32", - Self::Bool => "Bool", - Self::Symbol => "Symbol", - Self::Bitset => "Bitset", - Self::Status => "Status", + Self::U256 => "U256", + Self::I256 => "I256", Self::Bytes => "Bytes", + Self::String => "String", + Self::Symbol => "Symbol", Self::Address => "Address", Self::Option(_) => "Option", Self::Result(_) => "Result", @@ -3598,17 +3685,22 @@ impl ScSpecTypeDef { #[allow(clippy::match_same_arms)] match self { Self::Val => ScSpecType::Val, + Self::Bool => ScSpecType::Bool, + Self::Void => ScSpecType::Void, + Self::Status => ScSpecType::Status, + Self::U32 => ScSpecType::U32, + Self::I32 => ScSpecType::I32, Self::U64 => ScSpecType::U64, Self::I64 => ScSpecType::I64, + Self::Timepoint => ScSpecType::Timepoint, + Self::Duration => ScSpecType::Duration, Self::U128 => ScSpecType::U128, Self::I128 => ScSpecType::I128, - Self::U32 => ScSpecType::U32, - Self::I32 => ScSpecType::I32, - Self::Bool => ScSpecType::Bool, - Self::Symbol => ScSpecType::Symbol, - Self::Bitset => ScSpecType::Bitset, - Self::Status => ScSpecType::Status, + Self::U256 => ScSpecType::U256, + Self::I256 => ScSpecType::I256, Self::Bytes => ScSpecType::Bytes, + Self::String => ScSpecType::String, + Self::Symbol => ScSpecType::Symbol, Self::Address => ScSpecType::Address, Self::Option(_) => ScSpecType::Option, Self::Result(_) => ScSpecType::Result, @@ -3622,7 +3714,7 @@ impl ScSpecTypeDef { } #[must_use] - pub const fn variants() -> [ScSpecType; 21] { + pub const fn variants() -> [ScSpecType; 26] { Self::VARIANTS } } @@ -3656,17 +3748,22 @@ impl ReadXdr for ScSpecTypeDef { #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)] let v = match dv { ScSpecType::Val => Self::Val, + ScSpecType::Bool => Self::Bool, + ScSpecType::Void => Self::Void, + ScSpecType::Status => Self::Status, + ScSpecType::U32 => Self::U32, + ScSpecType::I32 => Self::I32, ScSpecType::U64 => Self::U64, ScSpecType::I64 => Self::I64, + ScSpecType::Timepoint => Self::Timepoint, + ScSpecType::Duration => Self::Duration, ScSpecType::U128 => Self::U128, ScSpecType::I128 => Self::I128, - ScSpecType::U32 => Self::U32, - ScSpecType::I32 => Self::I32, - ScSpecType::Bool => Self::Bool, - ScSpecType::Symbol => Self::Symbol, - ScSpecType::Bitset => Self::Bitset, - ScSpecType::Status => Self::Status, + ScSpecType::U256 => Self::U256, + ScSpecType::I256 => Self::I256, ScSpecType::Bytes => Self::Bytes, + ScSpecType::String => Self::String, + ScSpecType::Symbol => Self::Symbol, ScSpecType::Address => Self::Address, ScSpecType::Option => Self::Option(Box::::read_xdr(r)?), ScSpecType::Result => Self::Result(Box::::read_xdr(r)?), @@ -3690,17 +3787,22 @@ impl WriteXdr for ScSpecTypeDef { #[allow(clippy::match_same_arms)] match self { Self::Val => ().write_xdr(w)?, + Self::Bool => ().write_xdr(w)?, + Self::Void => ().write_xdr(w)?, + Self::Status => ().write_xdr(w)?, + Self::U32 => ().write_xdr(w)?, + Self::I32 => ().write_xdr(w)?, Self::U64 => ().write_xdr(w)?, Self::I64 => ().write_xdr(w)?, + Self::Timepoint => ().write_xdr(w)?, + Self::Duration => ().write_xdr(w)?, Self::U128 => ().write_xdr(w)?, Self::I128 => ().write_xdr(w)?, - Self::U32 => ().write_xdr(w)?, - Self::I32 => ().write_xdr(w)?, - Self::Bool => ().write_xdr(w)?, - Self::Symbol => ().write_xdr(w)?, - Self::Bitset => ().write_xdr(w)?, - Self::Status => ().write_xdr(w)?, + Self::U256 => ().write_xdr(w)?, + Self::I256 => ().write_xdr(w)?, Self::Bytes => ().write_xdr(w)?, + Self::String => ().write_xdr(w)?, + Self::Symbol => ().write_xdr(w)?, Self::Address => ().write_xdr(w)?, Self::Option(v) => v.write_xdr(w)?, Self::Result(v) => v.write_xdr(w)?, @@ -4673,118 +4775,62 @@ impl WriteXdr for ScSpecEntry { } } -// ScSymbol is an XDR Typedef defines as: -// -// typedef string SCSymbol<10>; -// -#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] -#[derive(Default, Debug)] -#[cfg_attr( - all(feature = "serde", feature = "alloc"), - derive(serde::Serialize, serde::Deserialize), - serde(rename_all = "snake_case") -)] -pub struct ScSymbol(pub StringM<10>); - -impl From for StringM<10> { - #[must_use] - fn from(x: ScSymbol) -> Self { - x.0 - } -} - -impl From> for ScSymbol { - #[must_use] - fn from(x: StringM<10>) -> Self { - ScSymbol(x) - } -} - -impl AsRef> for ScSymbol { - #[must_use] - fn as_ref(&self) -> &StringM<10> { - &self.0 - } -} - -impl ReadXdr for ScSymbol { - #[cfg(feature = "std")] - fn read_xdr(r: &mut impl Read) -> Result { - let i = StringM::<10>::read_xdr(r)?; - let v = ScSymbol(i); - Ok(v) - } -} - -impl WriteXdr for ScSymbol { - #[cfg(feature = "std")] - fn write_xdr(&self, w: &mut impl Write) -> Result<()> { - self.0.write_xdr(w) - } -} - -impl Deref for ScSymbol { - type Target = StringM<10>; - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl From for Vec { - #[must_use] - fn from(x: ScSymbol) -> Self { - x.0 .0 - } -} - -impl TryFrom> for ScSymbol { - type Error = Error; - fn try_from(x: Vec) -> Result { - Ok(ScSymbol(x.try_into()?)) - } -} - -#[cfg(feature = "alloc")] -impl TryFrom<&Vec> for ScSymbol { - type Error = Error; - fn try_from(x: &Vec) -> Result { - Ok(ScSymbol(x.try_into()?)) - } -} - -impl AsRef> for ScSymbol { - #[must_use] - fn as_ref(&self) -> &Vec { - &self.0 .0 - } -} - -impl AsRef<[u8]> for ScSymbol { - #[cfg(feature = "alloc")] - #[must_use] - fn as_ref(&self) -> &[u8] { - &self.0 .0 - } - #[cfg(not(feature = "alloc"))] - #[must_use] - fn as_ref(&self) -> &[u8] { - self.0 .0 - } -} - // ScValType is an XDR Enum defines as: // // enum SCValType // { -// SCV_U63 = 0, -// SCV_U32 = 1, -// SCV_I32 = 2, -// SCV_STATIC = 3, -// SCV_OBJECT = 4, -// SCV_SYMBOL = 5, -// SCV_BITSET = 6, -// SCV_STATUS = 7 +// SCV_BOOL = 0, +// SCV_VOID = 1, +// SCV_STATUS = 2, +// +// // 32 bits is the smallest type in WASM or XDR; no need for u8/u16. +// SCV_U32 = 3, +// SCV_I32 = 4, +// +// // 64 bits is naturally supported by both WASM and XDR also. +// SCV_U64 = 5, +// SCV_I64 = 6, +// +// // Time-related u64 subtypes with their own functions and formatting. +// SCV_TIMEPOINT = 7, +// SCV_DURATION = 8, +// +// // 128 bits is naturally supported by Rust and we use it for Soroban +// // fixed-point arithmetic prices / balances / similar "quantities". These +// // are represented in XDR as a pair of 2 u64s, unlike {u,i}256 which is +// // represented as an array of 32 bytes. +// SCV_U128 = 9, +// SCV_I128 = 10, +// +// // 256 bits is the size of sha256 output, ed25519 keys, and the EVM machine +// // word, so for interop use we include this even though it requires a small +// // amount of Rust guest and/or host library code. +// SCV_U256 = 11, +// SCV_I256 = 12, +// +// // TODO: possibly allocate subtypes of i64, i128 and/or u256 for +// // fixed-precision with a specific number of decimals. +// +// // Bytes come in 3 flavors, 2 of which have meaningfully different +// // formatting and validity-checking / domain-restriction. +// SCV_BYTES = 13, +// SCV_STRING = 14, +// SCV_SYMBOL = 15, +// +// // Vecs and maps are just polymorphic containers of other ScVals. +// SCV_VEC = 16, +// SCV_MAP = 17, +// +// // SCContractExecutable and SCAddressType are types that gets used separately from +// // SCVal so we do not flatten their structures into separate SCVal cases. +// SCV_CONTRACT_EXECUTABLE = 18, +// SCV_ADDRESS = 19, +// +// // SCV_LEDGER_KEY_CONTRACT_EXECUTABLE and SCV_LEDGER_KEY_NONCE are unique +// // symbolic SCVals used as the key for ledger entries for a contract's code +// // and an address' nonce, respectively. +// SCV_LEDGER_KEY_CONTRACT_EXECUTABLE = 20, +// SCV_LEDGER_KEY_NONCE = 21 // }; // // enum @@ -4797,47 +4843,110 @@ impl AsRef<[u8]> for ScSymbol { )] #[repr(i32)] pub enum ScValType { - U63 = 0, - U32 = 1, - I32 = 2, - Static = 3, - Object = 4, - Symbol = 5, - Bitset = 6, - Status = 7, + Bool = 0, + Void = 1, + Status = 2, + U32 = 3, + I32 = 4, + U64 = 5, + I64 = 6, + Timepoint = 7, + Duration = 8, + U128 = 9, + I128 = 10, + U256 = 11, + I256 = 12, + Bytes = 13, + String = 14, + Symbol = 15, + Vec = 16, + Map = 17, + ContractExecutable = 18, + Address = 19, + LedgerKeyContractExecutable = 20, + LedgerKeyNonce = 21, } impl ScValType { - pub const VARIANTS: [ScValType; 8] = [ - ScValType::U63, + pub const VARIANTS: [ScValType; 22] = [ + ScValType::Bool, + ScValType::Void, + ScValType::Status, ScValType::U32, ScValType::I32, - ScValType::Static, - ScValType::Object, + ScValType::U64, + ScValType::I64, + ScValType::Timepoint, + ScValType::Duration, + ScValType::U128, + ScValType::I128, + ScValType::U256, + ScValType::I256, + ScValType::Bytes, + ScValType::String, ScValType::Symbol, - ScValType::Bitset, - ScValType::Status, + ScValType::Vec, + ScValType::Map, + ScValType::ContractExecutable, + ScValType::Address, + ScValType::LedgerKeyContractExecutable, + ScValType::LedgerKeyNonce, ]; - pub const VARIANTS_STR: [&'static str; 8] = [ - "U63", "U32", "I32", "Static", "Object", "Symbol", "Bitset", "Status", + pub const VARIANTS_STR: [&'static str; 22] = [ + "Bool", + "Void", + "Status", + "U32", + "I32", + "U64", + "I64", + "Timepoint", + "Duration", + "U128", + "I128", + "U256", + "I256", + "Bytes", + "String", + "Symbol", + "Vec", + "Map", + "ContractExecutable", + "Address", + "LedgerKeyContractExecutable", + "LedgerKeyNonce", ]; #[must_use] pub const fn name(&self) -> &'static str { match self { - Self::U63 => "U63", + Self::Bool => "Bool", + Self::Void => "Void", + Self::Status => "Status", Self::U32 => "U32", Self::I32 => "I32", - Self::Static => "Static", - Self::Object => "Object", + Self::U64 => "U64", + Self::I64 => "I64", + Self::Timepoint => "Timepoint", + Self::Duration => "Duration", + Self::U128 => "U128", + Self::I128 => "I128", + Self::U256 => "U256", + Self::I256 => "I256", + Self::Bytes => "Bytes", + Self::String => "String", Self::Symbol => "Symbol", - Self::Bitset => "Bitset", - Self::Status => "Status", + Self::Vec => "Vec", + Self::Map => "Map", + Self::ContractExecutable => "ContractExecutable", + Self::Address => "Address", + Self::LedgerKeyContractExecutable => "LedgerKeyContractExecutable", + Self::LedgerKeyNonce => "LedgerKeyNonce", } } #[must_use] - pub const fn variants() -> [ScValType; 8] { + pub const fn variants() -> [ScValType; 22] { Self::VARIANTS } } @@ -4868,14 +4977,28 @@ impl TryFrom for ScValType { fn try_from(i: i32) -> Result { let e = match i { - 0 => ScValType::U63, - 1 => ScValType::U32, - 2 => ScValType::I32, - 3 => ScValType::Static, - 4 => ScValType::Object, - 5 => ScValType::Symbol, - 6 => ScValType::Bitset, - 7 => ScValType::Status, + 0 => ScValType::Bool, + 1 => ScValType::Void, + 2 => ScValType::Status, + 3 => ScValType::U32, + 4 => ScValType::I32, + 5 => ScValType::U64, + 6 => ScValType::I64, + 7 => ScValType::Timepoint, + 8 => ScValType::Duration, + 9 => ScValType::U128, + 10 => ScValType::I128, + 11 => ScValType::U256, + 12 => ScValType::I256, + 13 => ScValType::Bytes, + 14 => ScValType::String, + 15 => ScValType::Symbol, + 16 => ScValType::Vec, + 17 => ScValType::Map, + 18 => ScValType::ContractExecutable, + 19 => ScValType::Address, + 20 => ScValType::LedgerKeyContractExecutable, + 21 => ScValType::LedgerKeyNonce, #[allow(unreachable_patterns)] _ => return Err(Error::Invalid), }; @@ -4907,118 +5030,6 @@ impl WriteXdr for ScValType { } } -// ScStatic is an XDR Enum defines as: -// -// enum SCStatic -// { -// SCS_VOID = 0, -// SCS_TRUE = 1, -// SCS_FALSE = 2, -// SCS_LEDGER_KEY_CONTRACT_CODE = 3 -// }; -// -// enum -#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] -#[cfg_attr( - all(feature = "serde", feature = "alloc"), - derive(serde::Serialize, serde::Deserialize), - serde(rename_all = "snake_case") -)] -#[repr(i32)] -pub enum ScStatic { - Void = 0, - True = 1, - False = 2, - LedgerKeyContractCode = 3, -} - -impl ScStatic { - pub const VARIANTS: [ScStatic; 4] = [ - ScStatic::Void, - ScStatic::True, - ScStatic::False, - ScStatic::LedgerKeyContractCode, - ]; - pub const VARIANTS_STR: [&'static str; 4] = ["Void", "True", "False", "LedgerKeyContractCode"]; - - #[must_use] - pub const fn name(&self) -> &'static str { - match self { - Self::Void => "Void", - Self::True => "True", - Self::False => "False", - Self::LedgerKeyContractCode => "LedgerKeyContractCode", - } - } - - #[must_use] - pub const fn variants() -> [ScStatic; 4] { - Self::VARIANTS - } -} - -impl Name for ScStatic { - #[must_use] - fn name(&self) -> &'static str { - Self::name(self) - } -} - -impl Variants for ScStatic { - fn variants() -> slice::Iter<'static, ScStatic> { - Self::VARIANTS.iter() - } -} - -impl Enum for ScStatic {} - -impl fmt::Display for ScStatic { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(self.name()) - } -} - -impl TryFrom for ScStatic { - type Error = Error; - - fn try_from(i: i32) -> Result { - let e = match i { - 0 => ScStatic::Void, - 1 => ScStatic::True, - 2 => ScStatic::False, - 3 => ScStatic::LedgerKeyContractCode, - #[allow(unreachable_patterns)] - _ => return Err(Error::Invalid), - }; - Ok(e) - } -} - -impl From for i32 { - #[must_use] - fn from(e: ScStatic) -> Self { - e as Self - } -} - -impl ReadXdr for ScStatic { - #[cfg(feature = "std")] - fn read_xdr(r: &mut impl Read) -> Result { - let e = i32::read_xdr(r)?; - let v: Self = e.try_into()?; - Ok(v) - } -} - -impl WriteXdr for ScStatic { - #[cfg(feature = "std")] - fn write_xdr(&self, w: &mut impl Write) -> Result<()> { - let i: i32 = (*self).into(); - i.write_xdr(w) - } -} - // ScStatusType is an XDR Enum defines as: // // enum SCStatusType @@ -6437,29 +6448,160 @@ impl WriteXdr for ScStatus { } } -// ScVal is an XDR Union defines as: +// Int128Parts is an XDR Struct defines as: // -// union SCVal switch (SCValType type) +// struct Int128Parts { +// // Both signed and unsigned 128-bit ints +// // are transported in a pair of uint64s +// // to reduce the risk of sign-extension. +// uint64 lo; +// uint64 hi; +// }; +// +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr( + all(feature = "serde", feature = "alloc"), + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "snake_case") +)] +pub struct Int128Parts { + pub lo: u64, + pub hi: u64, +} + +impl ReadXdr for Int128Parts { + #[cfg(feature = "std")] + fn read_xdr(r: &mut impl Read) -> Result { + Ok(Self { + lo: u64::read_xdr(r)?, + hi: u64::read_xdr(r)?, + }) + } +} + +impl WriteXdr for Int128Parts { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut impl Write) -> Result<()> { + self.lo.write_xdr(w)?; + self.hi.write_xdr(w)?; + Ok(()) + } +} + +// ScContractExecutableType is an XDR Enum defines as: +// +// enum SCContractExecutableType // { -// case SCV_U63: -// int64 u63; -// case SCV_U32: -// uint32 u32; -// case SCV_I32: -// int32 i32; -// case SCV_STATIC: -// SCStatic ic; -// case SCV_OBJECT: -// SCObject* obj; -// case SCV_SYMBOL: -// SCSymbol sym; -// case SCV_BITSET: -// uint64 bits; -// case SCV_STATUS: -// SCStatus status; +// SCCONTRACT_EXECUTABLE_WASM_REF = 0, +// SCCONTRACT_EXECUTABLE_TOKEN = 1 // }; // -// union with discriminant ScValType +// enum +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr( + all(feature = "serde", feature = "alloc"), + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "snake_case") +)] +#[repr(i32)] +pub enum ScContractExecutableType { + WasmRef = 0, + Token = 1, +} + +impl ScContractExecutableType { + pub const VARIANTS: [ScContractExecutableType; 2] = [ + ScContractExecutableType::WasmRef, + ScContractExecutableType::Token, + ]; + pub const VARIANTS_STR: [&'static str; 2] = ["WasmRef", "Token"]; + + #[must_use] + pub const fn name(&self) -> &'static str { + match self { + Self::WasmRef => "WasmRef", + Self::Token => "Token", + } + } + + #[must_use] + pub const fn variants() -> [ScContractExecutableType; 2] { + Self::VARIANTS + } +} + +impl Name for ScContractExecutableType { + #[must_use] + fn name(&self) -> &'static str { + Self::name(self) + } +} + +impl Variants for ScContractExecutableType { + fn variants() -> slice::Iter<'static, ScContractExecutableType> { + Self::VARIANTS.iter() + } +} + +impl Enum for ScContractExecutableType {} + +impl fmt::Display for ScContractExecutableType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.name()) + } +} + +impl TryFrom for ScContractExecutableType { + type Error = Error; + + fn try_from(i: i32) -> Result { + let e = match i { + 0 => ScContractExecutableType::WasmRef, + 1 => ScContractExecutableType::Token, + #[allow(unreachable_patterns)] + _ => return Err(Error::Invalid), + }; + Ok(e) + } +} + +impl From for i32 { + #[must_use] + fn from(e: ScContractExecutableType) -> Self { + e as Self + } +} + +impl ReadXdr for ScContractExecutableType { + #[cfg(feature = "std")] + fn read_xdr(r: &mut impl Read) -> Result { + let e = i32::read_xdr(r)?; + let v: Self = e.try_into()?; + Ok(v) + } +} + +impl WriteXdr for ScContractExecutableType { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut impl Write) -> Result<()> { + let i: i32 = (*self).into(); + i.write_xdr(w) + } +} + +// ScContractExecutable is an XDR Union defines as: +// +// union SCContractExecutable switch (SCContractExecutableType type) +// { +// case SCCONTRACT_EXECUTABLE_WASM_REF: +// Hash wasm_id; +// case SCCONTRACT_EXECUTABLE_TOKEN: +// void; +// }; +// +// union with discriminant ScContractExecutableType #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] #[cfg_attr( @@ -6468,103 +6610,71 @@ impl WriteXdr for ScStatus { serde(rename_all = "snake_case") )] #[allow(clippy::large_enum_variant)] -pub enum ScVal { - U63(i64), - U32(u32), - I32(i32), - Static(ScStatic), - Object(Option), - Symbol(ScSymbol), - Bitset(u64), - Status(ScStatus), +pub enum ScContractExecutable { + WasmRef(Hash), + Token, } -impl ScVal { - pub const VARIANTS: [ScValType; 8] = [ - ScValType::U63, - ScValType::U32, - ScValType::I32, - ScValType::Static, - ScValType::Object, - ScValType::Symbol, - ScValType::Bitset, - ScValType::Status, - ]; - pub const VARIANTS_STR: [&'static str; 8] = [ - "U63", "U32", "I32", "Static", "Object", "Symbol", "Bitset", "Status", +impl ScContractExecutable { + pub const VARIANTS: [ScContractExecutableType; 2] = [ + ScContractExecutableType::WasmRef, + ScContractExecutableType::Token, ]; + pub const VARIANTS_STR: [&'static str; 2] = ["WasmRef", "Token"]; #[must_use] pub const fn name(&self) -> &'static str { match self { - Self::U63(_) => "U63", - Self::U32(_) => "U32", - Self::I32(_) => "I32", - Self::Static(_) => "Static", - Self::Object(_) => "Object", - Self::Symbol(_) => "Symbol", - Self::Bitset(_) => "Bitset", - Self::Status(_) => "Status", + Self::WasmRef(_) => "WasmRef", + Self::Token => "Token", } } #[must_use] - pub const fn discriminant(&self) -> ScValType { + pub const fn discriminant(&self) -> ScContractExecutableType { #[allow(clippy::match_same_arms)] match self { - Self::U63(_) => ScValType::U63, - Self::U32(_) => ScValType::U32, - Self::I32(_) => ScValType::I32, - Self::Static(_) => ScValType::Static, - Self::Object(_) => ScValType::Object, - Self::Symbol(_) => ScValType::Symbol, - Self::Bitset(_) => ScValType::Bitset, - Self::Status(_) => ScValType::Status, + Self::WasmRef(_) => ScContractExecutableType::WasmRef, + Self::Token => ScContractExecutableType::Token, } } #[must_use] - pub const fn variants() -> [ScValType; 8] { + pub const fn variants() -> [ScContractExecutableType; 2] { Self::VARIANTS } } -impl Name for ScVal { +impl Name for ScContractExecutable { #[must_use] fn name(&self) -> &'static str { Self::name(self) } } -impl Discriminant for ScVal { +impl Discriminant for ScContractExecutable { #[must_use] - fn discriminant(&self) -> ScValType { + fn discriminant(&self) -> ScContractExecutableType { Self::discriminant(self) } } -impl Variants for ScVal { - fn variants() -> slice::Iter<'static, ScValType> { +impl Variants for ScContractExecutable { + fn variants() -> slice::Iter<'static, ScContractExecutableType> { Self::VARIANTS.iter() } } -impl Union for ScVal {} +impl Union for ScContractExecutable {} -impl ReadXdr for ScVal { +impl ReadXdr for ScContractExecutable { #[cfg(feature = "std")] fn read_xdr(r: &mut impl Read) -> Result { - let dv: ScValType = ::read_xdr(r)?; + let dv: ScContractExecutableType = ::read_xdr(r)?; #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)] let v = match dv { - ScValType::U63 => Self::U63(i64::read_xdr(r)?), - ScValType::U32 => Self::U32(u32::read_xdr(r)?), - ScValType::I32 => Self::I32(i32::read_xdr(r)?), - ScValType::Static => Self::Static(ScStatic::read_xdr(r)?), - ScValType::Object => Self::Object(Option::::read_xdr(r)?), - ScValType::Symbol => Self::Symbol(ScSymbol::read_xdr(r)?), - ScValType::Bitset => Self::Bitset(u64::read_xdr(r)?), - ScValType::Status => Self::Status(ScStatus::read_xdr(r)?), + ScContractExecutableType::WasmRef => Self::WasmRef(Hash::read_xdr(r)?), + ScContractExecutableType::Token => Self::Token, #[allow(unreachable_patterns)] _ => return Err(Error::Invalid), }; @@ -6572,44 +6682,25 @@ impl ReadXdr for ScVal { } } -impl WriteXdr for ScVal { +impl WriteXdr for ScContractExecutable { #[cfg(feature = "std")] fn write_xdr(&self, w: &mut impl Write) -> Result<()> { self.discriminant().write_xdr(w)?; #[allow(clippy::match_same_arms)] match self { - Self::U63(v) => v.write_xdr(w)?, - Self::U32(v) => v.write_xdr(w)?, - Self::I32(v) => v.write_xdr(w)?, - Self::Static(v) => v.write_xdr(w)?, - Self::Object(v) => v.write_xdr(w)?, - Self::Symbol(v) => v.write_xdr(w)?, - Self::Bitset(v) => v.write_xdr(w)?, - Self::Status(v) => v.write_xdr(w)?, + Self::WasmRef(v) => v.write_xdr(w)?, + Self::Token => ().write_xdr(w)?, }; Ok(()) } } -// ScObjectType is an XDR Enum defines as: +// ScAddressType is an XDR Enum defines as: // -// enum SCObjectType +// enum SCAddressType // { -// // We have a few objects that represent non-stellar-specific concepts -// // like general-purpose maps, vectors, numbers, blobs. -// -// SCO_VEC = 0, -// SCO_MAP = 1, -// SCO_U64 = 2, -// SCO_I64 = 3, -// SCO_U128 = 4, -// SCO_I128 = 5, -// SCO_BYTES = 6, -// SCO_CONTRACT_CODE = 7, -// SCO_ADDRESS = 8, -// SCO_NONCE_KEY = 9 -// -// // TODO: add more +// SC_ADDRESS_TYPE_ACCOUNT = 0, +// SC_ADDRESS_TYPE_CONTRACT = 1 // }; // // enum @@ -6621,103 +6712,57 @@ impl WriteXdr for ScVal { serde(rename_all = "snake_case") )] #[repr(i32)] -pub enum ScObjectType { - Vec = 0, - Map = 1, - U64 = 2, - I64 = 3, - U128 = 4, - I128 = 5, - Bytes = 6, - ContractCode = 7, - Address = 8, - NonceKey = 9, -} - -impl ScObjectType { - pub const VARIANTS: [ScObjectType; 10] = [ - ScObjectType::Vec, - ScObjectType::Map, - ScObjectType::U64, - ScObjectType::I64, - ScObjectType::U128, - ScObjectType::I128, - ScObjectType::Bytes, - ScObjectType::ContractCode, - ScObjectType::Address, - ScObjectType::NonceKey, - ]; - pub const VARIANTS_STR: [&'static str; 10] = [ - "Vec", - "Map", - "U64", - "I64", - "U128", - "I128", - "Bytes", - "ContractCode", - "Address", - "NonceKey", - ]; +pub enum ScAddressType { + Account = 0, + Contract = 1, +} + +impl ScAddressType { + pub const VARIANTS: [ScAddressType; 2] = [ScAddressType::Account, ScAddressType::Contract]; + pub const VARIANTS_STR: [&'static str; 2] = ["Account", "Contract"]; #[must_use] pub const fn name(&self) -> &'static str { match self { - Self::Vec => "Vec", - Self::Map => "Map", - Self::U64 => "U64", - Self::I64 => "I64", - Self::U128 => "U128", - Self::I128 => "I128", - Self::Bytes => "Bytes", - Self::ContractCode => "ContractCode", - Self::Address => "Address", - Self::NonceKey => "NonceKey", + Self::Account => "Account", + Self::Contract => "Contract", } } #[must_use] - pub const fn variants() -> [ScObjectType; 10] { + pub const fn variants() -> [ScAddressType; 2] { Self::VARIANTS } } -impl Name for ScObjectType { +impl Name for ScAddressType { #[must_use] fn name(&self) -> &'static str { Self::name(self) } } -impl Variants for ScObjectType { - fn variants() -> slice::Iter<'static, ScObjectType> { +impl Variants for ScAddressType { + fn variants() -> slice::Iter<'static, ScAddressType> { Self::VARIANTS.iter() } } -impl Enum for ScObjectType {} +impl Enum for ScAddressType {} -impl fmt::Display for ScObjectType { +impl fmt::Display for ScAddressType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(self.name()) } } -impl TryFrom for ScObjectType { +impl TryFrom for ScAddressType { type Error = Error; fn try_from(i: i32) -> Result { let e = match i { - 0 => ScObjectType::Vec, - 1 => ScObjectType::Map, - 2 => ScObjectType::U64, - 3 => ScObjectType::I64, - 4 => ScObjectType::U128, - 5 => ScObjectType::I128, - 6 => ScObjectType::Bytes, - 7 => ScObjectType::ContractCode, - 8 => ScObjectType::Address, - 9 => ScObjectType::NonceKey, + 0 => ScAddressType::Account, + 1 => ScAddressType::Contract, #[allow(unreachable_patterns)] _ => return Err(Error::Invalid), }; @@ -6725,14 +6770,14 @@ impl TryFrom for ScObjectType { } } -impl From for i32 { +impl From for i32 { #[must_use] - fn from(e: ScObjectType) -> Self { + fn from(e: ScAddressType) -> Self { e as Self } } -impl ReadXdr for ScObjectType { +impl ReadXdr for ScAddressType { #[cfg(feature = "std")] fn read_xdr(r: &mut impl Read) -> Result { let e = i32::read_xdr(r)?; @@ -6741,7 +6786,7 @@ impl ReadXdr for ScObjectType { } } -impl WriteXdr for ScObjectType { +impl WriteXdr for ScAddressType { #[cfg(feature = "std")] fn write_xdr(&self, w: &mut impl Write) -> Result<()> { let i: i32 = (*self).into(); @@ -6749,14 +6794,17 @@ impl WriteXdr for ScObjectType { } } -// ScMapEntry is an XDR Struct defines as: +// ScAddress is an XDR Union defines as: // -// struct SCMapEntry +// union SCAddress switch (SCAddressType type) // { -// SCVal key; -// SCVal val; +// case SC_ADDRESS_TYPE_ACCOUNT: +// AccountID accountId; +// case SC_ADDRESS_TYPE_CONTRACT: +// Hash contractId; // }; // +// union with discriminant ScAddressType #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] #[cfg_attr( @@ -6764,26 +6812,85 @@ impl WriteXdr for ScObjectType { derive(serde::Serialize, serde::Deserialize), serde(rename_all = "snake_case") )] -pub struct ScMapEntry { - pub key: ScVal, - pub val: ScVal, +#[allow(clippy::large_enum_variant)] +pub enum ScAddress { + Account(AccountId), + Contract(Hash), } -impl ReadXdr for ScMapEntry { +impl ScAddress { + pub const VARIANTS: [ScAddressType; 2] = [ScAddressType::Account, ScAddressType::Contract]; + pub const VARIANTS_STR: [&'static str; 2] = ["Account", "Contract"]; + + #[must_use] + pub const fn name(&self) -> &'static str { + match self { + Self::Account(_) => "Account", + Self::Contract(_) => "Contract", + } + } + + #[must_use] + pub const fn discriminant(&self) -> ScAddressType { + #[allow(clippy::match_same_arms)] + match self { + Self::Account(_) => ScAddressType::Account, + Self::Contract(_) => ScAddressType::Contract, + } + } + + #[must_use] + pub const fn variants() -> [ScAddressType; 2] { + Self::VARIANTS + } +} + +impl Name for ScAddress { + #[must_use] + fn name(&self) -> &'static str { + Self::name(self) + } +} + +impl Discriminant for ScAddress { + #[must_use] + fn discriminant(&self) -> ScAddressType { + Self::discriminant(self) + } +} + +impl Variants for ScAddress { + fn variants() -> slice::Iter<'static, ScAddressType> { + Self::VARIANTS.iter() + } +} + +impl Union for ScAddress {} + +impl ReadXdr for ScAddress { #[cfg(feature = "std")] fn read_xdr(r: &mut impl Read) -> Result { - Ok(Self { - key: ScVal::read_xdr(r)?, - val: ScVal::read_xdr(r)?, - }) + let dv: ScAddressType = ::read_xdr(r)?; + #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)] + let v = match dv { + ScAddressType::Account => Self::Account(AccountId::read_xdr(r)?), + ScAddressType::Contract => Self::Contract(Hash::read_xdr(r)?), + #[allow(unreachable_patterns)] + _ => return Err(Error::Invalid), + }; + Ok(v) } } -impl WriteXdr for ScMapEntry { +impl WriteXdr for ScAddress { #[cfg(feature = "std")] fn write_xdr(&self, w: &mut impl Write) -> Result<()> { - self.key.write_xdr(w)?; - self.val.write_xdr(w)?; + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Account(v) => v.write_xdr(w)?, + Self::Contract(v) => v.write_xdr(w)?, + }; Ok(()) } } @@ -6794,6 +6901,12 @@ impl WriteXdr for ScMapEntry { // pub const SCVAL_LIMIT: u64 = 256000; +// ScsymbolLimit is an XDR Const defines as: +// +// const SCSYMBOL_LIMIT = 32; +// +pub const SCSYMBOL_LIMIT: u64 = 32; + // ScVec is an XDR Typedef defines as: // // typedef SCVal SCVec; @@ -6994,476 +7107,404 @@ impl AsRef<[ScMapEntry]> for ScMap { } } -// ScContractCodeType is an XDR Enum defines as: +// ScBytes is an XDR Typedef defines as: // -// enum SCContractCodeType -// { -// SCCONTRACT_CODE_WASM_REF = 0, -// SCCONTRACT_CODE_TOKEN = 1 -// }; +// typedef opaque SCBytes; // -// enum -#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[derive(Default, Debug)] #[cfg_attr( all(feature = "serde", feature = "alloc"), derive(serde::Serialize, serde::Deserialize), serde(rename_all = "snake_case") )] -#[repr(i32)] -pub enum ScContractCodeType { - WasmRef = 0, - Token = 1, -} - -impl ScContractCodeType { - pub const VARIANTS: [ScContractCodeType; 2] = - [ScContractCodeType::WasmRef, ScContractCodeType::Token]; - pub const VARIANTS_STR: [&'static str; 2] = ["WasmRef", "Token"]; +pub struct ScBytes(pub BytesM<256000>); +impl From for BytesM<256000> { #[must_use] - pub const fn name(&self) -> &'static str { - match self { - Self::WasmRef => "WasmRef", - Self::Token => "Token", - } + fn from(x: ScBytes) -> Self { + x.0 } +} +impl From> for ScBytes { #[must_use] - pub const fn variants() -> [ScContractCodeType; 2] { - Self::VARIANTS + fn from(x: BytesM<256000>) -> Self { + ScBytes(x) } } -impl Name for ScContractCodeType { +impl AsRef> for ScBytes { #[must_use] - fn name(&self) -> &'static str { - Self::name(self) + fn as_ref(&self) -> &BytesM<256000> { + &self.0 } } -impl Variants for ScContractCodeType { - fn variants() -> slice::Iter<'static, ScContractCodeType> { - Self::VARIANTS.iter() +impl ReadXdr for ScBytes { + #[cfg(feature = "std")] + fn read_xdr(r: &mut impl Read) -> Result { + let i = BytesM::<256000>::read_xdr(r)?; + let v = ScBytes(i); + Ok(v) } } -impl Enum for ScContractCodeType {} +impl WriteXdr for ScBytes { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut impl Write) -> Result<()> { + self.0.write_xdr(w) + } +} -impl fmt::Display for ScContractCodeType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(self.name()) +impl Deref for ScBytes { + type Target = BytesM<256000>; + fn deref(&self) -> &Self::Target { + &self.0 } } -impl TryFrom for ScContractCodeType { - type Error = Error; +impl From for Vec { + #[must_use] + fn from(x: ScBytes) -> Self { + x.0 .0 + } +} - fn try_from(i: i32) -> Result { - let e = match i { - 0 => ScContractCodeType::WasmRef, - 1 => ScContractCodeType::Token, - #[allow(unreachable_patterns)] - _ => return Err(Error::Invalid), - }; - Ok(e) +impl TryFrom> for ScBytes { + type Error = Error; + fn try_from(x: Vec) -> Result { + Ok(ScBytes(x.try_into()?)) } } -impl From for i32 { - #[must_use] - fn from(e: ScContractCodeType) -> Self { - e as Self +#[cfg(feature = "alloc")] +impl TryFrom<&Vec> for ScBytes { + type Error = Error; + fn try_from(x: &Vec) -> Result { + Ok(ScBytes(x.try_into()?)) } } -impl ReadXdr for ScContractCodeType { - #[cfg(feature = "std")] - fn read_xdr(r: &mut impl Read) -> Result { - let e = i32::read_xdr(r)?; - let v: Self = e.try_into()?; - Ok(v) +impl AsRef> for ScBytes { + #[must_use] + fn as_ref(&self) -> &Vec { + &self.0 .0 } } -impl WriteXdr for ScContractCodeType { - #[cfg(feature = "std")] - fn write_xdr(&self, w: &mut impl Write) -> Result<()> { - let i: i32 = (*self).into(); - i.write_xdr(w) +impl AsRef<[u8]> for ScBytes { + #[cfg(feature = "alloc")] + #[must_use] + fn as_ref(&self) -> &[u8] { + &self.0 .0 + } + #[cfg(not(feature = "alloc"))] + #[must_use] + fn as_ref(&self) -> &[u8] { + self.0 .0 } } -// ScContractCode is an XDR Union defines as: +// ScString is an XDR Typedef defines as: // -// union SCContractCode switch (SCContractCodeType type) -// { -// case SCCONTRACT_CODE_WASM_REF: -// Hash wasm_id; -// case SCCONTRACT_CODE_TOKEN: -// void; -// }; +// typedef string SCString; // -// union with discriminant ScContractCodeType -#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[derive(Default, Debug)] #[cfg_attr( all(feature = "serde", feature = "alloc"), derive(serde::Serialize, serde::Deserialize), serde(rename_all = "snake_case") )] -#[allow(clippy::large_enum_variant)] -pub enum ScContractCode { - WasmRef(Hash), - Token, -} - -impl ScContractCode { - pub const VARIANTS: [ScContractCodeType; 2] = - [ScContractCodeType::WasmRef, ScContractCodeType::Token]; - pub const VARIANTS_STR: [&'static str; 2] = ["WasmRef", "Token"]; +pub struct ScString(pub StringM<256000>); +impl From for StringM<256000> { #[must_use] - pub const fn name(&self) -> &'static str { - match self { - Self::WasmRef(_) => "WasmRef", - Self::Token => "Token", - } + fn from(x: ScString) -> Self { + x.0 } +} +impl From> for ScString { #[must_use] - pub const fn discriminant(&self) -> ScContractCodeType { - #[allow(clippy::match_same_arms)] - match self { - Self::WasmRef(_) => ScContractCodeType::WasmRef, - Self::Token => ScContractCodeType::Token, - } + fn from(x: StringM<256000>) -> Self { + ScString(x) } +} +impl AsRef> for ScString { #[must_use] - pub const fn variants() -> [ScContractCodeType; 2] { - Self::VARIANTS + fn as_ref(&self) -> &StringM<256000> { + &self.0 } } -impl Name for ScContractCode { - #[must_use] - fn name(&self) -> &'static str { - Self::name(self) +impl ReadXdr for ScString { + #[cfg(feature = "std")] + fn read_xdr(r: &mut impl Read) -> Result { + let i = StringM::<256000>::read_xdr(r)?; + let v = ScString(i); + Ok(v) } } -impl Discriminant for ScContractCode { - #[must_use] - fn discriminant(&self) -> ScContractCodeType { - Self::discriminant(self) +impl WriteXdr for ScString { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut impl Write) -> Result<()> { + self.0.write_xdr(w) } } -impl Variants for ScContractCode { - fn variants() -> slice::Iter<'static, ScContractCodeType> { - Self::VARIANTS.iter() +impl Deref for ScString { + type Target = StringM<256000>; + fn deref(&self) -> &Self::Target { + &self.0 } } -impl Union for ScContractCode {} - -impl ReadXdr for ScContractCode { - #[cfg(feature = "std")] - fn read_xdr(r: &mut impl Read) -> Result { - let dv: ScContractCodeType = ::read_xdr(r)?; - #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)] - let v = match dv { - ScContractCodeType::WasmRef => Self::WasmRef(Hash::read_xdr(r)?), - ScContractCodeType::Token => Self::Token, - #[allow(unreachable_patterns)] - _ => return Err(Error::Invalid), - }; - Ok(v) +impl From for Vec { + #[must_use] + fn from(x: ScString) -> Self { + x.0 .0 } } -impl WriteXdr for ScContractCode { - #[cfg(feature = "std")] - fn write_xdr(&self, w: &mut impl Write) -> Result<()> { - self.discriminant().write_xdr(w)?; - #[allow(clippy::match_same_arms)] - match self { - Self::WasmRef(v) => v.write_xdr(w)?, - Self::Token => ().write_xdr(w)?, - }; - Ok(()) +impl TryFrom> for ScString { + type Error = Error; + fn try_from(x: Vec) -> Result { + Ok(ScString(x.try_into()?)) } } -// Int128Parts is an XDR Struct defines as: -// -// struct Int128Parts { -// // Both signed and unsigned 128-bit ints -// // are transported in a pair of uint64s -// // to reduce the risk of sign-extension. -// uint64 lo; -// uint64 hi; -// }; -// -#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] -#[cfg_attr( - all(feature = "serde", feature = "alloc"), - derive(serde::Serialize, serde::Deserialize), - serde(rename_all = "snake_case") -)] -pub struct Int128Parts { - pub lo: u64, - pub hi: u64, +#[cfg(feature = "alloc")] +impl TryFrom<&Vec> for ScString { + type Error = Error; + fn try_from(x: &Vec) -> Result { + Ok(ScString(x.try_into()?)) + } } -impl ReadXdr for Int128Parts { - #[cfg(feature = "std")] - fn read_xdr(r: &mut impl Read) -> Result { - Ok(Self { - lo: u64::read_xdr(r)?, - hi: u64::read_xdr(r)?, - }) +impl AsRef> for ScString { + #[must_use] + fn as_ref(&self) -> &Vec { + &self.0 .0 } } -impl WriteXdr for Int128Parts { - #[cfg(feature = "std")] - fn write_xdr(&self, w: &mut impl Write) -> Result<()> { - self.lo.write_xdr(w)?; - self.hi.write_xdr(w)?; - Ok(()) +impl AsRef<[u8]> for ScString { + #[cfg(feature = "alloc")] + #[must_use] + fn as_ref(&self) -> &[u8] { + &self.0 .0 + } + #[cfg(not(feature = "alloc"))] + #[must_use] + fn as_ref(&self) -> &[u8] { + self.0 .0 } } -// ScAddressType is an XDR Enum defines as: +// ScSymbol is an XDR Typedef defines as: // -// enum SCAddressType -// { -// SC_ADDRESS_TYPE_ACCOUNT = 0, -// SC_ADDRESS_TYPE_CONTRACT = 1 -// }; +// typedef string SCSymbol; // -// enum -#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[derive(Default, Debug)] #[cfg_attr( all(feature = "serde", feature = "alloc"), derive(serde::Serialize, serde::Deserialize), serde(rename_all = "snake_case") )] -#[repr(i32)] -pub enum ScAddressType { - Account = 0, - Contract = 1, -} - -impl ScAddressType { - pub const VARIANTS: [ScAddressType; 2] = [ScAddressType::Account, ScAddressType::Contract]; - pub const VARIANTS_STR: [&'static str; 2] = ["Account", "Contract"]; +pub struct ScSymbol(pub StringM<32>); +impl From for StringM<32> { #[must_use] - pub const fn name(&self) -> &'static str { - match self { - Self::Account => "Account", - Self::Contract => "Contract", - } - } - - #[must_use] - pub const fn variants() -> [ScAddressType; 2] { - Self::VARIANTS + fn from(x: ScSymbol) -> Self { + x.0 } } -impl Name for ScAddressType { +impl From> for ScSymbol { #[must_use] - fn name(&self) -> &'static str { - Self::name(self) - } -} - -impl Variants for ScAddressType { - fn variants() -> slice::Iter<'static, ScAddressType> { - Self::VARIANTS.iter() - } -} - -impl Enum for ScAddressType {} - -impl fmt::Display for ScAddressType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(self.name()) - } -} - -impl TryFrom for ScAddressType { - type Error = Error; - - fn try_from(i: i32) -> Result { - let e = match i { - 0 => ScAddressType::Account, - 1 => ScAddressType::Contract, - #[allow(unreachable_patterns)] - _ => return Err(Error::Invalid), - }; - Ok(e) + fn from(x: StringM<32>) -> Self { + ScSymbol(x) } } -impl From for i32 { +impl AsRef> for ScSymbol { #[must_use] - fn from(e: ScAddressType) -> Self { - e as Self + fn as_ref(&self) -> &StringM<32> { + &self.0 } } -impl ReadXdr for ScAddressType { +impl ReadXdr for ScSymbol { #[cfg(feature = "std")] fn read_xdr(r: &mut impl Read) -> Result { - let e = i32::read_xdr(r)?; - let v: Self = e.try_into()?; + let i = StringM::<32>::read_xdr(r)?; + let v = ScSymbol(i); Ok(v) } } -impl WriteXdr for ScAddressType { +impl WriteXdr for ScSymbol { #[cfg(feature = "std")] fn write_xdr(&self, w: &mut impl Write) -> Result<()> { - let i: i32 = (*self).into(); - i.write_xdr(w) + self.0.write_xdr(w) } } -// ScAddress is an XDR Union defines as: -// -// union SCAddress switch (SCAddressType type) -// { -// case SC_ADDRESS_TYPE_ACCOUNT: -// AccountID accountId; -// case SC_ADDRESS_TYPE_CONTRACT: -// Hash contractId; -// }; -// -// union with discriminant ScAddressType -#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] -#[cfg_attr( - all(feature = "serde", feature = "alloc"), - derive(serde::Serialize, serde::Deserialize), - serde(rename_all = "snake_case") -)] -#[allow(clippy::large_enum_variant)] -pub enum ScAddress { - Account(AccountId), - Contract(Hash), +impl Deref for ScSymbol { + type Target = StringM<32>; + fn deref(&self) -> &Self::Target { + &self.0 + } } -impl ScAddress { - pub const VARIANTS: [ScAddressType; 2] = [ScAddressType::Account, ScAddressType::Contract]; - pub const VARIANTS_STR: [&'static str; 2] = ["Account", "Contract"]; - +impl From for Vec { #[must_use] - pub const fn name(&self) -> &'static str { - match self { - Self::Account(_) => "Account", - Self::Contract(_) => "Contract", - } + fn from(x: ScSymbol) -> Self { + x.0 .0 } +} - #[must_use] - pub const fn discriminant(&self) -> ScAddressType { - #[allow(clippy::match_same_arms)] - match self { - Self::Account(_) => ScAddressType::Account, - Self::Contract(_) => ScAddressType::Contract, - } +impl TryFrom> for ScSymbol { + type Error = Error; + fn try_from(x: Vec) -> Result { + Ok(ScSymbol(x.try_into()?)) } +} - #[must_use] - pub const fn variants() -> [ScAddressType; 2] { - Self::VARIANTS +#[cfg(feature = "alloc")] +impl TryFrom<&Vec> for ScSymbol { + type Error = Error; + fn try_from(x: &Vec) -> Result { + Ok(ScSymbol(x.try_into()?)) } } -impl Name for ScAddress { +impl AsRef> for ScSymbol { #[must_use] - fn name(&self) -> &'static str { - Self::name(self) + fn as_ref(&self) -> &Vec { + &self.0 .0 } } -impl Discriminant for ScAddress { +impl AsRef<[u8]> for ScSymbol { + #[cfg(feature = "alloc")] #[must_use] - fn discriminant(&self) -> ScAddressType { - Self::discriminant(self) + fn as_ref(&self) -> &[u8] { + &self.0 .0 } -} - -impl Variants for ScAddress { - fn variants() -> slice::Iter<'static, ScAddressType> { - Self::VARIANTS.iter() + #[cfg(not(feature = "alloc"))] + #[must_use] + fn as_ref(&self) -> &[u8] { + self.0 .0 } } -impl Union for ScAddress {} +// ScNonceKey is an XDR Struct defines as: +// +// struct SCNonceKey { +// SCAddress nonce_address; +// }; +// +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr( + all(feature = "serde", feature = "alloc"), + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "snake_case") +)] +pub struct ScNonceKey { + pub nonce_address: ScAddress, +} -impl ReadXdr for ScAddress { +impl ReadXdr for ScNonceKey { #[cfg(feature = "std")] fn read_xdr(r: &mut impl Read) -> Result { - let dv: ScAddressType = ::read_xdr(r)?; - #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)] - let v = match dv { - ScAddressType::Account => Self::Account(AccountId::read_xdr(r)?), - ScAddressType::Contract => Self::Contract(Hash::read_xdr(r)?), - #[allow(unreachable_patterns)] - _ => return Err(Error::Invalid), - }; - Ok(v) + Ok(Self { + nonce_address: ScAddress::read_xdr(r)?, + }) } } -impl WriteXdr for ScAddress { +impl WriteXdr for ScNonceKey { #[cfg(feature = "std")] fn write_xdr(&self, w: &mut impl Write) -> Result<()> { - self.discriminant().write_xdr(w)?; - #[allow(clippy::match_same_arms)] - match self { - Self::Account(v) => v.write_xdr(w)?, - Self::Contract(v) => v.write_xdr(w)?, - }; + self.nonce_address.write_xdr(w)?; Ok(()) } } -// ScObject is an XDR Union defines as: +// ScVal is an XDR Union defines as: // -// union SCObject switch (SCObjectType type) +// union SCVal switch (SCValType type) // { -// case SCO_VEC: -// SCVec vec; -// case SCO_MAP: -// SCMap map; -// case SCO_U64: +// +// case SCV_BOOL: +// bool b; +// case SCV_VOID: +// void; +// case SCV_STATUS: +// SCStatus error; +// +// case SCV_U32: +// uint32 u32; +// case SCV_I32: +// int32 i32; +// +// case SCV_U64: // uint64 u64; -// case SCO_I64: +// case SCV_I64: // int64 i64; -// case SCO_U128: +// case SCV_TIMEPOINT: +// TimePoint timepoint; +// case SCV_DURATION: +// Duration duration; +// +// case SCV_U128: // Int128Parts u128; -// case SCO_I128: +// case SCV_I128: // Int128Parts i128; -// case SCO_BYTES: -// opaque bin; -// case SCO_CONTRACT_CODE: -// SCContractCode contractCode; -// case SCO_ADDRESS: +// +// case SCV_U256: +// uint256 u256; +// case SCV_I256: +// uint256 i256; +// +// case SCV_BYTES: +// SCBytes bytes; +// case SCV_STRING: +// SCString str; +// case SCV_SYMBOL: +// SCSymbol sym; +// +// // Vec and Map are recursive so need to live +// // behind an option, due to xdrpp limitations. +// case SCV_VEC: +// SCVec *vec; +// case SCV_MAP: +// SCMap *map; +// +// case SCV_CONTRACT_EXECUTABLE: +// SCContractExecutable exec; +// case SCV_ADDRESS: // SCAddress address; -// case SCO_NONCE_KEY: -// SCAddress nonceAddress; +// +// // Special SCVals reserved for system-constructed contract-data +// // ledger keys, not generally usable elsewhere. +// case SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: +// void; +// case SCV_LEDGER_KEY_NONCE: +// SCNonceKey nonce_key; // }; // -// union with discriminant ScObjectType +// union with discriminant ScValType #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] #[cfg_attr( @@ -7472,122 +7513,196 @@ impl WriteXdr for ScAddress { serde(rename_all = "snake_case") )] #[allow(clippy::large_enum_variant)] -pub enum ScObject { - Vec(ScVec), - Map(ScMap), +pub enum ScVal { + Bool(bool), + Void, + Status(ScStatus), + U32(u32), + I32(i32), U64(u64), I64(i64), + Timepoint(TimePoint), + Duration(Duration), U128(Int128Parts), I128(Int128Parts), - Bytes(BytesM<256000>), - ContractCode(ScContractCode), + U256(Uint256), + I256(Uint256), + Bytes(ScBytes), + String(ScString), + Symbol(ScSymbol), + Vec(Option), + Map(Option), + ContractExecutable(ScContractExecutable), Address(ScAddress), - NonceKey(ScAddress), -} - -impl ScObject { - pub const VARIANTS: [ScObjectType; 10] = [ - ScObjectType::Vec, - ScObjectType::Map, - ScObjectType::U64, - ScObjectType::I64, - ScObjectType::U128, - ScObjectType::I128, - ScObjectType::Bytes, - ScObjectType::ContractCode, - ScObjectType::Address, - ScObjectType::NonceKey, + LedgerKeyContractExecutable, + LedgerKeyNonce(ScNonceKey), +} + +impl ScVal { + pub const VARIANTS: [ScValType; 22] = [ + ScValType::Bool, + ScValType::Void, + ScValType::Status, + ScValType::U32, + ScValType::I32, + ScValType::U64, + ScValType::I64, + ScValType::Timepoint, + ScValType::Duration, + ScValType::U128, + ScValType::I128, + ScValType::U256, + ScValType::I256, + ScValType::Bytes, + ScValType::String, + ScValType::Symbol, + ScValType::Vec, + ScValType::Map, + ScValType::ContractExecutable, + ScValType::Address, + ScValType::LedgerKeyContractExecutable, + ScValType::LedgerKeyNonce, ]; - pub const VARIANTS_STR: [&'static str; 10] = [ - "Vec", - "Map", + pub const VARIANTS_STR: [&'static str; 22] = [ + "Bool", + "Void", + "Status", + "U32", + "I32", "U64", "I64", + "Timepoint", + "Duration", "U128", "I128", + "U256", + "I256", "Bytes", - "ContractCode", + "String", + "Symbol", + "Vec", + "Map", + "ContractExecutable", "Address", - "NonceKey", + "LedgerKeyContractExecutable", + "LedgerKeyNonce", ]; #[must_use] pub const fn name(&self) -> &'static str { match self { - Self::Vec(_) => "Vec", - Self::Map(_) => "Map", + Self::Bool(_) => "Bool", + Self::Void => "Void", + Self::Status(_) => "Status", + Self::U32(_) => "U32", + Self::I32(_) => "I32", Self::U64(_) => "U64", Self::I64(_) => "I64", + Self::Timepoint(_) => "Timepoint", + Self::Duration(_) => "Duration", Self::U128(_) => "U128", Self::I128(_) => "I128", + Self::U256(_) => "U256", + Self::I256(_) => "I256", Self::Bytes(_) => "Bytes", - Self::ContractCode(_) => "ContractCode", + Self::String(_) => "String", + Self::Symbol(_) => "Symbol", + Self::Vec(_) => "Vec", + Self::Map(_) => "Map", + Self::ContractExecutable(_) => "ContractExecutable", Self::Address(_) => "Address", - Self::NonceKey(_) => "NonceKey", + Self::LedgerKeyContractExecutable => "LedgerKeyContractExecutable", + Self::LedgerKeyNonce(_) => "LedgerKeyNonce", } } #[must_use] - pub const fn discriminant(&self) -> ScObjectType { + pub const fn discriminant(&self) -> ScValType { #[allow(clippy::match_same_arms)] match self { - Self::Vec(_) => ScObjectType::Vec, - Self::Map(_) => ScObjectType::Map, - Self::U64(_) => ScObjectType::U64, - Self::I64(_) => ScObjectType::I64, - Self::U128(_) => ScObjectType::U128, - Self::I128(_) => ScObjectType::I128, - Self::Bytes(_) => ScObjectType::Bytes, - Self::ContractCode(_) => ScObjectType::ContractCode, - Self::Address(_) => ScObjectType::Address, - Self::NonceKey(_) => ScObjectType::NonceKey, + Self::Bool(_) => ScValType::Bool, + Self::Void => ScValType::Void, + Self::Status(_) => ScValType::Status, + Self::U32(_) => ScValType::U32, + Self::I32(_) => ScValType::I32, + Self::U64(_) => ScValType::U64, + Self::I64(_) => ScValType::I64, + Self::Timepoint(_) => ScValType::Timepoint, + Self::Duration(_) => ScValType::Duration, + Self::U128(_) => ScValType::U128, + Self::I128(_) => ScValType::I128, + Self::U256(_) => ScValType::U256, + Self::I256(_) => ScValType::I256, + Self::Bytes(_) => ScValType::Bytes, + Self::String(_) => ScValType::String, + Self::Symbol(_) => ScValType::Symbol, + Self::Vec(_) => ScValType::Vec, + Self::Map(_) => ScValType::Map, + Self::ContractExecutable(_) => ScValType::ContractExecutable, + Self::Address(_) => ScValType::Address, + Self::LedgerKeyContractExecutable => ScValType::LedgerKeyContractExecutable, + Self::LedgerKeyNonce(_) => ScValType::LedgerKeyNonce, } } #[must_use] - pub const fn variants() -> [ScObjectType; 10] { + pub const fn variants() -> [ScValType; 22] { Self::VARIANTS } } -impl Name for ScObject { +impl Name for ScVal { #[must_use] fn name(&self) -> &'static str { Self::name(self) } } -impl Discriminant for ScObject { +impl Discriminant for ScVal { #[must_use] - fn discriminant(&self) -> ScObjectType { + fn discriminant(&self) -> ScValType { Self::discriminant(self) } } -impl Variants for ScObject { - fn variants() -> slice::Iter<'static, ScObjectType> { +impl Variants for ScVal { + fn variants() -> slice::Iter<'static, ScValType> { Self::VARIANTS.iter() } } -impl Union for ScObject {} +impl Union for ScVal {} -impl ReadXdr for ScObject { +impl ReadXdr for ScVal { #[cfg(feature = "std")] fn read_xdr(r: &mut impl Read) -> Result { - let dv: ScObjectType = ::read_xdr(r)?; + let dv: ScValType = ::read_xdr(r)?; #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)] let v = match dv { - ScObjectType::Vec => Self::Vec(ScVec::read_xdr(r)?), - ScObjectType::Map => Self::Map(ScMap::read_xdr(r)?), - ScObjectType::U64 => Self::U64(u64::read_xdr(r)?), - ScObjectType::I64 => Self::I64(i64::read_xdr(r)?), - ScObjectType::U128 => Self::U128(Int128Parts::read_xdr(r)?), - ScObjectType::I128 => Self::I128(Int128Parts::read_xdr(r)?), - ScObjectType::Bytes => Self::Bytes(BytesM::<256000>::read_xdr(r)?), - ScObjectType::ContractCode => Self::ContractCode(ScContractCode::read_xdr(r)?), - ScObjectType::Address => Self::Address(ScAddress::read_xdr(r)?), - ScObjectType::NonceKey => Self::NonceKey(ScAddress::read_xdr(r)?), + ScValType::Bool => Self::Bool(bool::read_xdr(r)?), + ScValType::Void => Self::Void, + ScValType::Status => Self::Status(ScStatus::read_xdr(r)?), + ScValType::U32 => Self::U32(u32::read_xdr(r)?), + ScValType::I32 => Self::I32(i32::read_xdr(r)?), + ScValType::U64 => Self::U64(u64::read_xdr(r)?), + ScValType::I64 => Self::I64(i64::read_xdr(r)?), + ScValType::Timepoint => Self::Timepoint(TimePoint::read_xdr(r)?), + ScValType::Duration => Self::Duration(Duration::read_xdr(r)?), + ScValType::U128 => Self::U128(Int128Parts::read_xdr(r)?), + ScValType::I128 => Self::I128(Int128Parts::read_xdr(r)?), + ScValType::U256 => Self::U256(Uint256::read_xdr(r)?), + ScValType::I256 => Self::I256(Uint256::read_xdr(r)?), + ScValType::Bytes => Self::Bytes(ScBytes::read_xdr(r)?), + ScValType::String => Self::String(ScString::read_xdr(r)?), + ScValType::Symbol => Self::Symbol(ScSymbol::read_xdr(r)?), + ScValType::Vec => Self::Vec(Option::::read_xdr(r)?), + ScValType::Map => Self::Map(Option::::read_xdr(r)?), + ScValType::ContractExecutable => { + Self::ContractExecutable(ScContractExecutable::read_xdr(r)?) + } + ScValType::Address => Self::Address(ScAddress::read_xdr(r)?), + ScValType::LedgerKeyContractExecutable => Self::LedgerKeyContractExecutable, + ScValType::LedgerKeyNonce => Self::LedgerKeyNonce(ScNonceKey::read_xdr(r)?), #[allow(unreachable_patterns)] _ => return Err(Error::Invalid), }; @@ -7595,27 +7710,78 @@ impl ReadXdr for ScObject { } } -impl WriteXdr for ScObject { +impl WriteXdr for ScVal { #[cfg(feature = "std")] fn write_xdr(&self, w: &mut impl Write) -> Result<()> { self.discriminant().write_xdr(w)?; #[allow(clippy::match_same_arms)] match self { - Self::Vec(v) => v.write_xdr(w)?, - Self::Map(v) => v.write_xdr(w)?, + Self::Bool(v) => v.write_xdr(w)?, + Self::Void => ().write_xdr(w)?, + Self::Status(v) => v.write_xdr(w)?, + Self::U32(v) => v.write_xdr(w)?, + Self::I32(v) => v.write_xdr(w)?, Self::U64(v) => v.write_xdr(w)?, Self::I64(v) => v.write_xdr(w)?, + Self::Timepoint(v) => v.write_xdr(w)?, + Self::Duration(v) => v.write_xdr(w)?, Self::U128(v) => v.write_xdr(w)?, Self::I128(v) => v.write_xdr(w)?, + Self::U256(v) => v.write_xdr(w)?, + Self::I256(v) => v.write_xdr(w)?, Self::Bytes(v) => v.write_xdr(w)?, - Self::ContractCode(v) => v.write_xdr(w)?, + Self::String(v) => v.write_xdr(w)?, + Self::Symbol(v) => v.write_xdr(w)?, + Self::Vec(v) => v.write_xdr(w)?, + Self::Map(v) => v.write_xdr(w)?, + Self::ContractExecutable(v) => v.write_xdr(w)?, Self::Address(v) => v.write_xdr(w)?, - Self::NonceKey(v) => v.write_xdr(w)?, + Self::LedgerKeyContractExecutable => ().write_xdr(w)?, + Self::LedgerKeyNonce(v) => v.write_xdr(w)?, }; Ok(()) } } +// ScMapEntry is an XDR Struct defines as: +// +// struct SCMapEntry +// { +// SCVal key; +// SCVal val; +// }; +// +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr( + all(feature = "serde", feature = "alloc"), + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "snake_case") +)] +pub struct ScMapEntry { + pub key: ScVal, + pub val: ScVal, +} + +impl ReadXdr for ScMapEntry { + #[cfg(feature = "std")] + fn read_xdr(r: &mut impl Read) -> Result { + Ok(Self { + key: ScVal::read_xdr(r)?, + val: ScVal::read_xdr(r)?, + }) + } +} + +impl WriteXdr for ScMapEntry { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut impl Write) -> Result<()> { + self.key.write_xdr(w)?; + self.val.write_xdr(w)?; + Ok(()) + } +} + // StoredTransactionSet is an XDR Union defines as: // // union StoredTransactionSet switch (int v) @@ -8267,108 +8433,6 @@ impl WriteXdr for SequenceNumber { } } -// TimePoint is an XDR Typedef defines as: -// -// typedef uint64 TimePoint; -// -#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] -#[derive(Debug)] -#[cfg_attr( - all(feature = "serde", feature = "alloc"), - derive(serde::Serialize, serde::Deserialize), - serde(rename_all = "snake_case") -)] -pub struct TimePoint(pub u64); - -impl From for u64 { - #[must_use] - fn from(x: TimePoint) -> Self { - x.0 - } -} - -impl From for TimePoint { - #[must_use] - fn from(x: u64) -> Self { - TimePoint(x) - } -} - -impl AsRef for TimePoint { - #[must_use] - fn as_ref(&self) -> &u64 { - &self.0 - } -} - -impl ReadXdr for TimePoint { - #[cfg(feature = "std")] - fn read_xdr(r: &mut impl Read) -> Result { - let i = u64::read_xdr(r)?; - let v = TimePoint(i); - Ok(v) - } -} - -impl WriteXdr for TimePoint { - #[cfg(feature = "std")] - fn write_xdr(&self, w: &mut impl Write) -> Result<()> { - self.0.write_xdr(w) - } -} - -// Duration is an XDR Typedef defines as: -// -// typedef uint64 Duration; -// -#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] -#[derive(Debug)] -#[cfg_attr( - all(feature = "serde", feature = "alloc"), - derive(serde::Serialize, serde::Deserialize), - serde(rename_all = "snake_case") -)] -pub struct Duration(pub u64); - -impl From for u64 { - #[must_use] - fn from(x: Duration) -> Self { - x.0 - } -} - -impl From for Duration { - #[must_use] - fn from(x: u64) -> Self { - Duration(x) - } -} - -impl AsRef for Duration { - #[must_use] - fn as_ref(&self) -> &u64 { - &self.0 - } -} - -impl ReadXdr for Duration { - #[cfg(feature = "std")] - fn read_xdr(r: &mut impl Read) -> Result { - let i = u64::read_xdr(r)?; - let v = Duration(i); - Ok(v) - } -} - -impl WriteXdr for Duration { - #[cfg(feature = "std")] - fn write_xdr(&self, w: &mut impl Write) -> Result<()> { - self.0.write_xdr(w) - } -} - // DataValue is an XDR Typedef defines as: // // typedef opaque DataValue<64>; @@ -23797,7 +23861,7 @@ impl WriteXdr for ContractId { // struct CreateContractArgs // { // ContractID contractID; -// SCContractCode source; +// SCContractExecutable source; // }; // #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] @@ -23809,7 +23873,7 @@ impl WriteXdr for ContractId { )] pub struct CreateContractArgs { pub contract_id: ContractId, - pub source: ScContractCode, + pub source: ScContractExecutable, } impl ReadXdr for CreateContractArgs { @@ -23817,7 +23881,7 @@ impl ReadXdr for CreateContractArgs { fn read_xdr(r: &mut impl Read) -> Result { Ok(Self { contract_id: ContractId::read_xdr(r)?, - source: ScContractCode::read_xdr(r)?, + source: ScContractExecutable::read_xdr(r)?, }) } } @@ -24827,7 +24891,7 @@ impl WriteXdr for HashIdPreimageSourceAccountContractId { // struct // { // Hash networkID; -// SCContractCode source; +// SCContractExecutable source; // uint256 salt; // } // @@ -24840,7 +24904,7 @@ impl WriteXdr for HashIdPreimageSourceAccountContractId { )] pub struct HashIdPreimageCreateContractArgs { pub network_id: Hash, - pub source: ScContractCode, + pub source: ScContractExecutable, pub salt: Uint256, } @@ -24849,7 +24913,7 @@ impl ReadXdr for HashIdPreimageCreateContractArgs { fn read_xdr(r: &mut impl Read) -> Result { Ok(Self { network_id: Hash::read_xdr(r)?, - source: ScContractCode::read_xdr(r)?, + source: ScContractExecutable::read_xdr(r)?, salt: Uint256::read_xdr(r)?, }) } @@ -24959,7 +25023,7 @@ impl WriteXdr for HashIdPreimageContractAuth { // struct // { // Hash networkID; -// SCContractCode source; +// SCContractExecutable source; // uint256 salt; // } createContractArgs; // case ENVELOPE_TYPE_CONTRACT_AUTH: @@ -36368,6 +36432,108 @@ pub type Uint64 = u64; // pub type Int64 = i64; +// TimePoint is an XDR Typedef defines as: +// +// typedef uint64 TimePoint; +// +#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[derive(Debug)] +#[cfg_attr( + all(feature = "serde", feature = "alloc"), + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "snake_case") +)] +pub struct TimePoint(pub u64); + +impl From for u64 { + #[must_use] + fn from(x: TimePoint) -> Self { + x.0 + } +} + +impl From for TimePoint { + #[must_use] + fn from(x: u64) -> Self { + TimePoint(x) + } +} + +impl AsRef for TimePoint { + #[must_use] + fn as_ref(&self) -> &u64 { + &self.0 + } +} + +impl ReadXdr for TimePoint { + #[cfg(feature = "std")] + fn read_xdr(r: &mut impl Read) -> Result { + let i = u64::read_xdr(r)?; + let v = TimePoint(i); + Ok(v) + } +} + +impl WriteXdr for TimePoint { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut impl Write) -> Result<()> { + self.0.write_xdr(w) + } +} + +// Duration is an XDR Typedef defines as: +// +// typedef uint64 Duration; +// +#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[derive(Debug)] +#[cfg_attr( + all(feature = "serde", feature = "alloc"), + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "snake_case") +)] +pub struct Duration(pub u64); + +impl From for u64 { + #[must_use] + fn from(x: Duration) -> Self { + x.0 + } +} + +impl From for Duration { + #[must_use] + fn from(x: u64) -> Self { + Duration(x) + } +} + +impl AsRef for Duration { + #[must_use] + fn as_ref(&self) -> &u64 { + &self.0 + } +} + +impl ReadXdr for Duration { + #[cfg(feature = "std")] + fn read_xdr(r: &mut impl Read) -> Result { + let i = u64::read_xdr(r)?; + let v = Duration(i); + Ok(v) + } +} + +impl WriteXdr for Duration { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut impl Write) -> Result<()> { + self.0.write_xdr(w) + } +} + // ExtensionPoint is an XDR Union defines as: // // union ExtensionPoint switch (int v) @@ -37565,9 +37731,7 @@ pub enum TypeVariant { ScSpecFunctionV0, ScSpecEntryKind, ScSpecEntry, - ScSymbol, ScValType, - ScStatic, ScStatusType, ScHostValErrorCode, ScHostObjErrorCode, @@ -37578,17 +37742,19 @@ pub enum TypeVariant { ScVmErrorCode, ScUnknownErrorCode, ScStatus, - ScVal, - ScObjectType, - ScMapEntry, - ScVec, - ScMap, - ScContractCodeType, - ScContractCode, Int128Parts, + ScContractExecutableType, + ScContractExecutable, ScAddressType, ScAddress, - ScObject, + ScVec, + ScMap, + ScBytes, + ScString, + ScSymbol, + ScNonceKey, + ScVal, + ScMapEntry, StoredTransactionSet, PersistedScpStateV0, PersistedScpStateV1, @@ -37597,8 +37763,6 @@ pub enum TypeVariant { String32, String64, SequenceNumber, - TimePoint, - Duration, DataValue, PoolId, AssetCode4, @@ -37914,6 +38078,8 @@ pub enum TypeVariant { Int32, Uint64, Int64, + TimePoint, + Duration, ExtensionPoint, CryptoKeyType, PublicKeyType, @@ -37971,9 +38137,7 @@ impl TypeVariant { TypeVariant::ScSpecFunctionV0, TypeVariant::ScSpecEntryKind, TypeVariant::ScSpecEntry, - TypeVariant::ScSymbol, TypeVariant::ScValType, - TypeVariant::ScStatic, TypeVariant::ScStatusType, TypeVariant::ScHostValErrorCode, TypeVariant::ScHostObjErrorCode, @@ -37984,17 +38148,19 @@ impl TypeVariant { TypeVariant::ScVmErrorCode, TypeVariant::ScUnknownErrorCode, TypeVariant::ScStatus, - TypeVariant::ScVal, - TypeVariant::ScObjectType, - TypeVariant::ScMapEntry, - TypeVariant::ScVec, - TypeVariant::ScMap, - TypeVariant::ScContractCodeType, - TypeVariant::ScContractCode, TypeVariant::Int128Parts, + TypeVariant::ScContractExecutableType, + TypeVariant::ScContractExecutable, TypeVariant::ScAddressType, TypeVariant::ScAddress, - TypeVariant::ScObject, + TypeVariant::ScVec, + TypeVariant::ScMap, + TypeVariant::ScBytes, + TypeVariant::ScString, + TypeVariant::ScSymbol, + TypeVariant::ScNonceKey, + TypeVariant::ScVal, + TypeVariant::ScMapEntry, TypeVariant::StoredTransactionSet, TypeVariant::PersistedScpStateV0, TypeVariant::PersistedScpStateV1, @@ -38003,8 +38169,6 @@ impl TypeVariant { TypeVariant::String32, TypeVariant::String64, TypeVariant::SequenceNumber, - TypeVariant::TimePoint, - TypeVariant::Duration, TypeVariant::DataValue, TypeVariant::PoolId, TypeVariant::AssetCode4, @@ -38320,6 +38484,8 @@ impl TypeVariant { TypeVariant::Int32, TypeVariant::Uint64, TypeVariant::Int64, + TypeVariant::TimePoint, + TypeVariant::Duration, TypeVariant::ExtensionPoint, TypeVariant::CryptoKeyType, TypeVariant::PublicKeyType, @@ -38375,9 +38541,7 @@ impl TypeVariant { "ScSpecFunctionV0", "ScSpecEntryKind", "ScSpecEntry", - "ScSymbol", "ScValType", - "ScStatic", "ScStatusType", "ScHostValErrorCode", "ScHostObjErrorCode", @@ -38388,17 +38552,19 @@ impl TypeVariant { "ScVmErrorCode", "ScUnknownErrorCode", "ScStatus", - "ScVal", - "ScObjectType", - "ScMapEntry", - "ScVec", - "ScMap", - "ScContractCodeType", - "ScContractCode", "Int128Parts", + "ScContractExecutableType", + "ScContractExecutable", "ScAddressType", "ScAddress", - "ScObject", + "ScVec", + "ScMap", + "ScBytes", + "ScString", + "ScSymbol", + "ScNonceKey", + "ScVal", + "ScMapEntry", "StoredTransactionSet", "PersistedScpStateV0", "PersistedScpStateV1", @@ -38407,8 +38573,6 @@ impl TypeVariant { "String32", "String64", "SequenceNumber", - "TimePoint", - "Duration", "DataValue", "PoolId", "AssetCode4", @@ -38724,6 +38888,8 @@ impl TypeVariant { "Int32", "Uint64", "Int64", + "TimePoint", + "Duration", "ExtensionPoint", "CryptoKeyType", "PublicKeyType", @@ -38783,9 +38949,7 @@ impl TypeVariant { Self::ScSpecFunctionV0 => "ScSpecFunctionV0", Self::ScSpecEntryKind => "ScSpecEntryKind", Self::ScSpecEntry => "ScSpecEntry", - Self::ScSymbol => "ScSymbol", Self::ScValType => "ScValType", - Self::ScStatic => "ScStatic", Self::ScStatusType => "ScStatusType", Self::ScHostValErrorCode => "ScHostValErrorCode", Self::ScHostObjErrorCode => "ScHostObjErrorCode", @@ -38796,17 +38960,19 @@ impl TypeVariant { Self::ScVmErrorCode => "ScVmErrorCode", Self::ScUnknownErrorCode => "ScUnknownErrorCode", Self::ScStatus => "ScStatus", - Self::ScVal => "ScVal", - Self::ScObjectType => "ScObjectType", - Self::ScMapEntry => "ScMapEntry", - Self::ScVec => "ScVec", - Self::ScMap => "ScMap", - Self::ScContractCodeType => "ScContractCodeType", - Self::ScContractCode => "ScContractCode", Self::Int128Parts => "Int128Parts", + Self::ScContractExecutableType => "ScContractExecutableType", + Self::ScContractExecutable => "ScContractExecutable", Self::ScAddressType => "ScAddressType", Self::ScAddress => "ScAddress", - Self::ScObject => "ScObject", + Self::ScVec => "ScVec", + Self::ScMap => "ScMap", + Self::ScBytes => "ScBytes", + Self::ScString => "ScString", + Self::ScSymbol => "ScSymbol", + Self::ScNonceKey => "ScNonceKey", + Self::ScVal => "ScVal", + Self::ScMapEntry => "ScMapEntry", Self::StoredTransactionSet => "StoredTransactionSet", Self::PersistedScpStateV0 => "PersistedScpStateV0", Self::PersistedScpStateV1 => "PersistedScpStateV1", @@ -38815,8 +38981,6 @@ impl TypeVariant { Self::String32 => "String32", Self::String64 => "String64", Self::SequenceNumber => "SequenceNumber", - Self::TimePoint => "TimePoint", - Self::Duration => "Duration", Self::DataValue => "DataValue", Self::PoolId => "PoolId", Self::AssetCode4 => "AssetCode4", @@ -39138,6 +39302,8 @@ impl TypeVariant { Self::Int32 => "Int32", Self::Uint64 => "Uint64", Self::Int64 => "Int64", + Self::TimePoint => "TimePoint", + Self::Duration => "Duration", Self::ExtensionPoint => "ExtensionPoint", Self::CryptoKeyType => "CryptoKeyType", Self::PublicKeyType => "PublicKeyType", @@ -39219,9 +39385,7 @@ impl core::str::FromStr for TypeVariant { "ScSpecFunctionV0" => Ok(Self::ScSpecFunctionV0), "ScSpecEntryKind" => Ok(Self::ScSpecEntryKind), "ScSpecEntry" => Ok(Self::ScSpecEntry), - "ScSymbol" => Ok(Self::ScSymbol), "ScValType" => Ok(Self::ScValType), - "ScStatic" => Ok(Self::ScStatic), "ScStatusType" => Ok(Self::ScStatusType), "ScHostValErrorCode" => Ok(Self::ScHostValErrorCode), "ScHostObjErrorCode" => Ok(Self::ScHostObjErrorCode), @@ -39232,17 +39396,19 @@ impl core::str::FromStr for TypeVariant { "ScVmErrorCode" => Ok(Self::ScVmErrorCode), "ScUnknownErrorCode" => Ok(Self::ScUnknownErrorCode), "ScStatus" => Ok(Self::ScStatus), - "ScVal" => Ok(Self::ScVal), - "ScObjectType" => Ok(Self::ScObjectType), - "ScMapEntry" => Ok(Self::ScMapEntry), - "ScVec" => Ok(Self::ScVec), - "ScMap" => Ok(Self::ScMap), - "ScContractCodeType" => Ok(Self::ScContractCodeType), - "ScContractCode" => Ok(Self::ScContractCode), "Int128Parts" => Ok(Self::Int128Parts), + "ScContractExecutableType" => Ok(Self::ScContractExecutableType), + "ScContractExecutable" => Ok(Self::ScContractExecutable), "ScAddressType" => Ok(Self::ScAddressType), "ScAddress" => Ok(Self::ScAddress), - "ScObject" => Ok(Self::ScObject), + "ScVec" => Ok(Self::ScVec), + "ScMap" => Ok(Self::ScMap), + "ScBytes" => Ok(Self::ScBytes), + "ScString" => Ok(Self::ScString), + "ScSymbol" => Ok(Self::ScSymbol), + "ScNonceKey" => Ok(Self::ScNonceKey), + "ScVal" => Ok(Self::ScVal), + "ScMapEntry" => Ok(Self::ScMapEntry), "StoredTransactionSet" => Ok(Self::StoredTransactionSet), "PersistedScpStateV0" => Ok(Self::PersistedScpStateV0), "PersistedScpStateV1" => Ok(Self::PersistedScpStateV1), @@ -39251,8 +39417,6 @@ impl core::str::FromStr for TypeVariant { "String32" => Ok(Self::String32), "String64" => Ok(Self::String64), "SequenceNumber" => Ok(Self::SequenceNumber), - "TimePoint" => Ok(Self::TimePoint), - "Duration" => Ok(Self::Duration), "DataValue" => Ok(Self::DataValue), "PoolId" => Ok(Self::PoolId), "AssetCode4" => Ok(Self::AssetCode4), @@ -39580,6 +39744,8 @@ impl core::str::FromStr for TypeVariant { "Int32" => Ok(Self::Int32), "Uint64" => Ok(Self::Uint64), "Int64" => Ok(Self::Int64), + "TimePoint" => Ok(Self::TimePoint), + "Duration" => Ok(Self::Duration), "ExtensionPoint" => Ok(Self::ExtensionPoint), "CryptoKeyType" => Ok(Self::CryptoKeyType), "PublicKeyType" => Ok(Self::PublicKeyType), @@ -39646,9 +39812,7 @@ pub enum Type { ScSpecFunctionV0(Box), ScSpecEntryKind(Box), ScSpecEntry(Box), - ScSymbol(Box), ScValType(Box), - ScStatic(Box), ScStatusType(Box), ScHostValErrorCode(Box), ScHostObjErrorCode(Box), @@ -39659,17 +39823,19 @@ pub enum Type { ScVmErrorCode(Box), ScUnknownErrorCode(Box), ScStatus(Box), - ScVal(Box), - ScObjectType(Box), - ScMapEntry(Box), - ScVec(Box), - ScMap(Box), - ScContractCodeType(Box), - ScContractCode(Box), Int128Parts(Box), + ScContractExecutableType(Box), + ScContractExecutable(Box), ScAddressType(Box), ScAddress(Box), - ScObject(Box), + ScVec(Box), + ScMap(Box), + ScBytes(Box), + ScString(Box), + ScSymbol(Box), + ScNonceKey(Box), + ScVal(Box), + ScMapEntry(Box), StoredTransactionSet(Box), PersistedScpStateV0(Box), PersistedScpStateV1(Box), @@ -39678,8 +39844,6 @@ pub enum Type { String32(Box), String64(Box), SequenceNumber(Box), - TimePoint(Box), - Duration(Box), DataValue(Box), PoolId(Box), AssetCode4(Box), @@ -39995,6 +40159,8 @@ pub enum Type { Int32(Box), Uint64(Box), Int64(Box), + TimePoint(Box), + Duration(Box), ExtensionPoint(Box), CryptoKeyType(Box), PublicKeyType(Box), @@ -40052,9 +40218,7 @@ impl Type { TypeVariant::ScSpecFunctionV0, TypeVariant::ScSpecEntryKind, TypeVariant::ScSpecEntry, - TypeVariant::ScSymbol, TypeVariant::ScValType, - TypeVariant::ScStatic, TypeVariant::ScStatusType, TypeVariant::ScHostValErrorCode, TypeVariant::ScHostObjErrorCode, @@ -40065,17 +40229,19 @@ impl Type { TypeVariant::ScVmErrorCode, TypeVariant::ScUnknownErrorCode, TypeVariant::ScStatus, - TypeVariant::ScVal, - TypeVariant::ScObjectType, - TypeVariant::ScMapEntry, - TypeVariant::ScVec, - TypeVariant::ScMap, - TypeVariant::ScContractCodeType, - TypeVariant::ScContractCode, TypeVariant::Int128Parts, + TypeVariant::ScContractExecutableType, + TypeVariant::ScContractExecutable, TypeVariant::ScAddressType, TypeVariant::ScAddress, - TypeVariant::ScObject, + TypeVariant::ScVec, + TypeVariant::ScMap, + TypeVariant::ScBytes, + TypeVariant::ScString, + TypeVariant::ScSymbol, + TypeVariant::ScNonceKey, + TypeVariant::ScVal, + TypeVariant::ScMapEntry, TypeVariant::StoredTransactionSet, TypeVariant::PersistedScpStateV0, TypeVariant::PersistedScpStateV1, @@ -40084,8 +40250,6 @@ impl Type { TypeVariant::String32, TypeVariant::String64, TypeVariant::SequenceNumber, - TypeVariant::TimePoint, - TypeVariant::Duration, TypeVariant::DataValue, TypeVariant::PoolId, TypeVariant::AssetCode4, @@ -40401,6 +40565,8 @@ impl Type { TypeVariant::Int32, TypeVariant::Uint64, TypeVariant::Int64, + TypeVariant::TimePoint, + TypeVariant::Duration, TypeVariant::ExtensionPoint, TypeVariant::CryptoKeyType, TypeVariant::PublicKeyType, @@ -40456,9 +40622,7 @@ impl Type { "ScSpecFunctionV0", "ScSpecEntryKind", "ScSpecEntry", - "ScSymbol", "ScValType", - "ScStatic", "ScStatusType", "ScHostValErrorCode", "ScHostObjErrorCode", @@ -40469,17 +40633,19 @@ impl Type { "ScVmErrorCode", "ScUnknownErrorCode", "ScStatus", - "ScVal", - "ScObjectType", - "ScMapEntry", - "ScVec", - "ScMap", - "ScContractCodeType", - "ScContractCode", "Int128Parts", + "ScContractExecutableType", + "ScContractExecutable", "ScAddressType", "ScAddress", - "ScObject", + "ScVec", + "ScMap", + "ScBytes", + "ScString", + "ScSymbol", + "ScNonceKey", + "ScVal", + "ScMapEntry", "StoredTransactionSet", "PersistedScpStateV0", "PersistedScpStateV1", @@ -40488,8 +40654,6 @@ impl Type { "String32", "String64", "SequenceNumber", - "TimePoint", - "Duration", "DataValue", "PoolId", "AssetCode4", @@ -40805,6 +40969,8 @@ impl Type { "Int32", "Uint64", "Int64", + "TimePoint", + "Duration", "ExtensionPoint", "CryptoKeyType", "PublicKeyType", @@ -40930,9 +41096,7 @@ impl Type { ScSpecEntryKind::read_xdr(r)?, ))), TypeVariant::ScSpecEntry => Ok(Self::ScSpecEntry(Box::new(ScSpecEntry::read_xdr(r)?))), - TypeVariant::ScSymbol => Ok(Self::ScSymbol(Box::new(ScSymbol::read_xdr(r)?))), TypeVariant::ScValType => Ok(Self::ScValType(Box::new(ScValType::read_xdr(r)?))), - TypeVariant::ScStatic => Ok(Self::ScStatic(Box::new(ScStatic::read_xdr(r)?))), TypeVariant::ScStatusType => { Ok(Self::ScStatusType(Box::new(ScStatusType::read_xdr(r)?))) } @@ -40961,25 +41125,25 @@ impl Type { ScUnknownErrorCode::read_xdr(r)?, ))), TypeVariant::ScStatus => Ok(Self::ScStatus(Box::new(ScStatus::read_xdr(r)?))), - TypeVariant::ScVal => Ok(Self::ScVal(Box::new(ScVal::read_xdr(r)?))), - TypeVariant::ScObjectType => { - Ok(Self::ScObjectType(Box::new(ScObjectType::read_xdr(r)?))) - } - TypeVariant::ScMapEntry => Ok(Self::ScMapEntry(Box::new(ScMapEntry::read_xdr(r)?))), - TypeVariant::ScVec => Ok(Self::ScVec(Box::new(ScVec::read_xdr(r)?))), - TypeVariant::ScMap => Ok(Self::ScMap(Box::new(ScMap::read_xdr(r)?))), - TypeVariant::ScContractCodeType => Ok(Self::ScContractCodeType(Box::new( - ScContractCodeType::read_xdr(r)?, - ))), - TypeVariant::ScContractCode => { - Ok(Self::ScContractCode(Box::new(ScContractCode::read_xdr(r)?))) - } TypeVariant::Int128Parts => Ok(Self::Int128Parts(Box::new(Int128Parts::read_xdr(r)?))), + TypeVariant::ScContractExecutableType => Ok(Self::ScContractExecutableType(Box::new( + ScContractExecutableType::read_xdr(r)?, + ))), + TypeVariant::ScContractExecutable => Ok(Self::ScContractExecutable(Box::new( + ScContractExecutable::read_xdr(r)?, + ))), TypeVariant::ScAddressType => { Ok(Self::ScAddressType(Box::new(ScAddressType::read_xdr(r)?))) } TypeVariant::ScAddress => Ok(Self::ScAddress(Box::new(ScAddress::read_xdr(r)?))), - TypeVariant::ScObject => Ok(Self::ScObject(Box::new(ScObject::read_xdr(r)?))), + TypeVariant::ScVec => Ok(Self::ScVec(Box::new(ScVec::read_xdr(r)?))), + TypeVariant::ScMap => Ok(Self::ScMap(Box::new(ScMap::read_xdr(r)?))), + TypeVariant::ScBytes => Ok(Self::ScBytes(Box::new(ScBytes::read_xdr(r)?))), + TypeVariant::ScString => Ok(Self::ScString(Box::new(ScString::read_xdr(r)?))), + TypeVariant::ScSymbol => Ok(Self::ScSymbol(Box::new(ScSymbol::read_xdr(r)?))), + TypeVariant::ScNonceKey => Ok(Self::ScNonceKey(Box::new(ScNonceKey::read_xdr(r)?))), + TypeVariant::ScVal => Ok(Self::ScVal(Box::new(ScVal::read_xdr(r)?))), + TypeVariant::ScMapEntry => Ok(Self::ScMapEntry(Box::new(ScMapEntry::read_xdr(r)?))), TypeVariant::StoredTransactionSet => Ok(Self::StoredTransactionSet(Box::new( StoredTransactionSet::read_xdr(r)?, ))), @@ -40998,8 +41162,6 @@ impl Type { TypeVariant::SequenceNumber => { Ok(Self::SequenceNumber(Box::new(SequenceNumber::read_xdr(r)?))) } - TypeVariant::TimePoint => Ok(Self::TimePoint(Box::new(TimePoint::read_xdr(r)?))), - TypeVariant::Duration => Ok(Self::Duration(Box::new(Duration::read_xdr(r)?))), TypeVariant::DataValue => Ok(Self::DataValue(Box::new(DataValue::read_xdr(r)?))), TypeVariant::PoolId => Ok(Self::PoolId(Box::new(PoolId::read_xdr(r)?))), TypeVariant::AssetCode4 => Ok(Self::AssetCode4(Box::new(AssetCode4::read_xdr(r)?))), @@ -41907,6 +42069,8 @@ impl Type { TypeVariant::Int32 => Ok(Self::Int32(Box::new(Int32::read_xdr(r)?))), TypeVariant::Uint64 => Ok(Self::Uint64(Box::new(Uint64::read_xdr(r)?))), TypeVariant::Int64 => Ok(Self::Int64(Box::new(Int64::read_xdr(r)?))), + TypeVariant::TimePoint => Ok(Self::TimePoint(Box::new(TimePoint::read_xdr(r)?))), + TypeVariant::Duration => Ok(Self::Duration(Box::new(Duration::read_xdr(r)?))), TypeVariant::ExtensionPoint => { Ok(Self::ExtensionPoint(Box::new(ExtensionPoint::read_xdr(r)?))) } @@ -42129,16 +42293,10 @@ impl Type { ReadXdrIter::<_, ScSpecEntry>::new(r) .map(|r| r.map(|t| Self::ScSpecEntry(Box::new(t)))), ), - TypeVariant::ScSymbol => Box::new( - ReadXdrIter::<_, ScSymbol>::new(r).map(|r| r.map(|t| Self::ScSymbol(Box::new(t)))), - ), TypeVariant::ScValType => Box::new( ReadXdrIter::<_, ScValType>::new(r) .map(|r| r.map(|t| Self::ScValType(Box::new(t)))), ), - TypeVariant::ScStatic => Box::new( - ReadXdrIter::<_, ScStatic>::new(r).map(|r| r.map(|t| Self::ScStatic(Box::new(t)))), - ), TypeVariant::ScStatusType => Box::new( ReadXdrIter::<_, ScStatusType>::new(r) .map(|r| r.map(|t| Self::ScStatusType(Box::new(t)))), @@ -42178,16 +42336,25 @@ impl Type { TypeVariant::ScStatus => Box::new( ReadXdrIter::<_, ScStatus>::new(r).map(|r| r.map(|t| Self::ScStatus(Box::new(t)))), ), - TypeVariant::ScVal => Box::new( - ReadXdrIter::<_, ScVal>::new(r).map(|r| r.map(|t| Self::ScVal(Box::new(t)))), + TypeVariant::Int128Parts => Box::new( + ReadXdrIter::<_, Int128Parts>::new(r) + .map(|r| r.map(|t| Self::Int128Parts(Box::new(t)))), ), - TypeVariant::ScObjectType => Box::new( - ReadXdrIter::<_, ScObjectType>::new(r) - .map(|r| r.map(|t| Self::ScObjectType(Box::new(t)))), + TypeVariant::ScContractExecutableType => Box::new( + ReadXdrIter::<_, ScContractExecutableType>::new(r) + .map(|r| r.map(|t| Self::ScContractExecutableType(Box::new(t)))), ), - TypeVariant::ScMapEntry => Box::new( - ReadXdrIter::<_, ScMapEntry>::new(r) - .map(|r| r.map(|t| Self::ScMapEntry(Box::new(t)))), + TypeVariant::ScContractExecutable => Box::new( + ReadXdrIter::<_, ScContractExecutable>::new(r) + .map(|r| r.map(|t| Self::ScContractExecutable(Box::new(t)))), + ), + TypeVariant::ScAddressType => Box::new( + ReadXdrIter::<_, ScAddressType>::new(r) + .map(|r| r.map(|t| Self::ScAddressType(Box::new(t)))), + ), + TypeVariant::ScAddress => Box::new( + ReadXdrIter::<_, ScAddress>::new(r) + .map(|r| r.map(|t| Self::ScAddress(Box::new(t)))), ), TypeVariant::ScVec => Box::new( ReadXdrIter::<_, ScVec>::new(r).map(|r| r.map(|t| Self::ScVec(Box::new(t)))), @@ -42195,28 +42362,25 @@ impl Type { TypeVariant::ScMap => Box::new( ReadXdrIter::<_, ScMap>::new(r).map(|r| r.map(|t| Self::ScMap(Box::new(t)))), ), - TypeVariant::ScContractCodeType => Box::new( - ReadXdrIter::<_, ScContractCodeType>::new(r) - .map(|r| r.map(|t| Self::ScContractCodeType(Box::new(t)))), + TypeVariant::ScBytes => Box::new( + ReadXdrIter::<_, ScBytes>::new(r).map(|r| r.map(|t| Self::ScBytes(Box::new(t)))), ), - TypeVariant::ScContractCode => Box::new( - ReadXdrIter::<_, ScContractCode>::new(r) - .map(|r| r.map(|t| Self::ScContractCode(Box::new(t)))), + TypeVariant::ScString => Box::new( + ReadXdrIter::<_, ScString>::new(r).map(|r| r.map(|t| Self::ScString(Box::new(t)))), ), - TypeVariant::Int128Parts => Box::new( - ReadXdrIter::<_, Int128Parts>::new(r) - .map(|r| r.map(|t| Self::Int128Parts(Box::new(t)))), + TypeVariant::ScSymbol => Box::new( + ReadXdrIter::<_, ScSymbol>::new(r).map(|r| r.map(|t| Self::ScSymbol(Box::new(t)))), ), - TypeVariant::ScAddressType => Box::new( - ReadXdrIter::<_, ScAddressType>::new(r) - .map(|r| r.map(|t| Self::ScAddressType(Box::new(t)))), + TypeVariant::ScNonceKey => Box::new( + ReadXdrIter::<_, ScNonceKey>::new(r) + .map(|r| r.map(|t| Self::ScNonceKey(Box::new(t)))), ), - TypeVariant::ScAddress => Box::new( - ReadXdrIter::<_, ScAddress>::new(r) - .map(|r| r.map(|t| Self::ScAddress(Box::new(t)))), + TypeVariant::ScVal => Box::new( + ReadXdrIter::<_, ScVal>::new(r).map(|r| r.map(|t| Self::ScVal(Box::new(t)))), ), - TypeVariant::ScObject => Box::new( - ReadXdrIter::<_, ScObject>::new(r).map(|r| r.map(|t| Self::ScObject(Box::new(t)))), + TypeVariant::ScMapEntry => Box::new( + ReadXdrIter::<_, ScMapEntry>::new(r) + .map(|r| r.map(|t| Self::ScMapEntry(Box::new(t)))), ), TypeVariant::StoredTransactionSet => Box::new( ReadXdrIter::<_, StoredTransactionSet>::new(r) @@ -42248,13 +42412,6 @@ impl Type { ReadXdrIter::<_, SequenceNumber>::new(r) .map(|r| r.map(|t| Self::SequenceNumber(Box::new(t)))), ), - TypeVariant::TimePoint => Box::new( - ReadXdrIter::<_, TimePoint>::new(r) - .map(|r| r.map(|t| Self::TimePoint(Box::new(t)))), - ), - TypeVariant::Duration => Box::new( - ReadXdrIter::<_, Duration>::new(r).map(|r| r.map(|t| Self::Duration(Box::new(t)))), - ), TypeVariant::DataValue => Box::new( ReadXdrIter::<_, DataValue>::new(r) .map(|r| r.map(|t| Self::DataValue(Box::new(t)))), @@ -43497,6 +43654,13 @@ impl Type { TypeVariant::Int64 => Box::new( ReadXdrIter::<_, Int64>::new(r).map(|r| r.map(|t| Self::Int64(Box::new(t)))), ), + TypeVariant::TimePoint => Box::new( + ReadXdrIter::<_, TimePoint>::new(r) + .map(|r| r.map(|t| Self::TimePoint(Box::new(t)))), + ), + TypeVariant::Duration => Box::new( + ReadXdrIter::<_, Duration>::new(r).map(|r| r.map(|t| Self::Duration(Box::new(t)))), + ), TypeVariant::ExtensionPoint => Box::new( ReadXdrIter::<_, ExtensionPoint>::new(r) .map(|r| r.map(|t| Self::ExtensionPoint(Box::new(t)))), @@ -43718,18 +43882,10 @@ impl Type { ReadXdrIter::<_, Frame>::new(r) .map(|r| r.map(|t| Self::ScSpecEntry(Box::new(t.0)))), ), - TypeVariant::ScSymbol => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::ScSymbol(Box::new(t.0)))), - ), TypeVariant::ScValType => Box::new( ReadXdrIter::<_, Frame>::new(r) .map(|r| r.map(|t| Self::ScValType(Box::new(t.0)))), ), - TypeVariant::ScStatic => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::ScStatic(Box::new(t.0)))), - ), TypeVariant::ScStatusType => Box::new( ReadXdrIter::<_, Frame>::new(r) .map(|r| r.map(|t| Self::ScStatusType(Box::new(t.0)))), @@ -43770,17 +43926,25 @@ impl Type { ReadXdrIter::<_, Frame>::new(r) .map(|r| r.map(|t| Self::ScStatus(Box::new(t.0)))), ), - TypeVariant::ScVal => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::ScVal(Box::new(t.0)))), + TypeVariant::Int128Parts => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::Int128Parts(Box::new(t.0)))), ), - TypeVariant::ScObjectType => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::ScObjectType(Box::new(t.0)))), + TypeVariant::ScContractExecutableType => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::ScContractExecutableType(Box::new(t.0)))), ), - TypeVariant::ScMapEntry => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::ScMapEntry(Box::new(t.0)))), + TypeVariant::ScContractExecutable => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::ScContractExecutable(Box::new(t.0)))), + ), + TypeVariant::ScAddressType => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::ScAddressType(Box::new(t.0)))), + ), + TypeVariant::ScAddress => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::ScAddress(Box::new(t.0)))), ), TypeVariant::ScVec => Box::new( ReadXdrIter::<_, Frame>::new(r) @@ -43790,29 +43954,29 @@ impl Type { ReadXdrIter::<_, Frame>::new(r) .map(|r| r.map(|t| Self::ScMap(Box::new(t.0)))), ), - TypeVariant::ScContractCodeType => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::ScContractCodeType(Box::new(t.0)))), + TypeVariant::ScBytes => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::ScBytes(Box::new(t.0)))), ), - TypeVariant::ScContractCode => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::ScContractCode(Box::new(t.0)))), + TypeVariant::ScString => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::ScString(Box::new(t.0)))), ), - TypeVariant::Int128Parts => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::Int128Parts(Box::new(t.0)))), + TypeVariant::ScSymbol => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::ScSymbol(Box::new(t.0)))), ), - TypeVariant::ScAddressType => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::ScAddressType(Box::new(t.0)))), + TypeVariant::ScNonceKey => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::ScNonceKey(Box::new(t.0)))), ), - TypeVariant::ScAddress => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::ScAddress(Box::new(t.0)))), + TypeVariant::ScVal => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::ScVal(Box::new(t.0)))), ), - TypeVariant::ScObject => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::ScObject(Box::new(t.0)))), + TypeVariant::ScMapEntry => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::ScMapEntry(Box::new(t.0)))), ), TypeVariant::StoredTransactionSet => Box::new( ReadXdrIter::<_, Frame>::new(r) @@ -43846,14 +44010,6 @@ impl Type { ReadXdrIter::<_, Frame>::new(r) .map(|r| r.map(|t| Self::SequenceNumber(Box::new(t.0)))), ), - TypeVariant::TimePoint => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::TimePoint(Box::new(t.0)))), - ), - TypeVariant::Duration => Box::new( - ReadXdrIter::<_, Frame>::new(r) - .map(|r| r.map(|t| Self::Duration(Box::new(t.0)))), - ), TypeVariant::DataValue => Box::new( ReadXdrIter::<_, Frame>::new(r) .map(|r| r.map(|t| Self::DataValue(Box::new(t.0)))), @@ -45116,6 +45272,14 @@ impl Type { ReadXdrIter::<_, Frame>::new(r) .map(|r| r.map(|t| Self::Int64(Box::new(t.0)))), ), + TypeVariant::TimePoint => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::TimePoint(Box::new(t.0)))), + ), + TypeVariant::Duration => Box::new( + ReadXdrIter::<_, Frame>::new(r) + .map(|r| r.map(|t| Self::Duration(Box::new(t.0)))), + ), TypeVariant::ExtensionPoint => Box::new( ReadXdrIter::<_, Frame>::new(r) .map(|r| r.map(|t| Self::ExtensionPoint(Box::new(t.0)))), @@ -45338,18 +45502,10 @@ impl Type { ReadXdrIter::<_, ScSpecEntry>::new(dec) .map(|r| r.map(|t| Self::ScSpecEntry(Box::new(t)))), ), - TypeVariant::ScSymbol => Box::new( - ReadXdrIter::<_, ScSymbol>::new(dec) - .map(|r| r.map(|t| Self::ScSymbol(Box::new(t)))), - ), TypeVariant::ScValType => Box::new( ReadXdrIter::<_, ScValType>::new(dec) .map(|r| r.map(|t| Self::ScValType(Box::new(t)))), ), - TypeVariant::ScStatic => Box::new( - ReadXdrIter::<_, ScStatic>::new(dec) - .map(|r| r.map(|t| Self::ScStatic(Box::new(t)))), - ), TypeVariant::ScStatusType => Box::new( ReadXdrIter::<_, ScStatusType>::new(dec) .map(|r| r.map(|t| Self::ScStatusType(Box::new(t)))), @@ -45390,16 +45546,25 @@ impl Type { ReadXdrIter::<_, ScStatus>::new(dec) .map(|r| r.map(|t| Self::ScStatus(Box::new(t)))), ), - TypeVariant::ScVal => Box::new( - ReadXdrIter::<_, ScVal>::new(dec).map(|r| r.map(|t| Self::ScVal(Box::new(t)))), + TypeVariant::Int128Parts => Box::new( + ReadXdrIter::<_, Int128Parts>::new(dec) + .map(|r| r.map(|t| Self::Int128Parts(Box::new(t)))), ), - TypeVariant::ScObjectType => Box::new( - ReadXdrIter::<_, ScObjectType>::new(dec) - .map(|r| r.map(|t| Self::ScObjectType(Box::new(t)))), + TypeVariant::ScContractExecutableType => Box::new( + ReadXdrIter::<_, ScContractExecutableType>::new(dec) + .map(|r| r.map(|t| Self::ScContractExecutableType(Box::new(t)))), ), - TypeVariant::ScMapEntry => Box::new( - ReadXdrIter::<_, ScMapEntry>::new(dec) - .map(|r| r.map(|t| Self::ScMapEntry(Box::new(t)))), + TypeVariant::ScContractExecutable => Box::new( + ReadXdrIter::<_, ScContractExecutable>::new(dec) + .map(|r| r.map(|t| Self::ScContractExecutable(Box::new(t)))), + ), + TypeVariant::ScAddressType => Box::new( + ReadXdrIter::<_, ScAddressType>::new(dec) + .map(|r| r.map(|t| Self::ScAddressType(Box::new(t)))), + ), + TypeVariant::ScAddress => Box::new( + ReadXdrIter::<_, ScAddress>::new(dec) + .map(|r| r.map(|t| Self::ScAddress(Box::new(t)))), ), TypeVariant::ScVec => Box::new( ReadXdrIter::<_, ScVec>::new(dec).map(|r| r.map(|t| Self::ScVec(Box::new(t)))), @@ -45407,29 +45572,27 @@ impl Type { TypeVariant::ScMap => Box::new( ReadXdrIter::<_, ScMap>::new(dec).map(|r| r.map(|t| Self::ScMap(Box::new(t)))), ), - TypeVariant::ScContractCodeType => Box::new( - ReadXdrIter::<_, ScContractCodeType>::new(dec) - .map(|r| r.map(|t| Self::ScContractCodeType(Box::new(t)))), + TypeVariant::ScBytes => Box::new( + ReadXdrIter::<_, ScBytes>::new(dec).map(|r| r.map(|t| Self::ScBytes(Box::new(t)))), ), - TypeVariant::ScContractCode => Box::new( - ReadXdrIter::<_, ScContractCode>::new(dec) - .map(|r| r.map(|t| Self::ScContractCode(Box::new(t)))), + TypeVariant::ScString => Box::new( + ReadXdrIter::<_, ScString>::new(dec) + .map(|r| r.map(|t| Self::ScString(Box::new(t)))), ), - TypeVariant::Int128Parts => Box::new( - ReadXdrIter::<_, Int128Parts>::new(dec) - .map(|r| r.map(|t| Self::Int128Parts(Box::new(t)))), + TypeVariant::ScSymbol => Box::new( + ReadXdrIter::<_, ScSymbol>::new(dec) + .map(|r| r.map(|t| Self::ScSymbol(Box::new(t)))), ), - TypeVariant::ScAddressType => Box::new( - ReadXdrIter::<_, ScAddressType>::new(dec) - .map(|r| r.map(|t| Self::ScAddressType(Box::new(t)))), + TypeVariant::ScNonceKey => Box::new( + ReadXdrIter::<_, ScNonceKey>::new(dec) + .map(|r| r.map(|t| Self::ScNonceKey(Box::new(t)))), ), - TypeVariant::ScAddress => Box::new( - ReadXdrIter::<_, ScAddress>::new(dec) - .map(|r| r.map(|t| Self::ScAddress(Box::new(t)))), + TypeVariant::ScVal => Box::new( + ReadXdrIter::<_, ScVal>::new(dec).map(|r| r.map(|t| Self::ScVal(Box::new(t)))), ), - TypeVariant::ScObject => Box::new( - ReadXdrIter::<_, ScObject>::new(dec) - .map(|r| r.map(|t| Self::ScObject(Box::new(t)))), + TypeVariant::ScMapEntry => Box::new( + ReadXdrIter::<_, ScMapEntry>::new(dec) + .map(|r| r.map(|t| Self::ScMapEntry(Box::new(t)))), ), TypeVariant::StoredTransactionSet => Box::new( ReadXdrIter::<_, StoredTransactionSet>::new(dec) @@ -45463,14 +45626,6 @@ impl Type { ReadXdrIter::<_, SequenceNumber>::new(dec) .map(|r| r.map(|t| Self::SequenceNumber(Box::new(t)))), ), - TypeVariant::TimePoint => Box::new( - ReadXdrIter::<_, TimePoint>::new(dec) - .map(|r| r.map(|t| Self::TimePoint(Box::new(t)))), - ), - TypeVariant::Duration => Box::new( - ReadXdrIter::<_, Duration>::new(dec) - .map(|r| r.map(|t| Self::Duration(Box::new(t)))), - ), TypeVariant::DataValue => Box::new( ReadXdrIter::<_, DataValue>::new(dec) .map(|r| r.map(|t| Self::DataValue(Box::new(t)))), @@ -46718,6 +46873,14 @@ impl Type { TypeVariant::Int64 => Box::new( ReadXdrIter::<_, Int64>::new(dec).map(|r| r.map(|t| Self::Int64(Box::new(t)))), ), + TypeVariant::TimePoint => Box::new( + ReadXdrIter::<_, TimePoint>::new(dec) + .map(|r| r.map(|t| Self::TimePoint(Box::new(t)))), + ), + TypeVariant::Duration => Box::new( + ReadXdrIter::<_, Duration>::new(dec) + .map(|r| r.map(|t| Self::Duration(Box::new(t)))), + ), TypeVariant::ExtensionPoint => Box::new( ReadXdrIter::<_, ExtensionPoint>::new(dec) .map(|r| r.map(|t| Self::ExtensionPoint(Box::new(t)))), @@ -46839,9 +47002,7 @@ impl Type { Self::ScSpecFunctionV0(ref v) => v.as_ref(), Self::ScSpecEntryKind(ref v) => v.as_ref(), Self::ScSpecEntry(ref v) => v.as_ref(), - Self::ScSymbol(ref v) => v.as_ref(), Self::ScValType(ref v) => v.as_ref(), - Self::ScStatic(ref v) => v.as_ref(), Self::ScStatusType(ref v) => v.as_ref(), Self::ScHostValErrorCode(ref v) => v.as_ref(), Self::ScHostObjErrorCode(ref v) => v.as_ref(), @@ -46852,17 +47013,19 @@ impl Type { Self::ScVmErrorCode(ref v) => v.as_ref(), Self::ScUnknownErrorCode(ref v) => v.as_ref(), Self::ScStatus(ref v) => v.as_ref(), - Self::ScVal(ref v) => v.as_ref(), - Self::ScObjectType(ref v) => v.as_ref(), - Self::ScMapEntry(ref v) => v.as_ref(), - Self::ScVec(ref v) => v.as_ref(), - Self::ScMap(ref v) => v.as_ref(), - Self::ScContractCodeType(ref v) => v.as_ref(), - Self::ScContractCode(ref v) => v.as_ref(), Self::Int128Parts(ref v) => v.as_ref(), + Self::ScContractExecutableType(ref v) => v.as_ref(), + Self::ScContractExecutable(ref v) => v.as_ref(), Self::ScAddressType(ref v) => v.as_ref(), Self::ScAddress(ref v) => v.as_ref(), - Self::ScObject(ref v) => v.as_ref(), + Self::ScVec(ref v) => v.as_ref(), + Self::ScMap(ref v) => v.as_ref(), + Self::ScBytes(ref v) => v.as_ref(), + Self::ScString(ref v) => v.as_ref(), + Self::ScSymbol(ref v) => v.as_ref(), + Self::ScNonceKey(ref v) => v.as_ref(), + Self::ScVal(ref v) => v.as_ref(), + Self::ScMapEntry(ref v) => v.as_ref(), Self::StoredTransactionSet(ref v) => v.as_ref(), Self::PersistedScpStateV0(ref v) => v.as_ref(), Self::PersistedScpStateV1(ref v) => v.as_ref(), @@ -46871,8 +47034,6 @@ impl Type { Self::String32(ref v) => v.as_ref(), Self::String64(ref v) => v.as_ref(), Self::SequenceNumber(ref v) => v.as_ref(), - Self::TimePoint(ref v) => v.as_ref(), - Self::Duration(ref v) => v.as_ref(), Self::DataValue(ref v) => v.as_ref(), Self::PoolId(ref v) => v.as_ref(), Self::AssetCode4(ref v) => v.as_ref(), @@ -47188,6 +47349,8 @@ impl Type { Self::Int32(ref v) => v.as_ref(), Self::Uint64(ref v) => v.as_ref(), Self::Int64(ref v) => v.as_ref(), + Self::TimePoint(ref v) => v.as_ref(), + Self::Duration(ref v) => v.as_ref(), Self::ExtensionPoint(ref v) => v.as_ref(), Self::CryptoKeyType(ref v) => v.as_ref(), Self::PublicKeyType(ref v) => v.as_ref(), @@ -47248,9 +47411,7 @@ impl Type { Self::ScSpecFunctionV0(_) => "ScSpecFunctionV0", Self::ScSpecEntryKind(_) => "ScSpecEntryKind", Self::ScSpecEntry(_) => "ScSpecEntry", - Self::ScSymbol(_) => "ScSymbol", Self::ScValType(_) => "ScValType", - Self::ScStatic(_) => "ScStatic", Self::ScStatusType(_) => "ScStatusType", Self::ScHostValErrorCode(_) => "ScHostValErrorCode", Self::ScHostObjErrorCode(_) => "ScHostObjErrorCode", @@ -47261,17 +47422,19 @@ impl Type { Self::ScVmErrorCode(_) => "ScVmErrorCode", Self::ScUnknownErrorCode(_) => "ScUnknownErrorCode", Self::ScStatus(_) => "ScStatus", - Self::ScVal(_) => "ScVal", - Self::ScObjectType(_) => "ScObjectType", - Self::ScMapEntry(_) => "ScMapEntry", - Self::ScVec(_) => "ScVec", - Self::ScMap(_) => "ScMap", - Self::ScContractCodeType(_) => "ScContractCodeType", - Self::ScContractCode(_) => "ScContractCode", Self::Int128Parts(_) => "Int128Parts", + Self::ScContractExecutableType(_) => "ScContractExecutableType", + Self::ScContractExecutable(_) => "ScContractExecutable", Self::ScAddressType(_) => "ScAddressType", Self::ScAddress(_) => "ScAddress", - Self::ScObject(_) => "ScObject", + Self::ScVec(_) => "ScVec", + Self::ScMap(_) => "ScMap", + Self::ScBytes(_) => "ScBytes", + Self::ScString(_) => "ScString", + Self::ScSymbol(_) => "ScSymbol", + Self::ScNonceKey(_) => "ScNonceKey", + Self::ScVal(_) => "ScVal", + Self::ScMapEntry(_) => "ScMapEntry", Self::StoredTransactionSet(_) => "StoredTransactionSet", Self::PersistedScpStateV0(_) => "PersistedScpStateV0", Self::PersistedScpStateV1(_) => "PersistedScpStateV1", @@ -47280,8 +47443,6 @@ impl Type { Self::String32(_) => "String32", Self::String64(_) => "String64", Self::SequenceNumber(_) => "SequenceNumber", - Self::TimePoint(_) => "TimePoint", - Self::Duration(_) => "Duration", Self::DataValue(_) => "DataValue", Self::PoolId(_) => "PoolId", Self::AssetCode4(_) => "AssetCode4", @@ -47609,6 +47770,8 @@ impl Type { Self::Int32(_) => "Int32", Self::Uint64(_) => "Uint64", Self::Int64(_) => "Int64", + Self::TimePoint(_) => "TimePoint", + Self::Duration(_) => "Duration", Self::ExtensionPoint(_) => "ExtensionPoint", Self::CryptoKeyType(_) => "CryptoKeyType", Self::PublicKeyType(_) => "PublicKeyType", @@ -47675,9 +47838,7 @@ impl Type { Self::ScSpecFunctionV0(_) => TypeVariant::ScSpecFunctionV0, Self::ScSpecEntryKind(_) => TypeVariant::ScSpecEntryKind, Self::ScSpecEntry(_) => TypeVariant::ScSpecEntry, - Self::ScSymbol(_) => TypeVariant::ScSymbol, Self::ScValType(_) => TypeVariant::ScValType, - Self::ScStatic(_) => TypeVariant::ScStatic, Self::ScStatusType(_) => TypeVariant::ScStatusType, Self::ScHostValErrorCode(_) => TypeVariant::ScHostValErrorCode, Self::ScHostObjErrorCode(_) => TypeVariant::ScHostObjErrorCode, @@ -47688,17 +47849,19 @@ impl Type { Self::ScVmErrorCode(_) => TypeVariant::ScVmErrorCode, Self::ScUnknownErrorCode(_) => TypeVariant::ScUnknownErrorCode, Self::ScStatus(_) => TypeVariant::ScStatus, - Self::ScVal(_) => TypeVariant::ScVal, - Self::ScObjectType(_) => TypeVariant::ScObjectType, - Self::ScMapEntry(_) => TypeVariant::ScMapEntry, - Self::ScVec(_) => TypeVariant::ScVec, - Self::ScMap(_) => TypeVariant::ScMap, - Self::ScContractCodeType(_) => TypeVariant::ScContractCodeType, - Self::ScContractCode(_) => TypeVariant::ScContractCode, Self::Int128Parts(_) => TypeVariant::Int128Parts, + Self::ScContractExecutableType(_) => TypeVariant::ScContractExecutableType, + Self::ScContractExecutable(_) => TypeVariant::ScContractExecutable, Self::ScAddressType(_) => TypeVariant::ScAddressType, Self::ScAddress(_) => TypeVariant::ScAddress, - Self::ScObject(_) => TypeVariant::ScObject, + Self::ScVec(_) => TypeVariant::ScVec, + Self::ScMap(_) => TypeVariant::ScMap, + Self::ScBytes(_) => TypeVariant::ScBytes, + Self::ScString(_) => TypeVariant::ScString, + Self::ScSymbol(_) => TypeVariant::ScSymbol, + Self::ScNonceKey(_) => TypeVariant::ScNonceKey, + Self::ScVal(_) => TypeVariant::ScVal, + Self::ScMapEntry(_) => TypeVariant::ScMapEntry, Self::StoredTransactionSet(_) => TypeVariant::StoredTransactionSet, Self::PersistedScpStateV0(_) => TypeVariant::PersistedScpStateV0, Self::PersistedScpStateV1(_) => TypeVariant::PersistedScpStateV1, @@ -47707,8 +47870,6 @@ impl Type { Self::String32(_) => TypeVariant::String32, Self::String64(_) => TypeVariant::String64, Self::SequenceNumber(_) => TypeVariant::SequenceNumber, - Self::TimePoint(_) => TypeVariant::TimePoint, - Self::Duration(_) => TypeVariant::Duration, Self::DataValue(_) => TypeVariant::DataValue, Self::PoolId(_) => TypeVariant::PoolId, Self::AssetCode4(_) => TypeVariant::AssetCode4, @@ -48074,6 +48235,8 @@ impl Type { Self::Int32(_) => TypeVariant::Int32, Self::Uint64(_) => TypeVariant::Uint64, Self::Int64(_) => TypeVariant::Int64, + Self::TimePoint(_) => TypeVariant::TimePoint, + Self::Duration(_) => TypeVariant::Duration, Self::ExtensionPoint(_) => TypeVariant::ExtensionPoint, Self::CryptoKeyType(_) => TypeVariant::CryptoKeyType, Self::PublicKeyType(_) => TypeVariant::PublicKeyType, diff --git a/src/next/scval_conversions.rs b/src/next/scval_conversions.rs index fba7fe3e..d48f5c73 100644 --- a/src/next/scval_conversions.rs +++ b/src/next/scval_conversions.rs @@ -1,4 +1,4 @@ -use super::{Int128Parts, ScMap, ScMapEntry, ScObject, ScStatic, ScStatus, ScSymbol, ScVal, ScVec}; +use super::{Int128Parts, ScBytes, ScMap, ScMapEntry, ScStatus, ScSymbol, ScVal, ScVec}; #[cfg(all(not(feature = "std"), feature = "alloc"))] extern crate alloc; @@ -7,46 +7,6 @@ use alloc::{string::String, vec, vec::Vec}; // TODO: Use the Error type for conversions in this file. -impl From for ScVal { - fn from(v: ScStatic) -> Self { - Self::Static(v) - } -} - -impl From<&ScStatic> for ScVal { - fn from(v: &ScStatic) -> Self { - Self::Static(*v) - } -} - -impl TryFrom for ScStatic { - type Error = (); - fn try_from(v: ScVal) -> Result { - if let ScVal::Static(s) = v { - Ok(s) - } else { - Err(()) - } - } -} - -impl From for ScVal { - fn from(v: ScObject) -> Self { - ScVal::Object(Some(v)) - } -} - -impl TryFrom for ScObject { - type Error = (); - fn try_from(v: ScVal) -> Result { - if let ScVal::Object(Some(o)) = v { - Ok(o) - } else { - Err(()) - } - } -} - impl From for ScVal { fn from(v: ScStatus) -> Self { ScVal::Status(v) @@ -112,11 +72,7 @@ impl TryFrom for u32 { impl From for ScVal { fn from(v: i64) -> ScVal { - if v < 0 { - ScObject::I64(v).into() - } else { - ScVal::U63(v) - } + ScVal::I64(v) } } @@ -129,7 +85,7 @@ impl From<&i64> for ScVal { impl TryFrom for i64 { type Error = (); fn try_from(v: ScVal) -> Result { - if let ScVal::U63(i) | ScVal::Object(Some(ScObject::I64(i))) = v { + if let ScVal::I64(i) = v { Ok(i) } else { Err(()) @@ -139,20 +95,20 @@ impl TryFrom for i64 { impl From<()> for ScVal { fn from(_: ()) -> Self { - ScStatic::Void.into() + ScVal::Void } } impl From<&()> for ScVal { fn from(_: &()) -> Self { - ScStatic::Void.into() + ScVal::Void } } impl TryFrom for () { type Error = (); fn try_from(v: ScVal) -> Result { - if let ScVal::Static(ScStatic::Void) = v { + if let ScVal::Void = v { Ok(()) } else { Err(()) @@ -162,7 +118,7 @@ impl TryFrom for () { impl From for ScVal { fn from(v: bool) -> Self { - if v { ScStatic::True } else { ScStatic::False }.into() + ScVal::Bool(v) } } @@ -175,76 +131,30 @@ impl From<&bool> for ScVal { impl TryFrom for bool { type Error = (); fn try_from(v: ScVal) -> Result { - match v { - ScVal::Static(ScStatic::False) => Ok(false), - ScVal::Static(ScStatic::True) => Ok(true), - _ => Err(()), - } - } -} - -impl From for ScObject { - fn from(v: i64) -> Self { - ScObject::I64(v) - } -} - -impl From<&i64> for ScObject { - fn from(v: &i64) -> Self { - ScObject::I64(*v) - } -} - -impl TryFrom for i64 { - type Error = (); - fn try_from(v: ScObject) -> Result { - if let ScObject::I64(i) = v { - Ok(i) + if let ScVal::Bool(b) = v { + Ok(b) } else { Err(()) } } } -impl From for ScObject { - fn from(v: u64) -> Self { - ScObject::U64(v) - } -} - -impl From<&u64> for ScObject { - fn from(v: &u64) -> Self { - ScObject::U64(*v) - } -} - impl From for ScVal { fn from(v: u64) -> Self { - <_ as Into>::into(v).into() + ScVal::U64(v) } } impl From<&u64> for ScVal { fn from(v: &u64) -> Self { - <_ as Into>::into(v).into() - } -} - -impl TryFrom for u64 { - type Error = (); - fn try_from(v: ScObject) -> Result { - if let ScObject::U64(i) = v { - Ok(i) - } else { - Err(()) - } + ScVal::U64(*v) } } impl TryFrom for u64 { type Error = (); fn try_from(v: ScVal) -> Result { - if let ScVal::Object(Some(ScObject::U64(i))) = v { + if let ScVal::U64(i) = v { Ok(i) } else { Err(()) @@ -292,101 +202,65 @@ pub mod int128_helpers { #[allow(clippy::wildcard_imports)] use int128_helpers::*; -impl From for ScObject { +impl From for ScVal { fn from(v: u128) -> Self { - ScObject::U128(Int128Parts { + ScVal::U128(Int128Parts { lo: u128_lo(v), hi: u128_hi(v), }) } } -impl From<&u128> for ScObject { - fn from(v: &u128) -> Self { - >::from(*v) - } -} - -impl From for ScVal { - fn from(v: u128) -> Self { - <_ as Into>::into(v).into() - } -} - impl From<&u128> for ScVal { fn from(v: &u128) -> Self { - <_ as Into>::into(v).into() + >::from(*v) } } -impl TryFrom for u128 { - type Error = (); - fn try_from(v: ScObject) -> Result { - if let ScObject::U128(i) = v { - Ok(u128_from_pieces(i.lo, i.hi)) - } else { - Err(()) - } +impl From<&Int128Parts> for u128 { + fn from(v: &Int128Parts) -> Self { + u128_from_pieces(v.lo, v.hi) } } impl TryFrom for u128 { type Error = (); fn try_from(v: ScVal) -> Result { - if let ScVal::Object(Some(ScObject::U128(i))) = v { - Ok(u128_from_pieces(i.lo, i.hi)) + if let ScVal::U128(i) = v { + Ok((&i).into()) } else { Err(()) } } } -impl From for ScObject { +impl From for ScVal { fn from(v: i128) -> Self { let v = u128_from_i128(v); - ScObject::I128(Int128Parts { + ScVal::I128(Int128Parts { lo: u128_lo(v), hi: u128_hi(v), }) } } -impl From<&i128> for ScObject { - fn from(v: &i128) -> Self { - >::from(*v) - } -} - -impl From for ScVal { - fn from(v: i128) -> Self { - <_ as Into>::into(v).into() - } -} - impl From<&i128> for ScVal { fn from(v: &i128) -> Self { - <_ as Into>::into(v).into() + >::from(*v) } } -impl TryFrom for i128 { - type Error = (); - fn try_from(v: ScObject) -> Result { - if let ScObject::I128(i) = v { - let v: u128 = u128_from_pieces(i.lo, i.hi); - Ok(i128_from_u128(v)) - } else { - Err(()) - } +impl From<&Int128Parts> for i128 { + fn from(v: &Int128Parts) -> Self { + i128_from_u128(u128_from_pieces(v.lo, v.hi)) } } impl TryFrom for i128 { type Error = (); fn try_from(v: ScVal) -> Result { - if let ScVal::Object(Some(ScObject::I128(i))) = v { - let v: u128 = u128_from_pieces(i.lo, i.hi); - Ok(i128_from_u128(v)) + if let ScVal::I128(i) = v { + Ok((&i).into()) } else { Err(()) } @@ -414,7 +288,7 @@ impl TryFrom for ScSymbol { impl TryFrom for ScVal { type Error = (); fn try_from(v: String) -> Result { - Ok(ScVal::Symbol(ScSymbol(v.try_into().map_err(|_| ())?))) + Ok(ScVal::Symbol(v.try_into().map_err(|_| ())?)) } } @@ -422,93 +296,85 @@ impl TryFrom for ScVal { impl TryFrom<&String> for ScVal { type Error = (); fn try_from(v: &String) -> Result { - Ok(ScVal::Symbol(ScSymbol(v.try_into().map_err(|_| ())?))) + Ok(ScVal::Symbol(v.try_into().map_err(|_| ())?)) } } #[cfg(feature = "alloc")] -impl TryFrom<&str> for ScVal { - type Error = (); - fn try_from(v: &str) -> Result { - Ok(ScVal::Symbol(ScSymbol(v.try_into().map_err(|_| ())?))) - } -} - -#[cfg(not(feature = "alloc"))] -impl TryFrom<&'static str> for ScVal { +impl TryFrom for ScSymbol { type Error = (); - fn try_from(v: &'static str) -> Result { - Ok(ScVal::Symbol(ScSymbol(v.try_into().map_err(|_| ())?))) + fn try_from(v: String) -> Result { + Ok(ScSymbol(v.try_into().map_err(|_| ())?)) } } #[cfg(feature = "alloc")] -impl TryFrom for String { +impl TryFrom<&String> for ScSymbol { type Error = (); - fn try_from(v: ScVal) -> Result { - if let ScVal::Symbol(s) = v { - // TODO: It might be worth distinguishing the error case where this - // is an invalid symbol with invalid characters. - Ok(s.0.into_string().map_err(|_| ())?) - } else { - Err(()) - } + fn try_from(v: &String) -> Result { + Ok(ScSymbol(v.try_into().map_err(|_| ())?)) } } #[cfg(feature = "alloc")] -impl TryFrom> for ScObject { +impl TryFrom<&str> for ScVal { type Error = (); - fn try_from(v: Vec) -> Result { - Ok(ScObject::Bytes(v.try_into().map_err(|_| ())?)) + fn try_from(v: &str) -> Result { + Ok(ScVal::Symbol(v.try_into().map_err(|_| ())?)) } } -#[cfg(feature = "alloc")] -impl TryFrom<&Vec> for ScObject { +#[cfg(not(feature = "alloc"))] +impl TryFrom<&'static str> for ScVal { type Error = (); - fn try_from(v: &Vec) -> Result { - Ok(ScObject::Bytes(v.try_into().map_err(|_| ())?)) + fn try_from(v: &'static str) -> Result { + Ok(ScVal::Symbol(v.try_into().map_err(|_| ())?)) } } #[cfg(feature = "alloc")] -impl TryFrom> for ScVal { +impl TryFrom<&str> for ScSymbol { type Error = (); - fn try_from(v: Vec) -> Result { - Ok(<_ as TryInto>::try_into(&v)?.into()) + fn try_from(v: &str) -> Result { + Ok(ScSymbol(v.try_into().map_err(|_| ())?)) } } -#[cfg(feature = "alloc")] -impl TryFrom<&Vec> for ScVal { +#[cfg(not(feature = "alloc"))] +impl TryFrom<&'static str> for ScSymbol { type Error = (); - fn try_from(v: &Vec) -> Result { - Ok(<_ as TryInto>::try_into(v)?.into()) + fn try_from(v: &'static str) -> Result { + Ok(ScSymbol(v.try_into().map_err(|_| ())?)) } } #[cfg(feature = "alloc")] -impl TryFrom<&[u8]> for ScObject { +impl TryFrom for String { type Error = (); - fn try_from(v: &[u8]) -> Result { - Ok(ScObject::Bytes(v.try_into().map_err(|_| ())?)) + fn try_from(v: ScVal) -> Result { + if let ScVal::Symbol(s) = v { + // TODO: It might be worth distinguishing the error case where this + // is an invalid symbol with invalid characters. + Ok(s.0.into_string().map_err(|_| ())?) + } else { + Err(()) + } } } #[cfg(feature = "alloc")] -impl TryFrom<[u8; N]> for ScObject { +impl TryFrom> for ScVal { type Error = (); - fn try_from(v: [u8; N]) -> Result { - Ok(ScObject::Bytes(v.try_into().map_err(|_| ())?)) + fn try_from(v: Vec) -> Result { + Ok(ScVal::Bytes(ScBytes(v.try_into().map_err(|_| ())?))) } } #[cfg(feature = "alloc")] -impl TryFrom<&[u8; N]> for ScObject { +impl TryFrom<&Vec> for ScVal { type Error = (); - fn try_from(v: &[u8; N]) -> Result { - Ok(ScObject::Bytes(v.try_into().map_err(|_| ())?)) + fn try_from(v: &Vec) -> Result { + Ok(ScVal::Bytes(ScBytes(v.try_into().map_err(|_| ())?))) } } @@ -516,7 +382,7 @@ impl TryFrom<&[u8; N]> for ScObject { impl TryFrom<&[u8]> for ScVal { type Error = (); fn try_from(v: &[u8]) -> Result { - Ok(<_ as TryInto>::try_into(v)?.into()) + Ok(ScVal::Bytes(ScBytes(v.try_into().map_err(|_| ())?))) } } @@ -524,7 +390,7 @@ impl TryFrom<&[u8]> for ScVal { impl TryFrom<[u8; N]> for ScVal { type Error = (); fn try_from(v: [u8; N]) -> Result { - Ok(<_ as TryInto>::try_into(v)?.into()) + Ok(ScVal::Bytes(ScBytes(v.try_into().map_err(|_| ())?))) } } @@ -532,15 +398,7 @@ impl TryFrom<[u8; N]> for ScVal { impl TryFrom<&[u8; N]> for ScVal { type Error = (); fn try_from(v: &[u8; N]) -> Result { - Ok(<_ as TryInto>::try_into(v)?.into()) - } -} - -#[cfg(not(feature = "alloc"))] -impl TryFrom<&'static [u8]> for ScObject { - type Error = (); - fn try_from(v: &'static [u8]) -> Result { - Ok(ScObject::Bytes(v.try_into().map_err(|_| ())?)) + Ok(ScVal::Bytes(ScBytes(v.try_into().map_err(|_| ())?))) } } @@ -548,31 +406,7 @@ impl TryFrom<&'static [u8]> for ScObject { impl TryFrom<&'static [u8]> for ScVal { type Error = (); fn try_from(v: &'static [u8]) -> Result { - Ok(<_ as TryInto>::try_into(v)?.into()) - } -} - -#[cfg(feature = "alloc")] -impl TryFrom for Vec { - type Error = (); - fn try_from(v: ScObject) -> Result { - if let ScObject::Bytes(b) = v { - Ok(b.into()) - } else { - Err(()) - } - } -} - -#[cfg(feature = "alloc")] -impl TryFrom<&ScObject> for Vec { - type Error = (); - fn try_from(v: &ScObject) -> Result { - if let ScObject::Bytes(b) = v { - Ok(b.into()) - } else { - Err(()) - } + Ok(ScVal::Bytes(ScBytes(v.try_into().map_err(|_| ())?))) } } @@ -580,7 +414,7 @@ impl TryFrom<&ScObject> for Vec { impl TryFrom for Vec { type Error = (); fn try_from(v: ScVal) -> Result { - if let ScVal::Object(Some(ScObject::Bytes(b))) = v { + if let ScVal::Bytes(ScBytes(b)) = v { Ok(b.into()) } else { Err(()) @@ -592,7 +426,7 @@ impl TryFrom for Vec { impl TryFrom<&ScVal> for Vec { type Error = (); fn try_from(v: &ScVal) -> Result { - if let ScVal::Object(Some(ScObject::Bytes(b))) = v { + if let ScVal::Bytes(ScBytes(b)) = v { Ok(b.into()) } else { Err(()) @@ -600,102 +434,62 @@ impl TryFrom<&ScVal> for Vec { } } -impl From for ScObject { - fn from(v: ScVec) -> Self { - ScObject::Vec(v) - } -} - impl From for ScVal { fn from(v: ScVec) -> Self { - <_ as Into>::into(v).into() + ScVal::Vec(Some(v)) } } #[cfg(feature = "alloc")] -impl> TryFrom> for ScObject { +impl> TryFrom> for ScVal { type Error = (); fn try_from(v: Vec) -> Result { - Ok(ScObject::Vec( + Ok(ScVal::Vec(Some( v.into_iter() .map(|t| <_ as TryInto>::try_into(t)) .collect::, _>>() // TODO: Impl conversion from Iterator to VecM in xdrgen generated code. .map_err(|_| ())? .try_into() .map_err(|_| ())?, - )) - } -} - -#[cfg(feature = "alloc")] -impl> TryFrom> for ScVal { - type Error = (); - fn try_from(v: Vec) -> Result { - Ok(<_ as TryInto>::try_into(v)?.into()) + ))) } } #[cfg(feature = "alloc")] -impl + Clone> TryFrom<&Vec> for ScObject { +impl + Clone> TryFrom<&Vec> for ScVal { type Error = (); fn try_from(v: &Vec) -> Result { - Ok(ScObject::Vec( + Ok(ScVal::Vec(Some( v.iter() .map(|t| <_ as TryInto>::try_into(t.clone())) .collect::, _>>() // TODO: Impl conversion from Iterator to VecM in xdrgen generated code. .map_err(|_| ())? .try_into() .map_err(|_| ())?, - )) + ))) } } #[cfg(feature = "alloc")] -impl<'a, T: TryInto> TryFrom<&'a Vec> for ScVal -where - ScObject: TryFrom<&'a Vec>, -{ - type Error = (); - fn try_from(v: &'a Vec) -> Result { - Ok(<_ as TryInto>::try_into(v) - .map_err(|_| ())? - .into()) - } -} - -#[cfg(feature = "alloc")] -impl + Clone> TryFrom<&[T]> for ScObject { +impl + Clone> TryFrom<&[T]> for ScVal { type Error = (); fn try_from(v: &[T]) -> Result { - Ok(ScObject::Vec( + Ok(ScVal::Vec(Some( v.iter() .map(|t| <_ as TryInto>::try_into(t.clone())) .collect::, _>>() // TODO: Impl conversion from Iterator to VecM in xdrgen generated code. .map_err(|_| ())? .try_into() .map_err(|_| ())?, - )) + ))) } } #[cfg(feature = "alloc")] -impl<'a, T: TryInto> TryFrom<&'a [T]> for ScVal -where - ScObject: TryFrom<&'a [T]>, -{ - type Error = (); - fn try_from(v: &'a [T]) -> Result { - Ok(<_ as TryInto>::try_into(v) - .map_err(|_| ())? - .into()) - } -} - -#[cfg(feature = "alloc")] -impl + Clone> TryFrom for Vec { +impl + Clone> TryFrom for Vec { type Error = (); - fn try_from(v: ScObject) -> Result { - if let ScObject::Vec(v) = v { + fn try_from(v: ScVal) -> Result { + if let ScVal::Vec(Some(v)) = v { v.iter() .map(|t| T::try_from(t.clone()).map_err(|_| ())) .collect::, _>>() @@ -705,46 +499,17 @@ impl + Clone> TryFrom for Vec { } } -#[cfg(feature = "alloc")] -impl + Clone> TryFrom for Vec { - type Error = (); - fn try_from(v: ScVal) -> Result { - if let ScVal::Object(Some(o)) = v { - <_ as TryInto>::try_into(o) - } else { - Err(()) - } - } -} - -impl From for ScObject { - fn from(v: ScMap) -> Self { - ScObject::Map(v) - } -} - impl From for ScVal { fn from(v: ScMap) -> Self { - <_ as Into>::into(v).into() - } -} - -impl TryFrom for ScMap { - type Error = (); - fn try_from(v: ScObject) -> Result { - if let ScObject::Map(m) = v { - Ok(m) - } else { - Err(()) - } + ScVal::Map(Some(v)) } } impl TryFrom for ScMap { type Error = (); fn try_from(v: ScVal) -> Result { - if let ScVal::Object(Some(o)) = v { - <_ as TryInto>::try_into(o) + if let ScVal::Map(Some(m)) = v { + Ok(m) } else { Err(()) } @@ -792,17 +557,6 @@ macro_rules! impl_for_tuple { } } - #[cfg(feature = "alloc")] - impl<$($typ),*> TryFrom<($($typ,)*)> for ScObject - where - $($typ: TryInto),* - { - type Error = (); - fn try_from(v: ($($typ,)*)) -> Result { - Ok(ScObject::Vec(<_ as TryInto>::try_into(v)?)) - } - } - #[cfg(feature = "alloc")] impl<$($typ),*> TryFrom<($($typ,)*)> for ScVal where @@ -810,7 +564,7 @@ macro_rules! impl_for_tuple { { type Error = (); fn try_from(v: ($($typ,)*)) -> Result { - Ok(ScVal::Object(Some(<_ as TryInto>::try_into(v)?))) + Ok(ScVal::Vec(Some(<_ as TryInto>::try_into(v)?))) } } @@ -836,30 +590,15 @@ macro_rules! impl_for_tuple { } } - impl<$($typ),*> TryFrom for ($($typ,)*) - where - $($typ: TryFrom + Clone),* - { - type Error = (); - - fn try_from(obj: ScObject) -> Result { - if let ScObject::Vec(vec) = obj { - <_ as TryFrom>::try_from(vec) - } else { - Err(()) - } - } - } - impl<$($typ),*> TryFrom for ($($typ,)*) where $($typ: TryFrom + Clone),* { type Error = (); - fn try_from(val: ScVal) -> Result { - if let ScVal::Object(Some(obj)) = val { - <_ as TryFrom>::try_from(obj) + fn try_from(obj: ScVal) -> Result { + if let ScVal::Vec(Some(vec)) = obj { + <_ as TryFrom>::try_from(vec) } else { Err(()) } @@ -884,7 +623,7 @@ impl_for_tuple! { 13 T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10 T1 #[cfg(test)] mod test { - use super::{ScObject, ScStatic, ScVal}; + use super::ScVal; #[test] fn i32_pos() { @@ -919,7 +658,7 @@ mod test { fn i64_pos() { let v = 5i64; let val: ScVal = v.try_into().unwrap(); - assert_eq!(val, ScVal::U63(5)); + assert_eq!(val, ScVal::I64(5)); let roundtrip: i64 = val.try_into().unwrap(); assert_eq!(v, roundtrip); } @@ -928,7 +667,7 @@ mod test { fn i64_neg() { let v = -5i64; let val: ScVal = v.try_into().unwrap(); - assert_eq!(val, ScVal::Object(Some(ScObject::I64(-5)))); + assert_eq!(val, ScVal::I64(-5)); let roundtrip: i64 = val.try_into().unwrap(); assert_eq!(v, roundtrip); } @@ -937,7 +676,7 @@ mod test { fn u64() { let v = 5u64; let val: ScVal = v.try_into().unwrap(); - assert_eq!(val, ScVal::Object(Some(ScObject::U64(5)))); + assert_eq!(val, ScVal::U64(5)); let roundtrip: u64 = val.try_into().unwrap(); assert_eq!(v, roundtrip); } @@ -950,21 +689,11 @@ mod test { let v = [1, 2, 3, 4, 5]; let val: ScVal = v.try_into().unwrap(); - assert_eq!( - val, - ScVal::Object(Some(ScObject::Bytes( - vec![1, 2, 3, 4, 5].try_into().unwrap() - ))) - ); + assert_eq!(val, ScVal::Bytes(vec![1, 2, 3, 4, 5].try_into().unwrap())); let v = &[1, 2, 3, 4, 5]; let val: ScVal = v.try_into().unwrap(); - assert_eq!( - val, - ScVal::Object(Some(ScObject::Bytes( - vec![1, 2, 3, 4, 5].try_into().unwrap() - ))) - ); + assert_eq!(val, ScVal::Bytes(vec![1, 2, 3, 4, 5].try_into().unwrap())); } #[cfg(feature = "alloc")] @@ -1001,10 +730,10 @@ mod test { fn option() { let v: Option = Some(1); let val: ScVal = v.into(); - assert_eq!(val, ScVal::U63(1)); + assert_eq!(val, ScVal::I64(1)); let v: Option = None; let val: ScVal = v.into(); - assert_eq!(val, ScVal::Static(ScStatic::Void)); + assert_eq!(val, ScVal::Void); } } diff --git a/src/next/scval_validations.rs b/src/next/scval_validations.rs index c82c3035..3a3995ab 100644 --- a/src/next/scval_validations.rs +++ b/src/next/scval_validations.rs @@ -1,6 +1,6 @@ #![allow(clippy::missing_errors_doc)] -use super::{Error, ScMap, ScObject, ScVal}; +use super::{Error, ScMap, ScVal}; pub trait Validate { type Error; @@ -12,14 +12,26 @@ impl Validate for ScVal { fn validate(&self) -> Result<(), Self::Error> { match self { - ScVal::U63(i) => { - // U63 is defined as valid per https://stellar.org/protocol/cap-46#comparison. - if *i >= 0 { - Ok(()) - } else { - Err(Error::Invalid) - } - } + ScVal::U32(_) + | ScVal::I32(_) + | ScVal::Status(_) + | ScVal::Bool(_) + | ScVal::Void + | ScVal::U64(_) + | ScVal::I64(_) + | ScVal::Timepoint(_) + | ScVal::Duration(_) + | ScVal::U128(_) + | ScVal::I128(_) + | ScVal::U256(_) + | ScVal::I256(_) + | ScVal::Bytes(_) + | ScVal::String(_) + | ScVal::Vec(Some(_)) + | ScVal::ContractExecutable(_) + | ScVal::Address(_) + | ScVal::LedgerKeyContractExecutable + | ScVal::LedgerKeyNonce(_) => Ok(()), ScVal::Symbol(s) => { // Symbol is defined as valid per https://github.com/stellar/rs-stellar-contract-env/blob/94c1717516c8fad4ad65caa148183b9fcbc408db/stellar-contract-env-common/src/symbol.rs#L107-L111. @@ -31,35 +43,8 @@ impl Validate for ScVal { Err(Error::Invalid) } } - - ScVal::Bitset(b) => { - // Bitset is defined as valid per https://github.com/stellar/rs-stellar-contract-env/blob/94c1717516c8fad4ad65caa148183b9fcbc408db/stellar-contract-env-common/src/bitset.rs#L53-L60. - if b & 0x0fff_ffff_ffff_ffff == *b { - Ok(()) - } else { - Err(Error::Invalid) - } - } - - ScVal::Object(None) => Err(Error::Invalid), - - ScVal::Object(Some(o)) => match o { - ScObject::Map(m) => m.validate(), - - // Other variants of ScObject are always valid. - ScObject::Vec(_) - | ScObject::U64(_) - | ScObject::I64(_) - | ScObject::U128(_) - | ScObject::I128(_) - | ScObject::Bytes(_) - | ScObject::ContractCode(_) - | ScObject::Address(_) - | ScObject::NonceKey(_) => Ok(()), - }, - - // Other variants of ScVal are always valid. - ScVal::U32(_) | ScVal::I32(_) | ScVal::Static(_) | ScVal::Status(_) => Ok(()), + ScVal::Vec(None) | ScVal::Map(None) => Err(Error::Invalid), + ScVal::Map(Some(m)) => m.validate(), } } } @@ -84,14 +69,6 @@ mod test { use super::{Error, ScVal, Validate}; - #[test] - fn u63() { - assert_eq!(ScVal::U63(0).validate(), Ok(())); - assert_eq!(ScVal::U63(1).validate(), Ok(())); - assert_eq!(ScVal::U63(i64::MAX).validate(), Ok(())); - assert_eq!(ScVal::U63(-1).validate(), Err(Error::Invalid)); - } - #[test] fn symbol() { assert_eq!( @@ -108,97 +85,83 @@ mod test { ); } - #[test] - fn bitset() { - assert_eq!(ScVal::Bitset(0x0000_0000_0000_0000).validate(), Ok(())); - assert_eq!(ScVal::Bitset(0x0fff_ffff_ffff_ffff).validate(), Ok(())); - assert_eq!( - ScVal::Bitset(0x1000_0000_0000_0000).validate(), - Err(Error::Invalid) - ); - assert_eq!( - ScVal::Bitset(0x1fff_ffff_ffff_ffff).validate(), - Err(Error::Invalid) - ); - } - #[test] #[cfg(feature = "alloc")] fn map() { - use super::super::{ScMap, ScMapEntry, ScObject}; + use super::super::{ScMap, ScMapEntry}; extern crate alloc; use alloc::vec; // Maps should be sorted by key and have no duplicates. The sort order // is just the "normal" sort order on ScVal emitted by derive(PartialOrd). assert_eq!( - ScVal::Object(Some(ScObject::Map(ScMap( + ScVal::Map(Some(ScMap( vec![ ScMapEntry { - key: ScVal::U63(0), + key: ScVal::I64(0), val: ScVal::U32(1), }, ScMapEntry { - key: ScVal::U63(1), - val: ScVal::U63(1), + key: ScVal::I64(1), + val: ScVal::I64(1), } ] .try_into() .unwrap() - )))) + ))) .validate(), Ok(()) ); assert_eq!( - ScVal::Object(Some(ScObject::Map(ScMap( + ScVal::Map(Some(ScMap( vec![ ScMapEntry { - key: ScVal::U63(0), - val: ScVal::U63(1), + key: ScVal::I64(0), + val: ScVal::I64(1), }, ScMapEntry { - key: ScVal::U63(1), - val: ScVal::U63(1), + key: ScVal::I64(1), + val: ScVal::I64(1), } ] .try_into() .unwrap() - )))) + ))) .validate(), Ok(()) ); assert_eq!( - ScVal::Object(Some(ScObject::Map(ScMap( + ScVal::Map(Some(ScMap( vec![ ScMapEntry { - key: ScVal::U63(2), - val: ScVal::U63(1), + key: ScVal::I64(2), + val: ScVal::I64(1), }, ScMapEntry { - key: ScVal::U63(1), - val: ScVal::U63(1), + key: ScVal::I64(1), + val: ScVal::I64(1), } ] .try_into() .unwrap() - )))) + ))) .validate(), Err(Error::Invalid) ); assert_eq!( - ScVal::Object(Some(ScObject::Map(ScMap( + ScVal::Map(Some(ScMap( vec![ ScMapEntry { - key: ScVal::U32(1), - val: ScVal::U63(1), + key: ScVal::I64(2), + val: ScVal::I64(1), }, ScMapEntry { - key: ScVal::U63(2), - val: ScVal::U63(1), + key: ScVal::U32(1), + val: ScVal::I64(1), }, ] .try_into() .unwrap() - )))) + ))) .validate(), Err(Error::Invalid) ); diff --git a/xdr/next b/xdr/next index df181487..32718f0a 160000 --- a/xdr/next +++ b/xdr/next @@ -1 +1 @@ -Subproject commit df18148747e807618acf4639db41c4fd6f0be9fc +Subproject commit 32718f0a958d0ba3172af10fc8a55a5b551398b0 diff --git a/xdr/next-version b/xdr/next-version index 2839f034..d4d8dfd1 100644 --- a/xdr/next-version +++ b/xdr/next-version @@ -1 +1 @@ -df18148747e807618acf4639db41c4fd6f0be9fc \ No newline at end of file +32718f0a958d0ba3172af10fc8a55a5b551398b0 \ No newline at end of file