Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up some logic #532

Merged
merged 2 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function no longer needs to return Result.

owner,
previous_transaction,
})
}
}

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