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

Use ObjectID over AccountAddress #468

Merged
merged 9 commits into from
Feb 18, 2022

Conversation

oxade
Copy link
Contributor

@oxade oxade commented Feb 17, 2022

ObjectID now wraps move_core_types::account_address::AccountAddress instead of being a raw alias.
This reduces confusion in code and error reporting.
Fixes #463

Few things:

  1. The AccountAddress uses in sui_programmability was largely left untouched since this is the boundary between Move (using AccountAddress) and Rust (using ObjectID).
  2. The base-types file is growing huge so I can potentially separate out the ObjectID impls if that's a problem

@lxfind
Copy link
Contributor

lxfind commented Feb 17, 2022

For the functions that are exactly the same between ObjectID and AccountAddress, could we simply call into AccountAddress for that? That reduces duplication and allows us to reuse as much as possible but keep the differences.

@oxade
Copy link
Contributor Author

oxade commented Feb 17, 2022

For the functions that are exactly the same between ObjectID and AccountAddress, could we simply call into AccountAddress for that? That reduces duplication and allows us to reuse as much as possible but keep the differences.

That's what's going on, but I still need the wrappers for the Rust type system since they're two different type.
If you check the code, it mostly calls self.0 which signifies calling/using the underlying AccountAddress type. If I didn't do that, the code would be much more.


/// Converts from hex string to ObjectID where the string is prefixed with 0x
/// Its okay if the strings are less than expected
pub fn from_hex_literal(literal: &str) -> Result<Self, ObjectIDParseError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we could do much more to dedup.
For example, for from_hex_literal function, we could very well call into AccountAddress::from_hex_literal, and map the error for return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right this was somewhat intentional. AccountAddress impls, will return AccountAddressParseError => "unable to parse AccountAddress" on any failure which is not descriptive enough and also confusing for users because it's ObjectIDs we're after (saw this scenario once). I'm trying to be descriptive on why things failed. Doing this unfortunately requires doing some checks of our own. It also makes sense to control our parsing logic/errors since this is user-facing. If I just map_err AccountAddressParseError, to ObjectIDParseError, it still doesn't convey all info because AccountAddressParseError disregards details.

But if you have an approach that returns clear errors and also avoids duplication, please make a commit and I'll take a look.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Let me file a separate issue to add better error message in Move repo for AccountAddressParseError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problemo. Thank you

@sblackshear
Copy link
Collaborator

The base-types file is growing huge so I can potentially separate out the ObjectID impls if that's a problem

+1 to this!

@oxade
Copy link
Contributor Author

oxade commented Feb 18, 2022

@lxfind @sblackshear any other comments on this?

The base-types file is growing huge so I can potentially separate out the ObjectID impls if that's a problem

+1 to this!

Existing issue in many other files.
Created issue for this #476

@oxade
Copy link
Contributor Author

oxade commented Feb 18, 2022

@lxfind @sblackshear is there's nothing else, please approve when possible so I can land it.
This ties into the data model & API work

/// Hex address: 0x0
pub const ZERO: Self = Self::new([0u8; Self::LENGTH]);
/// Hex address: 0x1
pub const ONE: Self = Self::get_hex_address_one();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still needed/used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

}

impl std::ops::Deref for ObjectID {
type Target = [u8; Self::LENGTH];
Copy link
Contributor

Choose a reason for hiding this comment

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

I think what @sblackshear meant here is probably to deref it to AccountAddress, instead of slice. But I will let Sam to confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@lxfind
Copy link
Contributor

lxfind commented Feb 18, 2022

@lxfind @sblackshear is there's nothing else, please approve when possible so I can land it. This ties into the data model & API work

You might want to consider using stacked PR if this is blocking you.

@oxade oxade merged commit ec02fe5 into main Feb 18, 2022
@oxade oxade deleted the enhance/prefer-objecteid-over-account-address branch February 18, 2022 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[all systems] Remove Use Of Raw move-core-types::AccountAddress In Favor Or ObjectID
3 participants