Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
78b2c5c
include livingassets-ownership pallet
asiniscalchi Jul 14, 2023
0d7e0ed
Merge branch 'dev' into feature/import_laos_ownership_pallet
asiniscalchi Jul 14, 2023
fed1e16
Some refactoring and skeleton
dastanbeksamatov Jul 14, 2023
404d967
LivingAssetsOwnership trait created
asiniscalchi Jul 17, 2023
bcf78d4
LivingAssetsOwnership trait is pub
asiniscalchi Jul 17, 2023
a8cca7f
test to check for pallet to satisfy trait
asiniscalchi Jul 17, 2023
2f18241
LivingAssetsOwnership trait implemented for Pallet
asiniscalchi Jul 17, 2023
2a0f9bf
test done
asiniscalchi Jul 17, 2023
43072ce
testing the trait functionality
asiniscalchi Jul 17, 2023
fffe582
Add precompile utils dep
dastanbeksamatov Jul 17, 2023
c476e34
Merge branch 'dev' of github-freeverse:freeverseio/laos-ownership-nod…
dastanbeksamatov Jul 17, 2023
f7b3f7e
Fix invalid pallet dir name
dastanbeksamatov Jul 17, 2023
3654bdf
test passing
asiniscalchi Jul 17, 2023
783d7c5
created function.rs
asiniscalchi Jul 17, 2023
52d7443
refactoring
asiniscalchi Jul 17, 2023
781830c
removed commented code
asiniscalchi Jul 17, 2023
8c4f3ea
added minimal doc
asiniscalchi Jul 17, 2023
2c9a482
better doc
asiniscalchi Jul 18, 2023
c3a2d97
fix compilation
asiniscalchi Jul 18, 2023
b1dc5ea
LivingAssetOwnership trait is generic of T::Config
asiniscalchi Jul 18, 2023
75bae98
+ documentation
asiniscalchi Jul 18, 2023
952df1f
+ file comment
asiniscalchi Jul 18, 2023
f02e3c0
added CollectionId associated type
asiniscalchi Jul 18, 2023
d7105f2
CollectionId is a associated type
asiniscalchi Jul 18, 2023
9686754
define CollectionId in the runtime
asiniscalchi Jul 18, 2023
5ad9634
+ doc
asiniscalchi Jul 18, 2023
07f6577
Fix some compile errors
dastanbeksamatov Jul 18, 2023
41134d8
Merge branch 'feature/living-assets-ownership-trait' of github-freeve…
dastanbeksamatov Jul 18, 2023
8082586
Use astar precompile utils
dastanbeksamatov Jul 19, 2023
8953c39
Try fix compile error
dastanbeksamatov Jul 19, 2023
b0b6f53
Some more changes
dastanbeksamatov Jul 19, 2023
a35cd15
Merge branch 'dev' of github-freeverse:freeverseio/laos-ownership-nod…
dastanbeksamatov Jul 19, 2023
9fd73b5
Remove workspace deps
dastanbeksamatov Jul 20, 2023
c61f74a
Fix more deps
dastanbeksamatov Jul 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
542 changes: 354 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ panic = "unwind"
members = [
"node",
"runtime",
"pallets/*",
"precompiles/*",
]

[workspace.package]
authors = ["Freeverse"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = ""
version = "0.0.1"
license = "Unlicense"
homepage = ""
repository = "https://github.com/freeverseio/pallet-livingassets-ownership"
repository = "https://github.com/freeverseio/pallet-living-assets-ownership"
edition = "2021"

[package.metadata.docs.rs]
Expand All @@ -19,9 +19,10 @@ scale-info = { version = "2.2.0", default-features = false, features = ["derive"
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.43" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }

[dev-dependencies]
serde = { version = "1.0.132" }
serde = { version = "1.0.163", default-features = false }

# Substrate
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
Expand All @@ -30,12 +31,13 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", default-features

[features]
default = ["std"]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks"]
std = [
"codec/std",
"scale-info/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"sp-arithmetic/std",
]
try-runtime = [ "frame-support/try-runtime" ]
try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime" ]
111 changes: 111 additions & 0 deletions pallets/living-assets-ownership/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#![cfg_attr(not(feature = "std"), no_std)]

/// Edit this file to define custom logic or remove it if it is not needed.
/// Learn more about FRAME and the core library of Substrate FRAME pallets:
/// <https://docs.substrate.io/reference/frame-pallets/>
pub use pallet::*;

mod functions;

#[cfg(test)]
mod mock;

#[cfg(test)]
mod tests;

#[frame_support::pallet]
pub mod pallet {
use frame_support::pallet_prelude::{OptionQuery, *};
use frame_system::pallet_prelude::*;

#[pallet::pallet]
pub struct Pallet<T>(_);

/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config: frame_system::Config {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Collection id type
type CollectionId: Member + Parameter + MaxEncodedLen + Copy;
}

/// Mapping from collection id to owner
#[pallet::storage]
#[pallet::getter(fn owner_of_collection)]
pub(super) type OwnerOfCollection<T: Config> =
StorageMap<_, Blake2_128Concat, T::CollectionId, T::AccountId, OptionQuery>;

/// Pallet events
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Collection created
/// parameters. [collection_id, who]
CollectionCreated { collection_id: T::CollectionId, who: T::AccountId },
}

// Errors inform users that something went wrong.
#[pallet::error]
pub enum Error<T> {
/// Collection already exists
CollectionAlreadyExists,
}

// Dispatchable functions allows users to interact with the pallet and invoke state changes.
// These functions materialize as "extrinsics", which are often compared to transactions.
// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())] // TODO set proper weight
pub fn create_collection(
origin: OriginFor<T>,
collection_id: T::CollectionId,
) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::do_create_collection(collection_id, who)
}
}

/// The `LivingAssetsOwnership` trait provides an interface for managing collections in a
/// decentralized and non-fungible asset management system. This system allows for the creation of
/// collections, each of which can be owned by a unique `AccountId`.
///
/// A collection in this context can be thought of as a container for non-fungible assets.
/// Each collection has an associated `collection_id` which is a unique identifier for the collection
/// and can be used to retrieve the owner of the collection.
///
/// # Methods
///
/// - `owner_of_collection(collection_id: T::CollectionId) -> Option<AccountId>`: This method retrieves the owner
/// of a collection given its `collection_id`. If no collection exists with the provided `collection_id`,
/// the method returns `None`.
///
/// - `create_collection(collection_id: T::CollectionId, who: AccountId) -> DispatchResult`: This method creates a
/// new collection with the specified `collection_id` and assigns ownership to the provided `AccountId`.
/// If a collection already exists with the provided `collection_id`, the method will return an error.
///
/// # Errors
///
/// - `CollectionAlreadyExists`: This error is returned by the `create_collection` method when a collection
/// with the provided `collection_id` already exists.
///
pub trait LivingAssetsOwnership<AccountId, CollectionId> {
/// Get owner of collection
fn owner_of_collection(collection_id: CollectionId) -> Option<AccountId>;

/// Create collection
fn create_collection(collection_id: CollectionId, who: AccountId) -> DispatchResult;
}

impl<T: Config> LivingAssetsOwnership<T::AccountId, T::CollectionId> for Pallet<T> {
fn owner_of_collection(collection_id: T::CollectionId) -> Option<T::AccountId> {
OwnerOfCollection::<T>::get(collection_id)
}

fn create_collection(collection_id: T::CollectionId, who: T::AccountId) -> DispatchResult {
Self::do_create_collection(collection_id, who)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod test {
use super::*;

type AccountId = <Test as frame_system::Config>::AccountId;
type CollectionId = <Test as crate::Config>::CollectionId;
type CollectionId = <Test as crate::Config>::CollectionId;

#[test]
fn owner_of_unexistent_collection_is_none() {
Expand Down Expand Up @@ -48,7 +48,7 @@ mod test {

#[test]
fn living_assets_ownership_trait_create_new_collection_by_living() {
new_test_ext().execute_with(|| {
new_test_ext().execute_with(|| {
let result = <LivingAssetsModule as LivingAssetsOwnership<AccountId, CollectionId>>::create_collection(0, 1);
assert_ok!(result);
assert_eq!(LivingAssetsModule::owner_of_collection(0), Some(1));
Expand Down
Loading