Skip to content

Commit

Permalink
[adapter] Make package id derivation efficient (MystenLabs#780)
Browse files Browse the repository at this point in the history
* [adapter] Make package id derivation efficient

Co-authored-by: George Danezis <[email protected]>
  • Loading branch information
gdanezis and George Danezis authored Mar 12, 2022
1 parent 43a40d9 commit cf03fe4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions sui_core/tests/staged/sui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ MoveObject:
- contents: BYTES
MovePackage:
STRUCT:
- id:
TYPENAME: ObjectID
- module_map:
MAP:
KEY: STR
Expand Down
17 changes: 7 additions & 10 deletions sui_types/src/move_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct TypeCheckSuccess {
// serde_bytes::ByteBuf is an analog of Vec<u8> with built-in fast serialization.
#[derive(Eq, PartialEq, Debug, Clone, Deserialize, Serialize, Hash)]
pub struct MovePackage {
id: ObjectID,
module_map: BTreeMap<String, ByteBuf>,
}

Expand All @@ -46,22 +47,15 @@ impl MovePackage {
&self.module_map
}

pub fn from_map(module_map: &BTreeMap<String, ByteBuf>) -> Self {
pub fn from_map(id: ObjectID, module_map: &BTreeMap<String, ByteBuf>) -> Self {
Self {
id,
module_map: module_map.clone(),
}
}

pub fn id(&self) -> ObjectID {
// TODO: simplify this
// https://github.com/MystenLabs/sui/issues/249
// All modules in the same package must have the same address. Pick any
ObjectID::from(
*CompiledModule::deserialize(self.module_map.values().next().unwrap())
.unwrap()
.self_id()
.address(),
)
self.id
}

pub fn module_id(&self, module: &Identifier) -> Result<ModuleId, SuiError> {
Expand Down Expand Up @@ -140,7 +134,10 @@ impl MovePackage {

impl From<&Vec<CompiledModule>> for MovePackage {
fn from(compiled_modules: &Vec<CompiledModule>) -> Self {
let id = ObjectID::from(*compiled_modules[0].self_id().address());

MovePackage::from_map(
id,
&compiled_modules
.iter()
.map(|module| {
Expand Down

0 comments on commit cf03fe4

Please sign in to comment.