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
30## Test30## Test
31```31```
32cargo +nightly test32cargo +nightly test
33```
34
35## UI custom types
36```
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```33```
modifiedsmart_contract/ink-types-node-runtime/calls/lib.rsdiffbeforeafterboth
7 use ink_core::env;7 use ink_core::env;
8 use ink_prelude::vec::Vec;8 use ink_prelude::vec::Vec;
9 use ink_prelude::*;9 use ink_prelude::*;
10 use ink_types_node_runtime::{calls as runtime_calls, NodeRuntimeTypes};10 use ink_types_node_runtime::{calls as runtime_calls, NodeRuntimeTypes, RawData, AccountList };
11 use scale::{11 use scale::{
12 Decode,12 Decode,
13 Encode,13 Encode,
29 fn new(&mut self) {}29 fn new(&mut self) {}
3030
31 #[ink(message)]31 #[ink(message)]
32 fn transfer(&self, collection_id: u64, item_id: u64, new_owner: AccountId) {32 fn transfer(&self, new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) {
33 env::println(&format!(33 env::println(&format!(
34 "transfer invoke_runtime params {:?}, {:?}, {:?} ",34 "transfer invoke_runtime params {:?}, {:?}, {:?}, {:?} ",
35 collection_id, item_id, new_owner35 new_owner, collection_id, item_id, value
36 ));36 ));
3737
38 let transfer_call = runtime_calls::transfer(collection_id, item_id, new_owner);38 let transfer_call = runtime_calls::transfer(new_owner, collection_id, item_id, value);
39 // dispatch the call to the runtime39 // dispatch the call to the runtime
40 let result = self.env().invoke_runtime(&transfer_call);40 let result = self.env().invoke_runtime(&transfer_call);
4141
63 }63 }
6464
65 #[ink(message)]65 #[ink(message)]
66 fn get_approved(&self, collection_id: u64, item_id: u64) -> Vec<AccountId> {66 fn get_approved(&self, collection_id: u64, item_id: u64) -> AccountList {
67 let mut key = vec![67 let mut key = vec![
68 // Precomputed: Twox128("Nft")68 // Precomputed: Twox128("Nft")
69 244, 63, 251, 230, 30, 244, 104, 116, 157, 54, 23, 172, 26, 99, 196, 183,69 244, 63, 251, 230, 30, 244, 104, 116, 157, 54, 23, 172, 26, 99, 196, 183,
92 match result {92 match result {
93 Some(Ok(accounts)) => { 93 Some(Ok(accounts)) => {
94 env::println(&format!("get_approved result {:?}", accounts));94 env::println(&format!("get_approved result {:?}", accounts));
95 accounts 95 AccountList(accounts)
96 },96 },
97 Some(Err(err)) => {97 Some(Err(err)) => {
98 env::println(&format!("Error reading {:?}", err));98 env::println(&format!("Error reading {:?}", err));
99 vec![]99 AccountList(vec![])
100 }100 }
101 None => {101 None => {
102 env::println(&format!("No data at key {:?}", key));102 env::println(&format!("No data at key {:?}", key));
103 vec![]103 AccountList(vec![])
104 }104 }
105 }105 }
106 }106 }
107107
108 #[ink(message)]108 #[ink(message)]
109 fn transfer_from(&self, collection_id: u64, item_id: u64, new_owner: AccountId) {109 fn transfer_from(&self, new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) {
110 env::println(&format!(110 env::println(&format!(
111 "transfer_from invoke_runtime params {:?}, {:?}, {:?} ",111 "transfer_from invoke_runtime params {:?}, {:?}, {:?}, {:?} ",
112 collection_id, item_id, new_owner112 new_owner, collection_id, item_id, value
113 ));113 ));
114114
115 let transfer_from_call =115 let transfer_from_call =
116 runtime_calls::transfer_from(collection_id, item_id, new_owner);116 runtime_calls::transfer_from(new_owner, collection_id, item_id, value);
117 // dispatch the call to the runtime117 // dispatch the call to the runtime
118 let result = self.env().invoke_runtime(&transfer_from_call);118 let result = self.env().invoke_runtime(&transfer_from_call);
119119
124124
125 // SafeTransferFrom125 // SafeTransferFrom
126 #[ink(message)]126 #[ink(message)]
127 fn create_item(&self, collection_id: u64, properties: Vec<u8>, owner: AccountId) {127 fn create_item(&self, collection_id: u64, properties: RawData, owner: AccountId) {
128 env::println(&format!(128 env::println(&format!(
129 "create_item invoke_runtime params {:?}, {:?} ",129 "create_item invoke_runtime params {:?}, {:?}, {:?} ",
130 collection_id, properties130 collection_id, properties, owner
131 ));131 ));
132132
133 let create_item_call = runtime_calls::create_item(collection_id, properties, owner);133 let create_item_call = runtime_calls::create_item(collection_id, properties.into(), owner);
134 // dispatch the call to the runtime134 // dispatch the call to the runtime
135 let result = self.env().invoke_runtime(&create_item_call);135 let result = self.env().invoke_runtime(&create_item_call);
136136
modifiedsmart_contract/ink-types-node-runtime/src/calls.rsdiffbeforeafterboth
17 }17 }
18}18}
19
20// #[cfg_attr(feature = "ink-generate-abi", derive(Metadata))]
21#[derive(Encode, Decode, Debug, Eq, Clone, PartialEq)]
22pub enum CollectionMode {
23 Invalid,
24 // custom data size
25 NFT(u32),
26 // decimal points
27 Fungible(u32),
28 // custom data size and decimal points
29 ReFungible(u32, u32),
30}
1931
20/// Generic Balance Call, could be used with other runtimes32/// Generic Balance Call, could be used with other runtimes
21#[derive(Encode, Decode, Clone, PartialEq, Eq)]33#[derive(Encode, Decode, Clone, PartialEq, Eq)]
25 T::AccountId: Member + Codec,37 T::AccountId: Member + Codec,
26{38{
27 #[allow(non_camel_case_types)]39 #[allow(non_camel_case_types)]
28 create_collection(Vec<u16>, Vec<u16>, Vec<u8>, u8, u32, u32),40 create_collection(Vec<u16>, Vec<u16>, Vec<u8>, CollectionMode),
2941
30 #[allow(non_camel_case_types)]42 #[allow(non_camel_case_types)]
31 destroy_collection(u64),43 destroy_collection(u64),
3244
33 #[allow(non_camel_case_types)]45 #[allow(non_camel_case_types)]
34 change_collection_owner(u64, T::AccountId),46 add_collection_admin(u64, T::AccountId),
3547
36 #[allow(non_camel_case_types)]48 #[allow(non_camel_case_types)]
37 add_collection_admin(u64, T::AccountId),49 remove_collection_admin(u64, T::AccountId),
3850
39 #[allow(non_camel_case_types)]51 #[allow(non_camel_case_types)]
40 remove_collection_admin(u64, T::AccountId),52 change_collection_owner(u64, T::AccountId),
53
54 #[allow(non_camel_case_types)]
55 set_collection_sponsor(u64, T::AccountId),
56
57 #[allow(non_camel_case_types)]
58 confirm_sponsorship(u64),
59
60 #[allow(non_camel_case_types)]
61 remove_collection_sponsor(u64),
4162
42 #[allow(non_camel_case_types)]63 #[allow(non_camel_case_types)]
43 create_item(u64, Vec<u8>, T::AccountId),64 create_item(u64, Vec<u8>, T::AccountId),
46 burn_item(u64, u64),67 burn_item(u64, u64),
4768
48 #[allow(non_camel_case_types)]69 #[allow(non_camel_case_types)]
49 transfer(T::AccountId, u64, u64),70 transfer(T::AccountId, u64, u64, u64),
5071
51 #[allow(non_camel_case_types)]72 #[allow(non_camel_case_types)]
52 nft_approve(T::AccountId, u64, u64),73 nft_approve(T::AccountId, u64, u64),
5374
54 #[allow(non_camel_case_types)]75 #[allow(non_camel_case_types)]
55 nft_transfer_from(T::AccountId, u64, u64),76 nft_transfer_from(T::AccountId, u64, u64, u64),
5677
57 #[allow(non_camel_case_types)]78 #[allow(non_camel_case_types)]
58 nft_safe_transfer(u64, u64, T::AccountId),79 nft_safe_transfer(u64, u64, T::AccountId),
80
81 #[allow(non_camel_case_types)]
82 set_offchain_schema(u64, Vec<u8>),
59}83}
6084
61pub fn transfer(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {85pub fn transfer(new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) -> Call {
62 Nft::<NodeRuntimeTypes>::transfer(collection_id, item_id, new_owner.into()).into()86 Nft::<NodeRuntimeTypes>::transfer(new_owner.into(), collection_id, item_id, value).into()
63}87}
6488
65pub fn create_collection(89pub fn create_collection(
66 collection_name: Vec<u16>,90 collection_name: Vec<u16>,
67 collection_description: Vec<u16>,91 collection_description: Vec<u16>,
68 token_prefix: Vec<u8>,92 token_prefix: Vec<u8>,
69 mode: u8,93 mode: CollectionMode
70 decimal_points: u32,
71 custom_data_size: u32,
72) -> Call {94) -> Call {
73 Nft::<NodeRuntimeTypes>::create_collection(95 Nft::<NodeRuntimeTypes>::create_collection(
74 collection_name,96 collection_name,
75 collection_description,97 collection_description,
76 token_prefix,98 token_prefix,
77 mode,99 mode
78 decimal_points,
79 custom_data_size,
80 )100 )
81 .into()101 .into()
82}102}
89 Nft::<NodeRuntimeTypes>::nft_approve(approved.into(), collection_id, item_id).into()109 Nft::<NodeRuntimeTypes>::nft_approve(approved.into(), collection_id, item_id).into()
90}110}
91111
92pub fn transfer_from(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {112pub fn transfer_from(new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) -> Call {
93 Nft::<NodeRuntimeTypes>::nft_transfer_from(collection_id, item_id, new_owner.into()).into()113 Nft::<NodeRuntimeTypes>::nft_transfer_from(new_owner.into(), collection_id, item_id, value).into()
94}114}
95115
96pub fn create_item(collection_id: u64, properties: Vec<u8>, owner: AccountId) -> Call {116pub fn create_item(collection_id: u64, properties: Vec<u8>, owner: AccountId) -> Call {
modifiedsmart_contract/ink-types-node-runtime/src/lib.rsdiffbeforeafterboth
4use ink_core::env::Clear;4use ink_core::env::Clear;
5use scale::{Decode, Encode};5use scale::{Decode, Encode};
6use sp_core::crypto::AccountId32;6use sp_core::crypto::AccountId32;
7use ink_prelude::vec::Vec;
7#[cfg(feature = "ink-generate-abi")]8#[cfg(feature = "ink-generate-abi")]
8use type_metadata::{HasTypeDef, HasTypeId, MetaType, Metadata, TypeDef, TypeId, TypeIdArray};9use type_metadata::{ HasTypeDef, HasTypeId, MetaType, Metadata, TypeDef, TypeId, TypeIdArray, TypeIdSlice};
910
10pub mod calls;11pub mod calls;
1112
46/// The default SRML balance type.47/// The default SRML balance type.
47pub type Balance = u128;48pub type Balance = u128;
49
50#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
51pub struct AccountList(pub Vec<AccountId>);
52
53impl AccountList {
54 pub fn new(param: Vec<AccountId>) -> AccountList {
55 AccountList(param)
56 }
57}
58
59impl Into<Vec<AccountId>> for AccountList {
60 fn into(self) -> Vec<AccountId> {
61 self.0
62 }
63}
64
65#[cfg(feature = "ink-generate-abi")]
66impl HasTypeDef for AccountList {
67 fn type_def() -> TypeDef {
68 TypeDef::builtin()
69 }
70}
71
72#[cfg(feature = "ink-generate-abi")]
73impl HasTypeId for AccountList {
74 fn type_id() -> TypeId {
75 TypeIdSlice::new(AccountId::meta_type()).into()
76 }
77}
78
79
80#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]
81pub struct RawData(Vec<u8>);
82
83impl Into<Vec<u8>> for RawData {
84 fn into(self) -> Vec<u8> {
85 self.0
86 }
87}
88
89#[cfg(feature = "ink-generate-abi")]
90impl HasTypeDef for RawData {
91 fn type_def() -> TypeDef {
92 TypeDef::builtin()
93 }
94}
95
96#[cfg(feature = "ink-generate-abi")]
97impl HasTypeId for RawData {
98 fn type_id() -> TypeId {
99 TypeIdSlice::new(u8::meta_type()).into()
100 }
101}
48102
49/// The default SRML hash type.103/// The default SRML hash type.
50#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]104#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]