Skip to content

Commit

Permalink
Merge pull request #8 from uni-arts-chain/dev
Browse files Browse the repository at this point in the history
admin transfer
  • Loading branch information
tuminfei authored Mar 17, 2022
2 parents a03e224 + ded537e commit 5eee455
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pallets/nft-multi/src/default_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ impl crate::WeightInfo for () {
.saturating_add(DbWeight::get().reads(5 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn admin_transfer() -> Weight {
(66_234_000 as Weight)
.saturating_add(DbWeight::get().reads(5 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn transfer_and_lock() -> Weight {
(66_234_000 as Weight)
.saturating_add(DbWeight::get().reads(5 as Weight))
Expand Down
23 changes: 23 additions & 0 deletions pallets/nft-multi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub trait WeightInfo {
fn create_item() -> Weight;
fn burn_item() -> Weight;
fn transfer() -> Weight;
fn admin_transfer() -> Weight;
fn transfer_and_lock() -> Weight;
fn batch_create_nft_item() -> Weight;
fn unlock() -> Weight;
Expand Down Expand Up @@ -410,6 +411,7 @@ decl_event!(
ItemCreated(u64, u64),
ItemDestroyed( u64, u64),
ItemTransfer(u64, u64, u64, AccountId, AccountId),
AdminTransfer(u64, u64, u64, AccountId, AccountId),
ItemLock(u64, u64, u64, AccountId),
ItemUnlock(u64, u64, u64, AccountId),
ItemOrderCreated(u64, u64, u64, u64, AccountId, u64, CurrencyId),
Expand Down Expand Up @@ -933,6 +935,27 @@ decl_module! {
// call event
Self::deposit_event(RawEvent::ItemTransfer(collection_id, item_id, value, sender, recipient));

Ok(())
}

#[weight = T::WeightInfo::admin_transfer()]
pub fn admin_transfer(origin, from: T::AccountId, to: T::AccountId, collection_id: u64, item_id: u64, value: u64) -> DispatchResult {

let sender = ensure_signed(origin)?;

Self::check_admin_permissions(collection_id, sender.clone())?;

let target_collection = <Collection<T>>::get(collection_id);

if let CollectionMode::ReFungible(_, _) = target_collection.mode {
Self::transfer_refungible(collection_id, item_id, value, from.clone(), to.clone())?;
// call event
Self::deposit_event(RawEvent::ItemTransfer(collection_id, item_id, value, from.clone(), to.clone()));
Self::deposit_event(RawEvent::AdminTransfer(collection_id, item_id, value, from.clone(), to.clone()));
} else {
panic!("Collection is not ReFungible mode");
}

Ok(())
}

Expand Down

0 comments on commit 5eee455

Please sign in to comment.