git.delta.rocks / unique-network / refs/commits / 907c4d4b8cb3

difftreelog

Merge branch 'master' of github.com:usetech-llc/nft_parachain

Greg Zaitsev2020-07-17parents: #019c2ca #8040196.patch.diff
in: master

12 files changed

modifiedDockerfile-testnetdiffbeforeafterboth
22
3FROM phusion/baseimage:0.10.2 as builder3FROM phusion/baseimage:0.10.2 as builder
4LABEL maintainer="gz@usetech.com"4LABEL maintainer="gz@usetech.com"
5#
6#ENV WASM_TOOLCHAIN=nightly-2020-05-01
7#
8#ARG PROFILE=release
9#
10#RUN apt-get update && \
11# apt-get dist-upgrade -y -o Dpkg::Options::="--force-confold" && \
12# apt-get install -y cmake pkg-config libssl-dev git clang
13#
14## Get project and run it
15##RUN git clone https://github.com/usetech-llc/nft_parachain /nft_parachain
16#RUN mkdir nft_parachain
17#WORKDIR /nft_parachain
18#COPY . .
19#
20#RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
21# export PATH="$PATH:$HOME/.cargo/bin" && \
22# rustup toolchain uninstall $(rustup toolchain list) && \
23# rustup default 1.44.0 && \
24# rustup toolchain install $WASM_TOOLCHAIN && \
25# rustup target add wasm32-unknown-unknown --toolchain $WASM_TOOLCHAIN && \
26# rustup target list --installed && \
27# rustup show && \
28# cargo build "--$PROFILE"
29# # && \
30# # cargo test
31#
32#RUN cd target/release && ls -la
33#
34## ===== RUN ======
35#
36#FROM phusion/baseimage:0.10.2
37#ARG PROFILE=release
38#
39#COPY --from=builder /nft_parachain/target/$PROFILE/nft /usr/local/bin
40#
41#EXPOSE 9944
42#VOLUME ["/chain-data"]
543
6ENV WASM_TOOLCHAIN=nightly-2020-05-01
7
8ARG PROFILE=release
9
10RUN apt-get update && \
11 apt-get dist-upgrade -y -o Dpkg::Options::="--force-confold" && \
12 apt-get install -y cmake pkg-config libssl-dev git clang
13
14# Get project and run it
15#RUN git clone https://github.com/usetech-llc/nft_parachain /nft_parachain
16RUN mkdir nft_parachain
17WORKDIR /nft_parachain
18COPY . .
19
20RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
21 export PATH="$PATH:$HOME/.cargo/bin" && \
22 rustup toolchain uninstall $(rustup toolchain list) && \
23 rustup default 1.44.0 && \
24 rustup toolchain install $WASM_TOOLCHAIN && \
25 rustup target add wasm32-unknown-unknown --toolchain $WASM_TOOLCHAIN && \
26 rustup target list --installed && \
27 rustup show && \
28 cargo build "--$PROFILE"
29 # && \
30 # cargo test
31
32RUN cd target/release && ls -la
33
34# ===== RUN ======
35
36FROM phusion/baseimage:0.10.2
37ARG PROFILE=release
38
39COPY --from=builder /nft_parachain/target/$PROFILE/nft /usr/local/bin
40
41EXPOSE 9944
42VOLUME ["/chain-data"]
43
44# Copy and run start script44# Copy and run start script
45COPY ["./run.sh", "./run.sh"]45COPY ["./run-testnet.sh", "./run.sh"]
46RUN chmod +x ./run.sh46RUN chmod +x ./run.sh
47CMD ["bash", "-c", "./run.sh"]47CMD ["bash", "-c", "./run.sh"]
4848
addeddeploy-testnet.shdiffbeforeafterboth

no changes

modifieddocker-compose-testnet.ymldiffbeforeafterboth
7 - 9944:99447 - 9944:9944
8 build:8 build:
9 context: ./9 context: ./
10 dockerfile: Dockerfile-production10 dockerfile: Dockerfile-testnet
11 volumes:11 volumes:
12 - ./chain-data-einstein:/chain-data12 - ./chain-data-einstein:/chain-data
13 networks: 13 networks:
21 - 9945:994421 - 9945:9944
22 build:22 build:
23 context: ./23 context: ./
24 dockerfile: Dockerfile-production24 dockerfile: Dockerfile-testnet
25 volumes:25 volumes:
26 - ./chain-data-newton:/chain-data26 - ./chain-data-newton:/chain-data
27 networks: 27 networks:
addednftTestnetSpec.jsondiffbeforeafterboth

no changes

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
96 // this is needed only if you are using events in your pallet96 // this is needed only if you are using events in your pallet
97 fn deposit_event() = default;97 fn deposit_event() = default;
98
99 // Initializing events
100 // this is needed only if you are using events in your module
101 // fn deposit_event<T>() = default;
102
103 // Create collection of NFT with given parameters
104 //
105 // @param customDataSz size of custom data in each collection item
106 // returns collection ID
10798
108 // Create collection of NFT with given parameters99 // Create collection of NFT with given parameters
109 //100 //
addedrun-testnet.shdiffbeforeafterboth

no changes

modifiedruntime/src/lib.rsdiffbeforeafterboth
8#[cfg(feature = "std")]8#[cfg(feature = "std")]
9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
1010
11use contracts_rpc_runtime_api::ContractExecResult;
11use grandpa::fg_primitives;12use grandpa::fg_primitives;
12use grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};13use grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
13use sp_api::impl_runtime_apis;14use sp_api::impl_runtime_apis;
21 transaction_validity::{TransactionSource, TransactionValidity},22 transaction_validity::{TransactionSource, TransactionValidity},
22 ApplyExtrinsicResult, MultiSignature,23 ApplyExtrinsicResult, MultiSignature,
23};24};
24use contracts_rpc_runtime_api::ContractExecResult;
25use sp_std::prelude::*;25use sp_std::prelude::*;
26#[cfg(feature = "std")]26#[cfg(feature = "std")]
27use sp_version::NativeVersion;27use sp_version::NativeVersion;
modifiedsmart_contract/ink-types-node-runtime/Cargo.tomldiffbeforeafterboth
1818
19[dependencies]19[dependencies]
20ink_core = { version = "2", git = "https://github.com/usetech-llc/ink", tag = "latest-v2", package = "ink_core", default-features = false }20ink_core = { version = "2", git = "https://github.com/usetech-llc/ink", tag = "latest-v2", package = "ink_core", default-features = false }
21ink_prelude = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_prelude", default-features = false }
21frame-system = { git = "https://github.com/usetech-llc/substrate/", branch = "nft_rc3", package = "frame-system", default-features = false }22frame-system = { git = "https://github.com/usetech-llc/substrate/", branch = "nft_rc3", package = "frame-system", default-features = false }
22pallet-indices = { git = "https://github.com/usetech-llc/substrate/", branch = "nft_rc3", package = "pallet-indices", default-features = false }23pallet-indices = { git = "https://github.com/usetech-llc/substrate/", branch = "nft_rc3", package = "pallet-indices", default-features = false }
23sp-core = { git = "https://github.com/usetech-llc/substrate/", branch = "nft_rc3", package = "sp-core", default-features = false }24sp-core = { git = "https://github.com/usetech-llc/substrate/", branch = "nft_rc3", package = "sp-core", default-features = false }
modifiedsmart_contract/ink-types-node-runtime/examples/calls/Cargo.lockdiffbeforeafterboth
803dependencies = [803dependencies = [
804 "frame-system",804 "frame-system",
805 "ink_core",805 "ink_core",
806 "ink_prelude",
806 "pallet-indices",807 "pallet-indices",
807 "parity-scale-codec",808 "parity-scale-codec",
808 "sp-core",809 "sp-core",
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};10 use ink_prelude::vec::Vec;
1111
12 /// This simple dummy contract dispatches substrate runtime calls12 /// This simple dummy contract dispatches substrate runtime calls
13 #[ink(storage)]13 #[ink(storage)]
17 #[ink(constructor)]17 #[ink(constructor)]
18 fn new(&mut self) {}18 fn new(&mut self) {}
1919
20 /// Dispatches a `transfer` call to the Balances srml module
21 #[ink(message)]20 #[ink(message)]
22 fn create_collection(&self, collection_name: Vec<u16>, collection_description: Vec<u16>, 21 fn transfer(&self, collection_id: u64, item_id: u64, new_owner: AccountId) {
23 token_prefix: Vec<u8>, 22
24 custom_data_sz: u32) {23 env::println(&format!(
25 // create the Balances::transfer Call24 "transfer invoke_runtime params {:?}, {:?}, {:?} ",
2625 collection_id,
27 // collection_name: Vec<u16>,26 item_id,
28 // collection_description: Vec<u16>,27 new_owner
29 // token_prefix: Vec<u8>,28 ));
30 // custom_data_sz: u32
3129
32 let transfer_call = runtime_calls::create_collection(collection_name, collection_description, token_prefix, custom_data_sz);30 let transfer_call = runtime_calls::transfer(collection_id, item_id, new_owner);
33 // dispatch the call to the runtime31 // dispatch the call to the runtime
34 let result = self.env().invoke_runtime(&transfer_call);32 let result = self.env().invoke_runtime(&transfer_call);
3533
36 // report result to console34 // report result to console
37 // NOTE: println should only be used on a development chain)35 // NOTE: println should only be used on a development chain)
38 env::println(&format!(36 env::println(&format!(
39 "Balance transfer invoke_runtime result {:?}",37 "transfer invoke_runtime result {:?}",
40 result38 result
41 ));39 ));
42 }40 }
41
42 // SafeTransfer
43
44 #[ink(message)]
45 fn approve(&self, approved: AccountId, collection_id: u64, item_id: u64) {
46
47 env::println(&format!(
48 "approve invoke_runtime params {:?}, {:?}, {:?} ",
49 approved,
50 collection_id,
51 item_id
52 ));
53
54 let approve_call = runtime_calls::approve(approved, collection_id, item_id);
55 // dispatch the call to the runtime
56 let result = self.env().invoke_runtime(&approve_call);
57
58 // report result to console
59 // NOTE: println should only be used on a development chain)
60 env::println(&format!(
61 "approve invoke_runtime result {:?}",
62 result
63 ));
64 }
65
66 ////////////////////////////////////////// GetApproved
67 ///
68 /// Returns an account's free balance, read directly from runtime storage
69 ///
70 /// # Key Scheme
71 ///
72 /// A key for the [substrate storage map]
73 /// (https://github.com/paritytech/substrate/blob/dd97b1478b31a4715df7e88a5ebc6664425fb6c6/frame/support/src/storage/generator/map.rs#L28)
74 /// is constructed with:
75 ///
76 /// ```nocompile
77 /// Twox128(module_prefix) ++ Twox128(storage_prefix) ++ Hasher(encode(key))
78 /// ```
79 ///
80 /// For the `System` module's `Account` map, the [hasher implementation]
81 /// (https://github.com/paritytech/substrate/blob/2c87fe171bc341755a43a3b32d67560469f8daac/frame/system/src/lib.rs#L349)
82 /// is `blake2_128_concat`.
83 // #[ink(message)]
84 // fn get_balance(&self, account: AccountId) -> Balance {
85 // let mut key = vec![
86 // // Precomputed: Twox128("System")
87 // 38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247,
88 // // Precomputed: Twox128("Account")
89 // 185, 157, 136, 14, 198, 129, 121, 156, 12, 243, 14, 136, 134, 55, 29, 169,
90 // ];
91
92 // let encoded_account = account.encode();
93 // let hashed_account = <Blake2x128>::hash_bytes(&encoded_account);
94
95 // // The hasher is `Blake2_128Concat` which appends the unhashed account to the hashed account
96 // key.extend_from_slice(&hashed_account);
97 // key.extend_from_slice(&encoded_account);
98
99 // // fetch from runtime storage
100 // let result = self.env().get_runtime_storage::<AccountInfo>(&key[..]);
101 // match result {
102 // Some(Ok(account_info)) => account_info.data.free,
103 // Some(Err(err)) => {
104 // env::println(&format!("Error reading AccountInfo {:?}", err));
105 // 0
106 // }
107 // None => {
108 // env::println(&format!("No data at key {:?}", key));
109 // 0
110 // }
111 // }
112 // }
113
114 #[ink(message)]
115 fn transfer_from(&self, collection_id: u64, item_id: u64, new_owner: AccountId) {
116
117 env::println(&format!(
118 "transfer_from invoke_runtime params {:?}, {:?}, {:?} ",
119 collection_id,
120 item_id,
121 new_owner
122 ));
123
124 let transfer_from_call = runtime_calls::transfer_from(collection_id, item_id, new_owner);
125 // dispatch the call to the runtime
126 let result = self.env().invoke_runtime(&transfer_from_call);
127
128 // report result to console
129 // NOTE: println should only be used on a development chain)
130 env::println(&format!(
131 "transfer_from invoke_runtime result {:?}",
132 result
133 ));
134 }
135
136 // SafeTransferFrom
137
138 #[ink(message)]
139 fn create_item(&self, collection_id: u64, properties: Vec<u8>) {
140
141 env::println(&format!(
142 "create_item invoke_runtime params {:?}, {:?} ",
143 collection_id,
144 properties
145 ));
146
147 let create_item_call = runtime_calls::create_item(collection_id, properties);
148 // dispatch the call to the runtime
149 let result = self.env().invoke_runtime(&create_item_call);
150
151 // report result to console
152 // NOTE: println should only be used on a development chain)
153 env::println(&format!(
154 "create_item invoke_runtime result {:?}",
155 result
156 ));
157 }
158
159 #[ink(message)]
160 fn burn_item(&self, collection_id: u64, item_id: u64) {
161
162 env::println(&format!(
163 "burn_item invoke_runtime params {:?}, {:?}",
164 collection_id,
165 item_id
166 ));
167
168 let burn_item_call = runtime_calls::burn_item(collection_id, item_id);
169 // dispatch the call to the runtime
170 let result = self.env().invoke_runtime(&burn_item_call);
171
172 // report result to console
173 // NOTE: println should only be used on a development chain)
174 env::println(&format!(
175 "burn_item invoke_runtime result {:?}",
176 result
177 ));
178 }
179
180 // GetOwner
181 // BalanceOf
43 }182 }
44
45 #[cfg(test)]
46 mod tests {
47 use super::*;
48 use sp_keyring::AccountKeyring;
49
50 #[test]
51 fn dispatches_balances_call() {
52 let calls = Calls::new();
53 let alice = AccountId::from(AccountKeyring::Alice.to_account_id());
54 // assert_eq!(calls.env().dispatched_calls().into_iter().count(), 0);
55 calls.balance_transfer(alice, 10000);
56 // assert_eq!(calls.env().dispatched_calls().into_iter().count(), 1);
57 }
58 }
59}183}
60184
modifiedsmart_contract/ink-types-node-runtime/src/calls.rsdiffbeforeafterboth
50// Balances::<NodeRuntimeTypes>::transfer(account.into(), balance).into()50// Balances::<NodeRuntimeTypes>::transfer(account.into(), balance).into()
51// }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
9252
9353
11474
115use ink_core::env::EnvTypes;75use ink_core::env::EnvTypes;
116use scale::{Codec, Decode, Encode};76use scale::{Codec, Decode, Encode};
117use pallet_indices::address::Address;77use sp_runtime::traits::Member;
118use sp_runtime::traits::Member;78use ink_prelude::vec::Vec;
119use crate::{AccountId, Balance, NodeRuntimeTypes};79use crate::{AccountId, Balance, NodeRuntimeTypes};
120use sp_runtime::sp_std::prelude::Vec;80
12181
122/// Default runtime Call type, a subset of the runtime Call module variants82/// Default runtime Call type, a subset of the runtime Call module variants
123///83///
124/// The codec indices of the modules *MUST* match those in the concrete runtime.84/// The codec indices of the modules *MUST* match those in the concrete runtime.
125#[derive(Encode, Decode)]85#[derive(Encode, Decode)]
126#[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]86#[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]
127pub enum Call {87pub enum Call {
128 #[codec(index = "8")]88 #[codec(index = "7")]
129 Nft(Nft<NodeRuntimeTypes>),89 Nft(Nft<NodeRuntimeTypes>),
130}90}
13191
142 T::AccountId: Member + Codec,102 T::AccountId: Member + Codec,
143{103 {
144 #[allow(non_camel_case_types)]104 #[allow(non_camel_case_types)]
145 create_nft_collection(Vec<u16>, Vec<u16>, Vec<u8>, u32),105 create_collection(Vec<u16>, Vec<u16>, Vec<u8>, u32),
106
107 #[allow(non_camel_case_types)]
108 destroy_collection(u64),
109
110 #[allow(non_camel_case_types)]
111 change_collection_owner(u64, T::AccountId),
146112
147 #[allow(non_camel_case_types)]113 #[allow(non_camel_case_types)]
148 add_collection_admin(u64, T::AccountId),114 add_collection_admin(u64, T::AccountId),
149115
150 // collection_name: Vec<u16>,116 #[allow(non_camel_case_types)]
151 // collection_description: Vec<u16>,117 remove_collection_admin(u64, T::AccountId),
152 // token_prefix: Vec<u8>,118
153 // custom_data_sz: u32119 #[allow(non_camel_case_types)]
154120 create_item(u64, Vec<u8>),
121
122 #[allow(non_camel_case_types)]
123 burn_item(u64, u64),
124
125 #[allow(non_camel_case_types)]
126 transfer(u64, u64, T::AccountId),
127
128 #[allow(non_camel_case_types)]
129 nft_approve(T::AccountId, u64, u64),
130
131 #[allow(non_camel_case_types)]
132 nft_transfer_from(u64, u64, T::AccountId),
133
134 #[allow(non_camel_case_types)]
135 nft_safe_transfer(u64, u64, T::AccountId),
155}136 }
156137
157// Construct a `Balances::transfer` call138
139
140
141pub fn transfer(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {
142 Nft::<NodeRuntimeTypes>::transfer(collection_id, item_id, new_owner.into()).into()
143}
144
158pub fn create_collection(collection_name: Vec<u16>, collection_description: Vec<u16>, 145pub fn create_collection(collection_name: Vec<u16>, collection_description: Vec<u16>,
159 token_prefix: Vec<u8>, custom_data_sz: u32) -> Call {146 token_prefix: Vec<u8>, custom_data_sz: u32) -> Call {
160 Nft::<NodeRuntimeTypes>::create_nft_collection(collection_name, collection_description, token_prefix, custom_data_sz).into()147 Nft::<NodeRuntimeTypes>::create_collection(collection_name, collection_description, token_prefix, custom_data_sz).into()
161}148}
162149
163#[cfg(test)]150// pub fn safe_transfer(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {
164mod tests {151// Nft::<NodeRuntimeTypes>::nft_safe_transfer(collection_id, item_id, new_owner.into()).into()
152// }
153
165 use crate::{calls, NodeRuntimeTypes};154pub fn approve(approved: AccountId, collection_id: u64, item_id: u64) -> Call {
166 use super::Call;155 Nft::<NodeRuntimeTypes>::nft_approve(approved.into(), collection_id, item_id).into()
156}
157
158//GetApproved
167159
168 use node_runtime::{self, Runtime};160pub fn transfer_from(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {
169 use pallet_indices::address;
170 use scale::{Decode, Encode};
171
172
173 #[test]
174 fn call_balance_transfer() {161 Nft::<NodeRuntimeTypes>::nft_transfer_from(collection_id, item_id, new_owner.into()).into()
175 let balance = 10_000;162}
176 let account_index = 0;163
177
178 let contract_address = calls::Address::Index(account_index);
179 let contract_transfer =
180 calls::Balances::<NodeRuntimeTypes>::transfer(contract_address, balance);
181 let contract_call = Call::Balances(contract_transfer);
182
183 let srml_address = address::Address::Index(account_index);
184 let srml_transfer = node_runtime::BalancesCall::<Runtime>::transfer(srml_address, balance);
185 let srml_call = node_runtime::Call::Balances(srml_transfer);164pub fn create_item(collection_id: u64, properties: Vec<u8>) -> Call {
186
187 let contract_call_encoded = contract_call.encode();
188 let srml_call_encoded = srml_call.encode();
189
190 assert_eq!(srml_call_encoded, contract_call_encoded);
191
192 let srml_call_decoded: node_runtime::Call =
193 Decode::decode(&mut contract_call_encoded.as_slice())165 Nft::<NodeRuntimeTypes>::create_item(collection_id, properties).into()
194 .expect("Balances transfer call decodes to srml type");166}
195 let srml_call_encoded = srml_call_decoded.encode();167
196 let contract_call_decoded: Call = Decode::decode(&mut srml_call_encoded.as_slice())168pub fn burn_item(collection_id: u64, item_id: u64) -> Call {
197 .expect("Balances transfer call decodes back to contract type");169 Nft::<NodeRuntimeTypes>::burn_item(collection_id, item_id).into()
198 assert!(contract_call == contract_call_decoded);170}
199 }171
200}172//GetOwner
201173//BalanceOf
modifiedsmart_contract/ink-types-node-runtime/src/lib.rsdiffbeforeafterboth

no syntactic changes