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

(NFT standard) Why is the owner_id hashed as the prefix in tokens_per_owner? #677

Open
willemneal opened this issue Dec 21, 2021 · 1 comment

Comments

@willemneal
Copy link
Contributor

willemneal commented Dec 21, 2021

// Enumeration extension: Record tokens_per_owner for use with enumeration view methods.
if let Some(tokens_per_owner) = &mut self.tokens_per_owner {
let mut token_ids = tokens_per_owner.get(&owner_id).unwrap_or_else(|| {
UnorderedSet::new(StorageKey::TokensPerOwner {
account_hash: env::sha256(owner_id.as_bytes()),
})
});
token_ids.insert(&token_id);
tokens_per_owner.insert(&owner_id, &token_ids);
}

It seems that you end up paying more to 1) hash the string and 2) store more bytes than with just the account_id.

@austinabell
Copy link
Contributor

It seems that you end up paying more to 1) hash the string and 2) store more bytes than with just the account_id.

Depends on the size of the account id. Account Ids can be up to 64 bytes in length, whereas the hash is always 32. I'm not sure if this change was benchmarked, but possibly was done to close the gap in costs between long and short lengths?

This doesn't affect the interface so it's really not part of the standard and if for whatever reason someone wanted to modify this, they would have the freedom to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: NEW❗
Development

No branches or pull requests

2 participants