Skip to content
Snippets Groups Projects
Unverified Commit 098811da authored by Petr Mensik's avatar Petr Mensik Committed by GitHub
Browse files

Add genesis config for nft (#351)

* Updated Substrate version

* Add genesis config for storage

* Remove unnecessary struct

* Refactored add_genesis_config section

* Add proper handling

* Refactor genesis BTreeMap to Vec

* Add comments to genesis type aliases
parent 0e859578
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ authors = ["Acala Developers"]
edition = "2018"
[dependencies]
serde = { version = "1.0.111", optional = true }
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }
sp-std = { version = "2.0.1", default-features = false }
sp-runtime = { version = "2.0.1", default-features = false }
......@@ -22,6 +23,7 @@ sp-core = { version = "2.0.1", default-features = false }
[features]
default = ["std"]
std = [
"serde",
"codec/std",
"sp-std/std",
"sp-runtime/std",
......
......@@ -91,6 +91,18 @@ pub type ClassInfoOf<T> =
ClassInfo<<T as Config>::TokenId, <T as frame_system::Config>::AccountId, <T as Config>::ClassData>;
pub type TokenInfoOf<T> = TokenInfo<<T as frame_system::Config>::AccountId, <T as Config>::TokenData>;
pub type GenesisTokenData<T> = (
<T as frame_system::Config>::AccountId, // Token owner
Vec<u8>, // Token metadata
<T as Config>::TokenData,
);
pub type GenesisTokens<T> = (
<T as frame_system::Config>::AccountId, // Token class owner
Vec<u8>, // Token class metadata
<T as Config>::ClassData,
Vec<GenesisTokenData<T>>, // Vector of tokens belonging to this class
);
decl_storage! {
trait Store for Module<T: Config> as NonFungibleToken {
/// Next available class ID.
......@@ -109,6 +121,20 @@ decl_storage! {
#[cfg(not(feature = "disable-tokens-by-owner"))]
pub TokensByOwner get(fn tokens_by_owner): double_map hasher(twox_64_concat) T::AccountId, hasher(twox_64_concat) (T::ClassId, T::TokenId) => Option<()>;
}
add_extra_genesis {
config(tokens): Vec<GenesisTokens<T>>;
build(|config: &GenesisConfig<T>| {
config.tokens.iter().for_each(|token_class| {
let class_id = Module::<T>::create_class(&token_class.0, token_class.1.to_vec(), token_class.2.clone())
.expect("Create class cannot fail while building genesis");
for (account_id, token_metadata, token_data) in &token_class.3 {
Module::<T>::mint(&account_id, class_id, token_metadata.to_vec(), token_data.clone())
.expect("Token mint cannot fail during genesis");
}
})
})
}
}
decl_module! {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment