From 657adbdfb65030cee7356e786e162a69d5bbd900 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Sun, 7 Apr 2024 06:05:01 +0700 Subject: [PATCH] work on more feature reduction --- Cargo.lock | 192 +----------------- packages/rs-dpp/Cargo.toml | 16 +- .../created_data_contract/mod.rs | 1 + .../created_data_contract/v0/mod.rs | 21 +- .../document_type/property/mod.rs | 5 +- .../data_contract/serialized_version/mod.rs | 1 + .../src/document/extended_document/mod.rs | 6 +- .../src/errors/consensus/basic/basic_error.rs | 14 +- .../consensus/basic/data_contract/mod.rs | 2 + .../rs-dpp/src/errors/consensus/basic/mod.rs | 2 + packages/rs-dpp/src/errors/consensus/codes.rs | 3 + packages/rs-dpp/src/errors/dpp_init_error.rs | 22 +- packages/rs-dpp/src/lib.rs | 2 + .../abstract_state_transition.rs | 3 + .../v0/state_transition_like.rs | 6 +- .../documents_batch_transition/mod.rs | 4 +- .../v0/state_transition_like.rs | 6 +- .../v0/state_transition_like.rs | 4 +- .../v0/state_transition_like.rs | 4 +- .../v0/state_transition_like.rs | 4 +- .../v0/state_transition_like.rs | 4 +- .../v0/state_transition_like.rs | 4 +- .../rs-dpp/src/tests/utils/error_helpers.rs | 110 ---------- packages/rs-dpp/src/tests/utils/mod.rs | 3 - .../rs-dpp/src/util/cbor_value/convert.rs | 8 +- packages/rs-dpp/src/util/deserializer.rs | 6 +- packages/rs-drive/Cargo.toml | 43 ++-- .../src/drive/cache/system_contracts.rs | 1 - .../src/drive/contract/contract_fetch_info.rs | 2 - packages/rs-drive/src/drive/contract/mod.rs | 33 +-- .../rs-drive/src/drive/document/query/mod.rs | 18 +- packages/rs-drive/src/query/mod.rs | 7 +- packages/rs-platform-value/Cargo.toml | 16 +- .../btreemap_field_replacement.rs | 10 +- .../btreemap_path_extensions.rs | 11 +- .../src/btreemap_extensions/mod.rs | 9 +- .../rs-platform-value/src/converter/mod.rs | 2 + .../src/converter/serde_json.rs | 10 +- packages/rs-platform-value/src/display.rs | 14 +- .../rs-platform-value/src/string_encoding.rs | 6 +- .../rs-platform-value/src/system_bytes.rs | 18 +- .../src/types/binary_data.rs | 6 +- .../rs-platform-value/src/types/bytes_20.rs | 6 +- .../rs-platform-value/src/types/bytes_32.rs | 6 +- .../rs-platform-value/src/types/bytes_36.rs | 6 +- .../rs-platform-value/src/types/identifier.rs | 2 + .../src/value_serialization/de.rs | 10 +- .../src/value_serialization/ser.rs | 10 +- packages/wasm-dpp/src/errors/from.rs | 1 - 49 files changed, 228 insertions(+), 472 deletions(-) delete mode 100644 packages/rs-dpp/src/tests/utils/error_helpers.rs diff --git a/Cargo.lock b/Cargo.lock index 82f9690d69..4e7e919947 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -630,12 +630,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - [[package]] name = "cc" version = "1.0.90" @@ -717,17 +711,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "bitflags 1.3.2", - "textwrap", - "unicode-width", -] - [[package]] name = "clap" version = "4.5.4" @@ -882,42 +865,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "criterion" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" -dependencies = [ - "atty", - "cast", - "clap 2.34.0", - "criterion-plot", - "csv", - "itertools 0.10.5", - "lazy_static", - "num-traits", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_cbor", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876" -dependencies = [ - "cast", - "itertools 0.10.5", -] - [[package]] name = "crossbeam-channel" version = "0.5.12" @@ -927,16 +874,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "crossbeam-deque" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - [[package]] name = "crossbeam-epoch" version = "0.9.18" @@ -962,27 +899,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "csv" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" -dependencies = [ - "csv-core", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" -dependencies = [ - "memchr", -] - [[package]] name = "curve25519-dalek" version = "4.1.2" @@ -1252,7 +1168,7 @@ version = "1.0.0-dev.10" dependencies = [ "anyhow", "async-trait", - "base64 0.20.0", + "base64 0.22.0", "bincode", "bls-signatures", "bs58 0.4.0", @@ -1307,7 +1223,6 @@ dependencies = [ "byteorder", "chrono", "ciborium", - "criterion", "derive_more", "dpp", "enum-map", @@ -1326,7 +1241,6 @@ dependencies = [ "platform-version", "rand", "serde", - "serde_json", "sqlparser", "tempfile", "thiserror", @@ -1344,7 +1258,7 @@ dependencies = [ "bincode", "chrono", "ciborium", - "clap 4.5.4", + "clap", "console-subscriber", "dapi-grpc", "dashcore-rpc", @@ -2169,7 +2083,6 @@ checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown 0.14.3", - "serde", ] [[package]] @@ -2819,12 +2732,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - [[package]] name = "openssl-probe" version = "0.1.5" @@ -2964,9 +2871,9 @@ dependencies = [ name = "platform-value" version = "1.0.0-dev.10" dependencies = [ - "base64 0.13.1", + "base64 0.22.0", "bincode", - "bs58 0.4.0", + "bs58 0.5.1", "ciborium", "hex", "indexmap 2.2.6", @@ -2978,7 +2885,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "treediff 4.0.3", + "treediff 5.0.0", ] [[package]] @@ -3011,34 +2918,6 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" -[[package]] -name = "plotters" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" - -[[package]] -name = "plotters-svg" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" -dependencies = [ - "plotters-backend", -] - [[package]] name = "polling" version = "2.8.0" @@ -3394,26 +3273,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "rayon" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -3565,7 +3424,7 @@ dependencies = [ "bincode", "bip37-bloom-filter", "ciborium", - "clap 4.5.4", + "clap", "dapi-grpc", "dapi-grpc-macros", "dashcore-rpc", @@ -3873,16 +3732,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_cbor" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" -dependencies = [ - "half", - "serde", -] - [[package]] name = "serde_derive" version = "1.0.197" @@ -4371,15 +4220,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.58" @@ -4441,16 +4281,6 @@ dependencies = [ "time-core", ] -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -4785,9 +4615,9 @@ dependencies = [ [[package]] name = "treediff" -version = "4.0.3" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d127780145176e2b5d16611cc25a900150e86e9fd79d3bde6ff3a37359c9cb5" +checksum = "e2ce481b2b7c2534fe7b5242cccebf37f9084392665c6a3783c414a1bada5432" [[package]] name = "triomphe" @@ -4837,12 +4667,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" - [[package]] name = "unicode-xid" version = "0.2.4" diff --git a/packages/rs-dpp/Cargo.toml b/packages/rs-dpp/Cargo.toml index 6bce21f3ea..ee69653565 100644 --- a/packages/rs-dpp/Cargo.toml +++ b/packages/rs-dpp/Cargo.toml @@ -14,7 +14,7 @@ authors = [ [dependencies] anyhow = { version = "1.0.81" } async-trait = { version = "0.1.79" } -base64 = "0.20.0" +base64 = "0.22.0" bls-signatures = { git = "https://github.com/dashpay/bls-signatures", tag = "v1.3.1", optional = true } bs58 = "0.4.0" byteorder = { version = "1.4" } @@ -39,7 +39,7 @@ json-patch = "0.2.6" jsonptr = "0.1.5" jsonschema = { git = "https://github.com/fominok/jsonschema-rs", branch = "feat-unevaluated-properties", default-features = false, features = [ "draft202012", -] } +], optional = true } lazy_static = { version = "1.4" } log = { version = "0.4.6" } num_enum = "0.5.7" @@ -58,11 +58,11 @@ platform-versioning = { path = "../rs-platform-versioning" } platform-serialization = { path = "../rs-platform-serialization" } platform-serialization-derive = { path = "../rs-platform-serialization-derive" } derive_more = "0.99.17" -ed25519-dalek = { version = "2.0.0-rc.2", features = ["rand_core"] } +ed25519-dalek = { version = "2.0.0-rc.2", features = ["rand_core"], optional = true } nohash-hasher = "0.2.0" rust_decimal = "1.29.1" rust_decimal_macros = "1.29.1" -indexmap = { version = "2.0.2", features = ["serde"] } +indexmap = { version = "2.0.2"} strum = { version = "0.25.0", features = ["derive"] } [dev-dependencies] @@ -185,10 +185,14 @@ abci = [ ] cbor = ["ciborium"] validation = [ + "json-schema-validation", "platform-value", "document-value-conversion", "state-transition-serde-conversion", + "ed25519-dalek" ] +platform-value-json = ["platform-value/json"] +json-schema-validation = ["jsonschema", "platform-value-json"] json-object = ["platform-value"] platform-value = [] identity-hashing = ["identity-serialization"] @@ -221,8 +225,8 @@ state-transition-validation = ["state-transitions", "message-signature-verificat state-transition-signing = ["state-transitions", "message-signing", "state-transition-validation"] state-transitions = [] system_contracts = ["factories", "data-contracts"] -fixtures-and-mocks = ["system_contracts"] -random-public-keys = ["bls-signatures"] +fixtures-and-mocks = ["system_contracts", "platform-value/json"] +random-public-keys = ["bls-signatures", "ed25519-dalek"] random-identities = ["random-public-keys"] random-documents = [] random-document-types = [] diff --git a/packages/rs-dpp/src/data_contract/created_data_contract/mod.rs b/packages/rs-dpp/src/data_contract/created_data_contract/mod.rs index 666725651c..f988047574 100644 --- a/packages/rs-dpp/src/data_contract/created_data_contract/mod.rs +++ b/packages/rs-dpp/src/data_contract/created_data_contract/mod.rs @@ -16,6 +16,7 @@ use crate::serialization::{ PlatformSerializableWithPlatformVersion, }; use crate::ProtocolError::{PlatformDeserializationError, PlatformSerializationError}; +#[cfg(feature = "data-contract-value-conversion")] use platform_value::Value; use platform_version::TryIntoPlatformVersioned; diff --git a/packages/rs-dpp/src/data_contract/created_data_contract/v0/mod.rs b/packages/rs-dpp/src/data_contract/created_data_contract/v0/mod.rs index dd99aecddf..349f110605 100644 --- a/packages/rs-dpp/src/data_contract/created_data_contract/v0/mod.rs +++ b/packages/rs-dpp/src/data_contract/created_data_contract/v0/mod.rs @@ -2,16 +2,23 @@ use crate::data_contract::DataContract; use bincode::{Decode, Encode}; #[cfg(feature = "data-contract-value-conversion")] -use crate::data_contract::conversion::value::v0::DataContractValueConversionMethodsV0; -use crate::data_contract::created_data_contract::fields::property_names::{ - DATA_CONTRACT, IDENTITY_NONCE, +use crate::{ + data_contract::{ + conversion::value::v0::DataContractValueConversionMethodsV0, + created_data_contract::fields::property_names::{ + DATA_CONTRACT, IDENTITY_NONCE, + } + }, + version::PlatformVersion, + ProtocolError, +}; +#[cfg(feature = "data-contract-value-conversion")] +use platform_value::{ + btreemap_extensions::BTreeValueRemoveFromMapHelper, + Error, Value }; use crate::data_contract::serialized_version::DataContractInSerializationFormat; use crate::prelude::IdentityNonce; -use crate::version::PlatformVersion; -use crate::ProtocolError; -use platform_value::btreemap_extensions::BTreeValueRemoveFromMapHelper; -use platform_value::{Error, Value}; // TODO: Decide on what we need ExtendedDataContract with metadata or CreatedDataContract or both. #[derive(Clone, Debug, PartialEq)] diff --git a/packages/rs-dpp/src/data_contract/document_type/property/mod.rs b/packages/rs-dpp/src/data_contract/document_type/property/mod.rs index 9910d4af4e..cfe1b52e40 100644 --- a/packages/rs-dpp/src/data_contract/document_type/property/mod.rs +++ b/packages/rs-dpp/src/data_contract/document_type/property/mod.rs @@ -15,21 +15,20 @@ use platform_value::Value; use rand::distributions::{Alphanumeric, Standard}; use rand::rngs::StdRng; use rand::Rng; -use serde::{Deserialize, Serialize}; pub mod array; // This struct will be changed in future to support more validation logic and serialization // It will become versioned and it will be introduced by a new document type version // @append_only -#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone)] pub struct DocumentProperty { pub property_type: DocumentPropertyType, pub required: bool, } // @append_only -#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone)] pub enum DocumentPropertyType { ///Todo decompose integer Integer, diff --git a/packages/rs-dpp/src/data_contract/serialized_version/mod.rs b/packages/rs-dpp/src/data_contract/serialized_version/mod.rs index eaf86bdd68..79879a9754 100644 --- a/packages/rs-dpp/src/data_contract/serialized_version/mod.rs +++ b/packages/rs-dpp/src/data_contract/serialized_version/mod.rs @@ -11,6 +11,7 @@ use derive_more::From; use platform_value::{Identifier, Value}; use platform_version::TryFromPlatformVersioned; use platform_versioning::PlatformVersioned; +#[cfg(feature = "data-contract-serde-conversion")] use serde::{Deserialize, Serialize}; pub(in crate::data_contract) mod v0; diff --git a/packages/rs-dpp/src/document/extended_document/mod.rs b/packages/rs-dpp/src/document/extended_document/mod.rs index a7fefc20bd..f5cf7919c2 100644 --- a/packages/rs-dpp/src/document/extended_document/mod.rs +++ b/packages/rs-dpp/src/document/extended_document/mod.rs @@ -338,6 +338,8 @@ mod test { use crate::data_contract::document_type::random_document::CreateRandomDocument; use crate::document::serialization_traits::ExtendedDocumentPlatformConversionMethodsV0; use crate::tests::fixtures::get_dashpay_contract_fixture; + use base64::Engine; + use base64::prelude::BASE64_STANDARD; fn init() { let _ = env_logger::builder() @@ -611,11 +613,11 @@ mod test { ); assert_eq!( json_document["alphaBinary"], - JsonValue::String(base64::encode(&alpha_value)) + JsonValue::String(BASE64_STANDARD.encode(&alpha_value)) ); assert_eq!( json_document["alphaIdentifier"], - JsonValue::String(base64::encode(&alpha_value)) + JsonValue::String(BASE64_STANDARD.encode(&alpha_value)) ); } diff --git a/packages/rs-dpp/src/errors/consensus/basic/basic_error.rs b/packages/rs-dpp/src/errors/consensus/basic/basic_error.rs index 1005ccce31..8ecc10cd03 100644 --- a/packages/rs-dpp/src/errors/consensus/basic/basic_error.rs +++ b/packages/rs-dpp/src/errors/consensus/basic/basic_error.rs @@ -11,10 +11,12 @@ use crate::consensus::basic::data_contract::{ IncompatibleDataContractSchemaError, IncompatibleRe2PatternError, InvalidCompoundIndexError, InvalidDataContractIdError, InvalidDataContractVersionError, InvalidDocumentTypeNameError, InvalidDocumentTypeRequiredSecurityLevelError, InvalidIndexPropertyTypeError, - InvalidIndexedPropertyConstraintError, InvalidJsonSchemaRefError, + InvalidIndexedPropertyConstraintError, SystemPropertyIndexAlreadyPresentError, UndefinedIndexPropertyError, UniqueIndicesLimitReachedError, UnknownSecurityLevelError, UnknownStorageKeyRequirementsError, }; +#[cfg(feature = "json-schema-validation")] +use crate::consensus::basic::data_contract::InvalidJsonSchemaRefError; use crate::consensus::basic::decode::{ ProtocolVersionParsingError, SerializedObjectParsingError, VersionError, }; @@ -56,8 +58,11 @@ use crate::consensus::basic::state_transition::{ use crate::consensus::basic::{IncompatibleProtocolVersionError, UnsupportedProtocolVersionError}; use crate::consensus::ConsensusError; -use crate::consensus::basic::json_schema_compilation_error::JsonSchemaCompilationError; -use crate::consensus::basic::json_schema_error::JsonSchemaError; +#[cfg(feature = "json-schema-validation")] +use crate::consensus::basic::{ + json_schema_compilation_error::JsonSchemaCompilationError, + json_schema_error::JsonSchemaError, +}; use crate::consensus::basic::unsupported_version_error::UnsupportedVersionError; use crate::consensus::basic::value_error::ValueError; use crate::consensus::state::identity::master_public_key_update_error::MasterPublicKeyUpdateError; @@ -98,10 +103,12 @@ pub enum BasicError { #[error(transparent)] IncompatibleProtocolVersionError(IncompatibleProtocolVersionError), + #[cfg(feature = "json-schema-validation")] // Structure error #[error(transparent)] JsonSchemaCompilationError(JsonSchemaCompilationError), + #[cfg(feature = "json-schema-validation")] #[error(transparent)] JsonSchemaError(JsonSchemaError), @@ -133,6 +140,7 @@ pub enum BasicError { #[error(transparent)] InvalidIndexPropertyTypeError(InvalidIndexPropertyTypeError), + #[cfg(feature = "json-schema-validation")] #[error(transparent)] InvalidJsonSchemaRefError(InvalidJsonSchemaRefError), diff --git a/packages/rs-dpp/src/errors/consensus/basic/data_contract/mod.rs b/packages/rs-dpp/src/errors/consensus/basic/data_contract/mod.rs index 5a5fdb4457..e82ffc305e 100644 --- a/packages/rs-dpp/src/errors/consensus/basic/data_contract/mod.rs +++ b/packages/rs-dpp/src/errors/consensus/basic/data_contract/mod.rs @@ -15,6 +15,7 @@ mod invalid_document_type_name_error; mod invalid_document_type_required_security_level; mod invalid_index_property_type_error; mod invalid_indexed_property_constraint_error; +#[cfg(feature = "json-schema-validation")] mod invalid_json_schema_ref_error; mod system_property_index_already_present_error; mod undefined_index_property_error; @@ -37,6 +38,7 @@ pub use invalid_data_contract_version_error::*; pub use invalid_document_type_required_security_level::*; pub use invalid_index_property_type_error::*; pub use invalid_indexed_property_constraint_error::*; +#[cfg(feature = "json-schema-validation")] pub use invalid_json_schema_ref_error::*; pub use system_property_index_already_present_error::*; diff --git a/packages/rs-dpp/src/errors/consensus/basic/mod.rs b/packages/rs-dpp/src/errors/consensus/basic/mod.rs index 1c417e2ee8..d38bbe0938 100644 --- a/packages/rs-dpp/src/errors/consensus/basic/mod.rs +++ b/packages/rs-dpp/src/errors/consensus/basic/mod.rs @@ -12,7 +12,9 @@ pub mod unsupported_protocol_version_error; pub mod basic_error; pub mod invalid_identifier_error; +#[cfg(feature = "json-schema-validation")] pub mod json_schema_compilation_error; +#[cfg(feature = "json-schema-validation")] pub mod json_schema_error; pub mod state_transition; pub mod unsupported_version_error; diff --git a/packages/rs-dpp/src/errors/consensus/codes.rs b/packages/rs-dpp/src/errors/consensus/codes.rs index 5d597a6c5e..92a6187aa7 100644 --- a/packages/rs-dpp/src/errors/consensus/codes.rs +++ b/packages/rs-dpp/src/errors/consensus/codes.rs @@ -38,7 +38,9 @@ impl ErrorWithCode for BasicError { Self::VersionError(_) => 10005, // Structure Errors: 10100-10199 + #[cfg(feature = "json-schema-validation")] Self::JsonSchemaCompilationError(..) => 10100, + #[cfg(feature = "json-schema-validation")] Self::JsonSchemaError(_) => 10101, Self::InvalidIdentifierError { .. } => 10102, Self::ValueError(_) => 10103, @@ -51,6 +53,7 @@ impl ErrorWithCode for BasicError { Self::InvalidDataContractIdError { .. } => 10204, Self::InvalidIndexedPropertyConstraintError { .. } => 10205, Self::InvalidIndexPropertyTypeError { .. } => 10206, + #[cfg(feature = "json-schema-validation")] Self::InvalidJsonSchemaRefError { .. } => 10207, Self::SystemPropertyIndexAlreadyPresentError { .. } => 10208, Self::UndefinedIndexPropertyError { .. } => 10209, diff --git a/packages/rs-dpp/src/errors/dpp_init_error.rs b/packages/rs-dpp/src/errors/dpp_init_error.rs index 9fa82c3f6f..42cc6fda52 100644 --- a/packages/rs-dpp/src/errors/dpp_init_error.rs +++ b/packages/rs-dpp/src/errors/dpp_init_error.rs @@ -1,15 +1,10 @@ -use std::borrow::Cow; - use crate::version::FeatureVersion; -use jsonschema::ValidationError; use thiserror::Error; #[derive(Error, Debug)] pub enum DashPlatformProtocolInitError { #[error(transparent)] SchemaDeserializationError(serde_json::Error), - #[error(transparent)] - ValidationError(ValidationError<'static>), #[error("Loaded Schema is invalid: {0}")] InvalidSchemaError(&'static str), #[error("platform init unknown version on {method}, received: {received}")] @@ -23,23 +18,8 @@ pub enum DashPlatformProtocolInitError { }, } -fn into_owned(err: ValidationError) -> ValidationError<'static> { - ValidationError { - instance_path: err.instance_path.clone(), - instance: Cow::Owned(err.instance.into_owned()), - kind: err.kind, - schema_path: err.schema_path, - } -} - impl From for DashPlatformProtocolInitError { fn from(error: serde_json::Error) -> Self { Self::SchemaDeserializationError(error) } -} - -impl<'a> From> for DashPlatformProtocolInitError { - fn from(err: ValidationError<'a>) -> Self { - Self::ValidationError(into_owned(err)) - } -} +} \ No newline at end of file diff --git a/packages/rs-dpp/src/lib.rs b/packages/rs-dpp/src/lib.rs index 2619f66c64..cef2d9f3e7 100644 --- a/packages/rs-dpp/src/lib.rs +++ b/packages/rs-dpp/src/lib.rs @@ -82,7 +82,9 @@ pub use bincode; pub use bls_signatures; #[cfg(feature = "system_contracts")] pub use data_contracts; +#[cfg(feature = "ed25519-dalek")] pub use ed25519_dalek; +#[cfg(feature = "jsonschema")] pub use jsonschema; pub use platform_serialization; pub use platform_value; diff --git a/packages/rs-dpp/src/state_transition/abstract_state_transition.rs b/packages/rs-dpp/src/state_transition/abstract_state_transition.rs index 47ab047381..7bd8e8f9f1 100644 --- a/packages/rs-dpp/src/state_transition/abstract_state_transition.rs +++ b/packages/rs-dpp/src/state_transition/abstract_state_transition.rs @@ -1,12 +1,15 @@ use serde::Serialize; +#[cfg(feature = "state-transition-json-conversion")] use serde_json::Value as JsonValue; pub mod state_transition_helpers { use super::*; use crate::ProtocolError; use platform_value::Value; + #[cfg(feature = "state-transition-json-conversion")] use std::convert::TryInto; + #[cfg(feature = "state-transition-json-conversion")] pub fn to_json<'a, I: IntoIterator>( serializable: impl Serialize, skip_signature_paths: I, diff --git a/packages/rs-dpp/src/state_transition/state_transitions/contract/data_contract_update_transition/v0/state_transition_like.rs b/packages/rs-dpp/src/state_transition/state_transitions/contract/data_contract_update_transition/v0/state_transition_like.rs index 5ada17858d..c0128f871f 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/contract/data_contract_update_transition/v0/state_transition_like.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/contract/data_contract_update_transition/v0/state_transition_like.rs @@ -1,3 +1,5 @@ +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use platform_value::BinaryData; use crate::prelude::UserFeeIncrease; @@ -45,8 +47,8 @@ impl StateTransitionLike for DataContractUpdateTransitionV0 { fn unique_identifiers(&self) -> Vec { vec![format!( "{}-{}-{:x}", - base64::encode(self.data_contract.owner_id()), - base64::encode(self.data_contract.id()), + BASE64_STANDARD.encode(self.data_contract.owner_id()), + BASE64_STANDARD.encode(self.data_contract.id()), self.identity_contract_nonce )] } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/mod.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/mod.rs index 046e6eee7b..f62e971fb7 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/mod.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/mod.rs @@ -96,7 +96,7 @@ pub enum DocumentsBatchTransition { // let maybe_signature = json_value.get_string(property_names::SIGNATURE).ok(); // let signature = if let Some(signature) = maybe_signature { // Some(BinaryData( -// base64::decode(signature).context("signature exists but isn't valid base64")?, +// BASE64_STANDARD.decode(signature).context("signature exists but isn't valid base64")?, // )) // } else { // None @@ -561,7 +561,7 @@ pub fn get_security_level_requirement(v: &Value, default: SecurityLevel) -> Secu // let data_contract_id = // Identifier::from_string(data_contract_id_base58, Encoding::Base58).unwrap(); // let owner_id = Identifier::from_string(owner_id_base58, Encoding::Base58).unwrap(); -// let entropy_bytes: [u8; 32] = base64::decode(entropy_base64).unwrap().try_into().unwrap(); +// let entropy_bytes: [u8; 32] = BASE64_STANDARD.decode(entropy_base64).unwrap().try_into().unwrap(); // // let mut data_contract = get_data_contract_fixture(Some(owner_id)).data_contract; // data_contract.id = data_contract_id; diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/v0/state_transition_like.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/v0/state_transition_like.rs index 4e7f896ef7..d971f3579d 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/v0/state_transition_like.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/v0/state_transition_like.rs @@ -1,3 +1,5 @@ +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use crate::prelude::UserFeeIncrease; use crate::state_transition::documents_batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods; use crate::state_transition::documents_batch_transition::document_transition::DocumentTransitionV0Methods; @@ -54,8 +56,8 @@ impl StateTransitionLike for DocumentsBatchTransitionV0 { .map(|transition| { format!( "{}-{}-{:x}", - base64::encode(self.owner_id), - base64::encode(transition.data_contract_id()), + BASE64_STANDARD.encode(self.owner_id), + BASE64_STANDARD.encode(transition.data_contract_id()), transition.identity_contract_nonce() ) }) diff --git a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_create_transition/v0/state_transition_like.rs b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_create_transition/v0/state_transition_like.rs index 9aa5ee38a6..f05d74c2ab 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_create_transition/v0/state_transition_like.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_create_transition/v0/state_transition_like.rs @@ -1,3 +1,5 @@ +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use platform_value::BinaryData; use crate::prelude::UserFeeIncrease; @@ -53,7 +55,7 @@ impl StateTransitionLike for IdentityCreateTransitionV0 { /// this is based on the asset lock fn unique_identifiers(&self) -> Vec { - vec![base64::encode(self.identity_id)] + vec![BASE64_STANDARD.encode(self.identity_id)] } fn user_fee_increase(&self) -> UserFeeIncrease { diff --git a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_transfer_transition/v0/state_transition_like.rs b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_transfer_transition/v0/state_transition_like.rs index 95133643c2..c3b2074d11 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_transfer_transition/v0/state_transition_like.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_transfer_transition/v0/state_transition_like.rs @@ -1,3 +1,5 @@ +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use platform_value::BinaryData; use crate::prelude::UserFeeIncrease; @@ -55,7 +57,7 @@ impl StateTransitionLike for IdentityCreditTransferTransitionV0 { fn unique_identifiers(&self) -> Vec { vec![format!( "{}-{:x}", - base64::encode(self.identity_id), + BASE64_STANDARD.encode(self.identity_id), self.nonce )] } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_withdrawal_transition/v0/state_transition_like.rs b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_withdrawal_transition/v0/state_transition_like.rs index 15c9358967..d35d9e1b0a 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_withdrawal_transition/v0/state_transition_like.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_withdrawal_transition/v0/state_transition_like.rs @@ -1,3 +1,5 @@ +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use platform_value::BinaryData; use crate::prelude::UserFeeIncrease; @@ -56,7 +58,7 @@ impl StateTransitionLike for IdentityCreditWithdrawalTransitionV0 { fn unique_identifiers(&self) -> Vec { vec![format!( "{}-{:x}", - base64::encode(self.identity_id), + BASE64_STANDARD.encode(self.identity_id), self.nonce )] } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_topup_transition/v0/state_transition_like.rs b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_topup_transition/v0/state_transition_like.rs index a04e462f90..ad9dc0971a 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_topup_transition/v0/state_transition_like.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_topup_transition/v0/state_transition_like.rs @@ -1,3 +1,5 @@ +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use platform_value::BinaryData; use crate::prelude::UserFeeIncrease; @@ -57,7 +59,7 @@ impl StateTransitionLike for IdentityTopUpTransitionV0 { let identifier = self.asset_lock_proof.create_identifier(); match identifier { Ok(identifier) => { - vec![base64::encode(identifier)] + vec![BASE64_STANDARD.encode(identifier)] } Err(_) => { // no unique identifier, this won't actually occur on Platform diff --git a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_update_transition/v0/state_transition_like.rs b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_update_transition/v0/state_transition_like.rs index 8145e1d385..dca658343a 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_update_transition/v0/state_transition_like.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_update_transition/v0/state_transition_like.rs @@ -1,3 +1,5 @@ +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use platform_value::BinaryData; use crate::prelude::UserFeeIncrease; @@ -55,7 +57,7 @@ impl StateTransitionLike for IdentityUpdateTransitionV0 { fn unique_identifiers(&self) -> Vec { vec![format!( "{}-{:x}", - base64::encode(self.identity_id), + BASE64_STANDARD.encode(self.identity_id), self.nonce )] } diff --git a/packages/rs-dpp/src/tests/utils/error_helpers.rs b/packages/rs-dpp/src/tests/utils/error_helpers.rs deleted file mode 100644 index fe53c3bb7a..0000000000 --- a/packages/rs-dpp/src/tests/utils/error_helpers.rs +++ /dev/null @@ -1,110 +0,0 @@ -use crate::consensus::basic::json_schema_error::JsonSchemaError; -use crate::consensus::basic::value_error::ValueError; -use crate::consensus::basic::BasicError; -use crate::consensus::fee::fee_error::FeeError; -use crate::consensus::signature::SignatureError; -use crate::consensus::state::state_error::StateError; -use crate::consensus::ConsensusError; -use crate::validation::{ConsensusValidationResult, SimpleConsensusValidationResult}; - -pub fn get_schema_error( - result: &SimpleConsensusValidationResult, - number: usize, -) -> &JsonSchemaError { - json_schema_error( - result - .errors - .get(number) - .expect("the error should be returned in validation result"), - ) -} - -pub fn get_basic_error(consensus_error: &ConsensusError) -> &BasicError { - match consensus_error { - ConsensusError::BasicError(basic_error) => basic_error, - _ => panic!("error '{:?}' isn't a basic error", consensus_error), - } -} - -// TODO: Not sure it should be here. Looks more like a test helper -pub fn json_schema_error(consensus_error: &ConsensusError) -> &JsonSchemaError { - match consensus_error { - ConsensusError::BasicError(BasicError::JsonSchemaError(err)) => err, - _ => panic!("error '{:?}' isn't a json schema error", consensus_error), - } -} - -pub fn value_error(consensus_error: &ConsensusError) -> &ValueError { - match consensus_error { - ConsensusError::BasicError(BasicError::ValueError(err)) => err, - _ => panic!("error '{:?}' isn't a value error", consensus_error), - } -} - -pub fn get_state_error_from_result( - result: &ConsensusValidationResult, - error_number: usize, -) -> &StateError { - match result - .errors - .get(error_number) - .expect("error should be found") - { - ConsensusError::StateError(state_error) => state_error, - _ => panic!( - "error '{:?}' isn't a state error", - result.errors[error_number] - ), - } -} - -pub fn get_basic_error_from_result( - result: &SimpleConsensusValidationResult, - error_number: usize, -) -> &BasicError { - match result - .errors - .get(error_number) - .expect("basic error should be found") - { - ConsensusError::BasicError(basic_error) => basic_error, - _ => panic!( - "error '{:?}' isn't a Basic error", - result.errors[error_number] - ), - } -} - -pub fn get_signature_error_from_result( - result: &ConsensusValidationResult, - error_number: usize, -) -> &SignatureError { - match result - .errors - .get(error_number) - .expect("error should be found") - { - ConsensusError::SignatureError(signature_error) => signature_error, - _ => panic!( - "error '{:?}' isn't a Signature error", - result.errors[error_number] - ), - } -} - -pub fn get_fee_error_from_result( - result: &ConsensusValidationResult, - error_number: usize, -) -> &FeeError { - match result - .errors - .get(error_number) - .expect("error should be found") - { - ConsensusError::FeeError(signature_error) => signature_error, - _ => panic!( - "error '{:?}' isn't a Fee error", - result.errors[error_number] - ), - } -} diff --git a/packages/rs-dpp/src/tests/utils/mod.rs b/packages/rs-dpp/src/tests/utils/mod.rs index ad4055a61b..0fc0b6d0e9 100644 --- a/packages/rs-dpp/src/tests/utils/mod.rs +++ b/packages/rs-dpp/src/tests/utils/mod.rs @@ -1,5 +1,2 @@ -pub use error_helpers::*; pub use utils::*; - -mod error_helpers; mod utils; diff --git a/packages/rs-dpp/src/util/cbor_value/convert.rs b/packages/rs-dpp/src/util/cbor_value/convert.rs index 18e8af258c..1d059ce5f6 100644 --- a/packages/rs-dpp/src/util/cbor_value/convert.rs +++ b/packages/rs-dpp/src/util/cbor_value/convert.rs @@ -1,4 +1,6 @@ use std::convert::TryInto; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use ciborium::value::Value as CborValue; @@ -40,7 +42,7 @@ pub(super) fn convert_to( FieldType::StringBase64 => { let text = cbor_value.as_text()?; - base64::decode(text).ok()? + BASE64_STANDARD.decode(text).ok()? } }; @@ -56,7 +58,7 @@ pub(super) fn convert_to( } FieldType::StringBase64 => { - let encoded = base64::encode(data_bytes); + let encoded = BASE64_STANDARD.encode(data_bytes); CborValue::Text(encoded) } }; @@ -96,6 +98,6 @@ mod tests { let result = convert_to(&cbor_value, FieldType::ArrayInt, FieldType::StringBase64) .expect("no error"); - assert_eq!(CborValue::Text(base64::encode(vec![0_u8; 32])), result); + assert_eq!(CborValue::Text(BASE64_STANDARD.encode(vec![0_u8; 32])), result); } } diff --git a/packages/rs-dpp/src/util/deserializer.rs b/packages/rs-dpp/src/util/deserializer.rs index b9dc94db20..221b054f42 100644 --- a/packages/rs-dpp/src/util/deserializer.rs +++ b/packages/rs-dpp/src/util/deserializer.rs @@ -70,12 +70,14 @@ pub fn split_cbor_feature_version( pub mod serde_entropy { use std::convert::TryInto; + use base64::Engine; + use base64::prelude::BASE64_STANDARD; use serde::{Deserialize, Deserializer, Serializer}; pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<[u8; 32], D::Error> { let data: String = Deserialize::deserialize(d)?; - base64::decode(&data) + BASE64_STANDARD.decode(&data) .map_err(|e| { serde::de::Error::custom(format!("Unable to decode {}' with base64 - {}", data, e)) })? @@ -92,6 +94,6 @@ pub mod serde_entropy { where S: Serializer, { - serializer.serialize_str(&base64::encode(buffer)) + serializer.serialize_str(&BASE64_STANDARD.encode(buffer)) } } diff --git a/packages/rs-drive/Cargo.toml b/packages/rs-drive/Cargo.toml index 559fb2c6ab..1a5c9587f3 100644 --- a/packages/rs-drive/Cargo.toml +++ b/packages/rs-drive/Cargo.toml @@ -25,7 +25,7 @@ indexmap = { version = "2.0.2" } sqlparser = { version = "0.38.0" } # used for int maps and needed in the verifier nohash-hasher = { version = "0.2.0" } -dpp = { path = "../rs-dpp", features = ["state-transitions", "fee-distribution"], default-features = false, optional = true } +dpp = { path = "../rs-dpp", features = ["state-transitions"], default-features = false, optional = true } thiserror = { version = "1.0.30" } tracing = { version = "0.1.37", default-features = false, features = [] } derive_more = { version = "0.99.17", optional = true} @@ -41,7 +41,6 @@ bs58 = { version = "0.5.0", optional = true } base64 = { version = "0.21.0", optional = true } hex = { version = "0.4.3", optional = true } tempfile = { version = "3", optional = true } -serde_json = { version = "1.0", features = ["preserve_order"], optional = true } enum-map = { version = "2.0.3", optional = true } intmap = { version = "2.0.0", features = ["serde"], optional = true } chrono = { version = "0.4.35", optional = true } @@ -52,22 +51,23 @@ grovedb-path = { git = "https://github.com/dashpay/grovedb", rev = "f5a3382c5537 grovedb-storage = { git = "https://github.com/dashpay/grovedb", rev = "f5a3382c5537de7417e983cdf2132792aa9fdc9d", optional = true } [dev-dependencies] -criterion = "0.3.5" -platform-version = { path = "../rs-platform-version", features = [ - "mock-versions", -] } -dpp = { path = "../rs-dpp", features = [ - "state-transitions", - "fee-distribution", - "document-cbor-conversion", - "random-documents", - "random-identities", - "random-public-keys", - "fixtures-and-mocks", - "system_contracts", - "factories", - "data-contract-json-conversion", -], default-features = false } +#criterion = "0.3.5" +#platform-version = { path = "../rs-platform-version", features = [ +# "mock-versions", +#] } +#dpp = { path = "../rs-dpp", features = [ +# "state-transitions", +# "fee-distribution", +# "document-cbor-conversion", +# "random-documents", +# "random-identities", +# "random-public-keys", +# "fixtures-and-mocks", +# "system_contracts", +# "factories", +# "data-contract-json-conversion", +#], default-features = false } +#serde_json = { version = "1.0", features = ["preserve_order"] } [[bench]] name = "benchmarks" @@ -75,14 +75,17 @@ harness = false [features] default = ["full", "verify", "fixtures-and-mocks"] +fee-distribution = ["dpp/fee-distribution"] fixtures-and-mocks = ["full", "dpp/fixtures-and-mocks", "verify", "dpp/data-contract-json-conversion", "dpp/random-public-keys"] server = [ "serde", "parking_lot", "arc-swap", "moka", + "dpp/platform-value-json", + "dpp/system_contracts", "dpp/state-transitions", - "dpp/fee-distribution", + "fee-distribution", "grovedb/full", "grovedb/estimated_costs", "grovedb-storage", @@ -98,11 +101,11 @@ full = [ "server", "ciborium", "serde", - "serde_json", "bs58", "tempfile", "base64", "chrono", ] +cbor_query = ["ciborium", "dpp/cbor"] grovedb_operations_logging = [] verify = ["grovedb/verify", "grovedb-costs", "dpp/state-transitions"] diff --git a/packages/rs-drive/src/drive/cache/system_contracts.rs b/packages/rs-drive/src/drive/cache/system_contracts.rs index b301d63cac..c1a2785c3c 100644 --- a/packages/rs-drive/src/drive/cache/system_contracts.rs +++ b/packages/rs-drive/src/drive/cache/system_contracts.rs @@ -5,7 +5,6 @@ use dpp::system_data_contracts::{load_system_data_contract, SystemDataContract}; use platform_version::version::PlatformVersion; use std::sync::Arc; -// TODO: Use ArcSwap /// System contracts pub struct SystemDataContracts { /// Withdrawal contract diff --git a/packages/rs-drive/src/drive/contract/contract_fetch_info.rs b/packages/rs-drive/src/drive/contract/contract_fetch_info.rs index 45c80895b3..034f5545c6 100644 --- a/packages/rs-drive/src/drive/contract/contract_fetch_info.rs +++ b/packages/rs-drive/src/drive/contract/contract_fetch_info.rs @@ -14,8 +14,6 @@ use dpp::tests::fixtures::get_masternode_reward_shares_data_contract_fixture; use grovedb_costs::OperationCost; #[cfg(feature = "fixtures-and-mocks")] use platform_version::version::PlatformVersion; - -#[cfg(any(feature = "server", feature = "verify"))] /// DataContract and fetch information #[derive(PartialEq, Debug, Clone)] pub struct DataContractFetchInfo { diff --git a/packages/rs-drive/src/drive/contract/mod.rs b/packages/rs-drive/src/drive/contract/mod.rs index a5ae344cf1..b0f73db3ff 100644 --- a/packages/rs-drive/src/drive/contract/mod.rs +++ b/packages/rs-drive/src/drive/contract/mod.rs @@ -1,32 +1,3 @@ -// MIT LICENSE -// -// Copyright (c) 2021 Dash Core Group -// -// Permission is hereby granted, free of charge, to any -// person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the -// Software without restriction, including without -// limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software -// is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice -// shall be included in all copies or substantial portions -// of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - //! DriveDataContracts. //! //! This module defines functions pertinent toDataContracts stored in Drive. @@ -34,7 +5,7 @@ #[cfg(feature = "server")] mod apply; -#[cfg(any(feature = "server", feature = "verify"))] +#[cfg(feature = "server")] mod contract_fetch_info; #[cfg(feature = "server")] mod estimation_costs; @@ -54,7 +25,7 @@ pub(crate) mod queries; pub mod test_helpers; #[cfg(feature = "server")] mod update; -#[cfg(any(feature = "server", feature = "verify"))] +#[cfg(feature = "server")] pub use contract_fetch_info::*; /// How many contracts to fetch at once. This is an arbitrary number and is needed to prevent diff --git a/packages/rs-drive/src/drive/document/query/mod.rs b/packages/rs-drive/src/drive/document/query/mod.rs index 5daa25ed23..421c2c03ca 100644 --- a/packages/rs-drive/src/drive/document/query/mod.rs +++ b/packages/rs-drive/src/drive/document/query/mod.rs @@ -133,7 +133,7 @@ impl Drive { // }) // } - #[cfg(feature = "fixtures-and-mocks")] + #[cfg(all(feature = "fixtures-and-mocks", feature = "cbor_query"))] /// Performs and returns the result of the specified query along with skipped items and the cost. pub fn query_raw_documents_from_contract_cbor_using_cbor_encoded_query_with_cost( &self, @@ -172,7 +172,7 @@ impl Drive { Ok((items, skipped, cost)) } - #[cfg(feature = "fixtures-and-mocks")] + #[cfg(all(feature = "fixtures-and-mocks", feature = "cbor_query"))] /// Performs and returns the result of the specified query along with the fee. /// Proof is generated. pub fn query_proof_of_documents_using_contract_id_using_cbor_encoded_query_with_cost( @@ -225,7 +225,7 @@ impl Drive { Ok((items, cost)) } - #[cfg(feature = "fixtures-and-mocks")] + #[cfg(all(feature = "fixtures-and-mocks", feature = "cbor_query"))] /// Performs and returns the result of the specified query along with the fee. /// Proof is generated. pub fn query_proof_of_documents_using_cbor_encoded_query_with_cost( @@ -263,7 +263,7 @@ impl Drive { Ok((items, cost)) } - #[cfg(feature = "fixtures-and-mocks")] + #[cfg(all(feature = "fixtures-and-mocks", feature = "cbor_query"))] /// Performs and returns the result of the specified internal query. /// Proof is generated. pub(crate) fn query_proof_of_documents_using_cbor_encoded_query( @@ -281,7 +281,7 @@ impl Drive { query.execute_with_proof_internal(self, transaction, drive_operations, platform_version) } - #[cfg(feature = "fixtures-and-mocks")] + #[cfg(all(feature = "fixtures-and-mocks", feature = "cbor_query"))] /// Performs the specified internal query and returns the root hash, values, and fee. pub fn query_proof_of_documents_using_cbor_encoded_query_only_get_elements( &self, @@ -320,7 +320,7 @@ impl Drive { } /// Performs the specified internal query and returns the root hash and values. - #[cfg(feature = "fixtures-and-mocks")] + #[cfg(all(feature = "fixtures-and-mocks", feature = "cbor_query"))] pub(crate) fn query_proof_of_documents_using_cbor_encoded_query_only_get_elements_internal( &self, contract: &DataContract, @@ -342,7 +342,7 @@ impl Drive { } /// Performs and returns the result of the specified query along with skipped items and the cost. - #[cfg(feature = "fixtures-and-mocks")] + #[cfg(all(feature = "fixtures-and-mocks", feature = "cbor_query"))] pub fn query_documents_cbor_from_contract( &self, contract: &DataContract, @@ -377,7 +377,7 @@ impl Drive { Ok((items, skipped, cost)) } - #[cfg(feature = "fixtures-and-mocks")] + #[cfg(all(feature = "fixtures-and-mocks", feature = "cbor_query"))] /// Performs and returns the result of the specified query along with skipped items and the cost. pub fn query_documents_cbor_with_document_type_lookup( &self, @@ -412,7 +412,7 @@ impl Drive { self.query_serialized_documents(query, epoch, transaction, platform_version) } - #[cfg(feature = "fixtures-and-mocks")] + #[cfg(all(feature = "fixtures-and-mocks", feature = "cbor_query"))] /// Performs and returns the result of the specified query along with skipped items. pub fn query_documents_for_cbor_query_internal( &self, diff --git a/packages/rs-drive/src/query/mod.rs b/packages/rs-drive/src/query/mod.rs index 932deb25e4..154f01449c 100644 --- a/packages/rs-drive/src/query/mod.rs +++ b/packages/rs-drive/src/query/mod.rs @@ -52,7 +52,7 @@ use { error::Error::GroveDB, fee::op::LowLevelDriveOperation, }, - dpp::{block::block_info::BlockInfo, platform_value::platform_value}, + dpp::block::block_info::BlockInfo, }; // Crate-local unconditional imports @@ -307,7 +307,7 @@ impl<'a> DriveQuery<'a> { == "$id"))) } - #[cfg(feature = "ciborium")] + #[cfg(feature = "cbor_query")] /// Converts a query CBOR to a `DriveQuery`. pub fn from_cbor( query_cbor: &[u8], @@ -747,7 +747,7 @@ impl<'a> DriveQuery<'a> { /// /// FIXME: The data contract is only refered as ID, and document type as its name. /// This can change in the future to include full data contract and document type. - #[cfg(feature = "ciborium")] + #[cfg(feature = "cbor_query")] pub fn to_cbor(&self) -> Result, Error> { let data: BTreeMap = self.into(); let cbor: BTreeMap = Value::convert_to_cbor_map(data)?; @@ -1775,6 +1775,7 @@ impl<'a> DriveQuery<'a> { } #[cfg(feature = "server")] + #[allow(unused)] /// Executes an internal query with no proof and returns the values and skipped items. pub(crate) fn execute_no_proof_internal( &self, diff --git a/packages/rs-platform-value/Cargo.toml b/packages/rs-platform-value/Cargo.toml index d5f9b6a223..0dedda70a3 100644 --- a/packages/rs-platform-value/Cargo.toml +++ b/packages/rs-platform-value/Cargo.toml @@ -9,15 +9,15 @@ license = "MIT" [dependencies] bincode = { version = "2.0.0-rc.3", features = ["serde"] } -ciborium = { git = "https://github.com/qrayven/ciborium", branch = "feat-ser-null-as-undefined" } -thiserror = "1.0.30" -bs58 = "0.4.0" -base64 = "0.13.0" +ciborium = { git = "https://github.com/qrayven/ciborium", branch = "feat-ser-null-as-undefined", optional = true } +thiserror = "1.0.58" +bs58 = "0.5.1" +base64 = "0.22.0" hex = "0.4.3" -serde = { version = "1.0.152", features = ["derive"] } -serde_json = { version = "1.0", features = ["preserve_order"] } +serde = { version = "1.0.197", features = ["derive"] } +serde_json = { version = "1.0", features = ["preserve_order"], optional = true } rand = { version = "0.8.4", features = ["small_rng"] } -treediff = "4.0.2" +treediff = "5.0.0" regex = "1.7.1" lazy_static = "1.4.0" platform-serialization = { path = "../rs-platform-serialization" } @@ -28,5 +28,7 @@ indexmap = "2.0.2" [features] default = ["std"] +cbor = ["ciborium"] +json = ["serde_json"] std = ["serde/std"] diff --git a/packages/rs-platform-value/src/btreemap_extensions/btreemap_field_replacement.rs b/packages/rs-platform-value/src/btreemap_extensions/btreemap_field_replacement.rs index 8424b50f7c..2910d30d5f 100644 --- a/packages/rs-platform-value/src/btreemap_extensions/btreemap_field_replacement.rs +++ b/packages/rs-platform-value/src/btreemap_extensions/btreemap_field_replacement.rs @@ -4,6 +4,8 @@ use std::collections::BTreeMap; use std::iter::Peekable; use std::vec::IntoIter; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; #[derive(Debug, Clone, Copy)] pub enum IntegerReplacementType { @@ -56,7 +58,7 @@ impl ReplacementType { } ReplacementType::BinaryBytes => Ok(Value::Bytes(bytes)), ReplacementType::TextBase58 => Ok(Value::Text(bs58::encode(bytes).into_string())), - ReplacementType::TextBase64 => Ok(Value::Text(base64::encode(bytes))), + ReplacementType::TextBase64 => Ok(Value::Text(BASE64_STANDARD.encode(bytes))), } } @@ -64,7 +66,7 @@ impl ReplacementType { match self { ReplacementType::BinaryBytes => Ok(Value::Bytes20(bytes)), ReplacementType::TextBase58 => Ok(Value::Text(bs58::encode(bytes).into_string())), - ReplacementType::TextBase64 => Ok(Value::Text(base64::encode(bytes))), + ReplacementType::TextBase64 => Ok(Value::Text(BASE64_STANDARD.encode(bytes))), _ => Err(Error::ByteLengthNot36BytesError( "trying to replace 36 bytes into an identifier".to_string(), )), @@ -76,7 +78,7 @@ impl ReplacementType { ReplacementType::Identifier => Ok(Value::Identifier(bytes)), ReplacementType::BinaryBytes => Ok(Value::Bytes32(bytes)), ReplacementType::TextBase58 => Ok(Value::Text(bs58::encode(bytes).into_string())), - ReplacementType::TextBase64 => Ok(Value::Text(base64::encode(bytes))), + ReplacementType::TextBase64 => Ok(Value::Text(BASE64_STANDARD.encode(bytes))), } } @@ -84,7 +86,7 @@ impl ReplacementType { match self { ReplacementType::BinaryBytes => Ok(Value::Bytes36(bytes)), ReplacementType::TextBase58 => Ok(Value::Text(bs58::encode(bytes).into_string())), - ReplacementType::TextBase64 => Ok(Value::Text(base64::encode(bytes))), + ReplacementType::TextBase64 => Ok(Value::Text(BASE64_STANDARD.encode(bytes))), _ => Err(Error::ByteLengthNot36BytesError( "trying to replace 36 bytes into an identifier".to_string(), )), diff --git a/packages/rs-platform-value/src/btreemap_extensions/btreemap_path_extensions.rs b/packages/rs-platform-value/src/btreemap_extensions/btreemap_path_extensions.rs index 12890d38b6..95d48b41b8 100644 --- a/packages/rs-platform-value/src/btreemap_extensions/btreemap_path_extensions.rs +++ b/packages/rs-platform-value/src/btreemap_extensions/btreemap_path_extensions.rs @@ -1,9 +1,12 @@ +#[cfg(feature = "json")] use serde_json::Value as JsonValue; use std::borrow::Borrow; use std::convert::TryFrom; use std::iter::FromIterator; -use std::{collections::BTreeMap, convert::TryInto}; +use std::collections::BTreeMap; +#[cfg(feature = "json")] +use std::convert::TryInto; use crate::value_map::ValueMapHelper; use crate::{Error, Identifier, Value}; @@ -73,10 +76,12 @@ pub trait BTreeValueMapPathHelper { &'a self, path: &str, ) -> Result; + #[cfg(feature = "json")] fn get_optional_inner_str_json_value_map_at_path>( &self, path: &str, ) -> Result, Error>; + #[cfg(feature = "json")] fn get_inner_str_json_value_map_at_path>( &self, path: &str, @@ -418,6 +423,7 @@ where }) } + #[cfg(feature = "json")] fn get_optional_inner_str_json_value_map_at_path>( &self, path: &str, @@ -436,7 +442,8 @@ where }) .transpose() } - + + #[cfg(feature = "json")] fn get_inner_str_json_value_map_at_path>( &self, path: &str, diff --git a/packages/rs-platform-value/src/btreemap_extensions/mod.rs b/packages/rs-platform-value/src/btreemap_extensions/mod.rs index 8660ca9939..35e4998faa 100644 --- a/packages/rs-platform-value/src/btreemap_extensions/mod.rs +++ b/packages/rs-platform-value/src/btreemap_extensions/mod.rs @@ -1,8 +1,11 @@ +#[cfg(feature = "json")] use serde_json::Value as JsonValue; use std::borrow::Borrow; use std::convert::TryFrom; use std::iter::FromIterator; -use std::{collections::BTreeMap, convert::TryInto}; +use std::collections::BTreeMap; +#[cfg(feature = "json")] +use std::convert::TryInto; use crate::{BinaryData, Error, Identifier, Value, ValueMap}; @@ -89,10 +92,12 @@ pub trait BTreeValueMapHelper { &'a self, key: &str, ) -> Result; + #[cfg(feature = "json")] fn get_optional_inner_str_json_value_map>( &self, key: &str, ) -> Result, Error>; + #[cfg(feature = "json")] fn get_inner_str_json_value_map>( &self, key: &str, @@ -356,6 +361,7 @@ where }) } + #[cfg(feature = "json")] fn get_optional_inner_str_json_value_map>( &self, key: &str, @@ -377,6 +383,7 @@ where .transpose() } + #[cfg(feature = "json")] fn get_inner_str_json_value_map>( &self, key: &str, diff --git a/packages/rs-platform-value/src/converter/mod.rs b/packages/rs-platform-value/src/converter/mod.rs index 02cf95f907..6b4a011257 100644 --- a/packages/rs-platform-value/src/converter/mod.rs +++ b/packages/rs-platform-value/src/converter/mod.rs @@ -1,2 +1,4 @@ +#[cfg(feature= "cbor")] pub mod ciborium; +#[cfg(feature= "json")] pub mod serde_json; diff --git a/packages/rs-platform-value/src/converter/serde_json.rs b/packages/rs-platform-value/src/converter/serde_json.rs index f4be4635ab..06ddf1cb9f 100644 --- a/packages/rs-platform-value/src/converter/serde_json.rs +++ b/packages/rs-platform-value/src/converter/serde_json.rs @@ -2,6 +2,8 @@ use crate::value_map::ValueMap; use crate::{Error, Value}; use serde_json::{Map, Number, Value as JsonValue}; use std::collections::BTreeMap; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; impl Value { pub fn convert_from_serde_json_map(map: I) -> R @@ -310,10 +312,10 @@ impl TryInto for Value { Value::I16(i) => JsonValue::Number(i.into()), Value::U8(i) => JsonValue::Number(i.into()), Value::I8(i) => JsonValue::Number(i.into()), - Value::Bytes(bytes) => JsonValue::String(base64::encode(bytes.as_slice())), - Value::Bytes20(bytes) => JsonValue::String(base64::encode(bytes.as_slice())), - Value::Bytes32(bytes) => JsonValue::String(base64::encode(bytes.as_slice())), - Value::Bytes36(bytes) => JsonValue::String(base64::encode(bytes.as_slice())), + Value::Bytes(bytes) => JsonValue::String(BASE64_STANDARD.encode(bytes.as_slice())), + Value::Bytes20(bytes) => JsonValue::String(BASE64_STANDARD.encode(bytes.as_slice())), + Value::Bytes32(bytes) => JsonValue::String(BASE64_STANDARD.encode(bytes.as_slice())), + Value::Bytes36(bytes) => JsonValue::String(BASE64_STANDARD.encode(bytes.as_slice())), Value::Float(float) => JsonValue::Number(Number::from_f64(float).unwrap_or(0.into())), Value::Text(string) => JsonValue::String(string), Value::Bool(value) => JsonValue::Bool(value), diff --git a/packages/rs-platform-value/src/display.rs b/packages/rs-platform-value/src/display.rs index 973fcf0a4c..622062ecd6 100644 --- a/packages/rs-platform-value/src/display.rs +++ b/packages/rs-platform-value/src/display.rs @@ -1,5 +1,7 @@ use crate::Value; use std::fmt::{Display, Formatter}; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; impl Display for Value { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { @@ -45,9 +47,9 @@ impl Value { Value::I16(i) => format!("{}", i), Value::U8(i) => format!("{}", i), Value::I8(i) => format!("{}", i), - Value::Bytes20(bytes20) => format!("bytes20 {}", base64::encode(bytes20.as_slice())), - Value::Bytes32(bytes32) => format!("bytes32 {}", base64::encode(bytes32.as_slice())), - Value::Bytes36(bytes36) => format!("bytes36 {}", base64::encode(bytes36.as_slice())), + Value::Bytes20(bytes20) => format!("bytes20 {}", BASE64_STANDARD.encode(bytes20.as_slice())), + Value::Bytes32(bytes32) => format!("bytes32 {}", BASE64_STANDARD.encode(bytes32.as_slice())), + Value::Bytes36(bytes36) => format!("bytes36 {}", BASE64_STANDARD.encode(bytes36.as_slice())), Value::Identifier(identifier) => format!( "identifier {}", bs58::encode(identifier.as_slice()).into_string() @@ -102,9 +104,9 @@ impl Value { Value::I16(i) => format!("(i16){}", i), Value::U8(i) => format!("(u8){}", i), Value::I8(i) => format!("(i8){}", i), - Value::Bytes20(bytes20) => format!("bytes20 {}", base64::encode(bytes20.as_slice())), - Value::Bytes32(bytes32) => format!("bytes32 {}", base64::encode(bytes32.as_slice())), - Value::Bytes36(bytes36) => format!("bytes36 {}", base64::encode(bytes36.as_slice())), + Value::Bytes20(bytes20) => format!("bytes20 {}", BASE64_STANDARD.encode(bytes20.as_slice())), + Value::Bytes32(bytes32) => format!("bytes32 {}", BASE64_STANDARD.encode(bytes32.as_slice())), + Value::Bytes36(bytes36) => format!("bytes36 {}", BASE64_STANDARD.encode(bytes36.as_slice())), Value::Identifier(identifier) => format!( "identifier {}", bs58::encode(identifier.as_slice()).into_string() diff --git a/packages/rs-platform-value/src/string_encoding.rs b/packages/rs-platform-value/src/string_encoding.rs index f411e2b375..ace0c77b44 100644 --- a/packages/rs-platform-value/src/string_encoding.rs +++ b/packages/rs-platform-value/src/string_encoding.rs @@ -1,5 +1,7 @@ use crate::Error; use base64; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use bs58; pub enum Encoding { @@ -14,7 +16,7 @@ pub fn decode(encoded_value: &str, encoding: Encoding) -> Result, Error> .into_vec() .map_err(|e| Error::StringDecodingError(e.to_string()))?), Encoding::Base64 => { - Ok(base64::decode(encoded_value) + Ok(BASE64_STANDARD.decode(encoded_value) .map_err(|e| Error::StringDecodingError(e.to_string()))?) } Encoding::Hex => Ok( @@ -26,7 +28,7 @@ pub fn decode(encoded_value: &str, encoding: Encoding) -> Result, Error> pub fn encode(value: &[u8], encoding: Encoding) -> String { match encoding { Encoding::Base58 => bs58::encode(value).into_string(), - Encoding::Base64 => base64::encode(value), + Encoding::Base64 => BASE64_STANDARD.encode(value), Encoding::Hex => hex::encode(value), } } diff --git a/packages/rs-platform-value/src/system_bytes.rs b/packages/rs-platform-value/src/system_bytes.rs index 0ffdd7d76c..3ce02bc757 100644 --- a/packages/rs-platform-value/src/system_bytes.rs +++ b/packages/rs-platform-value/src/system_bytes.rs @@ -1,3 +1,5 @@ +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use crate::{BinaryData, Bytes20, Bytes32, Bytes36, Error, Identifier, Value}; impl Value { @@ -117,7 +119,7 @@ impl Value { /// ``` pub fn into_binary_bytes(self) -> Result, Error> { match self { - Value::Text(text) => base64::decode(text).map_err(|_| { + Value::Text(text) => BASE64_STANDARD.decode(text).map_err(|_| { Error::StructureError( "value was a string, but could not be decoded from base 64".to_string(), ) @@ -189,7 +191,7 @@ impl Value { /// ``` pub fn to_binary_bytes(&self) -> Result, Error> { match self { - Value::Text(text) => base64::decode(text).map_err(|_| { + Value::Text(text) => BASE64_STANDARD.decode(text).map_err(|_| { Error::StructureError( "value was a string, but could not be decoded from base 64".to_string(), ) @@ -354,7 +356,7 @@ impl Value { /// ``` pub fn into_bytes_20(self) -> Result { match self { - Value::Text(text) => Bytes20::from_vec(base64::decode(text).map_err(|_| { + Value::Text(text) => Bytes20::from_vec(BASE64_STANDARD.decode(text).map_err(|_| { Error::StructureError( "value was a string, but could not be decoded from base 64".to_string(), ) @@ -402,7 +404,7 @@ impl Value { /// ``` pub fn to_bytes_20(&self) -> Result { match self { - Value::Text(text) => Bytes20::from_vec(base64::decode(text).map_err(|_| { + Value::Text(text) => Bytes20::from_vec(BASE64_STANDARD.decode(text).map_err(|_| { Error::StructureError( "value was a string, but could not be decoded from base 64".to_string(), ) @@ -453,7 +455,7 @@ impl Value { /// ``` pub fn into_bytes_32(self) -> Result { match self { - Value::Text(text) => Bytes32::from_vec(base64::decode(text).map_err(|_| { + Value::Text(text) => Bytes32::from_vec(BASE64_STANDARD.decode(text).map_err(|_| { Error::StructureError( "value was a string, but could not be decoded from base 64".to_string(), ) @@ -504,7 +506,7 @@ impl Value { /// ``` pub fn to_bytes_32(&self) -> Result { match self { - Value::Text(text) => Bytes32::from_vec(base64::decode(text).map_err(|_| { + Value::Text(text) => Bytes32::from_vec(BASE64_STANDARD.decode(text).map_err(|_| { Error::StructureError( "value was a string, but could not be decoded from base 64".to_string(), ) @@ -553,7 +555,7 @@ impl Value { /// ``` pub fn into_bytes_36(self) -> Result { match self { - Value::Text(text) => Bytes36::from_vec(base64::decode(text).map_err(|_| { + Value::Text(text) => Bytes36::from_vec(BASE64_STANDARD.decode(text).map_err(|_| { Error::StructureError( "value was a string, but could not be decoded from base 64".to_string(), ) @@ -601,7 +603,7 @@ impl Value { /// ``` pub fn to_bytes_36(&self) -> Result { match self { - Value::Text(text) => Bytes36::from_vec(base64::decode(text).map_err(|_| { + Value::Text(text) => Bytes36::from_vec(BASE64_STANDARD.decode(text).map_err(|_| { Error::StructureError( "value was a string, but could not be decoded from base 64".to_string(), ) diff --git a/packages/rs-platform-value/src/types/binary_data.rs b/packages/rs-platform-value/src/types/binary_data.rs index cd42cd415c..983bc7a99e 100644 --- a/packages/rs-platform-value/src/types/binary_data.rs +++ b/packages/rs-platform-value/src/types/binary_data.rs @@ -5,6 +5,8 @@ use bincode::{Decode, Encode}; use serde::de::Visitor; use serde::{Deserialize, Serialize}; use std::fmt; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; #[derive(Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Encode, Decode)] pub struct BinaryData(pub Vec); @@ -15,7 +17,7 @@ impl Serialize for BinaryData { S: serde::Serializer, { if serializer.is_human_readable() { - serializer.serialize_str(&base64::encode(self.0.as_slice())) + serializer.serialize_str(&BASE64_STANDARD.encode(self.0.as_slice())) } else { serializer.serialize_bytes(&self.0) } @@ -41,7 +43,7 @@ impl<'de> Deserialize<'de> for BinaryData { where E: serde::de::Error, { - let bytes = base64::decode(v).map_err(|e| E::custom(format!("{}", e)))?; + let bytes = BASE64_STANDARD.decode(v).map_err(|e| E::custom(format!("{}", e)))?; Ok(BinaryData(bytes)) } } diff --git a/packages/rs-platform-value/src/types/bytes_20.rs b/packages/rs-platform-value/src/types/bytes_20.rs index 16c9af731d..2f96af3219 100644 --- a/packages/rs-platform-value/src/types/bytes_20.rs +++ b/packages/rs-platform-value/src/types/bytes_20.rs @@ -5,6 +5,8 @@ use bincode::{Decode, Encode}; use serde::de::Visitor; use serde::{Deserialize, Serialize}; use std::fmt; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; #[derive(Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Copy, Encode, Decode)] pub struct Bytes20(pub [u8; 20]); @@ -75,7 +77,7 @@ impl Serialize for Bytes20 { S: serde::Serializer, { if serializer.is_human_readable() { - serializer.serialize_str(&base64::encode(self.0)) + serializer.serialize_str(&BASE64_STANDARD.encode(self.0)) } else { serializer.serialize_bytes(&self.0) } @@ -101,7 +103,7 @@ impl<'de> Deserialize<'de> for Bytes20 { where E: serde::de::Error, { - let bytes = base64::decode(v).map_err(|e| E::custom(format!("{}", e)))?; + let bytes = BASE64_STANDARD.decode(v).map_err(|e| E::custom(format!("{}", e)))?; if bytes.len() != 20 { return Err(E::invalid_length(bytes.len(), &self)); } diff --git a/packages/rs-platform-value/src/types/bytes_32.rs b/packages/rs-platform-value/src/types/bytes_32.rs index 077e98ef67..8cb070d25a 100644 --- a/packages/rs-platform-value/src/types/bytes_32.rs +++ b/packages/rs-platform-value/src/types/bytes_32.rs @@ -7,6 +7,8 @@ use rand::Rng; use serde::de::Visitor; use serde::{Deserialize, Serialize}; use std::fmt; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; #[derive(Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Copy, Encode, Decode)] pub struct Bytes32(pub [u8; 32]); @@ -77,7 +79,7 @@ impl Serialize for Bytes32 { S: serde::Serializer, { if serializer.is_human_readable() { - serializer.serialize_str(&base64::encode(self.0)) + serializer.serialize_str(&BASE64_STANDARD.encode(self.0)) } else { serializer.serialize_bytes(&self.0) } @@ -103,7 +105,7 @@ impl<'de> Deserialize<'de> for Bytes32 { where E: serde::de::Error, { - let bytes = base64::decode(v).map_err(|e| E::custom(format!("{}", e)))?; + let bytes = BASE64_STANDARD.decode(v).map_err(|e| E::custom(format!("{}", e)))?; if bytes.len() != 32 { return Err(E::invalid_length(bytes.len(), &self)); } diff --git a/packages/rs-platform-value/src/types/bytes_36.rs b/packages/rs-platform-value/src/types/bytes_36.rs index 57cdc91fe1..c75874078c 100644 --- a/packages/rs-platform-value/src/types/bytes_36.rs +++ b/packages/rs-platform-value/src/types/bytes_36.rs @@ -5,6 +5,8 @@ use bincode::{Decode, Encode}; use serde::de::Visitor; use serde::{Deserialize, Serialize}; use std::fmt; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Copy, Encode, Decode)] pub struct Bytes36(pub [u8; 36]); @@ -71,7 +73,7 @@ impl Serialize for Bytes36 { S: serde::Serializer, { if serializer.is_human_readable() { - serializer.serialize_str(&base64::encode(self.0)) + serializer.serialize_str(&BASE64_STANDARD.encode(self.0)) } else { serializer.serialize_bytes(&self.0) } @@ -97,7 +99,7 @@ impl<'de> Deserialize<'de> for Bytes36 { where E: serde::de::Error, { - let bytes = base64::decode(v).map_err(|e| E::custom(format!("{}", e)))?; + let bytes = BASE64_STANDARD.decode(v).map_err(|e| E::custom(format!("{}", e)))?; if bytes.len() != 36 { return Err(E::invalid_length(bytes.len(), &self)); } diff --git a/packages/rs-platform-value/src/types/identifier.rs b/packages/rs-platform-value/src/types/identifier.rs index da1ad105ec..4529310c84 100644 --- a/packages/rs-platform-value/src/types/identifier.rs +++ b/packages/rs-platform-value/src/types/identifier.rs @@ -8,6 +8,7 @@ use std::fmt; use serde::de::Visitor; use serde::{Deserialize, Serialize}; +#[cfg(feature = "json")] use serde_json::Value as JsonValue; use crate::string_encoding::Encoding; @@ -191,6 +192,7 @@ impl Identifier { Ok(Identifier::new(vec.try_into().unwrap())) } + #[cfg(feature = "json")] pub fn to_json_value_vec(&self) -> Vec { self.to_buffer() .iter() diff --git a/packages/rs-platform-value/src/value_serialization/de.rs b/packages/rs-platform-value/src/value_serialization/de.rs index 2f064926bd..6f766c0a7b 100644 --- a/packages/rs-platform-value/src/value_serialization/de.rs +++ b/packages/rs-platform-value/src/value_serialization/de.rs @@ -1,5 +1,7 @@ use core::{fmt, slice}; use std::iter::Peekable; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; use serde::de::value::SeqDeserializer; use serde::de::{self, Deserializer as _, IntoDeserializer}; @@ -177,7 +179,7 @@ impl<'de> de::Deserializer<'de> for Deserializer { match self.0 { Value::Bytes(x) => { if human_readable { - visitor.visit_str(base64::encode(x).as_str()) + visitor.visit_str(BASE64_STANDARD.encode(x).as_str()) } else { visitor.visit_bytes(&x) } @@ -200,21 +202,21 @@ impl<'de> de::Deserializer<'de> for Deserializer { Value::I8(x) => visitor.visit_i8(x), Value::Bytes20(x) => { if human_readable { - visitor.visit_str(base64::encode(x).as_str()) + visitor.visit_str(BASE64_STANDARD.encode(x).as_str()) } else { visitor.visit_bytes(&x) } } Value::Bytes32(x) => { if human_readable { - visitor.visit_str(base64::encode(x).as_str()) + visitor.visit_str(BASE64_STANDARD.encode(x).as_str()) } else { visitor.visit_bytes(&x) } } Value::Bytes36(x) => { if human_readable { - visitor.visit_str(base64::encode(x).as_str()) + visitor.visit_str(BASE64_STANDARD.encode(x).as_str()) } else { visitor.visit_bytes(&x) } diff --git a/packages/rs-platform-value/src/value_serialization/ser.rs b/packages/rs-platform-value/src/value_serialization/ser.rs index 00d022223c..888df198cb 100644 --- a/packages/rs-platform-value/src/value_serialization/ser.rs +++ b/packages/rs-platform-value/src/value_serialization/ser.rs @@ -3,6 +3,8 @@ use crate::value_map::ValueMap; use crate::{to_value, Value}; use serde::ser::{Impossible, Serialize}; use std::fmt::Display; +use base64::Engine; +use base64::prelude::BASE64_STANDARD; // We only use our own error type; no need for From conversions provided by the // standard library's try! macro. This reduces lines of LLVM IR by 4%. @@ -45,28 +47,28 @@ impl Serialize for Value { Value::I8(i) => serializer.serialize_i8(*i), Value::Bytes(bytes) => { if serializer.is_human_readable() { - serializer.serialize_str(base64::encode(bytes).as_str()) + serializer.serialize_str(BASE64_STANDARD.encode(bytes).as_str()) } else { serializer.serialize_bytes(bytes) } } Value::Bytes20(bytes) => { if serializer.is_human_readable() { - serializer.serialize_str(base64::encode(bytes).as_str()) + serializer.serialize_str(BASE64_STANDARD.encode(bytes).as_str()) } else { serializer.serialize_bytes(bytes) } } Value::Bytes32(bytes) => { if serializer.is_human_readable() { - serializer.serialize_str(base64::encode(bytes).as_str()) + serializer.serialize_str(BASE64_STANDARD.encode(bytes).as_str()) } else { serializer.serialize_bytes(bytes) } } Value::Bytes36(bytes) => { if serializer.is_human_readable() { - serializer.serialize_str(base64::encode(bytes).as_str()) + serializer.serialize_str(BASE64_STANDARD.encode(bytes).as_str()) } else { serializer.serialize_bytes(bytes) } diff --git a/packages/wasm-dpp/src/errors/from.rs b/packages/wasm-dpp/src/errors/from.rs index b53dfeccbe..6806d6e2dd 100644 --- a/packages/wasm-dpp/src/errors/from.rs +++ b/packages/wasm-dpp/src/errors/from.rs @@ -38,7 +38,6 @@ pub fn from_dpp_err(pe: ProtocolError) -> JsValue { pub fn from_dpp_init_error(e: DashPlatformProtocolInitError) -> JsValue { match e { DashPlatformProtocolInitError::SchemaDeserializationError(e) => e.to_string().into(), - DashPlatformProtocolInitError::ValidationError(e) => e.to_string().into(), DashPlatformProtocolInitError::InvalidSchemaError(e) => e.to_string().into(), // TODO(versioning): add rest erros _ => JsValue::from_str(&format!("Error conversion not implemented: {e:#}",)),