difftreelog
Merge pull request #37 from usetech-llc/feature/nftpar_164
in: master
Feature/nftpar 164
5 files changed
node/Cargo.tomldiffbeforeafterboth--- a/node/Cargo.toml
+++ b/node/Cargo.toml
@@ -23,6 +23,7 @@
[dependencies]
futures = '0.3.4'
log = '0.4.8'
+flexi_logger = "0.15.7"
parking_lot = '0.10.0'
structopt = '0.3.8'
jsonrpc-core = '15.0.0'
node/src/chain_spec.rsdiffbeforeafterboth--- a/node/src/chain_spec.rs
+++ b/node/src/chain_spec.rs
@@ -167,7 +167,8 @@
description: vec![],
token_prefix: vec![],
mint_mode: false,
- offchain_schema: vec![],
+ offchain_schema: vec![],
+ schema_version: SchemaVersion::default(),
sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),
unconfirmed_sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),
const_on_chain_schema: vec![],
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -1,3 +1,5 @@
+#![recursion_limit = "1024"]
+
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "std")]
@@ -54,7 +56,6 @@
pub type CollectionId = u32;
pub type TokenId = u32;
-
pub type DecimalPoints = u8;
#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
@@ -97,6 +98,18 @@
}
}
+#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub enum SchemaVersion {
+ ImageURL,
+ Unique,
+}
+impl Default for SchemaVersion {
+ fn default() -> Self {
+ Self::ImageURL
+ }
+}
+
#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct Ownership<AccountId> {
@@ -116,6 +129,7 @@
pub token_prefix: Vec<u8>, // 16 include null escape char
pub mint_mode: bool,
pub offchain_schema: Vec<u8>,
+ pub schema_version: SchemaVersion,
pub sponsor: AccountId, // Who pays fees. If set to default address, the fees are applied to the transaction sender
pub unconfirmed_sponsor: AccountId, // Sponsor address that has not yet confirmed sponsorship
pub limits: CollectionLimits, // Collection private restrictions
@@ -258,7 +272,7 @@
pub enum CreateItemData {
NFT(CreateNftData),
Fungible(CreateFungibleData),
- ReFungible(CreateReFungibleData)
+ ReFungible(CreateReFungibleData),
}
impl CreateItemData {
@@ -570,6 +584,7 @@
decimal_points: decimal_points,
token_prefix: prefix,
offchain_schema: Vec::new(),
+ schema_version: SchemaVersion::ImageURL,
sponsor: T::AccountId::default(),
unconfirmed_sponsor: T::AccountId::default(),
variable_on_chain_schema: Vec::new(),
@@ -1200,7 +1215,6 @@
Ok(())
}
- ///
#[weight = 0]
pub fn safe_transfer_from(origin, collection_id: CollectionId, item_id: TokenId, new_owner: T::AccountId) -> DispatchResult {
@@ -1259,7 +1273,35 @@
Ok(())
}
-
+
+ /// Set schema standard
+ /// ImageURL
+ /// Unique
+ ///
+ /// # Permissions
+ ///
+ /// * Collection Owner
+ /// * Collection Admin
+ ///
+ /// # Arguments
+ ///
+ /// * collection_id.
+ ///
+ /// * schema: SchemaVersion: enum
+ #[weight = 0]
+ pub fn set_schema_version(
+ origin,
+ collection_id: CollectionId,
+ version: SchemaVersion
+ ) -> DispatchResult {
+ let sender = ensure_signed(origin)?;
+ Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;
+ let mut target_collection = <Collection<T>>::get(collection_id);
+ target_collection.schema_version = version;
+ <Collection<T>>::insert(collection_id, target_collection);
+
+ Ok(())
+ }
/// Set off-chain data schema.
///
@@ -1458,7 +1500,7 @@
impl<T: Trait> Module<T> {
fn is_correct_transfer(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, recipient: &T::AccountId) -> DispatchResult {
-
+
// check token limit and account token limit
let account_items: u32 = <AddressTokens<T>>::get(collection_id, recipient).len() as u32;
ensure!(collection.limits.account_token_ownership_limit > account_items, Error::<T>::AccountTokenLimitExceeded);
pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -77,6 +77,19 @@
// Use cases tests region
// #region
+
+#[test]
+fn set_version_schema() {
+ new_test_ext().execute_with(|| {
+ default_limits();
+ let origin1 = Origin::signed(1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+
+ assert_ok!(TemplateModule::set_schema_version(origin1, collection_id, SchemaVersion::Unique));
+ assert_eq!(TemplateModule::collection(collection_id).schema_version, SchemaVersion::Unique);
+ });
+}
+
#[test]
fn create_fungible_collection_fails_with_large_decimal_numbers() {
new_test_ext().execute_with(|| {
runtime_types.jsondiffbeforeafterboth1{2 "Schedule": {3 "version": "u32",4 "put_code_per_byte_cost": "Gas",5 "grow_mem_cost": "Gas",6 "regular_op_cost": "Gas",7 "return_data_per_byte_cost": "Gas",8 "event_data_per_byte_cost": "Gas",9 "event_per_topic_cost": "Gas",10 "event_base_cost": "Gas",11 "call_base_cost": "Gas",12 "instantiate_base_cost": "Gas",13 "dispatch_base_cost": "Gas",14 "sandbox_data_read_cost": "Gas",15 "sandbox_data_write_cost": "Gas",16 "transfer_cost": "Gas",17 "instantiate_cost": "Gas",18 "max_event_topics": "u32",19 "max_stack_height": "u32",20 "max_memory_pages": "u32",21 "max_table_size": "u32",22 "enable_println": "bool",23 "max_subject_len": "u32"24 },25 "AccessMode": {26 "_enum": [27 "Normal",28 "WhiteList"29 ]30 },31 "DecimalPoints": "u8",32 "CollectionMode": {33 "_enum": {34 "Invalid": null,35 "NFT": null,36 "Fungible": "DecimalPoints",37 "ReFungible": "DecimalPoints"38 }39 },40 "Ownership": {41 "Owner": "AccountId",42 "Fraction": "u128"43 },44 "FungibleItemType": {45 "Collection": "CollectionId",46 "Owner": "AccountId",47 "Value": "u128"48 },49 "NftItemType": {50 "Collection": "CollectionId",51 "Owner": "AccountId",52 "ConstData": "Vec<u8>",53 "VariableData": "Vec<u8>"54 },55 "ReFungibleItemType": {56 "Collection": "CollectionId",57 "Owner": "Vec<Ownership<AccountId>>",58 "ConstData": "Vec<u8>",59 "VariableData": "Vec<u8>"60 },61 "CollectionType": {62 "Owner": "AccountId",63 "Mode": "CollectionMode",64 "Access": "AccessMode",65 "DecimalPoints": "DecimalPoints",66 "Name": "Vec<u16>",67 "Description": "Vec<u16>",68 "TokenPrefix": "Vec<u8>",69 "MintMode": "bool",70 "OffchainSchema": "Vec<u8>",71 "Sponsor": "AccountId",72 "UnconfirmedSponsor": "AccountId",73 "Limits": "CollectionLimits",74 "VariableOnChainSchema": "Vec<u8>",75 "ConstOnChainSchema": "Vec<u8>"76 },77 "ApprovePermissions": {78 "Approved": "AccountId",79 "Amount": "u128"80 },81 "RawData": "Vec<u8>",82 "Address": "AccountId",83 "LookupSource": "AccountId",84 "Weight": "u64",85 "CreateNftData": {86 "const_data": "Vec<u8>",87 "variable_data": "Vec<u8>" 88 },89 "CreateFungibleData": {},90 "CreateReFungibleData": {91 "const_data": "Vec<u8>",92 "variable_data": "Vec<u8>" 93 },94 "CreateItemData": {95 "_enum": {96 "NFT": "CreateNftData",97 "Fungible": "CreateFungibleData",98 "ReFungible": "CreateReFungibleData"99 }100 },101 "CollectionId": "u32",102 "TokenId": "u32",103 "BasketItem": {104 "Address": "AccountId",105 "start_block": "BlockNumber"106 },107 "ChainLimits": {108 "collection_numbers_limit": "u32",109 "account_token_ownership_limit": "u32",110 "collections_admins_limit": "u64",111 "custom_data_limit": "u32",112 "nft_sponsor_timeout": "u32",113 "fungible_sponsor_timeout": "u32",114 "refungible_sponsor_timeout": "u32"115 },116 "CollectionLimits": {117 "AccountTokenOwnershipLimit": "u32",118 "SponsoredMintSize": "u32",119 "TokenLimit": "u32",120 "SponsorTimeout": "u32"121 }122 }123 1{2 "Schedule": {3 "version": "u32",4 "put_code_per_byte_cost": "Gas",5 "grow_mem_cost": "Gas",6 "regular_op_cost": "Gas",7 "return_data_per_byte_cost": "Gas",8 "event_data_per_byte_cost": "Gas",9 "event_per_topic_cost": "Gas",10 "event_base_cost": "Gas",11 "call_base_cost": "Gas",12 "instantiate_base_cost": "Gas",13 "dispatch_base_cost": "Gas",14 "sandbox_data_read_cost": "Gas",15 "sandbox_data_write_cost": "Gas",16 "transfer_cost": "Gas",17 "instantiate_cost": "Gas",18 "max_event_topics": "u32",19 "max_stack_height": "u32",20 "max_memory_pages": "u32",21 "max_table_size": "u32",22 "enable_println": "bool",23 "max_subject_len": "u32"24 },25 "AccessMode": {26 "_enum": [27 "Normal",28 "WhiteList"29 ]30 },31 "DecimalPoints": "u8",32 "CollectionMode": {33 "_enum": {34 "Invalid": null,35 "NFT": null,36 "Fungible": "DecimalPoints",37 "ReFungible": "DecimalPoints"38 }39 },40 "Ownership": {41 "Owner": "AccountId",42 "Fraction": "u128"43 },44 "FungibleItemType": {45 "Collection": "CollectionId",46 "Owner": "AccountId",47 "Value": "u128"48 },49 "NftItemType": {50 "Collection": "CollectionId",51 "Owner": "AccountId",52 "ConstData": "Vec<u8>",53 "VariableData": "Vec<u8>"54 },55 "ReFungibleItemType": {56 "Collection": "CollectionId",57 "Owner": "Vec<Ownership<AccountId>>",58 "ConstData": "Vec<u8>",59 "VariableData": "Vec<u8>"60 },61 "CollectionType": {62 "Owner": "AccountId",63 "Mode": "CollectionMode",64 "Access": "AccessMode",65 "DecimalPoints": "DecimalPoints",66 "Name": "Vec<u16>",67 "Description": "Vec<u16>",68 "TokenPrefix": "Vec<u8>",69 "MintMode": "bool",70 "OffchainSchema": "Vec<u8>",71 "SchemaVersion": "SchemaVersion",72 "Sponsor": "AccountId",73 "UnconfirmedSponsor": "AccountId",74 "Limits": "CollectionLimits",75 "VariableOnChainSchema": "Vec<u8>",76 "ConstOnChainSchema": "Vec<u8>"77 },78 "ApprovePermissions": {79 "Approved": "AccountId",80 "Amount": "u128"81 },82 "RawData": "Vec<u8>",83 "Address": "AccountId",84 "LookupSource": "AccountId",85 "Weight": "u64",86 "CreateNftData": {87 "const_data": "Vec<u8>",88 "variable_data": "Vec<u8>" 89 },90 "CreateFungibleData": {},91 "CreateReFungibleData": {92 "const_data": "Vec<u8>",93 "variable_data": "Vec<u8>" 94 },95 "CreateItemData": {96 "_enum": {97 "NFT": "CreateNftData",98 "Fungible": "CreateFungibleData",99 "ReFungible": "CreateReFungibleData"100 }101 },102 "SchemaVersion": {103 "_enum": [104 "ImageURL",105 "Unique"106 ]107 },108 "CollectionId": "u32",109 "TokenId": "u32",110 "BasketItem": {111 "Address": "AccountId",112 "start_block": "BlockNumber"113 },114 "ChainLimits": {115 "collection_numbers_limit": "u32",116 "account_token_ownership_limit": "u32",117 "collections_admins_limit": "u64",118 "custom_data_limit": "u32",119 "nft_sponsor_timeout": "u32",120 "fungible_sponsor_timeout": "u32",121 "refungible_sponsor_timeout": "u32"122 },123 "CollectionLimits": {124 "AccountTokenOwnershipLimit": "u32",125 "SponsoredMintSize": "u32",126 "TokenLimit": "u32",127 "SponsorTimeout": "u32"128 }129 }130