Skip to content

Commit

Permalink
sui-types: remove dependency on the move-compiler
Browse files Browse the repository at this point in the history
Remove dependency on the move-compiler from the sui-types crate, and
move the json-rpc specific functionality to the sui-json-rpc-types
crate.

In addition remove a few unused dependencies from sui-types.
  • Loading branch information
bmwill committed Dec 18, 2024
1 parent 9229371 commit ae1acd5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 45 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/sui-json-rpc-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ tabled.workspace = true
move-binary-format.workspace = true
move-core-types.workspace = true
move-bytecode-utils.workspace = true
move-disassembler.workspace = true
move-ir-types.workspace = true

mysten-metrics.workspace = true
sui-types.workspace = true
Expand Down
33 changes: 32 additions & 1 deletion crates/sui-json-rpc-types/src/sui_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,39 @@ impl SuiData for SuiParsedData {
}

fn try_from_package(package: MovePackage) -> Result<Self, anyhow::Error> {
fn disassemble_modules<'a, I>(modules: I) -> SuiResult<BTreeMap<String, Value>>
where
I: Iterator<Item = &'a Vec<u8>>,
{
let mut disassembled = BTreeMap::new();
for bytecode in modules {
// this function is only from JSON RPC - it is OK to deserialize with max Move binary
// version
let module =
move_binary_format::CompiledModule::deserialize_with_defaults(bytecode)
.map_err(|error| SuiError::ModuleDeserializationFailure {
error: error.to_string(),
})?;
let d = move_disassembler::disassembler::Disassembler::from_module_with_max_size(
&module,
move_ir_types::location::Spanned::unsafe_no_loc(()).loc,
*sui_types::move_package::MAX_DISASSEMBLED_MODULE_SIZE,
)
.map_err(|e| SuiError::ObjectSerializationError {
error: e.to_string(),
})?;
let bytecode_str =
d.disassemble()
.map_err(|e| SuiError::ObjectSerializationError {
error: e.to_string(),
})?;
disassembled.insert(module.name().to_string(), Value::String(bytecode_str));
}
Ok(disassembled)
}

Ok(Self::Package(SuiMovePackage {
disassembled: package.disassemble()?,
disassembled: disassemble_modules(package.serialized_module_map().values())?,
}))
}

Expand Down
3 changes: 0 additions & 3 deletions crates/sui-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ roaring.workspace = true
enum_dispatch.workspace = true
eyre.workspace = true
indexmap.workspace = true
jsonrpsee.workspace = true
move-binary-format.workspace = true
move-bytecode-utils.workspace = true
move-command-line-common.workspace = true
move-core-types.workspace = true
move-disassembler.workspace = true
move-ir-types.workspace = true
move-vm-test-utils.workspace = true
move-vm-types.workspace = true
move-vm-profiler.workspace = true
Expand Down
38 changes: 0 additions & 38 deletions crates/sui-types/src/move_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ use move_core_types::{
identifier::{IdentStr, Identifier},
language_storage::StructTag,
};
use move_disassembler::disassembler::Disassembler;
use move_ir_types::location::Spanned;
use once_cell::sync::Lazy;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::serde_as;
use serde_with::Bytes;
use std::collections::{BTreeMap, BTreeSet};
Expand Down Expand Up @@ -527,10 +524,6 @@ impl MovePackage {
})
}

pub fn disassemble(&self) -> SuiResult<BTreeMap<String, Value>> {
disassemble_modules(self.module_map.values())
}

pub fn normalize(
&self,
binary_config: &BinaryConfig,
Expand Down Expand Up @@ -604,37 +597,6 @@ pub fn is_test_fun(name: &IdentStr, module: &CompiledModule, fn_info_map: &FnInf
}
}

pub fn disassemble_modules<'a, I>(modules: I) -> SuiResult<BTreeMap<String, Value>>
where
I: Iterator<Item = &'a Vec<u8>>,
{
let mut disassembled = BTreeMap::new();
for bytecode in modules {
// this function is only from JSON RPC - it is OK to deserialize with max Move binary
// version
let module = CompiledModule::deserialize_with_defaults(bytecode).map_err(|error| {
SuiError::ModuleDeserializationFailure {
error: error.to_string(),
}
})?;
let d = Disassembler::from_module_with_max_size(
&module,
Spanned::unsafe_no_loc(()).loc,
*MAX_DISASSEMBLED_MODULE_SIZE,
)
.map_err(|e| SuiError::ObjectSerializationError {
error: e.to_string(),
})?;
let bytecode_str = d
.disassemble()
.map_err(|e| SuiError::ObjectSerializationError {
error: e.to_string(),
})?;
disassembled.insert(module.name().to_string(), Value::String(bytecode_str));
}
Ok(disassembled)
}

pub fn normalize_modules<'a, I>(
modules: I,
binary_config: &BinaryConfig,
Expand Down

0 comments on commit ae1acd5

Please sign in to comment.