Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
Expand All @@ -47,23 +49,22 @@ 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"
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" }
28 changes: 25 additions & 3 deletions src/encode_string_representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Vec<u8>, ScryptoSborError> {
Expand All @@ -35,8 +53,12 @@ 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
radix_common_git::data::scrypto::scrypto_encode(&scrypto_value)
.map_err(|e| ScryptoSborError::EncodeError(convert_encode_error(e)))
}
}
}