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

Make asset ids valid standard UUIDs. #1737

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion pallets/asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2224,8 +2224,9 @@ impl<T: Config> Module<T> {
}

pub fn generate_asset_id(caller_acc: T::AccountId, update: bool) -> AssetID {
let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero());
let nonce = Self::get_nonce(&caller_acc, update);
blake2_128(&(b"modlpy/pallet_asset", caller_acc, nonce).encode()).into()
blake2_128(&(b"modlpy/pallet_asset", genesis_hash, caller_acc, nonce).encode()).into()
}

fn get_nonce(caller_acc: &T::AccountId, update: bool) -> u64 {
Expand Down
8 changes: 6 additions & 2 deletions primitives/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ use polymesh_primitives_derive::VecU8StrongTyped;
pub struct AssetID([u8; 16]);

impl From<[u8; 16]> for AssetID {
fn from(value: [u8; 16]) -> Self {
fn from(mut value: [u8; 16]) -> Self {
// Version 8.
value[6] = (value[6] & 0x0f) | 0x80;
// Standard RFC4122 variant (bits 10xx)
value[8] = (value[8] & 0x3f) | 0x80;
AssetID(value)
}
}

impl AssetID {
/// Creates a new [`AssetID`] instance;
pub fn new(value: [u8; 16]) -> Self {
AssetID(value)
value.into()
}

/// Converts [`AssetID`] type into a shared reference of bytes.
Expand Down