1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
pub use super::*;
pub use frame_support::{
assert_ok,
dispatch::{DispatchResult, EncodeLike},
inherent::Vec,
pallet_prelude::*,
sp_runtime::{
traits::{AccountIdConversion, Hash, One, Saturating, StaticLookup, Zero},
PerThing, Percent,
},
storage::child,
traits::{
Currency, ExistenceRequirement, Get, LockableCurrency, ReservableCurrency, WithdrawReasons,
},
PalletId,
};
pub use frame_system::{ensure_signed, pallet_prelude::*, RawOrigin};
pub use scale_info::{
prelude::{format, vec},
TypeInfo,
};
pub use serde::{Deserialize, Serialize};
pub type BlockNumberOf<T> = <T as frame_system::Config>::BlockNumber;
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
#[derive(Clone, Encode, Decode, PartialEq, Eq, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Owners<T: Config> {
pub owners: Vec<(T::AccountId, <T as Assets::Config>::Balance)>,
pub created_at_block: BlockNumberOf<T>,
pub token_id: <T as pallet::Config>::AssetId,
pub supply: <T as Assets::Config>::Balance,
}
impl<T: Config> Owners<T> {
pub fn new(virtual_account: T::AccountId) -> DispatchResult {
let owners = Vec::new();
let created_at_block = <frame_system::Pallet<T>>::block_number();
let token_id: <T as pallet::Config>::AssetId = TokenId::<T>::get().into();
let supply = Zero::zero();
let tokens = Owners::<T> { owners, created_at_block, token_id, supply };
Tokens::<T>::insert(virtual_account, tokens);
Ok(())
}
}
#[derive(Clone, Encode, Decode, PartialEq, Eq, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Ownership<T: Config> {
pub virtual_account: T::AccountId,
pub owners: Vec<T::AccountId>,
pub created: BlockNumberOf<T>,
pub token_id: <T as pallet::Config>::AssetId,
pub rent_nbr: u32,
}
impl<T: Config> Ownership<T> {
pub fn new(
collection: T::NftCollectionId,
item: T::NftItemId,
virtual_account: T::AccountId,
) -> DispatchResult {
let owners = Vec::new();
let created = <frame_system::Pallet<T>>::block_number();
let token_id: <T as pallet::Config>::AssetId = TokenId::<T>::get().into();
let rent_nbr = 0;
let ownership = Ownership::<T> { virtual_account, owners, created, token_id, rent_nbr };
Virtual::<T>::insert(collection, item, ownership);
Ok(())
}
}