-
Notifications
You must be signed in to change notification settings - Fork 0
solidity create collection return an ethereum address #103
solidity create collection return an ethereum address #103
Conversation
asiniscalchi
commented
Aug 3, 2023
•
edited
Loading
edited
- create collection return address to ERC721
- create collection emit event
- removed owner of
…dity_create_collection_return_an_address
precompile/living-assets/src/lib.rs
Outdated
/// `from_low_u64_be` method to convert the `u64` value into the lower 64 bits of the `H160`. | ||
/// Additionally, the function sets the first bit of the resulting `H160` to 1, which can be used to | ||
/// distinguish addresses created by this function from other addresses. | ||
pub fn collection_id_to_address(collection_id: CollectionId) -> H160 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would suggest refactoring it to a trait with default implementation. this way it looks nicer and will be more extensible
pub trait CollectonIdToAddress {
fn collection_id_to_address(collection_id: CollectionId) -> H160 {
let mut address = H160::from_low_u64_be(collection_id);
address.0[0] |= 0x80; // Set the first bit to 1
address
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see why you'd think that way, but for now, I'm not inclined to generalize this part of the code. I usually prefer to keep things simple until there's a real need to make them more complex. If someone needs to extend this in the future, they can take care of it then.
By the way, you were spot on about the public visibility. That was a mistake on my part, and I'll be fixing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was suggesting it mainly because it's not idiomatic to do conversions with a regular function, instead use an existing trait (From
, Into
, sp_runtime::Convert
), or declare new one. I am ok with this way of doing it of course, just looks a bit odd to me