From efd897507910a2d62b97fbceb9e293309ee880f3 Mon Sep 17 00:00:00 2001 From: fpieper Date: Tue, 11 Mar 2025 13:12:27 +0100 Subject: [PATCH 1/3] Update encode_string_representation to use git-based radix_common and sbor dependencies internally and convert to types from sbor from crates. --- Cargo.toml | 19 +++++++++--------- src/encode_string_representation.rs | 31 ++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index da678fe..a69bd40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,14 +11,11 @@ radix-common = { workspace = true } sbor = { workspace = true } radix-engine-interface = { workspace = true } radix-engine = { workspace = true } -sbor-json = { workspace = true } scrypto = { workspace = true } radix-client = { git = "https://github.com/ociswap/radix-client", features = [ "gateway", ], optional = true, tag = "v1.0.1" } - handler_macro = { path = "./handler_macro" } - serde_json = "1.0.114" serde = "1.0.197" log = "0.4.21" @@ -37,6 +34,11 @@ sqlx = { version = "0.7.4", features = [ ], optional = true } serde_with = "3.9.0" +# Add sbor-json with matching git versions with aliases +sbor-json = { git = 'https://github.com/radixdlt/radix-engine-toolkit.git', tag = "v2.2.0" } +sbor-git = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0", package = "sbor", features = ["serde"] } +radix-common-git = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0", package = "radix-common", features = ["serde"] } + [features] default = ["gateway", "file", "database", "channel"] database = ["sqlx"] @@ -55,15 +57,14 @@ package.rust-version = "1.81" [workspace.dependencies] -sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0", features = [ +sbor = { version = "1.3.0", features = [ "serde", ] } -radix-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0", features = [ +radix-common = { version = "1.3.0", features = [ "serde", ] } -radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0" } -radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0" } -scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0", features = [ +radix-engine = { version = "1.3.0" } +radix-engine-interface = { version = "1.3.0" } +scrypto = { version = "1.3.0", features = [ "serde", ] } -sbor-json = { git = 'https://github.com/radixdlt/radix-engine-toolkit.git', tag = "v2.2.0" } diff --git a/src/encode_string_representation.rs b/src/encode_string_representation.rs index d65ebbf..1e825d7 100644 --- a/src/encode_string_representation.rs +++ b/src/encode_string_representation.rs @@ -3,11 +3,13 @@ //! it uses some experimental features, and I want to keep supporting //! stable Rust. -use radix_common::prelude::scrypto_encode; use sbor::{DecodeError, EncodeError}; use sbor_json::scrypto::programmatic::{ utils::value_contains_network_mismatch, value::ProgrammaticScryptoValue, }; +// Import the git versions with aliases +use radix_common_git; +use sbor_git; #[derive(Debug, Clone)] pub enum StringRepresentation { @@ -23,6 +25,22 @@ pub enum ScryptoSborError { ValueContainsNetworkMismatch, } +// Convert from git version's EncodeError to crates.io version +fn convert_encode_error(error: sbor_git::EncodeError) -> EncodeError { + match error { + sbor_git::EncodeError::MaxDepthExceeded(depth) => + EncodeError::MaxDepthExceeded(depth), + sbor_git::EncodeError::SizeTooLarge { actual, max_allowed } => + EncodeError::SizeTooLarge { actual, max_allowed }, + sbor_git::EncodeError::MismatchingArrayElementValueKind { element_value_kind, actual_value_kind } => + EncodeError::MismatchingArrayElementValueKind { element_value_kind, actual_value_kind }, + sbor_git::EncodeError::MismatchingMapKeyValueKind { key_value_kind, actual_value_kind } => + EncodeError::MismatchingMapKeyValueKind { key_value_kind, actual_value_kind }, + sbor_git::EncodeError::MismatchingMapValueValueKind { value_value_kind, actual_value_kind } => + EncodeError::MismatchingMapValueValueKind { value_value_kind, actual_value_kind }, + } +} + pub fn encode_string_representation( representation: StringRepresentation, ) -> Result, ScryptoSborError> { @@ -35,8 +53,15 @@ pub fn encode_string_representation( return Err(ScryptoSborError::ValueContainsNetworkMismatch); } - let value = value.to_scrypto_value(); - scrypto_encode(&value).map_err(ScryptoSborError::EncodeError) + // This returns a Value from the git version + let scrypto_value = value.to_scrypto_value(); + + // Use the git version's encoder directly + let bytes = radix_common_git::data::scrypto::scrypto_encode(&scrypto_value) + .map_err(|e| ScryptoSborError::EncodeError(convert_encode_error(e)))?; + + // Return the raw bytes + Ok(bytes) } } } From 3c493671f988457760530009ec5d97eea0885c68 Mon Sep 17 00:00:00 2001 From: fpieper Date: Tue, 11 Mar 2025 13:13:01 +0100 Subject: [PATCH 2/3] Bump version to 1.3.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a69bd40..2fceaed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ channel = [] [workspace] members = ["examples", "handler_macro"] resolver = "2" -package.version = "1.3.0" +package.version = "1.3.1" package.edition = "2021" package.license-file = "LICENSE" package.repository = "https://github.com/ociswap/radix-event-stream" From 0062760192e24dac1281593ff660be53a4ecab58 Mon Sep 17 00:00:00 2001 From: fpieper Date: Tue, 11 Mar 2025 13:15:13 +0100 Subject: [PATCH 3/3] Slight refactoring --- src/encode_string_representation.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/encode_string_representation.rs b/src/encode_string_representation.rs index 1e825d7..5daed3b 100644 --- a/src/encode_string_representation.rs +++ b/src/encode_string_representation.rs @@ -57,11 +57,8 @@ pub fn encode_string_representation( let scrypto_value = value.to_scrypto_value(); // Use the git version's encoder directly - let bytes = radix_common_git::data::scrypto::scrypto_encode(&scrypto_value) - .map_err(|e| ScryptoSborError::EncodeError(convert_encode_error(e)))?; - - // Return the raw bytes - Ok(bytes) + radix_common_git::data::scrypto::scrypto_encode(&scrypto_value) + .map_err(|e| ScryptoSborError::EncodeError(convert_encode_error(e))) } } }