git.delta.rocks / unique-network / refs/commits / 0a7b60da8a0b

difftreelog

feat implement all CE calls in test contract

Yaroslav Bolyukin2021-06-04parent: #0b72135.patch.diff
in: master

4 files changed

modifiedsmart_contracs/transfer/Cargo.tomldiffbeforeafterboth
--- a/smart_contracs/transfer/Cargo.toml
+++ b/smart_contracs/transfer/Cargo.toml
@@ -4,15 +4,17 @@
 authors = ["[Greg Zaitsev] <[your_email]>"]
 edition = "2018"
 
+[workspace]
+
 [dependencies]
-ink_primitives = { git = "https://github.com/usetech-llc/ink", branch = "unique", default-features = false }
-ink_metadata = { git = "https://github.com/usetech-llc/ink", branch = "unique", default-features = false, features = ["derive"], optional = true }
-ink_env = { git = "https://github.com/usetech-llc/ink", branch = "unique", default-features = false }
-ink_storage = { git = "https://github.com/usetech-llc/ink", branch = "unique", default-features = false }
-ink_lang = { git = "https://github.com/usetech-llc/ink", branch = "unique", default-features = false }
+ink_primitives = { default-features = false }
+ink_metadata = { default-features = false, features = ["derive"], optional = true }
+ink_env = { default-features = false }
+ink_storage = { default-features = false }
+ink_lang = { default-features = false }
 
-scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] }
-scale-info = { version = "0.4.1", default-features = false, features = ["derive"], optional = true }
+scale = { package = "parity-scale-codec", version = "2.1.1", default-features = false, features = ["derive"] }
+scale-info = { version = "0.6.0", default-features = false, features = ["derive"] }
 
 [lib]
 name = "nft_transfer"
@@ -28,6 +30,7 @@
     "ink_metadata/std",
     "ink_env/std",
     "ink_storage/std",
+    "ink_lang/std",
     "ink_primitives/std",
     "scale/std",
     "scale-info/std",
modifiedsmart_contracs/transfer/lib.rsdiffbeforeafterboth
--- a/smart_contracs/transfer/lib.rs
+++ b/smart_contracs/transfer/lib.rs
@@ -1,4 +1,6 @@
 #![cfg_attr(not(feature = "std"), no_std)]
+extern crate alloc;
+use alloc::vec::Vec;
 
 use ink_lang as ink;
 use ink_env::{Environment, DefaultEnvironment};
@@ -36,6 +38,24 @@
     }
 }
 
+#[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
+pub enum CreateItemData {
+    Nft {
+        const_data: Vec<u8>,
+        variable_data: Vec<u8>,
+    },
+    Fungible {
+        value: u128,
+    },
+    ReFungible {
+        const_data: Vec<u8>,
+        variable_data: Vec<u8>,
+        pieces: u128,
+    },
+}
+
+type DefaultAccountId = <DefaultEnvironment as Environment>::AccountId;
+
 #[ink::chain_extension]
 pub trait NftChainExtension {
     type ErrorCode = NftErrorCode;
@@ -43,11 +63,26 @@
     /// Transfer one NFT token from sender
     ///
     #[ink(extension = 0, returns_result = false)]
-    fn transfer(recipient: <DefaultEnvironment as Environment>::AccountId, collection_id: u32, token_id: u32, amount: u128);
+    fn transfer(recipient: DefaultAccountId, collection_id: u32, token_id: u32, amount: u128);
+    #[ink(extension = 1, returns_result = false)]
+    fn create_item(owner: DefaultAccountId, collection_id: u32, data: CreateItemData);
+    #[ink(extension = 2, returns_result = false)]
+    fn create_multiple_items(owner: DefaultAccountId, collection_id: u32, data: Vec<CreateItemData>);
+    #[ink(extension = 3, returns_result = false)]
+    fn approve(spender: DefaultAccountId, collection_id: u32, item_id: u32, amount: u128);
+    #[ink(extension = 4, returns_result = false)]
+    fn transfer_from(owner: DefaultAccountId, recipient: DefaultAccountId, collection_id: u32, item_id: u32, amount: u128);
+    #[ink(extension = 5, returns_result = false)]
+    fn set_variable_meta_data(collection_id: u32, item_id: u32, data: Vec<u8>);
+    #[ink(extension = 6, returns_result = false)]
+    fn toggle_white_list(collection_id: u32, address: DefaultAccountId, whitelisted: bool);
 }
 
-#[ink::contract(env = crate::NftEnvironment)]
+#[ink::contract(env = crate::NftEnvironment, dynamic_storage_allocator = true)]
 mod nft_transfer {
+    use alloc::vec::Vec;
+    // use ink_storage::Vec;
+    use crate::CreateItemData;
 
     #[ink(storage)]
     pub struct NftTransfer {
@@ -69,6 +104,42 @@
                 .extension()
                 .transfer(recipient, collection_id, token_id, amount);
         }
+        #[ink(message)]
+        pub fn create_item(&mut self, recipient: AccountId, collection_id: u32, data: CreateItemData) {
+            let _ = self.env()
+                .extension()
+                .create_item(recipient, collection_id, data);
+        }
+        #[ink(message)]
+        pub fn create_multiple_items(&mut self, owner: AccountId, collection_id: u32, data: Vec<CreateItemData>) {
+            let _ = self.env()
+                .extension()
+                .create_multiple_items(owner, collection_id, data);
+        }
+        #[ink(message)]
+        pub fn approve(&mut self, spender: AccountId, collection_id: u32, item_id: u32, amount: u128) {
+            let _ = self.env()
+                .extension()
+                .approve(spender, collection_id, item_id, amount);
+        }
+        #[ink(message)]
+        pub fn transfer_from(&mut self, owner: AccountId, recipient: AccountId, collection_id: u32, item_id: u32, amount: u128) {
+            let _ = self.env()
+                .extension()
+                .transfer_from(owner, recipient, collection_id, item_id, amount);
+        }
+        #[ink(message)]
+        pub fn set_variable_meta_data(&mut self, collection_id: u32, item_id: u32, data: Vec<u8>) {
+            let _ = self.env()
+                .extension()
+                .set_variable_meta_data(collection_id, item_id, data);
+        }
+        #[ink(message)]
+        pub fn toggle_white_list(&mut self, collection_id: u32, address: AccountId, whitelisted: bool) {
+            let _ = self.env()
+                .extension()
+                .toggle_white_list(collection_id, address, whitelisted);
+        }
 
     }
 
modifiedtests/src/transfer_contract/metadata.jsondiffbeforeafterboth
before · tests/src/transfer_contract/metadata.json
1{2  "metadataVersion": "0.1.0",3  "source": {4    "hash": "0xfbbc0729acefed9d99f93f6cbb751d12e317958fd0fe183f5781329b37f1bf6e",5    "language": "ink! 3.0.0-rc2",6    "compiler": "rustc 1.51.0-nightly"7  },8  "contract": {9    "name": "nft_transfer",10    "version": "0.1.0",11    "authors": [12      "[Greg Zaitsev] <[your_email]>"13    ]14  },15  "spec": {16    "constructors": [17      {18        "args": [],19        "docs": [20          "Default Constructor",21          "",22          "Constructors can delegate to other constructors."23        ],24        "name": [25          "default"26        ],27        "selector": "0x6a3712e2"28      }29    ],30    "docs": [],31    "events": [],32    "messages": [33      {34        "args": [35          {36            "name": "recipient",37            "type": {38              "displayName": [39                "AccountId"40              ],41              "type": 142            }43          },44          {45            "name": "collection_id",46            "type": {47              "displayName": [48                "u32"49              ],50              "type": 451            }52          },53          {54            "name": "token_id",55            "type": {56              "displayName": [57                "u32"58              ],59              "type": 460            }61          },62          {63            "name": "amount",64            "type": {65              "displayName": [66                "u128"67              ],68              "type": 569            }70          }71        ],72        "docs": [73          " Transfer one NFT token"74        ],75        "mutates": true,76        "name": [77          "transfer"78        ],79        "payable": false,80        "returnType": null,81        "selector": "0xfae3a09d"82      }83    ]84  },85  "storage": {86    "struct": {87      "fields": []88    }89  },90  "types": [91    {92      "def": {93        "composite": {94          "fields": [95            {96              "type": 297            }98          ]99        }100      },101      "path": [102        "ink_env",103        "types",104        "AccountId"105      ]106    },107    {108      "def": {109        "array": {110          "len": 32,111          "type": 3112        }113      }114    },115    {116      "def": {117        "primitive": "u8"118      }119    },120    {121      "def": {122        "primitive": "u32"123      }124    },125    {126      "def": {127        "primitive": "u128"128      }129    }130  ]131}
modifiedtests/src/transfer_contract/nft_transfer.wasmdiffbeforeafterboth

binary blob — no preview