Skip to content

Commit

Permalink
Bypass json checking which is limited
Browse files Browse the repository at this point in the history
  • Loading branch information
gdanezis committed Sep 8, 2024
1 parent 3e9eb2e commit 924f940
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion crates/sui-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ impl SuiJsonValue {
Ok(Self(json_value))
}

pub fn new_unchecked(json_value: JsonValue) -> Result<SuiJsonValue, anyhow::Error> {
Ok(Self(json_value))
}

fn check_value(json_value: &JsonValue) -> Result<(), anyhow::Error> {
match json_value {
// No checks needed for Bool and String
Expand Down Expand Up @@ -395,7 +399,7 @@ fn json_value_to_sui_address(value: &JsonValue) -> anyhow::Result<SuiAddress> {
}
}

fn move_value_to_json(move_value: &MoveValue) -> Option<JsonValue> {
pub fn move_value_to_json(move_value: &MoveValue) -> Option<JsonValue> {
Some(match move_value {
MoveValue::Vector(values) => JsonValue::Array(
values
Expand Down
17 changes: 11 additions & 6 deletions crates/sui-light-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use sui_types::{
effects::{TransactionEffects, TransactionEffectsAPI, TransactionEvents},
message_envelope::Envelope,
messages_checkpoint::{CertifiedCheckpointSummary, CheckpointSummary, EndOfEpochData},
object::{Data, Object},
object::{bounded_visitor::BoundedVisitor, Data, Object},
};

use sui_config::genesis::Genesis;

use sui_json::SuiJsonValue;
use sui_json::{move_value_to_json, SuiJsonValue};
use sui_package_resolver::Result as ResolverResult;
use sui_package_resolver::{Package, PackageStore, Resolver};
use sui_sdk::SuiClientBuilder;
Expand Down Expand Up @@ -558,8 +558,11 @@ pub async fn main() {
.await
.unwrap();

let result = BoundedVisitor::deserialize_value(&event.contents, &type_layout)
.expect("Cannot deserialize");
let json = move_value_to_json(&result).expect("Cannot convert to json");
let json_val =
SuiJsonValue::from_bcs_bytes(Some(&type_layout), &event.contents).unwrap();
SuiJsonValue::new_unchecked(json).expect("Cannot convert to json");

println!(
"Event:\n - Package: {}\n - Module: {}\n - Sender: {}\n - Type: {}\n{}",
Expand All @@ -586,9 +589,11 @@ pub async fn main() {
.await
.unwrap();

let json_val =
SuiJsonValue::from_bcs_bytes(Some(&type_layout), move_object.contents())
.unwrap();
let result =
BoundedVisitor::deserialize_value(move_object.contents(), &type_layout)
.expect("Cannot deserialize");
let json = move_value_to_json(&result).expect("Cannot convert to json");
let json_val = SuiJsonValue::new_unchecked(json).expect("Cannot convert to json");

let (oid, version, hash) = object.compute_object_reference();
println!(
Expand Down

0 comments on commit 924f940

Please sign in to comment.