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

Add function to directly set extra data #336

Merged
merged 8 commits into from
Jun 15, 2022

Conversation

Vectorized
Copy link
Collaborator

@Vectorized Vectorized commented Jun 14, 2022

In case people want to use the extra data to store the type of token.

Changes:

  • Changed _setAux function body to be consistent with the function body of _setExtraDataAt.
  • Made _nextExtraData private. Forgot to make it private previously.
  • Remove redundant test code.
  • Renamed a local variable previousExtraData to extraData.
    Cuz there is another variable called prevPackedOwnership, and this triggers OCD.

@Vectorized Vectorized requested a review from cygaar June 14, 2022 04:03
/**
* @dev Directly sets the extra data for the ownership data `index`.
*/
function _setExtraDataAt(uint256 index, uint24 extraData) internal {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not necessarily specific to this PR, but we use index and tokenId to access _packedOwnerships. We should probably make these consistent in a a future PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

index refers to something that may not be initialized, and will expose the user to the underlying logic.

tokenId refers to something that is initialized.

assembly {
extraDataCasted := extraData
}
packed = (packed & BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << BITPOS_EXTRA_DATA);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, is this cheaper to do in assembly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope. That's why I removed it.

@Vectorized Vectorized merged commit 7eae303 into chiru-labs:main Jun 15, 2022
@Vectorized Vectorized deleted the feature/directExtraData branch July 18, 2022 00:05
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.

2 participants