difftreelog
add extra genesis
in: master
3 files changed
node/src/chain_spec.rsdiffbeforeafterboth--- a/node/src/chain_spec.rs
+++ b/node/src/chain_spec.rs
@@ -1,8 +1,9 @@
-use nft_runtime::{
- AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig,
- SystemConfig, WASM_BINARY,
-};
-use nft_runtime::{ContractsConfig, ContractsSchedule};
+// use nft_runtime::{
+// AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig,
+// SystemConfig, WASM_BINARY,
+// };
+// use nft_runtime::{ContractsConfig, ContractsSchedule, NftConfig, CollectionType};
+use nft_runtime::*;
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{sr25519, Pair, Public};
@@ -128,6 +129,25 @@
.collect(),
}),
sudo: Some(SudoConfig { key: root_key }),
+ nft: Some(NftConfig {
+ collection: vec![(1, CollectionType {
+ owner: get_account_id_from_seed::<sr25519::Public>("Alice"),
+ mode: CollectionMode::NFT(50),
+ access: AccessMode::Normal,
+ decimal_points: 0,
+ name: vec!(),
+ description: vec!(),
+ token_prefix: vec!(),
+ custom_data_size: 50,
+ mint_mode: false,
+ offchain_schema: vec!(),
+ sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),
+ unconfirmed_sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),
+ })],
+ nft_item_id: vec!(),
+ fungible_item_id: vec!(),
+ refungible_item_id: vec!(),
+ }),
contracts: Some(ContractsConfig {
current_schedule: ContractsSchedule {
enable_println,
pallets/nft/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]1#![cfg_attr(not(feature = "std"), no_std)]223/// For more guidance on Substrate FRAME, see the example pallet3#[cfg(feature = "std")]4/// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs4pub use serde::*;55use codec::{Decode, Encode};6use codec::{Decode, Encode};6pub use frame_support::{7pub use frame_support::{32 },33 },33 FixedPointOperand, FixedU128,34 FixedPointOperand, FixedU128,34};35};35use sp_std::prelude::*;363637#[cfg(test)]37#[cfg(test)]38mod mock;38mod mock;393940#[cfg(test)]40#[cfg(test)]41mod tests;41mod tests;424243#[derive(Encode, Decode, Debug, Eq, Clone, PartialEq)]43#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]44#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]44pub enum CollectionMode {45pub enum CollectionMode {45 Invalid,46 Invalid,46 // custom data size47 // custom data size62 }63 }63}64}646565#[derive(Encode, Decode, Debug, Clone, PartialEq)]66#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]67#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]66pub enum AccessMode {68pub enum AccessMode {67 Normal,69 Normal,68 WhiteList,70 WhiteList,79 }81 }80}82}818382#[derive(Encode, Decode, Default, Clone, PartialEq)]84#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]83#[cfg_attr(feature = "std", derive(Debug))]85#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]84pub struct Ownership<AccountId> {86pub struct Ownership<AccountId> {85 pub owner: AccountId,87 pub owner: AccountId,86 pub fraction: u128,88 pub fraction: u128,87}89}889089#[derive(Encode, Decode, Default, Clone, PartialEq)]91#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]90#[cfg_attr(feature = "std", derive(Debug))]92#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]91pub struct CollectionType<AccountId> {93pub struct CollectionType<AccountId> {92 pub owner: AccountId,94 pub owner: AccountId,93 pub mode: CollectionMode,95 pub mode: CollectionMode,103 pub unconfirmed_sponsor: AccountId, // Sponsor address that has not yet confirmed sponsorship105 pub unconfirmed_sponsor: AccountId, // Sponsor address that has not yet confirmed sponsorship104}106}105107106#[derive(Encode, Decode, Default, Clone, PartialEq)]108#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]107#[cfg_attr(feature = "std", derive(Debug))]109#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]108pub struct CollectionAdminsType<AccountId> {110pub struct CollectionAdminsType<AccountId> {109 pub admin: AccountId,111 pub admin: AccountId,110 pub collection_id: u64,112 pub collection_id: u64,111}113}112114113#[derive(Encode, Decode, Default, Clone, PartialEq)]115#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]114#[cfg_attr(feature = "std", derive(Debug))]116#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]115pub struct NftItemType<AccountId> {117pub struct NftItemType<AccountId> {116 pub collection: u64,118 pub collection: u64,117 pub owner: AccountId,119 pub owner: AccountId,118 pub data: Vec<u8>,120 pub data: Vec<u8>,119}121}120122121#[derive(Encode, Decode, Default, Clone, PartialEq)]123#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]122#[cfg_attr(feature = "std", derive(Debug))]124#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]123pub struct FungibleItemType<AccountId> {125pub struct FungibleItemType<AccountId> {124 pub collection: u64,126 pub collection: u64,125 pub owner: AccountId,127 pub owner: AccountId,126 pub value: u128,128 pub value: u128,127}129}128130129#[derive(Encode, Decode, Default, Clone, PartialEq)]131#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]130#[cfg_attr(feature = "std", derive(Debug))]132#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]131pub struct ReFungibleItemType<AccountId> {133pub struct ReFungibleItemType<AccountId> {132 pub collection: u64,134 pub collection: u64,133 pub owner: Vec<Ownership<AccountId>>,135 pub owner: Vec<Ownership<AccountId>>,134 pub data: Vec<u8>,136 pub data: Vec<u8>,135}137}136138137#[derive(Encode, Decode, Default, Clone, PartialEq)]139#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]138#[cfg_attr(feature = "std", derive(Debug))]140#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]139pub struct ApprovePermissions<AccountId> {141pub struct ApprovePermissions<AccountId> {140 pub approved: AccountId,142 pub approved: AccountId,141 pub amount: u64,143 pub amount: u64,142}144}143145144#[derive(Encode, Decode, Default, Clone, PartialEq)]146#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]145#[cfg_attr(feature = "std", derive(Debug))]147#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]146pub struct VestingItem<AccountId, Moment> {148pub struct VestingItem<AccountId, Moment> {147 pub sender: AccountId,149 pub sender: AccountId,148 pub recipient: AccountId,150 pub recipient: AccountId,165 ChainVersion: u64;167 ChainVersion: u64;166 ItemListIndex: map hasher(blake2_128_concat) u64 => u64;168 ItemListIndex: map hasher(blake2_128_concat) u64 => u64;167169168 pub Collection get(fn collection): map hasher(identity) u64 => CollectionType<T::AccountId>;170 pub Collection get(fn collection) config(): map hasher(identity) u64 => CollectionType<T::AccountId>;169 pub AdminList get(fn admin_list_collection): map hasher(identity) u64 => Vec<T::AccountId>;171 pub AdminList get(fn admin_list_collection): map hasher(identity) u64 => Vec<T::AccountId>;170 pub WhiteList get(fn white_list): map hasher(identity) u64 => Vec<T::AccountId>;172 pub WhiteList get(fn white_list): map hasher(identity) u64 => Vec<T::AccountId>;171173176 pub ApprovedList get(fn approved): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) (u64, T::AccountId) => Vec<ApprovePermissions<T::AccountId>>;178 pub ApprovedList get(fn approved): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) (u64, T::AccountId) => Vec<ApprovePermissions<T::AccountId>>;177179178 /// Item collections180 /// Item collections179 pub NftItemList get(fn nft_item_id): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => NftItemType<T::AccountId>;181 pub NftItemList get(fn nft_item_id) config(): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => NftItemType<T::AccountId>;180 pub FungibleItemList get(fn fungible_item_id): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => FungibleItemType<T::AccountId>;182 pub FungibleItemList get(fn fungible_item_id) config(): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => FungibleItemType<T::AccountId>;181 pub ReFungibleItemList get(fn refungible_item_id): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => ReFungibleItemType<T::AccountId>;183 pub ReFungibleItemList get(fn refungible_item_id) config(): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => ReFungibleItemType<T::AccountId>;182184183 /// Index list185 /// Index list184 pub AddressTokens get(fn address_tokens): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) T::AccountId => Vec<u64>;186 pub AddressTokens get(fn address_tokens): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) T::AccountId => Vec<u64>;187 pub ContractSponsor get(fn contract_sponsor): map hasher(identity) T::AccountId => T::AccountId;189 pub ContractSponsor get(fn contract_sponsor): map hasher(identity) T::AccountId => T::AccountId;188 pub UnconfirmedContractSponsor get(fn unconfirmed_contract_sponsor): map hasher(identity) T::AccountId => T::AccountId;190 pub UnconfirmedContractSponsor get(fn unconfirmed_contract_sponsor): map hasher(identity) T::AccountId => T::AccountId;189 }191 }192 add_extra_genesis {193 build(|config: &GenesisConfig<T>| {194 // Modification of storage195 for (_num, _c) in &config.collection {196 <Module<T>>::init_collection(_c);197 }198199 for (_num, _q, _i) in &config.nft_item_id {200 <Module<T>>::init_nft_token(_i);201 }202203 for (_num, _q, _i) in &config.fungible_item_id {204 <Module<T>>::init_fungible_token(_i);205 }206207 for (_num, _q, _i) in &config.refungible_item_id {208 <Module<T>>::init_refungible_token(_i);209 }210 })211 }190}212}191213192decl_event!(214decl_event!(568590569 let sender = ensure_signed(origin)?;591 let sender = ensure_signed(origin)?;592593 // Check access and mint mode 594 let target_collection = <Collection<T>>::get(collection_id);570 Self::check_white_list(collection_id, sender.clone())?;595 if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) {596597 Self::check_white_list(collection_id, sender.clone())?;571 Self::check_white_list(collection_id, recipient.clone())?;598 Self::check_white_list(collection_id, recipient.clone())?;572 let target_collection = <Collection<T>>::get(collection_id);599 ensure!(target_collection.access == AccessMode::WhiteList, "Collection must have WhiteList access");600 ensure!(target_collection.mint_mode == true, "Collection must be in mint mode");601 }573602574 match target_collection.mode603 match target_collection.mode575 {604 {623624 ensure!(approved_list_exists, "Only approved addresses can call this method");652 ensure!(approved_list_exists, "Only approved addresses can call this method");625626 Self::check_white_list(collection_id, from.clone())?;627 Self::check_white_list(collection_id, recipient.clone())?;628653629 let list_itm = <ApprovedList<T>>::get(collection_id, (item_id, from.clone()));654 let list_itm = <ApprovedList<T>>::get(collection_id, (item_id, from.clone()));630 let opt_item = list_itm.iter().find(|i| i.approved == sender.clone());655 let opt_item = list_itm.iter().find(|i| i.approved == sender.clone());631 ensure!(opt_item.is_some(), "No approve found");656 ensure!(opt_item.is_some(), "No approve found");632 ensure!(opt_item.unwrap().amount >= value, "Requested value more than approved");657 ensure!(opt_item.unwrap().amount >= value, "Requested value more than approved");658659 // Check access and mint mode 660 let target_collection = <Collection<T>>::get(collection_id);661 if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) {662663 Self::check_white_list(collection_id, sender.clone())?;664 Self::check_white_list(collection_id, recipient.clone())?;665 ensure!(target_collection.access == AccessMode::WhiteList, "Collection must have WhiteList access");666 ensure!(target_collection.mint_mode == true, "Collection must be in mint mode");667 }633668634 // remove approve669 // remove approve635 let approve_list: Vec<ApprovePermissions<T::AccountId>> = <ApprovedList<T>>::get(collection_id, (item_id, from.clone()))670 let approve_list: Vec<ApprovePermissions<T::AccountId>> = <ApprovedList<T>>::get(collection_id, (item_id, from.clone()))636 .into_iter().filter(|i| i.approved != sender.clone()).collect();671 .into_iter().filter(|i| i.approved != sender.clone()).collect();637 <ApprovedList<T>>::insert(collection_id, (item_id, from.clone()), approve_list);672 <ApprovedList<T>>::insert(collection_id, (item_id, from.clone()), approve_list);638673639 let target_collection = <Collection<T>>::get(collection_id);640674641 match target_collection.mode675 match target_collection.mode642 {676 {1114 Ok(())1148 Ok(())1115 }1149 }11501151 fn init_collection(item: &CollectionType<T::AccountId>){11521153 // check params1154 assert!(item.decimal_points <= 4, "decimal_points parameter must be lower than 4");1155 assert!(item.name.len() <= 64, "Collection name can not be longer than 63 char");1156 assert!(item.name.len() <= 256, "Collection description can not be longer than 255 char");1157 assert!(item.token_prefix.len() <= 16, "Token prefix can not be longer than 15 char");1158 1159 // Generate next collection ID1160 let next_id = CreatedCollectionCount::get()1161 .checked_add(1)1162 .expect("collection id error");1163 1164 CreatedCollectionCount::put(next_id); 1165 }11661167 fn init_nft_token(item: &NftItemType<T::AccountId>){11681169 let current_index = <ItemListIndex>::get(item.collection)1170 .checked_add(1)1171 .expect("Item list index id error");11721173 let item_owner = item.owner.clone();1174 let collection_id = item.collection.clone();1175 Self::add_token_index(collection_id, current_index, item.owner.clone()).unwrap();11761177 <ItemListIndex>::insert(collection_id, current_index);11781179 // Update balance1180 let new_balance = <Balance<T>>::get(collection_id, item_owner.clone())1181 .checked_add(1)1182 .unwrap();1183 <Balance<T>>::insert(collection_id, item_owner.clone(), new_balance);1184 }11851186 fn init_fungible_token(item: &FungibleItemType<T::AccountId>){11871188 let current_index = <ItemListIndex>::get(item.collection)1189 .checked_add(1)1190 .expect("Item list index id error");1191 let owner = item.owner.clone();1192 let value = item.value as u64;11931194 Self::add_token_index(item.collection, current_index, owner.clone()).unwrap();11951196 <ItemListIndex>::insert(item.collection, current_index);11971198 // Update balance1199 let new_balance = <Balance<T>>::get(item.collection, owner.clone())1200 .checked_add(value)1201 .unwrap();1202 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);1203 }12041205 fn init_refungible_token(item: &ReFungibleItemType<T::AccountId>){12061207 let current_index = <ItemListIndex>::get(item.collection)1208 .checked_add(1)1209 .expect("Item list index id error");12101211 let value = item.owner.first().unwrap().fraction as u64;1212 let owner = item.owner.first().unwrap().owner.clone();12131214 Self::add_token_index(item.collection, current_index, owner.clone()).unwrap();12151216 <ItemListIndex>::insert(item.collection, current_index);12171218 // Update balance1219 let new_balance = <Balance<T>>::get(item.collection, owner.clone())1220 .checked_add(value)1221 .unwrap();1222 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);1223 }111612241117 fn add_token_index(collection_id: u64, item_index: u64, owner: T::AccountId) -> DispatchResult {1225 fn add_token_index(collection_id: u64, item_index: u64, owner: T::AccountId) -> DispatchResult {1118 let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.clone());1226 let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.clone());runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -53,8 +53,10 @@
pub use timestamp::Call as TimestampCall;
-/// Importing a nft pallet
-pub use nft;
+/// Re-export a nft pallet
+/// TODO: Check this re-export. Is this safe and good style?
+extern crate nft;
+pub use nft::*;
/// An index to a block.
pub type BlockNumber = u32;
@@ -318,7 +320,7 @@
Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},
TransactionPayment: transaction_payment::{Module, Storage},
Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>},
- Nft: nft::{Module, Call, Storage, Event<T>},
+ Nft: nft::{Module, Call, Config<T>, Storage, Event<T>},
}
);