git.delta.rocks / unique-network / refs/commits / 37abce617d2e

difftreelog

Smart contract update

str-mv2020-07-16parent: #00ded0c.patch.diff
in: master

6 files changed

addedsmart_contract/ink-types-node-runtime/Cargo.lockdiffbeforeafterboth

no changes

modifiedsmart_contract/ink-types-node-runtime/examples/calls/Cargo.lockdiffbeforeafterboth
--- a/smart_contract/ink-types-node-runtime/examples/calls/Cargo.lock
+++ b/smart_contract/ink-types-node-runtime/examples/calls/Cargo.lock
@@ -189,6 +189,7 @@
  "ink_types_node_runtime",
  "parity-scale-codec",
  "sp-keyring",
+ "sp-runtime",
  "type-metadata",
 ]
 
modifiedsmart_contract/ink-types-node-runtime/examples/calls/Cargo.tomldiffbeforeafterboth
--- a/smart_contract/ink-types-node-runtime/examples/calls/Cargo.toml
+++ b/smart_contract/ink-types-node-runtime/examples/calls/Cargo.toml
@@ -11,6 +11,7 @@
 ink_lang = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_lang", default-features = false }
 ink_prelude = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_prelude", default-features = false }
 
+sp-runtime = { git = "https://github.com/paritytech/substrate/", tag = "v2.0.0-rc3", package = "sp-runtime", default-features = false }
 scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] }
 sp-keyring = { git = "https://github.com/paritytech/substrate/", tag = "v2.0.0-rc3", package = "sp-keyring", optional = true }
 ink_types_node_runtime = { path = "../../", default-features = false }
modifiedsmart_contract/ink-types-node-runtime/examples/calls/lib.rsdiffbeforeafterboth
--- a/smart_contract/ink-types-node-runtime/examples/calls/lib.rs
+++ b/smart_contract/ink-types-node-runtime/examples/calls/lib.rs
@@ -7,6 +7,7 @@
     use ink_core::env;
     use ink_prelude::*;
     use ink_types_node_runtime::{calls as runtime_calls, NodeRuntimeTypes};
+    use ink_core::{memory::vec::Vec, storage};
 
     /// This simple dummy contract dispatches substrate runtime calls
     #[ink(storage)]
@@ -18,12 +19,19 @@
 
         /// Dispatches a `transfer` call to the Balances srml module
         #[ink(message)]
-        fn balance_transfer(&self, dest: AccountId, value: Balance) {
+        fn create_collection(&self, collection_name: Vec<u16>, collection_description: Vec<u16>, 
+                            token_prefix: Vec<u8>, 
+                            custom_data_sz: u32) {
             // create the Balances::transfer Call
-            let transfer_call = runtime_calls::transfer_balance(dest, value);
+
+            // collection_name: Vec<u16>,
+            // collection_description: Vec<u16>,
+            // token_prefix: Vec<u8>,
+            // custom_data_sz: u32
+
+            let transfer_call = runtime_calls::create_collection(collection_name, collection_description, token_prefix, custom_data_sz);
             // dispatch the call to the runtime
             let result = self.env().invoke_runtime(&transfer_call);
-            // let _ = self.env().invoke_runtime(&transfer_call);
 
             // report result to console
             // NOTE: println should only be used on a development chain)
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
@@ -1,3 +1,101 @@
+// // Copyright 2019 Parity Technologies (UK) Ltd.
+// // This file is part of ink!.
+// //
+// // ink! is free software: you can redistribute it and/or modify
+// // it under the terms of the GNU General Public License as published by
+// // the Free Software Foundation, either version 3 of the License, or
+// // (at your option) any later version.
+// //
+// // ink! is distributed in the hope that it will be useful,
+// // but WITHOUT ANY WARRANTY; without even the implied warranty of
+// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// // GNU General Public License for more details.
+// //
+// // You should have received a copy of the GNU General Public License
+// // along with ink!.  If not, see <http://www.gnu.org/licenses/>.
+
+// use ink_core::env::EnvTypes;
+// use scale::{Codec, Decode, Encode};
+// use sp_runtime::traits::Member;
+// use crate::{AccountId, Balance, NodeRuntimeTypes};
+
+// /// Default runtime Call type, a subset of the runtime Call module variants
+// ///
+// /// The codec indices of the  modules *MUST* match those in the concrete runtime.
+// #[derive(Encode, Decode)]
+// #[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]
+// pub enum Call {
+//     #[codec(index = "5")]
+//     Balances(Balances<NodeRuntimeTypes>),
+// }
+
+// impl From<Balances<NodeRuntimeTypes>> for Call {
+//     fn from(balances_call: Balances<NodeRuntimeTypes>) -> Call {
+//         Call::Balances(balances_call)
+//     }
+// }
+// /// Generic Balance Call, could be used with other runtimes
+// #[derive(Encode, Decode, Clone, PartialEq, Eq)]
+// pub enum Balances<T>
+// where
+//     T: EnvTypes,
+//     T::AccountId: Member + Codec,
+// {
+//     #[allow(non_camel_case_types)]
+//     transfer(T::AccountId, #[codec(compact)] T::Balance),
+// }
+
+// /// Construct a `Balances::transfer` call
+// pub fn transfer_balance(account: AccountId, balance: Balance) -> Call {
+//     Balances::<NodeRuntimeTypes>::transfer(account.into(), balance).into()
+// }
+
+// #[cfg(test)]
+// mod tests {
+//     use crate::{calls, NodeRuntimeTypes};
+//     use super::Call;
+
+//     use node_runtime::{self, Runtime};
+//     use pallet_indices::address;
+//     use scale::{Decode, Encode};
+
+
+//     #[test]
+//     fn call_balance_transfer() {
+//         let balance = 10_000;
+//         let account_index = 0;
+
+//         let contract_address = calls::Address::Index(account_index);
+//         let contract_transfer =
+//             calls::Balances::<NodeRuntimeTypes>::transfer(contract_address, balance);
+//         let contract_call = Call::Balances(contract_transfer);
+
+//         let srml_address = address::Address::Index(account_index);
+//         let srml_transfer = node_runtime::BalancesCall::<Runtime>::transfer(srml_address, balance);
+//         let srml_call = node_runtime::Call::Balances(srml_transfer);
+
+//         let contract_call_encoded = contract_call.encode();
+//         let srml_call_encoded = srml_call.encode();
+
+//         assert_eq!(srml_call_encoded, contract_call_encoded);
+
+//         let srml_call_decoded: node_runtime::Call =
+//             Decode::decode(&mut contract_call_encoded.as_slice())
+//                 .expect("Balances transfer call decodes to srml type");
+//         let srml_call_encoded = srml_call_decoded.encode();
+//         let contract_call_decoded: Call = Decode::decode(&mut srml_call_encoded.as_slice())
+//             .expect("Balances transfer call decodes back to contract type");
+//         assert!(contract_call == contract_call_decoded);
+//     }
+// }
+
+
+
+
+
+
+
+
 // Copyright 2019 Parity Technologies (UK) Ltd.
 // This file is part of ink!.
 //
@@ -19,6 +117,7 @@
 use pallet_indices::address::Address;
 use sp_runtime::traits::Member;
 use crate::{AccountId, Balance, NodeRuntimeTypes};
+use sp_runtime::sp_std::prelude::Vec;
 
 /// Default runtime Call type, a subset of the runtime Call module variants
 ///
@@ -26,29 +125,39 @@
 #[derive(Encode, Decode)]
 #[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]
 pub enum Call {
-    #[codec(index = "5")]
-    Balances(Balances<NodeRuntimeTypes>),
+    #[codec(index = "8")]
+    Nft(Nft<NodeRuntimeTypes>),
 }
 
-impl From<Balances<NodeRuntimeTypes>> for Call {
-    fn from(balances_call: Balances<NodeRuntimeTypes>) -> Call {
-        Call::Balances(balances_call)
+impl From<Nft<NodeRuntimeTypes>> for Call {
+    fn from(nft_call: Nft<NodeRuntimeTypes>) -> Call {
+        Call::Nft(nft_call)
     }
 }
 /// Generic Balance Call, could be used with other runtimes
 #[derive(Encode, Decode, Clone, PartialEq, Eq)]
-pub enum Balances<T>
-where
-    T: EnvTypes,
-    T::AccountId: Member + Codec,
+pub enum Nft<T>
+ where
+     T: EnvTypes,
+     T::AccountId: Member + Codec,
 {
     #[allow(non_camel_case_types)]
-    transfer(T::AccountId, #[codec(compact)] T::Balance),
+    create_nft_collection(Vec<u16>, Vec<u16>, Vec<u8>, u32),
+
+    #[allow(non_camel_case_types)]
+    add_collection_admin(u64, T::AccountId),
+
+    // collection_name: Vec<u16>,
+    // collection_description: Vec<u16>,
+    // token_prefix: Vec<u8>,
+    // custom_data_sz: u32
+
 }
 
-/// Construct a `Balances::transfer` call
-pub fn transfer_balance(account: AccountId, balance: Balance) -> Call {
-    Balances::<NodeRuntimeTypes>::transfer(account.into(), balance).into()
+// Construct a `Balances::transfer` call
+pub fn create_collection(collection_name: Vec<u16>, collection_description: Vec<u16>, 
+                        token_prefix: Vec<u8>, custom_data_sz: u32) -> Call {
+    Nft::<NodeRuntimeTypes>::create_nft_collection(collection_name, collection_description, token_prefix, custom_data_sz).into()
 }
 
 #[cfg(test)]
addedsmart_contract/ink-types-node-runtime/src/nft.rsdiffbeforeafterboth
--- /dev/null
+++ b/smart_contract/ink-types-node-runtime/src/nft.rs
@@ -0,0 +1,98 @@
+// Copyright 2019 Parity Technologies (UK) Ltd.
+// This file is part of ink!.
+//
+// ink! is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// ink! is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with ink!.  If not, see <http://www.gnu.org/licenses/>.
+
+use ink_core::env::EnvTypes;
+use scale::{Codec, Decode, Encode};
+use pallet_indices::address::Address;
+use sp_runtime::traits::Member;
+use crate::{AccountId, Balance, NodeRuntimeTypes};
+
+/// Default runtime Call type, a subset of the runtime Call module variants
+///
+/// The codec indices of the  modules *MUST* match those in the concrete runtime.
+#[derive(Encode, Decode)]
+#[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]
+pub enum Nft {
+    #[codec(index = "8")]
+    Nft(Nft<NodeRuntimeTypes>),
+}
+
+impl From<Nft<NodeRuntimeTypes>> for Call {
+    fn from(nft_call: Nft<NodeRuntimeTypes>) -> Call {
+        Call::Nft(nft_call)
+    }
+}
+/// Generic Balance Call, could be used with other runtimes
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
+pub enum Nft<T>
+where
+    T: EnvTypes,
+ //   T::AccountId: Member + Codec,
+{
+    #[allow(non_camel_case_types)]
+    create_nft_collection(Vec<u16>, Vec<u16>, Vec<u8>, u32),
+
+
+    // collection_name: Vec<u16>,
+    // collection_description: Vec<u16>,
+    // token_prefix: Vec<u8>,
+    // custom_data_sz: u32
+
+}
+
+/// Construct a `Balances::transfer` call
+// pub fn transfer_balance(account: AccountId, balance: Balance) -> Call {
+//     Balances::<NodeRuntimeTypes>::transfer(account.into(), balance).into()
+// }
+
+// #[cfg(test)]
+// mod tests {
+//     use crate::{calls, NodeRuntimeTypes};
+//     use super::Call;
+
+//     use node_runtime::{self, Runtime};
+//     use pallet_indices::address;
+//     use scale::{Decode, Encode};
+
+
+//     #[test]
+//     fn call_balance_transfer() {
+//         let balance = 10_000;
+//         let account_index = 0;
+
+//         let contract_address = calls::Address::Index(account_index);
+//         let contract_transfer =
+//             calls::Balances::<NodeRuntimeTypes>::transfer(contract_address, balance);
+//         let contract_call = Call::Balances(contract_transfer);
+
+//         let srml_address = address::Address::Index(account_index);
+//         let srml_transfer = node_runtime::BalancesCall::<Runtime>::transfer(srml_address, balance);
+//         let srml_call = node_runtime::Call::Balances(srml_transfer);
+
+//         let contract_call_encoded = contract_call.encode();
+//         let srml_call_encoded = srml_call.encode();
+
+//         assert_eq!(srml_call_encoded, contract_call_encoded);
+
+//         let srml_call_decoded: node_runtime::Call =
+//             Decode::decode(&mut contract_call_encoded.as_slice())
+//                 .expect("Balances transfer call decodes to srml type");
+//         let srml_call_encoded = srml_call_decoded.encode();
+//         let contract_call_decoded: Call = Decode::decode(&mut srml_call_encoded.as_slice())
+//             .expect("Balances transfer call decodes back to contract type");
+//         assert!(contract_call == contract_call_decoded);
+//     }
+// }