difftreelog
Smart contract update
in: master
4 files changed
smart_contract/ink-types-node-runtime/README.mddiffbeforeafterboth--- a/smart_contract/ink-types-node-runtime/README.md
+++ b/smart_contract/ink-types-node-runtime/README.md
@@ -30,64 +30,4 @@
## Test
```
cargo +nightly test
-```
-
-## UI custom types
-```
-{
- "Schedule": {
- "version": "u32",
- "put_code_per_byte_cost": "Gas",
- "grow_mem_cost": "Gas",
- "regular_op_cost": "Gas",
- "return_data_per_byte_cost": "Gas",
- "event_data_per_byte_cost": "Gas",
- "event_per_topic_cost": "Gas",
- "event_base_cost": "Gas",
- "call_base_cost": "Gas",
- "instantiate_base_cost": "Gas",
- "dispatch_base_cost": "Gas",
- "sandbox_data_read_cost": "Gas",
- "sandbox_data_write_cost": "Gas",
- "transfer_cost": "Gas",
- "instantiate_cost": "Gas",
- "max_event_topics": "u32",
- "max_stack_height": "u32",
- "max_memory_pages": "u32",
- "max_table_size": "u32",
- "enable_println": "bool",
- "max_subject_len": "u32"
- },
- "CollectionMode": {
- "_enum": {
- "Invalid": null,
- "NFT": "u32",
- "Fungible": "u32",
- "ReFungible": "(u32, u32)"
- }
- },
- "NftItemType": {
- "Collection": "u64",
- "Owner": "AccountId",
- "Data": "Vec<u8>"
- },
- "CollectionType": {
- "Owner": "AccountId",
- "Mode": "CollectionMode",
- "Access": "u8",
- "NextItemId": "u64",
- "DecimalPoints": "u32",
- "Name": "Vec<u16>",
- "Description": "Vec<u16>",
- "TokenPrefix": "Vec<u8>",
- "CustomDataSize": "u32",
- "OffchainSchema": "Vec<u8>",
- "Sponsor": "AccountId",
- "UnconfirmedSponsor": "AccountId"
- },
- "RawData": "Vec<u8>",
- "Address": "AccountId",
- "LookupSource": "AccountId",
- "Weight": "u64"
-}
```
\ No newline at end of file
smart_contract/ink-types-node-runtime/calls/lib.rsdiffbeforeafterboth--- a/smart_contract/ink-types-node-runtime/calls/lib.rs
+++ b/smart_contract/ink-types-node-runtime/calls/lib.rs
@@ -7,7 +7,7 @@
use ink_core::env;
use ink_prelude::vec::Vec;
use ink_prelude::*;
- use ink_types_node_runtime::{calls as runtime_calls, NodeRuntimeTypes};
+ use ink_types_node_runtime::{calls as runtime_calls, NodeRuntimeTypes, RawData, AccountList };
use scale::{
Decode,
Encode,
@@ -29,13 +29,13 @@
fn new(&mut self) {}
#[ink(message)]
- fn transfer(&self, collection_id: u64, item_id: u64, new_owner: AccountId) {
+ fn transfer(&self, new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) {
env::println(&format!(
- "transfer invoke_runtime params {:?}, {:?}, {:?} ",
- collection_id, item_id, new_owner
+ "transfer invoke_runtime params {:?}, {:?}, {:?}, {:?} ",
+ new_owner, collection_id, item_id, value
));
- let transfer_call = runtime_calls::transfer(collection_id, item_id, new_owner);
+ let transfer_call = runtime_calls::transfer(new_owner, collection_id, item_id, value);
// dispatch the call to the runtime
let result = self.env().invoke_runtime(&transfer_call);
@@ -63,7 +63,7 @@
}
#[ink(message)]
- fn get_approved(&self, collection_id: u64, item_id: u64) -> Vec<AccountId> {
+ fn get_approved(&self, collection_id: u64, item_id: u64) -> AccountList {
let mut key = vec![
// Precomputed: Twox128("Nft")
244, 63, 251, 230, 30, 244, 104, 116, 157, 54, 23, 172, 26, 99, 196, 183,
@@ -92,28 +92,28 @@
match result {
Some(Ok(accounts)) => {
env::println(&format!("get_approved result {:?}", accounts));
- accounts
+ AccountList(accounts)
},
Some(Err(err)) => {
env::println(&format!("Error reading {:?}", err));
- vec![]
+ AccountList(vec![])
}
None => {
env::println(&format!("No data at key {:?}", key));
- vec![]
+ AccountList(vec![])
}
}
}
#[ink(message)]
- fn transfer_from(&self, collection_id: u64, item_id: u64, new_owner: AccountId) {
+ fn transfer_from(&self, new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) {
env::println(&format!(
- "transfer_from invoke_runtime params {:?}, {:?}, {:?} ",
- collection_id, item_id, new_owner
+ "transfer_from invoke_runtime params {:?}, {:?}, {:?}, {:?} ",
+ new_owner, collection_id, item_id, value
));
let transfer_from_call =
- runtime_calls::transfer_from(collection_id, item_id, new_owner);
+ runtime_calls::transfer_from(new_owner, collection_id, item_id, value);
// dispatch the call to the runtime
let result = self.env().invoke_runtime(&transfer_from_call);
@@ -124,13 +124,13 @@
// SafeTransferFrom
#[ink(message)]
- fn create_item(&self, collection_id: u64, properties: Vec<u8>, owner: AccountId) {
+ fn create_item(&self, collection_id: u64, properties: RawData, owner: AccountId) {
env::println(&format!(
- "create_item invoke_runtime params {:?}, {:?} ",
- collection_id, properties
+ "create_item invoke_runtime params {:?}, {:?}, {:?} ",
+ collection_id, properties, owner
));
- let create_item_call = runtime_calls::create_item(collection_id, properties, owner);
+ let create_item_call = runtime_calls::create_item(collection_id, properties.into(), owner);
// dispatch the call to the runtime
let result = self.env().invoke_runtime(&create_item_call);
smart_contract/ink-types-node-runtime/src/calls.rsdiffbeforeafterboth1use crate::{AccountId, NodeRuntimeTypes};2use ink_core::env::EnvTypes;3use ink_prelude::vec::Vec;4use scale::{Codec, Decode, Encode};5use sp_runtime::traits::Member;67#[derive(Encode, Decode)]8#[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]9pub enum Call {10 #[codec(index = "7")]11 Nft(Nft<NodeRuntimeTypes>),12}1314impl From<Nft<NodeRuntimeTypes>> for Call {15 fn from(nft_call: Nft<NodeRuntimeTypes>) -> Call {16 Call::Nft(nft_call)17 }18}1920/// Generic Balance Call, could be used with other runtimes21#[derive(Encode, Decode, Clone, PartialEq, Eq)]22pub enum Nft<T>23where24 T: EnvTypes,25 T::AccountId: Member + Codec,26{27 #[allow(non_camel_case_types)]28 create_collection(Vec<u16>, Vec<u16>, Vec<u8>, u8, u32, u32),2930 #[allow(non_camel_case_types)]31 destroy_collection(u64),3233 #[allow(non_camel_case_types)]34 change_collection_owner(u64, T::AccountId),3536 #[allow(non_camel_case_types)]37 add_collection_admin(u64, T::AccountId),3839 #[allow(non_camel_case_types)]40 remove_collection_admin(u64, T::AccountId),4142 #[allow(non_camel_case_types)]43 create_item(u64, Vec<u8>, T::AccountId),4445 #[allow(non_camel_case_types)]46 burn_item(u64, u64),4748 #[allow(non_camel_case_types)]49 transfer(T::AccountId, u64, u64),5051 #[allow(non_camel_case_types)]52 nft_approve(T::AccountId, u64, u64),5354 #[allow(non_camel_case_types)]55 nft_transfer_from(T::AccountId, u64, u64),5657 #[allow(non_camel_case_types)]58 nft_safe_transfer(u64, u64, T::AccountId),59}6061pub fn transfer(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {62 Nft::<NodeRuntimeTypes>::transfer(collection_id, item_id, new_owner.into()).into()63}6465pub fn create_collection(66 collection_name: Vec<u16>,67 collection_description: Vec<u16>,68 token_prefix: Vec<u8>,69 mode: u8,70 decimal_points: u32,71 custom_data_size: u32,72) -> Call {73 Nft::<NodeRuntimeTypes>::create_collection(74 collection_name,75 collection_description,76 token_prefix,77 mode,78 decimal_points,79 custom_data_size,80 )81 .into()82}8384// pub fn safe_transfer(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {85// Nft::<NodeRuntimeTypes>::nft_safe_transfer(collection_id, item_id, new_owner.into()).into()86// }8788pub fn approve(approved: AccountId, collection_id: u64, item_id: u64) -> Call {89 Nft::<NodeRuntimeTypes>::nft_approve(approved.into(), collection_id, item_id).into()90}9192pub fn transfer_from(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {93 Nft::<NodeRuntimeTypes>::nft_transfer_from(collection_id, item_id, new_owner.into()).into()94}9596pub fn create_item(collection_id: u64, properties: Vec<u8>, owner: AccountId) -> Call {97 Nft::<NodeRuntimeTypes>::create_item(collection_id, properties, owner).into()98}99100pub fn burn_item(collection_id: u64, item_id: u64) -> Call {101 Nft::<NodeRuntimeTypes>::burn_item(collection_id, item_id).into()102}1use crate::{AccountId, NodeRuntimeTypes};2use ink_core::env::EnvTypes;3use ink_prelude::vec::Vec;4use scale::{Codec, Decode, Encode};5use sp_runtime::traits::Member;67#[derive(Encode, Decode)]8#[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]9pub enum Call {10 #[codec(index = "7")]11 Nft(Nft<NodeRuntimeTypes>),12}1314impl From<Nft<NodeRuntimeTypes>> for Call {15 fn from(nft_call: Nft<NodeRuntimeTypes>) -> Call {16 Call::Nft(nft_call)17 }18}1920// #[cfg_attr(feature = "ink-generate-abi", derive(Metadata))]21#[derive(Encode, Decode, Debug, Eq, Clone, PartialEq)]22pub enum CollectionMode {23 Invalid,24 // custom data size25 NFT(u32),26 // decimal points27 Fungible(u32),28 // custom data size and decimal points29 ReFungible(u32, u32),30}3132/// Generic Balance Call, could be used with other runtimes33#[derive(Encode, Decode, Clone, PartialEq, Eq)]34pub enum Nft<T>35where36 T: EnvTypes,37 T::AccountId: Member + Codec,38{39 #[allow(non_camel_case_types)]40 create_collection(Vec<u16>, Vec<u16>, Vec<u8>, CollectionMode),4142 #[allow(non_camel_case_types)]43 destroy_collection(u64),4445 #[allow(non_camel_case_types)]46 add_collection_admin(u64, T::AccountId),4748 #[allow(non_camel_case_types)]49 remove_collection_admin(u64, T::AccountId),5051 #[allow(non_camel_case_types)]52 change_collection_owner(u64, T::AccountId),5354 #[allow(non_camel_case_types)]55 set_collection_sponsor(u64, T::AccountId),5657 #[allow(non_camel_case_types)]58 confirm_sponsorship(u64),5960 #[allow(non_camel_case_types)]61 remove_collection_sponsor(u64),6263 #[allow(non_camel_case_types)]64 create_item(u64, Vec<u8>, T::AccountId),6566 #[allow(non_camel_case_types)]67 burn_item(u64, u64),6869 #[allow(non_camel_case_types)]70 transfer(T::AccountId, u64, u64, u64),7172 #[allow(non_camel_case_types)]73 nft_approve(T::AccountId, u64, u64),7475 #[allow(non_camel_case_types)]76 nft_transfer_from(T::AccountId, u64, u64, u64),7778 #[allow(non_camel_case_types)]79 nft_safe_transfer(u64, u64, T::AccountId),8081 #[allow(non_camel_case_types)]82 set_offchain_schema(u64, Vec<u8>),83}8485pub fn transfer(new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) -> Call {86 Nft::<NodeRuntimeTypes>::transfer(new_owner.into(), collection_id, item_id, value).into()87}8889pub fn create_collection(90 collection_name: Vec<u16>,91 collection_description: Vec<u16>,92 token_prefix: Vec<u8>,93 mode: CollectionMode94) -> Call {95 Nft::<NodeRuntimeTypes>::create_collection(96 collection_name,97 collection_description,98 token_prefix,99 mode100 )101 .into()102}103104// pub fn safe_transfer(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {105// Nft::<NodeRuntimeTypes>::nft_safe_transfer(collection_id, item_id, new_owner.into()).into()106// }107108pub fn approve(approved: AccountId, collection_id: u64, item_id: u64) -> Call {109 Nft::<NodeRuntimeTypes>::nft_approve(approved.into(), collection_id, item_id).into()110}111112pub fn transfer_from(new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) -> Call {113 Nft::<NodeRuntimeTypes>::nft_transfer_from(new_owner.into(), collection_id, item_id, value).into()114}115116pub fn create_item(collection_id: u64, properties: Vec<u8>, owner: AccountId) -> Call {117 Nft::<NodeRuntimeTypes>::create_item(collection_id, properties, owner).into()118}119120pub fn burn_item(collection_id: u64, item_id: u64) -> Call {121 Nft::<NodeRuntimeTypes>::burn_item(collection_id, item_id).into()122}smart_contract/ink-types-node-runtime/src/lib.rsdiffbeforeafterboth--- a/smart_contract/ink-types-node-runtime/src/lib.rs
+++ b/smart_contract/ink-types-node-runtime/src/lib.rs
@@ -4,8 +4,9 @@
use ink_core::env::Clear;
use scale::{Decode, Encode};
use sp_core::crypto::AccountId32;
+use ink_prelude::vec::Vec;
#[cfg(feature = "ink-generate-abi")]
-use type_metadata::{HasTypeDef, HasTypeId, MetaType, Metadata, TypeDef, TypeId, TypeIdArray};
+use type_metadata::{ HasTypeDef, HasTypeId, MetaType, Metadata, TypeDef, TypeId, TypeIdArray, TypeIdSlice};
pub mod calls;
@@ -46,6 +47,59 @@
/// The default SRML balance type.
pub type Balance = u128;
+#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
+pub struct AccountList(pub Vec<AccountId>);
+
+impl AccountList {
+ pub fn new(param: Vec<AccountId>) -> AccountList {
+ AccountList(param)
+ }
+}
+
+impl Into<Vec<AccountId>> for AccountList {
+ fn into(self) -> Vec<AccountId> {
+ self.0
+ }
+}
+
+#[cfg(feature = "ink-generate-abi")]
+impl HasTypeDef for AccountList {
+ fn type_def() -> TypeDef {
+ TypeDef::builtin()
+ }
+}
+
+#[cfg(feature = "ink-generate-abi")]
+impl HasTypeId for AccountList {
+ fn type_id() -> TypeId {
+ TypeIdSlice::new(AccountId::meta_type()).into()
+ }
+}
+
+
+#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]
+pub struct RawData(Vec<u8>);
+
+impl Into<Vec<u8>> for RawData {
+ fn into(self) -> Vec<u8> {
+ self.0
+ }
+}
+
+#[cfg(feature = "ink-generate-abi")]
+impl HasTypeDef for RawData {
+ fn type_def() -> TypeDef {
+ TypeDef::builtin()
+ }
+}
+
+#[cfg(feature = "ink-generate-abi")]
+impl HasTypeId for RawData {
+ fn type_id() -> TypeId {
+ TypeIdSlice::new(u8::meta_type()).into()
+ }
+}
+
/// The default SRML hash type.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]
pub struct Hash([u8; 32]);