Skip to content

Commit

Permalink
Expose programmatic JSON encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Sep 12, 2023
1 parent 5148c11 commit 7af73cf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion generator/src/function_spec/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ pub fn generate_function_spec() -> OpenApi {
NotarizedTransactionStaticallyValidate,
UtilsKnownAddress,
ScryptoSborDecodeToString,
ManifestSborDecodeToString
ScryptoSborEncodeStringRepresentation,
ManifestSborDecodeToString,
]
}

Expand Down
39 changes: 39 additions & 0 deletions radix-engine-toolkit/src/functions/scrypto_sbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,42 @@ impl<'f> Function<'f> for ScryptoSborDecodeToString {

export_function!(ScryptoSborDecodeToString as scrypto_sbor_decode_to_string);
export_jni_function!(ScryptoSborDecodeToString as scryptoSborDecodeToString);

#[typeshare::typeshare]
#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug, PartialEq, Eq)]
#[serde(tag = "kind", content = "value")]
pub enum SerializableScryptoSborStringRepresentation {
ProgrammaticJson(String),
}

#[typeshare::typeshare]
pub type ScryptoSborEncodeStringRepresentationInput = SerializableScryptoSborStringRepresentation;

#[typeshare::typeshare]
pub type ScryptoSborEncodeStringRepresentationOutput = SerializableBytes;

pub struct ScryptoSborEncodeStringRepresentation;
impl<'f> Function<'f> for ScryptoSborEncodeStringRepresentation {
type Input = ScryptoSborEncodeStringRepresentationInput;
type Output = ScryptoSborEncodeStringRepresentationOutput;

fn handle(input: Self::Input) -> Result<Self::Output, crate::error::InvocationHandlingError> {
let input = match input {
SerializableScryptoSborStringRepresentation::ProgrammaticJson(value) => {
radix_engine_toolkit_core::functions::scrypto_sbor::StringRepresentation::ProgrammaticJson(value)
}
};
let bytes =
radix_engine_toolkit_core::functions::scrypto_sbor::encode_string_representation(
input,
)?;
Ok(bytes.into())
}
}

export_function!(
ScryptoSborEncodeStringRepresentation as scrypto_sbor_encode_string_representation
);
export_jni_function!(
ScryptoSborEncodeStringRepresentation as scryptoSborEncodeStringRepresentation
);
1 change: 0 additions & 1 deletion sbor-json/tests/programmatic_scrypto_sbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ pub fn value_with_two_address_of_the_same_network_has_no_network_mismatch() {

// Act
let contains_network_mismatch = value_contains_network_mismatch(&value);
println!("{}", serde_json::to_string(&value).unwrap());

// Assert
assert!(!contains_network_mismatch)
Expand Down

0 comments on commit 7af73cf

Please sign in to comment.