git.delta.rocks / unique-network / refs/commits / d96245d01eab

difftreelog

Unit tests added

str-mv2020-09-08parent: #aa92af0.patch.diff
in: master

3 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -129,6 +129,18 @@
     pub amount: u64
 }
 
+#[derive(Encode, Decode, Default, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Debug))]
+pub struct VestingItem<AccountId, Moment>
+{
+    pub sender: AccountId,
+    pub recipient: AccountId,
+    pub collection_id: u64,
+    pub item_id: u64,
+    pub amount: u64,
+    pub vesting_date: Moment
+}
+
 pub trait Trait: system::Trait {
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
 
@@ -156,6 +168,10 @@
         pub FungibleItemList get(fn fungible_item_id): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => FungibleItemType<T::AccountId>;
         pub ReFungibleItemList get(fn refungible_item_id): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => ReFungibleItemType<T::AccountId>;
 
+        // Active vesting list
+        // pub VestingList get(fn vesting): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => VestingItem<T::AccountId, T::Moment>;
+
+        /// Index list
         pub AddressTokens get(fn address_tokens): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) T::AccountId => Vec<u64>;
 
         // Sponsorship
@@ -636,6 +652,7 @@
 
     fn burn_refungible_item(collection_id: u64, item_id: u64, owner: T::AccountId) -> DispatchResult {
   
+        ensure!(<ReFungibleItemList<T>>::contains_key(collection_id, item_id), "Item does not exists");
         let collection = <ReFungibleItemList<T>>::get(collection_id, item_id);
         let item = collection.owner.iter().filter(|&i| i.owner == owner).next().unwrap();
         Self::remove_token_index(collection_id, item_id, owner.clone())?;
@@ -655,6 +672,7 @@
 
     fn burn_nft_item(collection_id: u64, item_id: u64) -> DispatchResult {
   
+        ensure!(<NftItemList<T>>::contains_key(collection_id, item_id), "Item does not exists");
         let item = <NftItemList<T>>::get(collection_id, item_id);
         Self::remove_token_index(collection_id, item_id, item.owner.clone())?;
 
@@ -671,6 +689,7 @@
 
     fn burn_fungible_item(collection_id: u64, item_id: u64) -> DispatchResult {
   
+        ensure!(<FungibleItemList<T>>::contains_key(collection_id, item_id), "Item does not exists");
         let item = <FungibleItemList<T>>::get(collection_id, item_id);
         Self::remove_token_index(collection_id, item_id, item.owner.clone())?;
 
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -183,7 +183,6 @@
     });
 }
 
-
 #[test]
 fn transfer_nft_item() {
     new_test_ext().execute_with(|| {
@@ -364,580 +363,416 @@
     });
 }
 
+#[test]
+fn change_collection_owner() {
+    new_test_ext().execute_with(|| {
+        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        let mode: CollectionMode = CollectionMode::NFT(2000);
 
+        let origin1 = Origin::signed(1);
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode
+        ));
+        assert_ok!(TemplateModule::change_collection_owner(
+            origin1.clone(),
+            1,
+            2
+        ));
+        assert_eq!(TemplateModule::collection(1).owner, 2);
+    });
+}
 
+#[test]
+fn destroy_collection() {
+    new_test_ext().execute_with(|| {
+        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        let mode: CollectionMode = CollectionMode::NFT(2000);
 
+        let origin1 = Origin::signed(1);
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode
+        ));
+        assert_ok!(TemplateModule::destroy_collection(origin1.clone(), 1));
+    });
+}
 
+#[test]
+fn burn_nft_item() {
+    new_test_ext().execute_with(|| {
+        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        let mode: CollectionMode = CollectionMode::NFT(2000);
 
+        let origin1 = Origin::signed(1);
+        let origin2 = Origin::signed(2);
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode
+        ));
+        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));
+        assert_ok!(TemplateModule::create_item(
+            origin2.clone(),
+            1,
+            [1, 2, 3].to_vec(),
+            1
+        ));
 
+        assert_eq!(TemplateModule::nft_item_id(1,1).data, [1,2,3].to_vec());
 
+        // check balance (collection with id = 1, user id = 1)
+        assert_eq!(TemplateModule::balance_count(1, 1), 1);
 
+        // burn item
+        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));
+        assert_noop!(
+            TemplateModule::burn_item(origin1.clone(), 1, 1),
+            "Item does not exists"
+        );
 
+        assert_eq!(TemplateModule::balance_count(1, 1), 0);
+    });
+}
 
+#[test]
+fn burn_fungible_item() {
+    new_test_ext().execute_with(|| {
+        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        let mode: CollectionMode = CollectionMode::Fungible(3);
 
+        let origin1 = Origin::signed(1);
+        let origin2 = Origin::signed(2);
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode
+        ));
+        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));
+        assert_ok!(TemplateModule::create_item(
+            origin2.clone(),
+            1,
+            [].to_vec(),
+            1
+        ));
 
+        // check balance (collection with id = 1, user id = 1)
+        assert_eq!(TemplateModule::balance_count(1, 1), 1000);
 
+        // burn item
+        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));
+        assert_noop!(
+            TemplateModule::burn_item(origin1.clone(), 1, 1),
+            "Item does not exists"
+        );
 
+        assert_eq!(TemplateModule::balance_count(1, 1), 0);
+    });
+}
 
-// #[test]
-// fn create_collection_test() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+#[test]
+fn burn_refungible_item() {
+    new_test_ext().execute_with(|| {
+        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        let mode: CollectionMode = CollectionMode::ReFungible(200, 3);
 
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_eq!(TemplateModule::collection(1).owner, 1);
-//     });
-// }
+        let origin1 = Origin::signed(1);
+        let origin2 = Origin::signed(2);
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode
+        ));
+        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));
+        assert_ok!(TemplateModule::create_item(
+            origin2.clone(),
+            1,
+            [1,2,3].to_vec(),
+            1
+        ));
 
-// #[test]
-// fn change_collection_owner() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        assert_eq!(TemplateModule::refungible_item_id(1,1).data, [1,2,3].to_vec());
 
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
+        // check balance (collection with id = 1, user id = 2)
+        assert_eq!(TemplateModule::balance_count(1, 1), 1000);
 
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::change_collection_owner(
-//             origin1.clone(),
-//             1,
-//             2
-//         ));
-//         assert_eq!(TemplateModule::collection(1).owner, 2);
-//     });
-// }
+        // burn item
+        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));
+        assert_noop!(
+            TemplateModule::burn_item(origin1.clone(), 1, 1),
+            "Item does not exists"
+        );
 
-// #[test]
-// fn destroy_collection() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        assert_eq!(TemplateModule::balance_count(1, 1), 0);
+    });
+}
 
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
+#[test]
+fn add_collection_admin() {
+    new_test_ext().execute_with(|| {
+        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        let mode: CollectionMode = CollectionMode::NFT(2000);
 
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::destroy_collection(origin1.clone(), 1));
-//     });
-// }
-
-// #[test]
-// fn create_item() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
-
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         let origin2 = Origin::signed(2);
-
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));
-//         assert_ok!(TemplateModule::create_item(
-//             origin2.clone(),
-//             1,
-//             [1, 1, 1].to_vec()
-//         ));
-
-//         // check balance (collection with id = 1, user id = 2)
-//         assert_eq!(TemplateModule::balance_count((1, 2)), 1);
-//     });
-// }
-
-// #[test]
-// fn burn_item() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
-
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         let origin2 = Origin::signed(2);
-
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));
-//         assert_ok!(TemplateModule::create_item(
-//             origin2.clone(),
-//             1,
-//             [1, 1, 1].to_vec()
-//         ));
-
-//         // check balance (collection with id = 1, user id = 2)
-//         assert_eq!(TemplateModule::balance_count((1, 2)), 1);
-
-//         // burn item
-//         assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));
-//         assert_noop!(
-//             TemplateModule::burn_item(origin1.clone(), 1, 1),
-//             "Item does not exists"
-//         );
-
-//         assert_eq!(TemplateModule::balance_count((1, 1)), 0);
-//     });
-// }
-
-// #[test]
-// fn add_collection_admin() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
-
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         let origin2 = Origin::signed(2);
-//         let origin3 = Origin::signed(3);
-
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin2.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin3.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-
-//         assert_eq!(TemplateModule::collection(1).owner, 1);
-//         assert_eq!(TemplateModule::collection(2).owner, 2);
-//         assert_eq!(TemplateModule::collection(3).owner, 3);
-
-//         // collection admin
-//         assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));
-//         assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 3));
-
-//         assert_eq!(TemplateModule::admin_list_collection(1).contains(&2), true);
-//         assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), true);
-//     });
-// }
-
-// #[test]
-// fn remove_collection_admin() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
-
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         let origin2 = Origin::signed(2);
-//         let origin3 = Origin::signed(3);
-
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin2.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin3.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-
-//         assert_eq!(TemplateModule::collection(1).owner, 1);
-//         assert_eq!(TemplateModule::collection(2).owner, 2);
-//         assert_eq!(TemplateModule::collection(3).owner, 3);
-
-//         // collection admin
-//         assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));
-//         assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 3));
-
-//         assert_eq!(TemplateModule::admin_list_collection(1).contains(&2), true);
-//         assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), true);
-
-//         // remove admin
-//         assert_ok!(TemplateModule::remove_collection_admin(
-//             origin2.clone(),
-//             1,
-//             3
-//         ));
-//         assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), false);
-//     });
-// }
-
-// #[test]
-// fn balance_of() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
-
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         let origin2 = Origin::signed(2);
-//         let origin3 = Origin::signed(3);
-
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin2.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin3.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-
-//         assert_eq!(TemplateModule::collection(1).owner, 1);
-//         assert_eq!(TemplateModule::collection(2).owner, 2);
-//         assert_eq!(TemplateModule::collection(3).owner, 3);
-
-//         // check balance before
-//         assert_eq!(TemplateModule::balance_count((1, 1)), 0);
-
-//         // create item
-//         assert_ok!(TemplateModule::create_item(
-//             origin1.clone(),
-//             1,
-//             [1, 1, 1].to_vec()
-//         ));
+        let origin1 = Origin::signed(1);
+        let origin2 = Origin::signed(2);
+        let origin3 = Origin::signed(3);
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode.clone()
+        ));
+        assert_ok!(TemplateModule::create_collection(
+            origin2.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode.clone()
+        ));
+        assert_ok!(TemplateModule::create_collection(
+            origin3.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode.clone()
+        ));
 
-//         // check balance (collection with id = 1, user id = 2)
-//         assert_eq!(TemplateModule::balance_count((1, 1)), 1);
-//         assert_eq!(TemplateModule::item_id((1, 1)).owner, 1);
-//     });
-// }
+        assert_eq!(TemplateModule::collection(1).owner, 1);
+        assert_eq!(TemplateModule::collection(2).owner, 2);
+        assert_eq!(TemplateModule::collection(3).owner, 3);
 
-// #[test]
-// fn transfer() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        // collection admin
+        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));
+        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 3));
 
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         let origin2 = Origin::signed(2);
-//         let origin3 = Origin::signed(3);
+        assert_eq!(TemplateModule::admin_list_collection(1).contains(&2), true);
+        assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), true);
+    });
+}
 
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin2.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin3.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
+#[test]
+fn remove_collection_admin() {
+    new_test_ext().execute_with(|| {
+        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        let mode: CollectionMode = CollectionMode::NFT(2000);
 
-//         assert_eq!(TemplateModule::collection(1).owner, 1);
-//         assert_eq!(TemplateModule::collection(2).owner, 2);
-//         assert_eq!(TemplateModule::collection(3).owner, 3);
+        let origin1 = Origin::signed(1);
+        let origin2 = Origin::signed(2);
+        let origin3 = Origin::signed(3);
 
-//         // create item
-//         assert_ok!(TemplateModule::create_item(
-//             origin1.clone(),
-//             1,
-//             [1, 1, 1].to_vec()
-//         ));
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode.clone()
+        ));
+        assert_ok!(TemplateModule::create_collection(
+            origin2.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode.clone()
+        ));
+        assert_ok!(TemplateModule::create_collection(
+            origin3.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode.clone()
+        ));
 
-//         // transfer
-//         assert_ok!(TemplateModule::transfer(origin1.clone(), 1, 1, 2));
-//         assert_eq!(TemplateModule::item_id((1, 1)).owner, 2);
+        assert_eq!(TemplateModule::collection(1).owner, 1);
+        assert_eq!(TemplateModule::collection(2).owner, 2);
+        assert_eq!(TemplateModule::collection(3).owner, 3);
 
-//         // balance_of check
-//         assert_eq!(TemplateModule::balance_count((1, 1)), 0);
-//         assert_eq!(TemplateModule::balance_count((1, 2)), 1);
-//     });
-// }
+        // collection admin
+        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));
+        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 3));
 
-// #[test]
-// fn approve() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        assert_eq!(TemplateModule::admin_list_collection(1).contains(&2), true);
+        assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), true);
 
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         let origin2 = Origin::signed(2);
-//         let origin3 = Origin::signed(3);
+        // remove admin
+        assert_ok!(TemplateModule::remove_collection_admin(
+            origin2.clone(),
+            1,
+            3
+        ));
+        assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), false);
+    });
+}
 
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin2.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin3.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
+#[test]
+fn balance_of() {
+    new_test_ext().execute_with(|| {
+        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        let nft_mode: CollectionMode = CollectionMode::NFT(2000);
+        let furg_mode: CollectionMode = CollectionMode::Fungible(3);
+        let refung_mode: CollectionMode = CollectionMode::ReFungible(2000, 3);
 
-//         assert_eq!(TemplateModule::collection(1).owner, 1);
-//         assert_eq!(TemplateModule::collection(2).owner, 2);
-//         assert_eq!(TemplateModule::collection(3).owner, 3);
+        let origin1 = Origin::signed(1);
 
-//         // create item
-//         assert_ok!(TemplateModule::create_item(
-//             origin1.clone(),
-//             1,
-//             [1, 1, 1].to_vec()
-//         ));
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            nft_mode.clone()
+        ));
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            furg_mode.clone()
+        ));
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            refung_mode.clone()
+        ));
 
-//         // approve
-//         assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
-//         assert_eq!(TemplateModule::approved((1, 1)).contains(&2), true);
-//     });
-// }
+        assert_eq!(TemplateModule::collection(1).owner, 1);
+        assert_eq!(TemplateModule::collection(2).owner, 1);
+        assert_eq!(TemplateModule::collection(3).owner, 1);
 
-// #[test]
-// fn get_approved() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        // check balance before
+        assert_eq!(TemplateModule::balance_count(1, 1), 0);
+        assert_eq!(TemplateModule::balance_count(2, 1), 0);
+        assert_eq!(TemplateModule::balance_count(3, 1), 0);
 
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         let origin2 = Origin::signed(2);
-//         let origin3 = Origin::signed(3);
+        // create item
+        assert_ok!(TemplateModule::create_item(
+            origin1.clone(),
+            1,
+            [1, 1, 1].to_vec(),
+            1
+        ));
 
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin2.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin3.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
+        assert_ok!(TemplateModule::create_item(
+            origin1.clone(),
+            2,
+            [].to_vec(),
+            1
+        ));
 
-//         assert_eq!(TemplateModule::collection(1).owner, 1);
-//         assert_eq!(TemplateModule::collection(2).owner, 2);
-//         assert_eq!(TemplateModule::collection(3).owner, 3);
+        assert_ok!(TemplateModule::create_item(
+            origin1.clone(),
+            3,
+            [1, 1, 1].to_vec(),
+            1
+        ));
 
-//         // create item
-//         assert_ok!(TemplateModule::create_item(
-//             origin1.clone(),
-//             1,
-//             [1, 1, 1].to_vec()
-//         ));
+        // check balance (collection with id = 1, user id = 1)
+        assert_eq!(TemplateModule::balance_count(1, 1), 1);
+        assert_eq!(TemplateModule::balance_count(2, 1), 1000);
+        assert_eq!(TemplateModule::balance_count(3, 1), 1000);
+        assert_eq!(TemplateModule::nft_item_id(1, 1).owner, 1);
+        assert_eq!(TemplateModule::fungible_item_id(2, 1).owner, 1);
+        assert_eq!(TemplateModule::refungible_item_id(3, 1).owner[0].owner, 1);
+    });
+}
 
-//         // approve
-//         assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
-//         assert_eq!(TemplateModule::approved((1, 1)).contains(&2), true);
-//     });
-// }
+#[test]
+fn approve() {
+    new_test_ext().execute_with(|| {
+        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        let nft_mode: CollectionMode = CollectionMode::NFT(2000);
+        let origin1 = Origin::signed(1);
 
-// #[test]
-// fn transfer_from() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            nft_mode.clone()
+        ));
 
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         let origin2 = Origin::signed(2);
-//         let origin3 = Origin::signed(3);
+        assert_eq!(TemplateModule::collection(1).owner, 1);
 
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin2.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin3.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
+        // create item
+        assert_ok!(TemplateModule::create_item(
+            origin1.clone(),
+            1,
+            [1, 1, 1].to_vec(),
+            1
+        ));
 
-//         assert_eq!(TemplateModule::collection(1).owner, 1);
-//         assert_eq!(TemplateModule::collection(2).owner, 2);
-//         assert_eq!(TemplateModule::collection(3).owner, 3);
+        // approve
+        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
+        assert_eq!(TemplateModule::approved(1, (1, 1))[0].approved, 2);
+    });
+}
 
-//         // create item
-//         assert_ok!(TemplateModule::create_item(
-//             origin1.clone(),
-//             1,
-//             [1, 1, 1].to_vec()
-//         ));
+#[test]
+fn transfer_from() {
+    new_test_ext().execute_with(|| {
+        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        let mode: CollectionMode = CollectionMode::NFT(2000);
+        let origin1 = Origin::signed(1);
+        let origin2 = Origin::signed(2);
 
-//         // approve
-//         assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
-//         assert_ok!(TemplateModule::transfer_from(origin1.clone(), 1, 1, 2));
-//     });
-// }
+        assert_ok!(TemplateModule::create_collection(
+            origin1.clone(),
+            col_name1.clone(),
+            col_desc1.clone(),
+            token_prefix1.clone(),
+            mode
+        ));
 
-// #[test]
-// fn index_list() {
-//     new_test_ext().execute_with(|| {
-//         let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
-//         let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
-//         let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+        assert_eq!(TemplateModule::collection(1).owner, 1);
 
-//         let size = 1024;
-//         let origin1 = Origin::signed(1);
-//         let origin2 = Origin::signed(2);
-//         let origin3 = Origin::signed(3);
+        // create item
+        assert_ok!(TemplateModule::create_item(
+            origin1.clone(),
+            1,
+            [1, 1, 1].to_vec(),
+            1
+        ));
 
-//         assert_ok!(TemplateModule::create_collection(
-//             origin1.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin2.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
-//         assert_ok!(TemplateModule::create_collection(
-//             origin3.clone(),
-//             col_name1.clone(),
-//             col_desc1.clone(),
-//             token_prefix1.clone(),
-//             size
-//         ));
+        // approve
+        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
+        assert_eq!(TemplateModule::approved(1, (1, 1))[0].approved, 2);
+        assert_ok!(TemplateModule::transfer_from(origin2.clone(), 1, 2, 1, 1, 1));
 
-//         assert_eq!(TemplateModule::collection(1).owner, 1);
-//         assert_eq!(TemplateModule::collection(2).owner, 2);
-//         assert_eq!(TemplateModule::collection(3).owner, 3);
-//         // create items
-//         assert_ok!(TemplateModule::create_item(
-//             origin1.clone(),
-//             1,
-//             [1, 1, 1].to_vec()
-//         ));
-//         assert_ok!(TemplateModule::create_item(
-//             origin1.clone(),
-//             1,
-//             [1, 1, 2].to_vec()
-//         ));
-//         assert_ok!(TemplateModule::create_item(
-//             origin1.clone(),
-//             1,
-//             [1, 2, 3].to_vec()
-//         ));
-//         assert_eq!(TemplateModule::address_tokens((1, 1)).len(), 3);
-//         // burn one
-//         assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 2));
-//         assert_eq!(TemplateModule::address_tokens((1, 1)).len(), 2);
-//         // burn another one
-//         assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 3));
-//         assert_eq!(TemplateModule::address_tokens((1, 1))[0], 1);
-//     });
-// }
+        // after transfer
+        assert_eq!(TemplateModule::balance_count(1, 1), 0);
+        assert_eq!(TemplateModule::balance_count(1, 2), 1);
+    });
+}
modifiedruntime/src/lib.rsdiffbeforeafterboth
before · runtime/src/lib.rs
1//! The Substrate Node Template runtime. This can be compiled with `#[no_std]`, ready for Wasm.23#![cfg_attr(not(feature = "std"), no_std)]4// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.5#![recursion_limit = "256"]67// Make the WASM binary available.8#[cfg(feature = "std")]9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));1011use contracts_rpc_runtime_api::ContractExecResult;12use grandpa::fg_primitives;13use grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};14use sp_api::impl_runtime_apis;15use sp_consensus_aura::sr25519::AuthorityId as AuraId;16use sp_core::{crypto::KeyTypeId, OpaqueMetadata};17use sp_runtime::{18    create_runtime_str, generic, impl_opaque_keys,19    transaction_validity::{TransactionSource, TransactionValidity},20    ApplyExtrinsicResult, MultiSignature,21	traits::{22        BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, Saturating, Verify,23	},24};25use sp_std::prelude::*;26#[cfg(feature = "std")]27use sp_version::NativeVersion;28use sp_version::RuntimeVersion;2930// A few exports that help ease life for downstream crates.31pub use balances::Call as BalancesCall;32pub use contracts::Schedule as ContractsSchedule;33pub use frame_support::{34    construct_runtime, parameter_types,35    traits::{Currency, Get, ExistenceRequirement, KeyOwnerProofSystem, OnUnbalanced, Randomness, WithdrawReason},36    weights::{37        DispatchInfo, PostDispatchInfo, constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},38        IdentityFee, Weight, WeightToFeePolynomial, GetDispatchInfo, Pays,39    },40    StorageValue,41	dispatch::DispatchResult,42};43use system::{self as system};44#[cfg(any(feature = "std", test))]45pub use sp_runtime::BuildStorage;46use sp_runtime::{47	Perbill,48};495051pub use timestamp::Call as TimestampCall;5253/// Importing a nft pallet54pub use nft;5556/// An index to a block.57pub type BlockNumber = u32;5859/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.60pub type Signature = MultiSignature;6162/// Some way of identifying an account on the chain. We intentionally make it equivalent63/// to the public key of our transaction signing scheme.64pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;6566/// The type for looking up accounts. We don't expect more than 4 billion of them, but you67/// never know...68pub type AccountIndex = u32;6970/// Balance of an account.71pub type Balance = u128;7273/// Index of a transaction in the chain.74pub type Index = u32;7576/// A hash of some data used by the chain.77pub type Hash = sp_core::H256;7879/// Digest item type.80pub type DigestItem = generic::DigestItem<Hash>;8182/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know83/// the specifics of the runtime. They can then be made to be agnostic over specific formats84/// of data like extrinsics, allowing for them to continue syncing the network through upgrades85/// to even the core data structures.86pub mod opaque {87    use super::*;8889    pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;9091    /// Opaque block header type.92    pub type Header = generic::Header<BlockNumber, BlakeTwo256>;93    /// Opaque block type.94    pub type Block = generic::Block<Header, UncheckedExtrinsic>;95    /// Opaque block identifier type.96    pub type BlockId = generic::BlockId<Block>;9798    impl_opaque_keys! {99        pub struct SessionKeys {100            pub aura: Aura,101            pub grandpa: Grandpa,102        }103    }104}105106/// This runtime version.107pub const VERSION: RuntimeVersion = RuntimeVersion {108    spec_name: create_runtime_str!("nft"),109    impl_name: create_runtime_str!("nft"),110    authoring_version: 1,111    spec_version: 1,112    impl_version: 1,113    apis: RUNTIME_API_VERSIONS,114    transaction_version: 1,115};116117pub const MILLISECS_PER_BLOCK: u64 = 6000;118119pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;120121// These time units are defined in number of blocks.122pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);123pub const HOURS: BlockNumber = MINUTES * 60;124pub const DAYS: BlockNumber = HOURS * 24;125126/// The version information used to identify this runtime when compiled natively.127#[cfg(feature = "std")]128pub fn native_version() -> NativeVersion {129    NativeVersion {130        runtime_version: VERSION,131        can_author_with: Default::default(),132    }133}134135parameter_types! {136    pub const BlockHashCount: BlockNumber = 2400;137    /// We allow for 2 seconds of compute with a 6 second average block time.138    pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;139    pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);140    /// Assume 10% of weight for average on_initialize calls.141    pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()142        .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();143    pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;144    pub const Version: RuntimeVersion = VERSION;145}146147impl system::Trait for Runtime {148    /// The basic call filter to use in dispatchable.149    type BaseCallFilter = ();150    /// The identifier used to distinguish between accounts.151    type AccountId = AccountId;152    /// The aggregated dispatch type that is available for extrinsics.153    type Call = Call;154    /// The lookup mechanism to get account ID from whatever is passed in dispatchers.155    type Lookup = IdentityLookup<AccountId>;156    /// The index type for storing how many extrinsics an account has signed.157    type Index = Index;158    /// The index type for blocks.159    type BlockNumber = BlockNumber;160    /// The type for hashing blocks and tries.161    type Hash = Hash;162    /// The hashing algorithm used.163    type Hashing = BlakeTwo256;164    /// The header type.165    type Header = generic::Header<BlockNumber, BlakeTwo256>;166    /// The ubiquitous event type.167    type Event = Event;168    /// The ubiquitous origin type.169    type Origin = Origin;170    /// Maximum number of block number to block hash mappings to keep (oldest pruned first).171    type BlockHashCount = BlockHashCount;172    /// Maximum weight of each block.173    type MaximumBlockWeight = MaximumBlockWeight;174    /// The weight of database operations that the runtime can invoke.175    type DbWeight = RocksDbWeight;176    /// The weight of the overhead invoked on the block import process, independent of the177    /// extrinsics included in that block.178    type BlockExecutionWeight = BlockExecutionWeight;179    /// The base weight of any extrinsic processed by the runtime, independent of the180    /// logic of that extrinsic. (Signature verification, nonce increment, fee, etc...)181    type ExtrinsicBaseWeight = ExtrinsicBaseWeight;182    /// The maximum weight that a single extrinsic of `Normal` dispatch class can have,183    /// idependent of the logic of that extrinsics. (Roughly max block weight - average on184    /// initialize cost).185    type MaximumExtrinsicWeight = MaximumExtrinsicWeight;186    /// Maximum size of all encoded transactions (in bytes) that are allowed in one block.187    type MaximumBlockLength = MaximumBlockLength;188    /// Portion of the block weight that is available to all normal transactions.189    type AvailableBlockRatio = AvailableBlockRatio;190    /// Version of the runtime.191    type Version = Version;192    /// Converts a module to the index of the module in `construct_runtime!`.193    ///194    /// This type is being generated by `construct_runtime!`.195    type ModuleToIndex = ModuleToIndex;196    /// What to do if a new account is created.197    type OnNewAccount = ();198    /// What to do if an account is fully reaped from the system.199    type OnKilledAccount = ();200    /// The data to be stored in an account.201    type AccountData = balances::AccountData<Balance>;202}203204impl aura::Trait for Runtime {205    type AuthorityId = AuraId;206}207208impl grandpa::Trait for Runtime {209    type Event = Event;210    type Call = Call;211212    type KeyOwnerProofSystem = ();213214    type KeyOwnerProof =215        <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;216217    type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(218        KeyTypeId,219        GrandpaId,220    )>>::IdentificationTuple;221222    type HandleEquivocation = ();223}224225parameter_types! {226    pub const MinimumPeriod: u64 = SLOT_DURATION / 2;227}228229impl timestamp::Trait for Runtime {230    /// A timestamp: milliseconds since the unix epoch.231    type Moment = u64;232    type OnTimestampSet = Aura;233    type MinimumPeriod = MinimumPeriod;234}235236parameter_types! {237    // pub const ExistentialDeposit: u128 = 500;238    pub const ExistentialDeposit: u128 = 0;239}240241impl balances::Trait for Runtime {242    /// The type for recording an account's balance.243    type Balance = Balance;244    /// The ubiquitous event type.245    type Event = Event;246    type DustRemoval = ();247    type ExistentialDeposit = ExistentialDeposit;248    type AccountStore = System;249}250251pub const MILLICENTS: Balance = 1_000_000_000;252pub const CENTS: Balance = 1_000 * MILLICENTS;253pub const DOLLARS: Balance = 100 * CENTS;254255parameter_types! {256    pub const TombstoneDeposit: Balance = 16 * MILLICENTS;257    pub const RentByteFee: Balance = 4 * MILLICENTS;258    pub const RentDepositOffset: Balance = 1000 * MILLICENTS;259    pub const SurchargeReward: Balance = 150 * MILLICENTS;260}261262impl contracts::Trait for Runtime {263    type Call = Call;264    type Time = Timestamp;265    type Randomness = RandomnessCollectiveFlip;266    type Currency = Balances;267    type Event = Event;268    type DetermineContractAddress = contracts::SimpleAddressDeterminer<Runtime>;269    type TrieIdGenerator = contracts::TrieIdFromParentCounter<Runtime>;270    type RentPayment = ();271    type SignedClaimHandicap = contracts::DefaultSignedClaimHandicap;272    type TombstoneDeposit = TombstoneDeposit;273    type StorageSizeOffset = contracts::DefaultStorageSizeOffset;274    type RentByteFee = RentByteFee;275    type RentDepositOffset = RentDepositOffset;276    type SurchargeReward = SurchargeReward;277    type MaxDepth = contracts::DefaultMaxDepth;278    type MaxValueSize = contracts::DefaultMaxValueSize;279    type WeightPrice = transaction_payment::Module<Self>;280}281282parameter_types! {283    pub const TransactionByteFee: Balance = 1;284}285286impl transaction_payment::Trait for Runtime {287    type Currency = balances::Module<Runtime>;288    type OnTransactionPayment = ();289    type TransactionByteFee = TransactionByteFee;290    type WeightToFee = IdentityFee<Balance>;291    type FeeMultiplierUpdate = ();292}293294impl sudo::Trait for Runtime {295    type Event = Event;296    type Call = Call;297}298299/// Used for the module nft in `./nft.rs`300impl nft::Trait for Runtime {301    type Event = Event;302}303304construct_runtime!(305    pub enum Runtime where306        Block = Block,307        NodeBlock = opaque::Block,308        UncheckedExtrinsic = UncheckedExtrinsic309    {310        System: system::{Module, Call, Config, Storage, Event<T>},311        RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},312        Contracts: contracts::{Module, Call, Config, Storage, Event<T>},313        Timestamp: timestamp::{Module, Call, Storage, Inherent},314        Aura: aura::{Module, Config<T>, Inherent(Timestamp)},315        Grandpa: grandpa::{Module, Call, Storage, Config, Event},316        Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},317        TransactionPayment: transaction_payment::{Module, Storage},318        Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>},319        Nft: nft::{Module, Call, Storage, Event<T>},320    }321);322323/// The address format for describing accounts.324pub type Address = AccountId;325/// Block header type as expected by this runtime.326pub type Header = generic::Header<BlockNumber, BlakeTwo256>;327/// Block type as expected by this runtime.328pub type Block = generic::Block<Header, UncheckedExtrinsic>;329/// A Block signed with a Justification330pub type SignedBlock = generic::SignedBlock<Block>;331/// BlockId type as expected by this runtime.332pub type BlockId = generic::BlockId<Block>;333/// The SignedExtension to the basic transaction logic.334pub type SignedExtra = (335    system::CheckSpecVersion<Runtime>,336    system::CheckTxVersion<Runtime>,337    system::CheckGenesis<Runtime>,338    system::CheckEra<Runtime>,339    system::CheckNonce<Runtime>,340    system::CheckWeight<Runtime>,341    nft::ChargeTransactionPayment<Runtime>,342);343/// Unchecked extrinsic type as expected by this runtime.344pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;345/// Extrinsic type that has already been checked.346pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;347/// Executive: handles dispatch to the various modules.348pub type Executive =349    frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;350351impl_runtime_apis! {352353    impl contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>354    for Runtime355    {356        fn call(357            origin: AccountId,358            dest: AccountId,359            value: Balance,360            gas_limit: u64,361            input_data: Vec<u8>,362        ) -> ContractExecResult {363            let exec_result =364                Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);365            match exec_result {366                Ok(v) => ContractExecResult::Success {367                    status: v.status,368                    data: v.data,369                },370                Err(_) => ContractExecResult::Error,371            }372        }373374        fn get_storage(375            address: AccountId,376            key: [u8; 32],377        ) -> contracts_primitives::GetStorageResult {378            Contracts::get_storage(address, key)379        }380381        fn rent_projection(382            address: AccountId,383        ) -> contracts_primitives::RentProjectionResult<BlockNumber> {384            Contracts::rent_projection(address)385        }386    }387388    impl sp_api::Core<Block> for Runtime {389        fn version() -> RuntimeVersion {390            VERSION391        }392393        fn execute_block(block: Block) {394            Executive::execute_block(block)395        }396397        fn initialize_block(header: &<Block as BlockT>::Header) {398            Executive::initialize_block(header)399        }400    }401402    impl sp_api::Metadata<Block> for Runtime {403        fn metadata() -> OpaqueMetadata {404            Runtime::metadata().into()405        }406    }407408    impl sp_block_builder::BlockBuilder<Block> for Runtime {409        fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {410            Executive::apply_extrinsic(extrinsic)411        }412413        fn finalize_block() -> <Block as BlockT>::Header {414            Executive::finalize_block()415        }416417        fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {418            data.create_extrinsics()419        }420421        fn check_inherents(422            block: Block,423            data: sp_inherents::InherentData,424        ) -> sp_inherents::CheckInherentsResult {425            data.check_extrinsics(&block)426        }427428        fn random_seed() -> <Block as BlockT>::Hash {429            RandomnessCollectiveFlip::random_seed()430        }431    }432433    impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {434        fn validate_transaction(435            source: TransactionSource,436            tx: <Block as BlockT>::Extrinsic,437        ) -> TransactionValidity {438            Executive::validate_transaction(source, tx)439        }440    }441442    impl sp_offchain::OffchainWorkerApi<Block> for Runtime {443        fn offchain_worker(header: &<Block as BlockT>::Header) {444            Executive::offchain_worker(header)445        }446    }447448    impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {449        fn slot_duration() -> u64 {450            Aura::slot_duration()451        }452453        fn authorities() -> Vec<AuraId> {454            Aura::authorities()455        }456    }457458    impl sp_session::SessionKeys<Block> for Runtime {459        fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {460            opaque::SessionKeys::generate(seed)461        }462463        fn decode_session_keys(464            encoded: Vec<u8>,465        ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {466            opaque::SessionKeys::decode_into_raw_public_keys(&encoded)467        }468    }469470    impl fg_primitives::GrandpaApi<Block> for Runtime {471        fn grandpa_authorities() -> GrandpaAuthorityList {472            Grandpa::grandpa_authorities()473        }474475        fn submit_report_equivocation_extrinsic(476            _equivocation_proof: fg_primitives::EquivocationProof<477                <Block as BlockT>::Hash,478                NumberFor<Block>,479            >,480            _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,481        ) -> Option<()> {482            None483        }484485        fn generate_key_ownership_proof(486            _set_id: fg_primitives::SetId,487            _authority_id: GrandpaId,488        ) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {489            // NOTE: this is the only implementation possible since we've490            // defined our key owner proof type as a bottom type (i.e. a type491            // with no values).492            None493        }494    }495}496
after · runtime/src/lib.rs
1//! The Substrate Node Template runtime. This can be compiled with `#[no_std]`, ready for Wasm.23#![cfg_attr(not(feature = "std"), no_std)]4// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.5#![recursion_limit = "256"]67// Make the WASM binary available.8#[cfg(feature = "std")]9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));1011use contracts_rpc_runtime_api::ContractExecResult;12use grandpa::fg_primitives;13use grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};14use sp_api::impl_runtime_apis;15use sp_consensus_aura::sr25519::AuthorityId as AuraId;16use sp_core::{crypto::KeyTypeId, OpaqueMetadata};17use sp_runtime::{18    create_runtime_str, generic, impl_opaque_keys,19    transaction_validity::{TransactionSource, TransactionValidity},20    ApplyExtrinsicResult, MultiSignature,21	traits::{22        BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, Saturating, Verify,23	},24};25use sp_std::prelude::*;26#[cfg(feature = "std")]27use sp_version::NativeVersion;28use sp_version::RuntimeVersion;2930// A few exports that help ease life for downstream crates.31pub use balances::Call as BalancesCall;32pub use contracts::Schedule as ContractsSchedule;33pub use frame_support::{34    construct_runtime, parameter_types,35    traits::{Currency, Get, ExistenceRequirement, KeyOwnerProofSystem, OnUnbalanced, Randomness, WithdrawReason},36    weights::{37        DispatchInfo, PostDispatchInfo, constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},38        IdentityFee, Weight, WeightToFeePolynomial, GetDispatchInfo, Pays,39    },40    StorageValue,41	dispatch::DispatchResult,42};43use system::{self as system};44#[cfg(any(feature = "std", test))]45pub use sp_runtime::BuildStorage;46use sp_runtime::{47	Perbill,48};495051pub use timestamp::Call as TimestampCall;5253/// Importing a nft pallet54pub use nft;5556/// An index to a block.57pub type BlockNumber = u32;5859/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.60pub type Signature = MultiSignature;6162/// Some way of identifying an account on the chain. We intentionally make it equivalent63/// to the public key of our transaction signing scheme.64pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;6566/// The type for looking up accounts. We don't expect more than 4 billion of them, but you67/// never know...68pub type AccountIndex = u32;6970/// Balance of an account.71pub type Balance = u128;7273/// Index of a transaction in the chain.74pub type Index = u32;7576/// A hash of some data used by the chain.77pub type Hash = sp_core::H256;7879/// Digest item type.80pub type DigestItem = generic::DigestItem<Hash>;8182/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know83/// the specifics of the runtime. They can then be made to be agnostic over specific formats84/// of data like extrinsics, allowing for them to continue syncing the network through upgrades85/// to even the core data structures.86pub mod opaque {87    use super::*;8889    pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;9091    /// Opaque block header type.92    pub type Header = generic::Header<BlockNumber, BlakeTwo256>;93    /// Opaque block type.94    pub type Block = generic::Block<Header, UncheckedExtrinsic>;95    /// Opaque block identifier type.96    pub type BlockId = generic::BlockId<Block>;9798    impl_opaque_keys! {99        pub struct SessionKeys {100            pub aura: Aura,101            pub grandpa: Grandpa,102        }103    }104}105106/// This runtime version.107pub const VERSION: RuntimeVersion = RuntimeVersion {108    spec_name: create_runtime_str!("nft"),109    impl_name: create_runtime_str!("nft"),110    authoring_version: 1,111    spec_version: 1,112    impl_version: 1,113    apis: RUNTIME_API_VERSIONS,114    transaction_version: 1,115};116117pub const MILLISECS_PER_BLOCK: u64 = 6000;118119pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;120121// These time units are defined in number of blocks.122pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);123pub const HOURS: BlockNumber = MINUTES * 60;124pub const DAYS: BlockNumber = HOURS * 24;125126/// The version information used to identify this runtime when compiled natively.127#[cfg(feature = "std")]128pub fn native_version() -> NativeVersion {129    NativeVersion {130        runtime_version: VERSION,131        can_author_with: Default::default(),132    }133}134135parameter_types! {136    pub const BlockHashCount: BlockNumber = 2400;137    /// We allow for 2 seconds of compute with a 6 second average block time.138    pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;139    pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);140    /// Assume 10% of weight for average on_initialize calls.141    pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()142        .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();143    pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;144    pub const Version: RuntimeVersion = VERSION;145}146147impl system::Trait for Runtime {148    /// The basic call filter to use in dispatchable.149    type BaseCallFilter = ();150    /// The identifier used to distinguish between accounts.151    type AccountId = AccountId;152    /// The aggregated dispatch type that is available for extrinsics.153    type Call = Call;154    /// The lookup mechanism to get account ID from whatever is passed in dispatchers.155    type Lookup = IdentityLookup<AccountId>;156    /// The index type for storing how many extrinsics an account has signed.157    type Index = Index;158    /// The index type for blocks.159    type BlockNumber = BlockNumber;160    /// The type for hashing blocks and tries.161    type Hash = Hash;162    /// The hashing algorithm used.163    type Hashing = BlakeTwo256;164    /// The header type.165    type Header = generic::Header<BlockNumber, BlakeTwo256>;166    /// The ubiquitous event type.167    type Event = Event;168    /// The ubiquitous origin type.169    type Origin = Origin;170    /// Maximum number of block number to block hash mappings to keep (oldest pruned first).171    type BlockHashCount = BlockHashCount;172    /// Maximum weight of each block.173    type MaximumBlockWeight = MaximumBlockWeight;174    /// The weight of database operations that the runtime can invoke.175    type DbWeight = RocksDbWeight;176    /// The weight of the overhead invoked on the block import process, independent of the177    /// extrinsics included in that block.178    type BlockExecutionWeight = BlockExecutionWeight;179    /// The base weight of any extrinsic processed by the runtime, independent of the180    /// logic of that extrinsic. (Signature verification, nonce increment, fee, etc...)181    type ExtrinsicBaseWeight = ExtrinsicBaseWeight;182    /// The maximum weight that a single extrinsic of `Normal` dispatch class can have,183    /// idependent of the logic of that extrinsics. (Roughly max block weight - average on184    /// initialize cost).185    type MaximumExtrinsicWeight = MaximumExtrinsicWeight;186    /// Maximum size of all encoded transactions (in bytes) that are allowed in one block.187    type MaximumBlockLength = MaximumBlockLength;188    /// Portion of the block weight that is available to all normal transactions.189    type AvailableBlockRatio = AvailableBlockRatio;190    /// Version of the runtime.191    type Version = Version;192    /// Converts a module to the index of the module in `construct_runtime!`.193    /// This type is being generated by `construct_runtime!`.194    type ModuleToIndex = ModuleToIndex;195    /// What to do if a new account is created.196    type OnNewAccount = ();197    /// What to do if an account is fully reaped from the system.198    type OnKilledAccount = ();199    /// The data to be stored in an account.200    type AccountData = balances::AccountData<Balance>;201}202203impl aura::Trait for Runtime {204    type AuthorityId = AuraId;205}206207impl grandpa::Trait for Runtime {208    type Event = Event;209    type Call = Call;210211    type KeyOwnerProofSystem = ();212213    type KeyOwnerProof =214        <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;215216    type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(217        KeyTypeId,218        GrandpaId,219    )>>::IdentificationTuple;220221    type HandleEquivocation = ();222}223224parameter_types! {225    pub const MinimumPeriod: u64 = SLOT_DURATION / 2;226}227228impl timestamp::Trait for Runtime {229    /// A timestamp: milliseconds since the unix epoch.230    type Moment = u64;231    type OnTimestampSet = Aura;232    type MinimumPeriod = MinimumPeriod;233}234235parameter_types! {236    // pub const ExistentialDeposit: u128 = 500;237    pub const ExistentialDeposit: u128 = 0;238}239240impl balances::Trait for Runtime {241    /// The type for recording an account's balance.242    type Balance = Balance;243    /// The ubiquitous event type.244    type Event = Event;245    type DustRemoval = ();246    type ExistentialDeposit = ExistentialDeposit;247    type AccountStore = System;248}249250pub const MILLICENTS: Balance = 1_000_000_000;251pub const CENTS: Balance = 1_000 * MILLICENTS;252pub const DOLLARS: Balance = 100 * CENTS;253254parameter_types! {255    pub const TombstoneDeposit: Balance = 16 * MILLICENTS;256    pub const RentByteFee: Balance = 4 * MILLICENTS;257    pub const RentDepositOffset: Balance = 1000 * MILLICENTS;258    pub const SurchargeReward: Balance = 150 * MILLICENTS;259}260261impl contracts::Trait for Runtime {262    type Call = Call;263    type Time = Timestamp;264    type Randomness = RandomnessCollectiveFlip;265    type Currency = Balances;266    type Event = Event;267    type DetermineContractAddress = contracts::SimpleAddressDeterminer<Runtime>;268    type TrieIdGenerator = contracts::TrieIdFromParentCounter<Runtime>;269    type RentPayment = ();270    type SignedClaimHandicap = contracts::DefaultSignedClaimHandicap;271    type TombstoneDeposit = TombstoneDeposit;272    type StorageSizeOffset = contracts::DefaultStorageSizeOffset;273    type RentByteFee = RentByteFee;274    type RentDepositOffset = RentDepositOffset;275    type SurchargeReward = SurchargeReward;276    type MaxDepth = contracts::DefaultMaxDepth;277    type MaxValueSize = contracts::DefaultMaxValueSize;278    type WeightPrice = transaction_payment::Module<Self>;279}280281parameter_types! {282    pub const TransactionByteFee: Balance = 1;283}284285impl transaction_payment::Trait for Runtime {286    type Currency = balances::Module<Runtime>;287    type OnTransactionPayment = ();288    type TransactionByteFee = TransactionByteFee;289    type WeightToFee = IdentityFee<Balance>;290    type FeeMultiplierUpdate = ();291}292293impl sudo::Trait for Runtime {294    type Event = Event;295    type Call = Call;296}297298/// Used for the module nft in `./nft.rs`299impl nft::Trait for Runtime {300    type Event = Event;301}302303construct_runtime!(304    pub enum Runtime where305        Block = Block,306        NodeBlock = opaque::Block,307        UncheckedExtrinsic = UncheckedExtrinsic308    {309        System: system::{Module, Call, Config, Storage, Event<T>},310        RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},311        Contracts: contracts::{Module, Call, Config, Storage, Event<T>},312        Timestamp: timestamp::{Module, Call, Storage, Inherent},313        Aura: aura::{Module, Config<T>, Inherent(Timestamp)},314        Grandpa: grandpa::{Module, Call, Storage, Config, Event},315        Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},316        TransactionPayment: transaction_payment::{Module, Storage},317        Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>},318        Nft: nft::{Module, Call, Storage, Event<T>},319    }320);321322/// The address format for describing accounts.323pub type Address = AccountId;324/// Block header type as expected by this runtime.325pub type Header = generic::Header<BlockNumber, BlakeTwo256>;326/// Block type as expected by this runtime.327pub type Block = generic::Block<Header, UncheckedExtrinsic>;328/// A Block signed with a Justification329pub type SignedBlock = generic::SignedBlock<Block>;330/// BlockId type as expected by this runtime.331pub type BlockId = generic::BlockId<Block>;332/// The SignedExtension to the basic transaction logic.333pub type SignedExtra = (334    system::CheckSpecVersion<Runtime>,335    system::CheckTxVersion<Runtime>,336    system::CheckGenesis<Runtime>,337    system::CheckEra<Runtime>,338    system::CheckNonce<Runtime>,339    system::CheckWeight<Runtime>,340    nft::ChargeTransactionPayment<Runtime>,341);342/// Unchecked extrinsic type as expected by this runtime.343pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;344/// Extrinsic type that has already been checked.345pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;346/// Executive: handles dispatch to the various modules.347pub type Executive =348    frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;349350impl_runtime_apis! {351352    impl contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>353    for Runtime354    {355        fn call(356            origin: AccountId,357            dest: AccountId,358            value: Balance,359            gas_limit: u64,360            input_data: Vec<u8>,361        ) -> ContractExecResult {362            let exec_result =363                Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);364            match exec_result {365                Ok(v) => ContractExecResult::Success {366                    status: v.status,367                    data: v.data,368                },369                Err(_) => ContractExecResult::Error,370            }371        }372373        fn get_storage(374            address: AccountId,375            key: [u8; 32],376        ) -> contracts_primitives::GetStorageResult {377            Contracts::get_storage(address, key)378        }379380        fn rent_projection(381            address: AccountId,382        ) -> contracts_primitives::RentProjectionResult<BlockNumber> {383            Contracts::rent_projection(address)384        }385    }386387    impl sp_api::Core<Block> for Runtime {388        fn version() -> RuntimeVersion {389            VERSION390        }391392        fn execute_block(block: Block) {393            Executive::execute_block(block)394        }395396        fn initialize_block(header: &<Block as BlockT>::Header) {397            Executive::initialize_block(header)398        }399    }400401    impl sp_api::Metadata<Block> for Runtime {402        fn metadata() -> OpaqueMetadata {403            Runtime::metadata().into()404        }405    }406407    impl sp_block_builder::BlockBuilder<Block> for Runtime {408        fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {409            Executive::apply_extrinsic(extrinsic)410        }411412        fn finalize_block() -> <Block as BlockT>::Header {413            Executive::finalize_block()414        }415416        fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {417            data.create_extrinsics()418        }419420        fn check_inherents(421            block: Block,422            data: sp_inherents::InherentData,423        ) -> sp_inherents::CheckInherentsResult {424            data.check_extrinsics(&block)425        }426427        fn random_seed() -> <Block as BlockT>::Hash {428            RandomnessCollectiveFlip::random_seed()429        }430    }431432    impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {433        fn validate_transaction(434            source: TransactionSource,435            tx: <Block as BlockT>::Extrinsic,436        ) -> TransactionValidity {437            Executive::validate_transaction(source, tx)438        }439    }440441    impl sp_offchain::OffchainWorkerApi<Block> for Runtime {442        fn offchain_worker(header: &<Block as BlockT>::Header) {443            Executive::offchain_worker(header)444        }445    }446447    impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {448        fn slot_duration() -> u64 {449            Aura::slot_duration()450        }451452        fn authorities() -> Vec<AuraId> {453            Aura::authorities()454        }455    }456457    impl sp_session::SessionKeys<Block> for Runtime {458        fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {459            opaque::SessionKeys::generate(seed)460        }461462        fn decode_session_keys(463            encoded: Vec<u8>,464        ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {465            opaque::SessionKeys::decode_into_raw_public_keys(&encoded)466        }467    }468469    impl fg_primitives::GrandpaApi<Block> for Runtime {470        fn grandpa_authorities() -> GrandpaAuthorityList {471            Grandpa::grandpa_authorities()472        }473474        fn submit_report_equivocation_extrinsic(475            _equivocation_proof: fg_primitives::EquivocationProof<476                <Block as BlockT>::Hash,477                NumberFor<Block>,478            >,479            _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,480        ) -> Option<()> {481            None482        }483484        fn generate_key_ownership_proof(485            _set_id: fg_primitives::SetId,486            _authority_id: GrandpaId,487        ) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {488            // NOTE: this is the only implementation possible since we've489            // defined our key owner proof type as a bottom type (i.e. a type490            // with no values).491            None492        }493    }494}495