diff --git a/crates/sui-sdk-types/Cargo.toml b/crates/sui-sdk-types/Cargo.toml index e6f49d87f..80986fabe 100644 --- a/crates/sui-sdk-types/Cargo.toml +++ b/crates/sui-sdk-types/Cargo.toml @@ -24,7 +24,6 @@ rustdoc-args = [ [features] default = [] serde = ["dep:serde", "dep:serde_derive", "dep:serde_with", "dep:bcs", "dep:serde_json", "roaring/std"] -schemars = ["serde", "dep:schemars", "dep:serde_json"] rand = ["dep:rand_core"] hash = ["dep:blake2"] proptest = ["dep:proptest", "dep:test-strategy", "serde"] @@ -44,9 +43,6 @@ serde_with = { version = "3.9", default-features = false, features = ["alloc"], bcs = { version = "0.1.6", optional = true } serde_json = { version = "1.0.128", optional = true } -# JsonSchema definitions for types, useful for generating an OpenAPI Specificaiton. -schemars = { version = "0.8.21", optional = true } - # RNG support rand_core = { version = "0.6.4", optional = true } diff --git a/crates/sui-sdk-types/src/address.rs b/crates/sui-sdk-types/src/address.rs index 9bb137e8c..bb4572865 100644 --- a/crates/sui-sdk-types/src/address.rs +++ b/crates/sui-sdk-types/src/address.rs @@ -194,39 +194,6 @@ impl std::fmt::Display for AddressParseError { impl std::error::Error for AddressParseError {} -#[cfg(feature = "schemars")] -impl schemars::JsonSchema for Address { - fn schema_name() -> String { - "Address".to_owned() - } - - fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - use schemars::schema::InstanceType; - use schemars::schema::Metadata; - use schemars::schema::SchemaObject; - use schemars::schema::StringValidation; - - let hex_length = Address::LENGTH * 2; - SchemaObject { - metadata: Some(Box::new(Metadata { - title: Some(Self::schema_name()), - description: Some("A 32-byte Sui address, encoded as a hex string.".to_owned()), - examples: vec![serde_json::to_value(Address::TWO).unwrap()], - ..Default::default() - })), - instance_type: Some(InstanceType::String.into()), - format: Some("hex".to_owned()), - string: Some(Box::new(StringValidation { - max_length: Some((hex_length + 2) as u32), - min_length: None, - pattern: Some(format!("0x[a-z0-9]{{1,{hex_length}}}")), - })), - ..Default::default() - } - .into() - } -} - #[cfg(test)] mod test { use super::*; diff --git a/crates/sui-sdk-types/src/checkpoint.rs b/crates/sui-sdk-types/src/checkpoint.rs index b1279be07..05ebc606a 100644 --- a/crates/sui-sdk-types/src/checkpoint.rs +++ b/crates/sui-sdk-types/src/checkpoint.rs @@ -19,11 +19,6 @@ pub type StakeUnit = u64; pub type ProtocolVersion = u64; #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "type", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum CheckpointCommitment { EcmhLiveObjectSet { digest: Digest }, @@ -35,7 +30,6 @@ pub enum CheckpointCommitment { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct EndOfEpochData { /// next_epoch_committee is `Some` if and only if the current checkpoint is @@ -50,7 +44,6 @@ pub struct EndOfEpochData { /// The protocol version that is in effect during the epoch that starts immediately after this /// checkpoint. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub next_epoch_protocol_version: ProtocolVersion, /// Commitments to epoch specific state (e.g. live object set) @@ -58,16 +51,12 @@ pub struct EndOfEpochData { } #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct CheckpointSummary { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: EpochId, - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub sequence_number: CheckpointSequenceNumber, /// Total number of transactions committed since genesis, including those in this /// checkpoint. - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub network_total_transactions: u64, pub content_digest: CheckpointContentsDigest, pub previous_digest: Option, @@ -78,15 +67,10 @@ pub struct CheckpointSummary { /// Timestamp of the checkpoint - number of milliseconds from the Unix epoch /// Checkpoint timestamps are monotonic, but not strongly monotonic - subsequent /// checkpoints can have same timestamp if they originate from the same underlining consensus commit - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub timestamp_ms: CheckpointTimestamp, /// Commitments to checkpoint-specific state (e.g. txns in checkpoint, objects read/written in /// checkpoint). - #[cfg_attr( - feature = "schemars", - schemars(with = "Option>") - )] pub checkpoint_commitments: Vec, /// Present only on the final checkpoint of the epoch. @@ -96,10 +80,6 @@ pub struct CheckpointSummary { /// code. Therefore, in order to allow extensions to be added to CheckpointSummary, we allow /// opaque data to be added to checkpoints which can be deserialized based on the current /// protocol version. - #[cfg_attr( - feature = "schemars", - schemars(with = "Option") - )] pub version_specific_data: Vec, } @@ -108,7 +88,6 @@ pub struct CheckpointSummary { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct SignedCheckpointSummary { pub checkpoint: CheckpointSummary, @@ -116,7 +95,6 @@ pub struct SignedCheckpointSummary { } #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct CheckpointContents( #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))] @@ -142,7 +120,6 @@ impl CheckpointContents { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct CheckpointTransactionInfo { pub transaction: TransactionDigest, @@ -156,7 +133,6 @@ pub struct CheckpointTransactionInfo { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct CheckpointData { pub checkpoint_summary: SignedCheckpointSummary, @@ -170,7 +146,6 @@ pub struct CheckpointData { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct CheckpointTransaction { /// The input Transaction @@ -178,7 +153,6 @@ pub struct CheckpointTransaction { feature = "serde", serde(with = "::serde_with::As::") )] - #[cfg_attr(feature = "schemars", schemars(with = "SignedTransaction"))] pub transaction: SignedTransaction, /// The effects produced by executing this transaction pub effects: TransactionEffects, diff --git a/crates/sui-sdk-types/src/crypto/bls12381.rs b/crates/sui-sdk-types/src/crypto/bls12381.rs index 4f2dcff94..9531b39da 100644 --- a/crates/sui-sdk-types/src/crypto/bls12381.rs +++ b/crates/sui-sdk-types/src/crypto/bls12381.rs @@ -5,7 +5,6 @@ feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Bls12381PublicKey( #[cfg_attr( @@ -14,7 +13,6 @@ pub struct Bls12381PublicKey( with = "::serde_with::As::<::serde_with::IfIsHumanReadable>" ) )] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] [u8; Self::LENGTH], ); @@ -106,7 +104,6 @@ impl std::fmt::Debug for Bls12381PublicKey { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Bls12381Signature( #[cfg_attr( @@ -115,7 +112,6 @@ pub struct Bls12381Signature( with = "::serde_with::As::<::serde_with::IfIsHumanReadable>" ) )] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] [u8; Self::LENGTH], ); diff --git a/crates/sui-sdk-types/src/crypto/ed25519.rs b/crates/sui-sdk-types/src/crypto/ed25519.rs index 8a6c9e669..f205e200b 100644 --- a/crates/sui-sdk-types/src/crypto/ed25519.rs +++ b/crates/sui-sdk-types/src/crypto/ed25519.rs @@ -5,14 +5,12 @@ feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Ed25519PublicKey( #[cfg_attr( feature = "serde", serde(with = "::serde_with::As::<::serde_with::IfIsHumanReadable>") )] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] [u8; Self::LENGTH], ); @@ -104,7 +102,6 @@ impl std::fmt::Debug for Ed25519PublicKey { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Ed25519Signature( #[cfg_attr( @@ -113,7 +110,6 @@ pub struct Ed25519Signature( with = "::serde_with::As::<::serde_with::IfIsHumanReadable>" ) )] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] [u8; Self::LENGTH], ); diff --git a/crates/sui-sdk-types/src/crypto/multisig.rs b/crates/sui-sdk-types/src/crypto/multisig.rs index 158a389ab..90d5a52de 100644 --- a/crates/sui-sdk-types/src/crypto/multisig.rs +++ b/crates/sui-sdk-types/src/crypto/multisig.rs @@ -30,7 +30,6 @@ pub enum MultisigMemberPublicKey { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct MultisigMember { public_key: MultisigMemberPublicKey, @@ -56,7 +55,6 @@ impl MultisigMember { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct MultisigCommittee { /// A list of committee members and their corresponding weight. @@ -114,7 +112,6 @@ impl MultisigCommittee { /// The struct that contains signatures and public keys necessary for authenticating a Multisig. #[derive(Debug, Clone)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct MultisigAggregatedSignature { /// The plain signature encoded with signature scheme. @@ -126,13 +123,6 @@ pub struct MultisigAggregatedSignature { bitmap: BitmapUnit, /// Legacy encoding for the bitmap. //TODO implement a strategy for legacy bitmap - #[cfg_attr( - feature = "schemars", - schemars( - skip_serializing_if = "Option::is_none", - with = "Option", - ) - )] #[cfg_attr(feature = "proptest", strategy(proptest::strategy::Just(None)))] legacy_bitmap: Option, /// The public key encoded with each public key with its signature scheme used along with the corresponding weight. @@ -534,7 +524,6 @@ mod serialization { #[derive(serde_derive::Serialize, serde_derive::Deserialize)] #[serde(tag = "scheme", rename_all = "lowercase")] #[serde(rename = "MultisigMemberPublicKey")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] enum ReadableMemberPublicKey { Ed25519 { public_key: Ed25519PublicKey }, Secp256k1 { public_key: Secp256k1PublicKey }, @@ -542,17 +531,6 @@ mod serialization { ZkLogin(ZkLoginPublicIdentifier), } - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for MultisigMemberPublicKey { - fn schema_name() -> String { - ReadableMemberPublicKey::schema_name() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - ReadableMemberPublicKey::json_schema(gen) - } - } - impl Serialize for MultisigMemberPublicKey { fn serialize(&self, serializer: S) -> Result where @@ -640,7 +618,6 @@ mod serialization { #[derive(serde_derive::Serialize, serde_derive::Deserialize)] #[serde(tag = "scheme", rename_all = "lowercase")] #[serde(rename = "MultisigMemberSignature")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] enum ReadableMemberSignature { Ed25519 { signature: Ed25519Signature }, Secp256k1 { signature: Secp256k1Signature }, @@ -648,17 +625,6 @@ mod serialization { ZkLogin(Box), } - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for MultisigMemberSignature { - fn schema_name() -> String { - ReadableMemberSignature::schema_name() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - ReadableMemberSignature::json_schema(gen) - } - } - impl Serialize for MultisigMemberSignature { fn serialize(&self, serializer: S) -> Result where diff --git a/crates/sui-sdk-types/src/crypto/passkey.rs b/crates/sui-sdk-types/src/crypto/passkey.rs index 12ff559a3..efcd5aac1 100644 --- a/crates/sui-sdk-types/src/crypto/passkey.rs +++ b/crates/sui-sdk-types/src/crypto/passkey.rs @@ -84,24 +84,12 @@ mod serialization { #[derive(serde::Deserialize)] #[serde(rename = "PasskeyAuthenticator")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] struct Authenticator { authenticator_data: Vec, client_data_json: String, signature: SimpleSignature, } - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for PasskeyAuthenticator { - fn schema_name() -> String { - Authenticator::schema_name() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - Authenticator::json_schema(gen) - } - } - impl Serialize for PasskeyAuthenticator { fn serialize(&self, serializer: S) -> Result where diff --git a/crates/sui-sdk-types/src/crypto/secp256k1.rs b/crates/sui-sdk-types/src/crypto/secp256k1.rs index 94f556192..f309bd7c9 100644 --- a/crates/sui-sdk-types/src/crypto/secp256k1.rs +++ b/crates/sui-sdk-types/src/crypto/secp256k1.rs @@ -5,7 +5,6 @@ feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Secp256k1PublicKey( #[cfg_attr( @@ -14,7 +13,6 @@ pub struct Secp256k1PublicKey( with = "::serde_with::As::<::serde_with::IfIsHumanReadable>" ) )] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] [u8; Self::LENGTH], ); @@ -106,7 +104,6 @@ impl std::fmt::Debug for Secp256k1PublicKey { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Secp256k1Signature( #[cfg_attr( @@ -115,7 +112,6 @@ pub struct Secp256k1Signature( with = "::serde_with::As::<::serde_with::IfIsHumanReadable>" ) )] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] [u8; Self::LENGTH], ); diff --git a/crates/sui-sdk-types/src/crypto/secp256r1.rs b/crates/sui-sdk-types/src/crypto/secp256r1.rs index 0e01918fc..21cfaf453 100644 --- a/crates/sui-sdk-types/src/crypto/secp256r1.rs +++ b/crates/sui-sdk-types/src/crypto/secp256r1.rs @@ -23,7 +23,6 @@ impl Secp256r1PrivateKey { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Secp256r1PublicKey( #[cfg_attr( @@ -32,7 +31,6 @@ pub struct Secp256r1PublicKey( with = "::serde_with::As::<::serde_with::IfIsHumanReadable>" ) )] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] [u8; Self::LENGTH], ); @@ -124,7 +122,6 @@ impl std::fmt::Debug for Secp256r1PublicKey { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Secp256r1Signature( #[cfg_attr( @@ -133,7 +130,6 @@ pub struct Secp256r1Signature( with = "::serde_with::As::<::serde_with::IfIsHumanReadable>" ) )] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] [u8; Self::LENGTH], ); diff --git a/crates/sui-sdk-types/src/crypto/signature.rs b/crates/sui-sdk-types/src/crypto/signature.rs index f107178da..8925fe6d3 100644 --- a/crates/sui-sdk-types/src/crypto/signature.rs +++ b/crates/sui-sdk-types/src/crypto/signature.rs @@ -9,11 +9,6 @@ use super::Secp256r1Signature; use super::ZkLoginAuthenticator; #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "scheme", rename_all = "lowercase") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum SimpleSignature { Ed25519 { @@ -490,7 +485,6 @@ mod serialization { #[derive(serde_derive::Deserialize)] #[serde(tag = "scheme", rename_all = "lowercase")] #[serde(rename = "UserSignature")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] enum ReadableUserSignature { Ed25519 { signature: Ed25519Signature, @@ -509,17 +503,6 @@ mod serialization { Passkey(PasskeyAuthenticator), } - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for UserSignature { - fn schema_name() -> String { - ReadableUserSignature::schema_name() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - ReadableUserSignature::json_schema(gen) - } - } - impl serde::Serialize for UserSignature { fn serialize(&self, serializer: S) -> Result where diff --git a/crates/sui-sdk-types/src/crypto/validator.rs b/crates/sui-sdk-types/src/crypto/validator.rs index 1ba8f37dd..87845f208 100644 --- a/crates/sui-sdk-types/src/crypto/validator.rs +++ b/crates/sui-sdk-types/src/crypto/validator.rs @@ -8,11 +8,9 @@ use crate::checkpoint::StakeUnit; feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ValidatorCommittee { #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: EpochId, pub members: Vec, } @@ -22,14 +20,11 @@ pub struct ValidatorCommittee { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ValidatorCommitteeMember { #[cfg_attr(feature = "serde", serde(with = "ValidatorPublicKeySerialization"))] - #[cfg_attr(feature = "schemars", schemars(with = "Bls12381PublicKey"))] pub public_key: Bls12381PublicKey, #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub stake: StakeUnit, } @@ -38,15 +33,12 @@ pub struct ValidatorCommitteeMember { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ValidatorAggregatedSignature { #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: EpochId, pub signature: Bls12381Signature, #[cfg_attr(feature = "serde", serde(with = "RoaringBitMapSerialization"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] #[cfg_attr( feature = "proptest", strategy(proptest::strategy::Just(roaring::RoaringBitmap::default())) @@ -99,14 +91,11 @@ impl<'de> serde_with::DeserializeAs<'de, Bls12381PublicKey> for BinaryValidatorP feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ValidatorSignature { #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: EpochId, #[cfg_attr(feature = "serde", serde(with = "ValidatorPublicKeySerialization"))] - #[cfg_attr(feature = "schemars", schemars(with = "Bls12381PublicKey"))] pub public_key: Bls12381PublicKey, pub signature: Bls12381Signature, } diff --git a/crates/sui-sdk-types/src/crypto/zklogin.rs b/crates/sui-sdk-types/src/crypto/zklogin.rs index 3e518f6fb..c828a2b29 100644 --- a/crates/sui-sdk-types/src/crypto/zklogin.rs +++ b/crates/sui-sdk-types/src/crypto/zklogin.rs @@ -4,11 +4,9 @@ use crate::u256::U256; /// An zk login authenticator with all the necessary fields. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ZkLoginAuthenticator { pub inputs: ZkLoginInputs, - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub max_epoch: EpochId, pub signature: SimpleSignature, } @@ -19,7 +17,6 @@ pub struct ZkLoginAuthenticator { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ZkLoginInputs { pub proof_points: ZkLoginProof, @@ -34,7 +31,6 @@ pub struct ZkLoginInputs { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Claim { pub value: String, @@ -47,7 +43,6 @@ pub struct Claim { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ZkLoginProof { pub a: CircomG1, @@ -58,7 +53,6 @@ pub struct ZkLoginProof { /// A G1 point in BN254 serialized as a vector of three strings which is the canonical decimal /// representation of the projective coordinates in Fq. #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct CircomG1(pub [Bn254FieldElement; 3]); @@ -66,14 +60,12 @@ pub struct CircomG1(pub [Bn254FieldElement; 3]); /// which are the canonical decimal representation of the coefficients of the projective coordinates /// in Fq2. #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct CircomG2(pub [[Bn254FieldElement; 2]; 3]); /// A wrapper struct to retrofit in [enum PublicKey] for zkLogin. /// Useful to construct [struct MultiSigPublicKey]. #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] //TODO ensure iss is less than 255 bytes long pub struct ZkLoginPublicIdentifier { @@ -107,7 +99,6 @@ impl ZkLoginPublicIdentifier { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Jwk { /// Key type parameter, @@ -126,7 +117,6 @@ pub struct Jwk { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct JwkId { /// iss string that identifies the OIDC provider. @@ -136,11 +126,8 @@ pub struct JwkId { } #[derive(Clone, Debug, Default, PartialEq, Eq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] -pub struct Bn254FieldElement( - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U256"))] [u8; 32], -); +pub struct Bn254FieldElement([u8; 32]); impl Bn254FieldElement { pub const fn new(bytes: [u8; 32]) -> Self { diff --git a/crates/sui-sdk-types/src/digest.rs b/crates/sui-sdk-types/src/digest.rs index 1398f9844..867734221 100644 --- a/crates/sui-sdk-types/src/digest.rs +++ b/crates/sui-sdk-types/src/digest.rs @@ -4,11 +4,9 @@ feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Digest( #[cfg_attr(feature = "serde", serde(with = "DigestSerialization"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base58"))] [u8; Self::LENGTH], ); @@ -193,7 +191,6 @@ macro_rules! impl_digest { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct $t(Digest); diff --git a/crates/sui-sdk-types/src/effects/mod.rs b/crates/sui-sdk-types/src/effects/mod.rs index 30475ae5a..d6123ebd3 100644 --- a/crates/sui-sdk-types/src/effects/mod.rs +++ b/crates/sui-sdk-types/src/effects/mod.rs @@ -16,16 +16,9 @@ use crate::execution_status::ExecutionStatus; /// The response from processing a transaction or a certified transaction #[derive(Eq, PartialEq, Clone, Debug)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "version") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum TransactionEffects { - #[cfg_attr(feature = "schemars", schemars(rename = "1"))] V1(Box), - #[cfg_attr(feature = "schemars", schemars(rename = "2"))] V2(Box), } diff --git a/crates/sui-sdk-types/src/effects/v1.rs b/crates/sui-sdk-types/src/effects/v1.rs index b5c239c2d..c83962182 100644 --- a/crates/sui-sdk-types/src/effects/v1.rs +++ b/crates/sui-sdk-types/src/effects/v1.rs @@ -10,14 +10,11 @@ use crate::TransactionEventsDigest; /// The response from processing a transaction or a certified transaction #[derive(Eq, PartialEq, Clone, Debug)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct TransactionEffectsV1 { /// The status of the execution - #[cfg_attr(feature = "schemars", schemars(flatten))] pub status: ExecutionStatus, /// The epoch when this transaction was executed. - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: EpochId, pub gas_used: GasCostSummary, /// The version that every modified (mutated or deleted) object had before it was modified by @@ -66,12 +63,10 @@ pub struct TransactionEffectsV1 { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ModifiedAtVersion { pub object_id: ObjectId, #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub version: Version, } @@ -80,7 +75,6 @@ pub struct ModifiedAtVersion { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ObjectReferenceWithOwner { pub reference: ObjectReference, diff --git a/crates/sui-sdk-types/src/effects/v2.rs b/crates/sui-sdk-types/src/effects/v2.rs index 443e43034..6e1547122 100644 --- a/crates/sui-sdk-types/src/effects/v2.rs +++ b/crates/sui-sdk-types/src/effects/v2.rs @@ -11,14 +11,11 @@ use crate::TransactionEventsDigest; /// The response from processing a transaction or a certified transaction #[derive(Eq, PartialEq, Clone, Debug)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct TransactionEffectsV2 { /// The status of the execution - #[cfg_attr(feature = "schemars", schemars(flatten))] pub status: ExecutionStatus, /// The epoch when this transaction was executed. - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: EpochId, pub gas_used: GasCostSummary, /// The transaction digest @@ -35,7 +32,6 @@ pub struct TransactionEffectsV2 { pub dependencies: Vec, /// The version number of all the written Move objects by this transaction. - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub lamport_version: Version, /// Objects whose state are changed in the object store. #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))] @@ -57,7 +53,6 @@ pub struct TransactionEffectsV2 { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ChangedObject { pub object_id: ObjectId, @@ -77,7 +72,6 @@ pub struct ChangedObject { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct UnchangedSharedObject { pub object_id: ObjectId, @@ -85,33 +79,24 @@ pub struct UnchangedSharedObject { } #[derive(Eq, PartialEq, Clone, Debug)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "kind", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum UnchangedSharedKind { /// Read-only shared objects from the input. We don't really need ObjectDigest /// for protocol correctness, but it will make it easier to verify untrusted read. ReadOnlyRoot { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] version: Version, digest: ObjectDigest, }, /// Deleted shared objects that appear mutably/owned in the input. MutateDeleted { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] version: Version, }, /// Deleted shared objects that appear as read-only in the input. ReadDeleted { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] version: Version, }, /// Shared objects in cancelled transaction. The sequence number embed cancellation reason. Cancelled { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] version: Version, }, /// Read of a per-epoch config object that should remain the same during an epoch. @@ -122,17 +107,11 @@ pub enum UnchangedSharedKind { /// it should be Exist, otherwise it's NonExist, e.g. wrapped objects should be /// NonExist. #[derive(Eq, PartialEq, Clone, Debug)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "state", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum ObjectIn { NotExist, /// The old version, digest and owner. Exist { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] version: Version, digest: ObjectDigest, owner: Owner, @@ -140,11 +119,6 @@ pub enum ObjectIn { } #[derive(Eq, PartialEq, Clone, Debug)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "state", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum ObjectOut { /// Same definition as in ObjectIn. @@ -154,7 +128,6 @@ pub enum ObjectOut { /// Packages writes need to be tracked separately with version because /// we don't use lamport version for package publish and upgrades. PackageWrite { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] version: Version, digest: ObjectDigest, }, @@ -166,7 +139,6 @@ pub enum ObjectOut { derive(serde_derive::Serialize, serde_derive::Deserialize), serde(rename_all = "lowercase") )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum IdOperation { None, diff --git a/crates/sui-sdk-types/src/events.rs b/crates/sui-sdk-types/src/events.rs index 027faefb5..0a3ca85d3 100644 --- a/crates/sui-sdk-types/src/events.rs +++ b/crates/sui-sdk-types/src/events.rs @@ -9,7 +9,6 @@ use super::TypeTag; feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct TransactionEvents(pub Vec); @@ -19,7 +18,6 @@ pub struct TransactionEvents(pub Vec); feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Event { pub package_id: ObjectId, @@ -31,7 +29,6 @@ pub struct Event { feature = "serde", serde(with = "crate::_serde::ReadableBase64Encoded") )] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] pub contents: Vec, } @@ -40,7 +37,6 @@ pub struct Event { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct BalanceChange { /// Owner of the balance change @@ -51,6 +47,5 @@ pub struct BalanceChange { /// /// A negative amount means spending coin value and positive means receiving coin value. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::I128"))] pub amount: i128, } diff --git a/crates/sui-sdk-types/src/execution_status.rs b/crates/sui-sdk-types/src/execution_status.rs index 1fe7e2077..2b3a47e4e 100644 --- a/crates/sui-sdk-types/src/execution_status.rs +++ b/crates/sui-sdk-types/src/execution_status.rs @@ -22,11 +22,6 @@ pub enum ExecutionStatus { pub type TypeParameterIndex = u16; #[derive(Eq, PartialEq, Clone, Debug)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "error", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum ExecutionError { // @@ -42,16 +37,12 @@ pub enum ExecutionError { FeatureNotYetSupported, /// Move object is larger than the maximum allowed size ObjectTooBig { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] object_size: u64, - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] max_object_size: u64, }, /// Package is larger than the maximum allowed size PackageTooBig { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] object_size: u64, - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] max_object_size: u64, }, /// Circular Object Ownership @@ -85,7 +76,6 @@ pub enum ExecutionError { /// Move runtime abort MoveAbort { location: MoveLocation, - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] code: u64, }, /// Bytecode verification error. @@ -129,9 +119,7 @@ pub enum ExecutionError { // /// Effects from the transaction are too large EffectsTooLarge { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] current_size: u64, - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] max_size: u64, }, @@ -146,14 +134,11 @@ pub enum ExecutionError { PublishUpgradeDependencyDowngrade, /// Invalid package upgrade - #[cfg_attr(feature = "schemars", schemars(title = "PackageUpgradeError"))] PackageUpgradeError { kind: PackageUpgradeError }, /// Indicates the transaction tried to write objects too large to storage WrittenObjectsTooLarge { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] object_size: u64, - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] max_object_size: u64, }, @@ -187,7 +172,6 @@ pub enum ExecutionError { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct MoveLocation { pub package: ObjectId, @@ -200,11 +184,6 @@ pub struct MoveLocation { } #[derive(Eq, PartialEq, Clone, Debug)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "kind", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum CommandArgumentError { /// The type of the value does not match the expected type @@ -241,11 +220,6 @@ pub enum CommandArgumentError { } #[derive(Eq, PartialEq, Clone, Debug)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "kind", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum PackageUpgradeError { /// Unable to fetch package @@ -271,11 +245,6 @@ pub enum PackageUpgradeError { derive(serde_derive::Serialize, serde_derive::Deserialize), serde(rename_all = "snake_case") )] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum TypeArgumentError { /// A type was not found in the module specified @@ -296,26 +265,13 @@ mod serialization { #[derive(serde_derive::Serialize, serde_derive::Deserialize)] #[serde(rename = "ExecutionStatus")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] struct ReadableExecutionStatus { success: bool, #[serde(skip_serializing_if = "Option::is_none")] status: Option, } - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for ExecutionStatus { - fn schema_name() -> String { - ReadableExecutionStatus::schema_name() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - ReadableExecutionStatus::json_schema(gen) - } - } - #[derive(serde_derive::Serialize, serde_derive::Deserialize)] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] struct FailureStatus { error: ExecutionError, #[serde(skip_serializing_if = "Option::is_none")] diff --git a/crates/sui-sdk-types/src/gas.rs b/crates/sui-sdk-types/src/gas.rs index 36a41579d..f89e7be63 100644 --- a/crates/sui-sdk-types/src/gas.rs +++ b/crates/sui-sdk-types/src/gas.rs @@ -27,28 +27,23 @@ feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct GasCostSummary { /// Cost of computation/execution #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub computation_cost: u64, /// Storage cost, it's the sum of all storage cost for all objects created or mutated. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub storage_cost: u64, /// The amount of storage cost refunded to the user for all objects deleted or mutated in the /// transaction. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub storage_rebate: u64, /// The fee for the rebate. The portion of the storage rebate kept by the system. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub non_refundable_storage_fee: u64, } diff --git a/crates/sui-sdk-types/src/lib.rs b/crates/sui-sdk-types/src/lib.rs index 0b7a632ca..698cfa066 100644 --- a/crates/sui-sdk-types/src/lib.rs +++ b/crates/sui-sdk-types/src/lib.rs @@ -274,136 +274,3 @@ mod _serde { pub(crate) use super::SignedTransactionWithIntentMessage; } - -#[cfg(feature = "schemars")] -mod _schemars { - use schemars::schema::InstanceType; - use schemars::schema::Metadata; - use schemars::schema::SchemaObject; - use schemars::JsonSchema; - - pub(crate) struct U64; - - impl JsonSchema for U64 { - fn schema_name() -> String { - "u64".to_owned() - } - - fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - SchemaObject { - metadata: Some(Box::new(Metadata { - description: Some("Radix-10 encoded 64-bit unsigned integer".to_owned()), - ..Default::default() - })), - instance_type: Some(InstanceType::String.into()), - format: Some("u64".to_owned()), - ..Default::default() - } - .into() - } - - fn is_referenceable() -> bool { - false - } - } - - pub(crate) struct I128; - - impl JsonSchema for I128 { - fn schema_name() -> String { - "i128".to_owned() - } - - fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - SchemaObject { - metadata: Some(Box::new(Metadata { - description: Some("Radix-10 encoded 128-bit signed integer".to_owned()), - ..Default::default() - })), - instance_type: Some(InstanceType::String.into()), - format: Some("i128".to_owned()), - ..Default::default() - } - .into() - } - - fn is_referenceable() -> bool { - false - } - } - - pub(crate) struct U256; - - impl JsonSchema for U256 { - fn schema_name() -> String { - "u256".to_owned() - } - - fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - SchemaObject { - metadata: Some(Box::new(Metadata { - description: Some("Radix-10 encoded 256-bit unsigned integer".to_owned()), - ..Default::default() - })), - instance_type: Some(InstanceType::String.into()), - format: Some("u256".to_owned()), - ..Default::default() - } - .into() - } - - fn is_referenceable() -> bool { - false - } - } - - pub(crate) struct Base64; - - impl JsonSchema for Base64 { - fn schema_name() -> String { - "Base64".to_owned() - } - - fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - SchemaObject { - metadata: Some(Box::new(Metadata { - description: Some("Base64 encoded data".to_owned()), - ..Default::default() - })), - instance_type: Some(InstanceType::String.into()), - format: Some("base64".to_owned()), - ..Default::default() - } - .into() - } - - fn is_referenceable() -> bool { - false - } - } - - pub(crate) struct Base58; - - impl JsonSchema for Base58 { - fn schema_name() -> String { - "Base58".to_owned() - } - - fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - SchemaObject { - metadata: Some(Box::new(Metadata { - description: Some("Base58 encoded data".to_owned()), - ..Default::default() - })), - instance_type: Some(InstanceType::String.into()), - format: Some("base58".to_owned()), - ..Default::default() - } - .into() - } - - fn is_referenceable() -> bool { - false - } - } -} diff --git a/crates/sui-sdk-types/src/object.rs b/crates/sui-sdk-types/src/object.rs index bf53976e8..e1c887af6 100644 --- a/crates/sui-sdk-types/src/object.rs +++ b/crates/sui-sdk-types/src/object.rs @@ -14,12 +14,10 @@ pub type Version = u64; feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ObjectReference { object_id: ObjectId, #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] version: Version, digest: ObjectDigest, } @@ -62,7 +60,6 @@ impl ObjectReference { derive(serde_derive::Serialize, serde_derive::Deserialize), serde(rename_all = "lowercase") )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum Owner { /// # Address Owned @@ -76,7 +73,6 @@ pub enum Owner { Shared( /// The version at which the object became shared #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] Version, ), /// # Immutable @@ -156,7 +152,6 @@ pub struct MovePackage { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct TypeOrigin { pub module_name: Identifier, @@ -170,14 +165,12 @@ pub struct TypeOrigin { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct UpgradeInfo { /// Id of the upgraded packages pub upgraded_id: ObjectId, /// Version of the upgraded package #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub upgraded_version: Version, } @@ -569,17 +562,14 @@ mod serialization { #[derive(serde_derive::Serialize, serde_derive::Deserialize)] #[serde(rename = "Object")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] struct ReadableObject { object_id: ObjectId, #[serde(with = "crate::_serde::ReadableDisplay")] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] version: Version, owner: Owner, #[serde(with = "::serde_with::As::")] #[serde(rename = "type")] - #[cfg_attr(feature = "schemars", schemars(with = "String"))] type_: ObjectType, #[serde(flatten)] @@ -587,62 +577,30 @@ mod serialization { previous_transaction: TransactionDigest, #[serde(with = "crate::_serde::ReadableDisplay")] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] storage_rebate: u64, } - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for Object { - fn schema_name() -> String { - ReadableObject::schema_name() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - ReadableObject::json_schema(gen) - } - } - #[derive(serde_derive::Serialize, serde_derive::Deserialize)] #[serde(untagged)] - #[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(rename = "ObjectData") - )] enum ReadableObjectData { Move(ReadableMoveStruct), Package(ReadablePackage), } #[derive(serde_derive::Serialize, serde_derive::Deserialize)] - #[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(rename = "Package") - )] struct ReadablePackage { #[serde( with = "::serde_with::As::>" )] - #[cfg_attr( - feature = "schemars", - schemars(with = "BTreeMap") - )] modules: BTreeMap>, type_origin_table: Vec, linkage_table: BTreeMap, } #[derive(serde_derive::Serialize, serde_derive::Deserialize)] - #[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(rename = "MoveStruct") - )] struct ReadableMoveStruct { has_public_transfer: bool, #[serde(with = "::serde_with::As::")] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] contents: Vec, } @@ -782,34 +740,20 @@ mod serialization { #[derive(serde_derive::Serialize, serde_derive::Deserialize)] #[serde(rename = "GenesisObject")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] struct ReadableGenesisObject { object_id: ObjectId, #[serde(with = "crate::_serde::ReadableDisplay")] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] version: Version, owner: Owner, #[serde(with = "::serde_with::As::")] #[serde(rename = "type")] - #[cfg_attr(feature = "schemars", schemars(with = "String"))] type_: ObjectType, #[serde(flatten)] data: ReadableObjectData, } - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for GenesisObject { - fn schema_name() -> String { - ReadableGenesisObject::schema_name() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - ReadableGenesisObject::json_schema(gen) - } - } - #[derive(serde_derive::Serialize, serde_derive::Deserialize)] enum BinaryGenesisObject { RawObject { data: ObjectData, owner: Owner }, diff --git a/crates/sui-sdk-types/src/object_id.rs b/crates/sui-sdk-types/src/object_id.rs index 89c8288c0..c57b140ce 100644 --- a/crates/sui-sdk-types/src/object_id.rs +++ b/crates/sui-sdk-types/src/object_id.rs @@ -5,7 +5,6 @@ use super::Address; feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ObjectId(Address); diff --git a/crates/sui-sdk-types/src/serialization_proptests.rs b/crates/sui-sdk-types/src/serialization_proptests.rs index a500e6b05..1fbfb3baf 100644 --- a/crates/sui-sdk-types/src/serialization_proptests.rs +++ b/crates/sui-sdk-types/src/serialization_proptests.rs @@ -7,13 +7,6 @@ use wasm_bindgen_test::wasm_bindgen_test as test; macro_rules! serialization_test { ($type:ident) => { paste::item! { - #[cfg_attr(target_arch = "wasm32", proptest(cases = 50))] - #[cfg_attr(not(target_arch = "wasm32"), proptest)] - #[allow(non_snake_case)] - fn [< test_valid_json_schema_ $type >] (instance: $type) { - assert_valid_json_schema(&instance); - } - #[cfg_attr(target_arch = "wasm32", proptest(cases = 50))] #[cfg_attr(not(target_arch = "wasm32"), proptest)] #[allow(non_snake_case)] @@ -33,28 +26,6 @@ macro_rules! serialization_test { }; } -fn assert_valid_json_schema(instance: &T) -where - T: serde::Serialize + schemars::JsonSchema, -{ - let root_schema = schemars::gen::SchemaGenerator::default().into_root_schema_for::(); - let schema = serde_json::json!(root_schema); - let compiled = jsonschema::Validator::new(&schema).unwrap(); - let instance = serde_json::json!(instance); - - let result = compiled.validate(&instance); - let r = result.is_ok(); - if let Err(errors) = result { - for error in errors { - println!("Validation error: {}", error); - println!("Instance path: {}", error.instance_path); - } - } - - // assert!(compiled.is_valid(&instance)); - assert!(r); -} - fn assert_roundtrip(instance: &T) where T: serde::Serialize + for<'de> serde::Deserialize<'de> + PartialEq + std::fmt::Debug, @@ -176,11 +147,6 @@ serialization_test!(Transaction); serialization_test!(TransactionExpiration); serialization_test!(TransactionKind); serialization_test!(TransferObjects); -// serialization_test!(UnresolvedGasPayment); -// serialization_test!(UnresolvedInputArgument); -// serialization_test!(UnresolvedObjectReference); -// serialization_test!(UnresolvedProgrammableTransaction); -// serialization_test!(UnresolvedTransaction); serialization_test!(Upgrade); serialization_test!(Identifier); serialization_test!(StructTag); diff --git a/crates/sui-sdk-types/src/transaction/mod.rs b/crates/sui-sdk-types/src/transaction/mod.rs index 9344c94b2..b5ea8c836 100644 --- a/crates/sui-sdk-types/src/transaction/mod.rs +++ b/crates/sui-sdk-types/src/transaction/mod.rs @@ -35,7 +35,6 @@ pub struct Transaction { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct SignedTransaction { pub transaction: Transaction, @@ -58,16 +57,13 @@ pub enum TransactionExpiration { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct GasPayment { pub objects: Vec, pub owner: Address, #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub price: u64, #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub budget: u64, } @@ -76,27 +72,22 @@ pub struct GasPayment { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct RandomnessStateUpdate { /// Epoch of the randomness state update transaction #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: u64, /// Randomness round of the update #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub randomness_round: u64, /// Updated random bytes #[cfg_attr( feature = "serde", serde(with = "crate::_serde::ReadableBase64Encoded") )] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] pub random_bytes: Vec, /// The initial version of the randomness object that it was shared at. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub randomness_obj_initial_shared_version: u64, // to version this struct, do not add new fields. Instead, add a RandomnessStateUpdateV2 to // TransactionKind. @@ -137,11 +128,6 @@ pub enum TransactionKind { /// EndOfEpochTransactionKind #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "kind", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum EndOfEpochTransactionKind { ChangeEpoch(ChangeEpoch), @@ -153,7 +139,6 @@ pub enum EndOfEpochTransactionKind { chain_id: super::CheckpointDigest, }, BridgeCommitteeInit { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] bridge_object_version: u64, }, } @@ -163,16 +148,13 @@ pub enum EndOfEpochTransactionKind { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct AuthenticatorStateExpire { /// expire JWKs that have a lower epoch than this #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub min_epoch: u64, /// The initial version of the authenticator object that it was shared at. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub authenticator_object_initial_shared_version: u64, } @@ -181,22 +163,18 @@ pub struct AuthenticatorStateExpire { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct AuthenticatorStateUpdate { /// Epoch of the authenticator state update transaction #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: u64, /// Consensus round of the authenticator state update #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub round: u64, /// newly active jwks pub new_active_jwks: Vec, /// The initial version of the authenticator object that it was shared at. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub authenticator_obj_initial_shared_version: u64, // to version this struct, do not add new fields. Instead, add a AuthenticatorStateUpdateV2 to // TransactionKind. @@ -207,14 +185,12 @@ pub struct AuthenticatorStateUpdate { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ActiveJwk { pub jwk_id: JwkId, pub jwk: Jwk, // the most recent epoch in which the jwk was validated #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: u64, } @@ -225,20 +201,16 @@ pub struct ActiveJwk { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ConsensusCommitPrologue { /// Epoch of the commit prologue transaction #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: u64, /// Consensus round of the commit #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub round: u64, /// Unix timestamp from consensus #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub commit_timestamp_ms: CheckpointTimestamp, } @@ -247,31 +219,22 @@ pub struct ConsensusCommitPrologue { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ConsensusCommitPrologueV2 { /// Epoch of the commit prologue transaction #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: u64, /// Consensus round of the commit #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub round: u64, /// Unix timestamp from consensus #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub commit_timestamp_ms: CheckpointTimestamp, /// Digest of consensus output pub consensus_commit_digest: ConsensusCommitDigest, } #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "kind", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum ConsensusDeterminedVersionAssignments { /// Cancelled transaction version assignment. @@ -286,7 +249,6 @@ pub enum ConsensusDeterminedVersionAssignments { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct CancelledTransaction { pub digest: TransactionDigest, @@ -299,12 +261,10 @@ pub struct CancelledTransaction { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct VersionAssignment { pub object_id: ObjectId, #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub version: Version, } @@ -313,16 +273,13 @@ pub struct VersionAssignment { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ConsensusCommitPrologueV3 { /// Epoch of the commit prologue transaction #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: u64, /// Consensus round of the commit #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub round: u64, /// The sub DAG index of the consensus commit. This field will be populated if there /// are multiple consensus commits per round. @@ -330,11 +287,9 @@ pub struct ConsensusCommitPrologueV3 { feature = "serde", serde(with = "crate::_serde::OptionReadableDisplay") )] - #[cfg_attr(feature = "schemars", schemars(with = "Option"))] pub sub_dag_index: Option, /// Unix timestamp from consensus #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub commit_timestamp_ms: CheckpointTimestamp, /// Digest of consensus output pub consensus_commit_digest: ConsensusCommitDigest, @@ -347,36 +302,28 @@ pub struct ConsensusCommitPrologueV3 { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ChangeEpoch { /// The next (to become) epoch ID. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch: EpochId, /// The protocol version in effect in the new epoch. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub protocol_version: ProtocolVersion, /// The total amount of gas charged for storage during the epoch. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub storage_charge: u64, /// The total amount of gas charged for computation during the epoch. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub computation_charge: u64, /// The amount of storage rebate refunded to the txn senders. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub storage_rebate: u64, /// The non-refundable storage fee. #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub non_refundable_storage_fee: u64, /// Unix timestamp when epoch started #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub epoch_start_timestamp_ms: u64, /// System packages (specifically framework and move stdlib) that are written before the new /// epoch starts. This tracks framework upgrades on chain. When executing the ChangeEpoch txn, @@ -392,11 +339,9 @@ pub struct ChangeEpoch { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct SystemPackage { #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))] - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] pub version: Version, #[cfg_attr( feature = "serde", @@ -404,7 +349,6 @@ pub struct SystemPackage { with = "::serde_with::As::>>" ) )] - #[cfg_attr(feature = "schemars", schemars(with = "Vec"))] #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))] pub modules: Vec>, pub dependencies: Vec, @@ -415,7 +359,6 @@ pub struct SystemPackage { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct GenesisTransaction { #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))] @@ -429,7 +372,6 @@ pub struct GenesisTransaction { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct ProgrammableTransaction { /// Input objects or primitive values @@ -442,16 +384,10 @@ pub struct ProgrammableTransaction { } #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "type", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum Input { // contains no structs or objects Pure { - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))] value: Vec, }, // A Move object, either immutable, or owned mutable. @@ -460,7 +396,6 @@ pub enum Input { // SharedObject::mutable controls whether caller asks for a mutable reference to shared object. Shared { object_id: ObjectId, - #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))] initial_shared_version: u64, mutable: bool, }, @@ -470,11 +405,6 @@ pub enum Input { /// A single command in a programmable transaction. #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr( - feature = "schemars", - derive(schemars::JsonSchema), - schemars(tag = "command", rename_all = "snake_case") -)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub enum Command { /// A call to either an entry or a public Move function @@ -512,7 +442,6 @@ pub enum Command { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct TransferObjects { #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))] @@ -525,7 +454,6 @@ pub struct TransferObjects { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct SplitCoins { pub coin: Argument, @@ -538,7 +466,6 @@ pub struct SplitCoins { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct MergeCoins { pub coin: Argument, @@ -551,7 +478,6 @@ pub struct MergeCoins { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Publish { #[cfg_attr( @@ -560,7 +486,6 @@ pub struct Publish { with = "::serde_with::As::>>" ) )] - #[cfg_attr(feature = "schemars", schemars(with = "Vec"))] pub modules: Vec>, pub dependencies: Vec, } @@ -570,7 +495,6 @@ pub struct Publish { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct MakeMoveVector { #[cfg_attr(feature = "serde", serde(rename = "type"))] @@ -584,7 +508,6 @@ pub struct MakeMoveVector { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Upgrade { #[cfg_attr( @@ -593,7 +516,6 @@ pub struct Upgrade { with = "::serde_with::As::>>" ) )] - #[cfg_attr(feature = "schemars", schemars(with = "Vec"))] pub modules: Vec>, pub dependencies: Vec, pub package: ObjectId, @@ -635,7 +557,6 @@ impl Argument { feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize) )] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct MoveCall { /// The package containing the module and function. diff --git a/crates/sui-sdk-types/src/transaction/serialization.rs b/crates/sui-sdk-types/src/transaction/serialization.rs index 3e04cdb05..9df1141e2 100644 --- a/crates/sui-sdk-types/src/transaction/serialization.rs +++ b/crates/sui-sdk-types/src/transaction/serialization.rs @@ -29,7 +29,6 @@ mod transaction { #[derive(serde_derive::Deserialize)] #[serde(tag = "version")] #[serde(rename = "Transaction")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] enum TransactionData { #[serde(rename = "1")] V1(TransactionV1), @@ -60,7 +59,6 @@ mod transaction { #[derive(serde_derive::Deserialize)] #[serde(rename = "TransactionV1")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] struct TransactionV1 { kind: TransactionKind, sender: Address, @@ -115,17 +113,6 @@ mod transaction { }) } } - - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for Transaction { - fn schema_name() -> String { - TransactionData::schema_name() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - TransactionData::json_schema(gen) - } - } } mod transaction_kind { @@ -160,7 +147,6 @@ mod transaction_kind { #[derive(serde_derive::Deserialize)] #[serde(tag = "kind", rename_all = "snake_case")] #[serde(rename = "TransactionKind")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] enum ReadableTransactionKind { ProgrammableTransaction(ProgrammableTransaction), ChangeEpoch(ChangeEpoch), @@ -175,17 +161,6 @@ mod transaction_kind { ConsensusCommitPrologueV3(ConsensusCommitPrologueV3), } - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for TransactionKind { - fn schema_name() -> String { - ReadableTransactionKind::schema_name() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - ReadableTransactionKind::json_schema(gen) - } - } - #[derive(serde_derive::Serialize)] enum BinaryTransactionKindRef<'a> { ProgrammableTransaction(&'a ProgrammableTransaction), @@ -743,7 +718,6 @@ mod argument { #[derive(serde_derive::Serialize, serde_derive::Deserialize)] #[serde(rename = "Argument", untagged, rename_all = "lowercase")] - #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] enum ReadableArgument { /// # Gas Gas(Gas), @@ -761,36 +735,6 @@ mod argument { Gas, } - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for Gas { - fn schema_name() -> std::string::String { - "GasArgument".to_owned() - } - - fn json_schema(_gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - schemars::schema::Schema::Object(schemars::schema::SchemaObject { - instance_type: Some(schemars::schema::InstanceType::String.into()), - enum_values: Some(vec!["gas".into()]), - ..Default::default() - }) - } - - fn is_referenceable() -> bool { - false - } - } - - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for Argument { - fn schema_name() -> String { - ReadableArgument::schema_name() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - ReadableArgument::json_schema(gen) - } - } - #[derive(serde_derive::Serialize, serde_derive::Deserialize)] enum BinaryArgument { Gas, @@ -1184,37 +1128,6 @@ mod transaction_expiration { } } } - - #[cfg(feature = "schemars")] - impl schemars::JsonSchema for TransactionExpiration { - fn schema_name() -> String { - "TransactionExpiration".into() - } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - use schemars::schema::Schema; - use schemars::schema::SchemaObject; - schemars::schema::Schema::Object(schemars::schema::SchemaObject { - subschemas: Some(Box::new(schemars::schema::SubschemaValidation { - one_of: Some(vec![ - schemars::_private::metadata::add_description( - schemars::_private::new_externally_tagged_enum( - "epoch", - gen.subschema_for::(), - ), - "Validators wont sign a transaction unless the expiration Epoch is greater than or equal to the current epoch", - ), - Schema::Object(SchemaObject { - instance_type: Some(schemars::schema::InstanceType::Null.into()), - ..SchemaObject::default() - }), - ]), - ..Default::default() - })), - ..Default::default() - }) - } - } } #[cfg(test)] diff --git a/crates/sui-sdk-types/src/type_tag/serialization.rs b/crates/sui-sdk-types/src/type_tag/serialization.rs index 4ce0547a4..b168fec40 100644 --- a/crates/sui-sdk-types/src/type_tag/serialization.rs +++ b/crates/sui-sdk-types/src/type_tag/serialization.rs @@ -244,83 +244,6 @@ impl<'de> Deserialize<'de> for StructTag { } } -#[cfg(feature = "schemars")] -mod json_schema { - use super::*; - use schemars::schema::InstanceType; - use schemars::schema::Metadata; - use schemars::schema::SchemaObject; - use schemars::schema::StringValidation; - use schemars::JsonSchema; - - pub(crate) static ALLOWED_IDENTIFIERS: &str = - r"(?:[a-zA-Z][a-zA-Z0-9_]{0,127})|(?:_[a-zA-Z0-9_]{0,127})"; - - impl JsonSchema for Identifier { - fn schema_name() -> String { - "Identifier".to_owned() - } - - fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - SchemaObject { - metadata: Some(Box::new(Metadata { - title: Some(Self::schema_name()), - description: Some("A Move Identifier".to_owned()), - examples: vec![serde_json::json!("sui")], - ..Default::default() - })), - instance_type: Some(InstanceType::String.into()), - string: Some(Box::new(StringValidation { - pattern: Some(ALLOWED_IDENTIFIERS.to_owned()), - ..Default::default() - })), - ..Default::default() - } - .into() - } - } - - impl JsonSchema for TypeTag { - fn schema_name() -> String { - "TypeTag".to_owned() - } - - fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - SchemaObject { - metadata: Some(Box::new(Metadata { - title: Some(Self::schema_name()), - description: Some("A Move TypeTag".to_owned()), - examples: vec![serde_json::json!("vector")], - ..Default::default() - })), - instance_type: Some(InstanceType::String.into()), - ..Default::default() - } - .into() - } - } - - impl JsonSchema for StructTag { - fn schema_name() -> String { - "StructTag".to_owned() - } - - fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - SchemaObject { - metadata: Some(Box::new(Metadata { - title: Some(Self::schema_name()), - description: Some("A Move StructTag".to_owned()), - examples: vec![serde_json::json!("0x2::coin::Coin<0x2::sui::SUI>")], - ..Default::default() - })), - instance_type: Some(InstanceType::String.into()), - ..Default::default() - } - .into() - } - } -} - #[cfg(test)] mod test { use super::*; diff --git a/crates/sui-transaction-builder/Cargo.toml b/crates/sui-transaction-builder/Cargo.toml index c88c02cde..1a63b5b18 100644 --- a/crates/sui-transaction-builder/Cargo.toml +++ b/crates/sui-transaction-builder/Cargo.toml @@ -8,10 +8,6 @@ publish = false readme = "README.md" description = "Transaction API for the Rust SDK for the Sui Blockchain" -[features] -default = [] -schemars = ["dep:schemars", "sui-types/schemars"] - [dependencies] base64ct = "1.6" bcs = "0.1.6" @@ -21,9 +17,6 @@ sui-types = { package = "sui-sdk-types", path = "../sui-sdk-types", features = [ thiserror = "2.0" serde_json = { version = "1.0.128" } -# JsonSchema definitions for types, useful for generating an OpenAPI Specificaiton. -schemars = { version = "0.8.21", optional = true } - [dev-dependencies] anyhow = "1.0" rand = "0.8" diff --git a/crates/sui-transaction-builder/src/unresolved.rs b/crates/sui-transaction-builder/src/unresolved.rs index 0ca0d21b8..4d60665bd 100644 --- a/crates/sui-transaction-builder/src/unresolved.rs +++ b/crates/sui-transaction-builder/src/unresolved.rs @@ -9,7 +9,6 @@ use sui_types::Version; // transaction using this type by providing all the required data. #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "UnresolvedTransaction")] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Transaction { #[serde(flatten)] pub ptb: ProgrammableTransaction, @@ -21,7 +20,6 @@ pub struct Transaction { #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "UnresolvedProgrammableTransaction")] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct ProgrammableTransaction { pub inputs: Vec, pub commands: Vec, @@ -29,7 +27,6 @@ pub struct ProgrammableTransaction { #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "UnresolvedGasPayment")] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct GasPayment { #[serde(default, skip_serializing_if = "Vec::is_empty")] pub objects: Vec, @@ -39,19 +36,16 @@ pub struct GasPayment { default, skip_serializing_if = "Option::is_none" )] - #[cfg_attr(feature = "schemars", schemars(with = "Option<_schemars::U64>"))] pub price: Option, #[serde( with = "OptionReadableDisplay", default, skip_serializing_if = "Option::is_none" )] - #[cfg_attr(feature = "schemars", schemars(with = "Option<_schemars::U64>"))] pub budget: Option, } #[derive(Clone, Debug)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "UnresolvedObjectReference")] pub struct ObjectReference { @@ -61,14 +55,12 @@ pub struct ObjectReference { default, skip_serializing_if = "Option::is_none" )] - #[cfg_attr(feature = "schemars", schemars(with = "Option<_schemars::U64>"))] pub version: Option, #[serde(skip_serializing_if = "Option::is_none")] pub digest: Option, } #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "UnresolvedInputKind")] #[serde(rename_all = "snake_case")] @@ -87,7 +79,6 @@ pub enum InputKind { /// If used in the context of transaction builder, make sure to call `tx.resolve` function on the /// transaction builder to resolve all unresolved inputs. #[derive(Clone, Debug, Default, PartialEq, Eq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "UnresolvedInput")] pub struct Input { @@ -109,7 +100,6 @@ pub struct Input { skip_serializing_if = "Option::is_none", alias = "initial_shared_version" )] - #[cfg_attr(feature = "schemars", schemars(with = "Option<_schemars::U64>"))] pub version: Option, /// The digest of this object. This field is only relevant for owned/immutable/receiving /// inputs. @@ -121,7 +111,6 @@ pub struct Input { } #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema), schemars(untagged))] #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "UnresolvedValue")] #[serde(try_from = "serde_json::Value", into = "serde_json::Value")] @@ -336,36 +325,3 @@ impl From for Input { pub(crate) type OptionReadableDisplay = ::serde_with::As>>; - -#[cfg(feature = "schemars")] -mod _schemars { - use schemars::schema::InstanceType; - use schemars::schema::Metadata; - use schemars::schema::SchemaObject; - use schemars::JsonSchema; - - pub(crate) struct U64; - - impl JsonSchema for U64 { - fn schema_name() -> String { - "u64".to_owned() - } - - fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - SchemaObject { - metadata: Some(Box::new(Metadata { - description: Some("Radix-10 encoded 64-bit unsigned integer".to_owned()), - ..Default::default() - })), - instance_type: Some(InstanceType::String.into()), - format: Some("u64".to_owned()), - ..Default::default() - } - .into() - } - - fn is_referenceable() -> bool { - false - } - } -}