Skip to content

Commit

Permalink
Clean up some logic (MystenLabs#532)
Browse files Browse the repository at this point in the history
* Clean up some logic
  • Loading branch information
oxade authored Feb 23, 2022
1 parent ae20572 commit fb02b41
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
6 changes: 3 additions & 3 deletions sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async fn genesis(
);
let sui_lib = sui_framework::get_sui_framework_modules(&genesis_conf.sui_framework_lib_path)?;
let lib_object =
Object::new_package(sui_lib, SuiAddress::default(), TransactionDigest::genesis())?;
Object::new_package(sui_lib, SuiAddress::default(), TransactionDigest::genesis());
preload_modules.push(lib_object);

info!(
Expand All @@ -174,7 +174,7 @@ async fn genesis(
move_lib,
SuiAddress::default(),
TransactionDigest::genesis(),
)?;
);
preload_modules.push(lib_object);

// Build custom move packages
Expand All @@ -194,7 +194,7 @@ async fn genesis(
)?;

let object =
Object::new_package(modules, SuiAddress::default(), TransactionDigest::genesis())?;
Object::new_package(modules, SuiAddress::default(), TransactionDigest::genesis());
info!("Loaded package [{}] from {:?}.", object.id(), path);
// Writing package id to network.conf for user to retrieve later.
config.loaded_move_packages.push((path, object.id()));
Expand Down
1 change: 0 additions & 1 deletion sui_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,6 @@ async fn test_hero() {
)
.await
.unwrap();
println!("ERRRR {:?}", effects.status);
assert!(matches!(effects.status, ExecutionStatus::Success { .. }));

// 7. Give them a boar!
Expand Down
2 changes: 1 addition & 1 deletion sui_programmability/adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub fn publish<E: Debug, S: ResourceResolver<Error = E> + ModuleResolver<Error =
}

// wrap the modules in an object, write it to the store
let package_object = Object::new_package(modules, sender, ctx.digest())?;
let package_object = Object::new_package(modules, sender, ctx.digest());
state_view.write_object(package_object);

let mut total_gas_used = gas_cost;
Expand Down
4 changes: 2 additions & 2 deletions sui_programmability/adapter/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fn create_genesis_module_objects(lib_dir: &Path) -> SuiResult<Genesis> {
sui_framework::get_move_stdlib_modules(&lib_dir.join("deps").join("move-stdlib"))?;
let owner = SuiAddress::default();
let objects = vec![
Object::new_package(sui_modules, owner, TransactionDigest::genesis())?,
Object::new_package(std_modules, owner, TransactionDigest::genesis())?,
Object::new_package(sui_modules, owner, TransactionDigest::genesis()),
Object::new_package(std_modules, owner, TransactionDigest::genesis()),
];
Ok(Genesis { objects })
}
38 changes: 17 additions & 21 deletions sui_types/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ impl MoveObject {
// 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 @@ -184,22 +183,21 @@ impl MovePackage {
}

pub fn from_map(module_map: &BTreeMap<String, ByteBuf>) -> Self {
// All modules in the same package must have the same address. Pick any
let id = ObjectID::from(
*CompiledModule::deserialize(module_map.values().next().unwrap())
.unwrap()
.self_id()
.address(),
);

Self {
id,
module_map: module_map.clone(),
}
}

pub fn id(&self) -> ObjectID {
self.id
// TODO: simplify this
// https://github.com/MystenLabs/fastnft/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(),
)
}

pub fn module_id(&self, module: &Identifier) -> Result<ModuleId, SuiError> {
Expand Down Expand Up @@ -236,10 +234,9 @@ impl MovePackage {
})
}
}
impl TryFrom<&Vec<CompiledModule>> for MovePackage {
type Error = SuiError;
fn try_from(compiled_modules: &Vec<CompiledModule>) -> Result<Self, SuiError> {
let package = MovePackage::from_map(
impl From<&Vec<CompiledModule>> for MovePackage {
fn from(compiled_modules: &Vec<CompiledModule>) -> Self {
MovePackage::from_map(
&compiled_modules
.iter()
.map(|module| {
Expand All @@ -248,8 +245,7 @@ impl TryFrom<&Vec<CompiledModule>> for MovePackage {
(module.self_id().name().to_string(), ByteBuf::from(bytes))
})
.collect(),
);
Ok(package)
)
}
}

Expand Down Expand Up @@ -370,12 +366,12 @@ impl Object {
modules: Vec<CompiledModule>,
owner: SuiAddress,
previous_transaction: TransactionDigest,
) -> Result<Self, SuiError> {
Ok(Object {
data: Data::Package(MovePackage::try_from(&modules)?),
) -> Self {
Object {
data: Data::Package(MovePackage::from(&modules)),
owner,
previous_transaction,
})
}
}

pub fn is_read_only(&self) -> bool {
Expand Down

0 comments on commit fb02b41

Please sign in to comment.