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
189 "ink_types_node_runtime",189 "ink_types_node_runtime",
190 "parity-scale-codec",190 "parity-scale-codec",
191 "sp-keyring",191 "sp-keyring",
192 "sp-runtime",
192 "type-metadata",193 "type-metadata",
193]194]
194195
modifiedsmart_contract/ink-types-node-runtime/examples/calls/Cargo.tomldiffbeforeafterboth
11ink_lang = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_lang", default-features = false }11ink_lang = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_lang", default-features = false }
12ink_prelude = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_prelude", default-features = false }12ink_prelude = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_prelude", default-features = false }
1313
14sp-runtime = { git = "https://github.com/paritytech/substrate/", tag = "v2.0.0-rc3", package = "sp-runtime", default-features = false }
14scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] }15scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] }
15sp-keyring = { git = "https://github.com/paritytech/substrate/", tag = "v2.0.0-rc3", package = "sp-keyring", optional = true }16sp-keyring = { git = "https://github.com/paritytech/substrate/", tag = "v2.0.0-rc3", package = "sp-keyring", optional = true }
16ink_types_node_runtime = { path = "../../", default-features = false }17ink_types_node_runtime = { path = "../../", default-features = false }
modifiedsmart_contract/ink-types-node-runtime/examples/calls/lib.rsdiffbeforeafterboth
7 use ink_core::env;7 use ink_core::env;
8 use ink_prelude::*;8 use ink_prelude::*;
9 use ink_types_node_runtime::{calls as runtime_calls, NodeRuntimeTypes};9 use ink_types_node_runtime::{calls as runtime_calls, NodeRuntimeTypes};
10 use ink_core::{memory::vec::Vec, storage};
1011
11 /// This simple dummy contract dispatches substrate runtime calls12 /// This simple dummy contract dispatches substrate runtime calls
12 #[ink(storage)]13 #[ink(storage)]
1819
19 /// Dispatches a `transfer` call to the Balances srml module20 /// Dispatches a `transfer` call to the Balances srml module
20 #[ink(message)]21 #[ink(message)]
21 fn balance_transfer(&self, dest: AccountId, value: Balance) {22 fn create_collection(&self, collection_name: Vec<u16>, collection_description: Vec<u16>,
23 token_prefix: Vec<u8>,
24 custom_data_sz: u32) {
22 // create the Balances::transfer Call25 // create the Balances::transfer Call
26
27 // collection_name: Vec<u16>,
28 // collection_description: Vec<u16>,
29 // token_prefix: Vec<u8>,
30 // custom_data_sz: u32
31
23 let transfer_call = runtime_calls::transfer_balance(dest, value);32 let transfer_call = runtime_calls::create_collection(collection_name, collection_description, token_prefix, custom_data_sz);
24 // dispatch the call to the runtime33 // dispatch the call to the runtime
25 let result = self.env().invoke_runtime(&transfer_call);34 let result = self.env().invoke_runtime(&transfer_call);
26 // let _ = self.env().invoke_runtime(&transfer_call);
2735
28 // report result to console36 // report result to console
29 // NOTE: println should only be used on a development chain)37 // NOTE: println should only be used on a development chain)
modifiedsmart_contract/ink-types-node-runtime/src/calls.rsdiffbeforeafterboth
1// // Copyright 2019 Parity Technologies (UK) Ltd.
2// // This file is part of ink!.
3// //
4// // ink! is free software: you can redistribute it and/or modify
5// // it under the terms of the GNU General Public License as published by
6// // the Free Software Foundation, either version 3 of the License, or
7// // (at your option) any later version.
8// //
9// // ink! is distributed in the hope that it will be useful,
10// // but WITHOUT ANY WARRANTY; without even the implied warranty of
11// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// // GNU General Public License for more details.
13// //
14// // You should have received a copy of the GNU General Public License
15// // along with ink!. If not, see <http://www.gnu.org/licenses/>.
16
17// use ink_core::env::EnvTypes;
18// use scale::{Codec, Decode, Encode};
19// use sp_runtime::traits::Member;
20// use crate::{AccountId, Balance, NodeRuntimeTypes};
21
22// /// Default runtime Call type, a subset of the runtime Call module variants
23// ///
24// /// The codec indices of the modules *MUST* match those in the concrete runtime.
25// #[derive(Encode, Decode)]
26// #[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]
27// pub enum Call {
28// #[codec(index = "5")]
29// Balances(Balances<NodeRuntimeTypes>),
30// }
31
32// impl From<Balances<NodeRuntimeTypes>> for Call {
33// fn from(balances_call: Balances<NodeRuntimeTypes>) -> Call {
34// Call::Balances(balances_call)
35// }
36// }
37// /// Generic Balance Call, could be used with other runtimes
38// #[derive(Encode, Decode, Clone, PartialEq, Eq)]
39// pub enum Balances<T>
40// where
41// T: EnvTypes,
42// T::AccountId: Member + Codec,
43// {
44// #[allow(non_camel_case_types)]
45// transfer(T::AccountId, #[codec(compact)] T::Balance),
46// }
47
48// /// Construct a `Balances::transfer` call
49// pub fn transfer_balance(account: AccountId, balance: Balance) -> Call {
50// Balances::<NodeRuntimeTypes>::transfer(account.into(), balance).into()
51// }
52
53// #[cfg(test)]
54// mod tests {
55// use crate::{calls, NodeRuntimeTypes};
56// use super::Call;
57
58// use node_runtime::{self, Runtime};
59// use pallet_indices::address;
60// use scale::{Decode, Encode};
61
62
63// #[test]
64// fn call_balance_transfer() {
65// let balance = 10_000;
66// let account_index = 0;
67
68// let contract_address = calls::Address::Index(account_index);
69// let contract_transfer =
70// calls::Balances::<NodeRuntimeTypes>::transfer(contract_address, balance);
71// let contract_call = Call::Balances(contract_transfer);
72
73// let srml_address = address::Address::Index(account_index);
74// let srml_transfer = node_runtime::BalancesCall::<Runtime>::transfer(srml_address, balance);
75// let srml_call = node_runtime::Call::Balances(srml_transfer);
76
77// let contract_call_encoded = contract_call.encode();
78// let srml_call_encoded = srml_call.encode();
79
80// assert_eq!(srml_call_encoded, contract_call_encoded);
81
82// let srml_call_decoded: node_runtime::Call =
83// Decode::decode(&mut contract_call_encoded.as_slice())
84// .expect("Balances transfer call decodes to srml type");
85// let srml_call_encoded = srml_call_decoded.encode();
86// let contract_call_decoded: Call = Decode::decode(&mut srml_call_encoded.as_slice())
87// .expect("Balances transfer call decodes back to contract type");
88// assert!(contract_call == contract_call_decoded);
89// }
90// }
91
92
93
19use pallet_indices::address::Address;117use pallet_indices::address::Address;
20use sp_runtime::traits::Member;118use sp_runtime::traits::Member;
21use crate::{AccountId, Balance, NodeRuntimeTypes};119use crate::{AccountId, Balance, NodeRuntimeTypes};
120use sp_runtime::sp_std::prelude::Vec;
22121
23/// Default runtime Call type, a subset of the runtime Call module variants122/// Default runtime Call type, a subset of the runtime Call module variants
24///123///
25/// The codec indices of the modules *MUST* match those in the concrete runtime.124/// The codec indices of the modules *MUST* match those in the concrete runtime.
26#[derive(Encode, Decode)]125#[derive(Encode, Decode)]
27#[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]126#[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]
28pub enum Call {127pub enum Call {
29 #[codec(index = "5")]128 #[codec(index = "8")]
30 Balances(Balances<NodeRuntimeTypes>),129 Nft(Nft<NodeRuntimeTypes>),
31}130}
32131
33impl From<Balances<NodeRuntimeTypes>> for Call {132impl From<Nft<NodeRuntimeTypes>> for Call {
34 fn from(balances_call: Balances<NodeRuntimeTypes>) -> Call {133 fn from(nft_call: Nft<NodeRuntimeTypes>) -> Call {
35 Call::Balances(balances_call)134 Call::Nft(nft_call)
36 }135 }
37}136}
38/// Generic Balance Call, could be used with other runtimes137/// Generic Balance Call, could be used with other runtimes
39#[derive(Encode, Decode, Clone, PartialEq, Eq)]138#[derive(Encode, Decode, Clone, PartialEq, Eq)]
40pub enum Balances<T>139pub enum Nft<T>
41where140 where
42 T: EnvTypes,141 T: EnvTypes,
43 T::AccountId: Member + Codec,142 T::AccountId: Member + Codec,
44{143{
45 #[allow(non_camel_case_types)]144 #[allow(non_camel_case_types)]
46 transfer(T::AccountId, #[codec(compact)] T::Balance),145 create_nft_collection(Vec<u16>, Vec<u16>, Vec<u8>, u32),
146
147 #[allow(non_camel_case_types)]
148 add_collection_admin(u64, T::AccountId),
149
150 // collection_name: Vec<u16>,
151 // collection_description: Vec<u16>,
152 // token_prefix: Vec<u8>,
153 // custom_data_sz: u32
154
47}155}
48156
49/// Construct a `Balances::transfer` call157// Construct a `Balances::transfer` call
50pub fn transfer_balance(account: AccountId, balance: Balance) -> Call {158pub fn create_collection(collection_name: Vec<u16>, collection_description: Vec<u16>,
159 token_prefix: Vec<u8>, custom_data_sz: u32) -> Call {
51 Balances::<NodeRuntimeTypes>::transfer(account.into(), balance).into()160 Nft::<NodeRuntimeTypes>::create_nft_collection(collection_name, collection_description, token_prefix, custom_data_sz).into()
52}161}
53162
54#[cfg(test)]163#[cfg(test)]
addedsmart_contract/ink-types-node-runtime/src/nft.rsdiffbeforeafterboth

no changes