difftreelog
Smart contract update
in: master
6 files changed
smart_contract/ink-types-node-runtime/Cargo.lockdiffbeforeafterbothno changes
smart_contract/ink-types-node-runtime/examples/calls/Cargo.lockdiffbeforeafterboth189 "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]194195smart_contract/ink-types-node-runtime/examples/calls/Cargo.tomldiffbeforeafterboth11ink_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 }131314sp-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 }smart_contract/ink-types-node-runtime/examples/calls/lib.rsdiffbeforeafterboth7 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};101111 /// This simple dummy contract dispatches substrate runtime calls12 /// This simple dummy contract dispatches substrate runtime calls12 #[ink(storage)]13 #[ink(storage)]181919 /// Dispatches a `transfer` call to the Balances srml module20 /// Dispatches a `transfer` call to the Balances srml module20 #[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 Call2627 // collection_name: Vec<u16>,28 // collection_description: Vec<u16>,29 // token_prefix: Vec<u8>,30 // custom_data_sz: u323123 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 runtime25 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);273528 // report result to console36 // report result to console29 // NOTE: println should only be used on a development chain)37 // NOTE: println should only be used on a development chain)smart_contract/ink-types-node-runtime/src/calls.rsdiffbeforeafterboth1// // 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 modify5// // it under the terms of the GNU General Public License as published by6// // the Free Software Foundation, either version 3 of the License, or7// // (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 of11// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// // GNU General Public License for more details.13// //14// // You should have received a copy of the GNU General Public License15// // along with ink!. If not, see <http://www.gnu.org/licenses/>.1617// use ink_core::env::EnvTypes;18// use scale::{Codec, Decode, Encode};19// use sp_runtime::traits::Member;20// use crate::{AccountId, Balance, NodeRuntimeTypes};2122// /// Default runtime Call type, a subset of the runtime Call module variants23// ///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// }3132// 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 runtimes38// #[derive(Encode, Decode, Clone, PartialEq, Eq)]39// pub enum Balances<T>40// where41// T: EnvTypes,42// T::AccountId: Member + Codec,43// {44// #[allow(non_camel_case_types)]45// transfer(T::AccountId, #[codec(compact)] T::Balance),46// }4748// /// Construct a `Balances::transfer` call49// pub fn transfer_balance(account: AccountId, balance: Balance) -> Call {50// Balances::<NodeRuntimeTypes>::transfer(account.into(), balance).into()51// }5253// #[cfg(test)]54// mod tests {55// use crate::{calls, NodeRuntimeTypes};56// use super::Call;5758// use node_runtime::{self, Runtime};59// use pallet_indices::address;60// use scale::{Decode, Encode};616263// #[test]64// fn call_balance_transfer() {65// let balance = 10_000;66// let account_index = 0;6768// 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);7273// 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);7677// let contract_call_encoded = contract_call.encode();78// let srml_call_encoded = srml_call.encode();7980// assert_eq!(srml_call_encoded, contract_call_encoded);8182// 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// }91929319use 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;2212123/// Default runtime Call type, a subset of the runtime Call module variants122/// Default runtime Call type, a subset of the runtime Call module variants24///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}3213133impl 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 runtimes39#[derive(Encode, Decode, Clone, PartialEq, Eq)]138#[derive(Encode, Decode, Clone, PartialEq, Eq)]40pub enum Balances<T>139pub enum Nft<T>41where140 where42 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),146147 #[allow(non_camel_case_types)]148 add_collection_admin(u64, T::AccountId),149150 // collection_name: Vec<u16>,151 // collection_description: Vec<u16>,152 // token_prefix: Vec<u8>,153 // custom_data_sz: u3215447}155}4815649/// Construct a `Balances::transfer` call157// Construct a `Balances::transfer` call50pub 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}5316254#[cfg(test)]163#[cfg(test)]smart_contract/ink-types-node-runtime/src/nft.rsdiffbeforeafterbothno changes