git.delta.rocks / unique-network / refs/commits / 72d901529a7b

difftreelog

Smart contract update

str-mv2020-08-04parent: #eff94a7.patch.diff
in: master

4 files changed

modifiedsmart_contract/ink-types-node-runtime/README.mddiffbeforeafterboth
before · smart_contract/ink-types-node-runtime/README.md
1# Node runtime types for `ink!`23Defines types for [ink!](https://github.com/paritytech/ink) smart contracts targeting [Substrate's `node-runtime`](https://github.com/paritytech/substrate/blob/master/bin/node/runtime/src/lib.rs).45Supplies an implementation of the [ink! `EnvTypes` trait](https://github.com/paritytech/ink/blob/master/core/src/env/types.rs#L128).67See `ink!` [examples](./examples) for usage.89## Requirements10```11rustup component add rust-src --toolchain nightly12rustup target add wasm32-unknown-unknown --toolchain nightly13rustup target add wasm32-unknown-unknown --toolchain stable14cargo install cargo-contract --vers 0.6.1 --force15```1617## Build1819### Runtime Dependencies20```21cargo +nightly build --release22```2324### ink! Smart Contract25```26cargo +nightly contract build27cargo +nightly contract generate-metadata28```2930## Test31```32cargo +nightly test33```3435## UI custom types36```37{38  "Schedule": {39    "version": "u32",40    "put_code_per_byte_cost": "Gas",41    "grow_mem_cost": "Gas",42    "regular_op_cost": "Gas",43    "return_data_per_byte_cost": "Gas",44    "event_data_per_byte_cost": "Gas",45    "event_per_topic_cost": "Gas",46    "event_base_cost": "Gas",47    "call_base_cost": "Gas",48    "instantiate_base_cost": "Gas",49    "dispatch_base_cost": "Gas",50    "sandbox_data_read_cost": "Gas",51    "sandbox_data_write_cost": "Gas",52    "transfer_cost": "Gas",53    "instantiate_cost": "Gas",54    "max_event_topics": "u32",55    "max_stack_height": "u32",56    "max_memory_pages": "u32",57    "max_table_size": "u32",58    "enable_println": "bool",59    "max_subject_len": "u32"60  },61  "CollectionMode": {62    "_enum": {63      "Invalid": null,64      "NFT": "u32",65      "Fungible": "u32",66      "ReFungible": "(u32, u32)"67    }68  },69  "NftItemType": {70    "Collection": "u64",71    "Owner": "AccountId",72    "Data": "Vec<u8>"73  },74  "CollectionType": {75    "Owner": "AccountId",76    "Mode": "CollectionMode",77    "Access": "u8",78    "NextItemId": "u64",79    "DecimalPoints": "u32",80    "Name": "Vec<u16>",81    "Description": "Vec<u16>",82    "TokenPrefix": "Vec<u8>",83    "CustomDataSize": "u32",84    "OffchainSchema": "Vec<u8>",85    "Sponsor": "AccountId",86    "UnconfirmedSponsor": "AccountId"87  },88  "RawData": "Vec<u8>",89  "Address": "AccountId",90  "LookupSource": "AccountId",91  "Weight": "u64"92}93```
after · smart_contract/ink-types-node-runtime/README.md
1# Node runtime types for `ink!`23Defines types for [ink!](https://github.com/paritytech/ink) smart contracts targeting [Substrate's `node-runtime`](https://github.com/paritytech/substrate/blob/master/bin/node/runtime/src/lib.rs).45Supplies an implementation of the [ink! `EnvTypes` trait](https://github.com/paritytech/ink/blob/master/core/src/env/types.rs#L128).67See `ink!` [examples](./examples) for usage.89## Requirements10```11rustup component add rust-src --toolchain nightly12rustup target add wasm32-unknown-unknown --toolchain nightly13rustup target add wasm32-unknown-unknown --toolchain stable14cargo install cargo-contract --vers 0.6.1 --force15```1617## Build1819### Runtime Dependencies20```21cargo +nightly build --release22```2324### ink! Smart Contract25```26cargo +nightly contract build27cargo +nightly contract generate-metadata28```2930## Test31```32cargo +nightly test33```
modifiedsmart_contract/ink-types-node-runtime/calls/lib.rsdiffbeforeafterboth
--- a/smart_contract/ink-types-node-runtime/calls/lib.rs
+++ b/smart_contract/ink-types-node-runtime/calls/lib.rs
@@ -7,7 +7,7 @@
     use ink_core::env;
     use ink_prelude::vec::Vec;
     use ink_prelude::*;
-    use ink_types_node_runtime::{calls as runtime_calls, NodeRuntimeTypes};
+    use ink_types_node_runtime::{calls as runtime_calls, NodeRuntimeTypes, RawData, AccountList };
     use scale::{
         Decode,
         Encode,
@@ -29,13 +29,13 @@
         fn new(&mut self) {}
 
         #[ink(message)]
-        fn transfer(&self, collection_id: u64, item_id: u64, new_owner: AccountId) {
+        fn transfer(&self, new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) {
             env::println(&format!(
-                "transfer invoke_runtime params {:?}, {:?}, {:?} ",
-                collection_id, item_id, new_owner
+                "transfer invoke_runtime params {:?}, {:?}, {:?}, {:?} ",
+                new_owner, collection_id, item_id, value
             ));
 
-            let transfer_call = runtime_calls::transfer(collection_id, item_id, new_owner);
+            let transfer_call = runtime_calls::transfer(new_owner, collection_id, item_id, value);
             // dispatch the call to the runtime
             let result = self.env().invoke_runtime(&transfer_call);
 
@@ -63,7 +63,7 @@
         }
 
         #[ink(message)]
-        fn get_approved(&self, collection_id: u64, item_id: u64) -> Vec<AccountId> {
+        fn get_approved(&self, collection_id: u64, item_id: u64) -> AccountList {
             let mut key = vec![
                 // Precomputed: Twox128("Nft")
                 244, 63, 251, 230, 30, 244, 104, 116, 157, 54, 23, 172, 26, 99, 196, 183,
@@ -92,28 +92,28 @@
             match result {
                 Some(Ok(accounts)) => { 
                     env::println(&format!("get_approved result {:?}", accounts));
-                    accounts 
+                    AccountList(accounts) 
                 },
                 Some(Err(err)) => {
                     env::println(&format!("Error reading {:?}", err));
-                    vec![]
+                    AccountList(vec![])
                 }
                 None => {
                     env::println(&format!("No data at key {:?}", key));
-                    vec![]
+                    AccountList(vec![])
                 }
             }
         }
 
         #[ink(message)]
-        fn transfer_from(&self, collection_id: u64, item_id: u64, new_owner: AccountId) {
+        fn transfer_from(&self, new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) {
             env::println(&format!(
-                "transfer_from invoke_runtime params {:?}, {:?}, {:?} ",
-                collection_id, item_id, new_owner
+                "transfer_from invoke_runtime params {:?}, {:?}, {:?}, {:?} ",
+                new_owner, collection_id, item_id, value
             ));
 
             let transfer_from_call =
-                runtime_calls::transfer_from(collection_id, item_id, new_owner);
+                runtime_calls::transfer_from(new_owner, collection_id, item_id, value);
             // dispatch the call to the runtime
             let result = self.env().invoke_runtime(&transfer_from_call);
 
@@ -124,13 +124,13 @@
 
         // SafeTransferFrom
         #[ink(message)]
-        fn create_item(&self, collection_id: u64, properties: Vec<u8>, owner: AccountId) {
+        fn create_item(&self, collection_id: u64, properties: RawData, owner: AccountId) {
             env::println(&format!(
-                "create_item invoke_runtime params {:?}, {:?} ",
-                collection_id, properties
+                "create_item invoke_runtime params {:?}, {:?}, {:?} ",
+                collection_id, properties, owner
             ));
 
-            let create_item_call = runtime_calls::create_item(collection_id, properties, owner);
+            let create_item_call = runtime_calls::create_item(collection_id, properties.into(), owner);
             // dispatch the call to the runtime
             let result = self.env().invoke_runtime(&create_item_call);
 
modifiedsmart_contract/ink-types-node-runtime/src/calls.rsdiffbeforeafterboth
--- a/smart_contract/ink-types-node-runtime/src/calls.rs
+++ b/smart_contract/ink-types-node-runtime/src/calls.rs
@@ -17,6 +17,18 @@
     }
 }
 
+// #[cfg_attr(feature = "ink-generate-abi", derive(Metadata))]
+#[derive(Encode, Decode, Debug, Eq, Clone, PartialEq)]
+pub enum CollectionMode {
+    Invalid,
+    // custom data size
+    NFT(u32),
+    // decimal points
+    Fungible(u32),
+    // custom data size and decimal points
+	ReFungible(u32, u32),
+}
+
 /// Generic Balance Call, could be used with other runtimes
 #[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub enum Nft<T>
@@ -25,19 +37,28 @@
     T::AccountId: Member + Codec,
 {
     #[allow(non_camel_case_types)]
-    create_collection(Vec<u16>, Vec<u16>, Vec<u8>, u8, u32, u32),
+    create_collection(Vec<u16>, Vec<u16>, Vec<u8>, CollectionMode),
 
     #[allow(non_camel_case_types)]
     destroy_collection(u64),
 
     #[allow(non_camel_case_types)]
+    add_collection_admin(u64, T::AccountId),
+
+    #[allow(non_camel_case_types)]
+    remove_collection_admin(u64, T::AccountId),
+
+    #[allow(non_camel_case_types)]
     change_collection_owner(u64, T::AccountId),
 
     #[allow(non_camel_case_types)]
-    add_collection_admin(u64, T::AccountId),
+    set_collection_sponsor(u64, T::AccountId),
+
+    #[allow(non_camel_case_types)]
+    confirm_sponsorship(u64),
 
     #[allow(non_camel_case_types)]
-    remove_collection_admin(u64, T::AccountId),
+    remove_collection_sponsor(u64),
 
     #[allow(non_camel_case_types)]
     create_item(u64, Vec<u8>, T::AccountId),
@@ -46,37 +67,36 @@
     burn_item(u64, u64),
 
     #[allow(non_camel_case_types)]
-    transfer(T::AccountId, u64, u64),
+    transfer(T::AccountId, u64, u64, u64),
 
     #[allow(non_camel_case_types)]
     nft_approve(T::AccountId, u64, u64),
 
     #[allow(non_camel_case_types)]
-    nft_transfer_from(T::AccountId, u64, u64),
+    nft_transfer_from(T::AccountId, u64, u64, u64),
 
     #[allow(non_camel_case_types)]
     nft_safe_transfer(u64, u64, T::AccountId),
+
+    #[allow(non_camel_case_types)]
+    set_offchain_schema(u64, Vec<u8>),
 }
 
-pub fn transfer(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {
-    Nft::<NodeRuntimeTypes>::transfer(collection_id, item_id, new_owner.into()).into()
+pub fn transfer(new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) -> Call {
+    Nft::<NodeRuntimeTypes>::transfer(new_owner.into(), collection_id, item_id, value).into()
 }
 
 pub fn create_collection(
     collection_name: Vec<u16>,
     collection_description: Vec<u16>,
     token_prefix: Vec<u8>,
-    mode: u8,
-    decimal_points: u32,
-    custom_data_size: u32,
+    mode: CollectionMode
 ) -> Call {
     Nft::<NodeRuntimeTypes>::create_collection(
         collection_name,
         collection_description,
         token_prefix,
-        mode,
-        decimal_points,
-        custom_data_size,
+        mode
     )
     .into()
 }
@@ -89,8 +109,8 @@
     Nft::<NodeRuntimeTypes>::nft_approve(approved.into(), collection_id, item_id).into()
 }
 
-pub fn transfer_from(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {
-    Nft::<NodeRuntimeTypes>::nft_transfer_from(collection_id, item_id, new_owner.into()).into()
+pub fn transfer_from(new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) -> Call {
+    Nft::<NodeRuntimeTypes>::nft_transfer_from(new_owner.into(), collection_id, item_id, value).into()
 }
 
 pub fn create_item(collection_id: u64, properties: Vec<u8>, owner: AccountId) -> Call {
modifiedsmart_contract/ink-types-node-runtime/src/lib.rsdiffbeforeafterboth
--- a/smart_contract/ink-types-node-runtime/src/lib.rs
+++ b/smart_contract/ink-types-node-runtime/src/lib.rs
@@ -4,8 +4,9 @@
 use ink_core::env::Clear;
 use scale::{Decode, Encode};
 use sp_core::crypto::AccountId32;
+use ink_prelude::vec::Vec;
 #[cfg(feature = "ink-generate-abi")]
-use type_metadata::{HasTypeDef, HasTypeId, MetaType, Metadata, TypeDef, TypeId, TypeIdArray};
+use type_metadata::{ HasTypeDef, HasTypeId, MetaType, Metadata, TypeDef, TypeId, TypeIdArray, TypeIdSlice};
 
 pub mod calls;
 
@@ -46,6 +47,59 @@
 /// The default SRML balance type.
 pub type Balance = u128;
 
+#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
+pub struct AccountList(pub Vec<AccountId>);
+
+impl AccountList {
+    pub fn new(param: Vec<AccountId>) -> AccountList {
+        AccountList(param)
+    }
+}
+
+impl Into<Vec<AccountId>> for AccountList {
+    fn into(self) -> Vec<AccountId> {
+        self.0
+    }
+}
+
+#[cfg(feature = "ink-generate-abi")]
+impl HasTypeDef for AccountList {
+    fn type_def() -> TypeDef {
+        TypeDef::builtin()
+    }
+}
+
+#[cfg(feature = "ink-generate-abi")]
+impl HasTypeId for AccountList {
+    fn type_id() -> TypeId {
+        TypeIdSlice::new(AccountId::meta_type()).into()
+    }
+}
+
+
+#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]
+pub struct RawData(Vec<u8>);
+
+impl Into<Vec<u8>> for RawData {
+    fn into(self) -> Vec<u8> {
+        self.0
+    }
+}
+
+#[cfg(feature = "ink-generate-abi")]
+impl HasTypeDef for RawData {
+    fn type_def() -> TypeDef {
+        TypeDef::builtin()
+    }
+}
+
+#[cfg(feature = "ink-generate-abi")]
+impl HasTypeId for RawData {
+    fn type_id() -> TypeId {
+        TypeIdSlice::new(u8::meta_type()).into()
+    }
+}
+
 /// The default SRML hash type.
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]
 pub struct Hash([u8; 32]);