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.rsdiffbeforeafterboth--- a/smart_contract/ink-types-node-runtime/src/calls.rs
+++ b/smart_contract/ink-types-node-runtime/src/calls.rs
@@ -17,6 +17,18 @@
}
}
+// #[cfg_attr(feature = "ink-generate-abi", derive(Metadata))]
+#[derive(Encode, Decode, Debug, Eq, Clone, PartialEq)]
+pub enum CollectionMode {
+ Invalid,
+ // custom data size
+ NFT(u32),
+ // decimal points
+ Fungible(u32),
+ // custom data size and decimal points
+ ReFungible(u32, u32),
+}
+
/// Generic Balance Call, could be used with other runtimes
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
pub enum Nft<T>
@@ -25,19 +37,28 @@
T::AccountId: Member + Codec,
{
#[allow(non_camel_case_types)]
- create_collection(Vec<u16>, Vec<u16>, Vec<u8>, u8, u32, u32),
+ create_collection(Vec<u16>, Vec<u16>, Vec<u8>, CollectionMode),
#[allow(non_camel_case_types)]
destroy_collection(u64),
#[allow(non_camel_case_types)]
+ add_collection_admin(u64, T::AccountId),
+
+ #[allow(non_camel_case_types)]
+ remove_collection_admin(u64, T::AccountId),
+
+ #[allow(non_camel_case_types)]
change_collection_owner(u64, T::AccountId),
#[allow(non_camel_case_types)]
- add_collection_admin(u64, T::AccountId),
+ set_collection_sponsor(u64, T::AccountId),
+
+ #[allow(non_camel_case_types)]
+ confirm_sponsorship(u64),
#[allow(non_camel_case_types)]
- remove_collection_admin(u64, T::AccountId),
+ remove_collection_sponsor(u64),
#[allow(non_camel_case_types)]
create_item(u64, Vec<u8>, T::AccountId),
@@ -46,37 +67,36 @@
burn_item(u64, u64),
#[allow(non_camel_case_types)]
- transfer(T::AccountId, u64, u64),
+ transfer(T::AccountId, u64, u64, u64),
#[allow(non_camel_case_types)]
nft_approve(T::AccountId, u64, u64),
#[allow(non_camel_case_types)]
- nft_transfer_from(T::AccountId, u64, u64),
+ nft_transfer_from(T::AccountId, u64, u64, u64),
#[allow(non_camel_case_types)]
nft_safe_transfer(u64, u64, T::AccountId),
+
+ #[allow(non_camel_case_types)]
+ set_offchain_schema(u64, Vec<u8>),
}
-pub fn transfer(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {
- Nft::<NodeRuntimeTypes>::transfer(collection_id, item_id, new_owner.into()).into()
+pub fn transfer(new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) -> Call {
+ Nft::<NodeRuntimeTypes>::transfer(new_owner.into(), collection_id, item_id, value).into()
}
pub fn create_collection(
collection_name: Vec<u16>,
collection_description: Vec<u16>,
token_prefix: Vec<u8>,
- mode: u8,
- decimal_points: u32,
- custom_data_size: u32,
+ mode: CollectionMode
) -> Call {
Nft::<NodeRuntimeTypes>::create_collection(
collection_name,
collection_description,
token_prefix,
- mode,
- decimal_points,
- custom_data_size,
+ mode
)
.into()
}
@@ -89,8 +109,8 @@
Nft::<NodeRuntimeTypes>::nft_approve(approved.into(), collection_id, item_id).into()
}
-pub fn transfer_from(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {
- Nft::<NodeRuntimeTypes>::nft_transfer_from(collection_id, item_id, new_owner.into()).into()
+pub fn transfer_from(new_owner: AccountId, collection_id: u64, item_id: u64, value: u64) -> Call {
+ Nft::<NodeRuntimeTypes>::nft_transfer_from(new_owner.into(), collection_id, item_id, value).into()
}
pub fn create_item(collection_id: u64, properties: Vec<u8>, owner: AccountId) -> Call {
smart_contract/ink-types-node-runtime/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]23use core::{array::TryFromSliceError, convert::TryFrom};4use ink_core::env::Clear;5use scale::{Decode, Encode};6use sp_core::crypto::AccountId32;7#[cfg(feature = "ink-generate-abi")]8use type_metadata::{HasTypeDef, HasTypeId, MetaType, Metadata, TypeDef, TypeId, TypeIdArray};910pub mod calls;1112/// Contract environment types defined in substrate node-runtime13#[cfg_attr(feature = "ink-generate-abi", derive(Metadata))]14#[derive(Clone, Debug, PartialEq, Eq)]15pub enum NodeRuntimeTypes {}1617#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]18pub struct AccountId(AccountId32);1920impl From<AccountId32> for AccountId {21 fn from(account: AccountId32) -> Self {22 AccountId(account)23 }24}2526impl From<[u8; 32]> for AccountId {27 fn from(account: [u8; 32]) -> Self {28 AccountId(AccountId32::from(account))29 }30}3132#[cfg(feature = "ink-generate-abi")]33impl HasTypeId for AccountId {34 fn type_id() -> TypeId {35 TypeIdArray::new(32, MetaType::new::<u8>()).into()36 }37}3839#[cfg(feature = "ink-generate-abi")]40impl HasTypeDef for AccountId {41 fn type_def() -> TypeDef {42 TypeDef::builtin()43 }44}4546/// The default SRML balance type.47pub type Balance = u128;4849/// The default SRML hash type.50#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]51pub struct Hash([u8; 32]);5253impl From<[u8; 32]> for Hash {54 fn from(hash: [u8; 32]) -> Hash {55 Hash(hash)56 }57}5859impl<'a> TryFrom<&'a [u8]> for Hash {60 type Error = TryFromSliceError;6162 fn try_from(bytes: &'a [u8]) -> Result<Hash, TryFromSliceError> {63 let hash = <[u8; 32]>::try_from(bytes)?;64 Ok(Hash(hash))65 }66}6768impl AsRef<[u8]> for Hash {69 fn as_ref(&self) -> &[u8] {70 &self.0[..]71 }72}7374impl AsMut<[u8]> for Hash {75 fn as_mut(&mut self) -> &mut [u8] {76 &mut self.0[..]77 }78}7980impl Clear for Hash {81 fn is_clear(&self) -> bool {82 self.as_ref().iter().all(|&byte| byte == 0x00)83 }8485 fn clear() -> Self {86 Self([0x00; 32])87 }88}8990/// The default SRML moment type.91pub type Moment = u64;9293/// The default SRML blocknumber type.94pub type BlockNumber = u64;9596/// The default SRML AccountIndex type.97pub type AccountIndex = u32;9899/// The default timestamp type.100pub type Timestamp = u64;101102impl ink_core::env::EnvTypes for NodeRuntimeTypes {103 type AccountId = AccountId;104 type Balance = Balance;105 type Hash = Hash;106 type Timestamp = Timestamp;107 type BlockNumber = BlockNumber;108 type Call = calls::Call;109}